make_OGCM_mercator error with ztosigma

I am having issues with make_OGCM_mercator. Although I manage to run the download part, when the vertical interpolation starts, I get an error with the function ztosigma, which is called in interp_OGCM.

This is the error message I receive:

Array indices must be positive integers or logical values.

Error in ztosigma (line 62)

Error in interp_OGCM (line 310)

Error in make_OGCM_mercator (line 175)

I have my grid file and ERA5_blk files already created. I have also downloaded the files and created the mercator_…cdf file, but I can’t seem to get past this error.

So, the error was that I had some nans on my grid file, cause I made a mistake when creating it.