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

Re: Newbie question: how to change netcdf header?



At 12:42 AM 10/26/2005, Roger Olivella wrote:
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):

Changing the header would generally change its size.
The variables data would follow the header in the netcdf file, so changing the headers size would require relocating the variables data. Operating systems don't usually support inserting/deleting into the middle of a file, making such an operation very expensive.

Executive summary: not practical. Simpler to build a new netcdf file from the old.


-------------------------------------
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


**********************************************
Eric Davies, M.Sc.
Barrodale Computing Services Ltd.
Tel: (250) 472-4372 Fax: (250) 472-4373
Web: http://www.barrodale.com
Email: address@hidden
**********************************************
Mailing Address:
P.O. Box 3075 STN CSC
Victoria BC Canada V8W 3W2

Shipping Address:
Hut R, McKenzie Avenue
University of Victoria
Victoria BC Canada V8W 3W2
**********************************************