#! /usr/bin/env python # # Python script to list the variables in a netcdf file. # # Execute from a bash shell, for example: # # lsnc.py file_name.nc # import sys from Numeric import * from Scientific.IO.NetCDF import * # print "arguments are:" # print sys.argv filename = sys.argv[1] # file = NetCDFFile('as11a.out.nc', 'r') file = NetCDFFile(filename, 'r') print "" print "Global attributes of this NetCDF file:" print "" print file.__dict__ print "" print "" print "This NetCDF file contains dimensions:" print "" print file.dimensions print "" print "" print "This NetCDF file contains variables:" print "" # print file.variables # this reports a dictionary, enclosed in {} print file.variables.keys() # a more readable list. print "" print "" print "Variable descriptions:" print "Variable, descriptions" print "Variable, shapes, dimension labels:" print "" #for name, var in file.variables.items(): keys = file.variables.keys() keys.sort() for name in keys: var = file.variables[name] print name, var.__dict__ print name, var.shape, var.dimensions print " " # phi_obj = file.variables['phi2'] # phi = phi_obj[:] # phi_units = phi_obj.units # print phi_obj.__dict__ # print phi[0] # # t = file.variables['t'][:] file.close()