gridspec_api/host/nccf_access_hostfile.py

00001 #!/usr/bin/env python
00002 """
00003 CDAT cdms2 gridspec extension. Allow a gridspec hostfile to opened as a single
00004 point of access to a mosaic.
00005 
00006 $Id: nccf_access_hostfile.py 336 2011-01-07 00:02:25Z dkindig $
00007 """
00008 from ctypes import * 
00009 import os.path
00010 import sys
00011 import cdms2
00012 
00013 class gridspecLibrary():
00014   def __init__(self):
00015     """
00016     Constructor - Create the gridspec cf library object
00017     """
00018 
00019     self.home = "/home/kindig/software/"
00020     self.libcf_dir = "libcf_uuid/lib/"
00021     self.libcf_so  = "libcf_gridspec.so"
00022 
00023     self.cf = CDLL(self.home + self.libcf_dir + self.libcf_so)
00024 
00025     return
00026 
00027 class hostFile:
00028   def __init__(self, hostfile, origHostFile):
00029     """
00030     Constructor
00031     @param filename - open the file and create an entire mosaic object
00032     @param gsLib - The GRIDSPEC API library
00033     """
00034 
00035     cf = gridspecLibrary()
00036     self.cf = cf.cf
00037 
00038     self.CF_MAX_STRING_SIZE = 256
00039 
00040     self.hId = c_int()
00041     self.mId = c_int()
00042     self.mosaic_filename = create_string_buffer(self.CF_MAX_STRING_SIZE)
00043 
00044     # Query the hostfile
00045     self.openHost(hostfile)
00046     self.getMosaicFilename()
00047 
00048 #    self.getGridFilenames()
00049 
00050   def openHost(self, hostfile):
00051     """
00052     Open and create the host file object with hId
00053     @param hostfile - The name of the host file
00054     """
00055 
00056     self.cf.nccf_def_host_from_file(hostfile, byref(self.hId))
00057 
00058   def getGridIds(self):
00059     """
00060     Read the grid filenames from host object
00061     """
00062     pass
00063 
00064   def getMosaicFilename(self):
00065     """
00066     Read the mosaic filename from host object
00067     """
00068 
00069     self.cf.nccf_get_host_mosaic_filename(self.hId, self.mosaic_filename)
00070     self.cf.nccf_get_host_mosaicid(self.hId, byref(self.mId))
00071 
00072     crdnm = (c_char_p*2)
00073     aa = crdnm()
00074     aa[0] = " " * self.CF_MAX_STRING_SIZE
00075     aa[1] = " " * self.CF_MAX_STRING_SIZE
00076 
00077     self.cf.nccf_get_mosaic_coord_names(self.mId, aa)
00078     self.coordinates = [aa[0], aa[1]]
00079 
00080     return
00081 
00082   # These functions get various items within the mosaic
00083 
00084   def getGrid(self, gridId):
00085     """
00086     Return a specific grid from the mosaic
00087     """
00088     pass
00089 
00090   def getVariable(self):
00091     """
00092     Return a specific variable from the mosaic
00093     """
00094     pass
00095 
00096   def getVariables(self):
00097     """
00098     Return all variables from the mosaic
00099     """
00100     pass
00101 
00102   def getAttribute(self, attid):
00103     """
00104     Return an attribute from the mosaic
00105     """
00106     pass
00107 
00108   def getDimensionUnits(self, dimid):
00109     """
00110     Return the units for a dimension from the mosaic
00111     """
00112     pass
00113 
00114   def getGlobal(self, attid):
00115     """
00116     Return a global attribute from the mosaic
00117     """
00118     pass
00119 
00120   def getSlab(self, varid, slabinfo ):
00121     """
00122     Return a slab of data for a variable from the mosaic
00123     """
00124     pass
00125 
00126   # These functions return information regarding the details of the mosaic 
00127   # described by the host file.
00128   def listall(self):
00129     """
00130     List all global attributes, attributes, dimensions and variables 
00131     associated with the hostfile
00132     """
00133     pass
00134 
00135   def listattributes(self):
00136     """
00137     List attributes associated with the hostfile
00138     """
00139     pass
00140 
00141   def listdimensions(self):
00142     """
00143     List dimensions associated with the hostfile
00144     """
00145     pass
00146 
00147   def listglobals(self):
00148     """
00149     List global attributes associated with the hostfile
00150     """
00151     pass
00152 
00153   def listvariable(self, varid):
00154     """
00155     List a specific variable attributes and dimensions associated with the
00156     hostfile
00157     """
00158     pass
00159 
00160   def listvariables(self):
00161     """
00162     List all variables attributes and dimensions associated with the
00163     hostfile
00164     """
00165     pass
00166 
00167 def main():
00168 
00169   # Define a file
00170   home = "/home/kindig/projects/libcf/libcf/build/gridspec_api/"
00171   host = "host/"
00172   hfil = "tst_three_tile_cubed_sphere_host.nc"
00173   hostfile = home + host + hfil
00174 
00175   # Exit if file doesn't exist
00176   if not os.path.isfile(hostfile): 
00177     sys.exit(1)
00178 
00179   origHostFile = cdms2.open(hostfile)
00180 
00181   if 'file_type' in origHostFile.listglobal():
00182     newHostFile = hostFile(hostfile, origHostFile)
00183 
00184 if __name__ == '__main__':
00185   main()
 All Classes Files Functions Defines

Generated on Tue Mar 1 2011 06:36:59 for libCF. LibCF is a Unidata library.