51 int main(
int argc,
char* argv[] )
54 using Teuchos::inoutArg;
64 std::string xmlInFileName =
"";
65 std::string extraXmlFile =
"";
66 std::string xmlOutFileName =
"paramList.out";
69 clp.
setOption(
"xml-in-file",&xmlInFileName,
"The XML file to read into a parameter list");
70 clp.
setOption(
"extra-xml-file",&extraXmlFile,
"File with extra XML text that will modify the initial XML read in");
71 clp.
setOption(
"xml-out-file",&xmlOutFileName,
"The XML file to write the final parameter list to");
73 "This example program shows how to read in a parameter list from an"
74 " XML file (given by --xml-in-file=xmlInFileName) and then modify it"
75 " given some XML specified on the command-line (given by --extra-xml=extrXmlStr)."
76 " The final parameter list is then written back to an XML file."
77 " (given by --xml-out-file=xmlOutFileName)."
80 parse_return = clp.
parse(argc,argv);
82 std::cout <<
"\nEnd Result: TEST FAILED" << std::endl;
88 if(xmlInFileName.length()) {
89 std::cout <<
"\nReading a parameter list from the XML file \""<<xmlInFileName<<
"\" ...\n";
90 Teuchos::updateParametersFromXmlFile(xmlInFileName,
inoutArg(paramList));
91 std::cout <<
"\nParameter list read from the XML file \""<<xmlInFileName<<
"\":\n\n";
92 paramList.
print(std::cout,2,
true,
true);
96 if(extraXmlFile.length()) {
97 std::ifstream myfile(extraXmlFile.c_str());
100 getline (myfile,line);
101 std::cout << line <<
"\n";
104 std::cout <<
"\nUpdating the parameter list given the extra XML std::string:\n\n"<<line<<
"\n";
105 Teuchos::updateParametersFromXmlString(line,
inoutArg(paramList));
106 std::cout <<
"\nParameter list after ammending extra XML std::string:\n\n";
107 paramList.
print(std::cout,2,
true,
true);
110 std::cout <<
"\nWriting the final parameter list back to the XML file \""<<xmlOutFileName<<
"\" ... \n";
111 Teuchos::writeParameterListToXmlFile(paramList,xmlOutFileName);
117 std::cout <<
"\nEnd Result: TEST PASSED" << std::endl;
119 std::cout <<
"\nEnd Result: TEST FAILED" << std::endl;
121 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.