Exemplo n.º 1
0
/** C.0: Loads, validates and parses an SBML file,
    also converts SBML level 1 to level 2 files,
    return NULL if errors were encountered during libSBML
    validation and consistency check, stores libSBML warngings
*/
SBMLDocument_t *
parseModel(char *file, int printMessage, int validate, char *schemaPath,
	   char *schema11FileName,
	   char *schema12FileName,
	   char *schema21FileName)
{
    unsigned int i, errors ;
    SBMLDocument_t *d;
    SBMLDocument_t *d2;
    SBMLReader_t *sr;

    if ( validate ) {
        if (  printMessage ) {
            fprintf(stderr, "Validating SBML.\n");
            fprintf(stderr, "This can take a while for SBML level 2.\n");
        }
        sr = newSBMLReader(schemaPath,
			   schema11FileName,
			   schema12FileName,
			   schema21FileName);
    }
    else {
        sr = SBMLReader_create();
    }

    d = SBMLReader_readSBML(sr, file);
    SBMLReader_free(sr);
    
    errors = 0;
    if ( validate ) {
      errors = SBMLDocument_getNumFatals(d) + SBMLDocument_getNumErrors(d);
    }
    
    if (SBMLDocument_getNumFatals(d) + SBMLDocument_getNumErrors(d) == 0)
        SBMLDocument_checkConsistency(d);
        /* AMF 9th Dec 2005 added back because inconsistent models can cause the
           solver to crash despite the consistancy check causing memory leaks - talk to Ben B! */

    /* check for warnings and errors */
    for (i =0 ; i != SBMLDocument_getNumWarnings(d); i++)
        storeSBMLError(WARNING_ERROR_TYPE, SBMLDocument_getWarning(d, i)); 

    for (i =0 ; i != SBMLDocument_getNumErrors(d); i++)
        storeSBMLError(ERROR_ERROR_TYPE, SBMLDocument_getError(d, i)); 

    for (i =0 ; i != SBMLDocument_getNumFatals(d); i++)
        storeSBMLError(FATAL_ERROR_TYPE, SBMLDocument_getFatal(d, i)); 

    RETURN_ON_ERRORS_WITH(NULL);
    
    /* convert level 1 models to level 2 */
    if ( SBMLDocument_getLevel(d) == 1 ) {      
        d2 = convertModel(d);
        SBMLDocument_free(d);
        if ( printMessage )
            fprintf(stderr, "SBML converted from level 1 to level 2.\n"); 
        return (d2);
    }
    return (d);
}
Exemplo n.º 2
0
int
main (int argc, char *argv[])
{
  const char *filename;

#ifdef __BORLANDC__
  unsigned long start, stop;
#else
  unsigned long long start, stop;
#endif
  unsigned long      size;
  unsigned int       errors = 0;

  SBMLDocument_t *d;


  if (argc != 2)
  {
    printf("Usage: validateSBML filename\n");
    return 2;
  }

  filename = argv[1];

  start = getCurrentMillis();
  d     = readSBML(filename);
  stop  = getCurrentMillis();

  errors  = SBMLDocument_getNumErrors(d);
  errors += SBMLDocument_checkConsistency(d);

  size = getFileSize(filename);

  printf( "\n" );
  printf( "        filename: %s\n" , filename     );
  printf( "       file size: %lu\n", size         );
  printf( "  read time (ms): %llu\n", stop - start );
  printf( "        error(s): %u\n" , errors       );

  if (errors > 0) SBMLDocument_printErrors(d, stdout);
  printf("\n");

  SBMLDocument_free(d);
  return errors;
}