diff --git a/src/external/scripts/mlog2db b/src/external/scripts/mlog2db deleted file mode 100755 index fe0c715f..00000000 --- a/src/external/scripts/mlog2db +++ /dev/null @@ -1,725 +0,0 @@ -#!/bin/bash - -if [ ! -x /usr/bin/awk ]; then - echo ">> mlog2db: Please make sure you have installed awk!" - exit 1 -fi - -if [ "$#" -lt 2 ] ; then - - cat <> mlog2db: Syntax error - you used the list specification without closing bracket (])! Quitting now." - echo - exit 1 - fi - - EXTENSION=$( eval echo \${$((RIGHTBRACKET + 1))} ) - FIRST_OPT_PAR=$((RIGHTBRACKET + 2)) - LAST_OPT_PAR=$# - RUNLIST_USED=0 - NUM_OF_IND_VAR=1 # 1 for the run number - - else - ISDIGIT1=$( echo $1 | awk '{ if (( $1 + 0 ) == $1 ) {print 1} else {print 0}}' ) # check if the first parameter is a number or not - ISDIGIT2=$( echo $2 | awk '{ if (( $1 + 0 ) == $1 ) {print 1} else {print 0}}' ) # check if the second parameter is a number or not - if [ "$ISDIGIT1" -eq 1 ] && [ "$ISDIGIT2" -eq 1 ]; then # start and end-runs are given - if [ "$1" -le "$2" ]; then # runs are given with increasing run numbers - for (( j=0; j<=$2-$1; j++ )) - do - RUNARRAY[$j]=$(( $1 + $j )) - done - LASTRUN=$(( $2 - $1 )) # RUNARRAY-index of the last run - else # runs are given with decreasing run numbers - for (( j=0; j<=$1-$2; j++ )) - do - RUNARRAY[$j]=$(( $1 - $j )) - done - LASTRUN=$(( $1 - $2 )) # RUNARRAY-index of the last run - fi - - EXTENSION=$3 - - FIRST_OPT_PAR=4 - LAST_OPT_PAR=$# - RUNLIST_USED=0 - NUM_OF_IND_VAR=1 # 1 for the run number - - elif [ "$ISDIGIT1" -eq 1 ] && [ "$ISDIGIT2" -eq 0 ]; then # only one run number is given - RUNARRAY[0]=$1 - - LASTRUN=0 # RUNARRAY-index of the last run - EXTENSION=$2 - - FIRST_OPT_PAR=3 - LAST_OPT_PAR=$# - RUNLIST_USED=0 - NUM_OF_IND_VAR=1 # 1 for the run number - - else # assume a runlist-file with "independent variables" is given - if [ ! -r $1 ]; then - echo - echo ">> mlog2db: The specified runlist file $1 is not present... Bye bye!" - echo - exit 1 - fi - - numberOfReadInLines=0 - - exec 3< $1 # open file for reading in the runlist-file the first time and get the runnumbers to be processed - while read -u 3 -a runList - do - if [ "$numberOfReadInLines" -eq 0 ]; then - NUM_OF_IND_VAR=${#runList[@]} - else - RUNARRAY[(( numberOfReadInLines - 1 ))]=${runList[0]} - fi - ((numberOfReadInLines++)) - done - exec 3<&- # close file - - LASTRUN=$(( ${#RUNARRAY[@]} - 1 )) # RUNARRAY-index of the last run - EXTENSION=$2 - - FIRST_OPT_PAR=3 - LAST_OPT_PAR=$# - RUNLIST_USED=1 - fi - fi - - # Check if fitting should be done - TEMP="" - for PAR in "$@" - do - if [ "${PAR:0:3}" == "fit" ]; then - TEMP=${PAR:4} - break - fi - done - - # Check if the swap-option of musrfit should be used -> then the msr-files will be used as output of musrfit instead of the mlog-files - MUSRFITPARAM="" - INPUTEXT=msr - OUTPUTEXT=mlog - for PAR in "$@" - do - if [ "$PAR" == "-s" ]; then - MUSRFITPARAM="-s" - INPUTEXT=mlog - OUTPUTEXT=msr - break - fi - done - - if [ "$TEMP" != "" ]; then # runs should be fitted using musrfit - - # Check for musrfit on the PATH and if found continue with searching the fit-template - PATHTOMUSRFIT=$(echo `which musrfit`) - if [ "$PATHTOMUSRFIT" == "" ]; then - echo - echo ">> mlog2db: No musrfit executable was found on the PATH or in the current directory!" - echo ">> mlog2db: Please install musrfit first!" - echo - exit 1 - else - if [ -r $TEMP$EXTENSION.$OUTPUTEXT ]; then - TEMPLATE=$TEMP$EXTENSION.$OUTPUTEXT - elif [ -r $TEMP$EXTENSION.$INPUTEXT ]; then - TEMPLATE=$TEMP$EXTENSION.$INPUTEXT - fi - fi - fi - - for (( q=0; q<=LASTRUN; q++ )) # loop over all RUNARRAY entries - the actual data-processing - do - COUNT=${RUNARRAY[$q]} - NEXTCOUNT=${RUNARRAY[ (( q + 1 )) ]} - NEXTINPUT=$NEXTCOUNT$EXTENSION.msr - FIRSTINPUT=${RUNARRAY[0]}$EXTENSION.msr - - if [ "$TEMP" != "" ]; then # if fitting should be done - if [ "$TEMPLATE" == "" ]; then - echo - echo ">> mlog2db: The specified musrfit template files $TEMP$3.mlog and $TEMP$3.msr do not exist!" - echo - exit 1 - fi - - # if it's the first run to be fitted, take the template and substitute the runnumber to match the first run - if [ "$q" -eq 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);} - if ($2 !~ count){ - print " " - print ">> mlog2db: ATTENTION The run-numbers in the filename and the RUN-block of the template file do not match!" - print ">> mlog2db: The run-number substitution is most likely going wrong!" - print " " - } - sub(count, nextcount, $0); - print $0 >> nextinput - } - else print $0 >> nextinput - }' $TEMPLATE - fi - - for PAR in "$@" - do - if [ "$PAR" == "-k" ]; then - MUSRFITPARAM="-k $MUSRFITPARAM" - break - fi - done - - echo - echo ">> mlog2db: musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM" - echo - musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM # the fit - - if [ "$q" -ne "$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);} - if ($2 !~ count){ - print " " - print ">> mlog2db: ATTENTION The run-numbers in the filename and the RUN-block of the file do not match!" - print ">> mlog2db: The run-number substitution is most likely going wrong!" - print " " - } - sub(count, nextcount, $0); - print $0 >> nextinput - } - else print $0 >> nextinput - }' $COUNT$EXTENSION.$OUTPUTEXT - fi - fi - - if [ ! -r $COUNT$EXTENSION.$OUTPUTEXT ]; then - echo - echo ">> mlog2db: The specified musrfit output file $COUNT$EXTENSION.$OUTPUTEXT 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 - NOSUMMARY=0 - for PAR in "$@" - do - if [ "$PAR" == "nosummary" ]; then - NOSUMMARY=1 - break - fi - done - - if [ "$NOSUMMARY" -eq 0 ]; then - - if [ -d $SUMMDIR ]; then - # extract runnumber from mlog/msr-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.$OUTPUTEXT ) - - # extract runyear from mlog/msr-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.$OUTPUTEXT ) - - 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 - - # determine the output-file - OUTFILE="out.db" - - for (( l="$FIRST_OPT_PAR"; l<="$LAST_OPT_PAR"; l++ )) - do - CUR_PAR=$( eval echo \${$l} ) - NEXT_PAR=$( eval echo \${$((l+1))} ) - if [ "${CUR_PAR:0:2}" == "-o" ]; then - if [ "$CUR_PAR" == "-o" ]; then - if [ "$l" -ne "$LAST_OPT_PAR" ] && [ "$NEXT_PAR" != "noheader" ] && [ "$NEXT_PAR" != "nosummary" ] \ - && [ "${NEXT_PAR:0:3}" != "fit" ] && [ "$NEXT_PAR" != "-k" ] && [ "$NEXT_PAR" != "-s" ]; then - OUTFILE=$NEXT_PAR - break - else - echo - echo ">> mlog2db: You did not specify an output file! The default one (out.db) will be used." - echo - fi - else - OUTFILE=${CUR_PAR:2} - break - fi - fi - done - - # determine, if the db-header should be written to the output file, default: YES - NOHEADER=0 - for PAR in "$@" - do - if [ "$PAR" == "noheader" ]; then - NOHEADER=1 - break - fi - done - - # determine the output file-format, default: db - FORMAT=db - for PAR in "$@" - do - if [ "$PAR" == "data" ]; then - FORMAT=dat - break - fi - done - - # put together all data to db-format and write it to the file - awk -v outfile=$OUTFILE -v noheader=$NOHEADER -v runList=$RUNLIST_USED -v numIndVar=$NUM_OF_IND_VAR -v format=$FORMAT '{ - - FS = " " - OFS = " " - - if(NR==1){title=$0; X=0; Y=0; i=1} - - if(NR>1){ - if(X == 0){ - if($1 == i){ - 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($1 ~ /^THEORY/) 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] = "0" - negErrArray[i+1] = "0" - negErrArray[i+2] = "0" - negErrArray[i+3] = "0" - - posErrArray[i] = "0" - posErrArray[i+1] = "0" - posErrArray[i+2] = "0" - posErrArray[i+3] = "0" - - # Read in the runlist-variable names - if(runList == 1){ - getline line < "'"$1"'" - split(line, indVar, " ") - } - - # Output to db-file in the case, the LEM summary file is accessible and the option "nosummary" is not set - - if(format != "dat") { - if("'"$TEMPERATURE"'" != "") { - - # Write the db-header - if("'"$q"'" == 0 && noheader != 1){ - - 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("'"$q"'" == "'"$LASTRUN"'") print "\n" >> outfile - } - - # If we do not have the information from the summary file or "nosummary" is set - else { - if("'"$q"'" == 0 && noheader != 1){ - - 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("'"$q"'" == "'"$LASTRUN"'") print "\n" >> outfile - } - } - - # output to a data-file with simple column-structure - # first if the LEM-summary files are present and "nosummary" has not been set - else { - if("'"$TEMPERATURE"'" != "") { - - # Write the dat-header - if("'"$q"'" == 0 && noheader != 1){ - - $1 = "T" - $2 = "Tr" - $3 = "E" - $4 = "RALRAR" - $5 = "RATRAB" - - for(k=1;k> outfile - } - - # Write the data-block - $1 = "'"$TEMPERATURE"'" - $2 = "'"$TRANSPORT"'" - if ("'"$ENERGY"'" != "") { $3 = "'"$ENERGY"'" } else { $3 = "-999" } - if ("'"$RALRAR"'" != "") { $4 = "'"$RALRAR"'" } else { $4 = "-999" } - if ("'"$RATRAB"'" != "") { $5 = "'"$RATRAB"'" } else { $5 = "-999" } - - 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++){ $(k+4) = indVarValue[k] } - break - } - } - } - - for(l=1;l> outfile - - if("'"$q"'" == "'"$LASTRUN"'") print "\n" >> outfile - } - - # If we do not have the information from the summary file or "nosummary" is set - # Writing to column-data file - else { - if("'"$q"'" == 0 && noheader != 1){ - - for(k=1;k> outfile - } - - # Write the data-block - - 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++){ $(k-1) = indVarValue[k] } - break - } - } - } - - for(l=1;l> outfile - - if("'"$q"'" == "'"$LASTRUN"'") print "\n" >> outfile - - } - } - } - }' $COUNT$EXTENSION.$OUTPUTEXT - done -fi