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 using System; 42 using System.Collections.Generic; 43 using System.IO; 44 using System.Text; 45 using libsbmlcs; 46 47 public class AddModelHistory 48 { printStatus(string message, long status)49 private static void printStatus(string message, long status) 50 { 51 string statusString; 52 switch (status) 53 { 54 case libsbml.LIBSBML_OPERATION_SUCCESS: 55 statusString = "succeeded"; 56 break; 57 case libsbml.LIBSBML_INVALID_OBJECT: 58 statusString = "invalid object"; 59 break; 60 case libsbml.LIBSBML_OPERATION_FAILED: 61 statusString = "operation failed"; 62 break; 63 default: 64 statusString = "unknown"; 65 break; 66 } 67 68 Console.Write(message + statusString + Environment.NewLine); 69 70 } 71 Main(string[] args)72 public static int Main(string[] args) 73 { 74 75 76 SBMLDocument d; 77 int errors; 78 79 if (args.Length != 2) 80 { 81 Console.Write(Environment.NewLine 82 + " usage: addModelHistory <input-filename> <output-filename>" + Environment.NewLine 83 + Environment.NewLine); 84 return 2; 85 } 86 87 88 d = libsbml.readSBML(args[0]); 89 errors = (int)d.getNumErrors(); 90 91 if (errors > 0) 92 { 93 Console.Write("Read Error(s):" + Environment.NewLine); 94 d.printErrors(); 95 96 Console.Write("Correct the above and re-run." + Environment.NewLine); 97 } 98 else 99 { 100 ModelHistory h = new ModelHistory(); 101 102 ModelCreator c = new ModelCreator(); 103 c.setFamilyName("Keating"); 104 c.setGivenName("Sarah"); 105 c.setEmail("sbml-team@caltech.edu"); 106 c.setOrganization("University of Hertfordshire"); 107 108 long status = h.addCreator(c); 109 printStatus("Status for addCreator: ", status); 110 111 112 Date date = new Date("1999-11-13T06:54:32"); 113 Date date2 = new Date("2007-11-30T06:54:00-02:00"); 114 115 status = h.setCreatedDate(date); 116 printStatus("Set created date: ", status); 117 118 status = h.setModifiedDate(date2); 119 printStatus("Set modified date: ", status); 120 121 status = d.getModel().setModelHistory(h); 122 printStatus("Set model history: ", status); 123 124 125 libsbml.writeSBML(d, args[1]); 126 } 127 128 return errors; 129 } 130 131 } 132