This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
I am using the NetcdfFileWriteable class as such NetcdfFileWriteable ncw = new NetcdfFileWriteable( "foo.nc", b ); add dims, vars ncw.create(); write data ncw.flush(); ncw.close();where boolean b = true or false, makes no difference to the following observed behavior.
Now, I want my app to hose any existing file foo.nc, i.e. my app knows what needs to be written to foo.nc, and any previous contents are irrelevant. Depending on the config of my app, different amounts of data are intended to be written to foo.nc. My app always writes all of the data for all variables defined, so no 'fill' is required.
Now, the strange part is that if foo.nc exists and I run my app, the contents of foo.nc will only change if the total size of the new dataset in bytes is larger than the existing size of the file foo.nc. If the app intends to write a smaller total number of bytes to foo.nc than is currently on the disk, say to define fewer variables than a previous run, then the new contents are not written.
Even more strangely, no matter if the file contents are or are not updated, the timestamp (file modification time on Unix??) of the file is updated unconditionally.
So, in short, my app will have to remove the file if it exists to be sure of the correct final contents of the file??
As I said, maybe this is as it all should be. If so, are there docs to show this? The javadoc comments for the class suggest to me that what I want to happen, should happen, but it isn't happening ;)
Any clarifications appreciated Stuart