warning:A bad value was passed to stringtointeger

From: Kim <r4rid_at_nyahnyahspammersnyahnyah>
Date: Thu Jan 21 2010 - 02:54:46 MST

Dear NCL user,
I got the code from ncl-talk archived for converting the binary files (gpcp daily data) to nc files. When I run the code it indicates some errors given below & code is also attached. Further, I want to make the file like ("GPCP.199610-200908.nc) and with the help of this file I am interested to draw the plot as the figure attached. Kindly, any help in this regarding will be appreciated.
Thanks
Kim
 
warning:A bad value was passed to stringtointeger, input strings must contain numeric digits, replacing with missing value
fatal:Subscript out of range, error in subscript #0
fatal:An error occurred reading c
fatal:Execute: Error occurred at or near line 33 in file gprec.ncl
 
fatal:Execute: Error occurred at or near line 78 in file gprec.ncl
*************************
; Convert binary to netCDF
; -------------------------------------------------------
DIRI = "/home/kim/GPCP1dd/" ; input directory with binary files
DIRO = "/home/kim/" ; output directory with netCDF
PACK = True
if (PACK) then
optPack = True
optPack@min_value = 0.
optPack@max_value = 2009. ; max value thru 2009 = 1975 mm/day :-)
optPack@scale_factor = 0.1
optPack@add_offset = 0.0
else
optPack = False
end if
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
function parse_gpcp_filename( fName:string )
; parse file name: return yyyy, mm
; gpcp_1dd_v1.1_p1d.200908
; 012345678901234567890123
; 1 2
begin
info = new( 2, "integer", "No_FillValue")
c = stringtochar( fName )
info(0) = stringtoint( (/c(18:21)/) ) ; yyyy
info(1) = stringtoint( (/c(22:23)/) ) ; mm
return( info )
end
begin
; -------------------------------------------------------
; define lat/lon grid: GPCP goes from N=>S
; -------------------------------------------------------
nlat = 180
mlon = 360
lon = lonGlobeFo(mlon,"lon","longitude","degrees_east")
lat = latGlobeFo(nlat,"lat","latitude","degrees_north")
lat = lat(::-1) ; make N=>S
printVarSummary(lat)
; -------------------------------------------------------
; Define generic file attributes
; -------------------------------------------------------
nline = inttochar(10) ; new line character
fAtt = 0 ; attributes for netCDF file
fAtt@creation_date = systemfunc("date")
fAtt@Reference = nline + \
"Huffman, G.J., R.F. Adler, M.M. Morrissey, S. Curtis " + nline + \
"R. Joyce, B. McGavock, and J. Susskind, 2001: " + nline + \
"Global precipitation at one-degree daily resolution from multi-satellite observations" + nline +\
"J. Hydrometeor., 2, 36-50" + nline
fAtt_at_Conversion = "NCL: http://www.ncl.ucar.edu/"
fAtt@Convention = "CF-1.0"
fAtt_at_Source = "ftp://rsd.gsfc.nasa.gov/pub/1dd-v1.1/"
fAtt_at_GSFC = "http://precip.gsfc.nasa.gov/"
fAtt@Comment = "netCDF version of original binary file(s)"
fAtt@Title = "GPCP ONE-DEGREE DAILY PRECIPITATION DATA SET"
; -------------------------------------------------------
; names of all 1dd files in the directory "diri"
; -------------------------------------------------------
diri = DIRI
fili = systemfunc("cd "+diri+" ; ls gpcp_1dd_v1.1_p1d*")
nfil = dimsizes( fili )
print(fili)
diro = DIRO
; -------------------------------------------------------
; Loop over all files and create individual netCDF.
; Use "ncrcat" if one file is desired/
; -------------------------------------------------------
setfileoption("bin","ReadByteOrder","BigEndian")
do nf=0,nfil-1
info = parse_gpcp_filename( fili(nf) ) ; yyyy, mm
yyyy = info(0) ; clarity
mm = info(1)
ntim = days_in_month(yyyy, mm )
; read header + all days in the month
dumy = fbindirread(diri+fili(nf),0,360+ntim*360*180,"float")
; create netCDF
prec = onedtond( dumy(360:), (/ntim,nlat,mlon/) ) ; skip header
delete (dumy) ; size may change for next month
; ---------------------------------------------------------
; Construct primary data object
; ---------------------------------------------------------
prec@long_name = "GPCP: daily precipitation"
prec@units = "mm/day"
prec@_FillValue = -99999.
prec@missing_value = prec@_FillValue
prec!0 = "time"
prec!1 = "lat"
prec!2 = "lon"
prec&lat = lat
prec&lon = lon
; ---------------------------------------------------------
; create time variables
; ---------------------------------------------------------
yyyymm = yyyy*100 + mm
days = ispan(1,ntim,1)
hh = 12 ; middle of day (arbitrary)
date = yyyymm*10000 + days*100 + hh
date!0 = "time"
date@long_name = "gregorian date"
date@units = "yyyymmddhh"
YYYY = conform(date, yyyy, -1) ; make scalar a vector to match "days"
MM = conform(date, mm, -1)
HH = conform(date, hh, -1)
ZERO = conform(date, 0, -1)
tunits = "days since 1996-10-01 00:00:00" ; arbitrary
time = ut_inv_calendar(YYYY,MM,days,HH, ZERO , ZERO ,tunits, 0)
time!0 = "time"
time@long_name = "time"
time@units = tunits
; ---------------------------------------------------------
; create netCDF
; ---------------------------------------------------------
yyyy = info(0)
mm = info(1)
yyyymm = yyyy*100 + mm
;ncfile = diro+fili(nf)+".nc"
ncfile = diro+"GPCP.1DD."+yyyymm+".nc"
print (ncfile)
system ("/bin/rm -f " + ncfile) ; remove an pre-file
ncdf = addfile(ncfile,"c") ; "c"reate the netCDF file
fileattdef( ncdf, fAtt )
dimNames = (/ "time", "lon", "lat" /)
dimSizes = (/ -1 , mlon, nlat /)
dimUnlim = (/ True , False, False /)
filedimdef( ncdf, dimNames, dimSizes, dimUnlim )
; Define 1D variables.
filevardef ( ncdf, "time", typeof(time), getvardims(time) )
filevarattdef( ncdf, "time", time )
filevardef ( ncdf, "lat", typeof(lat), getvardims(lat) )
filevarattdef( ncdf, "lat", lat )
filevardef ( ncdf, "lon", typeof(lon), getvardims(lon) )
filevarattdef( ncdf, "lon", lon )
; Define 1D variables.
filevardef ( ncdf, "date", typeof(date), getvardims(date) )
filevarattdef( ncdf, "date", date )
if (PACK) then
filevardef ( ncdf, "PREC", "short", getvardims(prec) )
pShort = pack_values(prec, "short", optPack)
delete(pShort@vMin_original_data) ; extraneous
delete(pShort@vMax_original_data)
filevarattdef( ncdf, "PREC", pShort )
else
filevardef ( ncdf, "PREC", typeof(prec), getvardims(prec) )
filevarattdef( ncdf, "PREC", prec )
end if
; Write variables.
ncdf->time = (/time/)
ncdf->lat = (/lat /)
ncdf->lon = (/lon /)
ncdf->date = (/date/)
if (PACK) then
ncdf->PREC = (/pShort/)
delete(pShort)
else
ncdf->PREC = (/prec/)
end if
delete (prec) ; size may change for next month
delete (time)
delete (date)
delete (days)
delete(YYYY )
delete(MM )
delete(HH )
delete(ZERO )
end do
end

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Thu Jan 21 02:54:53 2010

This archive was generated by hypermail 2.1.8 : Thu Jan 21 2010 - 13:54:45 MST