Skip to content

Commit

Permalink
First working version ! IL FAUT TESTER
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmanelli committed Oct 10, 2014
1 parent 010ddc5 commit 792ad90
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 70 deletions.
18 changes: 18 additions & 0 deletions AwkFiles/cleanCmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BEGIN{
pat="([0-9]+) ([0-9]+)"
}
match($0,pat,n){
print "Cleaning simulation number "n[1]", with timestamp of: "n[2]
}
END{
if(n[1]){
system("gawk -v n="n[1]" -f AwkFiles/rmDoneFromList simuList > simuList_TMP")
system("gawk -v n="n[1]" -f AwkFiles/rmDoneFromStarted startedSimuList > startedSimuList_TMP")
} else {
system("gawk -v n=0 -f AwkFiles/rmDoneFromList simuList > simuList_TMP")
system("gawk -v n=0 -f AwkFiles/rmDoneFromStarted startedSimuList > startedSimuList_TMP")
}

system("rm simuList && rm startedSimuList && rm doneSimuList");
system("mv simuList_TMP simuList && mv startedSimuList_TMP startedSimuList");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,9 @@ a "#" at than line:

#OP_
#

When a stopped simulation is found, this program searches for a file called
_input.restart.in_ that is a template with the common information for all
simulation fixes. Then it adds to this template the pending operations and
stores the new file in input.restart.STEP.in WITHOUT modifying the template.
It is necessary to leave a template file for this program to work.
4 changes: 2 additions & 2 deletions checkPid → Scripts/checkPid
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

RUNPID="$(ps -e --sort -pid | grep simuStack | awk -v thisPid="$1" -f notThisPid)"
RUNPID="$(ps -e --sort -pid | grep simuStack | awk -v thisPid="$1" -f AwkFiles/notThisPid)"

if [ -f stackPid ]
then
FILEPID="$(cat stackPid | awk -f extractPid)"
FILEPID="$(cat stackPid | awk -f AwkFiles/extractPid)"
fi

if [ ! $RUNPID ];
Expand Down
3 changes: 3 additions & 0 deletions Scripts/cleanStackList
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

gawk -f AwkFiles/cleanCmd doneSimuList
69 changes: 35 additions & 34 deletions updateRestart → Scripts/updateRestart
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
#!/bin/bash

started="$(cat startedSimuList)"
if [ ! $started ];
if [ ! "$started" ]
then
echo "Nothing found"
# echo "Nothing found"
exit 0;
fi

simupath="$(gawk -f getPath simuList)"
if [ ! $simupath ];
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 lastStep)"
if [ ! $lastRestartStep ];
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="$(cd "$simupath" && ls -l input.restart.in | gawk '{print $NF}')"
echo "RESTART FILE: $input_restart_file"
input_restart_file="input.restart.in"
#echo "RESTART FILE: $input_restart_file"
#-- VERIFY RESTART FILE
if [ ! -f ${simupath}/${input_restart_file} ]
if [ ! -f "${simupath}/${input_restart_file}" ]
then
echo "No input restart template found ! Ereasing the simulation..."
exit 4
# echo "No input restart template found ! Ereasing the simulation..."
exit 3
fi
#-- FIND INPUT FILE
input_file="$(gawk -f getInputFile simuList)"
echo "INPUT FILE: $input_file"
input_file="$(gawk -f AwkFiles/getInputFile simuList)"
#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..."
exit 5
# echo "No input file found in simuList! Ereasing the simulation..."
exit 4
fi
#-- FIND OUTPUT FILE
output_file="$(gawk -f getOutputFile simuList)"
echo "OUTPUT FILE: $output_file"
output_file="$(gawk -f AwkFiles/getOutputFile simuList)"
#echo "OUTPUT FILE: $output_file"
# VERIFY OUTPUT FILE
if [ ! -f "${simupath}/${output_file}" ]
then
echo "No output file found! Ereasing the simulation..."
exit 6
# echo "No output file found! Ereasing the simulation..."
exit 5
fi

# WITH INPUT FILE:
gawk -v m='all' -f extractOps ${simupath}/${input_file}".in" > ops_tmp
gawk -v m='all' -f AwkFiles/extractOps ${simupath}/${input_file}".in" > ops_tmp
#-- FIND N OF OPERATIONS
ops_N="$(gawk -v m='match_nops' -f extractOps ops_tmp)"
ops_N="$(gawk -v m='match_nops' -f AwkFiles/extractOps ops_tmp)"
#-- FIND NUMBER OF GENERAL THERMO LINES
thindex="$(gawk -v m='match_thindex' -f extractOps ops_tmp)"
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
Expand All @@ -90,7 +90,7 @@ done
# WITH THE TMP.RESTART.STEP INFO:
# 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++ ))
Expand All @@ -108,8 +108,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 @@ -136,9 +136,10 @@ done

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

exit 2
exit 6
18 changes: 0 additions & 18 deletions cleanCmd

This file was deleted.

3 changes: 0 additions & 3 deletions cleanStackList

This file was deleted.

Empty file removed simuList
Empty file.
37 changes: 24 additions & 13 deletions simuStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#define SIMULIST_OK 0
#define WRONG_PATH 1
#define STOPPED_FOUND 2
#define NO_TEMPLATE 3
#define NO_INPUT_FILE 4
#define NO_OUTPUT_FILE 5
#define UDPATE_DONE 6

using namespace std;

Expand Down Expand Up @@ -51,7 +54,7 @@ int main(int argc, char** argv){
fstream donelist;
fstream logfile;

sprintf(cmd,"./checkPid %d",stackID);
sprintf(cmd,"./Scripts/checkPid %d",stackID);
exitCode = system(cmd);
if( (WEXITSTATUS(exitCode) == STACK_RUNNING) || \
(WEXITSTATUS(exitCode) == STACK_FILE_CHANGED) || \
Expand All @@ -73,17 +76,25 @@ int main(int argc, char** argv){
//TODO: REEMPLAZAR EN EL INPUT RESTART EL VALOR DE RESTART MAYOR ENCONTRADO EN LA CARPETA
//TODO: NORMALIZAR LOS COMANDOS, i.e: PRIMERO UN CD (PARA UBICARSE)
cout << endl << "Cleaning simulation list..." << endl;
system("./cleanStackList");
system("./Scripts/cleanStackList");

cout << endl << "Looking for stopped simulations..." << endl;
exitCode=system("./updateRestart");
if( WEXITSTATUS(exitCode) == STOPPED_FOUND){
cout << "Found stopped simulations, updating simuList file..." << endl;
} else if( WEXITSTATUS(exitCode) == WRONG_PATH){
cout << "Found wrong path, please check simuList file..." << endl;
} else if( WEXITSTATUS(exitCode) == SIMULIST_OK){
cout << "Nothing found. OK" << endl;
}
exitCode=system("./Scripts/updateRestart");
if( WEXITSTATUS(exitCode) == WRONG_PATH ){
cout << "Found wrong path. Verify and launch again." << endl;
exit(1);
} else if( WEXITSTATUS(exitCode) == NO_TEMPLATE ){
cout << "No input restart template found! Verify and launch again." << endl;
exit(1)
} else if( WEXITSTATUS(exitCode) == NO_INPUT_FILE ){
cout << "No input file found! Verify and launch again." << endl;
exit(1)
} else if( WEXITSTATUS(exitCode) == NO_OUTPUT_FILE ){
cout << "No output file found! Verify and launch again." << endl;
} else if( (WEXITSTATUS(exitCode) == SIMULIST_OK) || \
(WEXITSTATUS(exitCode) == UPDATE_DONE) ){
cout << "Update done. OK" << endl;
}

cout << "Stack ready to run." << endl;

Expand Down Expand Up @@ -120,7 +131,7 @@ int main(int argc, char** argv){
int err = system(line.c_str());

openStream(logfile, log, fstream::out | fstream::app);
logfile << "(Up) Command completed with error code: " << err << endl;
logfile << "(Up) Command completed with error code: " << WEXITSTATUS(err) << endl;
logfile << "#################################################" << endl << endl;
logfile.close();

Expand Down

0 comments on commit 792ad90

Please sign in to comment.