[Yt-svn] yt: Some updates to the art hierarchy reader

hg at spacepope.org hg at spacepope.org
Thu Oct 14 14:15:34 PDT 2010


hg Repository: yt
details:   yt/rev/590305fb4a7d
changeset: 3441:590305fb4a7d
user:      Matthew Turk <matthewturk at gmail.com>
date:
Thu Oct 14 14:15:03 2010 -0700
description:
Some updates to the art hierarchy reader

diffstat:

 yt/utilities/_amr_utils/fortran_reader.pyx |  29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diffs (62 lines):

diff -r 80e00573f7a9 -r 590305fb4a7d yt/utilities/_amr_utils/fortran_reader.pyx
--- a/yt/utilities/_amr_utils/fortran_reader.pyx	Wed Oct 13 16:38:35 2010 -0700
+++ b/yt/utilities/_amr_utils/fortran_reader.pyx	Thu Oct 14 14:15:03 2010 -0700
@@ -29,6 +29,10 @@
 
 from stdio cimport fopen, fclose, FILE
 
+#cdef inline int imax(int i0, int i1):
+    #if i0 > i1: return i0
+    #return i1
+
 cdef extern from "endian_swap.h":
     void FIX_SHORT( unsigned short )
     void FIX_LONG( unsigned )
@@ -94,20 +98,24 @@
     cdef int readin
     cdef FILE *f = fopen(fn, "rb")
     fseek(f, offset, SEEK_SET)
-    cdef int * Level = <int *> alloca(sizeof(int)*(max_level-min_level+1))
+    cdef int Level
     cdef int * iNOLL = <int *> alloca(sizeof(int)*(max_level-min_level+1))
     cdef int * iHOLL = <int *> alloca(sizeof(int)*(max_level-min_level+1))
     cell_ind = 0
-    for Lev in xrange(min_level + 1, max_level + 1):
+    cdef int total_cells = 0
+    cdef int iOctMax = 0
+    for Lev in range(min_level + 1, max_level + 1):
         fread(&readin, sizeof(int), 1, f); FIX_LONG(readin)
-        print "Reading Hierarchy for Level"
-        fread(&Level[Lev], sizeof(int), 1, f); FIX_LONG(Level[Lev])
-        fread(&iNOLL[Lev], sizeof(int), 1, f); FIX_LONG(iNOLL[Lev])
-        fread(&iHOLL[Lev], sizeof(int), 1, f); FIX_LONG(iHOLL[Lev])
+        fread(&Level, sizeof(int), 1, f); FIX_LONG(Level)
+        fread(&iNOLL[Level], sizeof(int), 1, f); FIX_LONG(iNOLL[Level])
+        fread(&iHOLL[Level], sizeof(int), 1, f); FIX_LONG(iHOLL[Level])
         fread(&readin, sizeof(int), 1, f); FIX_LONG(readin)
-        iOct = iHOLL[Lev] - 1
-        nLevel = iNOLL[Lev]
-        for ic1 in xrange(nLevel):
+        iOct = iHOLL[Level] - 1
+        nLevel = iNOLL[Level]
+        print "Reading Hierarchy for Level", Lev, Level, nLevel, iOct
+        total_cells += nLevel
+        for ic1 in range(nLevel):
+            iOctMax = imax(iOctMax, iOct)
             #print readin, iOct, nLevel, sizeof(int) 
             next_record = ftell(f)
             fread(&readin, sizeof(int), 1, f); FIX_LONG(readin)
@@ -119,7 +127,7 @@
             oct_indices[iOct, 2] = iOctPs[2]
             fread(dummy_records, sizeof(int), 6, f) # skip Nb
             fread(&readin, sizeof(int), 1, f); FIX_LONG(readin)
-            oct_parents[iOct] = readin
+            oct_parents[iOct] = readin - 1
             fread(&readin, sizeof(int), 1, f); FIX_LONG(readin)
             oct_levels[iOct] = readin
             fread(&iOct, sizeof(int), 1, f); FIX_LONG(iOct);
@@ -129,3 +137,4 @@
         next_record = (2*sizeof(int) + readin) * (nLevel * nchild)
         next_record -= sizeof(int)
         fseek(f, next_record, SEEK_CUR)
+    print "Read this many cells", total_cells, iOctMax



More information about the yt-svn mailing list