Reputation: 1033
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!
Upvotes: 0
Views: 941
Reputation: 1387
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() );
Upvotes: 0
Reputation: 6352
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
Upvotes: 1