obs_utils.F90 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. MODULE obs_utils
  2. !!======================================================================
  3. !! *** MODULE obs_utils ***
  4. !! Observation diagnostics: Utility functions
  5. !!=====================================================================
  6. !!----------------------------------------------------------------------
  7. !! grt_cir_dis : Great circle distance
  8. !! grt_cir_dis_saa : Great circle distance (small angle)
  9. !! chkerr : Error-message managment for NetCDF files
  10. !! chkdim : Error-message managment for NetCDF files
  11. !! fatal_error : Fatal error handling
  12. !! ddatetoymdhms : Convert YYYYMMDD.hhmmss to components
  13. !!----------------------------------------------------------------------
  14. !! * Modules used
  15. USE par_oce, ONLY : & ! Precision variables
  16. & wp, &
  17. & dp, &
  18. & i8
  19. USE in_out_manager ! I/O manager
  20. USE lib_mpp ! For ctl_warn/stop
  21. IMPLICIT NONE
  22. !! * Routine accessibility
  23. PRIVATE
  24. PUBLIC grt_cir_dis, & ! Great circle distance
  25. & grt_cir_dis_saa, & ! Great circle distance (small angle)
  26. & str_c_to_for, & ! Remove non-printable chars from string
  27. & chkerr, & ! Error-message managment for NetCDF files
  28. & chkdim, & ! Check if dimensions are correct for a variable
  29. & fatal_error, & ! Fatal error handling
  30. & warning, & ! Warning handling
  31. & ddatetoymdhms ! Convert YYYYMMDD.hhmmss to components
  32. !!----------------------------------------------------------------------
  33. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  34. !! $Id: obs_utils.F90 2715 2011-03-30 15:58:35Z rblod $
  35. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  36. !!----------------------------------------------------------------------
  37. CONTAINS
  38. #include "grt_cir_dis.h90"
  39. #include "grt_cir_dis_saa.h90"
  40. #include "str_c_to_for.h90"
  41. SUBROUTINE chkerr( kstatus, cd_name, klineno )
  42. !!----------------------------------------------------------------------
  43. !!
  44. !! *** ROUTINE chkerr ***
  45. !!
  46. !! ** Purpose : Error-message managment for NetCDF files.
  47. !!
  48. !! ** Method :
  49. !!
  50. !! ** Action :
  51. !!
  52. !! History
  53. !! ! 02-12 (N. Daget) hdlerr
  54. !! ! 06-04 (A. Vidard) f90/nemovar migration, change name
  55. !! ! 06-10 (A. Weaver) Cleanup
  56. !!----------------------------------------------------------------------
  57. !! * Modules used
  58. USE netcdf ! NetCDF library
  59. USE dom_oce, ONLY : & ! Ocean space and time domain variables
  60. & nproc
  61. !! * Arguments
  62. INTEGER :: kstatus
  63. INTEGER :: klineno
  64. CHARACTER(LEN=*) :: cd_name
  65. !! * Local declarations
  66. CHARACTER(len=200) :: clineno
  67. ! Main computation
  68. IF ( kstatus /= nf90_noerr ) THEN
  69. WRITE(clineno,'(A,I8)')' at line number ', klineno
  70. CALL ctl_stop( ' chkerr', ' Netcdf Error in ' // TRIM( cd_name ), &
  71. & clineno, nf90_strerror( kstatus ) )
  72. ENDIF
  73. END SUBROUTINE chkerr
  74. SUBROUTINE chkdim( kfileid, kvarid, kndim, kdim, cd_name, klineno )
  75. !!----------------------------------------------------------------------
  76. !!
  77. !! *** ROUTINE chkerr ***
  78. !!
  79. !! ** Purpose : Error-message managment for NetCDF files.
  80. !!
  81. !! ** Method :
  82. !!
  83. !! ** Action :
  84. !!
  85. !! History
  86. !! ! 07-03 (K. Mogenen + E. Remy) Initial version
  87. !!----------------------------------------------------------------------
  88. !! * Modules used
  89. USE netcdf ! NetCDF library
  90. USE dom_oce, ONLY : & ! Ocean space and time domain variables
  91. & nproc
  92. !! * Arguments
  93. INTEGER :: kfileid ! NetCDF file id
  94. INTEGER :: kvarid ! NetCDF variable id
  95. INTEGER :: kndim ! Expected number of dimensions
  96. INTEGER, DIMENSION(kndim) :: kdim ! Expected dimensions
  97. CHARACTER(LEN=*) :: cd_name ! Calling routine name
  98. INTEGER :: klineno ! Calling line number
  99. !! * Local declarations
  100. INTEGER :: indim
  101. INTEGER, ALLOCATABLE, DIMENSION(:) :: &
  102. & idim,ilendim
  103. INTEGER :: ji
  104. LOGICAL :: llerr
  105. CHARACTER(len=200) :: clineno
  106. CALL chkerr( nf90_inquire_variable( kfileid, kvarid, ndims=indim ), &
  107. & cd_name, klineno )
  108. ALLOCATE(idim(indim),ilendim(indim))
  109. CALL chkerr( nf90_inquire_variable( kfileid, kvarid, dimids=idim ), &
  110. & cd_name, klineno )
  111. DO ji = 1, indim
  112. CALL chkerr( nf90_inquire_dimension( kfileid, idim(ji), &
  113. & len=ilendim(ji) ), &
  114. & cd_name, klineno )
  115. END DO
  116. IF ( indim /= kndim ) THEN
  117. WRITE(clineno,'(A,I8)')' at line number ', klineno
  118. CALL ctl_stop( ' chkdim', &
  119. & ' Netcdf no dim error in ' // TRIM( cd_name ), &
  120. & clineno )
  121. ENDIF
  122. DO ji = 1, indim
  123. IF ( ilendim(ji) /= kdim(ji) ) THEN
  124. WRITE(clineno,'(A,I8)')' at line number ', klineno
  125. CALL ctl_stop( ' chkdim', &
  126. & ' Netcdf dim len error in ' // TRIM( cd_name ), &
  127. & clineno )
  128. ENDIF
  129. END DO
  130. DEALLOCATE(idim,ilendim)
  131. END SUBROUTINE chkdim
  132. SUBROUTINE fatal_error( cd_name, klineno )
  133. !!----------------------------------------------------------------------
  134. !!
  135. !! *** ROUTINE fatal_error ***
  136. !!
  137. !! ** Purpose : Fatal error handling
  138. !!
  139. !! ** Method :
  140. !!
  141. !! ** Action :
  142. !!
  143. !! History
  144. !!----------------------------------------------------------------------
  145. !! * Modules used
  146. !! * Arguments
  147. INTEGER :: klineno
  148. CHARACTER(LEN=*) :: cd_name
  149. !! * Local declarations
  150. CHARACTER(len=200) :: clineno
  151. WRITE(clineno,'(A,I8)')' at line number ', klineno
  152. CALL ctl_stop( ' fatal_error', ' Error in ' // TRIM( cd_name ), &
  153. & clineno)
  154. END SUBROUTINE fatal_error
  155. SUBROUTINE warning( cd_name, klineno )
  156. !!----------------------------------------------------------------------
  157. !!
  158. !! *** ROUTINE warning ***
  159. !!
  160. !! ** Purpose : Warning handling
  161. !!
  162. !! ** Method :
  163. !!
  164. !! ** Action :
  165. !!
  166. !! History
  167. !!----------------------------------------------------------------------
  168. !! * Modules used
  169. !! * Arguments
  170. INTEGER :: klineno
  171. CHARACTER(LEN=*) :: cd_name
  172. !! * Local declarations
  173. CHARACTER(len=200) :: clineno
  174. WRITE(clineno,'(A,I8)')' at line number ', klineno
  175. CALL ctl_warn( ' warning', ' Potential problem in ' // TRIM( cd_name ), &
  176. & clineno)
  177. END SUBROUTINE warning
  178. #include "ddatetoymdhms.h90"
  179. END MODULE obs_utils