- Timestamp:
- May 19, 2015, 6:28:34 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r419 r420 14548 14548 14549 14549 for vn in vnames: 14550 print ' ' + fname + ': adding var:',vn,' ...' 14551 14552 varo = oc.variables[vn] 14553 vartype = varo.dtype 14554 vardims = varo.dimensions 14555 varattrs = varo.ncattrs() 14556 14557 for vdn in vardims: 14558 if not searchInlist(nc.dimensions,vdn): 14559 print warnmsg 14560 print ' ' + fname + ": adding dimension '" + vdn + \ 14561 "' from variable '" + vdn + "' which is not in file !!" 14562 add_dims(oc,nc,[vdn]) 14563 14564 if searchInlist(varattrs,'_FillValue'): 14565 newvar = nc.createVariable(vn, vartype, vardims, \ 14566 fill_value=varo.getncattr('_FillValue')) 14567 else: 14568 newvar = nc.createVariable(vn, vartype, vardims) 14569 14570 for attrn in varattrs: 14571 attrv = varo.getncattr(attrn) 14572 newattr = set_attribute(newvar, attrn, attrv) 14573 14574 newvar[:] = varo[:] 14575 14576 nc.sync() 14550 if not searchInlist(nc.variables,vn): 14551 print ' ' + fname + ': adding var:',vn,' ...' 14552 14553 varo = oc.variables[vn] 14554 vartype = varo.dtype 14555 vardims = varo.dimensions 14556 varattrs = varo.ncattrs() 14557 14558 for vdn in vardims: 14559 if not searchInlist(nc.dimensions,vdn): 14560 print warnmsg 14561 print ' ' + fname + ": adding dimension '" + vdn + \ 14562 "' from variable '" + vdn + "' which is not in file !!" 14563 add_dims(oc,nc,[vdn]) 14564 14565 if searchInlist(varattrs,'_FillValue'): 14566 newvar = nc.createVariable(vn, vartype, vardims, \ 14567 fill_value=varo.getncattr('_FillValue')) 14568 else: 14569 newvar = nc.createVariable(vn, vartype, vardims) 14570 14571 for attrn in varattrs: 14572 attrv = varo.getncattr(attrn) 14573 newattr = set_attribute(newvar, attrn, attrv) 14574 14575 newvar[:] = varo[:] 14576 14577 nc.sync() 14577 14578 14578 14579 return
Note: See TracChangeset
for help on using the changeset viewer.