[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie question: how to change netcdf header?



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