- Timestamp:
- Oct 15, 2015, 11:02:49 AM (9 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r632 r656 28 28 'fdimadd', 'fgaddattr', 'field_stats', 'file_creation', 'file_oper_alongdims', \ 29 29 'filter_2dim', \ 30 'flipdim', 'fvaradd', 'gaddattrk', 'gaddattr', 'get_namelist_vars', \ 30 'flipdim', 'fvaradd', 'gaddattrk', 'gaddattr', 'get_attribute', \ 31 'get_namelist_vars', \ 31 32 'getvalues_lonlat', 'grattr', \ 32 33 'grmattr', 'igattrs', 'increaseDimvar', 'isgattrs', 'isvattrs', 'ivars', 'ivattrs',\ … … 162 163 elif oper == 'gaddattr': 163 164 ncvar.gaddattr(opts.values, opts.ncfile) 165 elif oper == 'get_attribute': 166 ncvar.get_attribute(opts.values, opts.ncfile, opts.varname) 164 167 elif oper == 'get_namelist_vars': 165 168 ncvar.get_namelist_vars(opts.values, opts.ncfile) -
trunk/tools/nc_var_tools.py
r650 r656 17015 17015 #DataSetSection_multivars('WRFt,20011111060000,20011111180000,-1','/home/lluis/PY/wrfout_d01_2001-11-11_00:00:00','all') 17016 17016 17017 def get_attribute(values, filen, varn): 17018 """ Function to get an attribute from a netCDF file 17019 values= [attrname] 17020 attrname: attribute name 17021 filen= name of the netCDF file 17022 varn= name of the variable ('global' for a global attribute) 17023 """ 17024 fname = 'get_attribute' 17025 attrn = values 17026 17027 if values == 'h': 17028 print fname + '_____________________________________________________________' 17029 print get_attribute.__doc__ 17030 quit() 17031 17032 onc = NetCDFFile(filen, 'r') 17033 17034 if varn == 'global': 17035 if not searchInlist(onc.ncattrs(), attrn): 17036 print errormsg 17037 print ' ' + fname + ": file '" + filen + "' does not have atribute '" + \ 17038 attrn + "' !!" 17039 quit(-1) 17040 else: 17041 attrv = onc.getncattr(attrn) 17042 else: 17043 if not searchInlist(onc.variables, varn): 17044 print errormsg 17045 print ' ' + fname + ": file '" + filen + "' does not have variable '" + \ 17046 varn + "' !!" 17047 quit(-1) 17048 else: 17049 ovar = onc.variables[varn] 17050 if not searchInlist(ovar.ncattrs(), attrn): 17051 print errormsg 17052 print ' ' + fname + ": variable '" + varn + "' does not have " + \ 17053 "atribute '" + attrn + "' !!" 17054 print ' it has:',ovar.ncattrs() 17055 quit(-1) 17056 else: 17057 attrv = ovar.getncattr(attrn) 17058 17059 onc.close() 17060 17061 print attrv 17062 17063 return 17064 17065 17017 17066 #quit() 17018 17067
Note: See TracChangeset
for help on using the changeset viewer.