Changeset 379 for trunk/UTIL


Ignore:
Timestamp:
Nov 14, 2011, 12:25:49 PM (13 years ago)
Author:
acolaitis
Message:

Fixed a rare but annoying conflict occuring when calling make_gcm_netcdf with a time dimension which length is equal to longitude/or/latitude/or/altitude

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/make_netcdf.py

    r376 r379  
    5555   
    5656   zdims={}
    57    zdims[nx]='longitude'
    58    zdims[ny]='latitude'
    59    zdims[nz]='altitude'
    60    zdims[nt]='Time'
     57   zdims['longitude']=nx
     58   zdims['latitude']=ny
     59   zdims['altitude']=nz
     60   zdims['Time']=nt
    6161   print zdims
    6262   # Find which variable uses which dimensions
     
    7070       j=0
    7171       for dim in zvardim:
    72            if dim not in zdims.keys():
     72           if dim not in zdims.values():
    7373              print "WARNING -----------------------------"
    7474              print "Dimensions given to subroutine do not match variables dimensions :"
     
    7878              exit()
    7979           else:
    80               zzvardim[j]=zdims[dim]
     80              a=get_key(zdims,dim)
     81              if len(a) is not 1:
     82                 if j is 0:                ##this should solve most conflicts with Time
     83                    zzvardim[j]=a[1]
     84                 else:
     85                    zzvardim[j]=a[0]
     86              else:
     87                 zzvardim[j]=a[0]
    8188              j=j+1
    8289       zvarcarac[zznames[i]]=zzvardim
    8390       i=i+1
    84    
     91   print zvarcarac 
     92 
    8593   #########################
    8694   ## Clean previous file ##
     
    130138   ## close file
    131139   file.close()
     140
     141def find_key(dic, val):
     142    """return the key of dictionary dic given the value"""
     143    return [k for k, v in dic.iteritems() if v == val][0]
     144
     145def get_key(self, value):
     146    """find the key(s) as a list given a value"""   
     147    return [item[0] for item in self.items() if item[1] == value]
Note: See TracChangeset for help on using the changeset viewer.