This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi,
I'm new in netcdf Java and I'm wondering if it's possible to change the netcdf header without changing the data. I've tried to do that but it doesn't work (v2.2.10 API):
-------------------------------------
import java.io.*;
import ucar.ma2.*;
import ucar.nc2.*;
public class test2 {
public static void main(String[] args) {
String filename="/home/netcdf/foo.nc";
try {
//Load netcdf:
NetcdfFileWriteable ncfile=new NetcdfFileWriteable(filename);
//Modify a netcdf variable (lattitude): from float datatype to double datatype
Variable varLat=ncfile.findVariable("lat");
varLat.setDataType(DataType.DOUBLE);//lat from float to double
//ncfile.create(); -> doesn't work
//Close:
ncfile.flush();
ncfile.close();
} catch (IOException ioe){
ioe.printStackTrace();
System.err.println("ERROR creating file");
}
-------------------------------------
I think that I'm missing a method that actally writes the changes to the nc file but I don't know wich is it. I've tried ncfile.create() but I've got "not in define mode".
Any help would be appreciate.
Thanks in advance,
Roger Olivella