def testLevels8_prof(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES, 'bcmk_toctoc', '2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr, fileId, -1, -1, -1, -1) rmn.fstcloseall(fileId) ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(ip1list), ct.byref(nip1), quiet) MB2PA = 100. p0_stn_mb = 1013. p0_stn = np.empty((1, ), dtype=np.float64, order='FORTRAN') p0_stn[0] = p0_stn_mb * MB2PA prof8 = np.empty((nip1.value, ), dtype=np.float64, order='FORTRAN') ni = 1 nj = 1 in_log = 0 ok = vgd.c_vgd_levels_8(vgd0ptr, ni, nj, nip1, ip1list, prof8, p0_stn, in_log) self.assertEqual(ok, vgd.VGD_OK) self.assertEqual([int(x) for x in prof8[0:5] * 10000.], [100000, 138426, 176879, 241410, 305984])
def testDiag_withref8_3d(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) rfld_name = C_MKSTR(' '*vgd.VGD_MAXSTR_NOMVAR) quiet = ct.c_int(0) ok = vgd.c_vgd_get_char(vgd0ptr, 'RFLD', rfld_name, quiet) rfld = rmn.fstlir(fileId, nomvar=rfld_name.value.strip())['d'] MB2PA = 100. rfld = rfld * MB2PA rmn.fstcloseall(fileId) ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, 'VIPM', ct.byref(ip1list), ct.byref(nip1), quiet) ni = rfld.shape[0] ; nj = rfld.shape[1] ; in_log = 0 levels8 = np.empty((ni, nj, nip1.value), dtype=np.float64, order='FORTRAN') rfld8 = np.empty((ni, nj), dtype=np.float64, order='FORTRAN') rfld8[:,:] = rfld[:,:] ok = vgd.c_vgd_diag_withref_8(vgd0ptr, ni, nj, nip1, ip1list, levels8, rfld8, in_log, vgd.VGD_DIAG_DPIS) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual([int(x) for x in levels8[ni//2,nj//2,0:5]*10000.], [100000, 138425, 176878, 241408, 305980])
def testLevels8_prof(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) rmn.fstcloseall(fileId) ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, 'VIPM', ct.byref(ip1list), ct.byref(nip1), quiet) MB2PA = 100. p0_stn_mb = 1013. p0_stn = np.empty((1,), dtype=np.float64, order='FORTRAN') p0_stn[0] = p0_stn_mb * MB2PA prof8 = np.empty((nip1.value,), dtype=np.float64, order='FORTRAN') ni = 1 ; nj = 1 ; in_log = 0 ok = vgd.c_vgd_levels_8(vgd0ptr, ni, nj, nip1, ip1list, prof8, p0_stn, in_log); self.assertEqual(ok,vgd.VGD_OK) self.assertEqual([int(x) for x in prof8[0:5]*10000.], [100000, 138426, 176879, 241410, 305984])
def testDiag_withref8_3d(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) rfld_name = C_MKSTR(' '*vgd.VGD_MAXSTR_NOMVAR) quiet = ct.c_int(0) ok = vgd.c_vgd_get_char(vgd0ptr, _C_WCHAR2CHAR('RFLD'), rfld_name, quiet) rfld = rmn.fstlir(fileId, nomvar=_C_CHAR2WCHAR(rfld_name.value).strip())['d'] MB2PA = 100. rfld = rfld * MB2PA rmn.fstcloseall(fileId) ip1list = ct.POINTER(ct.c_int)() nip1 = ct.c_int(0) quiet = ct.c_int(0) ok = vgd.c_vgd_get_int_1d(vgd0ptr, _C_WCHAR2CHAR('VIPM'), ct.byref(ip1list), ct.byref(nip1), quiet) ni = rfld.shape[0] ; nj = rfld.shape[1] ; in_log = 0 levels8 = np.empty((ni, nj, nip1.value), dtype=np.float64, order='FORTRAN') rfld8 = np.empty((ni, nj), dtype=np.float64, order='FORTRAN') rfld8[:,:] = rfld[:,:] ok = vgd.c_vgd_diag_withref_8(vgd0ptr, ni, nj, nip1, ip1list, levels8, rfld8, in_log, vgd.VGD_DIAG_DPIS) self.assertEqual(ok,vgd.VGD_OK) self.assertEqual([int(x) for x in levels8[ni//2,nj//2,0:5]*10000.], [100000, 138425, 176878, 241408, 305980])
def testNewRead(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) rmn.fstcloseall(fileId) self.assertEqual(ok,vgd.VGD_OK)
def _newReadBcmk(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) rmn.fstcloseall(fileId) return vgd0ptr
def _newReadBcmk(self): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() fileName = os.path.join(ATM_MODEL_DFILES,'bcmk_toctoc','2009042700_000') fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr,fileId,-1,-1,-1,-1) ## vgd1ptr = vgd.c_vgd_construct() ## ok = vgd.c_vgd_new_read(vgd1ptr,fileId,-1,-1,-1,-1) rmn.fstcloseall(fileId) return vgd0ptr
def testWriteDesc(self): vgd0ptr = self._newReadBcmk() self.erase_testfile() fileName = self.fname fileId = rmn.fstopenall(fileName, rmn.FST_RW) ok = vgd.c_vgd_write_desc(vgd0ptr,fileId) rmn.fstcloseall(fileId) self.assertEqual(ok,vgd.VGD_OK) fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd1ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd1ptr,fileId,-1,-1,-1,-1) rmn.fstcloseall(fileId) self.erase_testfile() ok = vgd.c_vgd_vgdcmp(vgd0ptr,vgd1ptr) self.assertEqual(ok,vgd.VGD_OK)
def testWriteDesc(self): vgd0ptr = self._newReadBcmk() self.erase_testfile() fileName = self.fname fileId = rmn.fstopenall(fileName, rmn.FST_RW) ok = vgd.c_vgd_write_desc(vgd0ptr, fileId) rmn.fstcloseall(fileId) self.assertEqual(ok, vgd.VGD_OK) fileId = rmn.fstopenall(fileName, rmn.FST_RO) vgd1ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd1ptr, fileId, -1, -1, -1, -1) rmn.fstcloseall(fileId) self.erase_testfile() ok = vgd.c_vgd_vgdcmp(vgd0ptr, vgd1ptr) self.assertEqual(ok, vgd.VGD_OK)
def _newReadBcmk(self, vcode_name=None): ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES').strip() if vcode_name is None: fileName = os.path.join(ATM_MODEL_DFILES, 'bcmk_toctoc', '2009042700_000') else: fileName = os.path.join(ATM_MODEL_DFILES, 'bcmk_vgrid', vcode_name.strip()) try: fileId = rmn.fstopenall(fileName, rmn.FST_RO) except Exception as e: print(e) raise RuntimeError("Invalid file name: {}".format(fileName)) vgd0ptr = vgd.c_vgd_construct() ok = vgd.c_vgd_new_read(vgd0ptr, fileId, -1, -1, -1, -1) rmn.fstcloseall(fileId) return vgd0ptr