1#!/usr/bin/env perl
2# -*-Perl-*-
3##
4## \file    addModelHistory.pl
5## \brief   adds Model History to a model
6## \author  Sarah Keating
7##
8## <!--------------------------------------------------------------------------
9## This sample program is distributed under a different license than the rest
10## of libSBML.  This program uses the open-source MIT license, as follows:
11##
12## Copyright (c) 2013-2018 by the California Institute of Technology
13## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
14## and the University of Heidelberg (Germany), with support from the National
15## Institutes of Health (USA) under grant R01GM070923.  All rights reserved.
16##
17## Permission is hereby granted, free of charge, to any person obtaining a
18## copy of this software and associated documentation files (the "Software"),
19## to deal in the Software without restriction, including without limitation
20## the rights to use, copy, modify, merge, publish, distribute, sublicense,
21## and/or sell copies of the Software, and to permit persons to whom the
22## Software is furnished to do so, subject to the following conditions:
23##
24## The above copyright notice and this permission notice shall be included in
25## all copies or substantial portions of the Software.
26##
27## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
33## DEALINGS IN THE SOFTWARE.
34##
35## Neither the name of the California Institute of Technology (Caltech), nor
36## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
37## of Heidelberg, nor the names of any contributors, may be used to endorse
38## or promote products derived from this software without specific prior
39## written permission.
40## ------------------------------------------------------------------------ -->
41
42
43use LibSBML;
44no strict;
45
46sub printStatus {
47  $message = $_[0];
48  $status = $_[1];
49  $statusString = "";
50  if (status == $LibSBML::LIBSBML_OPERATION_SUCCESS) {
51    $statusString = "succeeded";
52  }
53  elsif (status == $LibSBML::LIBSBML_INVALID_OBJECT) {
54    $statusString = "invalid object";
55  }
56  elsif (status == $LibSBML::LIBSBML_OPERATION_FAILED) {
57    $statusString = "operation failed";
58  }
59  else {
60    $statusString = "unknown";
61  }
62  print ($message, $statusString, "\n");
63}
64
65
66if ($#ARGV  != 1) {
67  print "usage: addModelHistory <input-filename> <output-filename>\n";
68  print "       Adds a model history to the model\n";
69  exit 2;
70}
71
72$d = LibSBML::readSBML($ARGV[0]);
73$errors = $d->getNumErrors();
74
75if (errors > 0) {
76    print("Read Error(s):", "\n");
77    $d->printErrors();
78    print("Correct the above and re-run.", "\n");
79	exit $errors;
80}
81
82$h = new LibSBML::ModelHistory();
83
84$c = new LibSBML::ModelCreator();
85$c->setFamilyName("Keating");
86$c->setGivenName("Sarah");
87$c->setEmail("sbml-team@caltech.edu");
88$c->setOrganization("University of Hertfordshire");
89
90$status = $h->addCreator($c);
91printStatus("Status for addCreator: ", $status);
92
93
94$date = new LibSBML::Date("1999-11-13T06:54:32");
95$date2 = new LibSBML::Date("2007-11-30T06:54:00-02:00");
96
97$status = $h->setCreatedDate($date);
98printStatus("Set created date:      ", $status);
99
100$status = $h->setModifiedDate($date2);
101printStatus("Set modified date:     ", $status);
102
103$status = $d->getModel()->setModelHistory($h);
104printStatus("Set model history:     ", $status);
105
106
107LibSBML::writeSBML($d, $ARGV[1]);
108
109exit $errors;
110
111