- Timestamp:
- 06/18/20 07:34:54 (4 years ago)
- Location:
- trunk/libIGCM
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libIGCM/libIGCM_comp/libIGCM_comp.ksh
r1520 r1535 1577 1577 # Read TimeSeries information from XML files, prepare CMIP6 TS directories and do modifications in dr2xml_${compname}.xml 1578 1578 if [ -f dr2xml_${compname}.xml ]; then 1579 eval IGCM_sys_Mkdir \${CMIP6_BUF_${comp}} 1580 eval CMIP6_DIR=\${CMIP6_BUF_${comp}} 1581 # Modify path from dr2xml_{compname}.xml 1582 if [ X${config_Post_dr2xmlFilePrefix} = XTRUE ]; then 1583 ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --filePrefix ${config_UserChoices_JobName} --file dr2xml_${compname}.xml 1584 else 1585 ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --file dr2xml_${compname}.xml 1579 if ( [ X"$( echo ${config_UserChoices_ExpType} | grep CMIP6 )" != "X" ] || [ X${config_Post_dr2xmlIPSL} = XTRUE ] ) ; then 1580 eval IGCM_sys_Mkdir \${CMIP6_BUF_${comp}} 1581 eval CMIP6_DIR=\${CMIP6_BUF_${comp}} 1582 # Modify path from dr2xml_{compname}.xml 1583 if [ X${config_Post_dr2xmlIPSL} = XTRUE ]; then 1584 ${libIGCM}/libIGCM_post/xios_parser.py -v modifydr2xmlIPSL --newPath ${CMIP6_DIR} --splitLastDate ${config_UserChoices_DateEnd} --JobName ${config_UserChoices_JobName} --ModelName ${config_UserChoices_ModelName} --ModelVersion ${config_UserChoices_LongName} --file dr2xml_${compname}.xml 1585 else 1586 ${libIGCM}/libIGCM_post/xios_parser.py -v modifyPath --newPath ${CMIP6_DIR} --file dr2xml_${compname}.xml 1587 fi 1588 # Overwrite the original file 1589 IGCM_sys_Mv modified.dr2xml_${compname}.xml dr2xml_${compname}.xml 1586 1590 fi 1587 # Overwrite the original file1588 IGCM_sys_Mv modified.dr2xml_${compname}.xml dr2xml_${compname}.xml1589 1591 fi 1590 1592 done -
trunk/libIGCM/libIGCM_config/libIGCM_config.ksh
r1528 r1535 192 192 config_Post_LightRestartPack=FALSE 193 193 fi 194 195 #==================================================== 196 # dr2xmlIPSL : apply default value if not defined 197 if ( [ X${config_Post_dr2xmlIPSL} = X${NULL_STR} ] || [ X${config_Post_dr2xmlIPSL} = X ] ) ; then 198 config_Post_dr2xmlIPSL=FALSE 199 fi 200 194 201 195 202 #==================================================== -
trunk/libIGCM/libIGCM_post/xios_parser.py
r1467 r1535 176 176 print '\n' 177 177 178 def modifydr2xmlIPSL(args): 179 """Recursively find tree element with file tag and change the path prefix of the name attribute.""" 180 181 # Loop over file_def files 182 for inputFile in args.file: 183 # Read the file_def_xml 184 if args.verbosity >= 1: print '\nReading dr2xml_def_xml=',inputFile 185 try: 186 tree = ET.parse(inputFile) 187 except: 188 print "Parse error. Please fix so that it can be parsed." 189 traceback.print_exc(file=sys.stdout) 190 return 191 root=tree.getroot() 192 if args.verbosity >= 3: print root.tag, root.attrib, '\n' 193 194 # Change file name prefix to point where we want 195 for elem in tree.iter(tag='file'): 196 if not elem.attrib.get('mode') == 'read': 197 name=elem.attrib.get('name') 198 if args.JobName is not None: 199 name = name.replace('JobName', args.JobName[0]).replace('ModelName', args.ModelName[0]) 200 elem.set('name', os.path.normpath(args.newPath[0]) + '/' + os.path.normpath(name)) 201 else: 202 elem.set('name', os.path.normpath(args.newPath[0]) + '/' + os.path.normpath(name)) 203 if args.verbosity >= 2: print elem.tag, elem.attrib 204 if args.splitLastDate is not None: elem.set('split_last_date', args.splitLastDate[0] + ' 00:00:00') 205 if args.ModelVersion is not None: 206 for childElem in elem.iter(tag='variable'): 207 if args.verbosity >= 2: print childElem.tag, childElem.attrib 208 if childElem.attrib.get('name') is not None: 209 if childElem.attrib.get('name') == 'model_version': 210 childElem.text = args.ModelVersion[0] 211 if args.ModelName is not None: 212 for childElem in elem.iter(tag='variable'): 213 if args.verbosity >= 2: print childElem.tag, childElem.attrib 214 if childElem.attrib.get('name') is not None: 215 if childElem.attrib.get('name') == 'source_id': 216 childElem.text = args.ModelName[0] 217 218 219 # Write out the results 220 if args.verbosity >= 1: print '\nWriting dr2xml_def_xml=','modified.' + inputFile 221 try: 222 tree.write ('modified.' + inputFile) 223 except: 224 print "Write error. Please fix so that it can be parsed." 225 traceback.print_exc(file=sys.stdout) 226 return 227 178 228 def modifyPath(args): 179 229 """Recursively find tree element with file tag and change the path prefix of the name attribute.""" 180 181 230 # Loop over file_def files 182 231 for inputFile in args.file: … … 191 240 root=tree.getroot() 192 241 if args.verbosity >= 3: print root.tag, root.attrib, '\n' 193 194 242 # Change file name prefix to point where we want 195 243 for elem in tree.iter(tag='file'): … … 201 249 elem.set('name', os.path.normpath(args.newPath[0]) + '/' + os.path.normpath(name)) 202 250 if args.verbosity >= 2: print elem.tag, elem.attrib 203 251 204 252 # Write out the results 205 253 if args.verbosity >= 1: print '\nWriting dr2xml_def_xml=','modified.' + inputFile … … 303 351 parser_check.add_argument('--file', nargs='+', required=True, help='XIOS xml file_def type') 304 352 parser_check.set_defaults(func=check, correction=False) 305 353 306 354 # create the parser for the "modify" command 307 355 parser_check = subparsers.add_parser('modify', help='Will make sure field_def is a superset of file_def') … … 309 357 parser_check.add_argument('--file', nargs='+', required=True, help='XIOS xml file_def type') 310 358 parser_check.set_defaults(func=check, correction=True) 359 360 # create the parser for the "modifydr2xmlIPSL" command 361 parser_check = subparsers.add_parser('modifydr2xmlIPSL', help='Adapt dr2xml_file to produce output files according to IPSL requirements') 362 parser_check.add_argument('--newPath', nargs=1, required=True, help='Directory output for file produced from dr2xml_file type') 363 parser_check.add_argument('--JobName', nargs=1, required=False, help='Name of the simulation to be added in the name of file produced from dr2xml_file type') 364 parser_check.add_argument('--ModelName', nargs=1, required=False, help='Name of the model to be added in the name of file produced from dr2xml_file type') 365 parser_check.add_argument('--ModelVersion', nargs=1, required=False, help='Model version to be added in global attributes of files produced from dr2xml_file type') 366 parser_check.add_argument('--file', nargs='+', required=True, help='XIOS xml dr2xml_file type') 367 parser_check.add_argument('--splitLastDate', nargs=1, required=False, help='Date to be used as split_last_date') 368 parser_check.set_defaults(func=modifydr2xmlIPSL) 311 369 312 370 # create the parser for the "modifyPath" command
Note: See TracChangeset
for help on using the changeset viewer.