mlog2db handles optional parameters more flexible and supports comments in the parameter block

This commit is contained in:
Bastian M. Wojek 2008-10-09 17:08:51 +00:00
parent 0f661ce441
commit 3c91c88bb0

View File

@ -107,7 +107,7 @@ else
done done
# search for the parameter including the "]" # search for the parameter including the "]"
for (( i=0; i<="$#"; i++ )) for (( i=1; i<="$#"; i++ ))
do do
RIGHTBRACKET=$( eval echo \$$i ) RIGHTBRACKET=$( eval echo \$$i )
if [ "${RIGHTBRACKET:(-1)}" == "]" ]; then if [ "${RIGHTBRACKET:(-1)}" == "]" ]; then
@ -126,12 +126,8 @@ else
fi fi
EXTENSION=$( eval echo \$$((RIGHTBRACKET + 1)) ) EXTENSION=$( eval echo \$$((RIGHTBRACKET + 1)) )
OPT_PAR_ONE=$( eval echo \$$((RIGHTBRACKET + 2)) ) FIRST_OPT_PAR=$((RIGHTBRACKET + 2))
OPT_PAR_TWO=$( eval echo \$$((RIGHTBRACKET + 3)) ) LAST_OPT_PAR=$#
OPT_PAR_THREE=$( eval echo \$$((RIGHTBRACKET + 4)) )
OPT_PAR_FOUR=$( eval echo \$$((RIGHTBRACKET + 5)) )
OPT_PAR_FIVE=$( eval echo \$$((RIGHTBRACKET + 6)) )
OPT_PAR_SIX=$( eval echo \$$((RIGHTBRACKET + 7)) )
RUNLIST_USED=0 RUNLIST_USED=0
NUM_OF_IND_VAR=1 # 1 for the run number NUM_OF_IND_VAR=1 # 1 for the run number
@ -155,12 +151,8 @@ else
EXTENSION=$3 EXTENSION=$3
OPT_PAR_ONE=$4 FIRST_OPT_PAR=4
OPT_PAR_TWO=$5 LAST_OPT_PAR=$#
OPT_PAR_THREE=$6
OPT_PAR_FOUR=$7
OPT_PAR_FIVE=$8
OPT_PAR_SIX=$9
RUNLIST_USED=0 RUNLIST_USED=0
NUM_OF_IND_VAR=1 # 1 for the run number NUM_OF_IND_VAR=1 # 1 for the run number
@ -170,12 +162,8 @@ else
LASTRUN=0 # RUNARRAY-index of the last run LASTRUN=0 # RUNARRAY-index of the last run
EXTENSION=$2 EXTENSION=$2
OPT_PAR_ONE=$3 FIRST_OPT_PAR=3
OPT_PAR_TWO=$4 LAST_OPT_PAR=$#
OPT_PAR_THREE=$5
OPT_PAR_FOUR=$6
OPT_PAR_FIVE=$7
OPT_PAR_SIX=$8
RUNLIST_USED=0 RUNLIST_USED=0
NUM_OF_IND_VAR=1 # 1 for the run number NUM_OF_IND_VAR=1 # 1 for the run number
@ -204,30 +192,21 @@ else
LASTRUN=$(( ${#RUNARRAY[@]} - 1 )) # RUNARRAY-index of the last run LASTRUN=$(( ${#RUNARRAY[@]} - 1 )) # RUNARRAY-index of the last run
EXTENSION=$2 EXTENSION=$2
OPT_PAR_ONE=$3 FIRST_OPT_PAR=3
OPT_PAR_TWO=$4 LAST_OPT_PAR=$#
OPT_PAR_THREE=$5
OPT_PAR_FOUR=$6
OPT_PAR_FIVE=$7
OPT_PAR_SIX=$8
RUNLIST_USED=1 RUNLIST_USED=1
fi fi
fi fi
# Check if fitting should be done # Check if fitting should be done
if [ "${OPT_PAR_ONE:0:3}" == "fit" ]; then TEMP=""
TEMP=${OPT_PAR_ONE:4} for PAR in "$@"
elif [ "${OPT_PAR_TWO:0:3}" == "fit" ]; then do
TEMP=${OPT_PAR_TWO:4} if [ "${PAR:0:3}" == "fit" ]; then
elif [ "${OPT_PAR_THREE:0:3}" == "fit" ]; then TEMP=${PAR:4}
TEMP=${OPT_PAR_THREE:4} break
elif [ "${OPT_PAR_FOUR:0:3}" == "fit" ]; then
TEMP=${OPT_PAR_FOUR:4}
elif [ "${OPT_PAR_FIVE:0:3}" == "fit" ]; then
TEMP=${OPT_PAR_FIVE:4}
elif [ "${OPT_PAR_SIX:0:3}" == "fit" ]; then
TEMP=${OPT_PAR_SIX:4}
fi fi
done
if [ "$TEMP" != "" ]; then # runs should be fitted using musrfit if [ "$TEMP" != "" ]; then # runs should be fitted using musrfit
@ -269,6 +248,12 @@ else
if(NR==1) print nextcount > nextinput if(NR==1) print nextcount > nextinput
else if($1 == "RUN") { else if($1 == "RUN") {
if (substr(count,1,1) != "_"){ count = sprintf("_%04u", count); nextcount = sprintf("_%04u", nextcount);} 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); sub(count, nextcount, $0);
print $0 >> nextinput print $0 >> nextinput
} }
@ -276,11 +261,18 @@ else
}' $TEMPLATE }' $TEMPLATE
fi fi
if [ "${OPT_PAR_ONE}" == "-k" ] || [ "${OPT_PAR_TWO}" == "-k" ] || [ "${OPT_PAR_THREE}" == "-k" ] || [ "${OPT_PAR_FOUR}" == "-k" ] \ MUSRFITPARAM=""
|| [ "${OPT_PAR_FIVE}" == "-k" ] || [ "${OPT_PAR_SIX}" == "-k" ]; then for PAR in "$@"
do
if [ "$PAR" == "-k" ]; then
MUSRFITPARAM="-k" MUSRFITPARAM="-k"
break
fi fi
done
echo
echo ">> mlog2db: musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM"
echo
musrfit $COUNT$EXTENSION.msr $MUSRFITPARAM # the fit 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 if [ "$q" -ne "$LASTRUN" ]; then # create the next musrfit input file if not the last specified run was fitted already
@ -288,6 +280,12 @@ else
if(NR==1) print nextcount > nextinput if(NR==1) print nextcount > nextinput
else if($1 == "RUN") { else if($1 == "RUN") {
if (substr(count,1,1) != "_"){ count = sprintf("_%04u", count); nextcount = sprintf("_%04u", nextcount);} 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); sub(count, nextcount, $0);
print $0 >> nextinput print $0 >> nextinput
} }
@ -304,8 +302,16 @@ else
fi fi
# if the "nosummary"-option is not set and the summary files are present, get some information from there # 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" ] \ NOSUMMARY=0
&& [ "${OPT_PAR_FOUR}" != "nosummary" ] && [ "${OPT_PAR_FIVE}" != "nosummary" ] && [ "${OPT_PAR_SIX}" != "nosummary" ]; then for PAR in "$@"
do
if [ "$PAR" == "nosummary" ]; then
NOSUMMARY=1
break
fi
done
if [ "$NOSUMMARY" -eq 0 ]; then
if [ -d $SUMMDIR ]; then if [ -d $SUMMDIR ]; then
# extract runnumber from mlog-file # extract runnumber from mlog-file
@ -342,71 +348,52 @@ else
fi fi
fi fi
# put together all data to db-format and write it to the file # determine the output-file
awk -v optPARone=$OPT_PAR_ONE -v optPARtwo=$OPT_PAR_TWO -v optPARthree=$OPT_PAR_THREE -v optPARfour=$OPT_PAR_FOUR \ OUTFILE="out.db"
-v optPARfive=$OPT_PAR_FIVE -v optPARsix=$OPT_PAR_SIX -v runList=$RUNLIST_USED -v numIndVar=$NUM_OF_IND_VAR '{
outfile="out.db" for (( l="$FIRST_OPT_PAR"; l<="$LAST_OPT_PAR"; l++ ))
if(optPARone ~ /^-o/){ do
if(optPARone == "-o"){ CUR_PAR=$( eval echo \$$l )
if(optPARtwo != "noheader" && optPARtwo != "nosummary" && optPARtwo !~ /^fit/ && optPARtwo != "-k"){ NEXT_PAR=$( eval echo \$$((l+1)) )
outfile = optPARtwo if [ "${CUR_PAR:0:2}" == "-o" ]; then
} if [ "$CUR_PAR" == "-o" ]; then
else if(NR==1) print ">> mlog2db: You did not specify an output file! The default one (out.db) will be used." if [ "$l" -ne "$LAST_OPT_PAR" ] && [ "$NEXT_PAR" != "noheader" ] && [ "$NEXT_PAR" != "nosummary" ] \
} && [ "${NEXT_PAR:0:3}" != "fit" ] && [ "$NEXT_PAR" != "-k" ]; then
else outfile = substr(optPARone,3) OUTFILE=$NEXT_PAR
} break
else if(optPARtwo ~ /^-o/){ else
if(optPARtwo == "-o"){ echo
if(optPARthree != "noheader" && optPARthree != "nosummary" && optPARthree !~ /^fit/ && optPARthree != "-k"){ echo ">> mlog2db: You did not specify an output file! The default one (out.db) will be used."
outfile = optPARthree echo
} fi
else if(NR==1) print ">> mlog2db: You did not specify an output file! The default one (out.db) will be used." else
} OUTFILE=${CUR_PAR:2}
else outfile = substr(optPARtwo,3) break
} fi
else if(optPARthree ~ /^-o/){ fi
if(optPARthree == "-o"){ done
if(optPARfour != "noheader" && optPARfour != "nosummary" && optPARfour !~ /^fit/ && optPARfour != "-k"){
outfile = optPARfour # determine, if the db-header should be written to the output file, default: YES
} NOHEADER=0
else if(NR==1) print ">> mlog2db: You did not specify an output file! The default one (out.db) will be used." for PAR in "$@"
} do
else outfile = substr(optPARthree,3) if [ "$PAR" == "noheader" ]; then
} NOHEADER=1
else if(optPARfour ~ /^-o/){ break
if(optPARfour == "-o"){ fi
if(optPARfive != "noheader" && optPARfive != "nosummary" && optPARfive !~ /^fit/ && optPARfive != "-k"){ done
outfile = optPARfive
} # put together all data to db-format and write it to the file
else if(NR==1) print ">> mlog2db: You did not specify an output file! The default one (out.db) will be used." awk -v outfile=$OUTFILE -v noheader=$NOHEADER -v runList=$RUNLIST_USED -v numIndVar=$NUM_OF_IND_VAR '{
}
else outfile = substr(optPARfour,3)
}
else if(optPARfive ~ /^-o/){
if(optPARfive == "-o"){
if(optPARsix != "noheader" && optPARsix != "nosummary" && optPARsix !~ /^fit/ && optPARsix != "-k"){
outfile = optPARsix
}
else if(NR==1) print ">> mlog2db: You did not specify an output file! The default one (out.db) will be used."
}
else outfile = substr(optPARfive,3)
}
else if(optPARsix ~ /^-o/){
if(optPARsix == "-o"){
if(NR==1) print ">> mlog2db: You did not specify an output file! The default one (out.db) will be used."
}
else outfile = substr(optPARsix,3)
}
FS = " " FS = " "
OFS = " " OFS = " "
if(NR==1){title=$0; X=0; Y=0; i=1} if(NR==1){title=$0; X=0; Y=0; i=1}
if(NR>4){ if(NR>1){
if(X == 0){ if(X == 0){
if($0 != ""){ if($1 == i){
parArray[i] = $2 parArray[i] = $2
dataArray[i] = $3 dataArray[i] = $3
if($4 ~ /^-/) if($4 ~ /^-/)
@ -419,7 +406,7 @@ else
posErrArray[i] = $5 posErrArray[i] = $5
i++ i++
} }
if($0 == "") X=1 if($1 ~ /^THEORY/) X=1
} }
} }
@ -469,7 +456,7 @@ else
if("'"$TEMPERATURE"'" != "") { if("'"$TEMPERATURE"'" != "") {
# Write the db-header # Write the db-header
if("'"$q"'" == 0 && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader" && optPARfour != "noheader" && optPARfive != "noheader" && optPARsix != "noheader"){ if("'"$q"'" == 0 && noheader != 1){
print "TITLE" >> outfile print "TITLE" >> outfile
print ">>>Put your title here<<<\n" >> outfile print ">>>Put your title here<<<\n" >> outfile
@ -540,7 +527,7 @@ else
# If we do not have the information from the summary file or "nosummary" is set # If we do not have the information from the summary file or "nosummary" is set
else { else {
if("'"$q"'" == 0 && optPARone != "noheader" && optPARtwo != "noheader" && optPARthree != "noheader" && optPARfour != "noheader" && optPARfive != "noheader" && optPARsix != "noheader"){ if("'"$q"'" == 0 && noheader != 1){
print "TITLE" >> outfile print "TITLE" >> outfile
print ">>>Put your title here<<<\n" >> outfile print ">>>Put your title here<<<\n" >> outfile