}
/////////////////////////////////////////////////////////////////////////////
private void makeVariables(int grpid, Group g) throws IOException {
IntByReference nvarsp = new IntByReference();
int ret = nc4.nc_inq_nvars(grpid, nvarsp);
if (ret != 0) throw new IOException(nc4.nc_strerror(ret));
int nvars = nvarsp.getValue();
if (debug) System.out.printf(" nvars= %d %n", nvars);
int[] varids = new int[nvars];
ret = nc4.nc_inq_varids(grpid, nvarsp, varids);
for (int i = 0; i < varids.length; i++) {
int varno = varids[i];
if (varno != i) System.out.printf("HEY varno=%d i=%d%n", varno, i);
byte[] name = new byte[NCLibrary.NC_MAX_NAME + 1];
IntByReference xtypep = new IntByReference();
IntByReference ndimsp = new IntByReference();
int[] dimids = new int[NCLibrary.NC_MAX_DIMS];
IntByReference nattsp = new IntByReference();
ret = nc4.nc_inq_var(grpid, varno, name, xtypep, ndimsp, dimids, nattsp);
if (ret != 0)
throw new IOException(nc4.nc_strerror(ret));
// figure out the datatype
int typeid = xtypep.getValue();
DataType dtype = convertDataType(typeid);
String vname = makeString(name);
Vinfo vinfo = new Vinfo(grpid, varno, typeid);
// figure out the dimensions
String dimList = makeDimList(grpid, ndimsp.getValue(), dimids);
UserType utype = userTypes.get(typeid);
if (utype != null) {
vinfo.utype = utype;
if (utype.userType == NCLibrary.NC_VLEN)
dimList = dimList +" *";
}
Variable v;
if (dtype != DataType.STRUCTURE) {
v = new Variable(ncfile, g, null, vname, dtype, dimList);
} else {
Structure s = new Structure(ncfile, g, null, vname);
s.setDimensions( dimList);
v = s;
if (utype.flds == null)
utype.readFields();
for (Field f : utype.flds) {
s.addMemberVariable(f.makeMemberVariable(g, s));
}
}
// create the Variable
ncfile.addVariable(g, v);
v.setSPobject(vinfo);
if (dtype.isEnum()) {
EnumTypedef enumTypedef = g.findEnumeration(utype.name);
v.setEnumTypedef(enumTypedef);
}
if (isUnsigned(typeid))
v.addAttribute(new Attribute("_Unsigned","true"));
// read Variable attributes
List<Attribute> atts = makeAttributes(grpid, varno, nattsp.getValue(), v);
for (Attribute att : atts) {
v.addAttribute(att);
//if (debug) System.out.printf(" add Variable Attribute %s %n",att);
}