nappy/contrib/aircraft/old_na_to_nc_with_aircraft.py
def defineNAComments(self, normal_comments=[], special_comments=[]):
        """
	Defines the Special and Normal comments sections in the NASA Ames file 
	object - including information gathered from the defineNAGlobals method.
	"""
	
        if hasattr(self, "ncom"):  normal_comments=self.ncom+normal_comments
	NCOM=[]
        for ncom in normal_comments:
            NCOM.append(ncom)
        if len(NCOM)>0:   NCOM.append("")
	
	if len(self.extra_comments[2])>0:
	    for excom in self.extra_comments[2]:
	        NCOM.append(excom)
	
        if len(self.extra_comments[1])>0:  
	    NCOM.append("Additional Global Attributes defined in the source file and not translated elsewhere:")
            for excom in self.extra_comments[1]:
                NCOM.append(excom)

        if hasattr(self, "history"):
            for h in self.history:
                NCOM.append(h)
        
	if len(NCOM)>0:
	    NCOM.insert(0, "###NASA Ames Normal Comments follow###")
	    NCOM.append("")
	    NCOM.append("###NASA Ames Normal Comments end###")
        NCOM.append("###Data Section begins on the next line###")

        specCommentsFlag=None
	SCOM=[]
	special_comments=self.extra_comments[0]
	if len(special_comments)>0: 
	    SCOM=["###NASA Ames Special Comments follow###"]
	    specCommentsFlag=1
        for scom in special_comments:
            SCOM.append(scom)


        #used_var_atts=("name", "long_name", "standard_name", "id", 
	    #    "missing_value", "fill_value", "units", 
		#"nasa_ames_var_number", "nasa_ames_aux_var_number")
        used_var_atts=("id",  "missing_value", "fill_value", "units", 
                   "nasa_ames_var_number", "nasa_ames_aux_var_number")
        varCommentsFlag=None

        # Create a string for the Special comments to hold rank-zero vars
	rankZeroVarsString=[]
	for var in self.rankZeroVars:
	    rankZeroVarsString.append("\tVariable %s: %s" % (var.id, getBestName(var)))
	    for att in var.attributes.keys():
	        value=var.attributes[att]
		if type(value) in (str, float, int):
		    rankZeroVarsString.append("\t\t%s = %s" % (att, var.attributes[att]))
	    #print "VALUES", dir(var), var._data ; rankZeroVarsString.append("\t\tvalue = %s" % var._data)
	
	if len(rankZeroVarsString)>0:
	    rankZeroVarsString.insert(0, "###Singleton Variables defined in the source file follow###")
	    rankZeroVarsString.append("###Singleton Variables defined in the source file end###")

        for var in self.orderedVars:
            varflag="unused"
            name=getBestName(var)
            for scom,value in var.attributes.items():
                if type(value) in (type([]), type(Numeric.array([0]))) and len(value)==1:
                    value=value[0]
                if type(value) in (str, float, int) and scom not in used_var_atts:
                    if varflag=="unused":
                        if varCommentsFlag==None:
                            varCommentsFlag=1
			    if specCommentsFlag==None:
			        SCOM=["###NASA Ames Special Comments follow###"]+rankZeroVarsString
                            SCOM.append("Additional Variable Attributes defined in the source file and not translated elsewhere:")
                            SCOM.append("###Variable attributes from source (NetCDF) file follow###")
                        varflag="using" 
                        SCOM.append("\tVariable %s: %s" % (var.id, name))
                    SCOM.append("\t\t%s = %s" % (scom, value))

        if varCommentsFlag==1:  SCOM.append("###Variable attributes from source (NetCDF) file end###")
        if specCommentsFlag==1:
	    SCOM.append("###NASA Ames Special Comments end###")

        """used_var_atts=("name", "long_name", "standard_name", "id", "missing_value", "fill_value", "units")
        for var in self.vars:
            for scom,value in var.attributes.items():
                name=getBestName(var)
                if type(value) in (str, float, int) and scom not in used_var_atts:
                    SCOM.append("\t%s: %s - %s" % (name, scom, value))"""

        # Strip out empty lines (or returns)
	NCOM_cleaned=[]
	SCOM_cleaned=[]
	#hiddenNewLineCount1=0
	for c in NCOM:
	    if c.strip() not in ("", " ", "  "):
	        #hiddenNewLineCount1=hiddenNewLineCount1+c.count("\n")
		# Replace new lines within one attribute with a newline and tab so easier to read
		lines=c.split("\n")
		for line in lines:
		    if line!=lines[0]: line="\t"+line
		    NCOM_cleaned.append(line)
		
	#hiddenNewLineCount2=0	
	for c in SCOM:
	    if c.strip() not in ("", " ", "  "): 	        
	        #hiddenNewLineCount2=hiddenNewLineCount2+c.count("\n")
		# Replace new lines within one attribute with a newline and tab so easier to read
	        #c=c.replace("\n", "\n\t")
		#SCOM_cleaned.append(c)
		lines=c.split("\n")
		for line in lines:
		    if line!=lines[0]: line="\t"+line
		    SCOM_cleaned.append(line)
		    
        self.na_dict["NCOM"]=NCOM_cleaned
        self.na_dict["NNCOML"]=len(self.na_dict["NCOM"])#+hiddenNewLineCount1
        self.na_dict["SCOM"]=SCOM_cleaned
        self.na_dict["NSCOML"]=len(self.na_dict["SCOM"])#+hiddenNewLineCount2
        return

	Defines the Special and Normal comments sections in the NASA Ames file 
	object - including information gathered from the defineNAGlobals method.
	
Defines the Special and Normal comments sections in the NASA Ames file
object - including information gathered from the defineNAGlobals method.
Defines the Special and Normal comments sections in the NASA Ames file object - including information gathered from the defineNAGlobals method .
def defineNAComments(self, normal_comments=[], special_comments=[]):
        if hasattr(self, "ncom"):  normal_comments=self.ncom+normal_comments
	NCOM=[]
        for ncom in normal_comments:
            NCOM.append(ncom)
        if len(NCOM)>0:   NCOM.append("")
	if len(self.extra_comments[2])>0:
	    for excom in self.extra_comments[2]:
	        NCOM.append(excom)
        if len(self.extra_comments[1])>0:  
	    NCOM.append("Additional Global Attributes defined in the source file and not translated elsewhere:")
            for excom in self.extra_comments[1]:
                NCOM.append(excom)
        if hasattr(self, "history"):
            for h in self.history:
                NCOM.append(h)
	if len(NCOM)>0:
	    NCOM.insert(0, "###NASA Ames Normal Comments follow###")
	    NCOM.append("")
	    NCOM.append("###NASA Ames Normal Comments end###")
        NCOM.append("###Data Section begins on the next line###")
        specCommentsFlag=None
	SCOM=[]
	special_comments=self.extra_comments[0]
	if len(special_comments)>0: 
	    SCOM=["###NASA Ames Special Comments follow###"]
	    specCommentsFlag=1
        for scom in special_comments:
            SCOM.append(scom)
        used_var_atts=("id",  "missing_value", "fill_value", "units", 
                   "nasa_ames_var_number", "nasa_ames_aux_var_number")
        varCommentsFlag=None
	rankZeroVarsString=[]
	for var in self.rankZeroVars:
	    rankZeroVarsString.append("\tVariable %s: %s" % (var.id, getBestName(var)))
	    for att in var.attributes.keys():
	        value=var.attributes[att]
		if type(value) in (str, float, int):
		    rankZeroVarsString.append("\t\t%s = %s" % (att, var.attributes[att]))
	if len(rankZeroVarsString)>0:
	    rankZeroVarsString.insert(0, "###Singleton Variables defined in the source file follow###")
	    rankZeroVarsString.append("###Singleton Variables defined in the source file end###")
        for var in self.orderedVars:
            varflag="unused"
            name=getBestName(var)
            for scom,value in var.attributes.items():
                if type(value) in (type([]), type(Numeric.array([0]))) and len(value)==1:
                    value=value[0]
                if type(value) in (str, float, int) and scom not in used_var_atts:
                    if varflag=="unused":
                        if varCommentsFlag==None:
                            varCommentsFlag=1
			    if specCommentsFlag==None:
			        SCOM=["###NASA Ames Special Comments follow###"]+rankZeroVarsString
                            SCOM.append("Additional Variable Attributes defined in the source file and not translated elsewhere:")
                            SCOM.append("###Variable attributes from source (NetCDF) file follow###")
                        varflag="using" 
                        SCOM.append("\tVariable %s: %s" % (var.id, name))
                    SCOM.append("\t\t%s = %s" % (scom, value))
        if varCommentsFlag==1:  SCOM.append("###Variable attributes from source (NetCDF) file end###")
        if specCommentsFlag==1:
	    SCOM.append("###NASA Ames Special Comments end###")
	NCOM_cleaned=[]
	SCOM_cleaned=[]
	for c in NCOM:
	    if c.strip() not in ("", " ", "  "):
		lines=c.split("\n")
		for line in lines:
		    if line!=lines[0]: line="\t"+line
		    NCOM_cleaned.append(line)
	for c in SCOM:
	    if c.strip() not in ("", " ", "  "): 	        
		lines=c.split("\n")
		for line in lines:
		    if line!=lines[0]: line="\t"+line
		    SCOM_cleaned.append(line)
        self.na_dict["NCOM"]=NCOM_cleaned
        self.na_dict["NNCOML"]=len(self.na_dict["NCOM"])
        self.na_dict["SCOM"]=SCOM_cleaned
        self.na_dict["NSCOML"]=len(self.na_dict["SCOM"])
        return
def defineNAComments ( self , normal_comments = [ ] , special_comments = [ ] ) : if hasattr ( self , "ncom" ) : normal_comments = self . ncom + normal_comments NCOM = [ ] for ncom in normal_comments : NCOM . append ( ncom ) if len ( NCOM ) > 0 : NCOM . append ( "" ) if len ( self . extra_comments [ 2 ] ) > 0 : for excom in self . extra_comments [ 2 ] : NCOM . append ( excom ) if len ( self . extra_comments [ 1 ] ) > 0 : NCOM . append ( "Additional Global Attributes defined in the source file and not translated elsewhere:" ) for excom in self . extra_comments [ 1 ] : NCOM . append ( excom ) if hasattr ( self , "history" ) : for h in self . history : NCOM . append ( h ) if len ( NCOM ) > 0 : NCOM . insert ( 0 , "###NASA Ames Normal Comments follow###" ) NCOM . append ( "" ) NCOM . append ( "###NASA Ames Normal Comments end###" ) NCOM . append ( "###Data Section begins on the next line###" ) specCommentsFlag = None SCOM = [ ] special_comments = self . extra_comments [ 0 ] if len ( special_comments ) > 0 : SCOM = [ "###NASA Ames Special Comments follow###" ] specCommentsFlag = 1 for scom in special_comments : SCOM . append ( scom ) used_var_atts = ( "id" , "missing_value" , "fill_value" , "units" , "nasa_ames_var_number" , "nasa_ames_aux_var_number" ) varCommentsFlag = None rankZeroVarsString = [ ] for var in self . rankZeroVars : rankZeroVarsString . append ( "\tVariable %s: %s" % ( var . id , getBestName ( var ) ) ) for att in var . attributes . keys ( ) : value = var . attributes [ att ] if type ( value ) in ( str , float , int ) : rankZeroVarsString . append ( "\t\t%s = %s" % ( att , var . attributes [ att ] ) ) if len ( rankZeroVarsString ) > 0 : rankZeroVarsString . insert ( 0 , "###Singleton Variables defined in the source file follow###" ) rankZeroVarsString . append ( "###Singleton Variables defined in the source file end###" ) for var in self . orderedVars : varflag = "unused" name = getBestName ( var ) for scom , value in var . attributes . items ( ) : if type ( value ) in ( type ( [ ] ) , type ( Numeric . array ( [ 0 ] ) ) ) and len ( value ) == 1 : value = value [ 0 ] if type ( value ) in ( str , float , int ) and scom not in used_var_atts : if varflag == "unused" : if varCommentsFlag == None : varCommentsFlag = 1 if specCommentsFlag == None : SCOM = [ "###NASA Ames Special Comments follow###" ] + rankZeroVarsString SCOM . append ( "Additional Variable Attributes defined in the source file and not translated elsewhere:" ) SCOM . append ( "###Variable attributes from source (NetCDF) file follow###" ) varflag = "using" SCOM . append ( "\tVariable %s: %s" % ( var . id , name ) ) SCOM . append ( "\t\t%s = %s" % ( scom , value ) ) if varCommentsFlag == 1 : SCOM . append ( "###Variable attributes from source (NetCDF) file end###" ) if specCommentsFlag == 1 : SCOM . append ( "###NASA Ames Special Comments end###" ) """used_var_atts=("name", "long_name", "standard_name", "id", "missing_value", "fill_value", "units")
        for var in self.vars:
            for scom,value in var.attributes.items():
                name=getBestName(var)
                if type(value) in (str, float, int) and scom not in used_var_atts:
                    SCOM.append("\t%s: %s - %s" % (name, scom, value))""" NCOM_cleaned = [ ] SCOM_cleaned = [ ] for c in NCOM : if c . strip ( ) not in ( "" , " " , "  " ) : lines = c . split ( "\n" ) for line in lines : if line != lines [ 0 ] : line = "\t" + line NCOM_cleaned . append ( line ) for c in SCOM : if c . strip ( ) not in ( "" , " " , "  " ) : lines = c . split ( "\n" ) for line in lines : if line != lines [ 0 ] : line = "\t" + line SCOM_cleaned . append ( line ) self . na_dict [ "NCOM" ] = NCOM_cleaned self . na_dict [ "NNCOML" ] = len ( self . na_dict [ "NCOM" ] ) self . na_dict [ "SCOM" ] = SCOM_cleaned self . na_dict [ "NSCOML" ] = len ( self . na_dict [ "SCOM" ] ) return
Defines the Special and Normal comments sections in the NASA Ames file
object - including information gathered from the defineNAGlobals method.
Defines the Special and Normal comments sections in the NASA Ames file object - including information gathered from the defineNAGlobals method .
"""
	Defines the Special and Normal comments sections in the NASA Ames file 
	object - including information gathered from the defineNAGlobals method.
	""" #used_var_atts=("name", "long_name", "standard_name", "id", 
 #    "missing_value", "fill_value", "units", 
 #"nasa_ames_var_number", "nasa_ames_aux_var_number")
 # Create a string for the Special comments to hold rank-zero vars
 #print "VALUES", dir(var), var._data ; rankZeroVarsString.append("\t\tvalue = %s" % var._data)
 """used_var_atts=("name", "long_name", "standard_name", "id", "missing_value", "fill_value", "units")
        for var in self.vars:
            for scom,value in var.attributes.items():
                name=getBestName(var)
                if type(value) in (str, float, int) and scom not in used_var_atts:
                    SCOM.append("\t%s: %s - %s" % (name, scom, value))""" # Strip out empty lines (or returns)
 #hiddenNewLineCount1=0
 #hiddenNewLineCount1=hiddenNewLineCount1+c.count("\n")
 # Replace new lines within one attribute with a newline and tab so easier to read
 #hiddenNewLineCount2=0	
 #hiddenNewLineCount2=hiddenNewLineCount2+c.count("\n")
 # Replace new lines within one attribute with a newline and tab so easier to read
 #c=c.replace("\n", "\n\t")
 #SCOM_cleaned.append(c)
 #+hiddenNewLineCount1
 #+hiddenNewLineCount2

self
normal_comments
special_comments