ccycle_coupling.f90 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. program CC_COUP
  2. ! First implementation: May 2020 (Etienne Tourigny) - dummy tm5 coupling - co2 ppm + fluxes, need to set co2 ppm value in namelist to activate this (284 for PI), or set to 0 to deactivate
  3. ! update: June 2020 (Etienne Tourigny) - always send co2, option to couple to pisces (disabled)
  4. use mod_oasis
  5. use mpi
  6. implicit none
  7. integer,parameter :: TM5GRID = 10800 ! CTM3
  8. integer,parameter :: t_max_year = 365
  9. integer,parameter :: t_max_leap = 366
  10. integer :: num_years,start_year
  11. double precision :: co2_ppm
  12. logical :: coupled_to_lpjguess, coupled_to_pisces
  13. namelist /NAMCC_COUP/ num_years,start_year,co2_ppm
  14. character(len=*),parameter :: NamelistFileName = "namelist.ccycle_coupling"
  15. integer,parameter :: NAMCC_COUPU = 999
  16. logical :: CC_COUPnotFree
  17. character(len=6),parameter :: model_name = "CC_COUP"
  18. ! dummy tm5 coupling - co2 ppm + fluxes
  19. character(len=128),parameter :: f_lco2_name = "LCO2_TM5"
  20. integer :: f_lco2_id = -77
  21. double precision :: f_lco2_data(TM5GRID,1)
  22. character(len=128),parameter :: f_oco2_name = "OCO2_TM5"
  23. integer :: f_oco2_id = -77
  24. double precision :: f_oco2_data(TM5GRID,1)
  25. ! character(len=128),parameter :: f_cflx_name = "TM5_LandCFLX"
  26. ! integer :: f_cflx_id = -77
  27. ! double precision :: f_cflx_data(TM5GRID,1)
  28. character(len=128),parameter :: f_cnat_name = "TM5_LandCNAT"
  29. integer :: f_cnat_id = -77
  30. double precision :: f_cnat_data(TM5GRID,1)
  31. character(len=128),parameter :: f_cant_name = "TM5_LandCANT"
  32. integer :: f_cant_id = -77
  33. double precision :: f_cant_data(TM5GRID,1)
  34. character(len=128),parameter :: f_cnpp_name = "TM5_LandCNPP"
  35. integer :: f_cnpp_id = -77
  36. double precision :: f_cnpp_data(TM5GRID,1)
  37. ! TODO add option for lpjg,pisces,and feedback
  38. character(len=128),parameter :: f_ocecflx_name = "TM5_OceCFLX"
  39. integer :: f_ocecflx_id = -77
  40. double precision :: f_ocecflx_data(TM5GRID,1)
  41. integer :: comp_id = -77
  42. integer :: part_id_tm5 = -77
  43. integer :: t,t_step,yr,lyr,t_max,t_step_full,cell,loopyr
  44. integer :: ierror
  45. integer::ix,iy
  46. logical :: isleapyear = .false.
  47. character yearstr*4
  48. integer::localcomm, cplcomm, icpl;
  49. ! *** START ***
  50. write (*,'(A)') "*II* ccycle_coupling: Hello"
  51. write (*,*) "*II* ccycle_coupling: TM5GRID=",TM5GRID
  52. ! Read RunLengthSec,TimeStepSec from namelist
  53. inquire(NAMCC_COUPU,opened=CC_COUPnotFree)
  54. if (CC_COUPnotFree) call ERROR('Namelist CCOUP not free',1)
  55. open(NAMCC_COUPU,file=NamelistFileName,status='OLD')
  56. read(NAMCC_COUPU,nml=NAMCC_COUP)
  57. close(NAMCC_COUPU)
  58. ! by default we are coupled to lpjg and not pisces
  59. coupled_to_lpjguess = .true.
  60. coupled_to_pisces = .false.
  61. write (*,'(A)') "*II* ccycle_coupling: Now initialising Ccycle_coupling using oasis_..."
  62. call oasis_init_comp(comp_id,model_name,ierror)
  63. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_init_comp returned ierror=",ierror
  64. icpl = 1
  65. call oasis_create_couplcomm(icpl,MPI_COMM_SELF, cplcomm, ierror)
  66. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_create_couplcomm ierror=",ierror
  67. write (*,'(A,I12)') "*II* ccycle_coupling: oasis_create_couplcomm returned cplcomm =",cplcomm
  68. ! dummy tm5 coupling
  69. call oasis_def_partition(part_id_tm5,(/ 0,0,TM5GRID /),ierror)
  70. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_def_partition returned part_id_co2 =",part_id_tm5
  71. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_def_partition returned ierror =",ierror
  72. if ( coupled_to_lpjguess ) then
  73. call oasis_def_var( f_lco2_id, f_lco2_name, &
  74. part_id_tm5, (/ 2,1 /), PRISM_Out, (/ 1,TM5GRID,1,1 /), PRISM_Real, ierror )
  75. call oasis_def_var( f_cnat_id, f_cnat_name, &
  76. part_id_tm5, (/ 2,1 /), PRISM_In, (/ 1,TM5GRID,1,1 /), PRISM_Real, ierror )
  77. call oasis_def_var( f_cant_id, f_cant_name, &
  78. part_id_tm5, (/ 2,1 /), PRISM_In, (/ 1,TM5GRID,1,1 /), PRISM_Real, ierror )
  79. call oasis_def_var( f_cnpp_id, f_cnpp_name, &
  80. part_id_tm5, (/ 2,1 /), PRISM_In, (/ 1,TM5GRID,1,1 /), PRISM_Real, ierror )
  81. endif
  82. if ( coupled_to_pisces ) then
  83. call oasis_def_var( f_oco2_id, f_oco2_name, &
  84. part_id_tm5, (/ 2,1 /), PRISM_Out, (/ 1,TM5GRID,1,1 /), PRISM_Real, ierror )
  85. call oasis_def_var( f_ocecflx_id, f_ocecflx_name, &
  86. part_id_tm5, (/ 2,1 /), PRISM_In, (/ 1,TM5GRID,1,1 /), PRISM_Real, ierror )
  87. endif
  88. write (*,'(A)') "*II* ccycle_coupling: before call oasis_enddef(ierror)"
  89. call oasis_enddef(ierror)
  90. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_enddef returned ierror =",ierror
  91. write (*,'(A)') "*II* ccycle_coupling: Beginning time loop"
  92. t_step_full = 0
  93. ! Repetitions of forcing
  94. ! do lyr = 1, num_loops
  95. ! Year loop
  96. do loopyr = start_year, start_year+num_years-1
  97. write (*,*) "*III* ccycle_coupling: Beginning year",loopyr
  98. yr = loopyr
  99. ! Leap year?
  100. isleapyear = .false.
  101. if (mod(yr,4) .eq. 0) isleapyear = .true.
  102. if (mod(yr,100) .eq. 0) isleapyear = .false.
  103. if (mod(yr,400) .eq. 0) isleapyear = .true.
  104. if (isleapyear .eq. .true.) then
  105. t_max = t_max_leap
  106. else
  107. t_max = t_max_year
  108. endif
  109. ! Day/6-hr loop for each year
  110. write (*,'(A,I5)') "*II* ccycle_coupling: t_max =",t_max
  111. do t_step=0,t_max-1
  112. write (*,*) "*III* ccycle_coupling: Beginning dayloop ",t_step
  113. t = t_step_full*86400
  114. ! -----------------------------------------------------------------------------------
  115. ! *** PUT variables
  116. ! -----------------------------------------------------------------------------------
  117. write (*,'(A,I6,A,I12)') "*II* ccycle_couplingPUT : Time step t = ",t_step," - time t=",t
  118. write (*,*) "*II* ccycle_coupling: co2_ppm = ",co2_ppm
  119. if ( coupled_to_lpjguess ) then
  120. f_lco2_data(:,:) = co2_ppm
  121. write (*,'(A,I3)') "*II* ccycle_coupling: calling oasis_put with f_lco2_id =",f_lco2_id
  122. call oasis_put(f_lco2_id,t,f_lco2_data,ierror)
  123. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_put returned ierror =",ierror
  124. endif
  125. if ( coupled_to_pisces ) then
  126. write (*,'(A,I3)') "*II* ccycle_coupling: calling oasis_put with f_oco2_id =",f_oco2_id
  127. f_oco2_data(:,:) = co2_ppm
  128. call oasis_put(f_oco2_id,t,f_oco2_data,ierror)
  129. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_put returned ierror =",ierror
  130. endif
  131. ! -----------------------------------------------------------------------------------
  132. ! *** GET variables
  133. ! -----------------------------------------------------------------------------------
  134. write (*,'(A,I6,A,I12)') "*II* ccycle_couplingGET : Time step t = ",t_step," - time t=",t
  135. if ( coupled_to_lpjguess ) then
  136. write (*,'(A,I3)') "*II* ccycle_coupling: calling oasis_get with f_cnat_id =",f_cnat_id
  137. call oasis_get(f_cnat_id,t,f_cnat_data,ierror)
  138. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_get returned ierror =",ierror
  139. write (*,'(A,I3)') "*II* ccycle_coupling: calling oasis_get with f_cant_id =",f_cant_id
  140. call oasis_get(f_cant_id,t,f_cant_data,ierror)
  141. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_get returned ierror =",ierror
  142. write (*,'(A,I3)') "*II* ccycle_coupling: calling oasis_get with f_cnpp_id =",f_cnpp_id
  143. call oasis_get(f_cnpp_id,t,f_cnpp_data,ierror)
  144. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_get returned ierror =",ierror
  145. write(*,*)"*II* ccycle_coupling: CNAT obtained from OASIS for test gridcell (g=8000) is ",f_cnat_data(8000,1)
  146. write(*,*)"*II* ccycle_coupling: CANT obtained from OASIS for test gridcell (g=8000) is ",f_cant_data(8000,1)
  147. write(*,*)"*II* ccycle_coupling: CNPP obtained from OASIS for test gridcell (g=8000) is ",f_cnpp_data(8000,1)
  148. endif
  149. if ( coupled_to_pisces ) then
  150. write (*,'(A,I3)') "*II* ccycle_coupling: calling oasis_get with f_ocecflx_id =",f_ocecflx_id
  151. call oasis_get(f_ocecflx_id,t,f_ocecflx_data,ierror)
  152. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_get returned ierror =",ierror
  153. write(*,*)"*II* ccycle_coupling: OCECFLX obtained from OASIS for test gridcell (g=8000) is ",f_ocecflx_data(8000,1)
  154. endif
  155. write (*,*) "*III* ccycle_coupling: Finished dayloop!",t_step, t_max
  156. ! Increase the full simulation counter
  157. t_step_full = t_step_full + 1
  158. ! End of dayloop
  159. enddo
  160. write (*,*) "*II* ccycle_coupling: End of year!",loopyr
  161. ! End of year loop
  162. enddo
  163. write (*,'(A)') "*II* ccycle_coupling: Finished time loop!"
  164. ! End of repetition loop
  165. ! enddo
  166. write (*,'(A)') "*II* ccycle_coupling: oasis_terminate..."
  167. call oasis_terminate(ierror)
  168. write (*,'(A,I3)') "*II* ccycle_coupling: oasis_terminate returned ierror =",ierror
  169. end program CC_COUP
  170. subroutine ERROR(msg,status)
  171. character(len=*),intent(in) :: msg
  172. integer,intent(in) :: status
  173. write (*,'("*EE*",A)') msg
  174. call EXIT(status)
  175. end subroutine ERROR