- Timestamp:
- Jan 18, 2016, 5:03:06 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r674 r675 1993 1993 def fvaradd(values, ncfile): 1994 1994 """ Adding variable (and all its attributes and dimensions) from a reference file to a file 1995 values = [netCDFref] :[varnref]1995 values = [netCDFref],[varnref] 1996 1996 netCDFref = netCDF file name as reference for the variable to add 1997 1997 varnref = name of the variable from [netCDFref] to be added … … 2006 2006 quit() 2007 2007 2008 refnc = values.split(' :')[0]2009 refvar = values.split(' :')[1]2008 refnc = values.split(',')[0] 2009 refvar = values.split(',')[1] 2010 2010 2011 2011 if not os.path.isfile(ncfile): 2012 2012 print errormsg 2013 print ' fvaradd: File "' + ncfile + '" does not exist !!'2013 print ' ' + fname + ': File "' + ncfile + '" does not exist !!' 2014 2014 print errormsg 2015 2015 quit(-1) … … 2017 2017 if not os.path.isfile(refnc): 2018 2018 print errormsg 2019 print ' fvaradd: Reference file "' + refnc + '" does not exist !!'2019 print ' ' + fname + ': Reference file "' + refnc + '" does not exist !!' 2020 2020 print errormsg 2021 2021 quit(-1) … … 2029 2029 else: 2030 2030 print errormsg 2031 print ' fvaradd: File "' + refnc + '" does not have variable: ' + refvar2031 print ' ' + fname + ': File "' + refnc + '" does not have variable: ' + refvar 2032 2032 ncf.close() 2033 2033 ncref.close() … … 2043 2043 for rdim in vardims: 2044 2044 if not searchInlist(newdims, rdim): 2045 print ' fvaradd: Adding dimension ' + rdim2045 print ' ' + fname + ': Adding dimension ' + rdim 2046 2046 ncf.close() 2047 2047 ncref.close() … … 2057 2057 varfil = False 2058 2058 2059 print ' fvaradd: Adding refvar:', refvar, 'shape: ', refvarv.shape2059 print ' ' + fname + ': Adding refvar:', refvar, 'shape: ', refvarv.shape 2060 2060 var = ncf.createVariable(refvar, vartype, vardims, fill_value=varfil) 2061 2061 … … 2078 2078 else: 2079 2079 print errormsg 2080 print ' fvaradd: variable size ',Nvars,' is not ready!!!!'2080 print ' ' + ': variable size ',Nvars,' is not ready!!!!' 2081 2081 2082 2082 # Allocating all the necessary memory (just in case) … … 2120 2120 ncref.close() 2121 2121 2122 return 2123 2122 2124 def fdimadd(values, ncfile): 2123 2125 """ Adding dimension from another reference file … … 2300 2302 for varn in ncvars: 2301 2303 if not varn == var: 2302 fvaradd(ncfile + ' :' + varn, 'tmp_py.nc')2304 fvaradd(ncfile + ',' + varn, 'tmp_py.nc') 2303 2305 2304 2306 fgaddattr(ncfile, 'tmp_py.nc') … … 3551 3553 ncfo.close() 3552 3554 fattradd('time', ncfile + ':time', ofile) 3553 fvaradd(ncfile +':lon', ofile)3554 fvaradd(ncfile +':lat', ofile)3555 fvaradd(ncfile , ':lon', ofile) 3556 fvaradd(ncfile , ':lat', ofile) 3555 3557 3556 3558 ncfo = NetCDFFile(ofile,'a') … … 3739 3741 ncfo.close() 3740 3742 fattradd('time', ncfile + ':time', ofile) 3741 fvaradd(ncfile +':lon', ofile)3742 fvaradd(ncfile +':lat', ofile)3743 fvaradd(ncfile , ':lon', ofile) 3744 fvaradd(ncfile , ':lat', ofile) 3743 3745 3744 3746 ncfo = NetCDFFile(ofile,'a') … … 5025 5027 ncfo.close() 5026 5028 fattradd('time', ncfile + ':time', ofile) 5027 fvaradd(ncfile +':lon', ofile)5028 fvaradd(ncfile +':lat', ofile)5029 fvaradd(ncfile , ':lon', ofile) 5030 fvaradd(ncfile , ':lat', ofile) 5029 5031 5030 5032 ncfo = NetCDFFile(ofile,'a') … … 5489 5491 ncfo.close() 5490 5492 5491 fvaradd(ncfile +':lon', ofile)5492 fvaradd(ncfile +':lat', ofile)5493 fvaradd(ncfile , ':lon', ofile) 5494 fvaradd(ncfile , ':lat', ofile) 5493 5495 5494 5496 fgaddattr(ncfile, ofile) … … 6598 6600 for varns in ncf.variables: 6599 6601 if not varns == varn: 6600 fvaradd(filename + ' :' + varns, ofile)6602 fvaradd(filename + ',' + varns, ofile) 6601 6603 6602 6604 ncfnew = NetCDFFile(ofile,'a') … … 8018 8020 for varns in ncf.variables: 8019 8021 if not varns == varn: 8020 fvaradd(filename + ' :' + varns, ofile)8022 fvaradd(filename + ',' + varns, ofile) 8021 8023 elif varns == oldlon: 8022 fvaradd(newprojectionfile + ' :' + newlon, ofile)8024 fvaradd(newprojectionfile + ',' + newlon, ofile) 8023 8025 elif varns == oldlat: 8024 fvaradd(newprojectionfile + ' :' + newlat, ofile)8026 fvaradd(newprojectionfile + ',' + newlat, ofile) 8025 8027 8026 8028 chvarname(oldlon, ofile, newlon) … … 17199 17201 else: 17200 17202 print warnmsg 17201 print ' ' + fname + ": Any 1D variables with dimension '" + dname + "' !!" 17203 print ' ' + fname + ": Any 1D variables with dimension '" + dname + "' !!" 17204 return 17202 17205 17203 17206 # Dpouble precision
Note: See TracChangeset
for help on using the changeset viewer.