Re: a little help with reading binary: coordinates

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Tue, 15 Jul 2008 19:05:15 -0600

Eric,

See documentation for the function fbindirread:

http://www.ncl.ucar.edu/Document/Functions/Built-in/fbindirread.shtml

   "All records in the file must have the same
   dimensions and must be the same type."

In lines 8 through 11, it appears that your program is trying to
read records of several different dimensions and data types from the
same file.

If all of the records are actually the same dimensions and type,
then you need to adjust the third and fourth arguments to all be the
same, namely rec_dims and rec_type.

If you have different size and type records, then you might consider
rewriting your input file for consistent records.

Alternately, you can attempt to read the non-conforming file as
follows. Read the file twice, as long 1-D arrays of type float and
double, and rec_dims = -1. Then compute direct offsets into the
long arrays, and extract your data records of different sizes from
computed offsets within these long arrays.

There is more than one way to do this sort of thing, and it depends
  on the complexity of your file. However, all file hacking of this
type requires an exact understanding of the details of the file format.

Finally, the values 0 ... 0 for lat and lon are clues that you are
somehow reading the coordinates incorrectly. Indeed you should see
the min and max coordinates for each of these.

Take a close look at your input file format before you go any
further. I recommend using the Unix "od" command, or something
similar, for inspecting the first few records in the file. You can
also do the same with NCL with fbindirread and fixed size 1-D arrays.

Dave Allured
CU/CIRES Climate Diagnostics Center (CDC)
http://cires.colorado.edu/science/centers/cdc/
NOAA/ESRL/PSD, Climate Analysis Branch (CAB)
http://www.cdc.noaa.gov/

Erik Noble wrote:
> Hi. I have a flat binary file that contains 16 records of gridded
> precipitation data.
> Today was my first time to use NCL to read a binary file.
>
> Although I was successful at reading the data, I am unsure if I am
> creating the lat and lon coordinates correctly. When I do a
> printVarSummary on both variables in the file, I get:
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
>
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
> Should I be getting lat: [ 0.. 0] and lon: [ 0.. 0]?
>
> -Erik
>
>
> ;************************************************
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> ;************************************************
> begin
> setfileoption ("bin", "ReadByteOrder", "BigEndian")
> do i = 0, 14 ; CMORPH binary file contains 16 records. NCL starts
> at counting at 0
> lat = fbindirread ("./20060901_3hr-025deg_cpc+comb",0, 480, "double")
> lon = fbindirread ("./20060901_3hr-025deg_cpc+comb",1, 1440, "double")
> cpc_combined_MW = fbindirread
> ("./20060901_3hr-025deg_cpc+comb",i,(/480,1440/),"float")
> CMORPH = fbindirread
> ("./20060901_3hr-025deg_cpc+comb",i+1,(/480,1440/),"float")
>
> ;=============================
> ; create lat and long coordinate variables
> ;============================
> lon!0 = "lon"
> lon_at_long_name = "lon"
> lon_at_units = "degrees-east"
> lon&lon = lon
>
> lat!0 = "lat"
> lat_at_long_name = "lat"
> lat_at_units = "degrees_north"
> lat&lat = lat
> ;=============================
> ; name dimensions of variables
> ;============================
> cpc_combined_MW!0 = "lat"
> cpc_combined_MW!1 = "lon"
> cpc_combined_MW&lat = lat
> cpc_combined_MW&lon = lon
> cpc_combined_MW_at_long_name = "merged microwave precipitation"
> cpc_combined_MW_at_units = "mm/hr"
> print(i)
> printVarSummary(cpc_combined_MW)
>
> CMORPH!0 = "lat"
> CMORPH!1 = "lon"
> CMORPH&lat = lat
> CMORPH&lon = lon
> CMORPH_at_long_name = "CMORPH"
> CMORPH_at_units = "mm/hr"
> print(i+1)
> printVarSummary(CMORPH)
>
> end do
> end
>
> ENOBLE_at_ATHENA: /usr/people/enoble> ncl bin3.ncl
> Copyright (C) 1995-2007 - All Rights Reserved
> University Corporation for Atmospheric Research
> NCAR Command Language Version 4.3.1
> The use of this software is governed by a License Agreement.
> See http://www.ncl.ucar.edu/ for more details.
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 0
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 1
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 1
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 2
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 2
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 3
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 3
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 4
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 4
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 5
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 5
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 6
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 6
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 7
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 7
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 8
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 8
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 9
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 9
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 10
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 10
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 11
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 11
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 12
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 12
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 13
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 13
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 14
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
>
>
> Variable: i
> Type: integer
> Total Size: 4 bytes
> 1 values
> Number of Dimensions: 1
> Dimensions and sizes: [1]
> Coordinates:
> (0) 14
>
>
> Variable: cpc_combined_MW
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : merged microwave precipitation
> (0) 15
>
>
> Variable: CMORPH
> Type: float
> Total Size: 2764800 bytes
> 691200 values
> Number of Dimensions: 2
> Dimensions and sizes: [lat | 480] x [lon | 1440]
> Coordinates:
> lat: [ 0.. 0]
> lon: [ 0.. 0]
> Number Of Attributes: 2
> units : mm/hr
> long_name : CMORPH
> ENOBLE_at_ATHENA: /usr/people/enoble>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Jul 15 2008 - 19:05:15 MDT

This archive was generated by hypermail 2.2.0 : Fri Jul 18 2008 - 08:51:52 MDT