|
Teuchos Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #include "Teuchos_Version.hpp" 00030 #include "Teuchos_GlobalMPISession.hpp" 00031 #include "Teuchos_CommandLineProcessor.hpp" 00032 #include "Teuchos_StandardCatchMacros.hpp" 00033 #include "Teuchos_ParameterList.hpp" 00034 #include "Teuchos_XMLParameterListHelpers.hpp" 00035 00036 #include <fstream> 00037 00038 int main( int argc, char* argv[] ) 00039 { 00040 Teuchos::GlobalMPISession mpiSession(&argc,&argv); 00041 00042 std::cout << std::endl << Teuchos::Teuchos_Version() << std::endl; 00043 00044 bool success = true; 00045 00046 try { 00047 00048 std::string xmlInFileName = ""; 00049 std::string extraXmlFile = ""; 00050 std::string xmlOutFileName = "paramList.out"; 00051 00052 Teuchos::CommandLineProcessor clp(false); // Don't throw exceptions 00053 clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list"); 00054 clp.setOption("extra-xml-file",&extraXmlFile,"File with extra XML text that will modify the initial XML read in"); 00055 clp.setOption("xml-out-file",&xmlOutFileName,"The XML file to write the final parameter list to"); 00056 clp.setDocString( 00057 "This example program shows how to read in a parameter list from an" 00058 " XML file (given by --xml-in-file=xmlInFileName) and then modify it" 00059 " given some XML specified on the command-line (given by --extra-xml=extrXmlStr)." 00060 " The final parameter list is then written back to an XML file." 00061 " (given by --xml-out-file=xmlOutFileName)." 00062 ); 00063 Teuchos::CommandLineProcessor::EParseCommandLineReturn 00064 parse_return = clp.parse(argc,argv); 00065 if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) { 00066 std::cout << "\nEnd Result: TEST FAILED" << std::endl; 00067 return parse_return; 00068 } 00069 00070 Teuchos::ParameterList paramList; 00071 00072 if(xmlInFileName.length()) { 00073 std::cout << "\nReading a parameter list from the XML file \""<<xmlInFileName<<"\" ...\n"; 00074 Teuchos::updateParametersFromXmlFile(xmlInFileName,¶mList); 00075 std::cout << "\nParameter list read from the XML file \""<<xmlInFileName<<"\":\n\n"; 00076 paramList.print(std::cout,2,true,true); 00077 } 00078 00079 std::string line(""); 00080 if(extraXmlFile.length()) { 00081 std::ifstream myfile(extraXmlFile.c_str()); 00082 if (myfile.is_open()) 00083 { 00084 getline (myfile,line); 00085 std::cout << line << "\n"; 00086 myfile.close(); 00087 } 00088 std::cout << "\nUpdating the parameter list given the extra XML std::string:\n\n"<<line<<"\n"; 00089 Teuchos::updateParametersFromXmlString(line,¶mList); 00090 std::cout << "\nParameter list after ammending extra XML std::string:\n\n"; 00091 paramList.print(std::cout,2,true,true); 00092 } 00093 00094 std::cout << "\nWriting the final parameter list back to the XML file \""<<xmlOutFileName<<"\" ... \n"; 00095 Teuchos::writeParameterListToXmlFile(paramList,xmlOutFileName); 00096 00097 } 00098 TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cerr,success); 00099 00100 if(success) 00101 std::cout << "\nEnd Result: TEST PASSED" << std::endl; 00102 else 00103 std::cout << "\nEnd Result: TEST FAILED" << std::endl; 00104 00105 return ( success ? 0 : 1 ); 00106 00107 }
1.7.4