From eaa297ef6e6fd89973f6be43e01a08b12a04ae6a Mon Sep 17 00:00:00 2001 From: "Bastian M. Wojek" Date: Fri, 5 Sep 2008 19:44:45 +0000 Subject: [PATCH] Expanded mlog2db for use with non-consecutive runs. --- src/external/scripts/mlog2db | 135 +++++++++++++++++++++++++---------- 1 file changed, 96 insertions(+), 39 deletions(-) diff --git a/src/external/scripts/mlog2db b/src/external/scripts/mlog2db index b61d70d3..bc2c948d 100755 --- a/src/external/scripts/mlog2db +++ b/src/external/scripts/mlog2db @@ -12,13 +12,20 @@ if [ $# -lt 3 ] ; then "musrfit-mlog to db converter" USAGE: mlog2db FIRSTRUN# LASTRUN# BLABLA [noheader | fit-TEMPLATERUN# | -oDB_OUTPUT_FILE] + OR + mlog2db \[LIST OF RUNS\] BLABLA [noheader | fit-TEMPLATERUN# | -oDB_OUTPUT_FILE] This small script converts subsequent musrfit output files (mlog) into one db file using bash/awk. Example 1: mlog2db 1423 1424 _ZF-LF-TF-supermeasurement generates the db-file "out.db" (or whatever filename you specified with the -o option) from 1423_ZF-LF-TF-supermeasurement.mlog and 1424_ZF-LF-TF-supermeasurement.mlog . -It also includes the db header. + +Example 2: +mlog2db [1423 1425] _ZF-LF-TF-supermeasurement +generates the db-file "out.db" (or whatever filename you specified with the -o option) from 1423_ZF-LF-TF-supermeasurement.mlog and 1425_ZF-LF-TF-supermeasurement.mlog . + +The output files in both examples above also include the db header. In the case you are dealing with LEM-data AND have locally mounted the /mnt/data/nemu directory some available parameters like the temperature or transport settings will be taken from the summary files and added to the db-file. @@ -28,7 +35,7 @@ If you additionally want to fit some data using musrfit specify the option "fit- In this case either a mlog-outputfile or a msr-inputfile have to be present for the specified template run. The subsequent inputfiles will be created. -Example 2: +Example 3: mlog2db 200 220 _tf_h13 -oABC.db fit-199 This will fit the runs 200 to 220 using musrfit. The file 199_tf_h13.mlog (or if that is not available: 199_tf_h13.msr) is used as @@ -36,7 +43,7 @@ template for the first musrfit input file. The results of the fits will be writt CAUTION: -The "indexing number" of the .mlog has to be at the beginning of the filename. +The "indexing number" of the .mlog has to be at the begin of the filename. Furthermore the data files that were fitted have to have the name "XXX_RUN#[_YYY]", where XXX,YYY are strings without whitespaces ("/" is OK). If you want to use the fitting feature, musrfit has to be installed either on the PATH or in the working directory. @@ -47,15 +54,67 @@ else export PATH=./:$PATH -COUNT=$1 SUMMDIR="/mnt/data/nemu/summ" -if [ "${4:0:3}" == "fit" ]; then - TEMP=${4:4} -else if [ "${5:0:3}" == "fit" ]; then - TEMP=${5:4} -else if [ "${6:0:3}" == "fit" ]; then - TEMP=${6:4} +# In case a list of runs is given by [...] +if [ "${1:0:1}" == "[" ]; then + RUNARRAY=($@) + if [ "$1" == "[" ]; then + RUNARRAY[0]="" + else + RUNARRAY[0]=${RUNARRAY[0]#"["} + fi + tLen=${#RUNARRAY[@]} + for (( i=0; i<${tLen}; i++ )); + do + if [ "$1" == "[" ]; then + RUNARRAY[$i]=${RUNARRAY[ (( i + 1 )) ]} + fi + if [ "${RUNARRAY[$i]:(-1)}" == "]" ]; then + if [ "${RUNARRAY[$i]}" == "]" ]; then + RUNARRAY[$i]="" + LASTRUN=$(( i - 1 )) + EMPTYENTRY=1 + else + RUNARRAY[$i]=${RUNARRAY[$i]%"]"} + LASTRUN=$i + fi + fi +# echo ${RUNARRAY[$i]} + done + + if [ "$EMPTYENTRY" == "1" ]; then + EXTENSION=${RUNARRAY[ (( LASTRUN + 2 )) ]} + OPT_PAR_ONE=${RUNARRAY[ (( LASTRUN + 3 )) ]} + OPT_PAR_TWO=${RUNARRAY[ (( LASTRUN + 4 )) ]} + OPT_PAR_THREE=${RUNARRAY[ (( LASTRUN + 5 )) ]} + else + EXTENSION=${RUNARRAY[ (( LASTRUN + 1 )) ]} + OPT_PAR_ONE=${RUNARRAY[ (( LASTRUN + 2 )) ]} + OPT_PAR_TWO=${RUNARRAY[ (( LASTRUN + 3 )) ]} + OPT_PAR_THREE=${RUNARRAY[ (( LASTRUN + 4 )) ]} + fi + +else # start and end-runs are given + for (( j=0; j<=$2-$1; j++ )); + do + RUNARRAY[$j]=$(( $1 + $j )) +# echo ${RUNARRAY[$j]} + done + LASTRUN=$(( $2 - $1 )) + EXTENSION=$3 + OPT_PAR_ONE=$4 + OPT_PAR_TWO=$5 + OPT_PAR_THREE=$6 +fi + +# Check if fitting should be done +if [ "${OPT_PAR_ONE:0:3}" == "fit" ]; then + TEMP=${OPT_PAR_ONE:4} +else if [ "${OPT_PAR_TWO:0:3}" == "fit" ]; then + TEMP=${OPT_PAR_TWO:4} +else if [ "${OPT_PAR_THREE:0:3}" == "fit" ]; then + TEMP=${OPT_PAR_THREE:4} fi fi fi @@ -73,21 +132,21 @@ if [ "$TEMP" != "" ]; then exit 1 else - if [ -e $TEMP$3.mlog ]; then - TEMPLATE=$TEMP$3.mlog + if [ -e $TEMP$EXTENSION.mlog ]; then + TEMPLATE=$TEMP$EXTENSION.mlog else if [ -e $TEMP$3.msr ]; then - TEMPLATE=$TEMP$3.msr + TEMPLATE=$TEMP$EXTENSION.msr fi fi fi fi -while [ $COUNT -le $2 ] +for (( q=0; q<=${LASTRUN}; q++ )); do - -let NEXTCOUNT=COUNT+1 -NEXTINPUT=$NEXTCOUNT$3.msr -FIRSTINPUT=$1$3.msr +COUNT=${RUNARRAY[$q]} +NEXTCOUNT=${RUNARRAY[ (( q + 1 )) ]} +NEXTINPUT=$NEXTCOUNT$EXTENSION.msr +FIRSTINPUT=${RUNARRAY[0]}$EXTENSION.msr if [ "$TEMP" != "" ]; then @@ -96,8 +155,8 @@ if [ "$TEMP" != "" ]; then exit 1 fi - if [ "$COUNT" == "$1" ]; then - awk -v count=$TEMP -v nextcount=$1 -v nextinput=$FIRSTINPUT '{ + 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);} @@ -107,10 +166,10 @@ if [ "$TEMP" != "" ]; then else print $0 >> nextinput }' $TEMPLATE fi + + musrfit $COUNT$EXTENSION.msr -k - musrfit $COUNT$3.msr - - if [ $NEXTCOUNT -le $2 ]; then + if [ "$NEXTCOUNT" != "${RUNARRAY[$LASTRUN]}" ]; then awk -v count=$COUNT -v nextcount=$NEXTCOUNT -v nextinput=$NEXTINPUT '{ if(NR==1) print nextcount > nextinput else if($1 == "RUN") { @@ -119,12 +178,12 @@ if [ "$TEMP" != "" ]; then print $0 >> nextinput } else print $0 >> nextinput - }' $COUNT$3.mlog + }' $COUNT$EXTENSION.mlog fi fi -if [ ! -e $COUNT$3.mlog ]; then - echo The specified musrfit output file $COUNT$3.mlog does not exist! +if [ ! -e $COUNT$EXTENSION.mlog ]; then + echo The specified musrfit output file $COUNT$EXTENSION.mlog does not exist! exit 1 fi @@ -137,7 +196,7 @@ RUNNUMBER=$( awk '{ if(runNumber[1] ~ /lem/ && runNumber[2] == "his") {print substr(runNumber[3],1,4) } X=1 } - }' $COUNT$3.mlog ) + }' $COUNT$EXTENSION.mlog ) RUNYEAR=$( awk '{ if(NR==1) X=0 @@ -147,7 +206,7 @@ RUNYEAR=$( awk '{ else print "XX" X=1 } - }' $COUNT$3.mlog ) + }' $COUNT$EXTENSION.mlog ) if [ "$RUNYEAR" != "XX" ]; then @@ -169,12 +228,12 @@ fi fi -awk -v parFOUR=$4 -v parFIVE=$5 -v parSIX=$6 '{ +awk -v optPARone=$OPT_PAR_ONE -v optPARtwo=$OPT_PAR_TWO -v optPARthree=$OPT_PAR_THREE '{ outfile="out.db" - if(parFOUR ~ /^-o/) outfile = substr(parFOUR,3) - if(parFIVE ~ /^-o/) outfile = substr(parFIVE,3) - if(parSIX ~ /^-o/) outfile = substr(parSIX,3) + if(optPARone ~ /^-o/) outfile = substr(optPARone,3) + if(optPARtwo ~ /^-o/) outfile = substr(optPARtwo,3) + if(optPARthree ~ /^-o/) outfile = substr(optPARthree,3) FS = " " OFS = " " @@ -241,7 +300,7 @@ awk -v parFOUR=$4 -v parFIVE=$5 -v parSIX=$6 '{ if("'"$TEMPERATURE"'" != "") { - if("'"$COUNT"'" == "'"$1"'" && parFOUR != "noheader" && parFIVE != "noheader" && parSIX != "noheader"){ + if("'"$COUNT"'" == "'"${RUNARRAY[0]}"'" && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader"){ print "TITLE" >> outfile print ">>>Put your title here<<<\n" >> outfile print "Abstract" >> outfile @@ -285,14 +344,14 @@ awk -v parFOUR=$4 -v parFIVE=$5 -v parSIX=$6 '{ print dataArray[i+3] ",,, " "'"$TITLE"'" >> outfile - if("'"$COUNT"'" == "'"$2"'") print "\n" >> outfile + if("'"$COUNT"'" == "'"${RUNARRAY[$LASTRUN]}"'") print "\n" >> outfile } # If we do not have the information from the summary file else { - if("'"$COUNT"'" == "'"$1"'" && parFOUR != "noheader" && parFIVE != "noheader" && parSIX != "noheader"){ + if("'"$COUNT"'" == "'"${RUNARRAY[0]}"'" && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader"){ print "TITLE" >> outfile print ">>>Put your title here<<<\n" >> outfile print "Abstract" >> outfile @@ -321,15 +380,13 @@ awk -v parFOUR=$4 -v parFIVE=$5 -v parSIX=$6 '{ print dataArray[i+3] ",,, " title >> outfile - if("'"$COUNT"'" == "'"$2"'") print "\n" >> outfile + if("'"$COUNT"'" == "'"${RUNARRAY[LASTRUN]}"'") print "\n" >> outfile } } -}' $COUNT$3.mlog - -((COUNT++)) +}' $COUNT$EXTENSION.mlog done