Validates one or more SBML files.
#include <iostream>
#include <sstream>
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>
class ProcessingCB : public Callback
{
public:
{
if (kbhit())
}
};
#endif // WIN32
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;
CallbackRegistry::addCallback(&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;
}