コード例 #1
0
    def test_isfst_openall_fstnbr(self):
        """isfst_openall_fstnbr should give known result with known input"""
        rmn.fstopt(rmn.FSTOP_MSGLVL, rmn.FSTOPI_MSG_CATAST)
        ## rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST,rmn.FSTOP_GET)

        HOME = os.getenv('HOME')
        a = rmn.isFST(os.path.join(HOME.strip(), '.profile'))
        self.assertFalse(a, 'isFST should return false on non FST files')

        ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES')
        myfile = os.path.join(ATM_MODEL_DFILES.strip(), 'bcmk/2009042700_000')
        a = rmn.isFST(myfile)
        self.assertTrue(a, 'isFST should return true on FST files')

        funit = rmn.fstopenall(myfile, rmn.FST_RO)
        self.assertTrue(funit > 0,
                        'fstopenall should return a valid file unit')

        nrec = rmn.c_fstnbrv(funit)
        self.assertEqual(nrec, 1083, ' c_fstnbrv found %d/1083 rec ' % nrec)

        nrec = rmn.fstnbrv(funit)
        self.assertEqual(nrec, 1083, ' fstnbrv found %d/1083 rec ' % nrec)

        rmn.fstcloseall(funit)
コード例 #2
0
    def test_fstecr_fstinf_fstluk(self):
        """fstinf, fstluk should give known result with known input"""
        rmn.fstopt(rmn.FSTOP_MSGLVL, rmn.FSTOPI_MSG_CATAST)
        (la, lo) = self.create_basefile()  #wrote 2 recs in that order: la, lo
        a = rmn.isFST(self.fname)
        self.assertTrue(a)
        funit = rmn.fstopenall(self.fname, rmn.FST_RW)
        nrec = rmn.c_fstnbrv(funit)
        keylist = rmn.fstinl(funit)
        kla = rmn.fstinf(funit, nomvar='LA')['key']
        la2prm = rmn.fstprm(kla)  #,rank=2)
        la2 = rmn.fstluk(kla)  #,rank=2)
        klo = rmn.fstinf(funit, nomvar='LO')
        lo2 = rmn.fstluk(klo)  #,rank=2)
        rmn.fstcloseall(funit)
        self.erase_testfile()

        self.assertEqual(nrec, 2, ' c_fstnbrv found %d/2 rec ' % nrec)
        self.assertEqual(
            len(keylist), 2,
            'fstinl found %d/2 rec: %s' % (len(keylist), repr(keylist)))

        self.assertEqual(la2['nomvar'].strip(), la['nomvar'].strip())
        self.assertEqual(lo2['nomvar'].strip(), lo['nomvar'].strip())

        self.assertEqual(la2['d'].shape, la['d'].shape)
        self.assertEqual(lo2['d'].shape, lo['d'].shape)

        if np.any(np.fabs(la2['d'] - la['d']) > self.epsilon):
            print('la2:', la2['d'])
            print('la :', la['d'])
            print(np.fabs(la2['d'] - la['d']))
        self.assertFalse(np.any(np.fabs(la2['d'] - la['d']) > self.epsilon))
        if np.any(np.fabs(lo2['d'] - lo['d']) > self.epsilon):
            print('lo2:', lo2['d'])
            print('lo :', lo['d'])
            print(np.fabs(lo2['d'] - lo['d']))
        self.assertFalse(np.any(np.fabs(la2['d'] - la['d']) > self.epsilon))
コード例 #3
0
    def test_fstecr_fstinf_fstluk(self):
        """fstinf, fstluk should give known result with known input"""
        rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST)
        (la,lo) = self.create_basefile() #wrote 2 recs in that order: la, lo
        a = rmn.isFST(self.fname)
        self.assertTrue(a)
        funit = rmn.fstopenall(self.fname,rmn.FST_RW)
        nrec = rmn.c_fstnbrv(funit)
        keylist = rmn.fstinl(funit)
        kla = rmn.fstinf(funit,nomvar='LA')['key']
        la2prm = rmn.fstprm(kla)#,rank=2)
        la2 = rmn.fstluk(kla)#,rank=2)
        klo = rmn.fstinf(funit,nomvar='LO')
        lo2 = rmn.fstluk(klo)#,rank=2)
        rmn.fstcloseall(funit)
        self.erase_testfile()

        self.assertEqual(nrec,2,' c_fstnbrv found %d/2 rec ' % nrec)
        self.assertEqual(len(keylist),2,'fstinl found %d/2 rec: %s' % (len(keylist),repr(keylist)))

        self.assertEqual(la2['nomvar'].strip(),la['nomvar'].strip())
        self.assertEqual(lo2['nomvar'].strip(),lo['nomvar'].strip())
        
        self.assertEqual(la2['d'].shape,la['d'].shape)
        self.assertEqual(lo2['d'].shape,lo['d'].shape)

        if np.any(np.fabs(la2['d'] - la['d']) > self.epsilon):
                print('la2:',la2['d'])
                print('la :',la['d'])
                print(np.fabs(la2['d'] - la['d']))
        self.assertFalse(np.any(np.fabs(la2['d'] - la['d']) > self.epsilon))
        if np.any(np.fabs(lo2['d'] - lo['d']) > self.epsilon):
                print('lo2:',lo2['d'])
                print('lo :',lo['d'])
                print(np.fabs(lo2['d'] - lo['d']))
        self.assertFalse(np.any(np.fabs(la2['d'] - la['d']) > self.epsilon))
コード例 #4
0
    def test_isfst_openall_fstnbr(self):
        """isfst_openall_fstnbr should give known result with known input"""
        rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST)
        ## rmn.fstopt(rmn.FSTOP_MSGLVL,rmn.FSTOPI_MSG_CATAST,rmn.FSTOP_GET)

        HOME = os.getenv('HOME')
        a = rmn.isFST(os.path.join(HOME.strip(),'.profile'))
        self.assertFalse(a,'isFST should return false on non FST files')

        ATM_MODEL_DFILES = os.getenv('ATM_MODEL_DFILES')
        myfile = os.path.join(ATM_MODEL_DFILES.strip(),'bcmk/2009042700_000')
        a = rmn.isFST(myfile)
        self.assertTrue(a,'isFST should return true on FST files')
    
        funit = rmn.fstopenall(myfile,rmn.FST_RO)
        self.assertTrue(funit>0,'fstopenall should return a valid file unit')

        nrec = rmn.c_fstnbrv(funit)
        self.assertEqual(nrec,1083,' c_fstnbrv found %d/1083 rec ' % nrec)
        
        nrec = rmn.fstnbrv(funit)
        self.assertEqual(nrec,1083,' fstnbrv found %d/1083 rec ' % nrec)
       
        rmn.fstcloseall(funit)