Re: Importing GPCP (precip) unformatted binary data

From: Saji Njarackalazhikam Hameed <saji_at_nyahnyahspammersnyahnyah>
Date: Tue, 24 Jul 2007 11:16:45 +0900

Hi Michael,

It just so happened that we recently converted GPCP data to netCDF. You
can find an implementation of Dennis' suggestions in the code provided
below..

hope it helps,

saji

;------------- %< cut from here ----------
; please load all the needed libraries here..
begin

years=ispan(1979,2007,1)
nyrs=dimsizes(years)
yr1=years(0)
yr2=years(nyrs-1)
nmon=12
nlon = 144
nlat = 72
lat=latGlobeFo(nlat,"lat","latitude","degrees_north")
lon=lonGlobeFo(nlon,"lon","longitude","degrees_east")
lat=lat(::-1)
time=new(nmon*nyrs,"double")
make_month_time_in_std_format(time,yr1,yr2,1,12) ; sorry this
; is a user defined procedure just to create time axis.

prec=new( (/nyrs*nmon,nlat,nlon/),"float")
prec@_FillValue=-99999.
prec_at_missing_value=prec@_FillValue
add_attributes(prec,(/"time","lat","lon"/))
prec&lat=lat
prec&lon=lon
prec&time=time
prec_at_long_name="Precipitation"
prec_at_units="mm/day"
prec_at_source="GPCP version 2 combined precipitation"
prec@webpage="http://lwf.ncdc.noaa.gov/oa/wmo/wdcamet-ncdc.html"

setfileoption("bin","ReadByteOrder","BigEndian")

iyrec=0
do iyr = yr1,yr2
  infile="gpcp_v2_psg."+iyr
  irec=1
  do imon=1,nmon
    do j = 1,nlat
      prec(iyrec,j-1,:) = fbindirread(infile, irec, nlon, "float")
      irec=irec+1
    end do
      if all(ismissing(prec(iyrec,:,:)))
       print("All Missing Values during month "+imon)
      break
      end if
    iyrec=iyrec+1
  end do
end do

print(iyrec-1)
print("Last Day of Data "+ut_calendar(time(iyrec-1),-2))

newprec=prec(:iyrec-1,:,:)
fout=addfile("gpcp_prec.nc","c")
fout->prec=newprec

end

;-------------- upto here %< ................

* Dennis Shea <shea_at_ucar.edu> [2007-07-23 15:39:27 -0600]:

> Hello,
>
> Mike's comment about netCDF is true. I would suggest the following URL.
> It is more up-to-date than the URL Mike suggested.
> http://www.cdc.noaa.gov/cdc/data.gpcp.html
>
> To decode the dates:
>
> f = addfile ("precip.mon.mean.nc" , "r")
> time = f->time
> yyyymm = ut_calendar(time, -1)
> print(yyyymm)
>
> ===========================
> To answer your specific question about the binary is more complicated.
>
> [1] There several important pieces of information you did not include:
>
> (a) Is the GPCP binary file "big endian" or "little endian" ?
> (b) What is the endian of your machine
> (c) Was the GPCP binary file written with fortran direct access
> [same a C block IO] or fortran sequential files? fbinread
> indicates
> it is a flat binary file.
>
> [2] If the file was written on a big endian machine and you are reading the
> file on a little endian machine then you should precede
> the reading of the file with:
> *setfileoption*("bin","ReadByteOrder","BigEndian")
>
> If the GPCP binary is little endian and you are reading on a big
> endian
> *setfileoption*("bin","ReadByteOrder","LittleEndian")
>
> [3] I thing you are providing the fbinread function with the wrong order.
> (/144,72,12/) should be (/12,72,144/). The former looks like fortran
> order.
>
> Good Luck
> D
>
> Michael Notaro wrote:
>> Mike,
>>
>> You could try the netcdf version of the dataset. It is easier to work
>> with.
>>
>> http://www.cgd.ucar.edu/cas/catalog/satellite/gpcp/gpcp.html
>> http://www.cdc.noaa.gov/cdc/data.gpcp.html
>> http://www.jisao.washington.edu/data/gpcp/
>>
>> Mike
>>
>> On Jul 23, 2007, at 4:03 PM, Michael Tosca wrote:
>>
>>> I am trying to import GPCP data via my NCL script. Here is the syntax i
>>> am using:
>>>
>>> gpcp=fbinread("/mtosca/el_nino_fire/gpcp_v2_psg.1998",(/144,72,12/),"float")
>>>
>>> it seems to import fine, but gives very strange values, i.e. on the order
>>> of e38, and there are even some NEGATIVE values, which makes no sense to
>>> me. How could precip be negative? I try to assign attributes to the
>>> dimensions using a dataset i created of lat, lon values of 2.5x2.5
>>> resolution. I keep getting 'segmentation fault'. any ideas?
>>>
>>> does anyone have previous use with GPCP data? The readme file indicates
>>> that each file is "12 grids of size 144x72 containing big-endian REAL*4
>>> values."
>>>
>>> Thanks!
>>> -Mike
>>>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
Saji N. Hameed
APEC Climate Center          				+82 51 668 7470
National Pension Corporation Busan Building 12F         
Yeonsan 2-dong, Yeonje-gu, BUSAN 611705			saji_at_apcc21.net
KOREA
_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 23 2007 - 20:16:45 MDT

This archive was generated by hypermail 2.2.0 : Thu Jul 26 2007 - 16:42:26 MDT