Array varArray;
// make the variables
// time
Variable timeVar = new Variable(ncfile, null, null, "time");
timeVar.setDataType(DataType.INT);
timeVar.setDimensions("time");
timeVar.addAttribute(new Attribute("units",
"seconds since "
+ df.toDateTimeString(nomTime)));
timeVar.addAttribute(new Attribute("long_name", "time"));
varArray = new ArrayInt.D1(1);
((ArrayInt.D1) varArray).set(0, 0);
timeVar.setCachedData(varArray, false);
ncfile.addVariable(null, timeVar);
// lines and elements
Variable lineVar = new Variable(ncfile, null, null, "lines");
lineVar.setDataType(DataType.INT);
lineVar.setDimensions("lines");
//lineVar.addAttribute(new Attribute("units", "km"));
lineVar.addAttribute(new Attribute("standard_name",
"projection_y_coordinate"));
varArray = new ArrayInt.D1(numLines);
for (int i = 0; i < numLines; i++) {
int pos = nav.isFlippedLineCoordinates()
? i
: numLines - i - 1;
((ArrayInt.D1) varArray).set(i, pos);
}
lineVar.setCachedData(varArray, false);
ncfile.addVariable(null, lineVar);
Variable elementVar = new Variable(ncfile, null, null, "elements");
elementVar.setDataType(DataType.INT);
elementVar.setDimensions("elements");
//elementVar.addAttribute(new Attribute("units", "km"));
elementVar.addAttribute(new Attribute("standard_name",
"projection_x_coordinate"));
varArray = new ArrayInt.D1(numElements);
for (int i = 0; i < numElements; i++) {
((ArrayInt.D1) varArray).set(i, i);
}
elementVar.setCachedData(varArray, false);
ncfile.addVariable(null, elementVar);
// TODO: handle bands and calibrations
Variable bandVar = new Variable(ncfile, null, null, "bands");
bandVar.setDataType(DataType.INT);
bandVar.setDimensions("bands");
bandVar.addAttribute(new Attribute("long_name",
"spectral band number"));
bandVar.addAttribute(new Attribute("axis", "Z"));
Array bandArray = new ArrayInt.D1(numBands);
for (int i = 0; i < numBands; i++) {
((ArrayInt.D1) bandArray).set(i, bandMap[i]);
}
bandVar.setCachedData(bandArray, false);
ncfile.addVariable(null, bandVar);
// the image
Variable imageVar = new Variable(ncfile, null, null, "image");
imageVar.setDataType(DataType.INT);
imageVar.setDimensions(image);
setCalTypeAttributes(imageVar, getCalType(calName));
imageVar.addAttribute(new Attribute(getADDescription(af.AD_CALTYPE),
calName));
imageVar.addAttribute(new Attribute("bands", bandArray));
imageVar.addAttribute(new Attribute("grid_mapping", "AREAnav"));
ncfile.addVariable(null, imageVar);
Variable dirVar = new Variable(ncfile, null, null, "areaDirectory");
dirVar.setDataType(DataType.INT);
dirVar.setDimensions("dirSize");
setAreaDirectoryAttributes(dirVar);
ArrayInt.D1 dirArray = new ArrayInt.D1(AreaFile.AD_DIRSIZE);
for (int i = 0; i < AreaFile.AD_DIRSIZE; i++) {
dirArray.set(i, dirBlock[i]);
}
dirVar.setCachedData(dirArray, false);
ncfile.addVariable(null, dirVar);
Variable navVar = new Variable(ncfile, null, null, "navBlock");
navVar.setDataType(DataType.INT);
navVar.setDimensions("navSize");
setNavBlockAttributes(navVar);
ArrayInt.D1 navArray = new ArrayInt.D1(navBlock.length);
for (int i = 0; i < navBlock.length; i++) {
navArray.set(i, navBlock[i]);
}
navVar.setCachedData(navArray, false);
ncfile.addVariable(null, navVar);
// projection variable
ProjectionImpl projection = new McIDASAreaProjection(af);
Variable proj = new Variable(ncfile, null, null, "AREAnav");
proj.setDataType(DataType.CHAR);
proj.setDimensions("");
List params = projection.getProjectionParameters();
for (int i = 0; i < params.size(); i++) {
Parameter p = (Parameter) params.get(i);
proj.addAttribute(new Attribute(p));
}
// For now, we have to overwrite the parameter versions of thes
proj.addAttribute(
new Attribute(
"grid_mapping_name", McIDASAreaProjection.GRID_MAPPING_NAME));
/*
proj.addAttribute(new Attribute(McIDASAreaProjection.ATTR_AREADIR,
dirArray));
proj.addAttribute(new Attribute(McIDASAreaProjection.ATTR_NAVBLOCK,
navArray));
*/
varArray = new ArrayChar.D0();
((ArrayChar.D0) varArray).set(' ');
proj.setCachedData(varArray, false);
ncfile.addVariable(null, proj);
// add the attributes
ncfile.addAttribute(null, new Attribute("Conventions", "CF-1.0"));