1 /**
2  * \file    addModelHistory.cpp
3  * \brief   adds Model History to a model
4  * \author  Sarah Keating
5  *
6  * <!--------------------------------------------------------------------------
7  * This sample program is distributed under a different license than the rest
8  * of libSBML.  This program uses the open-source MIT license, as follows:
9  *
10  * Copyright (c) 2013-2018 by the California Institute of Technology
11  * (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
12  * and the University of Heidelberg (Germany), with support from the National
13  * Institutes of Health (USA) under grant R01GM070923.  All rights reserved.
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining a
16  * copy of this software and associated documentation files (the "Software"),
17  * to deal in the Software without restriction, including without limitation
18  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
19  * and/or sell copies of the Software, and to permit persons to whom the
20  * Software is furnished to do so, subject to the following conditions:
21  *
22  * The above copyright notice and this permission notice shall be included in
23  * all copies or substantial portions of the Software.
24  *
25  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
31  * DEALINGS IN THE SOFTWARE.
32  *
33  * Neither the name of the California Institute of Technology (Caltech), nor
34  * of the European Bioinformatics Institute (EMBL-EBI), nor of the University
35  * of Heidelberg, nor the names of any contributors, may be used to endorse
36  * or promote products derived from this software without specific prior
37  * written permission.
38  * ------------------------------------------------------------------------ -->
39  */
40 
41 #include <stdio.h>
42 
43 #include <sbml/SBMLTypes.h>
44 
45 #include <sbml/xml/XMLNode.h>
46 #include <sbml/annotation/ModelHistory.h>
47 
48 
printStatus(const char * message,int status)49 void printStatus(const char* message, int status)
50 {
51 	printf("%s", message);
52 	switch(status)
53 	{
54 	case LIBSBML_OPERATION_SUCCESS:
55     printf("succeeded");
56 		break;
57 	case LIBSBML_INVALID_OBJECT:
58     printf("invalid object");
59 		break;
60 	case LIBSBML_OPERATION_FAILED:
61     printf("operation failed");
62 		break;
63 	default:
64     printf("unknown");
65 		break;
66 	}
67   printf("\n");
68 }
69 
70 int
main(int argc,char * argv[])71 main (int argc, char *argv[])
72 {
73 
74   SBMLDocument_t* d;
75   Model_t* m;
76   unsigned int  errors;
77 
78   if (argc != 3)
79   {
80     printf("\n"
81       "  usage: addModelHistory <input-filename> <output-filename>\n"
82       "\n");
83     return 2;
84   }
85 
86   d      = readSBML(argv[1]);
87   errors = SBMLDocument_getNumErrors(d);
88 
89   if (errors > 0)
90   {
91     printf("Read Error(s):\n");
92     SBMLDocument_printErrors(d, stdout);
93     printf("Correct the above and re-run.\n");
94   }
95   else
96   {
97     int status;
98     Date_t* date, *date2;
99     ModelHistory_t* h = ModelHistory_create();
100     ModelCreator_t* c = ModelCreator_create();
101 
102     ModelCreator_setFamilyName(c, "Keating");
103     ModelCreator_setGivenName(c, "Sarah");
104     ModelCreator_setEmail(c, "sbml-team@caltech.edu");
105     ModelCreator_setOrganisation(c, "University of Hertfordshire");
106 
107 
108     status = ModelHistory_addCreator(h, c);
109 	  printStatus("Status for addCreator: ", status);
110 
111 
112     date = Date_createFromString("1999-11-13T06:54:32");
113     date2 = Date_createFromString("2007-11-30T06:54:00-02:00");
114 
115     status = ModelHistory_setCreatedDate(h, date);
116 	  printStatus("Set created date:      ", status);
117 
118     status = ModelHistory_setModifiedDate(h, date2);
119 	  printStatus("Set modified date:     ", status);
120 
121     m = SBMLDocument_getModel(d);
122     status =  Model_setModelHistory(m, h);
123 	  printStatus("Set model history:     ", status);
124 
125     writeSBML(d, argv[2]);
126 
127     Date_free(date);
128     Date_free(date2);
129     ModelCreator_free(c);
130     ModelHistory_free(h);
131   }
132 
133   SBMLDocument_free(d);
134   return errors;
135 }
136 
137