[cig-commits] r4497 - mc/3D/CitcomS/trunk/visual

tan2 at geodynamics.org tan2 at geodynamics.org
Fri Sep 8 12:14:12 PDT 2006


Author: tan2
Date: 2006-09-08 12:14:12 -0700 (Fri, 08 Sep 2006)
New Revision: 4497

Modified:
   mc/3D/CitcomS/trunk/visual/h52combined.py
Log:
* Using 'caps' attribute in the input group
* frame -> timestep conversion
* Cleaned up the code


Modified: mc/3D/CitcomS/trunk/visual/h52combined.py
===================================================================
--- mc/3D/CitcomS/trunk/visual/h52combined.py	2006-09-08 17:13:41 UTC (rev 4496)
+++ mc/3D/CitcomS/trunk/visual/h52combined.py	2006-09-08 19:14:12 UTC (rev 4497)
@@ -4,8 +4,8 @@
 #
 #<LicenseText>
 #
-# CitcomS.py by Eh Tan, Eun-seo Choi, and Pururav Thoutireddy.
-# Copyright (C) 2002-2005, California Institute of Technology.
+# CitcomS.py by Eh Tan
+# Copyright (C) 2002-2006, California Institute of Technology.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -25,10 +25,10 @@
 #
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-'''Convert the HDF5 output file to ASCII file(s), with the same format as the
-combined file
+'''Convert the HDF5 output file to ASCII file(s), with the format of the
+combined cap files
 
-usage: h52combined.py h5file step1 [step2 [...] ]
+usage: h5tocap.py h5file frame1 [frame2 [...] ]
 '''
 
 import tables
@@ -46,39 +46,31 @@
 
 
 
-def convert(h5file, prefix, record):
-    print 'in convert():', h5file, prefix, record
-
+def convert(h5file, prefix, frame):
     f = tables.openFile(h5file)
-
     try:
+        caps = int(f.root.input._v_attrs.caps)
+        steps = f.root.time.col('step')
+
         # loop through all the caps
-        for cap in range(12):
+        for cap in range(caps):
             cap_no = 'cap%02d' % cap
+            group = getattr(f.root, cap_no)
 
-            # get 'cap_no' group, if no such group, return None
-            group = _get_hdf_group(f.root, cap_no)
-            print repr(group)
-            if group is None:
-                break
-
             x = group.coord
-            v = group.velocity[record,:]
-            t = group.temperature[record,:]
-            visc = group.viscosity[record,:]
+            v = group.velocity[frame,:]
+            t = group.temperature[frame,:]
+            visc = group.viscosity[frame,:]
 
-            # TODO: map record -> step
-            outputfile = '%s.%s.%d' % (prefix, cap_no, record)
-            #print outputfile
+            outputfile = '%s.%s.%d' % (prefix, cap_no, steps[frame])
 
+            print 'writing to', outputfile, '...'
             output(outputfile, x, v, t, visc)
 
-
-
     finally:
         f.close()
 
-    return outputfile
+    return
 
 
 
@@ -109,26 +101,10 @@
     finally:
         out.close()
 
+    return
 
 
-def _get_hdf_group(base, child):
-    try:
-        return base._f_getChild(child)
-    except tables.exceptions.NoSuchNodeError:
-        return None
 
-
-
-def make_general(outputfile):
-    import os
-
-    path = os.path.dirname(__file__)
-    cmd = '%s/dxgeneral.sh %s' % (path, outputfile)
-    #print cmd
-    os.system(cmd)
-
-
-
 if __name__ == '__main__':
     import sys
 
@@ -140,13 +116,11 @@
     h5file = sys.argv[1]
     file_prefix = find_prefix(h5file)
 
-    steps = [ int(x) for x in sys.argv[2:] ]
+    frames = [ int(x) for x in sys.argv[2:] ]
 
 
-    for step in steps:
+    for frame in frames:
         # write to outputfile
-        outputfile = convert(h5file, file_prefix, step)
+        convert(h5file, file_prefix, frame)
 
-        # generate header file for OpenDX
-        make_general(outputfile)
 



More information about the cig-commits mailing list