Lat_rho & lon_rho indexes

Dear All,

I am currently trying to validate my CROCO model output with some CTD observation data which is at some fixed longitude and latitude points. For this I need model output data say salinity at this same or nearest lat_rho and lon_rho as for CTD data.

I tried to find the corresponding index from lat_rho and lon_rho but due to staggered grid I am facing difficulties to get it correctly. Can any one pleasse help to to overcome with this problem??

Many thanks!

Anurag

You can do something like this to find the “nearest” matrix index for your location

nc=netcdf(‘croco_grd.nc’,‘r’);
lat_rho=nc{‘lat_rho’}(:,:);
lon_rho=nc{‘lon_rho’}(:,:);
close(nc)

lat1= -10.; % Set your location here
lon1= -130.;

indx1=find(abs(min(abs(lat1-lat_rho(:,1)))==abs((lat1-lat_rho(:,1)))));
indx2=find(abs(min(abs(lon1-lon_rho(1,:)))==abs((lon1-lon_rho(1,:)))));

lat_rho(indx1,indx2)
lon_rho(indx1,indx2)

1 Like

Thank you andres! I shall try accordingly.

Hi Andres,

I tried accordingly to get corresponding indexes as you suggested however I am not getting it correctly.

For an example, I need the corresponding indexes for lon1= 53.7640 and lat1=26.3720, so I defined them as lon1 at lat1 and then I am using the same code as you mentioned above to find the indx1 and indx2.
I am getting the index values at this steps but once I look on lat_rho(indx1,indx2) and lon_rho(indx1,indx2) at these indexes I am getting the coordinate lon_rho as 49.4085 and lat_rho as 31.3533 which are far away from my set locations lon1 and lat1 which are 53.7640 & 26.3720 respectively.
I will be glad if I can be pointed to ways to solve this issue.

Many Thanks.

Anurag

@ak11283 @andres
what is tried accordingly? :slight_smile:

Hi,

Have you any idea to choose the indexes for some fixed longitude and latitude points from lat_rho & lon_rho on a staggered grid? I hope now you shall be able to understand that what I am looking for. :slightly_smiling_face:

Anurag

1 Like

@ak11283
__staggered grid in CFD, ! Ivar unknown! :stuck_out_tongue_winking_eye: __