XmlToParameterList.cpp

Go to the documentation of this file.
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 int main( int argc, char* argv[] )
00037 {
00038   Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00039 
00040   std::cout << std::endl << Teuchos::Teuchos_Version() << std::endl;
00041 
00042   bool success = true;
00043 
00044   try {
00045 
00046     std::string    xmlInFileName = "";
00047     std::string    extraXmlStr = "";
00048     std::string    xmlOutFileName = "paramList.out";
00049 
00050     Teuchos::CommandLineProcessor  clp(false); // Don't throw exceptions
00051     clp.setOption("xml-in-file",&xmlInFileName,"The XML file to read into a parameter list");
00052     clp.setOption("extra-xml",&extraXmlStr,"Extra XML that will modify the initial XML read in");
00053     clp.setOption("xml-out-file",&xmlOutFileName,"The XML file to write the final parameter list to");
00054     clp.setDocString(
00055       "This example program shows how to read in a parameter list from an"
00056       " XML file (given by --xml-in-file=xmlInFileName) and then modify it"
00057       " given some XML specified on the command-line (given by --extra-xml=extrXmlStr)."
00058       " The final parameter list is then written back to an XML file."
00059       " (given by --xml-out-file=xmlOutFileName)."
00060       );
00061     Teuchos::CommandLineProcessor::EParseCommandLineReturn
00062       parse_return = clp.parse(argc,argv);
00063     if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
00064       std::cout << "\nEnd Result: TEST FAILED" << std::endl;
00065       return parse_return;
00066     }
00067 
00068     Teuchos::ParameterList paramList;
00069 
00070     if(xmlInFileName.length()) {
00071       std::cout << "\nReading a parameter list from the XML file \""<<xmlInFileName<<"\" ...\n";
00072       Teuchos::updateParametersFromXmlFile(xmlInFileName,&paramList);
00073       std::cout << "\nParameter list read from the XML file \""<<xmlInFileName<<"\":\n\n";
00074       paramList.print(std::cout,2,true,true);
00075     }
00076     
00077     if(extraXmlStr.length()) {
00078       std::cout << "\nUpdating the parameter list given the extra XML std::string:\n\n"<<extraXmlStr<<"\n";
00079       Teuchos::updateParametersFromXmlString(extraXmlStr,&paramList);
00080       std::cout << "\nParameter list after ammending extra XML std::string:\n\n";
00081       paramList.print(std::cout,2,true,true);
00082     }
00083 
00084     std::cout << "\nWriting the final parameter list back to the XML file \""<<xmlOutFileName<<"\" ... \n";
00085     Teuchos::writeParameterListToXmlFile(paramList,xmlOutFileName);
00086 
00087   }
00088   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cerr,success);
00089 
00090   if(success)
00091     std::cout << "\nEnd Result: TEST PASSED" << std::endl;
00092   else
00093     std::cout << "\nEnd Result: TEST FAILED" << std::endl;
00094 
00095   return ( success ? 0 : 1 );
00096 
00097 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:14:01 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1