Changeset 2238 in lmdz_wrf


Ignore:
Timestamp:
Nov 17, 2018, 2:56:47 PM (6 years ago)
Author:
lfita
Message:

Working version with arguments of `read_grib.py'

Fixing error message in `datetimeStr_conversion'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/generic_tools.py

    r2234 r2238  
    547547          "[H], [H], ':', [M], [M], ':', [S], [S]"}
    548548
     549    availcftimeu = ['weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds']
     550
    549551    if StringDT[0:1] == 'h':
    550552        print fname + '_____________________________________________________________'
     
    594596        else:
    595597              print errormsg
    596               print '    timeref_datetime: time units "' + tunits + '" not ready!!!!'
     598              print '  ' + fname + ': time units"' + tunits + '" not ready!!!!'
     599              print '    available ones:', availcftimeu
    597600              quit(-1)
    598601
     
    722725        else:
    723726              print errormsg
    724               print '    timeref_datetime: time units "' + tunits + '" not ready!!!!'
     727              print '  ' + fname + ': time units"' + tunits + '" not ready!!!!'
     728              print '    available ones:', availcftimeu
    725729              quit(-1)
    726730        dateYmdHMS = cfdt
  • trunk/tools/read_grib.py

    r2232 r2238  
    11# FROM: https://pypi.org/project/pupygrib/
     2from optparse import OptionParser
    23import numpy as np
    34import pupygrib
     
    89
    910errormsg = 'ERROR -- error -- ERROR -- error'
    10 
    11 ifile = 'ERAI_pl200503_130.grib'
    12 
    13 ofile = 'ERAI_pl_130.nc'
    1411
    1512def grib128_ncname(varid):
     
    5350    return [varn,Lvarn,units,cfvalues[0], cfvalues[1], cfvalues[4].replace('|', ' ')]
    5451
    55 timeu = 'minutes since 1949-12-01 00:00:00'
     52parser = OptionParser()
     53parser.add_option("-g", "--grib_file", dest="gribfile", help="GRIB file to use",
     54  metavar="FILE")
     55parser.add_option("-o", "--output_file", dest="ncfile", help="name of NC file to generate",
     56  metavar="FILE")
     57parser.add_option("-t", "--timeunits", dest="timeunits",
     58  help="CF reference of time values [Tunits] since [DateRef] ('!', for spaces minutes!since!1949-12-01!00:00:00 as default)",
     59  metavar="STRING")
     60
     61(opts, args) = parser.parse_args()
    5662
    5763#######    #######
    5864## MAIN
    5965    #######
     66
     67if opts.gribfile is None:
     68    print errormsg
     69    print "  no grib input file name provided !!"
     70    print "     you should provide one file name as -g [FileName]"
     71    quit(-1)
     72
     73if not os.path.isfile(opts.gribfile):
     74    print errormsg
     75    print "  no grib file '" + opts.gribfile + "' found !!"
     76    quit(-1)
     77else:
     78    ifile = opts.gribfile
     79
     80if opts.ncfile is None:
     81    print errormsg
     82    print "  no netcdf output file name provided !!"
     83    print "     you should provide one file name as -o [FileName]"
     84    quit(-1)
     85else:
     86    ofile = opts.ncfile
     87
     88if opts.timeunits is None:
     89    print errormsg
     90    print "  no time units provided !!"
     91    print "     using the default ones as 'minutes since 1949-12-01 00:00:00'"
     92    quit(-1)
     93else:
     94  timeu = opts.timeunits.replace('!', ' ')
    6095
    6196with open(ifile, 'rb') as stream:
Note: See TracChangeset for help on using the changeset viewer.