def make_messagefile(lib, name = 'hspfmsg.wdm', verbose = True): """builds the HSPF message file from a list of the paths to the source sequential Fortran files (.SEQ).""" sys.path.append(os.getcwd()) import hspf if verbose: print('building the HSPF message file') # SEQ files needed from the various subdirectories in LIB3.2\MSG adwdmseqs = ['ATTR001', 'ATTR051', 'ATTR101', 'ATTR151', 'ATTR201', 'ATTR301', 'ATTR351', 'ATTR401'] aideseqs = ['MESSAGE'] waideseqs = ['AWFEB', 'TSLIST', 'AGPLOT'] awstatseqs = ['TSCMPR', 'A193', 'PROFDR'] annseqs = ['PGENER', 'QTPRNT'] #hspfseqs = ['hiouci', 'hprbut', 'hruntspt', 'himpqua', # 'hspfitab', 'hrch', 'hdatut', 'hringeut', 'htsinsi', # 'hringen', 'hspf', 'hspfec', 'hpersno', 'hperpho', # 'hpernit', 'hperpes', 'hrchnut', 'hperwat', 'hrchaci', # 'hrchgqu', 'hrchhyd', 'hrchphc', 'hrchsed', 'hrchhtr', # 'hrchplk', 'hwdmut', 'hdssut', 'hdssx', 'hutop', 'hutopinp', # 'hrunut', 'hrinseq', 'hrinwdm', 'hrindss', 'hruntsgw', # 'himp', 'himpwat', 'hperagut', 'hruntsgq', 'hperqua', 'hper', # 'hruntsgp', 'hruntsgt', 'hruntspw', 'hutdura', 'hruntsut', # 'hruntsgd', 'hruntspd', 'hrints', 'hrintss', 'htssut', # 'specact', 'perlndts', 'implndts', 'rchrests', 'copyts', # 'pltgents', 'displyts', 'duranlts', 'generts', 'mutsints', # 'perlnd', 'implnd', 'rchres', 'copy', 'pltgen', 'disply', # 'gener', 'duranl', 'mutsin'] #newaqtseqs = ['sgtabl', 'agmap', 'prwplt', 'ucimod', 'ucirea', 'wsgsim', # 'wsgutl', 'dspeci', 'wsgsys', 'tsplot', 'durani', 'tsfreq', # 'sturbn'] hspfseqs = os.listdir('{}/hspf122'.format(lib)) newaqtseqs = os.listdir('{}/NEWAQT12'.format(lib)) newaqtseqs.remove('DSNSEL.SEQ') # build a list of all the seq files from LIB3.0 seqfiles = [] for seq in aideseqs: seqfiles.append('{}/AIDE/{}.SEQ'.format(lib, seq)) for seq in waideseqs: seqfiles.append('{}/WAIDE/{}.SEQ'.format(lib, seq)) for seq in awstatseqs: seqfiles.append('{}/AWSTAT/{}.SEQ'.format(lib, seq)) for seq in annseqs: seqfiles.append('{}/ANN/{}.SEQ'.format(lib, seq)) for seq in hspfseqs: seqfiles.append('{}/hspf122/{}'.format(lib, seq)) for seq in newaqtseqs: seqfiles.append('{}/NEWAQT12/{}'.format(lib, seq)) n = 35 # Fortran file number for the message file E = 99 # Fortran file number for the error file m = 36 # Fortran file number for the seq file if os.path.exists(name): if verbose: print('warning: message file exists, deleting') os.remove(name) # open up the new file and the error file hspf.wdbopnpy(n, name, 2) hspf.erroropen(E) # make the attribute file attributes = {} for seq in adwdmseqs: if verbose: print('adding attributes to the message file') p = lib + '/ADWDM/{}.SEQ'.format(seq) hspf.seqopen(p, m) hspf.seqimport(n, m, 0) hspf.seqclose(m) # make an independent Python file of the ADWDM attributes with open(p, 'r') as f: lines = f.readlines() for line in lines: if line[1:10] == 'ATTRIBUTE': attributes[int(line[30:33].strip())] = \ WDMattribute(line[12:18], int(line[30:33].strip())) current = attributes[int(line[30:33].strip())] if line[1:5] == 'TYPE': current.add_type(line[10:19].strip()) if line[1:7] == 'LENGTH': current.add_length(line[9:11].strip()) if line[1:5] == 'DESC': current.add_description(line[10:]) if line[1:6] == 'RANGE': current.add_range(line) if line[1:8] == 'DEFAULT': current.add_default(line[10:19]) if line[1:5] == 'HELP': current.create_help() if line[:3] == ' ': current.add_help(line[3:]) # work around for inconistency in lib3.0 (thanks Aquaterra) hspf.seqopen(lib + '/ADWDM/attr251.seq', m) hspf.seqimport(n, m, 0) hspf.seqclose(m) with open(lib + '/ADWDM/attr251.seq', 'r') as f: lines = f.readlines() for line in lines: if line[1:10] == 'ATTRIBUTE': attributes[int(line[30:33].strip())] = \ WDMattribute(line[12:18], int(line[30:33].strip())) current = attributes[int(line[30:33].strip())] if line[1:5] == 'TYPE': current.add_type(line[10:19].strip()) if line[1:7] == 'LENGTH': current.add_length(line[9:11].strip()) if line[1:5] == 'DESC': current.add_description(line[10:]) if line[1:6] == 'RANGE': current.add_range(line) if line[1:8] == 'DEFAULT': current.add_default(line[10:19]) if line[1:5] == 'HELP': current.create_help() if line[:3] == ' ': current.add_help(line[3:]) wdmattributes = {v.attribute: {'index': k, 'desc': v.desc, 'type': v.type, 'length': v.length, 'min': v.min, 'max': v.max, 'default': v.default, 'value': v.value, 'help': v.help } for k, v in attributes.items()} with open('attributes', 'wb') as f: pickle.dump(wdmattributes, f) # now import the data sets for f in seqfiles: if verbose: print('importing data from {}'.format(f)) hspf.seqopen(f, m) hspf.seqimport(n, m, n) hspf.seqclose(m) # close up the wdm file and the error file hspf.seqclose(E) hspf.wdflclpy(n)
def make_messagefile(lib, name = 'hspfmsg.wdm', verbose = True): """builds the HSPF message file from a list of the paths to the source sequential Fortran files (.SEQ).""" if verbose: print('building the HSPF message file') # SEQ files needed from the various subdirectories in LIB3.2\MSG adwdmseqs = ['ATTR001', 'ATTR051', 'ATTR101', 'ATTR151', 'ATTR201', 'ATTR301', 'ATTR351', 'ATTR401'] aideseqs = ['MESSAGE'] waideseqs = ['AWFEB', 'TSLIST', 'AGPLOT'] awstatseqs = ['TSCMPR', 'A193', 'PROFDR'] annseqs = ['PGENER', 'QTPRNT'] #hspfseqs = ['hiouci', 'hprbut', 'hruntspt', 'himpqua', # 'hspfitab', 'hrch', 'hdatut', 'hringeut', 'htsinsi', # 'hringen', 'hspf', 'hspfec', 'hpersno', 'hperpho', # 'hpernit', 'hperpes', 'hrchnut', 'hperwat', 'hrchaci', # 'hrchgqu', 'hrchhyd', 'hrchphc', 'hrchsed', 'hrchhtr', # 'hrchplk', 'hwdmut', 'hdssut', 'hdssx', 'hutop', 'hutopinp', # 'hrunut', 'hrinseq', 'hrinwdm', 'hrindss', 'hruntsgw', # 'himp', 'himpwat', 'hperagut', 'hruntsgq', 'hperqua', 'hper', # 'hruntsgp', 'hruntsgt', 'hruntspw', 'hutdura', 'hruntsut', # 'hruntsgd', 'hruntspd', 'hrints', 'hrintss', 'htssut', # 'specact', 'perlndts', 'implndts', 'rchrests', 'copyts', # 'pltgents', 'displyts', 'duranlts', 'generts', 'mutsints', # 'perlnd', 'implnd', 'rchres', 'copy', 'pltgen', 'disply', # 'gener', 'duranl', 'mutsin'] #newaqtseqs = ['sgtabl', 'agmap', 'prwplt', 'ucimod', 'ucirea', 'wsgsim', # 'wsgutl', 'dspeci', 'wsgsys', 'tsplot', 'durani', 'tsfreq', # 'sturbn'] hspfseqs = os.listdir(lib + '/hspf122') newaqtseqs = os.listdir(lib + '/NEWAQT12') print(newaqtseqs) newaqtseqs.remove('DSNSEL.SEQ') # build a list of all the seq files from LIB3.2 seqfiles = [] for seq in aideseqs: seqfiles.append(lib + '/AIDE/%s.SEQ' % seq) for seq in waideseqs: seqfiles.append(lib + '/WAIDE/%s.SEQ' % seq) for seq in awstatseqs: seqfiles.append(lib + '/AWSTAT/%s.SEQ' % seq) for seq in annseqs: seqfiles.append(lib + '/ANN/%s.SEQ' % seq) for seq in hspfseqs: seqfiles.append(lib + '/hspf122/%s' % seq) for seq in newaqtseqs: seqfiles.append(lib + '/NEWAQT12/%s' % seq) n = 35 # Fortran file number for the message file E = 99 # Fortran file number for the error file m = 36 # Fortran file number for the seq file if os.path.exists(name): if verbose: print('warning: message file exists, deleting') os.remove(name) # open up the new file and the error file hspf.wdbopnpy(n, name, 2) hspf.erroropen(E) # add the attributes from adwdm first for seq in adwdmseqs: if verbose: print('adding attributes to the message file') f = lib + '/ADWDM/%s.SEQ' % seq hspf.seqopen(f, m) hspf.seqimport(n, m, 0) hspf.seqclose(m) # work around for inconistency in lib3.0 (thanks Aquaterra) hspf.seqopen(lib + '/ADWDM/attr251.seq', m) hspf.seqimport(n, m, 0) hspf.seqclose(m) # now import the data sets for f in seqfiles: if verbose: print('importing data from %s' % f) hspf.seqopen(f, m) hspf.seqimport(n, m, n) hspf.seqclose(m) # close up the wdm file and the error file hspf.wdflclpy(n) hspf.wdflclpy(E)
def make_messagefile(lib, name='hspfmsg.wdm', verbose=True): """builds the HSPF message file from a list of the paths to the source sequential Fortran files (.SEQ).""" if verbose: print('building the HSPF message file') # SEQ files needed from the various subdirectories in LIB3.2\MSG adwdmseqs = [ 'ATTR001', 'ATTR051', 'ATTR101', 'ATTR151', 'ATTR201', 'ATTR301', 'ATTR351', 'ATTR401' ] aideseqs = ['MESSAGE'] waideseqs = ['AWFEB', 'TSLIST', 'AGPLOT'] awstatseqs = ['TSCMPR', 'A193', 'PROFDR'] annseqs = ['PGENER', 'QTPRNT'] #hspfseqs = ['hiouci', 'hprbut', 'hruntspt', 'himpqua', # 'hspfitab', 'hrch', 'hdatut', 'hringeut', 'htsinsi', # 'hringen', 'hspf', 'hspfec', 'hpersno', 'hperpho', # 'hpernit', 'hperpes', 'hrchnut', 'hperwat', 'hrchaci', # 'hrchgqu', 'hrchhyd', 'hrchphc', 'hrchsed', 'hrchhtr', # 'hrchplk', 'hwdmut', 'hdssut', 'hdssx', 'hutop', 'hutopinp', # 'hrunut', 'hrinseq', 'hrinwdm', 'hrindss', 'hruntsgw', # 'himp', 'himpwat', 'hperagut', 'hruntsgq', 'hperqua', 'hper', # 'hruntsgp', 'hruntsgt', 'hruntspw', 'hutdura', 'hruntsut', # 'hruntsgd', 'hruntspd', 'hrints', 'hrintss', 'htssut', # 'specact', 'perlndts', 'implndts', 'rchrests', 'copyts', # 'pltgents', 'displyts', 'duranlts', 'generts', 'mutsints', # 'perlnd', 'implnd', 'rchres', 'copy', 'pltgen', 'disply', # 'gener', 'duranl', 'mutsin'] #newaqtseqs = ['sgtabl', 'agmap', 'prwplt', 'ucimod', 'ucirea', 'wsgsim', # 'wsgutl', 'dspeci', 'wsgsys', 'tsplot', 'durani', 'tsfreq', # 'sturbn'] hspfseqs = os.listdir(lib + '/hspf122') newaqtseqs = os.listdir(lib + '/NEWAQT12') print(newaqtseqs) newaqtseqs.remove('DSNSEL.SEQ') # build a list of all the seq files from LIB3.2 seqfiles = [] for seq in aideseqs: seqfiles.append(lib + '/AIDE/%s.SEQ' % seq) for seq in waideseqs: seqfiles.append(lib + '/WAIDE/%s.SEQ' % seq) for seq in awstatseqs: seqfiles.append(lib + '/AWSTAT/%s.SEQ' % seq) for seq in annseqs: seqfiles.append(lib + '/ANN/%s.SEQ' % seq) for seq in hspfseqs: seqfiles.append(lib + '/hspf122/%s' % seq) for seq in newaqtseqs: seqfiles.append(lib + '/NEWAQT12/%s' % seq) n = 35 # Fortran file number for the message file E = 99 # Fortran file number for the error file m = 36 # Fortran file number for the seq file if os.path.exists(name): if verbose: print('warning: message file exists, deleting') os.remove(name) # open up the new file and the error file hspf.wdbopnpy(n, name, 2) hspf.erroropen(E) # add the attributes from adwdm first for seq in adwdmseqs: if verbose: print('adding attributes to the message file') f = lib + '/ADWDM/%s.SEQ' % seq hspf.seqopen(f, m) hspf.seqimport(n, m, 0) hspf.seqclose(m) # work around for inconistency in lib3.0 (thanks Aquaterra) hspf.seqopen(lib + '/ADWDM/attr251.seq', m) hspf.seqimport(n, m, 0) hspf.seqclose(m) # now import the data sets for f in seqfiles: if verbose: print(('importing data from %s' % f)) hspf.seqopen(f, m) hspf.seqimport(n, m, n) hspf.seqclose(m) # close up the wdm file and the error file hspf.wdflclpy(n) hspf.wdflclpy(E)
def make_messagefile(lib, name='hspfmsg.wdm', verbose=True): """builds the HSPF message file from a list of the paths to the source sequential Fortran files (.SEQ).""" sys.path.append(os.getcwd()) import hspf if verbose: print('building the HSPF message file') # SEQ files needed from the various subdirectories in LIB3.2\MSG adwdmseqs = [ 'ATTR001', 'ATTR051', 'ATTR101', 'ATTR151', 'ATTR201', 'ATTR301', 'ATTR351', 'ATTR401' ] aideseqs = ['MESSAGE'] waideseqs = ['AWFEB', 'TSLIST', 'AGPLOT'] awstatseqs = ['TSCMPR', 'A193', 'PROFDR'] annseqs = ['PGENER', 'QTPRNT'] #hspfseqs = ['hiouci', 'hprbut', 'hruntspt', 'himpqua', # 'hspfitab', 'hrch', 'hdatut', 'hringeut', 'htsinsi', # 'hringen', 'hspf', 'hspfec', 'hpersno', 'hperpho', # 'hpernit', 'hperpes', 'hrchnut', 'hperwat', 'hrchaci', # 'hrchgqu', 'hrchhyd', 'hrchphc', 'hrchsed', 'hrchhtr', # 'hrchplk', 'hwdmut', 'hdssut', 'hdssx', 'hutop', 'hutopinp', # 'hrunut', 'hrinseq', 'hrinwdm', 'hrindss', 'hruntsgw', # 'himp', 'himpwat', 'hperagut', 'hruntsgq', 'hperqua', 'hper', # 'hruntsgp', 'hruntsgt', 'hruntspw', 'hutdura', 'hruntsut', # 'hruntsgd', 'hruntspd', 'hrints', 'hrintss', 'htssut', # 'specact', 'perlndts', 'implndts', 'rchrests', 'copyts', # 'pltgents', 'displyts', 'duranlts', 'generts', 'mutsints', # 'perlnd', 'implnd', 'rchres', 'copy', 'pltgen', 'disply', # 'gener', 'duranl', 'mutsin'] #newaqtseqs = ['sgtabl', 'agmap', 'prwplt', 'ucimod', 'ucirea', 'wsgsim', # 'wsgutl', 'dspeci', 'wsgsys', 'tsplot', 'durani', 'tsfreq', # 'sturbn'] hspfseqs = os.listdir('{}/hspf122'.format(lib)) newaqtseqs = os.listdir('{}/NEWAQT12'.format(lib)) newaqtseqs.remove('DSNSEL.SEQ') # build a list of all the seq files from LIB3.0 seqfiles = [] for seq in aideseqs: seqfiles.append('{}/AIDE/{}.SEQ'.format(lib, seq)) for seq in waideseqs: seqfiles.append('{}/WAIDE/{}.SEQ'.format(lib, seq)) for seq in awstatseqs: seqfiles.append('{}/AWSTAT/{}.SEQ'.format(lib, seq)) for seq in annseqs: seqfiles.append('{}/ANN/{}.SEQ'.format(lib, seq)) for seq in hspfseqs: seqfiles.append('{}/hspf122/{}'.format(lib, seq)) for seq in newaqtseqs: seqfiles.append('{}/NEWAQT12/{}'.format(lib, seq)) n = 35 # Fortran file number for the message file E = 99 # Fortran file number for the error file m = 36 # Fortran file number for the seq file if os.path.exists(name): if verbose: print('warning: message file exists, deleting') os.remove(name) # open up the new file and the error file hspf.wdbopnpy(n, name, 2) hspf.erroropen(E) # make the attribute file attributes = {} for seq in adwdmseqs: if verbose: print('adding attributes to the message file') p = lib + '/ADWDM/{}.SEQ'.format(seq) hspf.seqopen(p, m) hspf.seqimport(n, m, 0) hspf.seqclose(m) # make an independent Python file of the ADWDM attributes with open(p, 'r') as f: lines = f.readlines() for line in lines: if line[1:10] == 'ATTRIBUTE': attributes[int(line[30:33].strip())] = \ WDMattribute(line[12:18], int(line[30:33].strip())) current = attributes[int(line[30:33].strip())] if line[1:5] == 'TYPE': current.add_type(line[10:19].strip()) if line[1:7] == 'LENGTH': current.add_length(line[9:11].strip()) if line[1:5] == 'DESC': current.add_description(line[10:]) if line[1:6] == 'RANGE': current.add_range(line) if line[1:8] == 'DEFAULT': current.add_default(line[10:19]) if line[1:5] == 'HELP': current.create_help() if line[:3] == ' ': current.add_help(line[3:]) # work around for inconistency in lib3.0 (thanks Aquaterra) hspf.seqopen(lib + '/ADWDM/attr251.seq', m) hspf.seqimport(n, m, 0) hspf.seqclose(m) with open(lib + '/ADWDM/attr251.seq', 'r') as f: lines = f.readlines() for line in lines: if line[1:10] == 'ATTRIBUTE': attributes[int(line[30:33].strip())] = \ WDMattribute(line[12:18], int(line[30:33].strip())) current = attributes[int(line[30:33].strip())] if line[1:5] == 'TYPE': current.add_type(line[10:19].strip()) if line[1:7] == 'LENGTH': current.add_length(line[9:11].strip()) if line[1:5] == 'DESC': current.add_description(line[10:]) if line[1:6] == 'RANGE': current.add_range(line) if line[1:8] == 'DEFAULT': current.add_default(line[10:19]) if line[1:5] == 'HELP': current.create_help() if line[:3] == ' ': current.add_help(line[3:]) wdmattributes = { v.attribute: { 'index': k, 'desc': v.desc, 'type': v.type, 'length': v.length, 'min': v.min, 'max': v.max, 'default': v.default, 'value': v.value, 'help': v.help } for k, v in attributes.items() } with open('attributes', 'wb') as f: pickle.dump(wdmattributes, f) # now import the data sets for f in seqfiles: if verbose: print('importing data from {}'.format(f)) hspf.seqopen(f, m) hspf.seqimport(n, m, n) hspf.seqclose(m) # close up the wdm file and the error file hspf.seqclose(E) hspf.wdflclpy(n)