Re: Reading netCDF (NUWG) file with Plain object

Ben-

Ben Podoll wrote:
I am accessing netCDF files basically with code below, this works but
doesn't seem efficient. I then set that 2D array (temp_arr) to a
FlatField samples. Is this the best way to read a netCDF file?

int NX = 125;
int NY = 125;
NetcdfFile nc = new NetcdfFile("C:\\grnd.nc", true);
float[][] temp_arr = new float[1][NX*NY];
for (int x=0; x<NX; x++) {
        for (int y=0; y<NY; y++) {
                int index[] = {0,0,y,x};
                temp_arr[0][x*NX + y] = nc.get("rh").getFloat(index);}
        }
}
nc.close();

But I am not sure if that is the most efficient way, I see many examples
of access with objects like the Plain object, but when I use that object
I get errors. Does this mean my netCDF file is not of the right format?

Either way will work, but Plain handles much more of the
variation from file to file (packing, fill values, set missing
values to NaN, etc).

The errors are just warnings that your netCDF file does not adhere
to the udunits standard for units specifications.  Plain will
just assign a null unit to the data since it can't decode it.
I've noted the problems below:

**********************************************************
CODE: **********************************************************

public class VerySimple {
   public static void main(String args[])throws Exception{

    //---create a netCDF reader---//
    Plain myPlain = new Plain();

    //---read an image sequence from a netCDF into a data object---//
    DataImpl myDataImpl = myPlain.open("C:\\grnd.nc");
  }
}

**********************************************************
ERRORS:
**********************************************************

Unknown netCDF conventions attribute (NUWG).  Using default view...

Plain has support for custom views for various conventions.  To date,
the only view that has been implemented is for the CF convention.
This warning just says that it will use the default view and ignore
any NUWG conventions.  Someday, maybe someone will implement a
NUWG view.

Couldn't decode unit attribute (/second) of variable "vor": Encountered
"/" at line 1, column 1.
Was expecting one of:
<EOF> <INTEGER> ...
    <REAL> ...
    <NAME> ...
    "." ...
    "(" ...

the unit specification should be 1/second (or s-1) instead of
/second.

Couldn't decode unit attribute (grams/kikogram) of variable "mr": Unit
not in database

ah, the old "kikogram" unit.  A measure of whale blubber?  This should
have been gram/kilogram.

Couldn't decode unit attribute (/second) of variable "div": Encountered
"/" at line 1, column 1.
Was expecting one of:
<EOF> <INTEGER> ...
    <REAL> ...
    <NAME> ...
    "." ...
    "(" ...

same comment as above.

Couldn't decode unit attribute (none) of variable "fwx": Unit not in
database
Couldn't decode unit attribute (none) of variable "hi": Unit not in
database

instead of having a unit "none" (which really isn't a unit), the
spec should have "", or not have a unit attribute.

The tact I take on unit specifications is what is acceptable in
a scientific journal.

Don
*************************************************************
Don Murray                               UCAR Unidata Program
dmurray@xxxxxxxxxxxxxxxx                        P.O. Box 3000
(303) 497-8628                              Boulder, CO 80307
http://www.unidata.ucar.edu/staff/donm
*************************************************************



  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: