<p><b>mhoffman@lanl.gov</b> 2012-05-23 13:55:35 -0600 (Wed, 23 May 2012)</p><p> BRANCH COMMIT -- land ice<br>
Updating the python tool for copying a regular grid (CISM) to an MPAS planar grid.<br>
It now works with the netCDF4 python module (i.e. on Jaguar).<br>
Also corrected the copying of the 'beta' field to be time independent because that is how it is setup (currently) in MPAS Registry.<br>
</p><hr noshade><pre><font color="gray">Modified: branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py
===================================================================
--- branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py        2012-05-23 14:50:23 UTC (rev 1932)
+++ branches/land_ice_projects/grid_tools/copy_CISM_grid_to_MPAS_grid.py        2012-05-23 19:55:35 UTC (rev 1933)
@@ -2,7 +2,18 @@
 # Copy fields from a regular CISM grid into a pre-existing MPAS grid 
 
 import sys, numpy
-from Scientific.IO.NetCDF import *
+try:
+  from Scientific.IO.NetCDF import NetCDFFile
+  netCDF_module = 'Scientific.IO.NetCDF'
+except ImportError:
+  try:
+    from netCDF4 import Dataset as NetCDFFile
+    netCDF_module = 'netCDF4'
+  except ImportError:
+      print 'Unable to import any of the following python modules:'
+      print '  Scientific.IO.NetCDF </font>
<font color="gray">  netcdf4 '
+      print 'One of them must be installed.'
+      raise ImportError('No netCDF module found')
 import math
 #import scipy.interpolate
 
@@ -58,7 +69,10 @@
 
     # Get the CISM dimensions if they exist
     try:
-      level = infile.dimensions['level']
+      if netCDF_module == 'Scientific.IO.NetCDF':
+        level = infile.dimensions['level']
+      else:
+        level = len(infile.dimensions['level'])
     except:
       print 'Input file is missing the dimension level.  Might not be a problem.'
 
@@ -101,8 +115,15 @@
 # Open the output file, get needed dimensions &amp; variables
 try:
     outfile = NetCDFFile(outfilename,'r+')
-    nVertLevels = outfile.dimensions['nVertLevels']
+    try:
+      if netCDF_module == 'Scientific.IO.NetCDF':
+        nVertLevels = outfile.dimensions['nVertLevels']
+      else:
+        nVertLevels = len(outfile.dimensions['nVertLevels'])
+    except:
+      print 'Output file is missing the dimension nVertLevels.  Might not be a problem.'
 
+
     # 1d vertical fields
     layerThicknessFractions = outfile.variables['layerThicknessFractions'][:]
 
@@ -158,7 +179,8 @@
       sf = 1.0
     beta = outfile.variables['beta']
     print '</font>
<font color="red">input beta min/max', inbeta[:].min()*sf, inbeta[:].max()*sf
-    beta[timelevout,:] = BilinearInterp(x0, y0, inbeta[timelev,:,:]*sf, xCell, yCell)
+    #beta[timelevout,:] = BilinearInterp(x0, y0, inbeta[timelev,:,:]*sf, xCell, yCell)
+    beta[:] = BilinearInterp(x0, y0, inbeta[timelev,:,:]*sf, xCell, yCell)
     print 'new beta min/max', beta[:].min(), beta[:].max()
     del inbeta, beta
 except:

</font>
</pre>