mod_oasis_sys.F90 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. !> System type methods
  2. MODULE mod_oasis_sys
  3. USE mod_oasis_kinds
  4. USE mod_oasis_data
  5. IMPLICIT NONE
  6. character(len=*),parameter,public :: astr = ' ABORT: ' ! abort string
  7. character(len=*),parameter,public :: estr = ' ERROR: ' ! error string
  8. character(len=*),parameter,public :: wstr = ' WARNING: ' ! warning string
  9. private
  10. public oasis_abort
  11. public oasis_flush
  12. public oasis_unitsetmin
  13. public oasis_unitget
  14. public oasis_unitfree
  15. public oasis_debug_enter
  16. public oasis_debug_exit
  17. public oasis_debug_note
  18. integer(ip_intwp_p),parameter :: muni = 20
  19. integer(ip_intwp_p),save :: unitno(muni) = -1
  20. integer(ip_intwp_p),save :: maxion
  21. integer(ip_intwp_p),parameter :: tree_delta = 2
  22. integer(ip_intwp_p),save :: tree_indent = 0
  23. !--------------------------------------------------------------------
  24. CONTAINS
  25. !--------------------------------------------------------------------
  26. !--------------------------------------------------------------------
  27. !> OASIS abort method, publically available to users
  28. SUBROUTINE oasis_abort(id_compid, cd_routine, cd_message, rcode)
  29. IMPLICIT NONE
  30. !--------------------------------------------------------------------
  31. INTEGER(kind=ip_intwp_p),INTENT(in),optional :: id_compid !< component id
  32. CHARACTER(len=*), INTENT(in),optional :: cd_routine !< string defining calling routine
  33. CHARACTER(len=*), INTENT(in),optional :: cd_message !< error message string
  34. INTEGER,INTENT(in),optional :: rcode !< optional code to return to invoking environment
  35. !--------------------------------------------------------------------
  36. INTEGER :: ierror, errcode
  37. character(len=*),parameter :: subname = '(oasis_abort)'
  38. !--------------------------------------------------------------------
  39. if (present(id_compid)) &
  40. WRITE (nulprt,*) subname,astr,'compid = ',id_compid
  41. if (present(cd_routine)) &
  42. WRITE (nulprt,*) subname,astr,'called by = ',trim(cd_routine)
  43. if (present(cd_message)) &
  44. WRITE (nulprt,*) subname,astr,'message = ',trim(cd_message)
  45. IF (PRESENT(rcode)) THEN
  46. errcode=rcode
  47. WRITE (nulprt,*) subname,astr,'errcode = ',errcode
  48. ELSE
  49. errcode=1
  50. ENDIF
  51. WRITE (nulprt,*) subname,astr,'on model = ',trim(compnm)
  52. WRITE (nulprt,*) subname,astr,'on global rank = ',mpi_rank_global
  53. WRITE (nulprt,*) subname,astr,'on local rank = ',mpi_rank_local
  54. WRITE (nulprt,*) subname,astr,'CALLING ABORT FROM OASIS LAYER NOW'
  55. CALL oasis_flush(nulprt)
  56. #if defined use_comm_MPI1 || defined use_comm_MPI2
  57. CALL MPI_ABORT (mpi_comm_global, errcode, ierror)
  58. #endif
  59. STOP
  60. END SUBROUTINE oasis_abort
  61. !==========================================================================
  62. !> Flushes output to file
  63. SUBROUTINE oasis_flush(nu)
  64. IMPLICIT NONE
  65. !--------------------------------------------------------------------
  66. INTEGER(kind=ip_intwp_p),INTENT(in) :: nu !< unit number of file
  67. !--------------------------------------------------------------------
  68. character(len=*),parameter :: subname = '(oasis_flush)'
  69. !--------------------------------------------------------------------
  70. CALL FLUSH(nu)
  71. END SUBROUTINE oasis_flush
  72. !==========================================================================
  73. !> Get a free unit number
  74. SUBROUTINE oasis_unitget(uio)
  75. IMPLICIT NONE
  76. !--------------------------------------------------------------------
  77. INTEGER(kind=ip_intwp_p),INTENT(out) :: uio !< unit number
  78. !--------------------------------------------------------------------
  79. INTEGER(kind=ip_intwp_p) :: n1
  80. logical :: found
  81. character(len=*),parameter :: subname = '(oasis_unitget)'
  82. !--------------------------------------------------------------------
  83. n1 = 0
  84. found = .false.
  85. do while (n1 < muni .and. .not.found)
  86. n1 = n1 + 1
  87. if (unitno(n1) < 0) then
  88. found = .true.
  89. uio = n1 + maxion
  90. unitno(n1) = uio
  91. if (OASIS_debug >= 2) write(nulprt,*) subname,n1,uio
  92. endif
  93. enddo
  94. if (.not.found) then
  95. write(nulprt,*) subname,estr,'no unit number available '
  96. call oasis_abort()
  97. endif
  98. END SUBROUTINE oasis_unitget
  99. !==========================================================================
  100. !> Set the minimum unit number allowed
  101. SUBROUTINE oasis_unitsetmin(uio)
  102. IMPLICIT NONE
  103. !--------------------------------------------------------------------
  104. INTEGER(kind=ip_intwp_p),INTENT(in) :: uio !< unit number
  105. !--------------------------------------------------------------------
  106. character(len=*),parameter :: subname = '(oasis_unitsetmin)'
  107. !--------------------------------------------------------------------
  108. maxion = uio
  109. if (OASIS_debug >= 20) write(nulprt,*) subname,maxion
  110. END SUBROUTINE oasis_unitsetmin
  111. !==========================================================================
  112. !> Release a unit number for reuse
  113. SUBROUTINE oasis_unitfree(uio)
  114. IMPLICIT NONE
  115. !--------------------------------------------------------------------
  116. INTEGER(kind=ip_intwp_p),INTENT(in) :: uio !< unit number
  117. !--------------------------------------------------------------------
  118. INTEGER(kind=ip_intwp_p) :: n1
  119. character(len=*),parameter :: subname = '(oasis_unitfree)'
  120. !--------------------------------------------------------------------
  121. do n1 = 1,muni
  122. if (unitno(n1) == uio) then
  123. unitno(n1) = -1
  124. if (OASIS_debug >= 20) write(nulprt,*) subname,n1,uio
  125. endif
  126. enddo
  127. END SUBROUTINE oasis_unitfree
  128. !=========================================================================
  129. !==========================================================================
  130. !> Used when a subroutine is entered, write info to log file at some debug level
  131. SUBROUTINE oasis_debug_enter(string)
  132. IMPLICIT NONE
  133. !--------------------------------------------------------------------
  134. CHARACTER(len=*), INTENT(in) :: string !< name of the subroutine
  135. character(len=*),parameter :: subname = '(oasis_debug_enter)'
  136. CHARACTER(len=1), pointer :: ch_blank(:)
  137. CHARACTER(len=500) :: tree_enter
  138. if (OASIS_debug >= 10) then
  139. ALLOCATE (ch_blank(tree_indent))
  140. ch_blank='-'
  141. tree_enter='-- ENTER '//TRIM(string)
  142. WRITE(nulprt,*) ch_blank,TRIM(tree_enter)
  143. tree_indent = tree_indent + tree_delta
  144. DEALLOCATE (ch_blank)
  145. CALL oasis_flush(nulprt)
  146. endif
  147. END SUBROUTINE oasis_debug_enter
  148. !==========================================================================
  149. !> Used when a subroutine is exited, write info to log file at some debug level
  150. SUBROUTINE oasis_debug_exit(string)
  151. IMPLICIT NONE
  152. !--------------------------------------------------------------------
  153. CHARACTER(len=*), INTENT(in) :: string !< name of subroutine
  154. character(len=*),parameter :: subname = '(oasis_debug_exit)'
  155. CHARACTER(len=1), pointer :: ch_blank(:)
  156. CHARACTER(len=500) :: tree_exit
  157. IF (OASIS_debug >= 10) THEN
  158. tree_indent = MAX(0,tree_indent - tree_delta)
  159. ALLOCATE (ch_blank(tree_indent))
  160. ch_blank='-'
  161. tree_exit='-- EXIT '//TRIM(string)
  162. WRITE(nulprt,*) ch_blank,TRIM(tree_exit)
  163. DEALLOCATE (ch_blank)
  164. CALL oasis_flush(nulprt)
  165. ENDIF
  166. END SUBROUTINE oasis_debug_exit
  167. !==========================================================================
  168. !> Used to write information from a subroutine, write info to log file at some debug level
  169. SUBROUTINE oasis_debug_note(string)
  170. IMPLICIT NONE
  171. !--------------------------------------------------------------------
  172. CHARACTER(len=*), INTENT(in) :: string !< string to write
  173. character(len=*),parameter :: subname = '(oasis_debug_note)'
  174. CHARACTER(len=1), pointer :: ch_blank(:)
  175. CHARACTER(len=500) :: tree_note
  176. if (OASIS_debug >= 12) then
  177. ALLOCATE (ch_blank(tree_indent))
  178. ch_blank='-'
  179. tree_note='-- NOTE '//TRIM(string)
  180. WRITE(nulprt,*) ch_blank,TRIM(tree_note)
  181. DEALLOCATE(ch_blank)
  182. call oasis_flush(nulprt)
  183. endif
  184. END SUBROUTINE oasis_debug_note
  185. !==========================================================================
  186. END MODULE mod_oasis_sys