Re: [Fwd: multi band tiff from netCDF]

  • To: Norman Barker
  • Subject: Re: [Fwd: multi band tiff from netCDF]
  • From: John Caron [mailto:caron@xxxxxxxxxxxxxxxx]
  • Date: Wed, 20 Apr 2005 18:06:42 +0100
_From owner-netcdf-java@xxxxxxxxxxxxxxxx Wed Apr 20 11:08:50 2005
Received: (from majordo@localhost)
        by unidata.ucar.edu (UCAR/Unidata) id j3KH7Qxx015661
        for netcdf-java-out; Wed, 20 Apr 2005 11:07:26 -0600 (MDT)
Received: from crow.rsinc.com (crow.rsinc.com [192.5.156.11])
        by unidata.ucar.edu (UCAR/Unidata) with ESMTP id j3KH6mv2015629;
        Wed, 20 Apr 2005 11:06:48 -0600 (MDT)
Organization: UCAR/Unidata
Keywords: 200504201706.j3KH6mv2015629
Received: from mack.corp.rsinc.com (nis1.bldr.rsinc.com [10.17.10.11])
        by crow.rsinc.com (8.12.11/8.12.10) with ESMTP id j3KH6lJs007463;
        Wed, 20 Apr 2005 11:06:48 -0600 (MDT)
Received: from apollo.rsinc.com (apollo.rsinc.com [10.17.10.67])
        by mack.corp.rsinc.com (8.12.11/8.12.10) with ESMTP id j3KH6lir028793;
        Wed, 20 Apr 2005 11:06:47 -0600 (MDT)
Received: from bath.uk.rsinc.com ([192.168.202.5]) by apollo.rsinc.com with 
Microsoft SMTPSVC(6.0.3790.211);
         Wed, 20 Apr 2005 11:07:04 -0600
X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: text/plain;
        charset="iso-8859-1"
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
Thread-Topic: [Fwd: multi band tiff from netCDF]
Thread-Index: AcVE6e6gLbhBLk7IRKaLRK6JFsuGkgA4IHuw
Cc: "Yuan Ho" <yuanho@xxxxxxxxxxxxxxxx>, <netcdf-java@xxxxxxxxxxxxxxxx>,
        <support-netcdf-java@xxxxxxxxxxxxxxxx>
X-OriginalArrivalTime: 20 Apr 2005 17:07:04.0890 (UTC) 
FILETIME=[607539A0:01C545CB]
Content-Transfer-Encoding: 8bit
X-MIME-Autoconverted: from quoted-printable to 8bit by unidata.ucar.edu id 
j3KH6nv2015630
Sender: owner-netcdf-java@xxxxxxxxxxxxxxxx
Precedence: bulk

Hi,

I have added geotiff tags, I have hacked this code into a class that you can 
use (it has a main method)
but it isn't particulary nicely written (I have spent two days going through 
the JAI source code to
understand it!!)

I have currently restricted the data to WGS84(LL) and floating point variables, 
but this is a restriction on my code, not the method, so it would be fairly 
easy to extend this.  I have commented
out the section that added the time stamp from the netCDF file since it will 
vary from netCDF to netCDF
but it is there to look at.

class usage is java TestGeotiffWriter netCDFFile varName 
and the result is the netCDFFile name with the extension changed to .tif.


Hope this helps,

Norman Barker

p.s. (apologies top posted again, since not sure whether this newsgroup accepts 
attachments and (long) file below)


import java.awt.image.ColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferFloat;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.List;

import javax.media.jai.JAI;
import javax.media.jai.ParameterBlockJAI;
import javax.media.jai.PlanarImage;
import javax.media.jai.TiledImage;

import ucar.ma2.Array;
import ucar.nc2.DataType;
import ucar.nc2.dataset.CoordinateAxis1D;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.grid.GeoGrid;
import ucar.nc2.dataset.grid.GridCoordSys;
import ucar.nc2.dataset.grid.GridDataset;
import ucar.unidata.geoloc.ProjectionPoint;
import ucar.unidata.geoloc.ProjectionRect;

import com.rsinc.data.IngestFile;
import com.sun.media.imageio.plugins.tiff.BaselineTIFFTagSet;
import com.sun.media.imageio.plugins.tiff.GeoTIFFTagSet;
import com.sun.media.jai.codec.ImageCodec;
import com.sun.media.jai.codec.ImageEncoder;
import com.sun.media.jai.codec.TIFFEncodeParam;
import com.sun.media.jai.codec.TIFFField;
import com.sun.media.jai.codecimpl.util.RasterFactory;

public class TestGeotiffWriter {
        public static String EXTENSION = "tif";

        public void convertToGeotiff(String ncdfFilename, String varName) {

                String outGTif = String.copyValueOf(ncdfFilename.toCharArray(), 
0,
                                ncdfFilename.lastIndexOf('.') + 1);
                outGTif = outGTif.concat(TestGeotiffWriter.EXTENSION);
                System.out.println("converting to " + outGTif);

                try {
                        NetcdfDataset ncDataset = 
NetcdfDataset.openDataset(ncdfFilename);

                        GridDataset gSet = new GridDataset(ncDataset);
                        GeoGrid grid = 
gSet.findGridByName(IngestFile.GRID_NAME);
                        GridCoordSys gcs = grid.getCoordinateSystem();

                        if (!gcs.isLatLon()) {
                                System.out.println("Only converting WGS84 (LL) 
at the mo");
                                return;
                        }

                        ProjectionRect bb = gcs.getBoundingBox();
                        ProjectionPoint minPt = bb.getMinPoint();
                        ProjectionPoint maxPt = bb.getMaxPoint();

                        // find the actual tie points of the data
                        double tlX = minPt.getX();
                        double tlY = maxPt.getY();

                        // lat and lon axes seem to get swapped so try this hack
                        // to find res in x and y
                        CoordinateAxis1D xaxis = (CoordinateAxis1D) 
gcs.getXHorizAxis();
                        CoordinateAxis1D yaxis = (CoordinateAxis1D) 
gcs.getYHorizAxis();
                        double xStart = xaxis.getCoordValue(0);
                        double yStart = yaxis.getCoordValue(0);
                        double xEnd = xaxis
                                        
.getCoordValue(grid.getXDimension().getLength() - 1);
                        double yEnd = yaxis
                                        
.getCoordValue(grid.getYDimension().getLength() - 1);
                        double xScale = (xEnd - xStart) / xaxis.getSize();
                        double yScale = (yEnd - yStart) / yaxis.getSize();

                        List list = ncDataset.getCoordinateAxes();
                        Iterator itr = list.iterator();
            boolean found = false;
                        while (itr.hasNext()) {
                                CoordinateAxis1D dim = (CoordinateAxis1D) 
itr.next();
                                String dimName = dim.getName();

                                if (dimName.equals(varName)) {
                                        found = true;
                                        int nBands = (int) dim.getSize();

                                        // do some checks before progressing
                                        if (dim.isUnlimited()) {
                                                // we can't do anything, log
                                                System.out
                                                                
.println("unlimited dimension can write infinite no of bands.");
                                                return;
                                        }

                                        if (dim.getDataType() != 
DataType.FLOAT) {
                                                System.out
                                                                .println("only 
converting variables of floating point at the moment");
                                                return;
                                        }

                                        int width = 
grid.getXDimension().getLength();
                                        int height = 
grid.getYDimension().getLength();

                                        ParameterBlockJAI pbjai = new 
ParameterBlockJAI("bandmerge");

                                        for (int i = 0; i < nBands; i++) {
                                                Array arr = 
grid.readDataSlice(-1, i, -1, -1);
                                                float[] data = (float[]) 
arr.getStorage();
                                                DataBufferFloat dbuffer = new 
DataBufferFloat(data,
                                                                width * height);

                                                // create a float data sample 
model
                                                SampleModel sampleModel = 
RasterFactory
                                                                
.createBandedSampleModel(DataBuffer.TYPE_FLOAT,
                                                                                
width, height, 1);

                                                // create a compatible colour 
model
                                                ColorModel colorModel = 
PlanarImage
                                                                
.createColorModel(sampleModel);

                                                // create a writable raster
                                                Raster raster = 
RasterFactory.createWritableRaster(
                                                                sampleModel, 
dbuffer, null);

                                                // create a tiled image using 
the float sample model
                                                TiledImage tiledImage = new 
TiledImage(0, 0, width,
                                                                height, 0, 0, 
sampleModel, colorModel);

                                                // set the data of the tiled 
image to be the raster
                                                tiledImage.setData(raster);

                                                pbjai.setSource(tiledImage, i);
                                        }

                                        // write to file
                                        PlanarImage result = 
JAI.create("bandmerge", pbjai, null);

                                        File file = new File(outGTif);
                                        FileOutputStream out = new 
FileOutputStream(file);

                                        //Then we create the image encoder and 
encode the buffered image in TIFF.

                                        // write geotiff information, in our 
case WGS84 (LL)
                                        TIFFEncodeParam params = new 
TIFFEncodeParam();

                                        // only dealing with Lat Lon (WGS84)
                                        if (gcs.isLatLon()) {
                                                String[] desc = { 
IngestFile.DIM_NAME + " Bands" };
                                                TIFFField descField = new 
TIFFField(
                                                                
BaselineTIFFTagSet.TAG_IMAGE_DESCRIPTION,
                                                                
TIFFField.TIFF_ASCII, 1, desc);

                                                double[] tiePts = { 0, 0, 0, 
tlX, tlY, 0 };

                                                TIFFField tiePtField = new 
TIFFField(
                                                                
GeoTIFFTagSet.TAG_MODEL_TIE_POINT,
                                                                
TIFFField.TIFF_DOUBLE, tiePts.length, tiePts);

                                                double[] pixelScales = { 
xScale, yScale, 0 };
                                                TIFFField pixelSclField = new 
TIFFField(
                                                                
GeoTIFFTagSet.TAG_MODEL_PIXEL_SCALE,
                                                                
TIFFField.TIFF_DOUBLE, pixelScales.length,
                                                                pixelScales);

                                                char[] geoKeyArr = { 1, 1, 2, 
3, // version, key major, key minor, no. keys
                                                                1024, 0, 1, 2, 
// GTModelTypeGeoKey 1024
                                                                1025, 0, 1, 1, 
// GTRasterTypeGeoKey 1025
                                                                2048, 0, 1, 
4326 // GeographicTypeGeoKey 2048
                                                };
                                                TIFFField geoKeyDir = new 
TIFFField(
                                                                
GeoTIFFTagSet.TAG_GEO_KEY_DIRECTORY,
                                                                
TIFFField.TIFF_SHORT, geoKeyArr.length,
                                                                (Object) 
geoKeyArr);

                                                TIFFField dateField = null;
                                                // get the first time stamp in 
the file
                                                /*                              
                        if (grid.getTimes() != null)
                                                 {
                                                 NamedObject dateObj = 
(NamedObject)grid.getTimes().get(0);
                                                 String dateStr = 
dateObj.getDescription();
                                                 // dateStr should be formatted 
to 20 chars
                                                 // time format in our netCDF 
files 
                                                 // days_since_20 10101.06
                                                 // format in tiff is 
YYYY:MM:DD HH:MM:SS
                                                 dateStr = dateStr.replace(' ', 
'0');
                                                 DateFormat formatter = new 
SimpleDateFormat("'days_since_'yyyyMMdd'.'HH");
                                                 Date date = 
formatter.parse(dateStr);
                                                 DateFormat tiffFormatter = new 
SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
                                                 // null terminated string
                                                 String[] tiffDateStr = 
{tiffFormatter.format(date)};
                                                 dateField = new 
TIFFField(BaselineTIFFTagSet.TAG_DATE_TIME, TIFFField.TIFF_ASCII, 1, 
tiffDateStr);
                                                 }*/
                                                if (dateField != null) {
                                                        TIFFField[] fields = { 
descField, geoKeyDir,
                                                                        
tiePtField, pixelSclField, dateField };
                                                        
params.setExtraFields(fields);
                                                } else {
                                                        TIFFField[] fields = { 
descField, geoKeyDir,
                                                                        
tiePtField, pixelSclField };
                                                        
params.setExtraFields(fields);
                                                }

                                        }

                                        
params.setCompression(TIFFEncodeParam.COMPRESSION_NONE);
                                        ImageEncoder encoder = 
ImageCodec.createImageEncoder(
                                                        "TIFF", out, params);

                                        if (encoder == null) {
                                                
System.out.println("imageEncoder is null");
                                                System.exit(0);
                                        }
                                        encoder.encode(result);
                                        out.close();
                                }
                        }  // end of while
                        if (!found)
                        {
                                System.out.println("failed to find named 
variable in dataset");
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }

        }
        
        public static void printUsage()
        {
                System.out.println("Usage: java TestGeotiffWriter netCDFFile 
variableName");
        }
        
        public static void main(String[] args)
        {
                if (args.length < 2)
                {
                        TestGeotiffWriter.printUsage();
                }
                else
                {
                        TestGeotiffWriter writer = new TestGeotiffWriter();
                        writer.convertToGeotiff(args[0], args[1]);
                        System.out.println("Finished conversion");
                }
        }

}


-----Original Message-----
Sent: Tuesday, April 19, 2005 3:13 PM
Cc: Yuan Ho; netcdf-java@xxxxxxxxxxxxxxxx;
support-netcdf-java@xxxxxxxxxxxxxxxx


Hi Norman:

Thanks for the code. We looked at using JAI to write TIFF, but failed to 
get it working ("JAI documentation is a bit sparse"). Is the code the 
complete way to do that? Are there any problems with it that you know 
of? It doesnt appear that youve added the geotiff tags, is that correct? 
Any advice you can give us on using or not using JAI?

thanks again!




Norman Barker wrote:

>Thanks for the reply, I will top post (apologies) since the file is long.
>
>I wrote some test code before I integrated into my app, and using netcdf-java 
>and
>JAI the following creates a multiband tif file. (there are some redundant 
>variables in
>there, apologies again).  JAI documentation is a bit sparse, so hope this 
>helps.
>
>Norman
>
>       public static void main(String[] args) {
>               String testNC = "/temp/test.nc";
>               String outGTif = "/temp/out.tif";
>               String gridName = "ta";
>               try {
>                       NetcdfDataset ncDataset = 
> NetcdfDataset.openDataset(testNC);
>                       
>                       GridDataset gSet = new GridDataset(ncDataset);
>                       GeoGrid grid = gSet.findGridByName(gridName);
>            GridCoordSys gcs = grid.getCoordinateSystem();
>                       
>                   //latlon coord does not need to be scaled
>                   double scaler = (gcs.isLatLon()) ? 1.0 : 1000.0;
>
>                   CoordinateAxis1D xaxis = (CoordinateAxis1D) 
> gcs.getXHorizAxis();
>                   CoordinateAxis1D yaxis = (CoordinateAxis1D) 
> gcs.getYHorizAxis();
>                   double xStart = xaxis.getCoordValue(0) * scaler;
>                   double yStart = yaxis.getCoordValue(0) * scaler;
>                       double xEnd = 
> xaxis.getCoordValue(grid.getXDimension().getLength()-1) * scaler;
>                       double yEnd = 
> yaxis.getCoordValue(grid.getYDimension().getLength()-1) * scaler;
>                       double xInc = (xEnd - xStart)/xaxis.getElementSize();
>                       double yInc = (yEnd - yStart)/yaxis.getElementSize();
>                       
>                       
>                       
>                       List list = ncDataset.getCoordinateAxes();
>                       Iterator itr = list.iterator();
>
>                       while (itr.hasNext()) {
>                               CoordinateAxis1D dim = (CoordinateAxis1D) 
> itr.next();
>                               String dimName = dim.getName();
>
>                               if (dimName.equals(IngestFile.DIM_NAME)) {
>                                       int nBands = (int) dim.getSize();
>                                       if (dim.isUnlimited()) {
>                                               // we can't do anything, log
>                                               return;
>                                       }
>                                       
>                                       int width = 
> grid.getXDimension().getLength();
>                                       int height = 
> grid.getYDimension().getLength();
>               
>                                       ParameterBlockJAI pbjai = new 
> ParameterBlockJAI("bandmerge");
>                                       
>                                       for (int i = 0; i < nBands; i++)
>                                       {
>                                               Array arr = 
> grid.readDataSlice(-1, i, -1, -1);
>                                               float[] data = (float[]) 
> arr.getStorage();
>                                               DataBufferFloat dbuffer = new 
> DataBufferFloat(data, width*height);
>                                               
>                                               // create a float data sample 
> model
>                                               SampleModel sampleModel = 
> RasterFactory.createBandedSampleModel(DataBuffer.TYPE_FLOAT, width, height, 
> 1);
>                                               
>                                               // create a compatible colour 
> model
>                                               ColorModel colorModel = 
> PlanarImage.createColorModel(sampleModel);
>                                               
>                                               // create a writable raster
>                                               Raster raster = 
> RasterFactory.createWritableRaster(sampleModel, dbuffer, null);
>                                               
>                                               // create a tiled image using 
> the float sample model
>                                               TiledImage tiledImage = new 
> TiledImage(0, 0, width, height, 0, 0, sampleModel, colorModel);
>                                               
>                                               // set the data of the tiled 
> image to be the raster
>                                               tiledImage.setData(raster);
>                                               
>                                               pbjai.setSource(tiledImage, i);
>                                       }
>                                       // save the image on a file
>                                       PlanarImage result = 
> JAI.create("bandmerge", pbjai, null);
>                                       JAI.create("filestore", result, 
> outGTif, "TIFF");
>                                       break;
>                               }
>                       }
>               } catch (Exception e) {
>                       e.printStackTrace();
>               }
>
>       }
>
>-----Original Message-----
>From: Yuan Ho [mailto:yuanho@xxxxxxxxxxxxxxxx]
>Sent: Monday, April 18, 2005 5:27 PM
>To: Norman Barker
>Cc: netcdf-java@xxxxxxxxxxxxxxxx; support-netcdf-java@xxxxxxxxxxxxxxxx
>Subject: Re: [Fwd: multi band tiff from netCDF]
>
>
>John Caron wrote:
>
>  
>
>>can you answer this?
>>cc to netcdf-java@xxxxxxxxxxxxxxxx and 
>>support-netcdf-java@xxxxxxxxxxxxxxxx
>>
>>-------- Original Message --------
>>Subject:     multi band tiff from netCDF
>>Date:     Mon, 18 Apr 2005 16:01:21 +0100
>>From:     Norman Barker <nbarker@xxxxxxxxx>
>>Organization:     UCAR/Unidata
>>To:     <netcdf-java@xxxxxxxxxxxxxxxx>
>>
>>
>>
>>Hi,
>>
>>I am using the java classes  to convert a netcdf file for one time 
>>instance, with 27 levels in Z (atmospheric pressure levels).
>>
>>I have created a loop with variable i, and attempting to write a band 
>>in the tif file
>>for each iteration. What seems to happen is the first band gets 
>>written ok, but then after that
>>the page number gets messed up?
>>
>>Array data = grid.readDataSlice(0, i, -1, -1);
>>writer.writeGrid(grid, data, false, xStart, yStart, xInc, yInc, i);
>>
>>Has anyone got any pseudo code for writing multiband tif files from 
>>netCDF?
>>
>>Many thanks,
>>
>>Norman Barker
>>    
>>
>
>Norman,
>               The code was not designed for multiband tiff files. We 
>originally believed that multipage was better to store multi variables 
>and/or multi vertical levels.
>We just realized that multiband was probably better embraced because of 
>the existing tiff readers and the concept of tiff community. This will 
>be my next task to change the
>software to use multiband to store tiff files, it will be released 
>sometime in the Summer.
>
>Yuan
>
>  
>


>From owner-netcdf-java@xxxxxxxxxxxxxxxx Thu 5  2005 May 15:35:45
Message-ID: <1115303745.427a2f41a616a@xxxxxxxxxxxxxxxxxxx>
Date: Thu,  5 May 2005 15:35:45 +0100
From: Adityarajsingh Santokhee <ads@xxxxxxxxxxxxxxxxxxxx>
To: netcdf-java@xxxxxxxxxxxxxxxx
Subject: Problem Reading GRIB Data


_From owner-netcdf-java@xxxxxxxxxxxxxxxx Thu May  5 08:37:24 2005
Received: (from majordo@localhost)
        by unidata.ucar.edu (UCAR/Unidata) id j45Ea0Ue001144
        for netcdf-java-out; Thu, 5 May 2005 08:36:00 -0600 (MDT)
Received: from vimg3.rdg.ac.uk (vimg3.rdg.ac.uk [134.225.1.80])
        by unidata.ucar.edu (UCAR/Unidata) with ESMTP id j45EZwP3001131
        for <netcdf-java@xxxxxxxxxxxxxxxx>; Thu, 5 May 2005 08:35:59 -0600 (MDT)
Organization: UCAR/Unidata
Keywords: 200505051435.j45EZwP3001131
Received: from vimp2.rdg.ac.uk ([134.225.16.91])
        by vimg3.rdg.ac.uk (Exim: gateway)
        with esmtp id 1DThSD-0004UM-00
        for netcdf-java@xxxxxxxxxxxxxxxx; Thu, 05 May 2005 15:35:53 +0100
Received: from vimh1.rdg.ac.uk ([134.225.16.83])
        by vimp2.rdg.ac.uk (Exim: virusscanner)
        with esmtp id 1DThS7-0000Eq-00
        for netcdf-java@xxxxxxxxxxxxxxxx; Thu, 05 May 2005 15:35:47 +0100
Received: from mercury.nerc-essc.ac.uk ([192.171.166.1])
        by vimh1.rdg.ac.uk (Exim: host)
        with esmtp id 1DThS7-0002JB-00; Thu, 05 May 2005 15:35:47 +0100
Received: from sweeney.nerc-essc.ac.uk (sweeney.nerc-essc.ac.uk 
[192.171.166.116])
        by mercury.nerc-essc.ac.uk (8.12.10/8.12.10) with ESMTP id 
j45EZkBW016460;
        Thu, 5 May 2005 15:35:46 +0100 (BST)
Received: from localhost.localdomain (sweeney [127.0.0.1])
        by sweeney.nerc-essc.ac.uk (8.12.8/8.12.8) with ESMTP id j45EZjwX000594;
        Thu, 5 May 2005 15:35:45 +0100
Received: (from apache@localhost)
        by localhost.localdomain (8.12.8/8.12.8/Submit) id j45EZjHc000592;
        Thu, 5 May 2005 15:35:45 +0100
Received: from brahman.nerc-essc.ac.uk (brahman.nerc-essc.ac.uk 
[192.171.166.139]) 
        by www.nerc-essc.ac.uk (IMP) with HTTP 
        for <ads@xxxxxxxxxxxxxxxxxxxxxxx>; Thu,  5 May 2005 15:35:45 +0100
Cc: support-netcdf-java@xxxxxxxxxxxxxxxx
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: Internet Messaging Program (IMP) 3.2.2
X-Originating-IP: 192.171.166.139
X-Scanner: exiscan *1DThS7-0000Eq-00*gHzch6aQTI.* (The University of Reading)
Sender: owner-netcdf-java@xxxxxxxxxxxxxxxx
Precedence: bulk


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.

>From owner-netcdf-java@xxxxxxxxxxxxxxxx Fri 6  2005 May 19:12:16
Message-ID: <1115403136.427bb38010be0@xxxxxxxxxxxxxxxxxxx>
Date: Fri,  6 May 2005 19:12:16 +0100
From: Adityarajsingh Santokhee <ads@xxxxxxxxxxxxxxxxxxxx>
In-Reply-To: <1115303745.427a2f41a616a@xxxxxxxxxxxxxxxxxxx>
To: netcdf-java@xxxxxxxxxxxxxxxx, support-netcdf-java@xxxxxxxxxxxxxxxx
Subject: Problem with GRIB files

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

_From owner-netcdf-java@xxxxxxxxxxxxxxxx Fri May  6 12:13:58 2005
Received: (from majordo@localhost)
        by unidata.ucar.edu (UCAR/Unidata) id j46ICZLq007071
        for netcdf-java-out; Fri, 6 May 2005 12:12:35 -0600 (MDT)
Received: from vimg3.rdg.ac.uk (vimg3.rdg.ac.uk [134.225.1.80])
        by unidata.ucar.edu (UCAR/Unidata) with ESMTP id j46ICTP3007055;
        Fri, 6 May 2005 12:12:30 -0600 (MDT)
Organization: UCAR/Unidata
Keywords: 200505061812.j46ICTP3007055
Received: from vimp2.rdg.ac.uk ([134.225.16.91])
        by vimg3.rdg.ac.uk (Exim: gateway)
        with esmtp id 1DU7JH-0007Up-00; Fri, 06 May 2005 19:12:23 +0100
Received: from vimh1.rdg.ac.uk ([134.225.16.83])
        by vimp2.rdg.ac.uk (Exim: virusscanner)
        with esmtp id 1DU7JB-0003k7-00; Fri, 06 May 2005 19:12:17 +0100
Received: from mercury.nerc-essc.ac.uk ([192.171.166.1])
        by vimh1.rdg.ac.uk (Exim: host)
        with esmtp id 1DU7JB-0002D1-00; Fri, 06 May 2005 19:12:17 +0100
Received: from sweeney.nerc-essc.ac.uk (sweeney.nerc-essc.ac.uk 
[192.171.166.116])
        by mercury.nerc-essc.ac.uk (8.12.10/8.12.10) with ESMTP id 
j46ICGBW010088;
        Fri, 6 May 2005 19:12:17 +0100 (BST)
Received: from localhost.localdomain (sweeney [127.0.0.1])
        by sweeney.nerc-essc.ac.uk (8.12.8/8.12.8) with ESMTP id j46ICGwX010635;
        Fri, 6 May 2005 19:12:16 +0100
Received: (from apache@localhost)
        by localhost.localdomain (8.12.8/8.12.8/Submit) id j46ICGuC010628;
        Fri, 6 May 2005 19:12:16 +0100
Received: from brahman.nerc-essc.ac.uk (brahman.nerc-essc.ac.uk 
[192.171.166.139]) 
        by www.nerc-essc.ac.uk (IMP) with HTTP 
        for <ads@xxxxxxxxxxxxxxxxxxxxxxx>; Fri,  6 May 2005 19:12:16 +0100
References: <1115303745.427a2f41a616a@xxxxxxxxxxxxxxxxxxx>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
User-Agent: Internet Messaging Program (IMP) 3.2.2
X-Originating-IP: 192.171.166.139
X-Scanner: exiscan *1DU7JB-0003k7-00*dPyNsTSw0ik* (The University of Reading)
Sender: owner-netcdf-java@xxxxxxxxxxxxxxxx
Precedence: bulk

Hello,

I have a few questions concerning reading GRIB files using the netcdf2.2
library:

1. are there any problems when using the grib.jar library with jakarta tomcat
server ? Netcdf files can be correctly read and data extracted. Grib files can
be opened only but it is failing each time i wish to extract data (all data as
well as section of it).

2. Are there any easier ways to reading data for a particular variable using its
internal name instead of the variable name. Currently, I have to get list of
all variables and then for each variable get its attributes and thereafter
check the attribute name for GRIB_param_number.

e.g:

for (int i=0; i<myVarList.size(); i++)
{
                Variable myVar = (Variable) myVarList.get(i);
                List attList = myVar.getAttributes();
                        
                for (int j=0; j<attList.size(); j++)
                {
                        Attribute att = (Attribute) attList.get(j);
                        if (att.getName().equals("GRIB_param_number")) 
                        {
                                //get the correct variable
                                if (att.getNumericValue().intValue() == var)
                                {
                                 .......
                                }
                        }
                }
}

Thanks in advance,

Adit.

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