From 7cdaa0143e260bfd5e5263f26a7af04dc35619ff Mon Sep 17 00:00:00 2001 From: "Bastian M. Wojek" Date: Thu, 25 Sep 2008 18:28:49 +0000 Subject: [PATCH] Completely changed parts of the mlog2db, added new features, fixed some weaknesses - and probably added new ones. --- src/external/scripts/mlog2db | 769 ++++++++++++++++++++--------------- 1 file changed, 439 insertions(+), 330 deletions(-) diff --git a/src/external/scripts/mlog2db b/src/external/scripts/mlog2db index 6199c911..9eda110a 100755 --- a/src/external/scripts/mlog2db +++ b/src/external/scripts/mlog2db @@ -1,33 +1,50 @@ #!/bin/bash if [ ! -e /usr/bin/awk ]; then - echo Please make sure you have installed awk! - exit 1 + echo Please make sure you have installed awk! + exit 1 fi -if [ $# -lt 3 ] ; then - +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 -# Check for musrfit on the PATH and if found continue with searching the fit-template + 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 - PATHTOMUSRFIT=$(echo `which musrfit`) - if [ "$PATHTOMUSRFIT" == "" ]; then - echo - echo No musrfit executable was found on the PATH or in the current directory! - echo Please install musrfit first! - echo - exit 1 - else + musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM # the fit - if [ -e $TEMP$EXTENSION.mlog ]; then - TEMPLATE=$TEMP$EXTENSION.mlog - else if [ -e $TEMP$3.msr ]; then - TEMPLATE=$TEMP$EXTENSION.msr - fi - fi - fi -fi + 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 -for (( q=0; q<=${LASTRUN}; q++ )); -do -COUNT=${RUNARRAY[$q]} -NEXTCOUNT=${RUNARRAY[ (( q + 1 )) ]} -NEXTINPUT=$NEXTCOUNT$EXTENSION.msr -FIRSTINPUT=${RUNARRAY[0]}$EXTENSION.msr + if [ ! -e $COUNT$EXTENSION.mlog ]; then + echo + echo "The specified musrfit output file "$COUNT$EXTENSION".mlog does not exist!" + echo + exit 1 + fi -#echo COUNT: $COUNT, NEXTCOUNT: $NEXTCOUNT, NEXTINPUT: $NEXTINPUT, FIRSTINPUT: $FIRSTINPUT + # 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 [ "$TEMP" != "" ]; then - - if [ "$TEMPLATE" == "" ]; then - echo The specified musrfit template files $TEMP$3.mlog and $TEMP$3.msr do not exist! - exit 1 - fi - - if [ "$COUNT" == "${RUNARRAY[0]}" ]; then - awk -v count=$TEMP -v nextcount=${RUNARRAY[0]} -v nextinput=$FIRSTINPUT '{ - 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 - }' $TEMPLATE - fi - - if [ "${OPT_PAR_ONE}" == "-k" ] || [ "${OPT_PAR_TWO}" == "-k" ] || [ "${OPT_PAR_THREE}" == "-k" ] || [ "${OPT_PAR_FOUR}" == "-k" ]; then - MUSRFITPARAM="-k" - fi - - musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM - - if [ "$COUNT" != "${RUNARRAY[$LASTRUN]}" ]; 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$EXTENSION.mlog - fi -fi - -if [ ! -e $COUNT$EXTENSION.mlog ]; then - echo The specified musrfit output file $COUNT$EXTENSION.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$EXTENSION.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 - } + 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 ) -if [ "$RUNYEAR" != "XX" ]; then + # 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 ) -SUMMFILE=$SUMMDIR/20$RUNYEAR/lem$RUNYEAR\_$RUNNUMBER.summ + 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 -TITLE=$( awk '{ if(NR==4) print $0 }' $SUMMFILE ) + # 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 '{ -ENERGY=$( awk '{ if($0 ~ /implantation energy/) print $(NF-1)}' $SUMMFILE ) + 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) -TEMPERATURE=$( awk '{ if($1 == "Sample_CF1") print $(NF-1)}' $SUMMFILE ) + FS = " " + OFS = " " -RALRAR=$( awk '{ if($5 == "RA-L") RAL=$7; if($1 == "RA-R") { RAR=$3; print RAL-RAR; nextfile } }' $SUMMFILE ) + if(NR==1){title=$0; X=0; Y=0; i=1} -RATRAB=$( awk '{ if($5 == "RA-T") RAT=$7; if($1 == "RA-B") { RAB=$3; print RAT-RAB; nextfile } }' $SUMMFILE ) + 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 + } + } -TRANSPORT=$( awk '{ if($1 == "Moderator") print $3}' $SUMMFILE ) - -fi - -fi - -awk -v optPARone=$OPT_PAR_ONE -v optPARtwo=$OPT_PAR_TWO -v optPARthree=$OPT_PAR_THREE -v optPARfour=$OPT_PAR_FOUR '{ - - 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) - - 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] = "" - - -# Output to file in the case, the LEM summary file is accessible - - if("'"$TEMPERATURE"'" != "") { - - if("'"$COUNT"'" == "'"${RUNARRAY[0]}"'" && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader" && optPARfour != "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 - - 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"'" == "'"${RUNARRAY[$LASTRUN]}"'") print "\n" >> outfile - - } - -# If we do not have the information from the summary file - - else { - if("'"$COUNT"'" == "'"${RUNARRAY[0]}"'" && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader" && optPARfour != "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 - - for(k=1;k> outfile - } - - $1 = "Data" - $2 = "T" - for(k=1;k> outfile - print "\\-e" >> outfile - } - - print "T = 000,,,\\" >> outfile - - for(l=1;l> outfile - } - - print dataArray[i+3] ",,, " title >> outfile - - if("'"$COUNT"'" == "'"${RUNARRAY[LASTRUN]}"'") print "\n" >> outfile - - - } - - } -}' $COUNT$EXTENSION.mlog - -done + 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