Re: [visad] visad Digest: Error in while using netcdfFile class

Hello,

Here I have tried netcdfFile class to read .h5 file.
But in both the way nullPointerException is coming when I try to read
dataset of my .hs file.

*I have attached a png file, containing screenshot of my file.*

And the coding is,
(1)

package myapp;



import java.io.IOException;

import ucar.ma2.Array;

import ucar.nc2.Dimension;

import ucar.nc2.NetcdfFile;

import ucar.nc2.Variable;



public class Netcdf_readh5

{

    String filePath;

    int scans=0;



    public Netcdf_readh5() throws IOException

    {

         filePath="F:\\Devanshi\\Input\\MT1SAPS_L2A.h5";

                NetcdfFile  ncFile = NetcdfFile.open(filePath);

       // System.out.println(ncFile);

        Variable var1 = ncFile.findVariable("ScienceData"); //the dataset

         Variable var2 = ncFile.findVariable("Latitude");



        Dimension d=var1.getDimension(0);

        System.out.println(d.getFullName());



 // scans = var.getDimension(0).getLength(); //Getting scans

      //  System.out.println("SCANS:  "+scans);

// int pixels = var.getDimension(1).getLength(); //Getting pixels

  //  System.out.println("PIXELS:  "+pixels);

// float samples[] =var.read(double.class); //suppose dataset is float data



//        Array a=var.read();

//       // float f[];

//       // Object i=a.copyTo1DJavaArray();

//        while(a.hasNext())

//        {

//            System.out.println("getIndex"+a.getIndex());

//

//        }

     }

    public static void main(String args[]) throws IOException

    {        new Netcdf_readh5();

    }   }



/*

Exception in thread "main" java.lang.NullPointerException

                at myapp.Netcdf_readh5.<init>(Netcdf_readh5.java:35)

//The Line is:  Dimension d=var1.getDimension(0);

*/
=====================================================
(2)

package myapp;



import java.io.IOException;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

import ucar.ma2.Array;

import ucar.nc2.NetcdfFile;

import ucar.nc2.Variable;

public class netcdf3 {

      String filePath;

     public netcdf3()    {

filePath="F:\\Devanshi\\Input\\MT1SAPS_L2A.h5";

               NetcdfFile ncFile=null;

               try              {

                                 ncFile=NetcdfFile.open(filePath);

              // System.out.println("ncFile"+ncFile);

               List ranges = new ArrayList();

                             ranges=ncFile.getVariables();

                             Iterator i= ranges.iterator();

             while(i.hasNext())             {

                 System.out.println("\n iterator......"+i.next());

             }

                            String str_var_lat = "Latitude";

Variable v = ncFile.findVariable(str_var_lat);

                            System.out.println(str_var_lat+" variable is
"+v);

                                 Array a1=v.read();

              System.out.println("\n\n\n  ARRAY a1 :
.................................................................."+a1);

          }

          catch(IOException ioe)    {

              System.out.println("error");

                 }

    }

      public static void main(String s[])    {

        new netcdf3();

    }    }

/*

Exception in thread "main" java.lang.NullPointerException

                at myapp.netcdf3.<init>(netcdf3.java)  // Array a1=v.read();

*/


-- 
Devanshi U. Prajapati

Attachment: hf.bmp
Description: Windows bitmap

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