Changeset 3510


Ignore:
Timestamp:
25/02/08 14:33:47 (11 years ago)
Author:
ckilburn
Message:

Annotation work

Location:
nappy/trunk/nappy
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/na_file/na_file.py

    r3463 r3510  
    2525import nappy.utils.common_utils 
    2626import nappy.na_error 
     27getAnnotation = nappy.utils.common_utils.getAnnotation 
    2728 
    2829class NAFile(nappy.na_file.na_core.NACore): 
     
    7374        self.is_open = True 
    7475 
    75     def write(self, delimiter="    ", float_format="%8.3f"): 
     76    def write(self, delimiter="    ", float_format="%8.3f", annotation = True): 
    7677        """ 
    7778        Writes an na_dict to the file and then flushes it to ensure data not  
     
    8182        self.float_format = float_format 
    8283        self.format = float_format + delimiter 
     84        self.annotation = annotation 
     85         
    8386        # Raise errors if dangerous behaviour 
    8487        if self.mode != "w": 
     
    172175        Writes the header section common to all NASA Ames files. 
    173176        """ 
    174         self.header.write("%s%s%s\n" % (self.NLHEAD, self.delimiter, self.FFI)) 
    175         self.header.write(nappy.utils.common_utils.getAnnotation("ONAME", delimiter = self.delimiter) + self.ONAME + "\n") 
    176         self.header.write("%s\n" % self.ORG) 
    177         self.header.write("%s\n" % self.SNAME) 
    178         self.header.write("%s\n" % self.MNAME) 
    179         self.header.write("%s%s%s\n" % (self.IVOL, self.delimiter, self.NVOL)) 
    180         self.header.write("%s %s %s%s%s %s %s\n" % (self.DATE[0], self.DATE[1], self.DATE[2], self.delimiter, self.RDATE[0], self.RDATE[1], self.RDATE[2])) 
     177        #Line 1 if often overwritten at _fixHeaderLength 
     178        annotation = getAnnotation("NLHEAD_FFI", self.annotation, delimiter = self.delimiter) 
     179        self.header.write("%s%d%s%d\n" % (annotation, self.NLHEAD, self.delimiter, self.FFI)) 
     180        self.header.write(getAnnotation("ONAME", self.annotation, delimiter = self.delimiter) + self.ONAME + "\n") 
     181        self.header.write(getAnnotation("ORG", self.annotation, delimiter = self.delimiter) + self.ORG + "\n") 
     182        self.header.write(getAnnotation("SNAME", self.annotation, delimiter = self.delimiter) + self.SNAME + "\n") 
     183        self.header.write(getAnnotation("MNAME", self.annotation, delimiter = self.delimiter) + self.MNAME + "\n") 
     184        annotation = getAnnotation("IVOL_NVOL", self.annotation, delimiter = self.delimiter) 
     185        self.header.write("%s%d%s%d\n" % (annotation, self.IVOL, self.delimiter, self.NVOL)) 
     186        annotation = getAnnotation("DATE_RDATE", self.annotation, delimiter = self.delimiter) 
     187        self.header.write("%s%d %d %d%s%d %d %d\n" % (annotation, self.DATE[0], self.DATE[1], self.DATE[2], self.delimiter, self.RDATE[0], self.RDATE[1], self.RDATE[2])) 
    181188 
    182189    def _readVariablesHeaderSection(self): 
     
    268275        lines = self.header.readlines() 
    269276        headlength = len(lines) 
    270         lines[0] = "%s%s%s\n" % (headlength, self.delimiter, self.FFI) 
     277        lines[0] = "%d%s%d\n" % (headlength, self.delimiter, self.FFI) 
    271278        self.header = StringIO.StringIO("".join(lines)) 
    272279        self.header.seek(0)  
  • nappy/trunk/nappy/utils/common_utils.py

    r3463 r3510  
    127127    return d 
    128128 
    129 def getAnnotation(item, delimiter = ',   '): 
     129def getAnnotation(item, annotation, delimiter = ',   '): 
    130130    """ 
    131131    Returns the annotation string for a given NASA Ames item. 
    132132    """ 
    133     #Pick up annotation config here 
    134     annotation = True 
    135      
    136     dict = {"NLHEAD_FFI" : "Number of header lines; sub-format (NASA ames FFI)", 
     133 
     134    dict = {"NLHEAD_FFI" : "Number of header lines and NASA Ames sub-format code", 
    137135            "ONAME" : "Name of data creator", 
    138136            "ORG" : "Institute of data creator", 
    139137            "SNAME" : "Instrument or model", 
    140138            "MNAME" : "Project name", 
    141             "IVOL_NVOL" : "Volume number: Total number of files", 
    142             "DATE_RDATE" : "Starting data of data; File creation date", 
     139            "IVOL_NVOL" : "Volume number and total number of files", 
     140            "DATE_RDATE" : "Starting data of data and file creation date", 
    143141            "DX" : "Interval between coordinate variable values (zero if not used)", 
    144142            "XNAME(1)" : "Name of first coordinate variable [i.e. axis] (with units)", 
Note: See TracChangeset for help on using the changeset viewer.