#! /bin/sh # This is the LHEA perl script: /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/asmsrcupdate # The purpose of this special block is to make this script work with # the user's local perl, regardless of where that perl is installed. # The variable LHEAPERL is set by the initialization script to # point to the local perl installation. #------------------------------------------------------------------------------- eval ' if [ "x$LHEAPERL" = x ]; then echo "Please run standard LHEA initialization before attempting to run /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/asmsrcupdate." exit 3 elif [ "$LHEAPERL" = noperl ]; then echo "During LHEA initialization, no acceptable version of Perl was found." echo "Cannot execute script /cvmfs/extras-fp7.egi.eu/extras/heasoft/ftools/x86_64-unknown-linux-gnu-libc2.19-0/bin/asmsrcupdate." exit 3 elif [ `$LHEAPERL -v < /dev/null 2> /dev/null | grep -ic "perl"` -eq 0 ]; then echo "LHEAPERL variable does not point to a usable perl." exit 3 else # Force Perl into 32-bit mode (to match the binaries) if necessary: if [ "x$HD_BUILD_ARCH_32_BIT" = xyes ]; then if [ `$LHEAPERL -V 2> /dev/null | grep -ic "USE_64_BIT"` -ne 0 ]; then VERSIONER_PERL_PREFER_32_BIT=yes export VERSIONER_PERL_PREFER_32_BIT fi fi exec $LHEAPERL -x $0 ${1+"$@"} fi ' if(0); # Do not delete anything above this comment from an installed LHEA script! #------------------------------------------------------------------------------- #! /usr1/local/bin/perl5 # J. Lochner: Aug 19, 1995 # Perl script for running ASMAPPEND on collection of master files # and appending files # # Revision History - # Nov. 15, 1995 - allow for new master file. A source in /incoming # which does not have a corresponding /master file is converted # into a master file # June 21, 1996 - Let user input directory name for master and # incoming files. User may also specify the type of files # to append. # July 18, 1997 - Script now correctly handles first file in incoming # list not having an existing master. Also correct bug to # properly rename new master files with _d1 designation. # N.B. It appears that script does not properly handle a new # source at the *end* of the incoming list (and likely never has.) # Sep. 8, 1997 - Made output less verbose, and omitted one of the pause # points. # Mar. 28 2008 (MJT) # Strengthened source name extraction against internal underscores # Corrected section that creates new master to handle current ASM # name convention. # require "utils.pl"; use Getopt::Std; # # check for flags and act appropriately # getopts('h'); if (defined $opt_h) { print <); print "Input name of directory containing incoming files\n"; chop($incoming=); print "Input type of files to append (e.g. .lc or .col)\n"; chop($file_type=); system("ls $incoming/*$file_type > incoming.txt"); system("ls $master_dir/*$file_type > master.txt"); open(INCOMING, "incoming.txt"); open(MASTER, "master.txt"); # # Read the master and incoming files # @mstrfile = ; @infile = ; $jm = "".@mstrfile - 1; $in = "".@infile - 1; print $jm+1," master files\n"; print $in+1," incoming files\n"; print "(hit any key to continue)"; chop($_=); print "pause at each step (y/n) "; chop($pause=); print "\n"; # # Find the first match # $m = 0; $i = 0; $jappend = 0; until ($m >= $jm || &srcnam($mstrfile[$m]) eq &srcnam($infile[$i])) { # print "\n".$mstrfile[$m]."\n"; # $mstrsrc = &srcnam($mstrfile[$m]); # print " master source = ".$mstrsrc."\n"; # print "Master # ".$m." = ".&srcnam($mstrfile[$m]).", Incoming # ".$i." = ".&srcnam($infile[$i])."\n"; $m++; } # # check for condition that there is no master for first # file in the append list # if ($m >= $jm) { print " No Master File for ".$infile[$i]."\n"; print ' Making it a master file ...'."\n"; chop($master = $infile[$i]); $s1 = rindex($master,"_"); $master = substr($master,0,$s1)."_d1.$file_type"; $master =~ s/$incoming/$master_dir/; chop($infile[$i]); print " Copying $infile[$i] to $master\n"; system("cp $infile[$i] $master"); $i = 1; $m = -1; } else { chop($master = $mstrfile[$m]); } # # Now process the first match and do rest of them. # while ($i <= $in && $m <= $jm) { $jappend = 0; open(APPENDLIST, "> append.txt"); print "master file # ".$m." = ".$master."\n"; while (&srcnam($master) eq &srcnam($infile[$i])) { $jappend++; print " APPENDLIST: Incoming # ".$i." ".$infile[$i]."\n"; print APPENDLIST $infile[$i]; $i++; } print "appending ",$jappend," incoming files for ",$master,"\n"; close(APPENDLIST); # if($pause eq "y") { # print "(hit any key to continue)"; # chop($_=); # } if ($jappend > 0) { @result = &runcom('asmappend '.$master.' @append.txt'); # print @result,"\n"; } print "\n Seaching for next master file: \n"; if($pause eq "y"){ print "(hit any key to continue)"; chop($_=); } $km = $m; $m++; until ($m > $jm || &srcnam($mstrfile[$m]) eq &srcnam($infile[$i])) { $m++; } print 'end of searching for next master. m = '.$m."\n\n"; if ($m <= $jm) { chop($master = $mstrfile[$m]); } elsif ($km < $jm) { $m = $km; print " No Master File for ".$infile[$i]."\n"; print ' Making it a master file ...'."\n"; chop($master = $infile[$i]); $s1 = rindex($master,"_"); $master = substr($master,0,$s1)."_d1.$file_type"; $master =~ s/$incoming/$master_dir/; chop($infile[$i]); print " Copying $infile[$i] to $master\n"; system("cp $infile[$i] $master"); $i++; } } print "done \n"; sub srcnam { local($x,$y,$filenam,$src); $filenam = $_[0]; $x = index($filenam,"_"); $y = rindex($filenam,"_"); $src = substr($filenam,$x+1,$y-$x-1); }