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)
z1=depth(thezlevs);

Error in interp_OGCM (line 310)
u=ztosigma(flipdim(u,1),zu,flipud(Z));

Error in make_OGCM_mercator (line 175)
interp_OGCM(OGCM_dir,OGCM_prefix,Ymin,Mmin,Roa,interp_method,…

I have my grid file and ERA5_blk files already created. I have also downloaded the raw_mercator.nc 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.