m_read_CLS_TSLA_grid.F90 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. module m_read_CLS_TSLA_grid
  2. ! Reads the CLS SST NetCDF dimensions
  3. integer, parameter, private :: STRLEN = 512
  4. contains
  5. subroutine read_CLS_TSLA_grid(filename,gr)
  6. !use mod_dimensions
  7. use mod_grid
  8. use netcdf
  9. use nfw_mod
  10. implicit none
  11. character(len=80), intent(in) :: filename
  12. type(grid), intent(out) :: gr
  13. character(len=80) :: fname
  14. logical :: ex
  15. !dimension ids
  16. integer :: data_ID,cycl_ID
  17. ! Array dimensions
  18. integer :: nb,cycl
  19. integer :: ncid,fcount
  20. character(STRLEN) :: Fpath
  21. character(STRLEN) :: ftemplate
  22. print *, 'read_CLS_TSLA_grid():'
  23. gr = default_grid
  24. gr%nx=0
  25. Fpath='./'
  26. ! Open file
  27. do fcount=1,7 !2 satellite Envissat,J2
  28. select case(fcount)
  29. case(1)
  30. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_en*.nc'
  31. case(2)
  32. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_j1*.nc'
  33. case(3)
  34. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_j2*.nc'
  35. case(4)
  36. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_e1*.nc'
  37. case(5)
  38. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_e2*.nc'
  39. case(6)
  40. ftemplate = trim(fpath)//'sla_'//trim(filename)//'_tp*.nc'
  41. case(7)
  42. ftemplate = trim(fpath)//'sla_'//trim(filename)//'_g2*.nc'
  43. end select
  44. call fname_fromtemplate(ftemplate, fname)
  45. inquire(file=trim(fname),exist=ex)
  46. if(ex) then
  47. call nfw_open(fname, nf_nowrite, ncid)
  48. print *, ' found "', trim(fname), '"...'
  49. ! Get dimension id in netcdf file ...
  50. call nfw_inq_dimid(fname, ncid, 'Data', data_ID)
  51. call nfw_inq_dimid(fname, ncid, 'Cycles', cycl_ID)
  52. ! Get dimension length from id
  53. call nfw_inq_dimlen(fname, ncid, data_ID, nb)
  54. call nfw_inq_dimlen(fname, ncid, cycl_ID, cycl)
  55. call nfw_close(fname, ncid)
  56. gr%nx=gr%nx+nb*cycl
  57. gr%ny=1
  58. gr%x0=0
  59. gr%y0=0
  60. gr%dx=0.1
  61. gr%dy=0.1
  62. gr%reg = .false.
  63. gr%order = 1
  64. gr%ux = 'm'
  65. gr%uy = 'm'
  66. gr%set = .true.
  67. endif
  68. enddo
  69. end subroutine read_CLS_TSLA_grid
  70. subroutine read_MYO_TSLA_grid(filename,gr)
  71. !use mod_dimensions
  72. use mod_grid
  73. use netcdf
  74. use nfw_mod
  75. implicit none
  76. character(len=80), intent(in) :: filename
  77. type(grid), intent(out) :: gr
  78. character(len=80) :: fname
  79. logical :: ex
  80. !dimension ids
  81. integer :: time_ID
  82. ! Array dimensions
  83. integer :: nb
  84. integer :: ncid,fcount
  85. character(STRLEN) :: Fpath
  86. character(STRLEN) :: ftemplate
  87. print *, 'read_MYO_TSLA_grid():'
  88. gr = default_grid
  89. gr%nx=0
  90. Fpath='./'
  91. ! Open file
  92. do fcount=1,9 !2 satellite Envissat,J2
  93. select case(fcount)
  94. case(1)
  95. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_en*.nc'
  96. case(2)
  97. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_j1*.nc'
  98. case(3)
  99. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_j2*.nc'
  100. case(4)
  101. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_e1*.nc'
  102. case(5)
  103. ftemplate=trim(Fpath)//'sla_'//trim(filename)//'_e2*.nc'
  104. case(6)
  105. ftemplate = trim(fpath)//'sla_'//trim(filename)//'_tp*.nc'
  106. case(7)
  107. ftemplate = trim(fpath)//'sla_'//trim(filename)//'_g2*.nc'
  108. case(8)
  109. ftemplate = trim(fpath)//'sla_'//trim(filename)//'_c2*.nc'
  110. case(9)
  111. ftemplate = trim(fpath)//'sla_'//trim(filename)//'_al*.nc'
  112. end select
  113. call fname_fromtemplate(ftemplate, fname)
  114. inquire(file=trim(fname),exist=ex)
  115. if(ex) then
  116. call nfw_open(fname, nf_nowrite, ncid)
  117. print *, ' found "', trim(fname), '"...'
  118. ! Get dimension id in netcdf file ...
  119. call nfw_inq_dimid(fname, ncid, 'time', time_ID)
  120. ! Get dimension length from id
  121. call nfw_inq_dimlen(fname, ncid, time_ID, nb)
  122. call nfw_close(fname, ncid)
  123. gr%nx=gr%nx+nb
  124. gr%ny=1
  125. gr%x0=0
  126. gr%y0=0
  127. gr%dx=0.1
  128. gr%dy=0.1
  129. gr%reg = .false.
  130. gr%order = 1
  131. gr%ux = 'm'
  132. gr%uy = 'm'
  133. gr%set = .true.
  134. endif
  135. enddo
  136. end subroutine read_MYO_TSLA_grid
  137. subroutine fname_fromtemplate(ftemplate, fname)
  138. character(*), intent(in) :: ftemplate
  139. character(*), intent(inout) :: fname
  140. character(STRLEN) :: command ! (there may be a limit of 80 on some systems)
  141. integer :: ios
  142. command = 'ls '//trim(ftemplate)//' 2> /dev/null > tsla_files.txt'
  143. call system(trim(command));
  144. open(10, file = 'tsla_files.txt')
  145. read(10, fmt = '(a)', iostat = ios) fname
  146. close(10)
  147. if (ios /= 0) then
  148. fname = ""
  149. end if
  150. end subroutine fname_fromtemplate
  151. end module m_read_CLS_TSLA_grid