Changeset 2101 in lmdz_wrf


Ignore:
Timestamp:
Aug 25, 2018, 10:58:42 PM (6 years ago)
Author:
lfita
Message:

Adding fill_value in `insert_variable'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r2097 r2101  
    1111511115    return
    1111611116
    11117 def insert_variable(onc, varn, varv, vardims, varvdims, onewnc):
     11117def insert_variable(onc, varn, varv, vardims, varvdims, onewnc, fill=None):
    1111811118    """ Function to insert a variable in an existing file
    1111911119    insert_variable(onc, varn, varv, vardims, onewnc)
     
    1112411124      [varvdims]= name of the variables with the values of the dimensions
    1112511125      [onewnc]= object of the new file
     11126      [fill]= fill value (None for no fill_value)
    1112611127    """
    1112711128
     
    1117211173                    else:
    1117311174                        newdim = onewnc.createDimension(dmn,len(onc.dimensions[dmn]))
    11174 
    11175             newvar = onewnc.createVariable(ivdim, refvdimv.dtype,                    \
    11176               (refvdimv.dimensions))
     11175 
     11176            newvar = onewnc.createVariable(ivdim, refvdimv.dtype, (refvdimv.dimensions))
    1117711177            varattrs = refvdimv.ncattrs()
    1117811178            newvar[:] = refvdimvals
     
    1119611196        newvar = onewnc.variables[varvalues[0]]
    1119711197    else:
    11198         newvar = onewnc.createVariable(varvalues[0], 'f4', (vardims))
     11198        if fill is None:
     11199            newvar = onewnc.createVariable(varvalues[0], 'f4', (vardims))
     11200        else:
     11201            newvar = onewnc.createVariable(varvalues[0], 'f4', (vardims),            \
     11202              fill_value=fill)
    1119911203        newattr = basicvardef(newvar, varvalues[1], varvalues[4].replace('|',' '),   \
    1120011204          varvalues[5])
Note: See TracChangeset for help on using the changeset viewer.