def fstinf(iunit, nomvar, typvar, etiket, ip1, ip2, ip3, datev, inhandle): """Find a record matching provided criterias (Interface to fstinf, dsfsui, fstinfx) recParamDict = Fstdc.fstinf(iunit, nomvar, typvar, etiket, ip1, ip2, ip3, datev, inhandle) @param iunit file unit number handle returned by Fstdc_fstouv (int) @param nomvar select according to var name, blank==wildcard (string) @param typvar select according to var type, blank==wildcard (string) @param etiket select according to etiket, blank==wildcard (string) @param ip1 select according to ip1, -1==wildcard (int) @param ip2 select according to ip2, -1==wildcard (int) @param ip3 select according to ip3, -1==wildcard (int) @param datev select according to date of validity, -1==wildcard (int) @param inhandle selcation criterion; inhandle=-2:search with criterion from start of file; inhandle=-1==fstsui, use previously provided criterion to find the next matching one; inhandle>=0 search with criterion from provided rec-handle (int) @returns python dict with record handle + record params keys/values @exception TypeError @exception Fstdc.error """ if inhandle < -1: mymatch = _rmn.fstinf(iunit, datev, etiket, ip1, ip2, ip3, typvar, nomvar) elif inhandle == -1: mymatch = _rmn.fstsui(iunit) else: mymatch = _rmn.fstinfx(inhandle, iunit, datev, etiket, ip1, ip2, ip3, typvar, nomvar) if not mymatch: raise error('No matching record') recParams = _rmn.fstprm(mymatch['key']) recParams['handle'] = recParams['key'] recParams['nom'] = recParams['nomvar'] recParams['type'] = recParams['typvar'] recParams['datev'] = recParams['xtra1'] #TODO: Keep Fstdc original bug? return recParams
def test_fstlir_fstlirx_fstlir_witharray(self): """fstlir_fstlirx_fstlir_witharray should give known result with known input""" rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST) ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES') myfile = os.path.join(ATM_MODEL_DFILES.strip(),'bcmk/2009042700_000') funit = rmn.fstopenall(myfile,rmn.FST_RO) k = rmn.fstinf(funit)['key'] a = rmn.fstprm(k) self.assertEqual(a['nomvar'].strip(),'P0','fstinf/fstprm wrong rec, Got %s expected P0' % (a['nomvar'])) k = rmn.fstsui(funit)['key'] a = rmn.fstprm(k) self.assertEqual(a['nomvar'].strip(),'TT','fstsui/fstprm wrong rec, Got %s expected TT' % (a['nomvar'])) k = rmn.fstinf(funit,nomvar='MX')['key'] a = rmn.fstlir(funit) a = rmn.fstlir(funit,dataArray=a['d']) self.assertEqual(a['nomvar'].strip(),'P0','fstlir wrong rec, Got %s expected P0' % (a['nomvar'])) self.assertEqual(int(np.amin(a['d'])),530) self.assertEqual(int(np.amax(a['d'])),1039) k = rmn.fstinf(funit,nomvar='MX')['key'] a = rmn.fstlirx(k,funit,dataArray=a['d']) self.assertEqual(a['nomvar'].strip(),'LA','fstlirx wrong rec, Got %s expected P0' % (a['nomvar'])) self.assertEqual(int(np.amin(a['d'])),-88) self.assertEqual(int(np.amax(a['d'])),88) a = rmn.fstlis(funit,dataArray=a['d']) self.assertEqual(a['nomvar'].strip(),'LO','fstlis wrong rec, Got %s expected P0' % (a['nomvar'])) self.assertEqual(int(np.amin(a['d'])),-180) self.assertEqual(int(np.amax(a['d'])),178) rmn.fstcloseall(funit)
def test_fstlir_fstlirx_fstlir_witharray(self): """fstlir_fstlirx_fstlir_witharray should give known result with known input""" rmn.fstopt(rmn.FSTOP_MSGLVL, rmn.FSTOPI_MSG_CATAST) ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES') myfile = os.path.join(ATM_MODEL_DFILES.strip(), 'bcmk/2009042700_000') funit = rmn.fstopenall(myfile, rmn.FST_RO) k = rmn.fstinf(funit)['key'] a = rmn.fstprm(k) self.assertEqual( a['nomvar'].strip(), 'P0', 'fstinf/fstprm wrong rec, Got %s expected P0' % (a['nomvar'])) k = rmn.fstsui(funit)['key'] a = rmn.fstprm(k) self.assertEqual( a['nomvar'].strip(), 'TT', 'fstsui/fstprm wrong rec, Got %s expected TT' % (a['nomvar'])) k = rmn.fstinf(funit, nomvar='MX')['key'] a = rmn.fstlir(funit) a = rmn.fstlir(funit, dataArray=a['d']) self.assertEqual( a['nomvar'].strip(), 'P0', 'fstlir wrong rec, Got %s expected P0' % (a['nomvar'])) self.assertEqual(int(np.amin(a['d'])), 530) self.assertEqual(int(np.amax(a['d'])), 1039) k = rmn.fstinf(funit, nomvar='MX')['key'] a = rmn.fstlirx(k, funit, dataArray=a['d']) self.assertEqual( a['nomvar'].strip(), 'LA', 'fstlirx wrong rec, Got %s expected P0' % (a['nomvar'])) self.assertEqual(int(np.amin(a['d'])), -88) self.assertEqual(int(np.amax(a['d'])), 88) a = rmn.fstlis(funit, dataArray=a['d']) self.assertEqual( a['nomvar'].strip(), 'LO', 'fstlis wrong rec, Got %s expected P0' % (a['nomvar'])) self.assertEqual(int(np.amin(a['d'])), -180) self.assertEqual(int(np.amax(a['d'])), 178) rmn.fstcloseall(funit)
def fstsui(iunit): """Find next record matching criterions (Interface to fstsui) recParamDict = Fstdc.fstsui(iunit) @param iunit file unit number handle returned by Fstdc_fstouv (int) @returns python dict with record handle + record params keys/values @exception TypeError @exception Fstdc.error """ try: mymatch = _rmn.fstsui(iunit) except: raise error('Problem getting record list') if not mymatch: raise error('No matching record') recParams = _rmn.fstprm(mymatch['key']) recParams['handle'] = recParams['key'] recParams['nom'] = recParams['nomvar'] recParams['type'] = recParams['typvar'] recParams['datev'] = recParams['xtra1'] #TODO: Keep Fstdc original bug? return recParams