Changeset 676 in lmdz_wrf


Ignore:
Timestamp:
Jan 18, 2016, 5:35:22 PM (9 years ago)
Author:
lfita
Message:

Fixing existence of variable in the output file in `fvaradd'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r675 r676  
    11721172        else:
    11731173            print errormsg
    1174             print '  fvaradd: variable size ',Nvars,' is not ready!!!!'
     1174            print '  ' + fname + ': variable size ',Nvars,' is not ready!!!!'
    11751175
    11761176# Allocating all the necessary memory (just in case)
     
    20572057      varfil = False
    20582058
    2059   print '    ' + fname + ': Adding refvar:', refvar, 'shape: ', refvarv.shape
    2060   var = ncf.createVariable(refvar, vartype, vardims, fill_value=varfil)
    2061 
    2062   varshape = refvarv.shape
    2063   Nvars = len(varshape)
     2059  if not ncf.variables.has_key(refvar):
     2060      print '    ' + fname + ': Adding refvar:', refvar, 'shape: ', refvarv.shape
     2061      var = ncf.createVariable(refvar, vartype, vardims, fill_value=varfil)
     2062
     2063      varshape = refvarv.shape
     2064      varvals = np.zeros(tuple(varshape), dtype=vartype)     
     2065      Nvars = len(varshape)
    20642066   
    2065   if not Nvars == 0:
    2066       if Nvars == 1:
    2067           varvals = np.zeros(varshape[0], dtype=vartype)
    2068       elif Nvars == 2:
    2069           varvals = np.zeros((varshape[0], varshape[1]), dtype=vartype)
    2070       elif Nvars == 3:
    2071           varvals = np.zeros((varshape[0], varshape[1], varshape[2]), dtype=vartype)
    2072       elif Nvars == 4:
    2073           varvals = np.zeros((varshape[0], varshape[1], varshape[2], varshape[3]), dtype=vartype)
    2074       elif Nvars == 5:
    2075           varvals = np.zeros((varshape[0], varshape[1], varshape[2], varshape[3], varshape[4]), dtype=vartype)
    2076       elif Nvars == 6:
    2077           varvals = np.zeros((varshape[0], varshape[1], varshape[2], varshape[3], varshape[4], varshape[5]), dtype=vartype)
    2078       else:
    2079           print errormsg
    2080           print '  ' + ': variable size ',Nvars,' is not ready!!!!'
    2081 
    20822067# Allocating all the necessary memory (just in case)
    20832068      var[:] = varvals
     
    21092094                          var[i,j,k,l,:,:] = varvals[i,j,k,l,:,:]
    21102095
    2111   newvar = ncf.variables[refvar]
    2112   for attr in varattr:
    2113       newvarattrs = newvar.ncattrs()
    2114       attrv = refvarv.getncattr(attr)
    2115       if not searchInlist(newvarattrs, attr):     
    2116           newvar.setncattr(attr, attrv)
    2117 
    2118   ncf.sync()
     2096      newvar = ncf.variables[refvar]
     2097      for attr in varattr:
     2098          newvarattrs = newvar.ncattrs()
     2099          attrv = refvarv.getncattr(attr)
     2100          if not searchInlist(newvarattrs, attr):     
     2101              newvar.setncattr(attr, attrv)
     2102
     2103      ncf.sync()
    21192104  ncf.close()
    21202105  ncref.close()
     
    35533538  ncfo.close()
    35543539  fattradd('time', ncfile + ':time', ofile)
    3555   fvaradd(ncfile , ':lon', ofile)
    3556   fvaradd(ncfile , ':lat', ofile)
     3540  fvaradd(ncfile + ',lon', ofile)
     3541  fvaradd(ncfile + ',lat', ofile)
    35573542
    35583543  ncfo = NetCDFFile(ofile,'a')
     
    37413726  ncfo.close()
    37423727  fattradd('time', ncfile + ':time', ofile)
    3743   fvaradd(ncfile , ':lon', ofile)
    3744   fvaradd(ncfile , ':lat', ofile)
     3728  fvaradd(ncfile + ',lon', ofile)
     3729  fvaradd(ncfile + ',lat', ofile)
    37453730
    37463731  ncfo = NetCDFFile(ofile,'a')
     
    50275012  ncfo.close()
    50285013  fattradd('time', ncfile + ':time', ofile)
    5029   fvaradd(ncfile , ':lon', ofile)
    5030   fvaradd(ncfile , ':lat', ofile)
     5014  fvaradd(ncfile + ',lon', ofile)
     5015  fvaradd(ncfile + ',lat', ofile)
    50315016
    50325017  ncfo = NetCDFFile(ofile,'a')
     
    54915476  ncfo.close()
    54925477
    5493   fvaradd(ncfile , ':lon', ofile)
    5494   fvaradd(ncfile , ':lat', ofile)
     5478  fvaradd(ncfile + ',lon', ofile)
     5479  fvaradd(ncfile + ',lat', ofile)
    54955480
    54965481  fgaddattr(ncfile, ofile)
Note: See TracChangeset for help on using the changeset viewer.