nappy/contrib/aircraft/old_na_to_nc_with_aircraft.py
def analyseVariables(self):
        """
	Method to examine the content of CDMS variables to return
	a tuple of two lists containing variables and auxiliary variables
	for the NASA Ames file object.
	Variables not compatible with the first file are binned to be used next.
	"""
	# Need to group the variables together in bins
	self.varBin=[]
	# Get largest ranked variable as the one we use as standard
	highrank=-1
        bestVar=None
	count=0
	for var in self.vars:
	    msg="Analysing: %s" % var.id
	    print msg
	    self.outputMessage.append(msg)
	    count=count+1

	    # get rank
	    rank=var.rank()

            # Deal with specific datasets with special rules
            if self.rule!=None and self.rule[0]=="aircraft":
                var=self._useLocalRule(var, self.rule)
                if type(var)==type(None): 
                    continue 
                rank=1

            # Deal with singleton variables
	    if rank==0: 
	        self.rankZeroVars.append(var)
		self.rankZeroVarIDs.append(var.id)
		continue
	    
	    if rank>highrank:
                highrank=rank
		bestVar=var
		bestVarIndex=count
            elif rank==highrank:
	        if len(var.flat)>len(bestVar.flat):
		    bestVar=var
		    bestVarIndex=count
	
	if len(self.rankZeroVars)==len(self.vars):  return (None, None)
	if not bestVar:  
            print "No variables produced"
            return (None, None)

        vars4NA=[bestVar]
        auxVars4NA=[]
        shape=bestVar.shape
        ndims=len(shape)
        self.na_dict["NIV"]=ndims

        # Work out which File Format Index is appropriate 
        if ndims in (2,3,4):
            self.na_dict["FFI"]=10+(ndims*1000)
        elif ndims>4:
            raise "Cannot write variables defined against greater than 4 axes in NASA Ames format."
        else:
            if len(auxVars4NA)>0 or (self.na_dict.has_key("NAUXV") and self.na_dict["NAUXV"]>0):
                self.na_dict["FFI"]=1010
            else:
                self.na_dict["FFI"]=1001
        #print self.na_dict["FFI"]
        axes=bestVar.getAxisList()
        
        # Get other variable info
	#print [v.id for v in self.vars], bestVarIndex
	#print [v.id for v in self.vars[:bestVarIndex-1]+self.vars[bestVarIndex:]]
        for var in self.vars[:bestVarIndex-1]+self.vars[bestVarIndex:]:
            # Deal with specific datasets with special rules
            if self.rule!=None and self.rule[0]=="aircraft":
                if var.rank()==2:
                    var=self._useLocalRule(var, self.rule)
                    if type(var)==type(None): continue

	    #print self.rankZeroVars
	    #for rzv in self.rankZeroVars:  
	    #    if var.id==rzv.id and var[0]==rzv[0]: continue
	    #print [v.id for v in self.rankZeroVars]
	    if var.id in self.rankZeroVarIDs: continue
	    #print var.id, ndims, shape, len(var.shape), var.shape
            if len(var.shape)!=ndims or var.shape!=shape: 
                # Could it be an auxiliary variable 
                if len(var.shape)!=1: 
		    self.varBin.append(var)
		    continue
                caxis=var.getAxis(0)
                if compareAxes(axes[0], caxis)==0: 
		    self.varBin.append(var)
		    continue
                # I think it is an auxiliary variable
                auxVars4NA.append(var) 
		# Also put it in var bin because auxiliary vars might be useful
		self.varBin.append(var)
            else:
                caxes=var.getAxisList()
		#print var.id, "here"
                for i in range(ndims):            
                    if compareAxes(axes[i], caxes[i])==0:
		        self.varBin.append(var)
                        continue
                # OK, I think they are compatible
                vars4NA.append(var)
		
        # Re-order if they previously came from NASA Ames files (i.e. including 
	# the attribute 'nasa_ames_var_number')
	orderedVars=[None]*1000
	otherVars=[]
	for var in vars4NA:
	    if hasattr(var, "nasa_ames_var_number"):
	        orderedVars[var.nasa_ames_var_number[0]]=var
            else:
	        otherVars.append(var)
	# Remake vars4NA now in order
	vars4NA=[]
	for var in orderedVars:
	    if var!=None: vars4NA.append(var)
        vars4NA=vars4NA+otherVars

        # Now re-order the Auxiliary variables if they previously came from NASA 
	# Ames files (i.e. including the attribute 'nasa_ames_aux_var_number')

	orderedAuxVars=[None]*1000
	otherAuxVars=[]
	for var in auxVars4NA:
	    if hasattr(var, "nasa_ames_aux_var_number"):
	        orderedAuxVars[var.nasa_ames_aux_var_number[0]]=var
            else:
	        otherAuxVars.append(var)
	# Remake auxVars4NA now in order
	auxVars4NA=[]
	for var in orderedAuxVars:
	    if var!=None: auxVars4NA.append(var)
        auxVars4NA=auxVars4NA+otherAuxVars	
        return (vars4NA, auxVars4NA)

	Method to examine the content of CDMS variables to return
	a tuple of two lists containing variables and auxiliary variables
	for the NASA Ames file object.
	Variables not compatible with the first file are binned to be used next.
	
Method to examine the content of CDMS variables to return
a tuple of two lists containing variables and auxiliary variables
for the NASA Ames file object.
Variables not compatible with the first file are binned to be used next.
Method to examine the content of CDMS variables to return a tuple of two lists containing variables and auxiliary variables for the NASA Ames file object . Variables not compatible with the first file are binned to be used next .
def analyseVariables(self):
	self.varBin=[]
	highrank=-1
        bestVar=None
	count=0
	for var in self.vars:
	    msg="Analysing: %s" % var.id
	    print msg
	    self.outputMessage.append(msg)
	    count=count+1
	    rank=var.rank()
            if self.rule!=None and self.rule[0]=="aircraft":
                var=self._useLocalRule(var, self.rule)
                if type(var)==type(None): 
                    continue 
                rank=1
	    if rank==0: 
	        self.rankZeroVars.append(var)
		self.rankZeroVarIDs.append(var.id)
		continue
	    if rank>highrank:
                highrank=rank
		bestVar=var
		bestVarIndex=count
            elif rank==highrank:
	        if len(var.flat)>len(bestVar.flat):
		    bestVar=var
		    bestVarIndex=count
	if len(self.rankZeroVars)==len(self.vars):  return (None, None)
	if not bestVar:  
            print "No variables produced"
            return (None, None)
        vars4NA=[bestVar]
        auxVars4NA=[]
        shape=bestVar.shape
        ndims=len(shape)
        self.na_dict["NIV"]=ndims
        if ndims in (2,3,4):
            self.na_dict["FFI"]=10+(ndims*1000)
        elif ndims>4:
            raise "Cannot write variables defined against greater than 4 axes in NASA Ames format."
        else:
            if len(auxVars4NA)>0 or (self.na_dict.has_key("NAUXV") and self.na_dict["NAUXV"]>0):
                self.na_dict["FFI"]=1010
            else:
                self.na_dict["FFI"]=1001
        axes=bestVar.getAxisList()
        for var in self.vars[:bestVarIndex-1]+self.vars[bestVarIndex:]:
            if self.rule!=None and self.rule[0]=="aircraft":
                if var.rank()==2:
                    var=self._useLocalRule(var, self.rule)
                    if type(var)==type(None): continue
	    if var.id in self.rankZeroVarIDs: continue
            if len(var.shape)!=ndims or var.shape!=shape: 
                if len(var.shape)!=1: 
		    self.varBin.append(var)
		    continue
                caxis=var.getAxis(0)
                if compareAxes(axes[0], caxis)==0: 
		    self.varBin.append(var)
		    continue
                auxVars4NA.append(var) 
		self.varBin.append(var)
            else:
                caxes=var.getAxisList()
                for i in range(ndims):            
                    if compareAxes(axes[i], caxes[i])==0:
		        self.varBin.append(var)
                        continue
                vars4NA.append(var)
	orderedVars=[None]*1000
	otherVars=[]
	for var in vars4NA:
	    if hasattr(var, "nasa_ames_var_number"):
	        orderedVars[var.nasa_ames_var_number[0]]=var
            else:
	        otherVars.append(var)
	vars4NA=[]
	for var in orderedVars:
	    if var!=None: vars4NA.append(var)
        vars4NA=vars4NA+otherVars
	orderedAuxVars=[None]*1000
	otherAuxVars=[]
	for var in auxVars4NA:
	    if hasattr(var, "nasa_ames_aux_var_number"):
	        orderedAuxVars[var.nasa_ames_aux_var_number[0]]=var
            else:
	        otherAuxVars.append(var)
	auxVars4NA=[]
	for var in orderedAuxVars:
	    if var!=None: auxVars4NA.append(var)
        auxVars4NA=auxVars4NA+otherAuxVars	
        return (vars4NA, auxVars4NA)
def analyseVariables ( self ) : self . varBin = [ ] highrank = - 1 bestVar = None count = 0 for var in self . vars : msg = "Analysing: %s" % var . id print msg self . outputMessage . append ( msg ) count = count + 1 rank = var . rank ( ) if self . rule != None and self . rule [ 0 ] == "aircraft" : var = self . _useLocalRule ( var , self . rule ) if type ( var ) == type ( None ) : continue rank = 1 if rank == 0 : self . rankZeroVars . append ( var ) self . rankZeroVarIDs . append ( var . id ) continue if rank > highrank : highrank = rank bestVar = var bestVarIndex = count elif rank == highrank : if len ( var . flat ) > len ( bestVar . flat ) : bestVar = var bestVarIndex = count if len ( self . rankZeroVars ) == len ( self . vars ) : return ( None , None ) if not bestVar : print "No variables produced" return ( None , None ) vars4NA = [ bestVar ] auxVars4NA = [ ] shape = bestVar . shape ndims = len ( shape ) self . na_dict [ "NIV" ] = ndims if ndims in ( 2 , 3 , 4 ) : self . na_dict [ "FFI" ] = 10 + ( ndims * 1000 ) elif ndims > 4 : raise "Cannot write variables defined against greater than 4 axes in NASA Ames format." else : if len ( auxVars4NA ) > 0 or ( self . na_dict . has_key ( "NAUXV" ) and self . na_dict [ "NAUXV" ] > 0 ) : self . na_dict [ "FFI" ] = 1010 else : self . na_dict [ "FFI" ] = 1001 axes = bestVar . getAxisList ( ) for var in self . vars [ : bestVarIndex - 1 ] + self . vars [ bestVarIndex : ] : if self . rule != None and self . rule [ 0 ] == "aircraft" : if var . rank ( ) == 2 : var = self . _useLocalRule ( var , self . rule ) if type ( var ) == type ( None ) : continue if var . id in self . rankZeroVarIDs : continue if len ( var . shape ) != ndims or var . shape != shape : if len ( var . shape ) != 1 : self . varBin . append ( var ) continue caxis = var . getAxis ( 0 ) if compareAxes ( axes [ 0 ] , caxis ) == 0 : self . varBin . append ( var ) continue auxVars4NA . append ( var ) self . varBin . append ( var ) else : caxes = var . getAxisList ( ) for i in range ( ndims ) : if compareAxes ( axes [ i ] , caxes [ i ] ) == 0 : self . varBin . append ( var ) continue vars4NA . append ( var ) orderedVars = [ None ] * 1000 otherVars = [ ] for var in vars4NA : if hasattr ( var , "nasa_ames_var_number" ) : orderedVars [ var . nasa_ames_var_number [ 0 ] ] = var else : otherVars . append ( var ) vars4NA = [ ] for var in orderedVars : if var != None : vars4NA . append ( var ) vars4NA = vars4NA + otherVars orderedAuxVars = [ None ] * 1000 otherAuxVars = [ ] for var in auxVars4NA : if hasattr ( var , "nasa_ames_aux_var_number" ) : orderedAuxVars [ var . nasa_ames_aux_var_number [ 0 ] ] = var else : otherAuxVars . append ( var ) auxVars4NA = [ ] for var in orderedAuxVars : if var != None : auxVars4NA . append ( var ) auxVars4NA = auxVars4NA + otherAuxVars return ( vars4NA , auxVars4NA )
Method to examine the content of CDMS variables to return
a tuple of two lists containing variables and auxiliary variables
for the NASA Ames file object.
Method to examine the content of CDMS variables to return a tuple of two lists containing variables and auxiliary variables for the NASA Ames file object .
"""
	Method to examine the content of CDMS variables to return
	a tuple of two lists containing variables and auxiliary variables
	for the NASA Ames file object.
	Variables not compatible with the first file are binned to be used next.
	""" # Need to group the variables together in bins
 # Get largest ranked variable as the one we use as standard
 # get rank
 # Deal with specific datasets with special rules
 # Deal with singleton variables
 # Work out which File Format Index is appropriate 
 #print self.na_dict["FFI"]
 # Get other variable info
 #print [v.id for v in self.vars], bestVarIndex
 #print [v.id for v in self.vars[:bestVarIndex-1]+self.vars[bestVarIndex:]]
 # Deal with specific datasets with special rules
 #print self.rankZeroVars
 #for rzv in self.rankZeroVars:  
 #    if var.id==rzv.id and var[0]==rzv[0]: continue
 #print [v.id for v in self.rankZeroVars]
 #print var.id, ndims, shape, len(var.shape), var.shape
 # Could it be an auxiliary variable 
 # I think it is an auxiliary variable
 # Also put it in var bin because auxiliary vars might be useful
 #print var.id, "here"
 # OK, I think they are compatible
 # Re-order if they previously came from NASA Ames files (i.e. including 
 # the attribute 'nasa_ames_var_number')
 # Remake vars4NA now in order
 # Now re-order the Auxiliary variables if they previously came from NASA 
 # Ames files (i.e. including the attribute 'nasa_ames_aux_var_number')
 # Remake auxVars4NA now in order

self