libSBML C API  5.18.0
printUnits.c

A command-line program that prints information about the units of measurement used in a given SBML file.

/**
* @file printUnits.cpp
* @brief Prints some unit information about the model
* @author Sarah Keating
* @author Michael Hucka
*
* <!--------------------------------------------------------------------------
* This sample program is distributed under a different license than the rest
* of libSBML. This program uses the open-source MIT license, as follows:
*
* Copyright (c) 2013-2018 by the California Institute of Technology
* (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
* and the University of Heidelberg (Germany), with support from the National
* Institutes of Health (USA) under grant R01GM070923. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* Neither the name of the California Institute of Technology (Caltech), nor
* of the European Bioinformatics Institute (EMBL-EBI), nor of the University
* of Heidelberg, nor the names of any contributors, may be used to endorse
* or promote products derived from this software without specific prior
* written permission.
* ------------------------------------------------------------------------ -->
*/
#include <stdio.h>
#include <sbml/SBMLTypes.h>
#include <sbml/units/UnitFormulaFormatter.h>
#include <sbml/units/FormulaUnitsData.h>
int
main (int argc, char *argv[])
{
unsigned int i,j;
char* filename;
SBMLDocument_t* document;
Model_t* model;
if (argc != 2)
{
printf("\nUsage: printUnits filename\n");
return 1;
}
filename = argv[1];
document = readSBML(filename);
if (SBMLDocument_getNumErrors(document) > 0)
{
fprintf(stderr, "Encountered the following SBML errors:\n");
SBMLDocument_printErrors(document, stdout);
return 1;
}
model = SBMLDocument_getModel(document);
if (model == NULL)
{
printf("No model present.\n");
return 1;
}
for (i = 0; i < Model_getNumSpecies(model); i++)
{
Species_t* s = Model_getSpecies(model, i);
printf("Species %d: %s\n"
, i
);
}
for (i = 0; i < Model_getNumCompartments(model); i++)
{
printf("Compartment %d: %s\n"
, i
);
}
for (i = 0; i < Model_getNumParameters(model); i++)
{
printf("Parameter %d: %s\n"
, i
);
}
for (i = 0; i < Model_getNumInitialAssignments(model); i++)
{
printf("InitialAssignment %d: %s"
, i
);
printf(" undeclared units: %s",
(InitialAssignment_containsUndeclaredUnits(ia) ? "yes\n" : "no\n"));
}
for (i = 0; i < Model_getNumEvents(model); i++)
{
Event_t *e = Model_getEvent(model, i);
printf("Event %d: \n", i);
{
printf( "Delay: %s\n",
printf( " undeclared units: %s",
(Delay_containsUndeclaredUnits(Event_getDelay(e)) ? "yes\n" : "no\n"));
}
for (j = 0; j < Event_getNumEventAssignments(e); j++)
{
printf( "Delay: %s\n",
printf( " undeclared units: %s",
(EventAssignment_containsUndeclaredUnits(ea) ? "yes\n" : "no\n"));
}
}
for (i = 0; i < Model_getNumReactions(model); i++)
{
Reaction_t *r = Model_getReaction(model, i);
printf("Reaction %d: \n", i);
{
printf( "Kinetic Law: %s\n",
printf( " undeclared units: %s",
(KineticLaw_containsUndeclaredUnits(kl) ? "yes\n" : "no\n"));
}
for (j = 0; j < Reaction_getNumReactants(r); j++)
{
{
printf( "Reactant stoichiometryMath %d: %s\n",
j,
printf( " undeclared units: %s",
(StoichiometryMath_containsUndeclaredUnits(sm) ? "yes\n" : "no\n"));
}
}
for (j = 0; j < Reaction_getNumProducts(r); j++)
{
{
printf( "Product stoichiometryMath %d: %s\n",
j,
printf( " undeclared units: %s",
(StoichiometryMath_containsUndeclaredUnits(sm) ? "yes\n" : "no\n"));
}
}
}
for (i = 0; i < Model_getNumRules(model); i++)
{
Rule_t *r = Model_getRule(model, i);
printf( "Rule %d: %s\n",
j,
printf( " undeclared units: %s",
(Rule_containsUndeclaredUnits(r) ? "yes\n" : "no\n"));
}
SBMLDocument_free(document);
return 0;
}