IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42444 for trunk/tools


Ignore:
Timestamp:
Apr 6, 2023, 6:00:06 PM (3 years ago)
Author:
eugene
Message:

big re-work to allow repeat, iterated fixes

Location:
trunk/tools/eam/rawfix.20230221/src
Files:
12 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/eam/rawfix.20230221/src/check_chip_locations.pl

    r42441 r42444  
    1313use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1414
    15 # USAGE: check_chip_locations.pl --dateobs (night) --chiplist (file) --stage (v0,v1,etc)
    16 # USAGE: check_chip_locations.pl --dateobs 2010/05/01 --chiplist gpc1.chips.txt --stage v0
     15# USAGE: check_chip_locations.pl --dateobs (night) --chiplist (file) --stage (0,1,etc)
     16# USAGE: check_chip_locations.pl --dateobs 2010/05/01 --chiplist gpc1.chips.txt --stage 0
    1717
    1818my ($fulldate, $dateword, $chiplist, $stage, $topdir) = &parse_cmdopts;
     
    3131# output files:
    3232# instance lists by host: YYYYMMDD/HOSTNAME.inst.STAGE.txt
    33 # chip states by chip: YYYYMMDD/CHIPNAME.uris.txt
     33# chip states by chip: YYYYMMDD/CHIPNAME.uris.STAGE.txt
    3434
    3535foreach my $chip_id (@chip_ids) {
    3636
    3737    my $outfh;
    38     open ($outfh, ">$topdir/$dateword/$chip_id.uris.txt");
     38    open ($outfh, ">$topdir/$dateword/$chip_id.uris.$stage.txt");
    3939
    4040    # get the list of chip neb paths for one chip
     
    182182    my $sql_chip_instances = "SELECT uri, host, available, xattr, cab_id from instance join storage_object using (so_id) join volume using (vol_id) where ext_id = '$ext_id'";
    183183    my $rowref   = $neb_dbh->selectall_arrayref( $sql_chip_instances );
    184  
     184   
    185185    return ($rowref, $ext_id);
    186186}
     
    338338    pod2usage( -msg => "Specify the top-level output directory with --topdir", -exitval => 2) unless defined $topdir;
    339339   
     340    # check that stage is an integer
     341    unless (&is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     342    unless ($stage >= 0) { die "stage must be a non-negative integer\n"; }
     343
    340344    # check the date format (require YYYY/MM/DD and use that from 00:00:00 to 23:59:59 or take start and end?)
    341345
     
    405409}
    406410
    407    
     411sub is_integer {
     412    defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
     413}
     414
    408415# example of using the return value of arrayref:
    409416
  • trunk/tools/eam/rawfix.20230221/src/check_md5s_dateobs.pl

    r42441 r42444  
    2020
    2121my $Nfail = 0;
     22my %failchips;
     23my %goodchips;
    2224
    2325foreach my $instfile (@instlist) {
     
    8082
    8183        if ($md5tru ne $md5obs) {
    82             print STDOUT "FAIL: $inst $state $md5tru $md5obs\n";
    83             $Nfail ++;
     84            &save_failure ($inst);
     85            if ($DEBUG > 2) { print STDOUT "FAIL: $inst $state $md5tru $md5obs\n"; }
    8486        } else {
    85             if ($DEBUG > 2) {
    86                 print STDOUT "$inst $state $md5tru = $md5obs\n";
    87             }
     87            &save_goodchip ($inst);
     88            if ($DEBUG > 2) { print STDOUT "$inst $state $md5tru = $md5obs\n"; }
    8889        }
    8990    }
    9091}
    9192
     93# save both good and fail chip lists
     94open (OUTFILE, ">$topdir/$dateword/goodchips.$stage.txt");
     95my @goodchipURIs = keys %goodchips;
     96foreach my $uri (@goodchipURIs) {
     97    print OUTFILE "$uri\n";
     98}
     99close (OUTFILE);
     100
     101open (OUTFILE, ">$topdir/$dateword/failchips.$stage.txt");
     102my @failchipURIs = keys %failchips;
     103foreach my $uri (@failchipURIs) {
     104    print OUTFILE "$uri\n";
     105}
     106close (OUTFILE);
     107
     108
     109## we only report an error if we could not find the md5sum files or if the inst and md5s
     110## files are inconsistent.  In that case, we cannot check the md5s for all instances
     111## if the md5sum is wrong for a chip, mark that chip and save it.  It will be skipped in fix_chip_locations
    92112if ($Nfail) {
    93113    print STDOUT "ERROR: $Nfail errors\n";
     
    105125    pod2usage( -msg => "Cannot determine target date, use --dateobs YYYY/MM/DD", -exitval => 2) unless defined $dateobs;
    106126    pod2usage( -msg => "Specify the top-level output directory with --topdir", -exitval => 2) unless defined $topdir;
    107     pod2usage( -msg => "Define the stage (v0, v1, etc) with --stage", -exitval => 2) unless defined $stage;
     127    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
     128   
     129    # check that stage is an integer
     130    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     131    unless ($stage >= 0) { die "stage must be a non-negative integer\n"; }
    108132   
    109133    # check the date format (require YYYY/MM/DD and use that from 00:00:00 to 23:59:59 or take start and end?)
     
    126150    return $status;
    127151}
     152
     153sub neb_reverse {
     154
     155    my (@neb_path) = split /\//, $_[0];
     156    my $neb_key = $neb_path[-1];
     157
     158    # Remove ins_id
     159    $neb_key =~ s/^\d+\.//;
     160
     161    # Convert colons to slashes.
     162    $neb_key =~ s%:%/%g;
     163
     164    # strip ending .fz added for compressed .fits images
     165    $neb_key =~ s%.fz$%%;
     166    return $neb_key;
     167}
     168
     169sub save_failure {
     170    my $nebfile = &neb_reverse($_[0]);
     171    if (defined $failchips{$nebfile}) {
     172        $failchips{$nebfile} ++;
     173    } else {
     174        $failchips{$nebfile} = 1;
     175    }
     176    return;
     177}
     178
     179sub save_goodchip {
     180    my $nebfile = &neb_reverse($_[0]);
     181    if (defined $goodchips{$nebfile}) {
     182        $goodchips{$nebfile} ++;
     183    } else {
     184        $goodchips{$nebfile} = 1;
     185    }
     186    return;
     187}
     188
     189sub is_integer {
     190   defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
     191}
  • trunk/tools/eam/rawfix.20230221/src/check_night_status.pl

    r42415 r42444  
    1111use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1212
    13 # USAGE: check_night_status.pl --dateobs (night) --chiplist (file)
     13# USAGE: check_night_status.pl --dateobs (night) --chiplist (file) --stage (0,1,etc)
    1414
    1515# we need to select targets for ITC copies of files currently only at ATRC:
     
    1717# for each chip, target a single host?
    1818
    19 my ($fulldate, $dateword, $chiplist) = &parse_cmdopts;
     19my ($fulldate, $dateword, $chiplist, $stage) = &parse_cmdopts;
    2020
    2121# read the list of chip_ids:
     
    3636foreach my $chip_id (@chip_ids) {
    3737
    38     my $urifile = "$dateword/$chip_id.uris.txt";
     38    my $urifile = "$dateword/$chip_id.uris.$stage.txt";
    3939    open (FILE, "$urifile");
    4040    my @lines = <FILE>;
     
    110110sub parse_cmdopts {
    111111
    112     my ($dateobs, $chiplist);
    113     GetOptions( 'dateobs=s' => \$dateobs, 'chiplist=s' => \$chiplist) || pod2usage(2);
     112    my ($dateobs, $chiplist, $stage);
     113    GetOptions( 'dateobs=s' => \$dateobs, 'chiplist=s' => \$chiplist, 'stage=s' => \$stage) || pod2usage(2);
    114114   
    115115    pod2usage( -msg => "Cannot determine target date, use --dateobs YYYY/MM/DD", -exitval => 2) unless defined $dateobs;
    116116    pod2usage( -msg => "Provide a list of chips with --chiplist", -exitval => 2) unless defined $chiplist;
     117    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
     118   
     119    # check that stage is an integer
     120    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     121    unless ($stage >= 0) { die "stage must be a non-negative integer\n"; }
     122
    117123   
    118124    # check the date format (require YYYY/MM/DD and use that from 00:00:00 to 23:59:59 or take start and end?)
     
    127133    my $dateword = sprintf ("%4d%02d%02d", $date_year, $date_month, $date_day);
    128134
    129     return ($fulldate, $dateword, $chiplist);
     135    return ($fulldate, $dateword, $chiplist, $stage);
    130136}
    131137
     138
     139sub is_integer {
     140   defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
     141}
     142   
  • trunk/tools/eam/rawfix.20230221/src/fix_chip_locations.pl

    r42441 r42444  
    1212use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1313
    14 # USAGE: fix_chip_locations.pl --dateobs (night) --chiplist (file) --stage (v0,v1,etc)
     14# USAGE: fix_chip_locations.pl --dateobs (night) --chiplist (file) --stage (0,1,etc)
    1515
    1616# we need to select targets for ITC copies of files currently only at ATRC:
     
    2525
    2626# choose ITC machines on which to place backup copies:
    27 my @volarray = &get_neb_volumes;
     27my @vol_copy = &get_neb_volumes_copy; # array of neb hosts to copy data to at ITC
     28my %vol_good = &get_neb_volumes_good; # hash of valid neb hosts
    2829my $volnum = 0;
    2930
    3031my $Ngood = 0;
     32my $Ndead = 0;
    3133my $Ngone = 0;
    32 my $Ndead = 0;
    3334my $Nsing = 0;
    3435my $Ndups = 0;
     
    4041my $Ncul3 = 0;
    4142
     43# load the lists of good and fail chips
     44my $prev = $stage - 1;
     45my $goodfile = "$topdir/$dateword/goodchips.$prev.txt";
     46my %goodchips;
     47if (-e $goodfile) {
     48    open (GOODFILE,  $goodfile);
     49    my @lines = <GOODFILE>;
     50    close (GOODFILE);
     51   
     52    foreach my $line (@lines) {
     53        chomp $line;
     54        $goodchips{$line} = 1;
     55    }
     56}
     57my $failfile = "$topdir/$dateword/failchips.$prev.txt";
     58my %failchips;
     59if (-e $failfile) {
     60    open (FAILFILE,  $failfile);
     61    my @lines = <FAILFILE>;
     62    close (FAILFILE);
     63   
     64    foreach my $line (@lines) {
     65        chomp $line;
     66        $failchips{$line} = 1;
     67    }
     68}
     69
    4270foreach my $chip_id (@chip_ids) {
    4371
    44     my $urifile = "$topdir/$dateword/$chip_id.uris.txt";
    45     open (FILE,  $urifile);
    46     my @lines = <FILE>;
    47     close (FILE);
     72    # read from chip_id file, update to next stage number
     73    my $urifile = "$topdir/$dateword/$chip_id.uris.$stage.txt";
     74    if (! -e $urifile) { die "missing file $urifile\n"; }
     75    open (URIFILE,  $urifile);
     76    my @lines = <URIFILE>;
     77    close (URIFILE);
    4878
    4979    foreach my $line (@lines) {
     
    6191        my $md5sum = $words[3];
    6292
     93        my $haveMD5 = 0;
     94        my $goodMD5 = 0;
     95        if ($goodchips{$ext_id}) { $haveMD5 = 1; $goodMD5 = 1; }
     96        if ($failchips{$ext_id}) { $haveMD5 = 1; }
     97
     98
     99        # nothing to be done, or need be done for these:
    63100        if ($state eq "GOOD:") { $Ngood++; next; }
    64101        if ($state eq "DEAD:") { $Ndead++; next; }
     
    66103
    67104        # one copy at ITC: neb-replicate will create a copy at ATRC
     105        # does not depend on existence of MD5sum
    68106        if ($state eq "SING:") {
    69107            my $status = &vsystem ("neb-replicate $ext_id");
     
    79117
    80118        # one copy at ATRC: neb-replicate will create a copy at ITC iff we supply the target volume
     119        # does not depend on existence of MD5sum
    81120        if ($state eq "SBCK:") {
    82             my $tgtvol = $volarray[$volnum];
     121            my $tgtvol = $vol_copy[$volnum];
    83122            my $status = &vsystem ("neb-replicate --volume $tgtvol $ext_id");
    84123            if ($status) { print STDERR "FAIL SBCK: neb-replicate : $ext_id on $tgtvol\n"; next; }
     
    92131        }
    93132
    94         # these are done in stage 2:
    95         if ($state eq "DUPS:") { $Ndups++; next; }
    96         if ($state eq "XBCK:") { $Nxbck++; next; }
    97 
    98         # these are done in stage 3:
    99         if ($state eq "CUL1:") { $Ncul1++; next; }
    100         if ($state eq "CUL2:") { $Ncul2++; next; }
    101         if ($state eq "CUL3:") { $Ncul3++; next; }
     133        # multiple copies @ ITC, but none at ATRC. use neb-replicate to make copies
     134        # skip if we do not know the state of the md5sum
     135        if ($state eq "DUPS:") {
     136            if ($haveMD5 && $goodMD5) {
     137                my $status = &vsystem ("neb-replicate $ext_id");
     138                if ($status) { print STDERR "FAIL DUPS: neb-replicate : $ext_id\n"; next; }
     139                my ($newfile, $newhost, $newxattr) = &get_new_instance ($ext_id);
     140                unless ($newxattr == 1) { die "new instance is not at ATRC? $ext_id : $newfile : $newhost : $newxattr\n"; }
     141                open (OUTFILE, ">>$topdir/$dateword/$newhost.inst.$stage.txt");
     142                print OUTFILE "$newfile $datast $md5sum\n";
     143                close (OUTFILE);
     144            }
     145            $Ndups++;
     146            next;
     147        }
     148
     149        # multiple copies @ ATRC, but none @ ITC: neb-replicate will create a copy at ITC iff we supply the target volume
     150        # skip if we do not know the state of the md5sum
     151        if ($state eq "XBCK:") {
     152            if ($haveMD5 && $goodMD5) {
     153                my $tgtvol = $vol_copy[$volnum];
     154                my $status = &vsystem ("neb-replicate --volume $tgtvol $ext_id");
     155                if ($status) { print STDERR "FAIL XBCK: neb-replicate : $ext_id on $tgtvol\n"; next; }
     156                my ($newfile, $newhost, $newxattr) = &get_new_instance ($ext_id);
     157                unless ($newxattr == 0) { die "new instance is not at ITC? $ext_id : $newfile : $newhost : $newxattr\n"; }
     158                open (OUTFILE, ">>$topdir/$dateword/$newhost.inst.$stage.txt");
     159                print OUTFILE "$newfile $datast $md5sum\n";
     160                close (OUTFILE);
     161            }
     162            $Nxbck++;
     163            next;
     164        }
     165
     166        # one copy at ITC: neb-replicate will create a copy at ATRC
     167        # skip if we do not know the state of the md5sum
     168        if (($state eq "CUL1:") || ($state eq "CUL2:") || ($state eq "CUL3:")) {
     169
     170            if ($haveMD5 && $goodMD5) {
     171                # get info for all instances of this chip
     172                # returns a reference to the array of instance data
     173                # also strips neb://hostname.volnum/ from nebname and returns as ext_id
     174                my ($inforows, $ext_id) =  &get_chip_instances ($ext_id);
     175
     176                my ($main_keep, $back_keep, $cull_list_r) = &check_instance_xattr ($inforows, $ext_id);
     177
     178                if ($main_keep eq "") { print STDERR "FAIL $state: missing ITC copy for $ext_id\n";  next; }
     179                if ($back_keep eq "") { print STDERR "FAIL $state: missing ATRC copy for $ext_id\n"; next; }
     180
     181                my $NcullTotal = @$cull_list_r;
     182                foreach my $instance (@$cull_list_r) {
     183                    my ($volname) = $instance =~ m|file:///data/([0-9a-zA-Z]*\.[0-9])/\S*|;
     184                    unless (defined $vol_good{$volname}) { die "ERROR: invalid volume name $volname\n"; }
     185                    # print STDERR "neb-cull $state: $ext_id $volname ($main_keep $back_keep)\n";
     186                    my $status = &vsystem ("neb-cull --volume $volname $ext_id");
     187                    if ($status) { print STDERR "FAIL CULL: neb-replicate : $ext_id\n"; next; }
     188                }
     189                # print STDERR "Ncull Total $NcullTotal\n";
     190            }
     191
     192            # these are done in stage 3:
     193            if ($state eq "CUL1:") { $Ncul1++; next; }
     194            if ($state eq "CUL2:") { $Ncul2++; next; }
     195            if ($state eq "CUL3:") { $Ncul3++; next; }
     196        }
    102197    }
    103198    $volnum ++;
     
    136231}
    137232
    138 # get the list of chip neb paths for one chip
    139 sub get_neb_volumes {
     233sub get_chip_instances {
     234
     235    my $ext_id = $_[0];
     236   
     237    my $sql_chip_instances = "SELECT uri, host, available, xattr, cab_id from instance join storage_object using (so_id) join volume using (vol_id) where ext_id = '$ext_id'";
     238    my $rowref   = $neb_dbh->selectall_arrayref( $sql_chip_instances );
     239   
     240    return ($rowref, $ext_id);
     241}
     242
     243# select 1 instance with xattr = 0, 1 with xattr = 1.
     244# the rest should be culled.
     245
     246sub check_instance_xattr {
     247
     248    my $rowref  = $_[0];
     249    my $ext_id  = $_[1];
     250
     251    my @inforows = @$rowref;
     252    my $Nrows    = @inforows;
     253
     254    if ($DEBUG > 5) { print "found $Nrows instances\n"; }
     255
     256    # get user_copies for this storage_object
     257    my $main_keep = "";
     258    my $back_keep = "";
     259    my @cull_list = ();
     260
     261    # xattr = 0 means instance @ ITC  (main)
     262    # xattr = 1 means instance @ ATRC (back)
     263    for (my $j = 0; $j < $Nrows; $j ++) {
     264        my $valref = $inforows[$j];
     265        my @values = @$valref;
     266       
     267        # the number of returned values per row must match the query above (in get_chip_instances)
     268        my $Nvalue = @values;
     269        if ($Nvalue != 5) {
     270            print STDERR "ERROR : INVALID DB XATTR RESPONSE: $ext_id\n";
     271            next;
     272        }
     273
     274        my $instance = $values[0];
     275        my $hostname = $values[1];
     276        my $xattr    = $values[3];
     277       
     278        if (($xattr == 0) && ($main_keep eq "")) { $main_keep = $instance; next; }
     279        if (($xattr == 1) && ($back_keep eq "")) { $back_keep = $instance; next; }
     280
     281        # if we make it here, we already have an instance at this location
     282        push (@cull_list, $instance);
     283    }
     284    return ($main_keep, $back_keep, \@cull_list);
     285}
     286
     287# get the list of neb hosts to copy data to at ITC
     288sub get_neb_volumes_copy {
    140289
    141290    my @volarray;
     
    164313}
    165314
     315# get the list of valid neb hosts (ITC or ATRC)
     316sub get_neb_volumes_good {
     317
     318    my %volarray;
     319
     320    my $sql_neb_volumes = "select name from mountedvol where ((xattr = 0) or (xattr = 1))";
     321    if ($DEBUG > 4) { print "sql: $sql_neb_volumes\n"; }
     322
     323    my $rowref   = $neb_dbh->selectall_arrayref( $sql_neb_volumes );
     324    my @tmparray = @$rowref;
     325    my $Nrows    = @tmparray;
     326
     327    if ($DEBUG > 4) { print "found $Nrows possible volumes\n"; }
     328
     329    foreach my $valref (@tmparray) {
     330        my @values = @$valref;
     331        # there should only be a single value (only name selected above)
     332        my $Nvalues = @values;
     333        if ($Nvalues == 0) { print "ERROR: missing uri\n"; next; }
     334        if ($Nvalues  > 1) { print "ERROR: too many uri entries?\n"; next; }
     335       
     336        $volarray{$values[0]} = 1;
     337        if ($DEBUG > 4) { print "$values[0]\n"; }
     338    }
     339   
     340    return %volarray;
     341}
     342
    166343# read the list of chip_ids:
    167344sub load_chip_list {
     
    194371    pod2usage( -msg => "Cannot determine target date, use --dateobs YYYY/MM/DD", -exitval => 2) unless defined $dateobs;
    195372    pod2usage( -msg => "Provide a list of chips with --chiplist", -exitval => 2) unless defined $chiplist;
    196     pod2usage( -msg => "Define the stage (v0, v1, etc) with --stage", -exitval => 2) unless defined $stage;
     373    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
    197374    pod2usage( -msg => "Specify the top-level output directory with --topdir", -exitval => 2) unless defined $topdir;
    198375   
     376    # check that stage is an integer
     377    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     378    unless ($stage >= 0) { die "stage must be a non-negative integer\n"; }
     379
    199380    # check the date format (require YYYY/MM/DD and use that from 00:00:00 to 23:59:59 or take start and end?)
    200381
     
    248429sub vsystem {
    249430    print STDERR "@_\n";
    250     #return 0;
     431    # return 0;
    251432    my $status = system ("@_");
    252433    return $status;
    253434}
     435
     436sub is_integer {
     437   defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
     438}
     439   
  • trunk/tools/eam/rawfix.20230221/src/get_md5s_instances.pl

    r42441 r42444  
    1111use Getopt::Long qw( GetOptions :config auto_help auto_version );
    1212
    13 # USAGE: get_md5s_instances.pl --hostname (hostname) --input (file) --stage (v0,v1,etc)
     13# USAGE: get_md5s_instances.pl --hostname (hostname) --input (file) --stage (0,1,etc)
    1414
    1515my ($myhost, $input, $stage) = &parse_cmdopts;
     
    2626
    2727if ($output eq $input) { die "output file ($output) matches input file ($input)\n"; }
     28
     29# read in both instance
     30my $out_hash_r;
    2831if (-e $output) {
    29     # check that all instances are in the output file?
    30     print "$output exists, skipping\n";
    31     exit 0;
     32    $out_hash_r = &load_output_list ($output);
    3233}
    3334
    34 open (OUTFILE, ">$output");
     35open (OUTFILE, ">>$output");
    3536
    3637# foreach my $instance (@$ins_list_r) {
     
    4142    my $md5sum_tru = $md5_list_r->[$i];
    4243
     44    # if the instance is already in the output file, skip it
     45    if (defined $out_hash_r) {
     46        my $name = $out_hash_r->{$instance};
     47        if (defined $name) {
     48            print STDERR "skipping $instance (already in output)\n";
     49            next;
     50        }
     51    }
     52
    4353    my $filename = $instance;
    4454    $filename =~ s|file://||;
    45    
     55
    4656    # check for the existence of the file first:
    4757    unless (-e $filename) {
     
    6373exit 0;
    6474
    65 # read the list of chip_ids:
     75# read the instance info
    6676sub load_instance_list {
    6777    my $infile = $_[0];
     
    8898}
    8999
     100# read the instance list in the output file
     101sub load_output_list {
     102    my $infile = $_[0];
     103
     104    my (%out_hash);
     105
     106    open(FILE,$infile) or die "cannot open file $infile\n";
     107
     108    my @lines = <FILE>;
     109
     110    foreach my $line (@lines) {
     111        chomp $line;
     112        if ($line =~ /^\s*#/) { next; } # skip lines with leading #
     113        my @words = split (/\s+/,$line);
     114
     115        if (@words != 4) { die "error in input $infile : $line\n"; }
     116        $out_hash{$words[0]} = 1;
     117    }
     118    close (FILE);
     119
     120    return (\%out_hash);
     121}
     122
    90123sub parse_cmdopts {
    91124
     
    95128    pod2usage( -msg => "Provide the input list with --input", -exitval => 2) unless defined $input;
    96129    pod2usage( -msg => "Define the host machine with --hostname", -exitval => 2) unless defined $myhost;
    97     pod2usage( -msg => "Define the stage (v0, v1, etc) with --stage", -exitval => 2) unless defined $stage;
     130    pod2usage( -msg => "Define the stage (0, 1, etc) with --stage", -exitval => 2) unless defined $stage;
     131   
     132    # check that stage is an integer
     133    unless (is_integer ($stage)) { die "stage must be a non-negative integer\n"; }
     134    unless ($stage >= 0) { die "stage must be a non-negative integer\n"; }
    98135   
    99136    return ($myhost, $input, $stage);
     
    106143    return $status;
    107144}
     145
     146sub is_integer {
     147   defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
     148}
     149   
Note: See TracChangeset for help on using the changeset viewer.