Changeset 1695 in lmdz_wrf
- Timestamp:
- Dec 7, 2017, 8:35:22 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1677 r1695 968 968 attrvalue = value of the attribute 969 969 """ 970 fname = 'set_attribute' 970 971 971 972 attvar = ncv.ncattrs() … … 4608 4609 addval=values.split(':')[3] 4609 4610 4610 filexist(filename, errormsg, 'add values')4611 gen.filexist(filename, errormsg, 'add values') 4611 4612 ncfa = NetCDFFile(filename,'r') 4612 4613 … … 4644 4645 else: 4645 4646 addvaln = addval 4646 addvalv =typemod(addvaln, str(varinf.dtype))4647 addvalv = gen.typemod(addvaln, str(varinf.dtype)) 4647 4648 4648 4649 newnc = NetCDFFile(newf,'w') … … 4669 4670 4670 4671 varattrs = var.ncattrs() 4671 if searchInlist(varattrs, '_FillValue'):4672 if gen.searchInlist(varattrs, '_FillValue'): 4672 4673 fillval = var.getncattr('_FillValue') 4673 4674 newvarobj = newnc.createVariable(vname, vkind, vdims, fill_value=fillval) … … 4676 4677 else: 4677 4678 newvarobj = newnc.createVariable(vname, vkind, vdims) 4678 4679 4679 4680 varobj=ncfa.variables[vname] 4680 4681 vals = varobj[:] 4681 4682 4682 4683 if vname == varN: 4683 for ival in range(Nvals): 4684 ## print ' ' + fname + ': adding',ival+1,' values' 4685 newvar = np.insert(vals, pos, addvalv, axis=dimension) 4686 vals=newvar.copy() 4687 newvarobj[:] = newvar 4684 for ival in range(Nvals): 4685 newvar = np.insert(vals, pos, addvalv, axis=dimension) 4686 vals=newvar.copy() 4687 newvarobj[:] = newvar 4688 4688 else: 4689 4689 if vname == dmodname: … … 4710 4710 else: 4711 4711 vardims=list(var.dimensions) 4712 if searchInlist(vardims,varinf.dimns[dimension]):4712 if gen.searchInlist(vardims,varinf.dimns[dimension]): 4713 4713 ## print ' ' + fname + ' variable ' + vname + ' has also the increased dimension!' 4714 4714 vardim=vardims.index(varinf.dimns[dimension]) … … 4720 4720 else: 4721 4721 newvarobj[:] = vals 4722 4723 4722 for vattr in varobj.ncattrs(): 4724 4723 if not vattr == '_FillValue': 4725 vattrval = var .getncattr(vattr)4726 new varobj= set_attribute(newvarobj, vattr, vattrval)4724 vattrval = varobj.getncattr(vattr) 4725 newattr = set_attribute(newvarobj, vattr, vattrval) 4727 4726 4728 4727 # Global attributes … … 4730 4729 for gattr in ncfa.ncattrs(): 4731 4730 gattrval = ncfa.getncattr(gattr) 4732 new nc= set_attribute(newnc, gattr, gattrval)4731 newattr = set_attribute(newnc, gattr, gattrval) 4733 4732 4734 4733 newnc.sync()
Note: See TracChangeset
for help on using the changeset viewer.