1 | import os |
---|
2 | import sys |
---|
3 | |
---|
4 | |
---|
5 | from user_param import * |
---|
6 | |
---|
7 | def main(): |
---|
8 | |
---|
9 | configNamePattern=[0, 0, 0, 0, 0, 0] |
---|
10 | |
---|
11 | f=open("user_param.py", "r") |
---|
12 | for line in f: |
---|
13 | line = line.strip() |
---|
14 | if line.startswith("UsingServer2"): |
---|
15 | configNamePattern[0] = '_UsingSrv2=' + UsingServer2 |
---|
16 | elif line.startswith("RatioServer2"): |
---|
17 | configNamePattern[1] = '_RatioSrv2=' + repr(RatioServer2) |
---|
18 | elif line.startswith("NumberPoolsServer2"): |
---|
19 | configNamePattern[2] = '_NbPoolsSrv2=' + repr(NumberPoolsServer2) |
---|
20 | elif line.startswith("NumberClients"): |
---|
21 | configNamePattern[3] = '_NbClients=' + repr(NumberClients) |
---|
22 | elif line.startswith("NumberServers"): |
---|
23 | configNamePattern[4] = '_NbServers=' + repr(NumberServers) |
---|
24 | elif line.startswith("Duration"): |
---|
25 | configNamePattern[5] = '_Duration=' + Duration |
---|
26 | f.close() |
---|
27 | |
---|
28 | |
---|
29 | configName = "config" |
---|
30 | defaultConfig = True |
---|
31 | |
---|
32 | for i in range(len(configNamePattern)): |
---|
33 | if configNamePattern[i] != 0: |
---|
34 | configName = configName + configNamePattern[i] |
---|
35 | defaultConfig = False |
---|
36 | |
---|
37 | if defaultConfig: |
---|
38 | configName = "config_default" |
---|
39 | |
---|
40 | |
---|
41 | if not os.path.exists(configName): |
---|
42 | os.mkdir(configName) |
---|
43 | print("\n ****************************************************************") |
---|
44 | print(" * Directory " + repr(configName) + " Created ") |
---|
45 | print(" * Copy results to \'not_validated_reference\' folder") |
---|
46 | print(" ****************************************************************\n") |
---|
47 | |
---|
48 | os.mkdir(configName+'/setup') |
---|
49 | os.mkdir(configName+'/tmp_reference') |
---|
50 | |
---|
51 | os.system('cp param.def '+configName+'/setup/') |
---|
52 | os.system('cp iodef.xml '+configName+'/setup/') |
---|
53 | os.system('cp context_atm.xml '+configName+'/setup/') |
---|
54 | os.system('cp context_grid_dynamico.xml '+configName+'/setup/') |
---|
55 | os.system('cp dynamico_grid.nc '+configName+'/setup/') |
---|
56 | |
---|
57 | os.system('cp atm_output.nc '+configName+'/tmp_reference/') |
---|
58 | # os.system('cp -r '+configName+'/tmp_reference/ ' + configName+'/reference/') |
---|
59 | |
---|
60 | else: |
---|
61 | print("\n ********************************************************") |
---|
62 | print(" * Directory " + repr(configName) + " already exists") |
---|
63 | print(" * Start comparing results with (tmp) references") |
---|
64 | print(" ********************************************************\n") |
---|
65 | |
---|
66 | tmp_ref = os.path.isdir(configName+'/tmp_reference') |
---|
67 | ref = os.path.isdir(configName+'/reference') |
---|
68 | |
---|
69 | if ref: |
---|
70 | print("\n =====================================") |
---|
71 | print(" | Comparing results with references |") |
---|
72 | print(" =====================================\n") |
---|
73 | os.system('rm -rf '+configName+'/tmp_reference/') |
---|
74 | tmp_ref = False |
---|
75 | path = configName+'/reference/' |
---|
76 | elif tmp_ref: |
---|
77 | print("\n ===================================================") |
---|
78 | print(" | Comparing results with NON-Validated references |") |
---|
79 | print(" ===================================================\n") |
---|
80 | path = ' '+configName+'/tmp_reference/' |
---|
81 | |
---|
82 | # os.system('> diff.txt') |
---|
83 | |
---|
84 | f=open("checkfile.def", "r") |
---|
85 | g=open("diff.txt", "w+r") |
---|
86 | h=open("report.txt", "a+") |
---|
87 | |
---|
88 | for line in f: |
---|
89 | line=line.strip() |
---|
90 | line=line.rstrip() |
---|
91 | if not line.startswith("#") and len(line) != 0: |
---|
92 | cmd = 'cdo diffn '+ line + path + line + ' | tail -1 > diff.txt' |
---|
93 | # print(cmd) |
---|
94 | os.system(cmd) |
---|
95 | |
---|
96 | for gline in g: |
---|
97 | if gline.strip().startswith("0"): |
---|
98 | h.write("test for "+configName+" for file "+line+" \tPASSED\n") |
---|
99 | print "\n ****************************************" |
---|
100 | print " ** "+line+" is valid !!! **" |
---|
101 | print "\n ****************************************" |
---|
102 | else: |
---|
103 | h.write("test for "+configName+" failed for "+line+" \tFAILED\n") |
---|
104 | print "\n **************************************************" |
---|
105 | print " ** "+line+" is NOT valid. Please debugging.. **" |
---|
106 | print "\n **************************************************" |
---|
107 | f.close() |
---|
108 | |
---|
109 | |
---|
110 | |
---|
111 | |
---|
112 | if __name__== "__main__": |
---|
113 | main() |
---|