sedarr.F90 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. MODULE sedarr
  2. !!======================================================================
  3. !! *** MODULE sedarr ***
  4. !! transform 1D (2D) array to a 2D (1D) table
  5. !!======================================================================
  6. #if defined key_sed
  7. !!----------------------------------------------------------------------
  8. !! arr_2d_1d : 2-D to 1-D
  9. !! arr_1d_2d : 1-D to 2-D
  10. !!----------------------------------------------------------------------
  11. !! * Modules used
  12. USE par_sed
  13. IMPLICIT NONE
  14. PRIVATE
  15. INTERFACE pack_arr
  16. MODULE PROCEDURE pack_arr_2d_1d , pack_arr_3d_2d
  17. END INTERFACE
  18. INTERFACE unpack_arr
  19. MODULE PROCEDURE unpack_arr_1d_2d , unpack_arr_2d_3d
  20. END INTERFACE
  21. !! * Routine accessibility
  22. PUBLIC pack_arr
  23. PUBLIC unpack_arr
  24. !!----------------------------------------------------------------------
  25. !! NEMO/TOP 3.3 , NEMO Consortium (2010)
  26. !! $Id: sedarr.F90 2355 2015-05-20 07:11:50Z ufla $
  27. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  28. !!----------------------------------------------------------------------
  29. CONTAINS
  30. SUBROUTINE pack_arr_2d_1d ( ndim1d, tab1d, tab2d, tab_ind )
  31. INTEGER, INTENT(in) :: ndim1d
  32. REAL(wp), DIMENSION (jpi, jpj), INTENT(in) :: tab2d
  33. INTEGER, DIMENSION (ndim1d), INTENT (in) :: tab_ind
  34. REAL(wp), DIMENSION(ndim1d), INTENT (out) :: tab1d
  35. INTEGER :: jn, jid, jjd
  36. DO jn = 1, ndim1d
  37. jid = MOD( tab_ind(jn) - 1, jpi ) + 1
  38. jjd = ( tab_ind(jn) - 1 ) / jpi + 1
  39. tab1d(jn) = tab2d(jid, jjd)
  40. END DO
  41. END SUBROUTINE pack_arr_2d_1d
  42. SUBROUTINE unpack_arr_1d_2d ( ndim1d, tab2d, tab_ind, tab1d )
  43. INTEGER, INTENT ( in) :: ndim1d
  44. INTEGER, DIMENSION (ndim1d) , INTENT (in) :: tab_ind
  45. REAL(wp), DIMENSION(ndim1d), INTENT (in) :: tab1d
  46. REAL(wp), DIMENSION (jpi, jpj), INTENT ( out) :: tab2d
  47. INTEGER :: jn, jid, jjd
  48. DO jn = 1, ndim1d
  49. jid = MOD( tab_ind(jn) - 1, jpi) + 1
  50. jjd = ( tab_ind(jn) - 1 ) / jpi + 1
  51. tab2d(jid, jjd) = tab1d(jn)
  52. END DO
  53. END SUBROUTINE unpack_arr_1d_2d
  54. SUBROUTINE pack_arr_3d_2d ( ndim1d, tab2d, tab3d, tab_ind )
  55. INTEGER, INTENT(in) :: ndim1d
  56. REAL(wp), DIMENSION(jpi,jpj,jpksed), INTENT(in) :: tab3d
  57. INTEGER, DIMENSION(ndim1d), INTENT (in) :: tab_ind
  58. REAL(wp), DIMENSION(ndim1d,jpksed), INTENT (out) :: tab2d
  59. INTEGER, DIMENSION(ndim1d) :: jid, jjd
  60. INTEGER :: jk, jn , ji, jj
  61. DO jn = 1, ndim1d
  62. jid(jn) = MOD( tab_ind(jn) - 1, jpi ) + 1
  63. jjd(jn) = ( tab_ind(jn) - 1 ) / jpi + 1
  64. END DO
  65. DO jk = 1, jpksed
  66. DO jn = 1, ndim1d
  67. ji = jid(jn)
  68. jj = jjd(jn)
  69. tab2d(jn,jk) = tab3d(ji,jj,jk)
  70. ENDDO
  71. ENDDO
  72. END SUBROUTINE pack_arr_3d_2d
  73. SUBROUTINE unpack_arr_2d_3d ( ndim1d, tab3d, tab_ind, tab2d )
  74. INTEGER, INTENT(in) :: ndim1d
  75. REAL(wp), DIMENSION(ndim1d,jpksed), INTENT(in) :: tab2d
  76. INTEGER, DIMENSION(ndim1d), INTENT (in) :: tab_ind
  77. REAL(wp), DIMENSION(jpi,jpj,jpksed), INTENT (out) :: tab3d
  78. INTEGER, DIMENSION(ndim1d) :: jid, jjd
  79. INTEGER :: jk, jn , ji, jj
  80. DO jn = 1, ndim1d
  81. jid(jn) = MOD( tab_ind(jn) - 1, jpi ) + 1
  82. jjd(jn) = ( tab_ind(jn) - 1 ) / jpi + 1
  83. END DO
  84. DO jk = 1, jpksed
  85. DO jn = 1, ndim1d
  86. ji = jid(jn)
  87. jj = jjd(jn)
  88. tab3d(ji, jj, jk) = tab2d(jn,jk)
  89. ENDDO
  90. ENDDO
  91. END SUBROUTINE unpack_arr_2d_3d
  92. #else
  93. !!======================================================================
  94. !! MODULE sedarr : Dummy module
  95. !!======================================================================
  96. CONTAINS
  97. SUBROUTINE pack_arr ! Empty routine
  98. END SUBROUTINE pack_arr
  99. SUBROUTINE unpack_arr ! Empty routine
  100. END SUBROUTINE unpack_arr
  101. !!======================================================================
  102. #endif
  103. END MODULE sedarr