m_read_MET_SST_grid.F90 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module m_read_MET_SST_grid
  2. ! Reads the CLS SST NetCDF dimensions
  3. contains
  4. subroutine read_MET_SST_grid(filename,gr)
  5. !use mod_dimensions
  6. use mod_grid
  7. use nfw_mod
  8. implicit none
  9. character(len=80), intent(in) :: filename
  10. type(grid), intent(out) :: gr
  11. logical :: ex
  12. !dimension ids
  13. integer :: lon_ID,lat_ID
  14. ! Array dimensions
  15. integer :: nblon,nblat
  16. integer :: ncid
  17. real, allocatable :: lat(:), lon(:)
  18. print *, 'read_MET_SST_grid():'
  19. gr = default_grid
  20. inquire(file=trim(filename),exist=ex)
  21. if(ex) then
  22. call nfw_open(filename, nf_nowrite, ncid)
  23. print *, ' found "', trim(filename), '"...'
  24. ! Get dimension id in netcdf file ...
  25. call nfw_inq_dimid(filename, ncid, 'lon', lon_ID)
  26. call nfw_inq_dimid(filename, ncid, 'lat', lat_ID)
  27. ! Get dimension length from id
  28. call nfw_inq_dimlen(filename, ncid, lon_ID, nblon)
  29. call nfw_inq_dimlen(filename, ncid, lat_ID, nblat)
  30. print*, 'Dimensions lon,lat:', nblon, nblat
  31. allocate(lon(nblon), lat(nblat))
  32. call nfw_inq_varid(filename, ncid, 'lon', lon_ID)
  33. call nfw_inq_varid(filename, ncid, 'lat', lat_ID)
  34. call nfw_get_var_double(filename, ncid, lon_ID, lon)
  35. call nfw_get_var_double(filename, ncid, lat_ID, lat)
  36. call nfw_close(filename, ncid)
  37. gr%nx=nblon
  38. gr%ny=nblat
  39. gr%x0=lon(1)
  40. gr%y0=lat(1)
  41. gr%dx=lon(2)-lon(1)
  42. gr%dy=lat(2)-lat(1)
  43. gr%reg = .true.
  44. gr%order = 2
  45. gr%ux = 'm'
  46. gr%uy = 'm'
  47. gr%set = .true.
  48. deallocate(lon,lat)
  49. endif
  50. end subroutine read_MET_SST_grid
  51. end module m_read_MET_SST_grid