Hi,
I have 3-hourly grib files and want to extract variables from these files.
I use the example efficient GRIB to nc: http://www.ncl.ucar.edu/Applications/gribeff.shtml. But I cannot figure out how to assign time attribute. 'fatal:No valid instance of variable initial_time found in file list'.
Please see my script and data information below. Also can access my some data and script via bluefire: /glade/home/zhangg/gld/nc.ncl GLDAS*.grb. Thanks.
-Guo Zhang
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
;************************************************
undef("rdVar4D")
function rdVar4D (f:file, vName:string, time:integer)
; read GRIB 4D variable and assign new dimension names
begin
var = f->$vName$; read variable
var!0 = "time" ; assign 'conventional' dimension names
var!1 = "lat"
var!2 = "lon"
var&time = time ; assign time coord variable
return(var)
end
begin
;***********************************************
; read in data from GRIB file
;***********************************************
gribfil = systemfunc("ls *.grb")
grib_in = addfiles(gribfil, "r")
; print(grib_in) ; file overview
; print(gribfil(0))
TIME = grib_in[:]->initial_time ; time as "hours since"
lat = grib_in[:]->g0_lat_0 ; latitude
lon = grib_in[:]->g0_lon_1 ; longitude
lat!0 = "lat" ; assign new dimension name
lon!0 = "lon"
TIME!0= "time"
time = cd_calendar(TIME, -3) ; change to date syntax
time!0= "time"
time_at_units = "yyyymmddhh"
snowf = rdVar4D (grib_in, "VAR_131_GDS0_SFC" ,time)
rainf = rdVar4D (grib_in, "VAR_132_GDS0_SFC" ,time)
....
file global attributes:
dimensions:
g0_lat_0 = 600
g0_lon_1 = 1440
lv_DBLY2 = 4
variables:
float PRES_GDS0_SFC ( g0_lat_0, g0_lon_1 )
center : Zagreb
long_name : Pressure
units : Pa
_FillValue : 1e+20
level_indicator : 1
gds_grid_type : 0
parameter_table_version : 1
parameter_number : 1
forecast_time : 0
forecast_time_units : hours
initial_time : 01/01/2008 (00:00)
float TMP_GDS0_SFC ( g0_lat_0, g0_lon_1 )
center : Zagreb
long_name : Temperature
units : K
_FillValue : 1e+20
level_indicator : 1
gds_grid_type : 0
parameter_table_version : 1
parameter_number : 11
forecast_time : 0
forecast_time_units : hours
initial_time : 01/01/2008 (00:00)
float WIND_GDS0_SFC ( g0_lat_0, g0_lon_1 )
center : Zagreb
long_name : Wind speed
units : m/s
_FillValue : 1e+20
level_indicator : 1
gds_grid_type : 0
parameter_table_version : 1
parameter_number : 32
forecast_time : 0
forecast_time_units : hours
initial_time : 01/01/2008 (00:00)
float SPF_H_GDS0_SFC ( g0_lat_0, g0_lon_1 )
center : Zagreb
long_name : Specific humidity
units : kg/kg
_FillValue : 1e+20
level_indicator : 1
gds_grid_type : 0
parameter_table_version : 1
parameter_number : 51
forecast_time : 0
forecast_time_units : hours
initial_time : 01/01/2008 (00:00)
float EVP_GDS0_SFC ( g0_lat_0, g0_lon_1 )
center : Zagreb
long_name : Evaporation
units : kg/m^2
_FillValue : 1e+20
level_indicator : 1
gds_grid_type : 0
parameter_table_version : 1
parameter_number : 57
forecast_time : 0
forecast_time_units : hours
initial_time : 01/01/2008 (00:00)
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Apr 9 12:48:13 2012
This archive was generated by hypermail 2.1.8 : Mon Apr 09 2012 - 13:43:03 MDT