m_read_CLS_SST_grid.F90 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. module m_read_CLS_SST_grid
  2. ! Reads the CLS SST NetCDF dimensions
  3. contains
  4. subroutine read_CLS_SST_grid(filename,gr)
  5. !use mod_dimensions
  6. use mod_grid
  7. use netcdf
  8. use m_nf90_err
  9. !use nfw_mod
  10. implicit none
  11. character(len=80), intent(in) :: filename
  12. type(grid), intent(out) :: gr
  13. !dimension ids
  14. integer :: NbLatitudes_ID, NbLongitudes_ID, LatLon_ID
  15. ! Array dimensions
  16. integer :: LatLon, NbLatitudes, NbLongitudes
  17. real, allocatable :: latlon0(:), dlatlon(:)
  18. !variables ids
  19. integer :: vLatLonMin_ID, vLatLonStep_ID
  20. integer :: ncid
  21. gr = default_grid
  22. ! Open file
  23. !filename='sst_topaz_19510.nc'
  24. call nf90_err(NF90_OPEN(trim(filename),NF90_NOCLOBBER,ncid))
  25. !call nfw_open(trim(filename), nf_nowrite, ncid)
  26. ! Get dimension id in netcdf file ...
  27. call nf90_err(nf90_Inq_Dimid(ncid,'LatLon',LatLon_ID))
  28. call nf90_err(nf90_Inq_Dimid(ncid,'NbLatitudes',NbLatitudes_ID))
  29. call nf90_err(nf90_Inq_Dimid(ncid,'NbLongitudes',NbLongitudes_ID))
  30. ! Get dimension length from id
  31. call nf90_err(nf90_Inquire_Dimension(ncid,LatLon_ID,len=LatLon))
  32. call nf90_err(nf90_Inquire_Dimension(ncid,NbLatitudes_ID,len=NbLatitudes))
  33. call nf90_err(nf90_Inquire_Dimension(ncid,NbLongitudes_ID,len=NbLongitudes))
  34. ! call nf90_err(nf90_Inquire_Dimension(ncid,GridDepth_ID,len=GridDepth))
  35. print*, 'Dimensions:', NbLatitudes, NbLongitudes, LatLon
  36. allocate(latlon0(LatLon)) ! Grid origin coordinates
  37. allocate(dlatlon(LatLon)) ! dx and dy
  38. ! Variable ids in netcdf file
  39. call nf90_err(nf90_inq_varid(ncid,'LatLonMin' ,vLatLonMin_ID),'LatLonMin')
  40. call nf90_err(nf90_inq_varid(ncid,'LatLonStep' ,vLatLonStep_ID),'LatLonStep')
  41. ! Variables in NetCDF file
  42. call nf90_err(nf90_get_var(ncid,vLatLonMin_ID ,latlon0))
  43. print *, 'Grid Origin ', latlon0
  44. call nf90_err(nf90_get_var(ncid,vLatLonStep_ID ,dlatlon))
  45. print *, 'Grid Size ', dlatlon
  46. gr%nx=NbLatitudes
  47. gr%ny=NbLongitudes
  48. gr%x0= latlon0(1)
  49. gr%y0= latlon0(2)
  50. ! gr%dx= 0.179
  51. gr%dx= dlatlon(1)
  52. gr%dy= dlatlon(2)
  53. gr%reg = .true.
  54. gr%order = 2
  55. gr%ux = 'deg'
  56. gr%uy = 'deg'
  57. gr%set = .true.
  58. deallocate(latlon0,dlatlon)
  59. end subroutine read_CLS_SST_grid
  60. end module m_read_CLS_SST_grid