The code is this answer does work Add a new dimension but it does not do what I want it to do.
To illustrate my problem further - I have the following definitions Time(unlimited), latitude, longitude, level as four dimensions and one variable geopotential height. What I want to do is that add a dimension dimz_Z to the existing variable geopotential height.
Right now with the answer in the code above here is how the netCDF file looks like with a ncdump
float hgt(time, level, lat, lon)
But the dimz_Z dimension is missing as seen below from the output of ncks.
hgt dimension 0: time, size = 1 NC_DOUBLE, chunksize = 1 (Record coordinate is time)
hgt dimension 1: level, size = 1 NC_FLOAT, chunksize = 1 (Coordinate is level)
hgt dimension 2: lat, size = 23 NC_FLOAT, chunksize = 23 (Coordinate is lat)
hgt dimension 3: lon, size = 21 NC_FLOAT, chunksize = 21 (Coordinate is lon)
It does show up in the definitions but as a stand-alone dimension and not part of the dimension of hgt
dimz_Z: type NC_FLOAT, 1 dimension, 0 attributes, compressed? no, chunked? no, packed? no
dimz_Z size (RAM) = 483*sizeof(NC_FLOAT) = 483*4 = 1932 bytes
dimz_Z dimension 0: dimz_Z, size = 483 NC_FLOAT (Coordinate is dimz_Z)
This is the output of the file
time[0]=1879032 level[0]=1000 lat[0]=60 lon[0]=50 hgt[0]=53 m
time[0]=1879032 level[0]=1000 lat[0]=60 lon[1]=52.5 hgt[1]=55 m
What I want is the following
time[0]=1879032 level[0]=1000 lat[0]=60 lon[0]=50 dimz_Z[0]=0 hgt[0]=53 m
time[0]=1879032 level[0]=1000 lat[0]=60 lon[1]=52.5 dimz_Z[0]=0 hgt[1]=55 m
What I have been told by a friend is that I cannot add this dimension to the existing variable. Instead in fortran I must define the variable hgt all over again as a five dimensional variable and put the values all over again. Is that correct or is there an alternative ? I am using Fortran 77 netcdf API.