user_output_settings.F90 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. !###############################################################################
  2. !
  3. ! Put out information on model settings:
  4. ! o regions
  5. !
  6. !### macro's ###################################################################
  7. !
  8. #define TRACEBACK write (gol,'("in ",a," (",a,", line",i5,")")') rname, __FILE__, __LINE__; call goErr
  9. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  10. #define IF_ERROR_RETURN(action) if (status> 0) then; TRACEBACK; action; return; end if
  11. !
  12. #include "tm5.inc"
  13. !
  14. !###############################################################################
  15. module User_Output_Settings
  16. use GO, only : gol, goPr, goErr
  17. implicit none
  18. private
  19. public :: User_Output_Settings_Init
  20. public :: User_Output_Settings_Done
  21. ! --- const ------------------------------------
  22. character(len=*), parameter :: mname = 'User_Output_Settings'
  23. ! --- var ------------------------------------
  24. ! base path:
  25. character(len=1024) :: settings_output_dir
  26. contains
  27. ! ====================================================================
  28. subroutine User_Output_Settings_Init( rcF, status )
  29. use GO, only : TrcFile, ReadRc
  30. use GO, only : pathsep
  31. use MDF, only : MDF_Init, MDF_Done
  32. use global_data, only : outdir
  33. ! --- in/out ---------------------------------
  34. type(TrcFile), intent(in) :: rcF
  35. integer, intent(out) :: status
  36. ! --- const ----------------------------------
  37. character(len=*), parameter :: rname = mname//'/User_Output_Settings_Init'
  38. ! --- local ----------------------------------
  39. character(len=256) :: subdir
  40. ! --- begin ----------------------------------
  41. ! read output subdirectory from settings:
  42. call ReadRc( rcF, 'settings.output.subdir', subdir, status, default='' )
  43. IF_ERROR_RETURN(status=1)
  44. ! base path:
  45. write (settings_output_dir,'(3a)') trim(outdir), pathsep, trim(subdir)
  46. ! setup MDF interface to HDF/NetCDF :
  47. call MDF_Init( status )
  48. IF_NOTOK_RETURN(status=1)
  49. ! write file with region defintions:
  50. call User_Output_Settings_Regions( status )
  51. IF_NOTOK_RETURN(status=1)
  52. ! done with MDF interface:
  53. call MDF_Done( status )
  54. IF_NOTOK_RETURN(status=1)
  55. ! ok
  56. status = 0
  57. end subroutine User_Output_Settings_Init
  58. ! ***
  59. subroutine User_Output_Settings_Done( status )
  60. ! --- in/out ---------------------------------
  61. integer, intent(out) :: status
  62. ! --- const ----------------------------------
  63. character(len=*), parameter :: rname = mname//'/User_Output_Settings_Done'
  64. ! --- local ----------------------------------
  65. ! --- begin ----------------------------------
  66. ! nothing to be done ...
  67. ! ok
  68. status = 0
  69. end subroutine User_Output_Settings_Done
  70. ! ***
  71. subroutine User_Output_Settings_Regions( status )
  72. use GO , only : pathsep
  73. use MDF , only : MDF_Create, MDF_Close, MDF_EndDef
  74. use MDF , only : MDF_NETCDF, MDF_REPLACE, MDF_GLOBAL, MDF_CHAR, MDF_INT, MDF_FLOAT
  75. use MDF , only : MDF_Put_Att
  76. use MDF , only : MDF_Def_Dim
  77. use MDF , only : MDF_Def_Var, MDF_Put_Var
  78. use dims , only : nregions
  79. use dims , only : region_name
  80. use dims , only : xbeg, xend, im
  81. use dims , only : ybeg, yend, jm
  82. use dims , only : parent
  83. use Partools , only : isRoot
  84. use MeteoData , only : lli
  85. use RedgridZoom, only : nred, jred, clustsize
  86. ! --- in/out ---------------------------------
  87. integer, intent(out) :: status
  88. ! --- const ----------------------------------
  89. character(len=*), parameter :: rname = mname//'/User_Output_Settings_Regions'
  90. ! --- local ----------------------------------
  91. character(len=1024) :: fname
  92. integer :: hid
  93. integer :: dimid_region, dimid_len_region_name
  94. integer :: varid_region_name
  95. integer :: varid_xbeg, varid_xend, varid_nx, varid_dx
  96. integer :: varid_ybeg, varid_yend, varid_ny, varid_dy
  97. integer :: varid_parent
  98. integer :: dimid_lon, dimid_blon
  99. integer :: dimid_lat, dimid_blat
  100. integer :: varid_lon, varid_blon
  101. integer :: varid_lat, varid_blat
  102. integer :: varid_rg_clustsize
  103. integer :: region
  104. integer :: imr, jmr
  105. integer, allocatable :: rg_clustsize(:)
  106. integer :: ired
  107. ! --- begin ----------------------------------
  108. ! root only ...
  109. if ( isRoot ) then
  110. ! * overview file
  111. ! compose filename:
  112. write (fname,'(a,a,"regions.nc")') trim(settings_output_dir), pathsep
  113. ! new file:
  114. call MDF_Create( trim(fname), MDF_NETCDF, MDF_REPLACE, hid, status )
  115. IF_NOTOK_RETURN(status=1)
  116. ! define dimensions:
  117. call MDF_Def_Dim( hid, 'region', nregions, dimid_region, status )
  118. IF_NOTOK_RETURN(status=1)
  119. call MDF_Def_Dim( hid, 'len_region_name', len(region_name(1)), dimid_len_region_name, status )
  120. IF_NOTOK_RETURN(status=1)
  121. ! variables:
  122. call MDF_Def_Var( hid, 'region_name', MDF_CHAR, (/dimid_len_region_name,dimid_region/), varid_region_name, status )
  123. IF_NOTOK_RETURN(status=1)
  124. call MDF_Def_Var( hid, 'xbeg', MDF_FLOAT, (/dimid_region/), varid_xbeg, status )
  125. IF_NOTOK_RETURN(status=1)
  126. call MDF_Def_Var( hid, 'xend', MDF_FLOAT, (/dimid_region/), varid_xend, status )
  127. IF_NOTOK_RETURN(status=1)
  128. call MDF_Def_Var( hid, 'ybeg', MDF_FLOAT, (/dimid_region/), varid_ybeg, status )
  129. IF_NOTOK_RETURN(status=1)
  130. call MDF_Def_Var( hid, 'yend', MDF_FLOAT, (/dimid_region/), varid_yend, status )
  131. IF_NOTOK_RETURN(status=1)
  132. call MDF_Def_Var( hid, 'nx', MDF_INT, (/dimid_region/), varid_nx, status )
  133. IF_NOTOK_RETURN(status=1)
  134. call MDF_Def_Var( hid, 'ny', MDF_INT, (/dimid_region/), varid_ny, status )
  135. IF_NOTOK_RETURN(status=1)
  136. call MDF_Def_Var( hid, 'dx', MDF_FLOAT, (/dimid_region/), varid_dx, status )
  137. IF_NOTOK_RETURN(status=1)
  138. call MDF_Def_Var( hid, 'dy', MDF_FLOAT, (/dimid_region/), varid_dy, status )
  139. IF_NOTOK_RETURN(status=1)
  140. call MDF_Def_Var( hid, 'parent', MDF_INT, (/dimid_region/), varid_parent, status )
  141. IF_NOTOK_RETURN(status=1)
  142. ! finished definition:
  143. call MDF_EndDef( hid, status )
  144. IF_NOTOK_RETURN(status=1)
  145. ! fill:
  146. call MDF_Put_Var( hid, varid_region_name, region_name(1:nregions), status )
  147. IF_NOTOK_RETURN(status=1)
  148. call MDF_Put_Var( hid, varid_xbeg, xbeg(1:nregions), status )
  149. IF_NOTOK_RETURN(status=1)
  150. call MDF_Put_Var( hid, varid_xend, xend(1:nregions), status )
  151. IF_NOTOK_RETURN(status=1)
  152. call MDF_Put_Var( hid, varid_ybeg, ybeg(1:nregions), status )
  153. IF_NOTOK_RETURN(status=1)
  154. call MDF_Put_Var( hid, varid_yend, yend(1:nregions), status )
  155. IF_NOTOK_RETURN(status=1)
  156. call MDF_Put_Var( hid, varid_nx, im(1:nregions), status )
  157. IF_NOTOK_RETURN(status=1)
  158. call MDF_Put_Var( hid, varid_ny, jm(1:nregions), status )
  159. IF_NOTOK_RETURN(status=1)
  160. call MDF_Put_Var( hid, varid_dx, (xend(1:nregions)-xbeg(1:nregions))/float(im(1:nregions)), status )
  161. IF_NOTOK_RETURN(status=1)
  162. call MDF_Put_Var( hid, varid_dy, (yend(1:nregions)-ybeg(1:nregions))/float(jm(1:nregions)), status )
  163. IF_NOTOK_RETURN(status=1)
  164. call MDF_Put_Var( hid, varid_parent, parent(1:nregions), status )
  165. IF_NOTOK_RETURN(status=1)
  166. ! close file:
  167. call MDF_Close( hid, status )
  168. IF_NOTOK_RETURN(status=1)
  169. ! * region files
  170. ! loop over regions:
  171. do region = 1, nregions
  172. ! local dimensions:
  173. imr = im(region)
  174. jmr = jm(region)
  175. ! compose filename:
  176. write (fname,'(a,a,"region_",a,".nc")') trim(settings_output_dir), pathsep, trim(region_name(region))
  177. ! new file:
  178. call MDF_Create( trim(fname), MDF_NETCDF, MDF_REPLACE, hid, status )
  179. IF_NOTOK_RETURN(status=1)
  180. ! global attributes:
  181. call MDF_Put_Att( hid, MDF_GLOBAL, 'region_name', trim(region_name(region)), status )
  182. IF_NOTOK_RETURN(status=1)
  183. if ( parent(region) == 0 ) then
  184. call MDF_Put_Att( hid, MDF_GLOBAL, 'parent', 'globe', status )
  185. IF_NOTOK_RETURN(status=1)
  186. else
  187. call MDF_Put_Att( hid, MDF_GLOBAL, 'parent', trim(region_name(parent(region))), status )
  188. IF_NOTOK_RETURN(status=1)
  189. end if
  190. ! define dimensions:
  191. call MDF_Def_Dim( hid, 'lon' , imr , dimid_lon , status )
  192. IF_NOTOK_RETURN(status=1)
  193. call MDF_Def_Dim( hid, 'blon', imr+1, dimid_blon, status )
  194. IF_NOTOK_RETURN(status=1)
  195. call MDF_Def_Dim( hid, 'lat' , jmr , dimid_lat , status )
  196. IF_NOTOK_RETURN(status=1)
  197. call MDF_Def_Dim( hid, 'blat', jmr+1, dimid_blat, status )
  198. IF_NOTOK_RETURN(status=1)
  199. ! grid variables:
  200. call MDF_Def_Var( hid, 'lon' , MDF_FLOAT, (/dimid_lon /), varid_lon , status )
  201. IF_NOTOK_RETURN(status=1)
  202. call MDF_Def_Var( hid, 'blon', MDF_FLOAT, (/dimid_blon/), varid_blon, status )
  203. IF_NOTOK_RETURN(status=1)
  204. call MDF_Def_Var( hid, 'lat' , MDF_FLOAT, (/dimid_lat /), varid_lat , status )
  205. IF_NOTOK_RETURN(status=1)
  206. call MDF_Def_Var( hid, 'blat', MDF_FLOAT, (/dimid_blat/), varid_blat, status )
  207. IF_NOTOK_RETURN(status=1)
  208. ! reduced grid variables:
  209. call MDF_Def_Var( hid, 'rg_clustsize', MDF_INT, (/dimid_lat/), varid_rg_clustsize, status )
  210. IF_NOTOK_RETURN(status=1)
  211. ! finished definition:
  212. call MDF_EndDef( hid, status )
  213. IF_NOTOK_RETURN(status=1)
  214. ! write grid variables:
  215. call MDF_Put_Var( hid, varid_lon , lli(region)%lon_deg , status )
  216. IF_NOTOK_RETURN(status=1)
  217. call MDF_Put_Var( hid, varid_blon, lli(region)%blon_deg, status )
  218. IF_NOTOK_RETURN(status=1)
  219. call MDF_Put_Var( hid, varid_lat , lli(region)%lat_deg , status )
  220. IF_NOTOK_RETURN(status=1)
  221. call MDF_Put_Var( hid, varid_blat, lli(region)%blat_deg, status )
  222. IF_NOTOK_RETURN(status=1)
  223. ! write reduced grid clust size:
  224. allocate( rg_clustsize(jmr) )
  225. rg_clustsize = 1
  226. do ired = 1, nred(region)
  227. rg_clustsize(jred(ired,region)) = clustsize(ired,region)
  228. end do
  229. call MDF_Put_Var( hid, varid_rg_clustsize, rg_clustsize, status )
  230. IF_NOTOK_RETURN(status=1)
  231. deallocate( rg_clustsize )
  232. ! close file:
  233. call MDF_Close( hid, status )
  234. IF_NOTOK_RETURN(status=1)
  235. end do ! regions
  236. end if ! root only
  237. ! ok
  238. status = 0
  239. end subroutine User_Output_Settings_Regions
  240. end module User_Output_Settings