NOAA-GFDL / FRE-NCtools

Tools for manipulating and creating netCDF inputs for FMS managed models
GNU Lesser General Public License v3.0
20 stars 28 forks source link

Are field_in area arrays using sufficient memory? #266

Open ngs333 opened 11 months ago

ngs333 commented 11 months ago

@mlee03 has noticed a very interesting and suspicious code relationship. In function do_scalar_conserve_interp, for second order conservative regridding, for cell_methods SUM or cell_measure true, field_in.area and grid_in.cell_area are indexed by a 3D index, with the horizontal component by itself being NX*NY:

...
n1 = k * nx1 * ny1 + j1 * nx1 + i1;
      else if (cell_measures)
             area *= (field_in[tile].area[n1]  / grid_in[tile].cell_area[n1]);
...

However, the arrays seem to be to small , of size NX * NY as determined by code inspection. For example, in function get_input_data , for the cell measure case:

field[n].area = (double *)malloc(nx * ny * sizeof(double));

Without some side effect programming or hidden correction of the array sizes, the code may be incorrect and it merits further investigation. If somehow the code is correct it should be documented. If its not correct, a clean code / non-mysterious software should be created.

This mystery can be seen in the baseline code, circa 2023.