source: nappy/trunk/nappy/nc_interface/na_content_collector.py @ 3470

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/nc_interface/na_content_collector.py@3470
Revision 3470, 26.4 KB checked in by astephen, 12 years ago (diff)

Got 1020 written from NetCDF.

Line 
1#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6cdms_to_na.py
7=============
8
9Holds the class CDMSToNA that converts a set of CDMS variables and global attributes.
10
11"""
12
13# Imports from python standard library
14import sys
15import time
16import re
17
18# Import from nappy package
19from nappy.na_error import na_error
20import nappy.utils
21import nappy.cdms_utils.axis_utils
22import nappy.cdms_utils.var_utils
23import nappy.utils.common_utils
24import nappy.na_file.na_core
25
26config_dict = nappy.utils.getConfigDict()
27nc_to_na_map = config_dict["nc_to_na_map"]
28version = nappy.utils.getVersion()
29
30# Import external packages (if available)
31if sys.platform.find("win") > -1:
32    raise na_error.NAPlatformError("Windows does not support CDMS. CDMS is required to convert to CDMS objects and NetCDF.")
33try:
34    import cdms, Numeric
35except:
36    raise Exception("Could not import third-party software. Nappy requires the CDMS and Numeric packages to be installed to convert to CDMS and NetCDF.")
37
38cdms.setAutoBounds("off") 
39
40DEBUG = nappy.utils.getDebug() 
41
42class NAContentCollector(nappy.na_file.na_core.NACore):
43    """
44    Class to build a NASA Ames File object from a set of
45    CDMS variables and global attributes (optional).
46    """
47   
48    def __init__(self, variables, global_attributes={}, requested_ffi=None):
49        """
50        Sets up instance variables and calls appropriate methods to
51        generate sections of NASA Ames file object.
52
53        Input arguments are:
54          * variables - list/tuple of actual CDMS variables
55          * global_attributes - dictionary of user-defined globals to include.
56
57        Typical usage:
58        >>> x = NAContentCollector(["temp", "precip"])
59        >>> x.collectNAContent()
60        >>> if x.found_na == True:
61        ...     print x.na_dict, x.var_ids, x.unused_vars
62        """
63        self.output_message = []
64        self.na_dict = {}
65        self.vars = variables
66
67        # Note that self.var_ids will be a list containing:
68        #    [ordered_vars,  auxiliary_vars,   rank_zero_vars]
69        self.var_ids = None
70        self.globals = global_attributes       
71        self.requested_ffi = requested_ffi
72        self.rank_zero_vars = []
73        self.rank_zero_var_ids = []
74
75        # Create a flag to check if anything found
76        self.found_na = False
77
78
79    def collectNAContent(self):
80        """
81        Collect NASA Ames content. Save the contents to the following instance
82        attributes:
83         * self.na_dict
84         * self.var_ids
85         * self.unused_vars
86        """
87        (self.ordered_vars, aux_vars) = self._analyseVariables()
88     
89        if self.ordered_vars == []:
90            print "WARNING: No NASA Ames content created."
91            self.unused_vars = []
92        else:
93            self.var_ids = [[var.id for var in self.ordered_vars],
94                            [var.id for var in aux_vars], 
95                            self.rank_zero_var_ids]
96            self.na_dict["NLHEAD"] = "-999"
97            self._defineNAVars(self.ordered_vars)
98            self._defineNAaux_vars(aux_vars)
99            self._defineNAGlobals()
100            self._defineNAComments()
101            self._defineGeneralHeader()
102            self.found_na = True
103
104
105    def _analyseVariables(self):
106        """
107        Method to examine the content of CDMS variables to return
108        a tuple of two lists containing variables and auxiliary variables
109        for the NASA Ames file object.
110        Variables not compatible with the first file are put in self.unused_vars
111        """
112        self.unused_vars = []
113        ffis_limited = False
114
115        highest_rank = -1
116        best_var = None
117        count = 0
118
119        # Need to get highest ranked variable (most dimensions) so that we can work out FFI
120        for var in self.vars:
121            msg = "Analysing: %s" % var.id
122            print msg
123            self.output_message.append(msg)
124            count = count + 1
125            # get rank
126            rank = var.rank()
127
128            # Deal with singleton variables
129            if rank == 0: 
130                self.rank_zero_vars.append(var)
131                self.rank_zero_var_ids.append(var.id)
132                continue
133           
134            # Update highest if highest found or if equals highest with bigger size
135            if rank > highest_rank or (rank == highest_rank and var.size() > best_var.size()):
136                highest_rank = rank
137                best_var = var
138                best_var_index = count
139
140        # If all are zero ranked variables or no vars identified/found then we cannot write any to NASA Ames and return ([], [])
141        if len(self.rank_zero_vars) == len(self.vars) or best_var is None: 
142            return ([], [])
143
144        # Now start to sort the variables into main and auxiliary
145        vars_for_na = [best_var]
146        aux_vars_for_na = []
147        shape = best_var.shape
148        number_of_dims = len(shape)
149        self.na_dict["NIV"] = number_of_dims
150
151        # Get the axes for the main variable being used
152        best_var_axes = best_var.getAxisList()
153       
154        # Get other variable info
155        rest_of_the_vars = self.vars[:best_var_index - 1] + self.vars[best_var_index:]
156
157        for var in rest_of_the_vars:
158
159            if var.id in self.rank_zero_var_ids: continue
160
161            # What to do with variables that have different number of dimensions or different shape
162            if len(var.shape) != number_of_dims or var.shape != shape: 
163                # Could it be an auxiliary variable?
164                if len(var.shape) != 1: 
165                    self.unused_vars.append(var)
166                    continue
167
168                first_axis = var.getAxis(0)
169                # Check if axis is identical to first axis of main best variable, if so, can be auxiliary var
170                if nappy.cdms_utils.axis_utils.areAxesIdentical(best_var_axes[0], first_axis) == False: 
171
172                    # If not identical, then it might still qualify as an auxiliary every n time points - valid for 1020
173                    if len(var.shape) == 1:
174                        nvpm = nappy.cdms_utils.axis_utils.isAxisRegularlySpacedSubsetOf(first_axis, best_var_axes[0])
175                        # NVPM is the number of implied values which is equal to (len(ax2)/len(ax1))
176                        if nvpm:
177                            ffis_limited = [1020]
178                            self.na_dict["NVPM"] = nvpm
179                        else: # if returned False, i.e. not regular subset axis
180                            self.unused_vars.append(var)
181                    else:
182                        self.unused_vars.append(var)
183                        continue
184
185                else:
186                    # This could be used as a standard auxiliary variable
187                    if ffis_limited in ([1020],):
188                        # Already fixed on 1020 and cannot collect incompatible FFI vars so do not use
189                        self.unused_vars.append(var)
190                    else:
191                        aux_vars_for_na.append(var) 
192
193            else:
194                this_var_axes = var.getAxisList()
195
196                # Loop through dimensions
197                for i in range(number_of_dims):           
198                    if nappy.cdms_utils.axis_utils.areAxesIdentical(best_var_axes[i], this_var_axes[i]) == False:
199                        self.unused_vars.append(var)
200                        continue
201
202                # OK, I think the current variable is compatible to write with the best variable along with a NASA Ames file
203                vars_for_na.append(var)
204               
205        # Send vars_for_na AND aux_vars_for_na to a method to check if they have previously been mapped
206        # from NASA Ames. In which case we'll write them back in the order they were initially read from the input file.
207        (vars_for_na, aux_vars_for_na) = self._reorderVarsIfPreviouslyNA(vars_for_na, aux_vars_for_na)
208
209        # Get the FFI
210        self.na_dict["FFI"] = self._decideFileFormatIndex(number_of_dims, aux_vars_for_na, ffis_limited)
211        return (vars_for_na, aux_vars_for_na)
212
213
214    def _reorderVarsIfPreviouslyNA(self, vars_for_na, aux_vars_for_na):
215        """
216        Re-order if they previously came from NASA Ames files (i.e. including the
217        attribute 'nasa_ames_var_number'). Return re-ordered or unchanged pair of
218        (vars_for_na, aux_vars_for_na).
219        """
220        # THIS SHOULD REALLY BE DONE IN A LOOP
221        # First do the main variables
222        ordered_vars = [None] * 1000 # Make a long list to put vars in
223        # Create a list of other variables to collect up any that are not labelled as nasa ames variables
224        other_vars = []
225        for var in vars_for_na:
226            if hasattr(var, "nasa_ames_var_number"):
227                ordered_vars[var.nasa_ames_var_number[0]] = var
228            else:
229                other_vars.append(var)
230
231        # Remake vars_for_na now in new order and clean out any that are "None"
232        vars_for_na = []
233        for var in ordered_vars:
234            if var != None: 
235                vars_for_na.append(var)
236
237        vars_for_na = vars_for_na + other_vars
238
239        # Now re-order the Auxiliary variables if they previously came from NASA
240        ordered_aux_vars = [None] * 1000
241        other_aux_vars = []
242
243        for var in aux_vars_for_na:
244            if hasattr(var, "nasa_ames_aux_var_number"):
245                ordered_aux_vars[var.nasa_ames_aux_var_number[0]] = var
246            else:
247                other_aux_vars.append(var)
248
249        # Remake aux_vars_for_na now in order
250        aux_vars_for_na = []
251        for var in ordered_aux_vars:
252            if var != None: 
253                aux_vars_for_na.append(var)
254
255        aux_vars_for_na = aux_vars_for_na + other_aux_vars     
256        return (vars_for_na, aux_vars_for_na)
257
258
259    def _decideFileFormatIndex(self, number_of_dims, aux_vars_for_na, ffis_limited=False):
260        """
261        Based on the number of dimensions and the NASA Ames dictionary return
262        the File Format Index.
263        If there is a choice then make the most sensible selection.
264        If the user has specified a 'requested_ffi' then try and deliver
265        that. Raise an error if not possible.
266        """
267        # If ffis_limited is set then must use one of those
268        if self.requested_ffi and ffis_limited:
269            if self.requested_ffi not in ffis_limited:
270                raise Exception("Cannot write this data to FFI '" + str(self.requested_ffi) + "', can only write to: " + str(ffis_limited) + ".")
271            else:
272                return self.requested_ffi
273
274        # Base the sub-selection on number of dimensions
275        if number_of_dims > 1:
276            ffi = 10 + (number_of_dims * 1000)
277        elif number_of_dims > 4:
278            raise Exception("Cannot write variables defined against greater than 4 axes in NASA Ames format.")
279        else:
280            if len(aux_vars_for_na) > 0 or (self.na_dict.has_key("NAUXV") and self.na_dict["NAUXV"] > 0):
281                ffi = 1010
282            else:
283                ffi = 1001
284
285        if self.requested_ffi and ffi != self.requested_ffi:
286            raise Exception("Cannot write this data to FFI '" + str(self.requested_ffi) + "', can only write to: " + str(ffi) + ".")
287        return ffi
288
289
290    def _defineNAVars(self, vars):
291        """
292        Method to define NASA Ames file object variables and their
293        associated metadata.
294        """
295        self.na_dict["NV"] = len(vars)
296        self.na_dict["VNAME"] = []
297        self.na_dict["VMISS"] = []
298        self.na_dict["VSCAL"] = []
299        self.na_dict["V"] = []
300
301        for var in vars:
302            name = nappy.cdms_utils.var_utils.getBestName(var)
303            self.na_dict["VNAME"].append(name)
304            miss = nappy.cdms_utils.var_utils.getMissingValue(var)
305            if type(miss) not in (type(1.2), type(1), type(1L)): 
306                miss = miss[0]
307            self.na_dict["VMISS"].append(miss)
308            self.na_dict["VSCAL"].append(1)
309            # Populate the variable list with the array
310            self.na_dict["V"].append(var._data)
311
312            # Create independent variable info
313            if not self.na_dict.has_key("X"):
314                # Set up lists ready to populate with values
315                self.na_dict["NXDEF"] = []
316                self.na_dict["NX"] = []
317
318                self.ax0 = var.getAxis(0)
319
320                self.na_dict["X"] = [self.ax0[:].tolist()]
321                self.na_dict["XNAME"] = [nappy.cdms_utils.var_utils.getBestName(self.ax0)]
322
323                if len(self.ax0) == 1:
324                    self.na_dict["DX"] = [0]
325                else:
326                    incr = self.ax0[1] - self.ax0[0]
327                    # Set default increment as gap between first two
328                    self.na_dict["DX"] = [incr]
329                    # Now overwrite it as zero if non-uniform interval in axis
330                    for i in range(1, len(self.ax0)):
331                        if (self.ax0[i] - self.ax0[i - 1]) != incr:
332                            self.na_dict["DX"] = [0]
333                            break
334
335                # If 1D only then "X" should only be a list and not list of lists
336                if self.na_dict["FFI"] in (1001, 1010, 1020):
337                    self.na_dict["X"] = self.na_dict["X"][0]
338
339                # If FFI is 1020 need to reduce axis down to reduced values as most are implied
340                if self.na_dict["FFI"] == 1020: 
341                    vals = self.na_dict["X"]
342                    self.na_dict["X"] = vals[0:len(vals):self.na_dict["NVPM"]] 
343
344                # Now add the rest of the axes to the self.na_dict objects
345                for axis in var.getAxisList()[1:]:
346                    self._appendAxisDefinition(axis)
347
348
349    def _defineNAaux_vars(self, aux_vars):
350        """
351        Method to define NASA Ames file object auxiliary variables and their
352        associated metadata.
353        """
354        self.na_dict["NAUXV"] = len(aux_vars)
355        self.na_dict["ANAME"] = []
356        self.na_dict["AMISS"] = []
357        self.na_dict["ASCAL"] = []
358        self.na_dict["A"] = []
359
360        for var in aux_vars:
361            name = nappy.cdms_utils.var_utils.getBestName(var)
362            self.na_dict["ANAME"].append(name)
363            miss = nappy.cdms_utils.var_utils.getMissingValue(var)
364            if type(miss) != type(1.1):  miss = miss[0]
365            self.na_dict["AMISS"].append(miss)
366            self.na_dict["ASCAL"].append(1)
367            # Populate the variable list with the array
368            self.na_dict["A"].append(var._data)
369
370    def _appendAxisDefinition(self, axis):
371        """
372        Method to create the appropriate NASA Ames file object
373        items associated with an axis (independent variable in
374        NASA Ames). It appends to the various self.na_dict containers.
375        """
376        length = len(axis)
377
378        self.na_dict["NX"].append(length)
379        self.na_dict["XNAME"].append(nappy.cdms_utils.var_utils.getBestName(axis))
380        # If only one item in axis values
381        if length < 2:
382            self.na_dict["DX"].append(0)
383            self.na_dict["NXDEF"].append(length)
384            self.na_dict["X"].append(axis[:].tolist())       
385            return
386   
387        incr = axis[1] - axis[0]
388        for i in range(1, length):
389            if (axis[i] - axis[i - 1]) != incr:
390                self.na_dict["DX"].append(0)
391                self.na_dict["NXDEF"].append(length)
392                self.na_dict["X"].append(axis.tolist())
393                break
394        else: # If did not break out of the loop
395            max_length = length
396            if length > 3: 
397                max_length = 3
398            self.na_dict["DX"].append(incr)
399            self.na_dict["NXDEF"].append(max_length)
400            self.na_dict["X"].append(axis[:max_length])
401
402    def _defineNAGlobals(self):
403        """
404        Maps CDMS (NetCDF) global attributes into NASA Ames Header fields.
405        """
406        # Check if we should add to it with locally set rules
407        local_attributes = nappy.utils.getConfigDict()["local_attributes"]
408        for att, value in local_attributes.items():
409            if not nc_to_na_map.has_key(att):
410                nc_to_na_map[key] = value
411
412        self.extra_comments = [[],[],[]]  # Normal comments, special comments, other comments
413        convention_or_reference_comments = []
414
415        for key in self.globals.keys():
416            if key != "first_valid_date_of_data" and type(self.globals[key]) \
417                                       not in (type("s"), type(1.1), type(1)):
418                continue
419
420            # Loop through keys of header/comment items to map
421            if key in nc_to_na_map.keys():
422                if key == "history":
423                    time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
424                    history = "History:\t%s - Converted to NASA Ames format using nappy-%s.\n\t%s" % \
425                                                 (time_string, version, self.globals[key])
426                    history = history.split("\n") 
427                    self.history = []
428                    for h in history:
429                        if h[:8] != "History:" and h[:1] != "\t": 
430                            h = "\t" + h
431                        self.history.append(h) 
432                   
433                elif key == "institution":
434                    # If fields came from NA then extract appropriate fields.
435                    match = re.match(r"(.*)\s+\(ONAME from NASA Ames file\);\s+(.*)\s+\(ORG from NASA Ames file\)\.", 
436                             self.globals[key])
437                    if match:
438                        self.na_dict["ONAME"] = match.groups()[0]
439                        self.na_dict["ORG"] = match.groups()[1]
440                    else:
441                        self.na_dict["ONAME"] = self.globals[key]
442                        self.na_dict["ORG"] = self.globals[key]           
443                    # NOTE: should probably do the following search and replace on all string lines
444                    self.na_dict["ONAME"] = self.na_dict["ONAME"].replace("\n", "  ")
445                    self.na_dict["ORG"] = self.na_dict["ORG"].replace("\n", "  ")
446                                   
447                elif key == "comment":
448                    # Need to work out if they are actually comments from NASA Ames in the first place
449                    comment_lines = self.globals[key].split("\n")
450                    normal_comments = []
451                    normal_comm_flag = None
452                    special_comments = []
453                    special_comm_flag = None
454
455                    for line in comment_lines:
456                        if line.find("###NASA Ames Special Comments follow###") > -1:
457                            special_comm_flag = 1
458                        elif line.find("###NASA Ames Special Comments end###") > -1:
459                            special_comm_flag = None
460                        elif line.find("###NASA Ames Normal Comments follow###") > -1:
461                            normal_comm_flag = 1
462                        elif line.find("###NASA Ames Normal Comments end###") > -1:
463                            normal_comm_flag = None     
464                        elif special_comm_flag == 1:
465                            special_comments.append(line)
466                        elif normal_comm_flag == 1:
467                            normal_comments.append(line)
468                        elif line.find("###Data Section begins on the next line###") > -1:
469                            pass
470                        else:
471                            normal_comments.append(line)           
472                   
473                    self.extra_comments = [special_comments, normal_comments, []]                   
474                                   
475                elif key == "first_valid_date_of_data":
476                    self.na_dict["DATE"] = self.globals[key]
477               
478                elif key in ("Conventions", "references"):
479                    #convention_or_reference_comments.append("%s:   %s" % (key, self.globals[key]))
480                    self.extra_comments[2].append("%s:   %s" % (key, self.globals[key]))
481                else:
482                    self.na_dict[nc_to_na_map[key]] = self.globals[key]
483            else:
484                self.extra_comments[2].append("%s:   %s" % (key, self.globals[key]))
485        return
486
487
488    def _defineNAComments(self, normal_comments=[], special_comments=[]):
489        """
490        Defines the Special and Normal comments sections in the NASA Ames file
491        object - including information gathered from the defineNAGlobals method.
492        """
493       
494        if hasattr(self, "ncom"):  normal_comments = self.ncom + normal_comments
495
496        NCOM = []
497        for ncom in normal_comments:
498            NCOM.append(ncom)
499
500        if len(NCOM) > 0:   NCOM.append("")
501       
502        if len(self.extra_comments[2]) > 0:
503            for excom in self.extra_comments[2]:
504                NCOM.append(excom)
505       
506        if len(self.extra_comments[1]) > 0: 
507            NCOM.append("Additional Global Attributes defined in the source file and not translated elsewhere:")
508            for excom in self.extra_comments[1]:
509                NCOM.append(excom)
510
511        if hasattr(self, "history"):
512            for h in self.history:
513                NCOM.append(h)
514       
515        if len(NCOM) > 0:
516            NCOM.insert(0, "###NASA Ames Normal Comments follow###")
517            NCOM.append("")
518            NCOM.append("###NASA Ames Normal Comments end###")
519            NCOM.append("###Data Section begins on the next line###")
520
521        spec_comm_flag = None
522        SCOM = []
523        special_comments = self.extra_comments[0]
524        if len(special_comments) > 0: 
525            SCOM = ["###NASA Ames Special Comments follow###"]
526
527            spec_comm_flag = 1
528        for scom in special_comments:
529            SCOM.append(scom)
530
531        used_var_atts = ("id",  "missing_value", "fill_value", "units", 
532                   "nasa_ames_var_number", "nasa_ames_aux_var_number")
533        var_comm_flag = None
534
535        # Create a string for the Special comments to hold rank-zero vars
536        rank_zero_vars_string = []
537
538        for var in self.rank_zero_vars:
539            rank_zero_vars_string.append("\tVariable %s: %s" % (var.id, nappy.cdms_utils.var_utils.getBestName(var)))
540
541            for att in var.attributes.keys():
542                value = var.attributes[att]
543
544                if type(value) in (type("s"), type(1.0), type(1)):
545
546                    rank_zero_vars_string.append("\t\t%s = %s" % (att, var.attributes[att]))
547
548        if len(rank_zero_vars_string) > 0:
549            rank_zero_vars_string.insert(0, "###Singleton Variables defined in the source file follow###")
550            rank_zero_vars_string.append("###Singleton Variables defined in the source file end###")
551
552        for var in self.ordered_vars:
553            varflag = "unused"
554            name = nappy.cdms_utils.var_utils.getBestName(var)
555
556            for scom,value in var.attributes.items():
557                if type(value) in (type([]), type(Numeric.array([0]))) and len(value) == 1:
558                    value = value[0]
559
560                if type(value) in (type("s"), type(1.1), type(1)) and scom not in used_var_atts:
561                    if varflag == "unused":
562                        if var_comm_flag == None:
563                            var_comm_flag = 1
564
565                    if spec_comm_flag == None:
566                        SCOM = ["###NASA Ames Special Comments follow###"] + rank_zero_vars_string
567                        SCOM.append("Additional Variable Attributes defined in the source file and not translated elsewhere:")
568                        SCOM.append("###Variable attributes from source (NetCDF) file follow###")
569                        varflag = "using" 
570
571                    SCOM.append("\tVariable %s: %s" % (var.id, name))
572                    SCOM.append("\t\t%s = %s" % (scom, value))
573
574        if var_comm_flag == 1: 
575            SCOM.append("###Variable attributes from source (NetCDF) file end###")
576        if spec_comm_flag == 1:
577            SCOM.append("###NASA Ames Special Comments end###")
578
579        # Strip out empty lines (or returns)
580        NCOM_cleaned = []
581        SCOM_cleaned = []
582
583        for c in NCOM:
584            if c.strip() not in ("", " ", "  "):
585                # Replace new lines within one attribute with a newline and tab so easier to read
586                lines = c.split("\n")
587                for line in lines:
588                    if line != lines[0]: 
589                        line = "\t" + line
590                    NCOM_cleaned.append(line)
591                       
592        for c in SCOM:
593            if c.strip() not in ("", " ", "  "):               
594                        # Replace new lines within one attribute with a newline and tab so easier to read
595                lines = c.split("\n")
596                for line in lines:
597                    if line != lines[0]: 
598                        line = "\t" + line
599                    SCOM_cleaned.append(line)
600                   
601        self.na_dict["NCOM"] = NCOM_cleaned
602        self.na_dict["NNCOML"] = len(self.na_dict["NCOM"])
603        self.na_dict["SCOM"] = SCOM_cleaned
604        self.na_dict["NSCOML"] = len(self.na_dict["SCOM"])
605        return
606
607
608    def _defineGeneralHeader(self, header_items={}):
609        """
610        Defines known header items and overwrites any with header_items
611        key/value pairs.
612        """
613        # Check if DATE field previously known in NASA Ames file
614        time_now = time.strftime("%Y %m %d", time.localtime(time.time())).split()
615        if not self.na_dict.has_key("RDATE"):
616            self.na_dict["RDATE"] = time_now
617       
618        if self.ax0.isTime():
619            # Get first date in list
620            try:
621                (unit, start_date) = re.match("(\w+)\s+?since\s+?(\d+-\d+-\d+)", self.ax0.units).groups()           
622                comptime = cdtime.s2c(start_date)
623                first_day = comptime.add(self.na_dict["X"][0], getattr(cdtime, unit.capitalize()))
624                self.na_dict["DATE"] = str(first_day).split(" ")[0].replace("-", " ").split()
625            except:
626                msg = "Nappy Warning: Could not get the first date in the file. You will need to manually edit the output file."
627                print msg
628                self.output_message.append(msg)
629                self.na_dict["DATE"] = ("DATE", "NOT", "KNOWN")
630        else: 
631            if not self.na_dict.has_key("DATE"):
632                msg = "Nappy Warning: Could not get the first date in the file. You will need to manually edit the output file."
633                print msg
634                self.output_message.append(msg)
635                self.na_dict["DATE"] = ("DATE", "NOT", "KNOWN")
636            else:
637                pass # i.e. use existing DATE
638
639        self.na_dict["IVOL"] = 1
640        self.na_dict["NVOL"] = 1
641        for key in header_items.keys():
642             self.na_dict[key] = header_items[key]
Note: See TracBrowser for help on using the repository browser.