Validates one or more SBML files.
#include <iostream>
#include <sstream>
using namespace std;
LIBSBML_CPP_NAMESPACE_USE
bool validateSBML(const string& filename, bool enableUnitCheck=true);
const string usage = "Usage: validateSBML [-u] filename [...]\n"
" -u : disable unit consistency check";
#ifdef WIN32
#include <conio.h>
{
public:
{
if (kbhit())
}
};
#endif
int
main (int argc, char* argv[])
{
bool enableUnitCheck = true;
if (argc < 2)
{
cout << usage << endl;
return 1;
}
else if (argc == 2)
{
if ( string("-u") == string(argv[1]) )
{
cout << usage << endl;
return 1;
}
}
# ifdef WIN32
ProcessingCB cb;
cout << "(Registered callback, press any key to interrupt validation)" << endl;
#endif
int argIndex = 1;
if ( string("-u") == string(argv[1]) )
{
enableUnitCheck = false;
++argIndex;
}
int numInvalidFiles = 0;
for (int i=argIndex; i < argc; i++)
{
if (!validateSBML(argv[i], enableUnitCheck))
++numInvalidFiles;
cout << "---------------------------------------------------------------------------\n";
}
int numFiles = (enableUnitCheck) ? argc - 1 : argc - 2;
cout << "Validated " << numFiles << " files, " << (numFiles - numInvalidFiles) << " valid files, "
<< numInvalidFiles << " invalid files" << endl;
if (!enableUnitCheck)
cout << "(Unit consistency checks skipped)" << endl;
return numInvalidFiles;
}
bool validateSBML(const string& filename, bool enableUnitCheck)
{
#ifdef __BORLANDC__
unsigned long start, stop;
#else
unsigned long long start, stop;
#endif
start = getCurrentMillis();
stop = getCurrentMillis();
double timeRead = (double)(stop - start);
bool seriousErrors = false;
unsigned int numReadErrors = 0;
unsigned int numReadWarnings = 0;
string errMsgRead = "";
if (errors > 0)
{
for (unsigned int i = 0; i < errors; i++)
{
{
seriousErrors = true;
++numReadErrors;
break;
}
else
++numReadWarnings;
}
ostringstream oss;
errMsgRead = oss.str();
}
unsigned int numCCErrors = 0;
unsigned int numCCWarnings = 0;
string errMsgCC = "";
bool skipCC = false;
double timeCC = 0.0;
bool isValid = true;
if (seriousErrors)
{
skipCC = true;
isValid = false;
errMsgRead += "Further consistency checking and validation aborted.";
}
else
{
unsigned int failures = 0;
start = getCurrentMillis();
stop = getCurrentMillis();
timeCC = (double)(stop - start);
if (failures > 0)
{
for (unsigned int i = 0; i < failures; i++)
{
{
++numCCErrors;
isValid = false;
}
else
++numCCWarnings;
}
ostringstream oss;
errMsgCC = oss.str();
}
}
cout << " filename : " << filename << endl;
cout << " file size (byte) : " << getFileSize(filename.c_str()) << endl;
cout << " read time (ms) : " << timeRead << endl;
if (!skipCC)
{
cout << " c-check time (ms) : " << timeCC << endl;
}
else
{
cout << " c-check time (ms) : skipped" << endl;
}
cout << " validation error(s) : " << numReadErrors + numCCErrors << endl;
if (!skipCC)
cout << " (consistency error(s)): " << numCCErrors << endl;
else
cout << " (consistency error(s)): skipped" << endl;
cout << " validation warning(s) : " << numReadWarnings + numCCWarnings << endl;
if (!skipCC)
cout << " (consistency warning(s)): " << numCCWarnings << endl;
else
cout << " (consistency warning(s)): skipped" << endl;
if ( !errMsgRead.empty() || !errMsgCC.empty() )
{
cout << "\n===== validation error/warning messages =====\n";
if (!errMsgRead.empty())
cout << errMsgRead << endl;
if (!errMsgCC.empty())
{
cout << "\n*** consistency check ***\n";
cout << errMsgCC << endl;
}
}
delete document;
return (isValid) ? true: false;
}
@ LIBSBML_CAT_UNITS_CONSISTENCY
Definition: SBMLError.h:975
Include all SBML types in a single header file.
Definition: CallbackRegistry.h:16
static void addCallback(Callback *cb)
Registers a new processing callback that will be called with a newly instantiated ModelDefinition obj...
Definition: CallbackRegistry.cpp:38
Definition: SBMLDocument.h:349
unsigned int getNumErrors() const
Returns the number of errors or warnings encountered during parsing, consistency checking,...
Definition: SBMLDocument.cpp:1163
unsigned int checkConsistency()
Performs consistency checking and validation on this SBML document.
Definition: SBMLDocument.cpp:699
const SBMLError * getError(unsigned int n) const
Returns the nth error or warning encountered during parsing, consistency checking,...
Definition: SBMLDocument.cpp:1146
void printErrors(std::ostream &stream=std::cerr) const
Prints all the errors or warnings encountered trying to parse, check, or translate this SBML document...
Definition: SBMLDocument.cpp:1186
void setConsistencyChecks(SBMLErrorCategory_t category, bool apply)
Controls the consistency checks that are performed when SBMLDocument::checkConsistency() is called.
Definition: SBMLDocument.cpp:677
Definition: SBMLReader.h:343
SBMLDocument * readSBML(const std::string &filename)
Reads an SBML document from the given file.
Definition: SBMLReader.cpp:112
bool isError() const
Predicate returning true or false depending on whether this error is a significant error.
Definition: XMLError.cpp:661
bool isFatal() const
Predicate returning true or false depending on whether this error is a fatal run-time error.
Definition: XMLError.cpp:671
@ LIBSBML_OPERATION_FAILED
Definition: operationReturnValues.h:83
@ LIBSBML_OPERATION_SUCCESS
Definition: operationReturnValues.h:61