5def merge(forIFiles_h=[],prdIFiles_h=[],carbonIFiles_h=[],scenarios_h=[],forOFilename_h="",prdOFilename_h="",carbonOFilename_h="", variables_h=[], regions_h=[], years_h=[]):
6 print(
"*** Processing..")
8 open(forOFilename_h,
'w').close()
10 open(prdOFilename_h,
'w').close()
11 if len(carbonIFiles_h)>0:
12 open(carbonOFilename_h,
'w').close()
16 for forIFile
in forIFiles_h:
17 merge_single_file(forIFile, forOFilename_h, scenarios_h,
False if forCounter
else True, variables_h, regions_h, years_h)
19 for prdIFile
in prdIFiles_h:
20 merge_single_file(prdIFile, prdOFilename_h, scenarios_h,
False if prdCounter
else True, variables_h, regions_h, years_h)
22 for carbonIFile
in carbonIFiles_h:
23 merge_single_file(carbonIFile, carbonOFilename_h, scenarios_h,
False if carbonCounter
else True, variables_h, regions_h, years_h)
42def merge_single_file(i_filename_h, o_filename_h, scenarios_h, keepHeader=False, variables_h=[], regions_h=[], years_h=[]):
43 i_file = open(i_filename_h,
'r')
44 o_file = open(o_filename_h,
'a')
53 row = i_file.readline()
54 scenarioFilter =
False
55 variableFilter =
False
64 parNamePos = positions[0]
65 regionPos = positions[1]
66 yearPos = positions[2]
70 fields = row.split(
';')
71 rowScenario = fields[0]
73 if(rowScenario
in scenarios_h):
76 if( (len(variables_h) == 0 )
or (fields[parNamePos]
in variables_h) ):
79 if( (len(regions_h) == 0)
or (fields[regionPos]
in regions_h) ):
82 if( (len(years_h) == 0)
or (fields[yearPos]
in years_h) ):
85 if (scenarioFilter
and variableFilter
and regionFilter
and yearFilter):
merge(forIFiles_h=[], prdIFiles_h=[], carbonIFiles_h=[], scenarios_h=[], forOFilename_h="", prdOFilename_h="", carbonOFilename_h="", variables_h=[], regions_h=[], years_h=[])
merge_single_file(i_filename_h, o_filename_h, scenarios_h, keepHeader=False, variables_h=[], regions_h=[], years_h=[])