Esempio n. 1
0
    def test_kw(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

        kw1[0] = 99
        kw1[1] = 77
        kw2[0] = 113
        kw2[1] = 335

        with TestAreaContext("python/fortio/write-kw"):
            f = FortIO.writer("test", fmt_file=False)
            kw1.fwrite(f)
            f.close()

            f = FortIO.open("test", mode="a")
            kw2.fwrite(f)
            f.close()

            f = FortIO.open("test", fmt_file=False)
            k1 = EclKW.fread(f)
            k2 = EclKW.fread(f)
            f.close()

            self.assertTrue(k1.equal(kw1))
            self.assertTrue(k2.equal(kw2))
Esempio n. 2
0
    def test_kw_write(self):
        with TestAreaContext("python/ecl_kw/writing"):

            data = [random.random() for i in range(10000)]

            kw = EclKW("TEST", len(data), EclTypeEnum.ECL_DOUBLE_TYPE)
            i = 0
            for d in data:
                kw[i] = d
                i += 1

            pfx = 'EclKW('
            self.assertEqual(pfx, repr(kw)[:len(pfx)])

            fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE)
            kw.fwrite(fortio)
            fortio.close()

            fortio = FortIO("ECL_KW_TEST")

            kw2 = EclKW.fread(fortio)

            self.assertTrue(kw.equal(kw2))

            ecl_file = EclFile("ECL_KW_TEST",
                               flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            kw3 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw3))
            ecl_file.save_kw(kw3)
            ecl_file.close()

            fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE)
            kw4 = EclKW.fread(fortio)
            self.assertTrue(kw.equal(kw4))
            fortio.seek(0)
            kw4.fwrite(fortio)
            fortio.close()

            ecl_file = EclFile("ECL_KW_TEST")
            kw5 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw5))
Esempio n. 3
0
    def test_ecl_kw_indexed_read(self):
        with TestAreaContext("ecl_kw_indexed_read") as area:
            fortio = FortIO("index_test", mode=FortIO.WRITE_MODE)

            element_count = 100000
            ecl_kw = EclKW.create("TEST", element_count,
                                  EclTypeEnum.ECL_INT_TYPE)

            for index in range(element_count):
                ecl_kw[index] = index

            ecl_kw.fwrite(fortio)

            fortio.close()

            fortio = FortIO("index_test", mode=FortIO.READ_MODE)

            new_ecl_kw = EclKW.fread(fortio)

            for index in range(element_count):
                self.assertEqual(new_ecl_kw[index], index)

            index_map = IntVector()
            index_map.append(2)
            index_map.append(3)
            index_map.append(5)
            index_map.append(7)
            index_map.append(11)
            index_map.append(13)
            index_map.append(313)
            index_map.append(1867)
            index_map.append(5227)
            index_map.append(7159)
            index_map.append(12689)
            index_map.append(18719)
            index_map.append(32321)
            index_map.append(37879)
            index_map.append(54167)
            index_map.append(77213)
            index_map.append(88843)
            index_map.append(99991)

            char_buffer = ctypes.create_string_buffer(
                len(index_map) * ctypes.sizeof(ctypes.c_int))

            freadIndexedData(fortio, 24, EclTypeEnum.ECL_INT_TYPE,
                             element_count, index_map, char_buffer)

            int_buffer = ctypes.cast(char_buffer, ctypes.POINTER(ctypes.c_int))

            for index, index_map_value in enumerate(index_map):
                self.assertEqual(index_map_value, int_buffer[index])
Esempio n. 4
0
    def test_kw(self):
        kw1 = EclKW("KW1", 2, EclDataType.ECL_INT)
        kw2 = EclKW("KW2", 2, EclDataType.ECL_INT)

        kw1[0] = 99
        kw1[1] = 77
        kw2[0] = 113
        kw2[1] = 335

        with TestAreaContext("python/fortio/write-kw"):
            f = FortIO("test", FortIO.WRITE_MODE, fmt_file=False)
            kw1.fwrite(f)

            f = FortIO("test", FortIO.APPEND_MODE)
            kw2.fwrite(f)

            f = FortIO("test", fmt_file=False)
            k1 = EclKW.fread(f)
            k2 = EclKW.fread(f)

            self.assertTrue(k1.equal(kw1))
            self.assertTrue(k2.equal(kw2))
Esempio n. 5
0
    def test_context(self):
        with TestAreaContext("python/fortio/context"):
            kw1 = EclKW.create("KW" , 2456 , EclTypeEnum.ECL_FLOAT_TYPE)
            for i in range(len(kw1)):
                kw1[i] = randint(0,1000)

            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )

            with openFortIO("file") as f:
                kw2 = EclKW.fread( f )

            self.assertTrue( kw1 == kw2 )
Esempio n. 6
0
    def test_kw(self):
        kw1 = EclKW.create("KW1", 2, EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW.create("KW2", 2, EclTypeEnum.ECL_INT_TYPE)

        kw1[0] = 99
        kw1[1] = 77
        kw2[0] = 113
        kw2[1] = 335

        with TestAreaContext("python/fortio/write-kw"):
            f = FortIO("test", FortIO.WRITE_MODE, fmt_file=False)
            kw1.fwrite(f)

            f = FortIO("test", FortIO.APPEND_MODE)
            kw2.fwrite(f)

            f = FortIO("test", fmt_file=False)
            k1 = EclKW.fread(f)
            k2 = EclKW.fread(f)

            self.assertTrue(k1.equal(kw1))
            self.assertTrue(k2.equal(kw2))
Esempio n. 7
0
    def test_context(self):
        with TestAreaContext("python/fortio/context"):
            kw1 = EclKW.create("KW" , 2456 , EclTypeEnum.ECL_FLOAT_TYPE)
            for i in range(len(kw1)):
                kw1[i] = randint(0,1000)

            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )

            with openFortIO("file") as f:
                kw2 = EclKW.fread( f )

            self.assertTrue( kw1 == kw2 )
Esempio n. 8
0
    def test_fmt(self):
        kw1 = EclKW( "NAME1" , 100 , EclTypeEnum.ECL_INT_TYPE)
        kw2 = EclKW( "NAME2" , 100 , EclTypeEnum.ECL_INT_TYPE)

        for i in range(len(kw1)):
            kw1[i] = i + 1
            kw2[i] = len(kw1) - kw1[i]
            
        with TestAreaContext("ecl_kw/fmt") as ta:
            with openFortIO( "TEST.FINIT" , FortIO.WRITE_MODE , fmt_file = True ) as f:
                kw1.fwrite( f )
                kw2.fwrite( f )
                
            with openFortIO( "TEST.FINIT" , fmt_file = True ) as f:
                kw1b = EclKW.fread( f )
                kw2b = EclKW.fread( f )

            self.assertTrue( kw1 == kw1b )
            self.assertTrue( kw2 == kw2b )

            f = EclFile( "TEST.FINIT" )
            self.assertTrue( kw1 == f[0] )
            self.assertTrue( kw2 == f[1] )
Esempio n. 9
0
    def test_ecl_kw_indexed_read(self):
        with TestAreaContext("ecl_kw_indexed_read") as area:
            fortio = FortIO("index_test", mode=FortIO.WRITE_MODE)

            element_count = 100000
            ecl_kw = EclKW("TEST", element_count, EclDataType.ECL_INT)

            for index in range(element_count):
                ecl_kw[index] = index

            ecl_kw.fwrite(fortio)

            fortio.close()


            fortio = FortIO("index_test", mode=FortIO.READ_MODE)

            new_ecl_kw = EclKW.fread(fortio)

            for index in range(element_count):
                self.assertEqual(new_ecl_kw[index], index)

            index_map = IntVector()
            index_map.append(2)
            index_map.append(3)
            index_map.append(5)
            index_map.append(7)
            index_map.append(11)
            index_map.append(13)
            index_map.append(313)
            index_map.append(1867)
            index_map.append(5227)
            index_map.append(7159)
            index_map.append(12689)
            index_map.append(18719)
            index_map.append(32321)
            index_map.append(37879)
            index_map.append(54167)
            index_map.append(77213)
            index_map.append(88843)
            index_map.append(99991)

            char_buffer = ctypes.create_string_buffer(len(index_map) * ctypes.sizeof(ctypes.c_int))

            self._freadIndexedData(fortio, 24, EclDataType.ECL_INT, element_count, index_map, char_buffer)

            int_buffer = ctypes.cast(char_buffer, ctypes.POINTER(ctypes.c_int))

            for index, index_map_value in enumerate(index_map):
                self.assertEqual(index_map_value, int_buffer[index])
Esempio n. 10
0
    def test_fmt(self):
        kw1 = EclKW( "NAME1" , 100 , EclDataType.ECL_INT)
        kw2 = EclKW( "NAME2" , 100 , EclDataType.ECL_INT)

        for i in range(len(kw1)):
            kw1[i] = i + 1
            kw2[i] = len(kw1) - kw1[i]
            
        with TestAreaContext("ecl_kw/fmt") as ta:
            with openFortIO( "TEST.FINIT" , FortIO.WRITE_MODE , fmt_file = True ) as f:
                kw1.fwrite( f )
                kw2.fwrite( f )
                
            with openFortIO( "TEST.FINIT" , fmt_file = True ) as f:
                kw1b = EclKW.fread( f )
                kw2b = EclKW.fread( f )

            self.assertTrue( kw1 == kw1b )
            self.assertTrue( kw2 == kw2b )

            f = EclFile( "TEST.FINIT" )
            self.assertTrue( kw1 == f[0] )
            self.assertTrue( kw2 == f[1] )
Esempio n. 11
0
    def test_kw_write(self):
        with TestAreaContext("python/ecl_kw/writing"):

            data = [random.random() for i in range(10000)]

            kw = EclKW("TEST", len(data), EclTypeEnum.ECL_DOUBLE_TYPE)
            i = 0
            for d in data:
                kw[i] = d
                i += 1

            fortio = FortIO("ECL_KW_TEST", FortIO.WRITE_MODE)
            kw.fwrite(fortio)
            fortio.close()

            fortio = FortIO("ECL_KW_TEST")

            kw2 = EclKW.fread(fortio)

            self.assertTrue(kw.equal(kw2))

            ecl_file = EclFile("ECL_KW_TEST", flags=EclFileFlagEnum.ECL_FILE_WRITABLE)
            kw3 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw3))
            ecl_file.save_kw(kw3)
            ecl_file.close()

            fortio = FortIO("ECL_KW_TEST", FortIO.READ_AND_WRITE_MODE)
            kw4 = EclKW.fread(fortio)
            self.assertTrue(kw.equal(kw4))
            fortio.seek(0)
            kw4.fwrite(fortio)
            fortio.close()

            ecl_file = EclFile("ECL_KW_TEST")
            kw5 = ecl_file["TEST"][0]
            self.assertTrue(kw.equal(kw5))
Esempio n. 12
0
    def test_context(self):
        with TestAreaContext("python/fortio/context") as t:
            kw1 = EclKW("KW" , 2456 , EclDataType.ECL_FLOAT)
            for i in range(len(kw1)):
                kw1[i] = randint(0,1000)

            with openFortIO("file" , mode = FortIO.WRITE_MODE) as f:
                kw1.fwrite( f )
                self.assertEqual( f.filename() , "file")

            t.sync( ) 

            with openFortIO("file") as f:
                kw2 = EclKW.fread( f )

            self.assertTrue( kw1 == kw2 )
Esempio n. 13
0
    def test_context(self):
        with TestAreaContext("python/fortio/context") as t:
            kw1 = EclKW("KW", 2456, EclDataType.ECL_FLOAT)
            for i in range(len(kw1)):
                kw1[i] = randint(0, 1000)

            with openFortIO("file", mode=FortIO.WRITE_MODE) as f:
                kw1.fwrite(f)
                self.assertEqual(f.filename(), "file")

            t.sync()

            with openFortIO("file") as f:
                kw2 = EclKW.fread(f)

            self.assertTrue(kw1 == kw2)