functionalized version 2, implemented version 1 using functions in version 2
[PsN.git] / bin / update_inits
bloba15a16c93df1a710ad3adbbbb6b6fcf5e23f758e
1 #!/usr/local/bin/perl
3 # Only for Development
4 use FindBin qw($Bin);
5 use lib "$Bin/../lib";
7 # Don't edit the line below, it must look exactly like this.
8 # Everything above this line will be replaced #
10 use PsN;
11 use model;
12 use output;
13 use Getopt::Long;
14 use File::Copy qw/cp mv/;
16 my %options;
18 my %optional_options = ( "output_model:s" => undef );
20 my $res = GetOptions( \%options,
21 @common_options::get_opt_strings,
22 keys(%optional_options) );
24 exit unless $res;
26 unless( $ARGV[0] ){
27 die "You must at least enter a model file name\n";
31 my $model = model -> new ( filename => $ARGV[0],
32 ignore_missing_output_files => 1 );
34 unless( $model ){
35 die "No such file: $ARGV[0]\n";
38 my $model_copy;
40 if( $options{'output_model'} ){
41 $model_copy = $model -> copy( filename => $options{'output_model'} );
44 my $output;
46 if( $ARGV[1] ){
48 $output = output -> new( filename => $ARGV[1] );
50 unless( $output ){
51 die "No such file: $ARGV[1]\n";
55 } elsif( defined $model -> outputs and -e $model -> outputs -> [0] -> filename ){
57 $output = $model -> outputs -> [0];
59 } else {
61 die "No outputfile to update from\n";
66 if( defined $model_copy ){
68 $model_copy -> update_inits( from_output => $output );
69 $model_copy -> _write;
71 } else {
73 cp( $ARGV[0], $ARGV[0].'.org' );
75 $model -> update_inits( from_output => $output );
76 $model -> _write;