19 int main(
int argc,
char* argv[] )
22 using Teuchos::inoutArg;
32 std::string xmlInFileName =
"";
33 std::string extraXmlFile =
"";
34 std::string xmlOutFileName =
"paramList.out";
37 clp.
setOption(
"xml-in-file",&xmlInFileName,
"The XML file to read into a parameter list");
38 clp.
setOption(
"extra-xml-file",&extraXmlFile,
"File with extra XML text that will modify the initial XML read in");
39 clp.
setOption(
"xml-out-file",&xmlOutFileName,
"The XML file to write the final parameter list to");
41 "This example program shows how to read in a parameter list from an"
42 " XML file (given by --xml-in-file=xmlInFileName) and then modify it"
43 " given some XML specified on the command-line (given by --extra-xml=extrXmlStr)."
44 " The final parameter list is then written back to an XML file."
45 " (given by --xml-out-file=xmlOutFileName)."
48 parse_return = clp.
parse(argc,argv);
50 std::cout <<
"\nEnd Result: TEST FAILED" << std::endl;
56 if(xmlInFileName.length()) {
57 std::cout <<
"\nReading a parameter list from the XML file \""<<xmlInFileName<<
"\" ...\n";
58 Teuchos::updateParametersFromXmlFile(xmlInFileName,
inoutArg(paramList));
59 std::cout <<
"\nParameter list read from the XML file \""<<xmlInFileName<<
"\":\n\n";
60 paramList.
print(std::cout,2,
true,
true);
64 if(extraXmlFile.length()) {
65 std::ifstream myfile(extraXmlFile.c_str());
68 getline (myfile,line);
69 std::cout << line <<
"\n";
72 std::cout <<
"\nUpdating the parameter list given the extra XML std::string:\n\n"<<line<<
"\n";
73 Teuchos::updateParametersFromXmlString(line,
inoutArg(paramList));
74 std::cout <<
"\nParameter list after ammending extra XML std::string:\n\n";
75 paramList.
print(std::cout,2,
true,
true);
78 std::cout <<
"\nWriting the final parameter list back to the XML file \""<<xmlOutFileName<<
"\" ... \n";
79 Teuchos::writeParameterListToXmlFile(paramList,xmlOutFileName);
85 std::cout <<
"\nEnd Result: TEST PASSED" << std::endl;
87 std::cout <<
"\nEnd Result: TEST FAILED" << std::endl;
89 return ( success ? 0 : 1 );
void print() const
Print function to use in debugging in a debugger.
Initialize, finalize, and query the global MPI session.
Simple helper functions that make it easy to read and write XML to and from a parameterlist.
Templated Parameter List class.
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
Set a boolean option.
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
Parse a command line.
Ptr< T > inoutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call...
std::string Teuchos_Version()
A list of parameters of arbitrary type.
int main(int argc, char *argv[])
EParseCommandLineReturn
Return value for CommandLineProcessor::parse(). Note: These enums are all given non-negative values s...
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
void setDocString(const char doc_string[])
Set a documentation sting for the entire program printed when –help is specified. ...
Class that helps parse command line input arguments from (argc,argv[]) and set options.