Skip to content

Commit

Permalink
Tags removed, only #OP necessary. No Order to respect
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmanelli committed Oct 14, 2014
1 parent 44d73fb commit 6586fd0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 72 deletions.
40 changes: 5 additions & 35 deletions AwkFiles/extractOps
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,10 @@ BEGIN{
ops_N=0
n_ops=1000;

undump="#UDOP_"
n_undump=1000

unfix="#UFIX_"
n_unfix=1000

op="(#OP_)"
op="(#OP)"
n_op=1000

restart="#ROP_"
n_restart=1000;

dump="#DOP_"
n_dump=1000

thermo="#THOP_"
n_thermo=1000

timestep="#TSOP_"
n_timestep=1000

run="run[ ]+([0-9]+)"
run="(run)[ ]+([0-9]+)"
n_run=1000

thermoinfo="#THERMO_INFO"
Expand All @@ -37,22 +19,10 @@ BEGIN{

}
(m=="match_op"||m=="all")&&match($0,op,str){n_op=NR; print str[1]; ops_N++}
NR==n_op+1&&match($1,"fix",str){print}
NR==n_op+1&&match($1,"fix"){print}
NR==n_op+1&&match($1,"(#)",str){print str[1]}
(m=="match_dump"||m=="all")&&match($0,dump,str){n_dump=NR; print}
NR==n_dump+1{print}
(m=="match_restart"||m=="all")&&match($0,restart,str){n_restart=NR; print}
NR==n_restart+1{print $2}
(m=="match_thermo"||m=="all")&&match($0,thermo,str){n_thermo=NR; print}
NR==n_thermo+1{print $2}
(m=="match_timestep"||m=="all")&&match($0,timestep,str){n_timestep=NR; print}
NR==n_timestep+1{print $2}
(m=="match_run"||m=="all")&&match($0,run,str){n_run=NR; print "#RUNOP"; print str[1]}
#NR==n_run+1{print $2}
(m=="match_undump"||m=="all")&&match($0,undump,str){n_undump=NR; print}
NR==n_undump+1{print}
(m=="match_unfix"||m=="all")&&match($0,unfix,str){n_unfix=NR; print}
NR==n_unfix+1{print}
(m=="match_run"||m=="all")&&match($0,run,str){n_run=NR; print str[1]" "str[2]}
(NR>n_op+1)&& !match($0,run,str){print}
(m=="match_endthinfo"||m=="all")&&match($0,endthermoinfo,str){n_endthinfo=NR; print}
(m=="match_thinfo"||m=="all")&&match($0,thermoinfo,str){n_thinfo=NR; print}
(NR>n_thinfo)&&(NR<n_endthinfo){print; n_th++}
Expand Down
83 changes: 46 additions & 37 deletions Scripts/updateRestart
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,55 @@
started="$(cat startedSimuList)"
if [ ! "$started" ]
then
# echo "Nothing found"
echo "Nothing found"
exit 0;
fi

simupath="$(gawk -f AwkFiles/getPath simuList)"
if [ ! "$simupath" ] || [ ! -d "$simupath" ]
then
# echo "Wrong path, please check the simuList file"
echo "Wrong path, please check the simuList file"
exit 1
fi

#echo "PATH: $simupath"
echo "PATH: $simupath"

list="$(cd "$simupath" && ls -l tmp.restart.*)"
lastRestartStep="$(echo "$list" | gawk -f AwkFiles/lastStep)"
if [ ! $lastRestartStep ]
then
# echo "Started but no restart.. same as if nothing was found"
echo "Started but no restart.. same as if nothing was found"
rm startedSimuList
exit 0
fi

#echo "LAST RESTART STEP: ${lastRestartStep}"
echo "LAST RESTART STEP: ${lastRestartStep}"

#-- FIND RESTART.INPUT FILE
input_restart_file="input.restart.in"
#echo "RESTART FILE: $input_restart_file"
echo "RESTART FILE: $input_restart_file"
#-- VERIFY RESTART FILE
if [ ! -f "${simupath}/${input_restart_file}" ]
then
# echo "No input restart template found ! Ereasing the simulation..."
echo "No input restart template found ! Ereasing the simulation..."
exit 3
fi
#-- FIND INPUT FILE
input_file="$(gawk -f AwkFiles/getInputFile simuList)"
#echo "INPUT FILE: $input_file"
echo "INPUT FILE: $input_file"
#-- VERIFY INPUT FILE
if [ ! -f "${simupath}/${input_file}.in" ]
then
# echo "No input file found in simuList! Ereasing the simulation..."
echo "No input file found in simuList! Ereasing the simulation..."
exit 4
fi
#-- FIND OUTPUT FILE
output_file="$(gawk -f AwkFiles/getOutputFile simuList)"
#echo "OUTPUT FILE: $output_file"
echo "OUTPUT FILE: $output_file"
# VERIFY OUTPUT FILE
if [ ! -f "${simupath}/${output_file}" ]
then
# echo "No output file found! Ereasing the simulation..."
echo "No output file found! Ereasing the simulation..."
exit 5
fi

Expand All @@ -64,38 +64,47 @@ thindex="$(gawk -v m='match_thindex' -f AwkFiles/extractOps ops_tmp)"
#-- FIND GENERAL THERMO INFO
gthermo="$(gawk "NR>1&&NR<(2+$thindex){print}" ops_tmp)"

#echo "OPS N: $ops_N"
#echo "THINDEX: $thindex"
#echo -e "GLOBAL THERMO:\n$gthermo"
echo "OPS N: $ops_N"
echo "THINDEX: $thindex"
echo -e "GLOBAL THERMO:\n$gthermo"

#-- FIND OPERATIONS #OP_X
#-- FIND RESTART STEP #ROP_X
#-- FIND DUMP INFO #DOP_X
#-- FIND THERMO INFO #THOP_X
#-- FIND TIMESTEP INFO #TSOP_X
#-- FIND RUN STEPS #RUNOP_X
run=()
for (( i = 1; i <= ${ops_N}; i++ ))
do
ops[$i]="$(gawk "NR==($i-1)*16+4+$thindex{print}" ops_tmp)"
dump[$i]="$(gawk "NR==($i-1)*16+6+$thindex{print}" ops_tmp)"
res[$i]="$(gawk "NR==($i-1)*16+8+$thindex{print}" ops_tmp)"
thermo[$i]="$(gawk "NR==($i-1)*16+10+$thindex{print}" ops_tmp)"
tstep[$i]="$(gawk "NR==($i-1)*16+12+$thindex{print}" ops_tmp)"
run[$i]="$(gawk "NR==($i-1)*16+14+$thindex{print}" ops_tmp)"
undump[$i]="$(gawk "NR==($i-1)*16+16+$thindex{print}" ops_tmp)"
unfix[$i]="$(gawk "NR==($i-1)*16+18+$thindex{print}" ops_tmp)"
# TODO: CHANGE BEHAVIOUR, BETWEEN 2 FIXES, WRITE ALL COMMANDS ?
opindex[1]="$(gawk 'match($0,"#OP",str){print NR+1; exit}' ops_tmp)"
ops[1]="$(gawk "NR==${opindex[1]}{print}" ops_tmp)"
for (( i = 2; i <= ${ops_N}; i++ ))
do
#-- SAVE OSP INDEXES ?
opindex[$i]="$(gawk 'NR>'${opindex[$i-1]}'&&match($0,"#OP",str){print NR+1; exit}' ops_tmp)"
ops[$i]="$(gawk "NR==${opindex[$i]}{print}" ops_tmp)"
# echo "OP: ${ops[$i-1]}"
cmdlist[$i-1]="$(gawk "NR>${opindex[$i-1]}&&NR<${opindex[$i]}-1{print}" ops_tmp)"
run[$i-1]="$(gawk 'NR>'${opindex[$i-1]}'&&NR<'${opindex[$i]}-1'&&match($0,"run[ ]+([0-9]+)",s){print s[1]}' ops_tmp)"
# echo -e "Cmd $i :\n${cmdlist[$i-1]}"
# echo "RUN: ${run[$i-1]}"
done
#echo "OP: ${ops[$i-1]}"
opindex[$i]="$(gawk 'match($0,"#N_OPS",str){print NR+1; exit}' ops_tmp)"
run[$i-1]="$(gawk 'NR>'${opindex[$i-1]}'&&NR<'${opindex[$i]}-1'&&match($0,"run[ ]+([0-9]+)",s){print s[1]}' ops_tmp)"
cmdlist[$i-1]="$(gawk "NR>${opindex[$i-1]}&&NR<${opindex[$i]}-1{print}" ops_tmp)"
#echo -e "Cmd $i :\n${cmdlist[$i-1]}"
#echo "RUN: ${run[$i-1]}"

# WITH THE TMP.RESTART.STEP INFO:
# MATCH THE LAST PARTIAL OPERATION PERFORMED COMPARING WITH RUN STEPS
#-- MATCH THE LAST PARTIAL OPERATION PERFORMED COMPARING WITH RUN STEPS
laststep="$(cat ${simupath}/${output_file} | awk 'BEGIN{ go=0}go==1&&match($1,"[0-9]+",step){print $1}go==0&&match($1,"Step"){go=1}go==1&&match($1,"Loop"){go=0}' | gawk 'END{print}')"
#echo "LAST SIMU STEP: $laststep"
echo "LAST SIMU STEP: $laststep"

tmprun=0
for (( i = 1; i <= ${ops_N}; i++ ))
do
tmprun=$(( $tmprun + ${run[$i]} ))

if (( $tmprun > ${lastRestartStep} ))
then
if [ "${ops[$i]}" == "#" ]
Expand All @@ -108,8 +117,8 @@ do
done
fi

# echo "LAST RUN (WHERE RESTART TOOK PLACE): ${ops[$i]}"
# echo "LAST RUN STEP (WHERE RESTART TOOK PLACE): ${run[$i]}"
echo "LAST RUN (WHERE RESTART TOOK PLACE): ${ops[$i]}"
echo "LAST RUN STEP (WHERE RESTART TOOK PLACE): ${run[$i]}"
break
fi
done
Expand All @@ -119,21 +128,21 @@ done
cat "${simupath}/${input_restart_file}" > "${simupath}/${input_file}.restart.${lastRestartStep}.in"
input_restart_file="${simupath}/${input_file}.restart.${lastRestartStep}.in"
sed -i {'s/\(read_restart[\t ]*\)\(.*\)/\1 tmp.restart.'"${lastRestartStep}"'/'} ${input_restart_file}
#-- PUT THE STEPS LEFT TO COMPLETE THE LAST OPERATION
#-- PUT THE OPERATIONS NOT PERFORMED
echo "#THERMO_INFO" >> ${input_restart_file}
echo -e "${gthermo}" >> ${input_restart_file}
echo -e "#END_THERMO_INFO\n" >> ${input_restart_file}
echo -e "#OP_\n${ops[$i]}\n#DOP_\n${dump[$i]}\n#ROP_\nrestart ${res[$i]} tmp.restart.*" >> ${input_restart_file}
echo -e "#THOP_\nthermo ${thermo[$i]}\n#TSOP_\ntimestep ${tstep[$i]}\n#RUNOP_\nrun $(( ${tmprun} - ${lastRestartStep} ))" >> ${input_restart_file}
echo -e "#UDOP_\n${undump[$i]}\n#UFIX_\n${unfix[$i]}\n\n" >> ${input_restart_file}
for (( h = (( $i + 1 )); h <= ${ops_N}; h++ ))

for (( h = $i; h <= ${ops_N}; h++ ))
do
echo -e "#OP_\n${ops[$h]}\n#DOP_\n${dump[$h]}\n#ROP_\nrestart ${res[$h]} tmp.restart.*" >> ${input_restart_file}
echo -e "#THOP_\nthermo ${thermo[$h]}\n#TSOP_\ntimestep ${tstep[$h]}\n#RUNOP_\nrun ${run[$h]}" >> ${input_restart_file}
echo -e "#UDOP_\n${undump[$h]}\n#UFIX_\n${unfix[$h]}\n\n" >> ${input_restart_file}
echo -e "#OP\n${ops[$h]}\n${cmdlist[$h]}\n" >> ${input_restart_file}
done

#-- PUT THE STEPS LEFT TO COMPLETE THE LAST OPERATION
sed -i {'1,/\(run[\t ]*\)\(.*\)/s/\(run[\t ]*\)\(.*\)/\1 '"$(( ${tmprun} - ${lastRestartStep} ))"'/'} ${input_restart_file}

exit 0

# WITH SIMULIST FILE:
#-- FIND THE FIRST SIMULATION AND CHANGE THE INPUT AND OUTPUT
gawk -v s=${lastRestartStep} -f AwkFiles/cmdUpdateRestart simuList > simuList_TMP
Expand Down

0 comments on commit 6586fd0

Please sign in to comment.