#! /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/xstar2xspec # 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/xstar2xspec." 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/xstar2xspec." 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! #------------------------------------------------------------------------------- #! /lheadev/bridgman/xstar/OSF1_4.0_alpha/bin/lhea-perl # # xstar2xspec # # Generate and manage multiple XSTAR runs to build atable and mtable models # for analysis by XSPEC. # # # Usage: # xstar2xspec {options} # # Options: # -restart Continues the XSTAR2XSPEC run using the previous run. # Note that it does *NOT* check the integrity of the # table files from the terminated run. This is the user's # responsibility. # -save Save the spectral FITS files, modifying the file name to # include the value of the loopcontrol variable for better # identification. Note this can use gobs of disk space. # -verbose Print gobs of informational(?) messages on the program run. # # Written by: W.T. Bridgman, RITSS, March 1999 # # History: # v1.0 # # record starting time $starttime = time; # Perl libraries required by FTOOLS require "utils.pl"; require "getparm.pl"; # initialize times variable $totaltime=$times; # initialize file names generated by xstar2xspec $PROCESSFILE="xstinitable.lis"; $PROCESSTEMP="xstinitable.tmp"; $INITFITS="xstinitable.fits"; $ATABLE1="xout_aout.fits"; $ATABLE2="xout_ain.fits"; $MTABLE="xout_mtable.fits"; $XSTAR2XSPECLOG="xstar2xspec.log"; # initialize file names generated by xstar $SPECTRALFILE="xout_spect1.fits"; $XSTARLOG="xout_step.log"; $SLENWARN=800; $SLENERROR=1000; # clear option flags $HELP=0; $RESTART=0; $SAVEFILES=0; $VERBOSE=0; # loop over the argument list and set the appropriate flags for($ARGNUM=0;$ARGNUM<=$#ARGV;$ARGNUM++){ if($ARGV[$ARGNUM] eq "-h") {$HELP=1;} if($ARGV[$ARGNUM] eq "-restart") {$RESTART=1;} if($ARGV[$ARGNUM] eq "-save"){$SAVEFILES=1;} if($ARGV[$ARGNUM] eq "-verbose"){$VERBOSE=1;} } if ($VERBOSE){$ENV{XSTARDEBUG}=1;} if($HELP) { print <; # read the first line close(FILEHANDLE); # submit XSTAR command $SCLEN=length($XSTARCOMMAND); if($SCLEN>$SLENERROR){ printf "XSTAR2XSPEC: FATAL ERROR! This command line is $SCLEN characters long.\n"; printf "XSTAR2XSPEC: The maximum allowed is $SLENERROR!\n"; exit; # terminate with extreme prejudice } if($SCLEN>$SLENWARN){ printf "XSTAR2XSPEC: WARNING! This command line is $SLEN characters long.\n"; printf "XSTAR2XSPEC: WARNING! The maximum limit is $SLENERROR!\n"; } $POS=index($XSTARCOMMAND,"loopcontrol="); $NUM=int(substr($XSTARCOMMAND,$POS+12)); printf "XSTAR2XSPEC: Executing Pass #%d\n",$NUM; if($VERBOSE){print $XSTARCOMMAND;} # call FTOOL using runcom which redirects stderr output @RC=&runcom($XSTARCOMMAND,"errhandler","xstar"); printf "xstar returns: ",@RC; print "xstar returns: ",@RC; # append xstar log to master log file if($VERBOSE){print "XSTAR2XSPEC: Appending xstar log file\n";} open(APPENDLOG,">>$XSTAR2XSPECLOG") ||die "XSTAR2XSPEC: Can't open $XSTAR2XSPECLOG. Exiting...\n"; open(LOGFILE,"<$XSTARLOG") ||die "XSTAR2XSPEC: Can't find $XSTARLOG file. Exiting...\n"; printf APPENDLOG "=============================================\n"; printf APPENDLOG "Command Line:\n"; printf APPENDLOG "$XSTARCOMMAND\n\nXSTAR Log:"; while(!eof(LOGFILE)){ $temp=; printf APPENDLOG $temp; } close(APPENDLOG); close(LOGFILE); # build entry for mtable & atables if($VERBOSE) {print "XSTAR2XSPEC: Updating ATABLES & MTABLE.\n";} @RC=&runcom("xstar2table","errhandler","xstar2table"); print "xstar2table returns: ",@RC; printf "xstar2table returns: ",@RC; print @RC; # remove first line from $PROCESSFILE open(INHANDLE,"<$PROCESSFILE") ||die "XSTAR2XSPEC: Can't open $PROCESSFILE\n"; open(OUTHANDLE,">$OUTFILE") ||die "XSTAR2XSPEC: Can't open $OUTFILE\n"; $LINE=; # read first line to discard it $LINECOUNTER=0; while(!eof(INHANDLE)){ $temp=; printf OUTHANDLE $temp; $LINECOUNTER++; } # end while close(INHANDLE); close(OUTHANDLE); printf "XSTAR2XSPEC: $LINECOUNTER runs remaining to process.\n"; $RC=`cp $OUTFILE $PROCESSFILE`; # rename output file if($RC) { printf "XSTAR2XSPEC: Error transcribing command file: $RC\n"; } if($LINECOUNTER==0) {$DONE=1;} # end of loop # if option set to save files, do it here if($SAVEFILES) { $POS=index($XSTARCOMMAND,"loopcontrol="); $NUM=int(substr($XSTARCOMMAND,$POS+12)); $SNUM=sprintf("%04d",$NUM); $POSF=index($SPECTRALFILE,".fits"); $NEWSPECFILE=substr($SPECTRALFILE,0,$POSF)."_".$SNUM.".fits"; $RC=`cp $SPECTRALFILE $NEWSPECFILE`; # copy file to new name } # cleanup after this run $RC=`rm xout_abund1.fits`; $RC=`rm xout_detail.fits`; $RC=`rm $SPECTRALFILE`; $RC=`rm xout_step.lis`; $RC=`rm $XSTARLOG`; } # end of 'while' loop # append closing steps to master log file open(APPENDLOG,">>$XSTAR2XSPECLOG") ||die "XSTAR2XSPEC: Can't open $XSTAR2XSPECLOG. Exiting...\n"; printf APPENDLOG "=============================================\n"; # compute total run time $endtime=time; $totaltime=$endtime-$starttime; printf "XSTAR2XSPEC: Execution time: %10.2f seconds\n",$totaltime; printf "XSTAR2XSPEC: Processing Complete!\n"; printf APPENDLOG "Execution time: %10.2f seconds\n",$totaltimes; printf APPENDLOG "XSTAR2XSPEC Processing Complete!\n"; close(APPENDLOG); # final cleanup $RC=`rm $PROCESSFILE`; $RC=`rm $PROCESSTEMP`; $RC=`rm $INITFITS`; # All done! ################################################### # # Grab all the parameters for xstar2xspec and set them # appropriately in the xstinitable parameter file # sub GetParms{ $ftoolname="xstinitable"; $specFileFlag=0; # physical parameter names @physparms=("trad","cfrac","temperature","pressure","density","rlrad38", "column","rlogxi","habund","heabund","cabund","nabund","oabund", "neabund","mgabund","siabund","sabund","arabund","caabund", "feabund","niabund"); # control parameter names @ctrlparms=("redshift","nsteps","niter","lwrite","lprint","lstep","npass", "lcpres","emult","taumax","xeemin","critf","vturbi","modelname", "loopcontrol","elow","ehigh"); # enter spectrum type $spectrum=&GetParameter($ftoolname,"spectrum",$status); #printf("%s=%s (status=%d)\n","spectrum",$spectrum,$status); if($spectrum eq "file") { $spectrumfile=&GetParameter($ftoolname,"spectrum_file",$status); #printf("%s=%s (status=%d)\n","spectrum_file",$spectrumfile,$status); $spectrumunits=&GetParameter($ftoolname,"spectun",$status); #printf("%s=%s (status=%d)\n","spectun",$spectrumunits,$status); $specFileFlag=1; } # loop over the physical parameters foreach $varname (@physparms) { # if spectrum file specified, skip 'trad' entry if(($varname eq "trad")&&($specFileFlag==1)){ next;} $value=&GetParameter($ftoolname,$varname,$status); #printf("%s=%s (status=%d)\n",$varname,$value,$status); # check parameter type $svarname=$varname."typ"; $type=&GetParameter($ftoolname,$svarname,$status); #printf("%s=%s (status=%d)\n",$svarname,$type,$status); # if variable is interpolated if($type==2) { $svarname=$varname."int"; $mode=&GetParameter($ftoolname,$svarname,$status); #printf("%s=%s (status=%d)\n",$svarname,$mode,$status); $svarname=$varname."sof"; $softmin=&GetParameter($ftoolname,$svarname,$status); #printf("%s=%s (status=%d)\n",$svarname,$softmin,$status); $svarname=$varname."nst"; $nsteps=&GetParameter($ftoolname,$svarname,$status); #printf("%s=%s (status=%d)\n",$svarname,$nsteps,$status); } } # end of foreach loop # now loop over the control parameters foreach $varname (@ctrlparms) { $value=&GetParameter($ftoolname,$varname,$status); #printf("%s=%s (status=%d)\n",$varname,$value,$status); } # end of foreach loop } ################################################################# # Error handler # sub errhandler { printf "XSTAR2XSPEC: Failure in %s\n",$_[0]; printf "XSTAR2XSPEC: Exiting program\n"; exit; }