/home/coin/SVN-release/OS-2.3.2/OS/misc/misc.cpp

Go to the documentation of this file.
00001 /* $Id: misc.cpp 3675 2010-09-12 05:36:34Z kmartin $ */
00017 //#include <cppad/cppad.hpp> 
00018 #include "OSConfig.h"
00019 #include "OSCoinSolver.h"
00020 #include "OSIpoptSolver.h"
00021 #include "OSResult.h" 
00022 #include "OSiLReader.h"        
00023 #include "OSiLWriter.h"   
00024 #include "OSrLReader.h"          
00025 #include "OSrLWriter.h"      
00026 #include "OSInstance.h"  
00027 #include "OSFileUtil.h"   
00028 #include "OSDefaultSolver.h"     
00029 #include "OShL.h"     
00030 #include "OSErrorClass.h"
00031 #include "OSmps2osil.h"   
00032 #include "OSBase64.h"
00033 #include "OSCommonUtil.h"
00034 #include "OSErrorClass.h"
00035 #include "OSMathUtil.h"
00036 #include "CoinFinite.hpp"
00037 
00038 #include<iostream> 
00039 #include <ostream>
00040 #include <sstream>
00041 #include <streambuf>
00042 
00043 #include<stdio.h>
00044  
00045 using std::cout;   
00046 using std::endl;
00047 
00053 int main(int argC, char* argV[]){
00057         FileUtil *fileUtil = NULL; 
00058         fileUtil = new FileUtil();
00059         cout << "Start Building the Model" << endl;
00060         std::cout << "Hello World" << std::endl;
00061 
00062         std::string osilFileName =   "../../data/osilFiles/rosenbrockmod.osil";
00063         std::cout << "Try to read a sample file" << std::endl;
00064         std::cout << "The file is: " ;
00065         std::cout <<  osilFileName << std::endl;
00066         std::string osil = fileUtil->getFileAsString( osilFileName.c_str() );
00067         OSiLReader *osilreader = NULL;
00068         osilreader = new OSiLReader(); 
00069         OSInstance *osinstance;
00070         osinstance = osilreader->readOSiL( osil);       
00071         std::string theModel;
00072 
00073 
00074         #if 0
00075         //WRITE STDOUT  TO A FILE -- C LEVEL stuff
00076         //http://bytes.com/groups/cpp/133393-usage-rdbuf
00077         ostringstream solverOutput;
00078         FILE * pFile;
00079         FILE * pFile2;
00080         pFile2 = freopen("os.log", "w", stdout);
00081         //if (pFile==NULL) throw ErrorClass ("Error opening file for stdout");
00082         std::cout << "LINE 1 OUTPUT "  << std::endl;  //cout will get diverted
00083         printf("LINE 2 OUTPUT \n"); // printf will get diverted
00084         fclose( pFile2);
00085         pFile = fopen("os.log", "r");
00086         char c;
00087         while (!feof( stdout)) {
00088                 c = fgetc (stdout);
00089                 if(c !=-1) solverOutput << c;
00090       }
00091         fileUtil->writeFileFromString("kipp.txt", solverOutput.str() );
00092         #endif
00093         
00094         #if  1
00095         //WRITE COUT TO A STRING -- this C++ stuff -- it will NOT write stdout, e.g. printf()
00096         ostringstream solverOutput;
00097         std::streambuf* save_buffer = cout.rdbuf(solverOutput.rdbuf()); //turn off cout
00098         std::cout << "LINE 1 OUTPUT " << std::endl ;  //this should get diverted
00099         printf("LINE 2 OUTPUT \n") ; //this will not get diverted
00100         cout.rdbuf(save_buffer); // turn cout back on
00101         std::cout << "LINE 3 OUTPUT " << std::endl;
00102         // now the string
00103         std::cout << solverOutput.str() << std::endl;
00104         #endif  
00105         
00106         //DEMO -- how to empty the string buffer
00107         ostringstream outStr;
00108         outStr << "Hello";
00109         outStr << " World" ;
00110         outStr << std::endl;
00111         std::cout << outStr.str() << std::endl;
00112         outStr.str(""); // here is where we empty the buffer
00113         outStr << "New" << std::endl;
00114         std::cout << outStr.str() << std::endl;
00115         
00116 
00117         delete fileUtil;
00118         fileUtil = NULL;
00119         return 0;
00120 }// end main
00121 

Generated on Fri Jan 7 03:24:38 2011 by  doxygen 1.4.7