1. Matthew Turk
  2. yt-3.0

Commits

Sam Leitner  committed 6acd615

fixed bug and cleaned up error handling in count_octs

  • Participants
  • Parent commits e7086b9
  • Branches yt-3.0

Comments (0)

Files changed (4)

File yt/frontends/artio/_artio_caller.pyx

View file
 """
 
 """
+import sys #snl this is for debugging
 
 from libc.stdint cimport int32_t, int64_t
 from libc.stdlib cimport malloc, free
     int artio_grid_read_root_cell_end(artio_file handle)
     int artio_grid_read_root_nocts(artio_file handle, int64_t sfc,\
                                   float *variables, int32_t *num_oct_levels, int32_t *num_octs_per_level)
+    int artio_grid_cache_sfc_range(artio_file handle, int64_t start, int64_t end)
 
     ctypedef void (* GridCallBackPos)(float * variables, int level, int refined, int64_t sfc_index, double pos[3])
     int artio_grid_read_sfc_range_pos(artio_file handle,\
 #        cdef int length
 #        while artio_parameter_iterate( self.handle, key, &type, &length ) == ARTIO_SUCCESS :
 #            print 'hi!!'
-
+def check_artio_status(status, name):
+        if status!=ARTIO_SUCCESS :
+            print 'failure with status', status, 'in function ',name 
+            sys.exit(1)
 cdef class artio_fileset :
     cdef public object parameters 
     cdef artio_file handle
         print 'done reading grid parameters'
 
 ###### callback for positions #############
-def count_octs(char *file_prefix,\
-                   int64_t sfc1, int64_t sfc2,\
-                   int min_level_to_read, int max_level_to_read,\
-                   int num_grid_variables
+def count_octs(char *file_prefix,
+               int64_t sfc1, int64_t sfc2,
+               int min_level_to_read, int max_level_to_read,
+               int num_grid_variables
                ) :
-    #max_level_to_read is currently unused, but could be useful
-    cdef artio_file handle
-    handle = artio_fileset_open( file_prefix, ARTIO_OPEN_GRID, artio_context_global ) 
-    artio_fileset_open_grid( handle ) 
-    num_total_octs = 0 
     cdef float * variables  
     cdef int32_t * num_oct_levels 
     cdef int32_t * num_octs_per_level 
+
     length = num_grid_variables * 8
     variables = <float *>malloc(length*sizeof(float))
     num_oct_levels = <int32_t *>malloc(1*sizeof(int32_t))
     length = max_level_to_read
     num_octs_per_level = <int32_t *>malloc(length*sizeof(int32_t))
-    
+
+    cdef artio_file handle
+    handle = artio_fileset_open( file_prefix, ARTIO_OPEN_GRID, artio_context_global ) 
+    artio_fileset_open_grid( handle ) 
+
+    num_total_octs =0
+    status = artio_grid_cache_sfc_range(handle, sfc1, sfc2)
+    check_artio_status(status, count_octs.__name__)
     for sfc in xrange(sfc1,sfc2):
-        artio_grid_read_root_nocts(handle,\
-                                  sfc,\
-                                  variables, num_oct_levels,\
-                                  num_octs_per_level)
+        status = artio_grid_read_root_nocts(handle, sfc,
+                                            variables, num_oct_levels,
+                                            num_octs_per_level)
+        check_artio_status(status, count_octs.__name__)
+        noct_levels = num_oct_levels[0]
         count_level_octs = {}          
-        count_level_octs = [ num_octs_per_level[i] for i in xrange(min(max_level_to_read,1)) ]
+        count_level_octs = [ num_octs_per_level[i] for i in xrange(noct_levels) ]
         num_sfc_octs = sum(count_level_octs)
         num_total_octs += num_sfc_octs
 
-    artio_grid_read_root_cell_end(handle)
+    status = artio_grid_read_root_cell_end(handle)
+    check_artio_status(status, count_octs.__name__)
+    artio_fileset_close_grid(handle)
+
     return num_total_octs
 
 ###### callback for positions #############
                 min_level_to_read, max_level_to_read,\
                 ARTIO_READ_LEAFS,\
                 wrap_cell_pos_callback)
-    if status != ARTIO_SUCCESS :
-        print "exiting sfc range read with error status", status
-        if status == ARTIO_ERR_MEMORY_ALLOCATION :
-            print "cannot allocate enough memory in one sfc range,",\
-                "try loading smaller pieces"
+    check_artio_status(status, grid_pos_fill.__name__)
 
 cdef void wrap_cell_pos_callback(float *variables, int level, int refined, int64_t sfc_index, double *pos):
     position = {}

File yt/frontends/artio/artio_headers/artio_grid.c

View file
 	}
 
 	ghandle = handle->grid;
-/*         variables = (float *)malloc(8*ghandle->num_grid_variables * sizeof(float)); */
-/* 	num_octs_per_level = (int *)malloc(ghandle->file_max_level * sizeof(int)); */
-/* 	num_oct_levels = (int *)malloc(sizeof(int)); */
-/*         printf("%d %d %d\n snl in artio_grid.c", ghandle->num_grid_variables ,ghandle->file_max_level, 1); */
 
 	ret = artio_grid_seek_to_sfc(handle, sfc);
 	if ( ret != ARTIO_SUCCESS ) return ret;

File yt/frontends/artio/data_structures.py

View file
 
         self._read_grid_header()
         self._read_particle_header()
-        print 'here once!!'
 
 #     @property
 #     def level_count(self):
 #        self.grid_offset = f.tell()
 #        self.local_oct_count = hvals['numbl'][self.pf.min_level:, self.domain_id - 1].sum()
         
-        print self._handle.parameters['grid_file_sfc_index'][1], self.pf.min_level
-        print '!!!!!!!!!!!!!!!!!!!!!',self._handle.parameters['grid_max_level'][0]
+        sfc_max = self._handle.parameters['grid_file_sfc_index'][1]-1
         self.local_oct_count = \
             count_octs(self._fileset_prefix,
-                       0, self._handle.parameters['grid_file_sfc_index'][1],
+                       0,sfc_max, 
                        self.pf.min_level,
                        self._handle.parameters['grid_max_level'][0], 
                        self._handle.parameters['num_grid_variables'][0])
            The most important is finding all the information to feed
            oct_handler.add
         """
-        print "in read_grid"
         sfc_max = self._handle.parameters['grid_file_sfc_index'][1]-1
-        sfc_max = 100   # for testing
+        sfc_max = 5   # for testing
         grid_pos_fill(self._fileset_prefix, 0,sfc_max, 0, 10)##########
 
     #snl this is where I would LIKE the callback to go:

File yt/frontends/artio/setup.py

View file
 import glob
 
 sourcefiles = ['yt/frontends/artio/_artio_caller.pyx',
-               'yt/frontends/artio/artio_headers/artio.c',
                'yt/frontends/artio/artio_headers/artio_grid.c',
                'yt/frontends/artio/artio_headers/artio_endian.c',
                'yt/frontends/artio/artio_headers/artio_mpi.c',