#!/bin/bash if [ ! -e /usr/bin/awk ]; then echo Please make sure you have installed awk! exit 1 fi if [ $# -lt 2 ] ; then cat < nextinput else if($1 == "RUN") { if (substr(count,1,1) != "_"){ count = sprintf("_%04u", count); nextcount = sprintf("_%04u", nextcount);} sub(count, nextcount, $0); print $0 >> nextinput } else print $0 >> nextinput }' $TEMPLATE fi if [ "${OPT_PAR_ONE}" == "-k" ] || [ "${OPT_PAR_TWO}" == "-k" ] || [ "${OPT_PAR_THREE}" == "-k" ] || [ "${OPT_PAR_FOUR}" == "-k" ] \ || [ "${OPT_PAR_FIVE}" == "-k" ]; then MUSRFITPARAM="-k" fi musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM # the fit if [ "$COUNT" != "${RUNARRAY[$LASTRUN]}" ]; then # create the next musrfit input file if not the last specified run was fitted already awk -v count=$COUNT -v nextcount=$NEXTCOUNT -v nextinput=$NEXTINPUT '{ if(NR==1) print nextcount > nextinput else if($1 == "RUN") { if (substr(count,1,1) != "_"){ count = sprintf("_%04u", count); nextcount = sprintf("_%04u", nextcount);} sub(count, nextcount, $0); print $0 >> nextinput } else print $0 >> nextinput }' $COUNT$EXTENSION.mlog fi fi if [ ! -e $COUNT$EXTENSION.mlog ]; then echo echo "The specified musrfit output file "$COUNT$EXTENSION".mlog does not exist!" echo exit 1 fi # if the "nosummary"-option is not set and the summary files are present, get some information from there if [ "${OPT_PAR_ONE}" != "nosummary" ] && [ "${OPT_PAR_TWO}" != "nosummary" ] && [ "${OPT_PAR_THREE}" != "nosummary" ] \ && [ "${OPT_PAR_FOUR}" != "nosummary" ] && [ "${OPT_PAR_FIVE}" != "nosummary" ]; then if [ -d $SUMMDIR ]; then # extract runnumber from mlog-file RUNNUMBER=$( awk '{ if(NR==1) X=0 if($1 ~ /^RUN/ && X==0) { split($2, runNumber, "_") if(runNumber[1] ~ /lem/ && runNumber[2] != "his") {print runNumber[2] } if(runNumber[1] ~ /lem/ && runNumber[2] == "his") {print substr(runNumber[3],1,4) } X=1 } }' $COUNT$EXTENSION.mlog ) # extract runyear from mlog-file in case of LEM-data RUNYEAR=$( awk '{ if(NR==1) X=0 if($1 ~ /^RUN/ && X==0) { split($2, runNumber, "_") if(runNumber[1] ~ /lem/) {print substr(runNumber[1],length(runNumber[1])-1)} else print "XX" X=1 } }' $COUNT$EXTENSION.mlog ) if [ "$RUNYEAR" != "XX" ]; then # in case of LEM-data search the summary-file SUMMFILE=$SUMMDIR/20$RUNYEAR/lem$RUNYEAR\_$RUNNUMBER.summ TITLE=$( awk '{ if(NR==4) print $0 }' $SUMMFILE ) ENERGY=$( awk '{ if($0 ~ /implantation energy/) print $(NF-1)}' $SUMMFILE ) TEMPERATURE=$( awk '{ if($1 == "Sample_CF1") print $(NF-1)}' $SUMMFILE ) RALRAR=$( awk '{ if($5 == "RA-L") RAL=$7; if($1 == "RA-R") { RAR=$3; print RAL-RAR; nextfile } }' $SUMMFILE ) RATRAB=$( awk '{ if($5 == "RA-T") RAT=$7; if($1 == "RA-B") { RAB=$3; print RAT-RAB; nextfile } }' $SUMMFILE ) TRANSPORT=$( awk '{ if($1 == "Moderator") print $3}' $SUMMFILE ) fi fi fi # put together all data to db-format and write it to the file awk -v optPARone=$OPT_PAR_ONE -v optPARtwo=$OPT_PAR_TWO -v optPARthree=$OPT_PAR_THREE -v optPARfour=$OPT_PAR_FOUR \ -v optPARfour=$OPT_PAR_FIVE -v runList=$RUNLIST_USED -v numIndVar=$NUM_OF_IND_VAR '{ outfile="out.db" if(optPARone ~ /^-o/) outfile = substr(optPARone,3) if(optPARtwo ~ /^-o/) outfile = substr(optPARtwo,3) if(optPARthree ~ /^-o/) outfile = substr(optPARthree,3) if(optPARfour ~ /^-o/) outfile = substr(optPARfour,3) if(optPARfive ~ /^-o/) outfile = substr(optPARfive,3) FS = " " OFS = " " if(NR==1){title=$0; X=0; Y=0; i=1} if(NR>4){ if(X == 0){ if($0 != ""){ parArray[i] = $2 dataArray[i] = $3 if($4 ~ /^-/) negErrArray[i] = (-1.0)*$4 else negErrArray[i] = $4 if($5 ~ /none/) posErrArray[i] = $4 else posErrArray[i] = $5 i++ } if($0 == "") X=1 } } if($1 ~ /^RUN/ && X==1){ split($2, runNumber, "_"); X=2 } if($1 ~ /^chi/ && X==2){ parArray[i] = "CHISQ" parArray[i+1] = "NDF" parArray[i+2] = "CHISQred" parArray[i+3] = "RUN" sub(/,/, "", $3); sub(/,/, "", $6); dataArray[i] = $3 dataArray[i+1] = $6 dataArray[i+2] = $9 for (j in runNumber) { if ( runNumber[j] ~ /^0/ ) { sub(/0+/, "", runNumber[j]) } if (int(runNumber[j]) == runNumber[j]) { dataArray[i+3] = runNumber[j] break } else dataArray[i+3] = "0000" } negErrArray[i] = "" negErrArray[i+1] = "" negErrArray[i+2] = "" negErrArray[i+3] = "" posErrArray[i] = "" posErrArray[i+1] = "" posErrArray[i+2] = "" posErrArray[i+3] = "" # Read in the runlist-variable names if(runList == 1){ getline line < "'"$1"'" split(line, indVar, " ") } # Output to file in the case, the LEM summary file is accessible and the option "nosummary" is not set if("'"$TEMPERATURE"'" != "") { # Write the db-header if("'"$COUNT"'" == "'"${RUNARRAY[0]}"'" && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader" && optPARfour != "noheader" && optPARfive != "noheader"){ print "TITLE" >> outfile print ">>>Put your title here<<<\n" >> outfile print "Abstract" >> outfile print ">>>Put your abstract here<<<\n" >> outfile print "LABELS" >> outfile print "T [K]" >> outfile print "Tr [kV]" >> outfile print "E [keV]" >> outfile print "RAL-RAR [kV]" >> outfile print "RAT-RAB [kV]" >> outfile if(runList == 1){ for(k=2;k<=numIndVar;k++){print indVar[k] >> outfile} } for(k=1;k> outfile } $1 = "Data" $2 = "T" $3 = "Tr" $4 = "E" $5 = "RALRAR" $6 = "RATRAB" for(k=1;k> outfile print "\\-e" >> outfile } # Write the data-block print "T = " "'"$TEMPERATURE"'" ",,,\\" >> outfile print "Tr = " "'"$TRANSPORT"'" ",,,\\" >> outfile if ("'"$ENERGY"'" != "") print "E = " "'"$ENERGY"'" ",,,\\" >> outfile else print "E = -999,,,\\" >> outfile if ("'"$RALRAR"'" != "") print "RALRAR = " "'"$RALRAR"'" ",,,\\" >> outfile else print "RALRAR = -999,,,\\" >> outfile if ("'"$RATRAB"'" != "") print "RATRAB = " "'"$RATRAB"'" ",,,\\" >> outfile else print "RATRAB = -999,,,\\" >> outfile if(runList == 1) { # process the "independent variables" from the file while((getline line < "'"$1"'") > 0){ split(line, indVarValue, " ") if (indVarValue[1] == "'"$COUNT"'"){ for(k=2;k<=numIndVar;k++){print indVar[k] " = " indVarValue[k] ",,,\\" >> outfile} break } } } for(l=1;l> outfile } print dataArray[i+3] ",,, " "'"$TITLE"'" >> outfile if("'"$COUNT"'" == "'"${RUNARRAY[$LASTRUN]}"'") print "\n" >> outfile } # If we do not have the information from the summary file or "nosummary" is set else { if("'"$COUNT"'" == "'"${RUNARRAY[0]}"'" && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader" && optPARfour != "noheader" && optPARfive != "noheader"){ print "TITLE" >> outfile print ">>>Put your title here<<<\n" >> outfile print "Abstract" >> outfile print ">>>Put your abstract here<<<\n" >> outfile print "LABELS" >> outfile if(runList == 1){ for(k=2;k<=numIndVar;k++){print indVar[k] >> outfile} } for(k=1;k> outfile } $1 = "Data" for(k=1;k> outfile print "\\-e" >> outfile } if(runList == 1) { while((getline line < "'"$1"'") > 0){ split(line, indVarValue, " ") if (indVarValue[1] == "'"$COUNT"'"){ for(k=2;k<=numIndVar;k++){print indVar[k] " = " indVarValue[k] ",,,\\" >> outfile} break } } } for(l=1;l> outfile } print dataArray[i+3] ",,, " title >> outfile if("'"$COUNT"'" == "'"${RUNARRAY[$LASTRUN]}"'") print "\n" >> outfile } } }' $COUNT$EXTENSION.mlog done fi