1#!/usr/bin/env perl
2# -*-Perl-*-
3##
4## @file    echoSBML.pl
5## @brief   Echos an SBML model.
6## @author  Akiya Jouraku (translated from libSBML C++ examples)
7## @author  Ben Bornstein
8## @author  Michael Hucka
9##
10##
11## <!--------------------------------------------------------------------------
12## This sample program is distributed under a different license than the rest
13## of libSBML.  This program uses the open-source MIT license, as follows:
14##
15## Copyright (c) 2013-2018 by the California Institute of Technology
16## (California, USA), the European Bioinformatics Institute (EMBL-EBI, UK)
17## and the University of Heidelberg (Germany), with support from the National
18## Institutes of Health (USA) under grant R01GM070923.  All rights reserved.
19##
20## Permission is hereby granted, free of charge, to any person obtaining a
21## copy of this software and associated documentation files (the "Software"),
22## to deal in the Software without restriction, including without limitation
23## the rights to use, copy, modify, merge, publish, distribute, sublicense,
24## and/or sell copies of the Software, and to permit persons to whom the
25## Software is furnished to do so, subject to the following conditions:
26##
27## The above copyright notice and this permission notice shall be included in
28## all copies or substantial portions of the Software.
29##
30## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
33## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
35## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
36## DEALINGS IN THE SOFTWARE.
37##
38## Neither the name of the California Institute of Technology (Caltech), nor
39## of the European Bioinformatics Institute (EMBL-EBI), nor of the University
40## of Heidelberg, nor the names of any contributors, may be used to endorse
41## or promote products derived from this software without specific prior
42## written permission.
43## ------------------------------------------------------------------------ -->
44
45use File::Basename;
46use LibSBML;
47no strict;
48
49if ($#ARGV != 1) {
50   print  "usage: echoSBML.pl input-filename output-filename\n";
51   exit 1;
52}
53
54$infile  = $ARGV[0];
55$outfile = $ARGV[1];
56
57unless (-e $infile) {
58  print("[Error] ", $infile, ": No such file.", "\n");
59  exit 1;
60}
61$reader  = new LibSBML::SBMLReader();
62$writer  = new LibSBML::SBMLWriter();
63$sbmldoc = $reader->readSBML($infile);
64
65if ($sbmldoc->getNumErrors() > 0) {
66  if ($sbmldoc->getError(0)->getErrorId() == $LibSBML::XMLFileUnreadable) {
67    # Handle case of unreadable file here.
68    $sbmldoc->printErrors();
69  }
70  elsif ($sbmldoc->getError(0)->getErrorId() == $LibSBML::XMLFileOperationError) {
71    # Handle case of other file error here.
72    $sbmldoc->printErrors();
73  }
74  else {
75    # Handle other error cases here.
76    $sbmldoc->printErrors();
77  }
78  exit 1;
79}
80$writer->writeSBML($sbmldoc, $outfile);
81print("[OK] Echoed ", $infile, " to ", $outfile, "\n");
82
83