I've got a couple of NetCDF files that I want to convert to Surfer 6's ".grd" format programmatically.
NetCDF's java library is only able to convert to NetCDF and I also can't seem to get CDO to run properly with Cydwin.
How do I convert these files in java (but using Windows, without Cydwin,...)?
I haven't found a java library to directly work with the files yet but there is a way to (indirectly) do this in java:
The Generic Mapping Tools can be used via command line in Windows to convert said files.
Installing it is easy: Download their exe from e.g. github and run it. This is going to install everything needed and also set the necessary environmental variable (has to be ticked during the installation process).
Afterwards the conversion can be run in
cmd
via a short command, e.g.:The input format is detected automatically (NetCDF in my case).
sf
("Golden Software Surfer format 6") states the desired output format. An overview of all supported input/output formats can be found here. I also tested it withsd
("Golden Software Surfer format 7") but that's indeed read-only (as stated in the link).The above command requires you to
cd
to the input file first and is then going to create the output file in the same folder. Instead you can also skip thecd
and give it the path directly:It is possible to use
cmd
in Java, as shown e.g. here. The full example in my case would look like this:This also prints everything that was output because of
-V
to console.