NOAA-EMC / GSI

Gridpoint Statistical Interpolation
GNU Lesser General Public License v3.0
66 stars 149 forks source link

unsafe interp_inc.fd/driver.f90 assumption #370

Closed RussTreadon-NOAA closed 2 years ago

RussTreadon-NOAA commented 2 years ago

As currently coded interp_inc.fd/driver.f90 assumes variables lon and lat are have the same integer addresses as dimensions lon and lat in the input netCDF file. This is shown in the following block of code from driver.f90 which loads the longitude array:

 error = nf90_inq_dimid(ncid_in, 'lon', id_dim)
 call netcdf_err(error, 'inquiring lon dimension for file='//trim(infile) )
 error = nf90_inquire_dimension(ncid_in, id_dim, len=lon_in)
 call netcdf_err(error, 'reading lon dimension for file='//trim(infile) )
 allocate(longitude_in(lon_in))
 error = nf90_get_var(ncid_in, id_dim, longitude_in)
 call netcdf_err(error, 'reading longitude_in for file='//trim(infile) )

We should not assume id_dim for the lon dimension is identical to id_dim for the lon variable. Instead, we should query the location of variable lon prior to getting lon. This is done by adding a call to nf90_inq_varid for variable lon prior to getting lon.

 error = nf90_inq_varid(ncid_in, 'lon', id_dim)
 call netcdf_err(error, 'inquiring var lon dimension for file='//trim(infile) )
 error = nf90_get_var(ncid_in, id_dim, longitude_in)
 call netcdf_err(error, 'reading longitude_in for file='//trim(infile) )

This issue is opened to document this problem and its resolution.

RussTreadon-NOAA commented 2 years ago

Create feature/interp in which to update interp_inc.fd/driver.f90