Changeset 3521 for nappy/trunk


Ignore:
Timestamp:
26/02/08 18:36:04 (12 years ago)
Author:
ckilburn
Message:

Annotations and isolating reverses on write

Location:
nappy/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/annotations.ini

    r3519 r3521  
    99DX=Interval between coordinate variable values (zero if not used) 
    1010NVPM=Number of extra independent variable points between independent variable values 
     11NX=Number of coordinate variable values 
     12NXDEF=Number of coordinate variable values explicity defined in header 
     13X=Values of coordinate variable 
     14LENX=Number of characters in character-based coordinate variable 
     15LENA=Number of characters in character-based auxiliary variable 
    1116XNAME=Name of coordinate variable [i.e. axis] (with units) 
    1217NV=Number of variables at each point (i.e. defined against both axes) 
     
    1520VNAME=Name of variable (with units) 
    1621NAUXV=Number of auxiliary variables (variables defined with one value) 
    17 ASCAL=Scale factors for each auxiliary variable 
    18 AMISS=Missing values for each auxiliary variable 
    19 ANAME=Name of auxiliary variable [long name in square brackets] (with units) 
     22NAUXC=Number of character-based auxiliary variables (variables defined with one value) 
     23ASCAL=Scale factors for auxiliary variable(s) 
     24AMISS=Missing values for auxiliary variable(s) 
     25ANAME=Name of auxiliary variable (with units) 
    2026NSCOML=Number of lines of special comments 
    2127SCOM=Special comments line 
  • nappy/trunk/nappy/na_file/na_file.py

    r3515 r3521  
    2626import nappy.na_error 
    2727getAnnotation = nappy.utils.common_utils.getAnnotation 
     28wrapLine = nappy.utils.common_utils.annotateLine 
     29wrapLines = nappy.utils.common_utils.annotateLines 
    2830 
    2931class NAFile(nappy.na_file.na_core.NACore): 
     
    176178        """ 
    177179        #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(wrapLine("NLHEAD_FFI", self.annotation, self.delimiter, "%d%s%d\n" % (self.NLHEAD, self.delimiter, self.FFI))) 
    180181        self.header.write(getAnnotation("ONAME", self.annotation, delimiter = self.delimiter) + self.ONAME + "\n") 
    181182        self.header.write(getAnnotation("ORG", self.annotation, delimiter = self.delimiter) + self.ORG + "\n") 
    182183        self.header.write(getAnnotation("SNAME", self.annotation, delimiter = self.delimiter) + self.SNAME + "\n") 
    183184        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])) 
     185        self.header.write(wrapLine("IVOL_NVOL", self.annotation, self.delimiter, "%d%s%d\n" % (self.IVOL, self.delimiter, self.NVOL))) 
     186        line = "%d %d %d%s%d %d %d\n" % (self.DATE[0], self.DATE[1], self.DATE[2], self.delimiter, self.RDATE[0], self.RDATE[1], self.RDATE[2]) 
     187        self.header.write(wrapLine("DATE_RDATE", self.annotation, self.delimiter, line)) 
    188188 
    189189    def _readVariablesHeaderSection(self): 
     
    202202        Assumes we are at the right point in the file. 
    203203        """ 
    204         annotation = getAnnotation("NV", self.annotation, delimiter = self.delimiter) 
    205         self.header.write("%s%d\n" % (annotation, self.NV)) 
    206         annotation = getAnnotation("VSCAL", self.annotation, delimiter = self.delimiter) 
    207         self.header.write((annotation + ("%s" + self.delimiter) * (self.NV - 1) + "%s\n") % tuple(self.VSCAL)) 
    208         annotation = getAnnotation("VMISS", self.annotation, delimiter = self.delimiter) 
    209         self.header.write((annotation + ("%s" + self.delimiter) * (self.NV - 1) + "%s\n") % tuple(self.VMISS)) 
    210         annotation = getAnnotation("VNAME", self.annotation, delimiter = self.delimiter) 
    211         self.header.write((annotation + "%s\n") * self.NV % tuple(self.VNAME)) 
     204        self.header.write(wrapLine("NV", self.annotation, self.delimiter, "%d\n" % self.NV)) 
     205        self.header.write(wrapLine("VSCAL", self.annotation, self.delimiter, (("%s" + self.delimiter) * (self.NV - 1) + "%s\n") % tuple(self.VSCAL))) 
     206        self.header.write(wrapLine("VMISS", self.annotation, self.delimiter, (("%s" + self.delimiter) * (self.NV - 1) + "%s\n") % tuple(self.VMISS))) 
     207        self.header.write(wrapLines("VNAME", self.annotation, self.delimiter, "%s\n" * self.NV % tuple(self.VNAME))) 
    212208 
    213209    def _readAuxVariablesHeaderSection(self): 
     
    227223        Assumes we are at the right point in the file. 
    228224        """ 
    229         annotation = getAnnotation("NAUXV", self.annotation, delimiter = self.delimiter) 
    230         self.header.write("%s%d\n" % (annotation, self.NAUXV)) 
     225        self.header.write(wrapLine("NAUXV", self.annotation, self.delimiter, "%d\n" % self.NAUXV)) 
    231226        if self.NAUXV > 0: 
    232             annotation = getAnnotation("ASCAL", self.annotation, delimiter = self.delimiter) 
    233             self.header.write((annotation + ("%s" + self.delimiter) * (self.NAUXV - 1) + "%s\n")  % tuple(self.ASCAL)) 
    234             annotation = getAnnotation("AMISS", self.annotation, delimiter = self.delimiter) 
    235             self.header.write((annotation + ("%s" + self.delimiter) * (self.NAUXV - 1) + "%s\n")  % tuple(self.AMISS)) 
    236             annotation = getAnnotation("ANAME", self.annotation, delimiter = self.delimiter) 
    237             self.header.write((annotation + "%s\n") * self.NAUXV % tuple(self.ANAME)) 
     227            line = (("%s" + self.delimiter) * (self.NAUXV - 1) + "%s\n")  % tuple(self.ASCAL) 
     228            self.header.write(wrapLine("ASCAL", self.annotation, self.delimiter, line)) 
     229            line = (("%s" + self.delimiter) * (self.NAUXV - 1) + "%s\n")  % tuple(self.AMISS) 
     230            self.header.write(wrapLine("AMISS", self.annotation, self.delimiter, line)) 
     231            line = "%s\n" * self.NAUXV % tuple(self.ANAME) 
     232            self.header.write(wrapLines("ANAME", self.annotation, self.delimiter, line)) 
    238233 
    239234    def _readCharAuxVariablesHeaderSection(self): 
     
    269264        Assumes we are at the right point in the file. 
    270265        """ 
    271         annotation = getAnnotation("NSCOML", self.annotation, delimiter = self.delimiter) 
    272         self.header.write(annotation + "%d\n" % self.NSCOML) 
    273         annotation = getAnnotation("SCOM", self.annotation, delimiter = self.delimiter) 
    274         self.header.write((annotation + "%s\n") * self.NSCOML % tuple(self.SCOM)) 
    275         annotation = getAnnotation("NNCOML", self.annotation, delimiter = self.delimiter) 
    276         self.header.write(annotation + "%d\n" % self.NNCOML) 
    277         annotation = getAnnotation("NCOM", self.annotation, delimiter = self.delimiter) 
    278         self.header.write((annotation + "%s\n") * self.NNCOML % tuple(self.NCOM)) 
     266        self.header.write(wrapLine("NSCOML", self.annotation, self.delimiter, "%d\n" % self.NSCOML)) 
     267        self.header.write(wrapLines("SCOM", self.annotation, self.delimiter, "%s\n" * self.NSCOML % tuple(self.SCOM))) 
     268        self.header.write(wrapLine("NNCOML", self.annotation, self.delimiter, "%d\n" % self.NNCOML)) 
     269        self.header.write(wrapLines("NCOM", self.annotation, self.delimiter, "%s\n" * self.NNCOML % tuple(self.NCOM))) 
    279270 
    280271    def _fixHeaderLength(self): 
     
    287278        lines = self.header.readlines() 
    288279        headlength = len(lines) 
    289         annotation = getAnnotation("NLHEAD_FFI", self.annotation, delimiter = self.delimiter) 
    290         lines[0] = "%s%d%s%d\n" % (annotation, headlength, self.delimiter, self.FFI) 
     280        lines[0] = wrapLine("NLHEAD_FFI", self.annotation, self.delimiter, "%d%s%d\n" % (headlength, self.delimiter, self.FFI)) 
    291281        self.header = StringIO.StringIO("".join(lines)) 
    292282        self.header.seek(0)  
  • nappy/trunk/nappy/na_file/na_file_1001.py

    r3519 r3521  
    1818import nappy.utils.common_utils 
    1919getAnnotation = nappy.utils.common_utils.getAnnotation 
     20wrapLine = nappy.utils.common_utils.annotateLine 
     21wrapLines = nappy.utils.common_utils.annotateLines 
    2022 
    2123 
     
    8789        for m in range(len(self.X)): 
    8890 
    89             var_string = var_string + (self.format % self.X[m]) 
     91            var_string = self.format % self.X[m] 
    9092 
    9193            for n in range(self.NV): 
  • nappy/trunk/nappy/na_file/na_file_2010.py

    r3461 r3521  
    1717import nappy.utils.list_manipulator 
    1818import nappy.na_file.na_file 
     19import nappy.utils.common_utils 
     20wrapLine = nappy.utils.common_utils.annotateLine 
     21wrapLines = nappy.utils.common_utils.annotateLines 
    1922 
    2023 
     
    5154    def writeHeader(self): 
    5255        """ 
    53         Writes FFI-specifc header section. 
     56        Writes FFI-specific header section. 
    5457        """         
    5558        self._writeCommonHeader() 
    56         self.DX.reverse() 
    57         self.header.write((("%s" + self.delimiter) * (self.NIV - 1) + "%s\n") % tuple(self.DX)) 
    58         self.NX.reverse() 
    59         self.header.write((("%s" + self.delimiter) * (self.NIV - 2) + "%s\n") % tuple(self.NX)) 
    60         self.NXDEF.reverse() 
    61         self.header.write((("%s" + self.delimiter) * (self.NIV - 2) + "%s\n") % tuple(self.NXDEF)) 
    62         self.NXDEF.reverse() 
     59        DX = self.DX 
     60        DX.reverse() 
     61        self.header.write(wrapLine("DX", self.annotation, self.delimiter, (("%s" + self.delimiter) * (self.NIV - 1) + "%s\n") % tuple(DX))) 
     62        NX = self.NX 
     63        NX.reverse() 
     64        self.header.write(wrapLine("NX", self.annotation, self.delimiter, (("%s" + self.delimiter) * (self.NIV - 2) + "%s\n") % tuple(NX))) 
     65        NXDEF = self.NXDEF 
     66        NXDEF.reverse() 
     67        self.header.write(wrapLine("NXDEF", self.annotation, self.delimiter, (("%s" + self.delimiter) * (self.NIV - 2) + "%s\n") % tuple(NXDEF))) 
     68 
    6369        X_lines = [] 
    6470 
     
    6874        X_lines.reverse() 
    6975        for line in X_lines: 
    70             self.header.write(line.lstrip()) 
     76            self.header.write(wrapLine("X", self.annotation, self.delimiter, line.lstrip())) 
    7177 
    72         self.XNAME.reverse() 
    73         self.header.write("%s\n" * self.NIV % tuple(self.XNAME)) 
     78        XNAME = self.XNAME 
     79        XNAME.reverse() 
     80        self.header.write(wrapLines("XNAME", self.annotation, self.delimiter, "%s\n" * self.NIV % tuple(XNAME))) 
    7481        self._writeVariablesHeaderSection() 
    7582        self._writeAuxVariablesHeaderSection() 
     
    135142            for a in range(self.NAUXV): 
    136143                var_string = var_string + (self.format % self.A[a][m]) 
    137             self.file.write("%s\n" % var_string.rstrip(" ,")) 
     144            self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
    138145             
    139146            # Write Variables 
     
    141148                outlines = nappy.utils.list_manipulator.recursiveListWriter(self.V[n][m], self.NX, delimiter = self.delimiter, float_format = self.float_format) 
    142149                for line in outlines: 
    143                     self.file.write(line) 
     150                    self.file.write(wrapLine("Data", self.annotation, self.delimiter, line)) 
    144151 
    145152    def _normalizeIndVars(self): 
  • nappy/trunk/nappy/na_file/na_file_2110.py

    r3491 r3521  
    1616import nappy.utils.text_parser 
    1717import nappy.na_file.na_file_2010 
     18import nappy.utils.common_utils 
     19wrapLine = nappy.utils.common_utils.annotateLine 
     20wrapLines = nappy.utils.common_utils.annotateLines 
    1821 
    1922class NAFile2110(nappy.na_file.na_file_2010.NAFile2010): 
     
    3841    def writeHeader(self): 
    3942        """ 
    40         Writes FFI-specifc header section. 
     43        Writes FFI-specific header section. 
    4144        """ 
    4245        self._writeCommonHeader() 
    43         self.DX.reverse() 
    44         self.header.write((("%s" + self.delimiter) * (self.NIV - 1) + "%s\n") % tuple(self.DX)) 
    45         self.XNAME.reverse() 
    46         self.header.write("%s\n" * self.NIV % tuple(self.XNAME)) 
     46        DX = self.DX 
     47        DX.reverse() 
     48        self.header.write(wrapLine("DX", self.annotation, self.delimiter, (("%s" + self.delimiter) * (self.NIV - 1) + "%s\n") % tuple(DX))) 
     49        XNAME = self.XNAME 
     50        XNAME.reverse() 
     51        self.header.write(wrapLines("XNAME", self.annotation, self.delimiter, "%s\n" * self.NIV % tuple(XNAME))) 
    4752        self._writeVariablesHeaderSection() 
    4853        self._writeAuxVariablesHeaderSection() 
     
    122127            for a in range(self.NAUXV):  
    123128                var_string = var_string + (self.format % self.A[a][m]) 
    124             self.file.write("%s\n" % var_string.rstrip(" ,")) 
     129            self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
    125130 
    126131            # Write second independant variable and dependant variables 
     
    131136                    var_string = var_string + (self.format %self.V[n][m][p]) 
    132137 
    133                 self.file.write("%s\n" %var_string.rstrip(" ,")) 
     138                self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" %var_string.rstrip(" ,"))) 
  • nappy/trunk/nappy/na_file/na_file_2160.py

    r3461 r3521  
    1616import nappy.utils.text_parser 
    1717import nappy.na_file.na_file_2110 
     18import nappy.utils.common_utils 
     19wrapLine = nappy.utils.common_utils.annotateLine 
     20wrapLines = nappy.utils.common_utils.annotateLines 
    1821 
    1922class NAFile2160(nappy.na_file.na_file_2110.NAFile2110): 
     
    4245        """ 
    4346        self._writeCommonHeader() 
    44         self.DX.reverse() 
    45         self.header.write("%s\n" % tuple(self.DX)) 
    46         self.header.write("%s\n" % self.LENX) 
    47         self.XNAME.reverse() 
    48         self.header.write("%s\n" * self.NIV % tuple(self.XNAME)) 
     47        DX = self.DX 
     48        DX.reverse() 
     49        self.header.write(wrapLine("DX", self.annotation, self.delimiter, "%s\n" % tuple(DX))) 
     50        self.header.write(wrapLine("LENX", self.annotation, self.delimiter, "%s\n" % self.LENX)) 
     51        XNAME = self.XNAME 
     52        XNAME.reverse() 
     53        self.header.write(wrapLines("XNAME", self.annotation, self.delimiter, "%s\n" * self.NIV % tuple(XNAME))) 
    4954        self._writeVariablesHeaderSection() 
    5055        self._writeAuxVariablesHeaderSection() 
     
    5863        Assumes we are at the right point in the file. 
    5964        """ 
    60         self.header.write("%s\n" % self.NAUXV) 
    61         self.header.write("%s\n" % self.NAUXC) 
     65        self.header.write(wrapLine("NAUXV", self.annotation, self.delimiter, "%d\n" % self.NAUXV)) 
     66        self.header.write(wrapLine("NAUXC", self.annotation, self.delimiter, "%d\n" % self.NAUXC)) 
    6267        if self.NAUXV > 0: 
    63             self.header.write((("%s" + self.delimiter) * (self.NAUXV - self.NAUXC - 1) + "%s\n")  % tuple(self.ASCAL)) 
    64             self.header.write((("%s" + self.delimiter) * (self.NAUXV - self.NAUXC - 1) + "%s\n")  % tuple(self.AMISS[0:(self.NAUXV - self.NAUXC)])) 
    65             self.header.write((("%s" + self.delimiter) * (self.NAUXC - 1) + "%s\n") % tuple(self.LENA[(self.NAUXV - self.NAUXC):])) 
    66             self.header.write(("%s\n" * self.NAUXC) % tuple(self.AMISS[(self.NAUXV - self.NAUXC):])) 
    67             self.header.write("%s\n" * self.NAUXV % tuple(self.ANAME)) 
     68            line = (("%s" + self.delimiter) * (self.NAUXV - self.NAUXC - 1) + "%s\n")  % tuple(self.ASCAL) 
     69            self.header.write(wrapLine("ASCAL", self.annotation, self.delimiter, line)) 
     70            line = (("%s" + self.delimiter) * (self.NAUXV - self.NAUXC - 1) + "%s\n")  % tuple(self.AMISS[0:(self.NAUXV - self.NAUXC)]) 
     71            self.header.write(wrapLine("AMISS", self.annotation, self.delimiter, line)) 
     72            line = (("%s" + self.delimiter) * (self.NAUXC - 1) + "%s\n") % tuple(self.LENA[(self.NAUXV - self.NAUXC):]) 
     73            self.header.write(wrapLine("LENA", self.annotation, self.delimiter, line)) 
     74            line = ("%s\n" * self.NAUXC) % tuple(self.AMISS[(self.NAUXV - self.NAUXC):]) 
     75            self.header.write(wrapLines("AMISS", self.annotation, self.delimiter, line)) 
     76            line = "%s\n" * self.NAUXV % tuple(self.ANAME) 
     77            self.header.write(wrapLines("ANAME", self.annotation, self.delimiter, line)) 
    6878 
    6979    def _setupArrays(self): 
     
    122132            # Write Independent variable mark and auxiliary variables 
    123133            var_string = "%s" % self.X[m][0] 
    124             self.file.write("%s\n" % var_string.rstrip(" ,")) 
     134            self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
    125135            var_string = "" 
    126136 
     
    128138                var_string = var_string + (self.format % self.A[a][m]) 
    129139 
    130             self.file.write("%s\n" % var_string.rstrip(" ,")) 
     140            self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
    131141 
    132142            for a in range(self.NAUXC): 
    133143                var_string = (("%s" + self.delimiter) % self.A[(self.NAUXV - self.NAUXC) + a][m]) 
    134                 self.file.write("%s\n" % var_string.rstrip(" ,")) 
     144                self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
    135145 
    136146            # Write second independant variable and dependant variables 
     
    141151                    var_string = var_string + (self.format % self.V[n][m][p]) 
    142152 
    143                 self.file.write("%s\n" % var_string.rstrip(" ,")) 
     153                self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
  • nappy/trunk/nappy/na_file/na_file_2310.py

    r3491 r3521  
    1616import nappy.utils.text_parser 
    1717import nappy.na_file.na_file_2110 
     18import nappy.utils.common_utils 
     19wrapLine = nappy.utils.common_utils.annotateLine 
     20wrapLines = nappy.utils.common_utils.annotateLines 
    1821 
    1922class NAFile2310(nappy.na_file.na_file_2110.NAFile2110): 
     
    4144        """ 
    4245        self._writeCommonHeader() 
    43         #self.DX.reverse() 
    44         self.header.write(("%s\n") % self.DX[0]) 
    45         self.XNAME.reverse() 
    46         self.header.write("%s\n" * self.NIV % tuple(self.XNAME)) 
     46        self.header.write(wrapLine("DX", self.annotation, self.delimiter, "%s\n" % self.DX[0])) 
     47        XNAME = self.XNAME 
     48        XNAME.reverse() 
     49        self.header.write(wrapLines("XNAME", self.annotation, self.delimiter, "%s\n" * self.NIV % tuple(self.XNAME))) 
    4750        self._writeVariablesHeaderSection() 
    4851        self._writeAuxVariablesHeaderSection() 
     
    103106                var_string = var_string + (self.format % self.A[a][m]) 
    104107 
    105             self.file.write("%s\n" % var_string.rstrip(" ,")) 
     108            self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
    106109 
    107110            # Write second independant variable and dependant variables 
     
    110113                for n in range(self.NV): 
    111114                    var_string = var_string + (self.format %self.V[n][m][p]) 
    112             self.file.write("%s\n" %var_string.rstrip(" ,")) 
     115            self.file.write(wrapLine("Data", self.annotation, self.delimiter, "%s\n" % var_string.rstrip(" ,"))) 
  • nappy/trunk/nappy/unit_tests/ck_test.py

    r3519 r3521  
    1010import nappy.na_file.na_file 
    1111 
    12 infile = os.path.join(base_dir, "data_files", "1020.na") 
    13 outfile = os.path.join(base_dir, "test_outputs", "test_1020.na") 
     12infile = os.path.join(base_dir, "data_files", "2160.na") 
     13outfile = os.path.join(base_dir, "test_outputs", "test_2160.na") 
    1414print "Opening the infile" 
    1515fin = nappy.openNAFile(infile) 
  • nappy/trunk/nappy/utils/common_utils.py

    r3519 r3521  
    165165    """ 
    166166 
    167     print "Incoming lines are", lines 
     167    #print "Incoming lines are", lines 
    168168    split_lines = lines.splitlines(1) 
    169169    output = "" 
     
    171171        output = output + annotateLine(item_name, annotate, delimiter, line) 
    172172 
    173     print "Outgoing lines are", output 
     173    #print "Outgoing lines are", output 
    174174    return output 
    175175     
Note: See TracChangeset for help on using the changeset viewer.