[Fwd: Re: Problem Reading GRIB Data] (fwd)


==============================================================================
Robb Kambic                                Unidata Program Center
Software Engineer III                      Univ. Corp for Atmospheric Research
rkambic@xxxxxxxxxxxxxxxx                   WWW: http://www.unidata.ucar.edu/
==============================================================================

---------- Forwarded message ----------
Date: Thu, 05 May 2005 10:51:17 -0700
From: John Caron <caron@xxxxxxxxxxxxxxxx>
To: robb@xxxxxxxxxxxxxxxx
Subject: [Fwd: Re: Problem Reading GRIB Data]

just got this

-------- Original Message --------
Subject:        Re: Problem Reading GRIB Data
Date:   Thu, 5 May 2005 18:13:41 +0100
From:   Adityarajsingh Santokhee <ads@xxxxxxxxxxxxxxxxxxxx>
Organization:   UCAR/Unidata
To:     John Caron <caron@xxxxxxxxxxxxxxxx>
References:     <1115303745.427a2f41a616a@xxxxxxxxxxxxxxxxxxx>
<427A335A.4020608@xxxxxxxxxxxxxxxx>
<1115305637.427a36a5a2f08@xxxxxxxxxxxxxxxxxxx>



Hello again John,

There was a bug in my program.


>                       int[] start  = {0,0,0,0};
>                       int[] stride = {1,1,1,1};
>                       int[] count  = {0,1,2,2}; <--------0 instead of 1
>                       myTest.readData(ds,4,start,stride,count);

The start index in count should have been 0 instead of 1. That was causing the
index out of bounds error.

Sorry for the mistake.

Adit


Quoting Adityarajsingh Santokhee <ads@xxxxxxxxxxxxxxxxxxxx>:

> Hello John,
>
> The GRIB file can be downloaded from:
>
>  http://www.nerc-essc.ac.uk/~ads/FOAM_atl19_anal.130502.scal.grb
>
> Version of jar file: 2.2.08
>
>
> Java Program used:
>
> import ucar.nc2.*;
> import ucar.ma2.*;
> import ucar.nc2.dataset.*;
>
> import java.io.*;
> import java.util.*;
> import java.text.DateFormat;
> import java.text.SimpleDateFormat;
>
>
> public class Test2netcdf
> {
>
>     public void readData(NetcdfDataset ncFile, int numDimensions, int[]
> start,
> int[] stride, int[] count)
>     {
>         try
>         {
>               String variableName = "Salinity";
>               Variable var = ncFile.findVariable(variableName);
>
>               List myList = new ArrayList();
>               for (int i = 0; i < numDimensions; i++)
>               {
>                       int lastElement = start[i] + (count[i] - 1) * stride[i];
>                       myList.add(i, new Range(start[i], lastElement, 
> stride[i]));
>               }
>
>               /*
>               this is the original range definition
>               myList.add(0, new Range(0, 0, 1));
>               myList.add(1, new Range(0, 19, 1));
>               myList.add(2, new Range(0, 629, 1));
>               myList.add(3, new Range(0, 899, 1));
>               */
>
>
>               Calendar calendar = Calendar.getInstance();
>               long start1 = calendar.getTimeInMillis();
>
>               Array arr = var.read(myList);
>               //Array subsetArr = arr.sectionNoReduce(myList);
>
>               Calendar calendar2 = Calendar.getInstance();
>               long end1 = calendar2.getTimeInMillis();
>
>               long timeTaken = end1 - start1;
>               System.out.println("Time Taken (ms) :  " + timeTaken);
>
>               // Get the data as an array of floats
>               //float[] data = (float[])subsetArr.copyTo1DJavaArray();
>               /*
>               int[] myShape = arr.getShape();
>               for (int i=0; i<myShape.length; i++)
>                       System.out.println("Shape :  " + myShape[i]);
>               */
>
>               ncFile.close();
>         }
>         catch(Exception ioe)
>         {
>               ioe.printStackTrace();
>         }
>     }
>
>
>
>
>       public static void main (String[] args)
>       {
>               try
>               {
>                       Test2netcdf myTest = new Test2netcdf();
>
>                       String [] filenames
>                       {
>                               "130502/FOAM_atl19_anal.130502.scal.grb"
>                       };
>
>
>                       for (int i=0; i<filenames.length; i++)
>                       {
>
>                               String path = 
> "/data/cadfael/marine/FOAM/FOAM_9th/" + filenames[i];
>                               NetcdfDataset ds = 
> NetcdfDataset.openDataset(path);
>
>                               int[] start  = {0,0,0,0};
>                               int[] stride = {1,1,1,1};
>                               int[] count  = {1,1,2,2};
>                               myTest.readData(ds,4,start,stride,count);
>                        }
>               }
>               catch (Exception e)
>               {
>                       e.printStackTrace();
>               }
>       }
> }
>
>
>
> Cheers,
>
> Adit
>
>
>
>
>
>
>
>
>
>
> Quoting John Caron <caron@xxxxxxxxxxxxxxxx>:
>
> > Adityarajsingh Santokhee wrote:
> >
> > >Hello,
> > >
> > >I am trying to read a variable's data from a GRIB file. The
> > read(java.util.List
> > >section) function is giving an array out of bounds error message for any
> > >section apart from the whole range. Are there any workarounds to this
> > problem
> > >or should I load whole data for that variable and then do subsetting.
> This
> > >might be a problem if I have to read hundred's of files.
> > >
> > >Error Message:
> > >
> > >java.lang.ArrayIndexOutOfBoundsException: 4
> > >        at ucar.ma2.ArrayFloat.setFloat(ArrayFloat.java:193)
> > >        at ucar.ma2.IteratorFast.setFloatNext(IteratorFast.java:61)
> > >        at
> >
> >ucar.nc2.iosp.grib.GribServiceProvider.readXY(GribServiceProvider.java:177)
> > >        at
> >
>
>ucar.nc2.iosp.grib.GribServiceProvider.readLevel(GribServiceProvider.java:150)
> > >        at
> >
>
>ucar.nc2.iosp.grib.GribServiceProvider.readData(GribServiceProvider.java:134)
> > >        at ucar.nc2.NetcdfFile.readData(NetcdfFile.java:848)
> > >        at ucar.nc2.Variable._read(Variable.java:737)
> > >        at ucar.nc2.Variable.read(Variable.java:451)
> > >        at ucar.nc2.dataset.VariableDS._read(VariableDS.java:206)
> > >        at ucar.nc2.Variable.read(Variable.java:451)
> > >        at ucar.nc2.dataset.VariableDS._read(VariableDS.java:206)
> > >        at ucar.nc2.Variable.read(Variable.java:475)
> > >        at Test2netcdf.readData(Test2netcdf.java:76)
> > >        at Test2netcdf.main(Test2netcdf.java:128)
> > >
> > >
> > >Cheers,
> > >
> > >Adit.
> > >
> > >
> > >----------------------------------------------------------------
> > >This message was sent using IMP, the Internet Messaging Program.
> > >
> > >
> > Hi Adit:
> >
> > send us the file or URL to the file so we can try to reproduce the
> > problem. also, what version of jar file are you using ? (see README
> > inside it)
> >
> >
>
>
> -----------------------------------------------------------------------
>  Adityarajsingh Santokhee         Tel: +44 118 378 5213 (direct line)
>  eScience Data Manager            Tel: +44 118 378 8741 (ESSC)
>  Reading e-Science Centre         Fax: +44 118 378 6413
>  ESSC                             Email: ads@xxxxxxxxxxxxxxxxxxxx
>  University of Reading
>  3 Earley Gate
>  Reading RG6 6AL, UK
>
> -----------------------------------------------------------------------
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>


-----------------------------------------------------------------------
 Adityarajsingh Santokhee         Tel: +44 118 378 5213 (direct line)
 eScience Data Manager            Tel: +44 118 378 8741 (ESSC)
 Reading e-Science Centre         Fax: +44 118 378 6413
 ESSC                             Email: ads@xxxxxxxxxxxxxxxxxxxx
 University of Reading
 3 Earley Gate
 Reading RG6 6AL, UK

-----------------------------------------------------------------------

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


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