Commit 0ba78bb5 authored by Florian Hindenlang's avatar Florian Hindenlang
Browse files

preparatory steps for python script, with [CI skip], CI should not be executed.

parent f9b3cc8a
Pipeline #11957 skipped
......@@ -46,7 +46,7 @@ contains
real(wp) :: wx, wy ! intermediate stage w, components x,y
! initial condition
x = x0 +2.
x = x0
y = 0.0_wp
! time loop
......
......@@ -24,4 +24,7 @@ program rk_solve
abs( x_in*cos(2.0_wp * real(num_st,wp)*dt) - x ) , &
abs( -2.0_wp*x_in*sin(2.0_wp * real(num_st,wp)*dt) - y ) )
write(*,*) " "
write(*,*) "PROGRAM RK_SOLVE FINISHED SUCCESSFULLY."
end program rk_solve
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import argparse
########################################################################################################
# HELPER ROUTINES (used by main program below)
########################################################################################################
# extract the error of the last line
def get_last_error(lines) :
tmp = [ line for line in lines if ("error is" in line)]
error = float(tmp[0].split(":")[1])
return error
########################################################################################################
def execute(execpath, case=0, project="default", keepdir=1, error_tol=0. , err= None ):
cwd = os.getcwd() #current working directory
print( " ")
print( "===> run ...")
testdir=("dirx_%d_%s" % (case,project) )
os.system('mkdir -p '+ testdir)
os.chdir(testdir)
cmdexec = ("../../%s" % execpath.strip() )
os.system(cmdexec+" 2>stderr 1>stdout")
stdout=open("stdout",'r').readlines()
stderr=open("stderr",'r').readlines()
success= False
for line in stdout :
if "FINISHED SUCCESSFULLY." in line :
success= True
if (not success) :
print("=============================================== ")
print(" !!!! PROBLEM WITH RUN, NOT FINISHED CORRECTLY!!!!! ")
print("=============================================== ")
print(" ")
err.extend(["caseID=%6d ,project= %s <=run" % (case,project)])
# go back to working directory and exit
os.chdir(cwd)
return success #=False
else :
print("=============================================== ")
print(" run finished sucessfully.")
print("=============================================== ")
print(" ")
print( " ")
print( "===> compare error ...")
error = get_last_error(stdout)
success = False
if(float(error) < float(error_tol)):
success = True
if (not success) :
print("=============================================== ")
print(" !!!! PROBLEM WITH ERROR COMPARISON, NOT BELOW TOLERANCE!!!!! ")
print(" %15.9e > tolerance=%15.e " %(error,error_tol))
print("=============================================== ")
print(" ")
err.extend(["caseID=%6d ,project= %s <=error" % (case,project)])
# go back to working directory and exit
os.chdir(cwd)
return success #=False
else :
print("=============================================== ")
print(" Error comparison successfull, %15.9e < %15.9e "%(error,error_tol))
print("=============================================== ")
print(" ")
# success still True, only delete sucessfull case directory if keepdir=0
os.chdir(cwd)
if(keepdir ==0) :
os.system('rm -rf '+testdir) #destroy directory
return success
########################################################################################################
# parse a str with comma separated ranges: 1,5,10-12
def parse_range(astr):
result = set()
for part in astr.split(','):
x = part.split('-')
result.update(range(int(x[0]), int(x[-1]) + 1))
return sorted(result)
########################################################################################################
# MAIN PROGRAM
########################################################################################################
parser = argparse.ArgumentParser(description='Tool to run tests')
parser.add_argument('-execpath', type=str, default='ode-1/rk_solve',help='path to executable, base is main folder,\n'
'default is "-execpath ode-1/rk-solve"')
#parser.add_argument('prm', help='path to parameter file')
parser.add_argument('-case', type=str, default='0', help="0 : DEFAULT, run all cases,\n"
"101,2-4 : list of specific cases to run (without spaces!) ")
parser.add_argument('-keepdir', type=int, default=1, help="1 : DEFAULT, keep all case directories,\n"
"0 : delete sucessfull case directories")
args = parser.parse_args()
cases = parse_range(args.case)
#list of errors in execute
collect_err= []
caseID =100
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
caseID=caseID+1
if(cases[0]==0 or (caseID in cases)) :
pname="first"
tol=0.2
print("caseID: %d name: %s" % (caseID,pname))
stat = execute(args.execpath,case=caseID,project=pname,\
keepdir=args.keepdir,error_tol=tol,err=collect_err)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
caseID=caseID+1
if(cases[0]==0 or (caseID in cases)) :
pname="second"
tol=0.1
print("caseID: %d name: %s" % (caseID,pname))
stat = execute(args.execpath,case=caseID,project=pname,\
keepdir=args.keepdir,error_tol=tol,err=collect_err)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#============================================================================
#FINAL ERROR HANDLING:
#============================================================================
if(len(collect_err) > 0 ) :
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("!!!!!!! WARNING, following cases failed: !!!!!!!!")
print(" ")
for line in collect_err :
print("--> "+line)
print(" ")
print("... see log.caseID_project files")
print(" and dirx_caseID_project folders.")
print(" rerun build script with -case option to run again spefic caseIDs.")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
sys.exit(100) #exit program with >0
else :
print("/////////////////////////////////////////////////////////")
print(" ")
print(" ==> ALL CASES WERE SUCCESSFULL!")
print(" ")
print("/////////////////////////////////////////////////////////")
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment