0

I have a netcdf file which I am opening in memory and trying to get a binary representation of that file. Unfortunately, there does not seem to be a method that allows this.

I've tried using an ObjectOutputStream and a DataOutputStream but none seem to work:

// Nothing gets writen into baos
NetcdfFile file = NetcdfFile.openInMemory("C:\\testVIL.nc");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(baos);
N3outputStreamWriter w = new N3outputStreamWriter(file);
w.writeDataAll(out);
out.close();
byte[] byteArray = baos.toByteArray();
for ( byte b : byteArray ) {
 System.out.print( (char) b );
}

// netcdfFile is not seralizable
NetcdfFile file = NetcdfFile.openInMemory("C:\\testVIL.nc");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( file );
byte[] byteArray = baos.toByteArray();
for ( byte b : byteArray ) {
  System.out.print( (char) b );
}

Can anyone suggest a way for me to get a binary representation for the netcdf file, I'm stumped!

2 Answers 2

1

The netCDF Operator (NCO) ncks will output binary

ncks -O -b binary.dat in.nc out.nc

For more details see

http://nco.sf.net/nco.html#bnr

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but I'm looking to do this in memory and have no disk I/O
0

NetCDF is already a binary representation, so not sure what you want.

Perhaps:

NetcdfFile file = NetcdfFile.openInMemory("C:\\testVIL.nc");
Variable v = ncfile.findVariable("varname");
Array data = v.read();
while(data.hasNext())
   System.out.printf("%f,", data.nextDouble() );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.