Changeset 675 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jan 18, 2016, 5:03:06 PM (9 years ago)
Author:
lfita
Message:

Fixing different sort of errors and updating `fvaradd':

  • Changing ':' to ','
  • Including use of `fname'
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var_tools.py

    r674 r675  
    19931993def fvaradd(values, ncfile):
    19941994  """ Adding variable (and all its attributes and dimensions) from a reference file to a file
    1995   values = [netCDFref]:[varnref]
     1995  values = [netCDFref],[varnref]
    19961996    netCDFref = netCDF file name as reference for the variable to add
    19971997    varnref = name of the variable from [netCDFref] to be added
     
    20062006      quit()
    20072007
    2008   refnc = values.split(':')[0]
    2009   refvar = values.split(':')[1]
     2008  refnc = values.split(',')[0]
     2009  refvar = values.split(',')[1]
    20102010
    20112011  if not os.path.isfile(ncfile):
    20122012    print errormsg
    2013     print '    fvaradd: File "' + ncfile + '" does not exist !!'
     2013    print '  ' + fname + ': File "' + ncfile + '" does not exist !!'
    20142014    print errormsg
    20152015    quit(-1)   
     
    20172017  if not os.path.isfile(refnc):
    20182018    print errormsg
    2019     print '    fvaradd: Reference file "' + refnc + '" does not exist !!'
     2019    print '   ' + fname + ': Reference file "' + refnc + '" does not exist !!'
    20202020    print errormsg
    20212021    quit(-1)   
     
    20292029  else:
    20302030      print errormsg
    2031       print '    fvaradd: File "' + refnc + '" does not have variable: ' + refvar
     2031      print '   ' + fname + ': File "' + refnc + '" does not have variable: ' + refvar
    20322032      ncf.close()
    20332033      ncref.close()
     
    20432043  for rdim in vardims:
    20442044      if not searchInlist(newdims, rdim):
    2045           print '      fvaradd: Adding dimension ' + rdim
     2045          print '    ' + fname + ': Adding dimension ' + rdim
    20462046          ncf.close()
    20472047          ncref.close()
     
    20572057      varfil = False
    20582058
    2059   print '      fvaradd: Adding refvar:', refvar, 'shape: ', refvarv.shape
     2059  print '    ' + fname + ': Adding refvar:', refvar, 'shape: ', refvarv.shape
    20602060  var = ncf.createVariable(refvar, vartype, vardims, fill_value=varfil)
    20612061
     
    20782078      else:
    20792079          print errormsg
    2080           print '  fvaradd: variable size ',Nvars,' is not ready!!!!'
     2080          print '  ' + ': variable size ',Nvars,' is not ready!!!!'
    20812081
    20822082# Allocating all the necessary memory (just in case)
     
    21202120  ncref.close()
    21212121
     2122  return
     2123
    21222124def fdimadd(values, ncfile):
    21232125  """ Adding dimension from another reference file
     
    23002302  for varn in ncvars:
    23012303      if not varn == var:
    2302            fvaradd(ncfile + ':' + varn, 'tmp_py.nc')
     2304           fvaradd(ncfile + ',' + varn, 'tmp_py.nc')
    23032305
    23042306  fgaddattr(ncfile, 'tmp_py.nc')
     
    35513553  ncfo.close()
    35523554  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)
    35553557
    35563558  ncfo = NetCDFFile(ofile,'a')
     
    37393741  ncfo.close()
    37403742  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)
    37433745
    37443746  ncfo = NetCDFFile(ofile,'a')
     
    50255027  ncfo.close()
    50265028  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)
    50295031
    50305032  ncfo = NetCDFFile(ofile,'a')
     
    54895491  ncfo.close()
    54905492
    5491   fvaradd(ncfile + ':lon', ofile)
    5492   fvaradd(ncfile + ':lat', ofile)
     5493  fvaradd(ncfile , ':lon', ofile)
     5494  fvaradd(ncfile , ':lat', ofile)
    54935495
    54945496  fgaddattr(ncfile, ofile)
     
    65986600    for varns in ncf.variables:
    65996601        if not varns == varn:
    6600             fvaradd(filename + ':' + varns, ofile)
     6602            fvaradd(filename + ',' + varns, ofile)
    66016603
    66026604    ncfnew = NetCDFFile(ofile,'a')
     
    80188020    for varns in ncf.variables:
    80198021        if not varns == varn:
    8020             fvaradd(filename + ':' + varns, ofile)
     8022            fvaradd(filename + ',' + varns, ofile)
    80218023        elif varns == oldlon:
    8022             fvaradd(newprojectionfile + ':' + newlon, ofile)
     8024            fvaradd(newprojectionfile + ',' + newlon, ofile)
    80238025        elif varns == oldlat:
    8024             fvaradd(newprojectionfile + ':' + newlat, ofile)
     8026            fvaradd(newprojectionfile + ',' + newlat, ofile)
    80258027
    80268028    chvarname(oldlon, ofile, newlon)
     
    1719917201    else:
    1720017202        print warnmsg
    17201         print '  ' + fname + ": Any  1D variables with dimension '" + dname + "' !!"
     17203        print '  ' + fname + ": Any 1D variables with dimension '" + dname + "' !!"
     17204        return
    1720217205
    1720317206# Dpouble precision
Note: See TracChangeset for help on using the changeset viewer.