C.2 read_grid_str.py

#!/usr/bin/env python
#
# User's Guide to CGNS - C.L.Rumsey et al. examples translation
# ## read_grid_str.py
# This is an example translation, this is a not straight word-to-word
# translation, it also tryes to emphasize some Python constructs
#
import CGNS
from Numeric import *

(imax,jmax,kmax)=(21,17,9)

#   open CGNS file for read-only
file=CGNS.pyCGNS('grid.cgns',CGNS.MODE_READ)

#   we know there is only one base and zone (real working code would check!)
(index_base,index_zone)=(1,1)

#   get zone size (and name - although not needed here)
(base_index,index_zone,zonename,isize)=file.zoneread(index_base,index_zone)

#   lower range index
irmin=[1,1,1]

#   upper range index of vertices
irmax=[isize[0],isize[1],isize[2]]

#   read grid coordinates (min/max not used)
x=file.coordread(index_base,index_zone,CGNS.CoordinateX)
y=file.coordread(index_base,index_zone,CGNS.CoordinateY)
z=file.coordread(index_base,index_zone,CGNS.CoordinateZ)

#   close CGNS file
file.close()