This is the exception am getting while creating Structure type of variable.
Please help me in this,
NetCDF-4 C library loaded (jna_path='null', libname='netcdf').
Netcdf nc_inq_libvers='4.3.2 of Feb 27 2015 14:08:46 $' isProtected=false
java.io.IOException: -101: NetCDF: HDF error
at ucar.nc2.jni.netcdf.Nc4Iosp.flush(Nc4Iosp.java:3171)
at ucar.nc2.NetcdfFileWriter.flush(NetcdfFileWriter.java:989)
at ucar.nc2.NetcdfFileWriter.close(NetcdfFileWriter.java:999)
at
com.util.general.NetcdfStructureData.<init>(NetcdfStructureData.java:62)
at
com.util.general.NetcdfStructureData.main(NetcdfStructureData.java:225)
One more question , ToolsUI gives gray scale image , is there any
possibility of getting colored image??
Thanking you,
Raghav
package com.util.general;
import java.util.ArrayList;
import java.util.List;
import ucar.ma2.*;
import ucar.nc2.*;
//import ucar.ma2.StructureMembers;
//import ucar.ma2.StructureMembers.Member;
//import ucar.multiarray.IndexIterator;
public class NetcdfStructureData {
String fileName = "StructureDataFile.nc";
NetcdfFileWriter nc = null;
NetcdfFile ncfile = null;
@SuppressWarnings({ "unchecked", "unused" })
public NetcdfStructureData() {
try {
Dimension a = new Dimension("a", 1, true);
Dimension b = new Dimension("b", 1, true);
Dimension c = new Dimension("c", 1, true);
Dimension d = new Dimension("d", 1, true);
Dimension e = new Dimension("e", 1, true);
// Netcdf file created
nc =
NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf4, fileName);
// Group created
Group g = nc.addGroup(null, "");
Group sankya = nc.addGroup(g, "Sankya");
// Dimension added to group
sankya.addDimension(a);
sankya.addDimension(b);
sankya.addDimension(c);
sankya.addDimension(d);
sankya.addDimension(e);
// nc.addDimension(null, "ab", 30);
// Variable added to group
nc.addVariable(sankya, "A", DataType.INT, "a");
nc.addVariable(sankya, "B", DataType.INT, "b");
nc.addVariable(sankya, "C", DataType.INT, "c");
nc.addVariable(sankya, "D", DataType.INT, "d");
List arrList = new ArrayList<>();
arrList.add(a);
arrList.add(b);
Variable sV = nc.addVariable(sankya, "S_Variable",
DataType.STRUCTURE, arrList);
// nc.addStructureMember(sV.getParentStructure(), "xyz",
DataType.INT, "ab");
// nc.addStructure(sankya, null, "sS", arrList);
// Structure ps = sV.getParentStructure();
// System.out.println("Parent Structure is = " + ps);
nc.addVariable(sankya, null, "Variable_P",
DataType.STRUCTURE, arrList);
nc.create();
if (nc != null) {
nc.close();
}
// ncfile = nc.getNetcdfFile();
// nc = NetcdfFileWriter.openExisting(fileName);
// Structure sd = new Structure(ncfile, sankya, null,
"MyStructure");
// sd.addMemberVariable(null);
// nc.addStructure(sankya, sd, null, null);
// nc.create();
// StructureMembers.Member
// StructureMembers structMemObj = new
StructureMembers("MyStruct");
//
// Index idx = new Index(new int[0], new int[1]);
// structMemObj.addMember("A", "Month End Balance","Rs",
DataType.INT, new int[0]);
//
// StructureData structDataObj = new
StructureData(structMemObj) {
//
// @Override
// public StructureData getScalarStructure(Member
m) {
// return null;
// }
//
// @Override
// public String getScalarString(Member m) {
// return null;
// }
//
// @Override
// public short getScalarShort(Member m) {
// return 0;
// }
//
// @Override
// public long getScalarLong(Member m) {
// return 0;
// }
//
// @Override
// public int getScalarInt(Member m) {
// return 0;
// }
//
// @Override
// public float getScalarFloat(Member m) {
// return 0;
// }
//
// @Override
// public double getScalarDouble(Member m) {
// return 0;
// }
//
// @Override
// public char getScalarChar(Member m) {
// return 0;
// }
//
// @Override
// public byte getScalarByte(Member m) {
// return 0;
// }
//
// @Override
// public String[] getJavaArrayString(Member m) {
// return null;
// }
//
// @Override
// public short[] getJavaArrayShort(Member m) {
// return null;
// }
//
// @Override
// public long[] getJavaArrayLong(Member m) {
// return null;
// }
//
// @Override
// public int[] getJavaArrayInt(Member m) {
// return null;
// }
//
// @Override
// public float[] getJavaArrayFloat(Member m) {
// return null;
// }
//
// @Override
// public double[] getJavaArrayDouble(Member m) {
// return null;
// }
//
// @Override
// public char[] getJavaArrayChar(Member m) {
// return null;
// }
//
// @Override
// public byte[] getJavaArrayByte(Member m) {
// return null;
// }
//
// @Override
// public ArrayStructure getArrayStructure(Member
m) {
// return null;
// }
//
// @Override
// public ArraySequence getArraySequence(Member m)
{
// return null;
// }
//
// @Override
// public Array getArray(Member m) {
// return null;
// }
//
// @Override
// public long convertScalarLong(Member m) {
// return 0;
// }
//
// @Override
// public int convertScalarInt(Member m) {
// return 0;
// }
//
// @Override
// public float convertScalarFloat(Member m) {
// return 0;
// }
//
// @Override
// public double convertScalarDouble(Member m) {
// return 0;
// }
// };
//
// ArrayStructure arrStructObj = new
ArrayStructure(structMemObj, idx ) {
//
// @Override
// protected StructureData
makeStructureData(ArrayStructure as, int recno) {
// return null;
// }
// };
// nc.addStructure(sankya, arg1, arg2, arg3)
// nc.create();
// nc.write
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
new NetcdfStructureData();
System.out.println("End of Main");
}
}