diff --git a/src/external/scripts/mlog2db b/src/external/scripts/mlog2db new file mode 100755 index 000000000..04dede6fb --- /dev/null +++ b/src/external/scripts/mlog2db @@ -0,0 +1,307 @@ +#!/bin/bash + +if [ ! -e /usr/bin/awk ]; then + echo Please make sure you have installed awk! + exit 1 +fi + +if [ $# -lt 3 ] ; 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 + + musrfit $COUNT$3.msr + + if [ $NEXTCOUNT -le $2 ]; then + 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$3.mlog + fi +fi + +if [ ! -e $COUNT$3.mlog ]; then + echo The specified musrfit output file $COUNT$3.mlog does not exist! + exit 1 +fi + +if [ -d $SUMMDIR ]; then +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$3.mlog ) + +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$3.mlog ) + +if [ "$RUNYEAR" != "XX" ]; then + +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 + +awk -v parFOUR=$4 -v parFIVE=$5 -v parSIX=$6 '{ + + outfile="out.db" + if(parFOUR ~ /^-o/) outfile = substr(parFOUR,3) + if(parFIVE ~ /^-o/) outfile = substr(parFIVE,3) + if(parSIX ~ /^-o/) outfile = substr(parSIX,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 + + if(runNumber[2] != "his") {dataArray[i+3] = runNumber[2] } + if(runNumber[2] == "his") {dataArray[i+3] = substr(runNumber[3],1,4) } + + negErrArray[i] = "" + negErrArray[i+1] = "" + negErrArray[i+2] = "" + negErrArray[i+3] = "" + + posErrArray[i] = "" + posErrArray[i+1] = "" + posErrArray[i+2] = "" + posErrArray[i+3] = "" + + +# Output to file in the case, the LEM summary file is accessible + + if("'"$TEMPERATURE"'" != "") { + + if("'"$COUNT"'" == "'"$1"'" && parFOUR != "noheader" && parFIVE != "noheader" && parSIX != "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" >> outfile + print "Tr" >> outfile + print "E" >> outfile + print "RAL-RAR" >> outfile + print "RAT-RAB" >> 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 + } + + 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 + + for(l=1;l> outfile + } + + print dataArray[i+3] ",,, " "'"$TITLE"'" >> outfile + + if("'"$COUNT"'" == "'"$2"'") print "\n" >> outfile + + } + +# If we do not have the information from the summary file + + else { + if("'"$COUNT"'" == "'"$1"'" && parFOUR != "noheader" && parFIVE != "noheader" && parSIX != "noheader"){ + print "TITLE" >> outfile + print ">>>Put your title here<<<\n" >> outfile + print "Abstract" >> outfile + print ">>>Put your abstract here<<<\n" >> outfile + print "LABELS" >> outfile + + for(k=1;k> outfile + } + + $1 = "Data" + for(k=1;k> outfile + print "\\-e" >> outfile + } + + for(l=1;l> outfile + } + + print dataArray[i+3] ",,, " title >> outfile + + if("'"$COUNT"'" == "'"$2"'") print "\n" >> outfile + + + } + + } +}' $COUNT$3.mlog + +((COUNT++)) + +done + +fi