copasi/sedml/CSEDMLExporter.cpp
/**
 * Export the model and Task to SEDML.
 * The SEDML document is written to the file given by SEDMLFilename and reference SBML model is written to SBMLFilename .
 * If the export fails, false is returned.
 */
Export the model and Task to SEDML.
The SEDML document is written to the file given by SEDMLFilename and reference SBML model is written to SBMLFilename .
If the export fails, false is returned.
Export the model and Task to SEDML . The SEDML document is written to the file given by SEDMLFilename and reference SBML model is written to SBMLFilename . If the export fails false is returned .
bool CSEDMLExporter::exportModelAndTasks(CDataModel& dataModel,
    const std::string& filename,
    const std::string& sbmlDocument,
    unsigned int sedmlLevel,
    unsigned int sedmlVersion,
    bool overwrite)
{
  bool success = true;
  std::string sedmlModelSource = createUniqueModelFileName(CDirEntry::dirName(filename), "model", ".xml");
  std::string sbmlFileName;
  sbmlFileName = CDirEntry::dirName(filename) + CDirEntry::Separator + sedmlModelSource;
  std::ifstream sbmlFile(CLocaleString::fromUtf8(sbmlFileName).c_str(), std::ios::in);
  if (sbmlFile && !overwrite)
    {
      CCopasiMessage(CCopasiMessage::ERROR, MCDirEntry + 1, sbmlFileName.c_str());
      return false;
    }
  std::ofstream sbmlOutFile(CLocaleString::fromUtf8(sbmlFileName).c_str(), std::ios::out | std::ios::trunc);
  sbmlOutFile << sbmlDocument;
  sbmlOutFile.close();
  std::string str = this->exportModelAndTasksToString(dataModel, sedmlModelSource, sedmlLevel, sedmlVersion);
  if (!str.empty())
    {
      std::ifstream testInfile(CLocaleString::fromUtf8(filename).c_str(), std::ios::in);
      if (testInfile && !overwrite)
        {
          CCopasiMessage(CCopasiMessage::ERROR, MCDirEntry + 1, filename.c_str());
          return false;
        }
      std::ofstream outfile(CLocaleString::fromUtf8(filename).c_str(), std::ios::out | std::ios::trunc);
      outfile << str;
      outfile.close();
    }
  else
    {
      success = false;
    }
  return success;
}
bool CSEDMLExporter :: exportModelAndTasks ( CDataModel & dataModel , const std :: string & filename , const std :: string & sbmlDocument , unsigned int sedmlLevel , unsigned int sedmlVersion , bool overwrite ) { bool success = true ; std :: string sedmlModelSource = createUniqueModelFileName ( CDirEntry :: dirName ( filename ) , " " , " " ) ; std :: string sbmlFileName ; sbmlFileName = CDirEntry :: dirName ( filename ) + CDirEntry :: Separator + sedmlModelSource ; std :: ifstream sbmlFile ( CLocaleString :: fromUtf8 ( sbmlFileName ) . c_str ( ) , std :: ios :: in ) ; if ( sbmlFile && ! overwrite ) { CCopasiMessage ( CCopasiMessage :: ERROR , MCDirEntry + 1 , sbmlFileName . c_str ( ) ) ; return false ; } std :: ofstream sbmlOutFile ( CLocaleString :: fromUtf8 ( sbmlFileName ) . c_str ( ) , std :: ios :: out | std :: ios :: trunc ) ; sbmlOutFile << sbmlDocument ; sbmlOutFile . close ( ) ; std :: string str = this -> exportModelAndTasksToString ( dataModel , sedmlModelSource , sedmlLevel , sedmlVersion ) ; if ( ! str . empty ( ) ) { std :: ifstream testInfile ( CLocaleString :: fromUtf8 ( filename ) . c_str ( ) , std :: ios :: in ) ; if ( testInfile && ! overwrite ) { CCopasiMessage ( CCopasiMessage :: ERROR , MCDirEntry + 1 , filename . c_str ( ) ) ; return false ; } std :: ofstream outfile ( CLocaleString :: fromUtf8 ( filename ) . c_str ( ) , std :: ios :: out | std :: ios :: trunc ) ; outfile << str ; outfile . close ( ) ; } else { success = false ; } return success ; }
Export the model and Task to SEDML.
Export the model and Task to SEDML .
/* create a string that represents the SBMLDocument */ // std::string sedmlModelSource = "model1.xml"; //always name of the SBML model to reference in SEDML document // create a unique name for all exported models, rather than to overwrite existing ones! // create a CCopasiMessage with the appropriate error /* write the sbml model document to a file */ //std::cout<<str<<std::endl; //only for debuging /* check if the file already exists.
       If yes, write if overwrite is true,
       else create an appropriate  CCopasiMessage. */ // create a CCopasiMessage with the appropriate error /* write the document to a file */ /* if no SBMLDocument could be created return false */