iom_ioipsl.F90 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. MODULE iom_ioipsl
  2. !!=====================================================================
  3. !! *** MODULE iom_ioipsl ***
  4. !! Input/Output manager : Library to read input files with IOIPSL (only fliocom module)
  5. !!====================================================================
  6. !! History : 9.0 ! 05 12 (J. Belier) Original code
  7. !! 9.0 ! 06 02 (S. Masson) Adaptation to NEMO
  8. !! " ! 07 07 (D. Storkey) Changes to iom_ioipsl_gettime
  9. !!--------------------------------------------------------------------
  10. !!gm caution add !DIR nec: improved performance to be checked as well as no result changes
  11. !!--------------------------------------------------------------------
  12. !! iom_open : open a file read only
  13. !! iom_close : close a file or all files opened by iom
  14. !! iom_get : read a field (interfaced to several routines)
  15. !! iom_gettime : read the time axis kvid in the file
  16. !! iom_varid : get the id of a variable in a file
  17. !! iom_rstput : write a field in a restart file (interfaced to several routines)
  18. !!--------------------------------------------------------------------
  19. USE dom_oce ! ocean space and time domain
  20. USE iom_def ! iom variables definitions
  21. USE ioipsl ! IOIPSL library
  22. USE in_out_manager ! I/O manager
  23. USE lib_mpp ! MPP library
  24. IMPLICIT NONE
  25. PRIVATE
  26. PUBLIC iom_ioipsl_open, iom_ioipsl_close, iom_ioipsl_varid, iom_ioipsl_get, iom_ioipsl_gettime, iom_ioipsl_rstput
  27. INTERFACE iom_ioipsl_get
  28. MODULE PROCEDURE iom_ioipsl_g0d, iom_ioipsl_g123d
  29. END INTERFACE
  30. INTERFACE iom_ioipsl_rstput
  31. MODULE PROCEDURE iom_ioipsl_rp0123d
  32. END INTERFACE
  33. !!----------------------------------------------------------------------
  34. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  35. !! $Id: iom_ioipsl.F90 4292 2013-11-20 16:28:04Z cetlod $
  36. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  37. !!----------------------------------------------------------------------
  38. CONTAINS
  39. SUBROUTINE iom_ioipsl_open( cdname, kiomid, ldwrt, ldok, kdompar )
  40. !!---------------------------------------------------------------------
  41. !! *** SUBROUTINE iom_open ***
  42. !!
  43. !! ** Purpose : open an input file with IOIPSL (only fliocom module)
  44. !!---------------------------------------------------------------------
  45. CHARACTER(len=*) , INTENT(inout) :: cdname ! File name
  46. INTEGER , INTENT( out) :: kiomid ! ioipsl identifier of the opened file
  47. LOGICAL , INTENT(in ) :: ldwrt ! read or write the file?
  48. LOGICAL , INTENT(in ) :: ldok ! check the existence
  49. INTEGER, DIMENSION(2,5), INTENT(in ), OPTIONAL :: kdompar ! domain parameters:
  50. CHARACTER(LEN=100) :: clinfo ! info character
  51. CHARACTER(LEN=10 ) :: clstatus ! status of opened file (REPLACE or NEW)
  52. INTEGER :: iln ! lengths of character
  53. INTEGER :: istop ! temporary storage of nstop
  54. INTEGER :: ifliodom ! model domain identifier (see flio_dom_set)
  55. INTEGER :: ioipslid ! ioipsl identifier of the opened file
  56. INTEGER :: jl ! loop variable
  57. LOGICAL :: llclobber ! local definition of ln_clobber
  58. !---------------------------------------------------------------------
  59. clinfo = ' iom_ioipsl_open ~~~ '
  60. istop = nstop
  61. !
  62. llclobber = ldwrt .AND. ln_clobber
  63. IF( ldok .AND. .NOT. llclobber ) THEN ! Open existing file...
  64. ! ! =============
  65. IF( ldwrt ) THEN ! ... in write mode
  66. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in WRITE mode'
  67. CALL flioopfd( TRIM(cdname), ioipslid, "WRITE" )
  68. ELSE ! ... in read mode
  69. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' open existing file: '//TRIM(cdname)//' in READ mode'
  70. CALL flioopfd( TRIM(cdname), ioipslid )
  71. ENDIF
  72. ELSE ! the file does not exist
  73. ! ! =============
  74. iln = INDEX( cdname, '.nc' )
  75. IF( ldwrt ) THEN ! the file should be open in write mode so we create it...
  76. IF( llclobber ) THEN ; clstatus = 'REPLACE 64'
  77. ELSE ; clstatus = 'NEW 64'
  78. ENDIF
  79. IF( jpnij > 1 ) THEN
  80. ! define the domain position regarding to the global domain (mainly useful in mpp)
  81. CALL flio_dom_set( jpnij, narea-1, (/1, 2/), (/jpiglo, jpjglo/) &
  82. & , kdompar(:,1), kdompar(:,2), kdompar(:,3), kdompar(:,4), kdompar(:,5) &
  83. & , 'BOX', ifliodom )
  84. ! Note that fliocrfd may change the value of cdname (add the cpu number...)
  85. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname(1:iln-1)//'... in WRITE mode'
  86. CALL fliocrfd( cdname, (/'x' , 'y' , 'z', 't'/) &
  87. & , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, ifliodom, mode = clstatus )
  88. ELSE ! the file should be open for read mode so it must exist...
  89. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' create new file: '//cdname//' in WRITE mode'
  90. CALL fliocrfd( cdname, (/'x' , 'y' , 'z', 't'/) &
  91. & , (/kdompar(1,1), kdompar(2,1), jpk, -1 /), ioipslid, mode = clstatus )
  92. ENDIF
  93. ELSE ! the file should be open for read mode so it must exist...
  94. CALL ctl_stop( TRIM(clinfo), ' should be impossible case...' )
  95. ENDIF
  96. ENDIF
  97. ! start to fill file informations
  98. ! =============
  99. IF( istop == nstop ) THEN ! no error within this routine
  100. !does not work with some compilers kiomid = MINLOC(iom_file(:)%nfid, dim = 1)
  101. kiomid = 0
  102. DO jl = jpmax_files, 1, -1
  103. IF( iom_file(jl)%nfid == 0 ) kiomid = jl
  104. ENDDO
  105. iom_file(kiomid)%name = TRIM(cdname)
  106. iom_file(kiomid)%nfid = ioipslid
  107. iom_file(kiomid)%iolib = jpioipsl
  108. iom_file(kiomid)%nvars = 0
  109. iom_file(kiomid)%irec = -1 ! useless for NetCDF files
  110. CALL flioinqf( ioipslid, id_uld = iom_file(kiomid)%iduld )
  111. IF(lwp) WRITE(numout,*) ' ---> '//TRIM(cdname)//' OK'
  112. ELSE
  113. kiomid = 0 ! return error flag
  114. ENDIF
  115. !
  116. END SUBROUTINE iom_ioipsl_open
  117. SUBROUTINE iom_ioipsl_close( kiomid )
  118. !!--------------------------------------------------------------------
  119. !! *** SUBROUTINE iom_ioipsl_close ***
  120. !!
  121. !! ** Purpose : close an input file with IOIPSL (only fliocom module)
  122. !!--------------------------------------------------------------------
  123. INTEGER, INTENT(in) :: kiomid ! iom identifier of the file to be closed
  124. !---------------------------------------------------------------------
  125. !
  126. CALL flioclo( iom_file(kiomid)%nfid )
  127. !
  128. END SUBROUTINE iom_ioipsl_close
  129. FUNCTION iom_ioipsl_varid ( kiomid, cdvar, kiv, kdimsz )
  130. !!-----------------------------------------------------------------------
  131. !! *** FUNCTION iom_varid ***
  132. !!
  133. !! ** Purpose : get the id of a variable in a file with IOIPSL (only fliocom module)
  134. !!-----------------------------------------------------------------------
  135. INTEGER , INTENT(in ) :: kiomid ! file Identifier
  136. CHARACTER(len=*) , INTENT(in ) :: cdvar ! name of the variable
  137. INTEGER , INTENT(in ) :: kiv !
  138. INTEGER, DIMENSION(:), INTENT( out), OPTIONAL :: kdimsz ! size of the dimensions
  139. !
  140. INTEGER :: iom_ioipsl_varid ! iom variable Id
  141. INTEGER :: ioipslid ! ioipsl file identifier
  142. INTEGER :: ji ! dummy loop index
  143. INTEGER :: i_nvd ! number of dimension of the variable
  144. INTEGER, DIMENSION(jpmax_dims) :: idimid ! dimension ids of the variable
  145. LOGICAL :: ll_fnd ! found test
  146. CHARACTER(LEN=100) :: clinfo ! info character
  147. !!-----------------------------------------------------------------------
  148. clinfo = 'iom_ioipsl_varid, file: '//trim(iom_file(kiomid)%name)//', var: '//trim(cdvar)
  149. iom_ioipsl_varid = 0 ! default definition
  150. IF( PRESENT(kdimsz) ) kdimsz(:) = 0 ! default definition
  151. ioipslid = iom_file(kiomid)%nfid ! get back ioipsl file identifier
  152. CALL flioinqv( ioipslid, cdvar, ll_fnd, nb_dims = i_nvd ) ! does the variable exist in the file
  153. IF( ll_fnd ) THEN
  154. IF( i_nvd <= jpmax_dims ) THEN
  155. iom_ioipsl_varid = kiv
  156. iom_file(kiomid)%nvars = kiv
  157. iom_file(kiomid)%nvid(kiv) = -1 ! variable id is not available in ioipsl
  158. iom_file(kiomid)%cn_var(kiv) = TRIM(cdvar)
  159. iom_file(kiomid)%ndims(kiv) = i_nvd
  160. iom_file(kiomid)%dimsz(:,kiv) = 0 ! reset dimsz in case previously used
  161. CALL flioinqv( ioipslid, cdvar, ll_fnd, &
  162. & len_dims = iom_file(kiomid)%dimsz(1:i_nvd,kiv), & ! dimensions size
  163. & id_dims = idimid(1:i_nvd) ) ! dimensions ids
  164. iom_file(kiomid)%luld(kiv) = .FALSE. ! default value
  165. DO ji = 1, i_nvd ! find the unlimited dimension
  166. IF( idimid(ji) == iom_file(kiomid)%iduld ) iom_file(kiomid)%luld(kiv) = .TRUE.
  167. END DO
  168. !---------- Deal with scale_factor and add_offset
  169. CALL flioinqa( ioipslid, cdvar, 'scale_factor', ll_fnd )
  170. IF( ll_fnd) THEN
  171. CALL fliogeta( ioipslid, cdvar, 'scale_factor', iom_file(kiomid)%scf(kiv) )
  172. ELSE
  173. iom_file(kiomid)%scf(kiv) = 1.
  174. END IF
  175. CALL flioinqa( ioipslid, cdvar, 'add_offset', ll_fnd )
  176. IF( ll_fnd ) THEN
  177. CALL fliogeta( ioipslid, cdvar, 'add_offset', iom_file(kiomid)%ofs(kiv) )
  178. ELSE
  179. iom_file(kiomid)%ofs(kiv) = 0.
  180. END IF
  181. ! return the simension size
  182. IF( PRESENT(kdimsz) ) THEN
  183. IF( i_nvd == SIZE(kdimsz) ) THEN
  184. kdimsz(:) = iom_file(kiomid)%dimsz(1:i_nvd,kiv)
  185. ELSE
  186. WRITE(ctmp1,*) i_nvd, SIZE(kdimsz)
  187. CALL ctl_stop( TRIM(clinfo), 'error in kdimsz size'//TRIM(ctmp1) )
  188. ENDIF
  189. ENDIF
  190. ELSE
  191. CALL ctl_stop( TRIM(clinfo), 'Too many dimensions in the file '//iom_file(kiomid)%name, &
  192. & 'increase the parameter jpmax_vars')
  193. ENDIF
  194. ELSE
  195. iom_ioipsl_varid = -1 ! variable not found, return error code: -1
  196. ENDIF
  197. !
  198. END FUNCTION iom_ioipsl_varid
  199. SUBROUTINE iom_ioipsl_g0d( kiomid, kvid, pvar, kstart )
  200. !!-----------------------------------------------------------------------
  201. !! *** ROUTINE iom_ioipsl_g0d ***
  202. !!
  203. !! ** Purpose : read a scalar with IOIPSL (only fliocom module)
  204. !!-----------------------------------------------------------------------
  205. INTEGER , INTENT(in ) :: kiomid ! Identifier of the file
  206. INTEGER , INTENT(in ) :: kvid ! variable id
  207. REAL(wp), INTENT( out) :: pvar ! read field
  208. INTEGER , DIMENSION(1), INTENT(in ), OPTIONAL :: kstart ! start position of the reading in each axis
  209. !
  210. CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), pvar, kstart )
  211. !
  212. END SUBROUTINE iom_ioipsl_g0d
  213. SUBROUTINE iom_ioipsl_g123d( kiomid, kvid, knbdim, kstart, kcount, kx1, kx2, ky1, ky2, &
  214. & pv_r1d, pv_r2d, pv_r3d)
  215. !!-----------------------------------------------------------------------
  216. !! *** ROUTINE iom_ioipsl_g123d ***
  217. !!
  218. !! ** Purpose : read a 1D/2D/3D variable with IOIPSL (only fliocom module)
  219. !!
  220. !! ** Method : read ONE record at each CALL
  221. !!-----------------------------------------------------------------------
  222. INTEGER , INTENT(in ) :: kiomid ! iom identifier of the file
  223. INTEGER , INTENT(in ) :: kvid ! Name of the variable
  224. INTEGER , INTENT(in ) :: knbdim ! number of dimensions of the variable
  225. INTEGER , DIMENSION(:) , INTENT(in ) :: kstart ! start position of the reading in each axis
  226. INTEGER , DIMENSION(:) , INTENT(in ) :: kcount ! number of points to be read in each axis
  227. INTEGER , INTENT(in ) :: kx1, kx2, ky1, ky2 ! subdomain indexes
  228. REAL(wp), DIMENSION(:) , INTENT( out), OPTIONAL :: pv_r1d ! read field (1D case)
  229. REAL(wp), DIMENSION(:,:) , INTENT( out), OPTIONAL :: pv_r2d ! read field (2D case)
  230. REAL(wp), DIMENSION(:,:,:) , INTENT( out), OPTIONAL :: pv_r3d ! read field (3D case)
  231. !
  232. INTEGER :: ioipslid ! ioipsl file identifier
  233. CHARACTER(LEN=100) :: clvn ! variable name
  234. !---------------------------------------------------------------------
  235. clvn = TRIM(iom_file(kiomid)%cn_var(kvid)) ! get back variable name
  236. ioipslid = iom_file(kiomid)%nfid ! get back IPIPSL file id
  237. !
  238. IF( PRESENT(pv_r1d) ) THEN
  239. CALL fliogetv( ioipslid, clvn, pv_r1d(: ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
  240. ELSEIF( PRESENT(pv_r2d) ) THEN
  241. CALL fliogetv( ioipslid, clvn, pv_r2d(kx1:kx2,ky1:ky2 ), start = kstart(1:knbdim), count = kcount(1:knbdim) )
  242. ELSEIF( PRESENT(pv_r3d) ) THEN
  243. CALL fliogetv( ioipslid, clvn, pv_r3d(kx1:kx2,ky1:ky2,:), start = kstart(1:knbdim), count = kcount(1:knbdim) )
  244. ENDIF
  245. !
  246. !
  247. END SUBROUTINE iom_ioipsl_g123d
  248. SUBROUTINE iom_ioipsl_gettime( kiomid, kvid, ptime, cdunits, cdcalendar )
  249. !!--------------------------------------------------------------------
  250. !! *** SUBROUTINE iom_gettime ***
  251. !!
  252. !! ** Purpose : read the time axis kvid in the file with IOIPSL (only fliocom module)
  253. !!--------------------------------------------------------------------
  254. INTEGER , INTENT(in ) :: kiomid ! file Identifier
  255. INTEGER , INTENT(in ) :: kvid ! variable id
  256. REAL(wp), DIMENSION(:) , INTENT( out) :: ptime ! the time axis
  257. CHARACTER(len=*), OPTIONAL, INTENT( out) :: cdunits ! units attribute
  258. CHARACTER(len=*), OPTIONAL, INTENT( out) :: cdcalendar ! calendar attribute
  259. !---------------------------------------------------------------------
  260. !
  261. CALL fliogetv( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), ptime(:), &
  262. & start=(/ 1 /), count=(/ iom_file(kiomid)%dimsz(1, kvid) /) )
  263. IF ( PRESENT(cdunits) ) THEN
  264. CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "units", cdunits )
  265. ENDIF
  266. IF ( PRESENT(cdcalendar) ) THEN
  267. CALL fliogeta( iom_file(kiomid)%nfid, TRIM(iom_file(kiomid)%cn_var(kvid)), "calendar", cdcalendar )
  268. ENDIF
  269. !
  270. END SUBROUTINE iom_ioipsl_gettime
  271. SUBROUTINE iom_ioipsl_rp0123d( kt, kwrite, kiomid, cdvar , kvid , ktype, &
  272. & pv_r0d, pv_r1d, pv_r2d, pv_r3d )
  273. !!--------------------------------------------------------------------
  274. !! *** SUBROUTINE iom_ioipsl_rstput ***
  275. !!
  276. !! ** Purpose : read the time axis cdvar in the file
  277. !!--------------------------------------------------------------------
  278. INTEGER , INTENT(in) :: kt ! ocean time-step
  279. INTEGER , INTENT(in) :: kwrite ! writing time-step
  280. INTEGER , INTENT(in) :: kiomid ! Identifier of the file
  281. CHARACTER(len=*) , INTENT(in) :: cdvar ! variable name
  282. INTEGER , INTENT(in) :: kvid ! variable id
  283. INTEGER , INTENT(in), OPTIONAL :: ktype ! variable type (default R8)
  284. REAL(wp) , INTENT(in), OPTIONAL :: pv_r0d ! written Od field
  285. REAL(wp), DIMENSION( :), INTENT(in), OPTIONAL :: pv_r1d ! written 1d field
  286. REAL(wp), DIMENSION(:, : ), INTENT(in), OPTIONAL :: pv_r2d ! written 2d field
  287. REAL(wp), DIMENSION(:, :, :), INTENT(in), OPTIONAL :: pv_r3d ! written 3d field
  288. !
  289. INTEGER :: idims ! number of dimension
  290. INTEGER :: idvar ! variable id
  291. INTEGER :: itype ! variable type
  292. INTEGER :: ix1, ix2, iy1, iy2 ! subdomain indexes
  293. INTEGER, DIMENSION(4) :: idimsz ! dimensions size
  294. INTEGER, DIMENSION(4) :: idimid ! dimensions id
  295. CHARACTER(LEN=100) :: clinfo ! info character
  296. INTEGER :: ioipslid ! ioipsl file identifier
  297. !---------------------------------------------------------------------
  298. !
  299. clinfo = ' iom_ioipsl_rp0123d, file: '//TRIM(iom_file(kiomid)%name)//', var: '//TRIM(cdvar)
  300. ioipslid = iom_file(kiomid)%nfid
  301. !
  302. ! define dimension variables if it is not already done
  303. ! ==========================
  304. IF( iom_file(kiomid)%nvars == 0 ) THEN
  305. ! define the dimension variables if it is not already done
  306. CALL fliodefv( ioipslid,'nav_lon', (/1,2/), v_t=flio_r4 , axis='X', &
  307. & long_name="Longitude", units="degrees_east" )
  308. CALL fliodefv( ioipslid,'nav_lat', (/1,2/), v_t=flio_r4 , axis='Y', &
  309. & long_name="Latitude", units="degrees_north" )
  310. CALL fliodefv( ioipslid,'nav_lev', (/3/) , v_t=flio_i4 , axis='Z', &
  311. & long_name="Model levels",units="model_levels")
  312. CALL fliodefv( ioipslid,'time_counter', (/4/), v_t=flio_r4, axis='T', &
  313. & long_name="Time axis", units='seconds since 0001-01-01 00:00:00' )
  314. ! update informations structure related the dimension variable we just added...
  315. iom_file(kiomid)%nvars = 4
  316. iom_file(kiomid)%luld(1:4) = (/ .FALSE., .FALSE., .FALSE., .TRUE. /)
  317. iom_file(kiomid)%cn_var(1:3) = (/ 'nav_lon', 'nav_lat', 'nav_lev' /)
  318. iom_file(kiomid)%cn_var(4) = 'time_counter'
  319. iom_file(kiomid)%ndims(1:4) = (/ 2, 2, 1, 1 /)
  320. ! trick: defined to 0 to say that dimension variables are defined but not yet written
  321. iom_file(kiomid)%dimsz(1, 1) = 0
  322. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' define dimension variables done'
  323. ENDIF
  324. ! define the data if it is not already done
  325. ! ===============
  326. IF( kvid <= 0 ) THEN
  327. ! variable definition
  328. IF( PRESENT(pv_r0d) ) THEN ; idims = 0
  329. ELSEIF( PRESENT(pv_r1d) ) THEN ; idims = 2 ; idimid(1:idims) = (/ 3,4/)
  330. ELSEIF( PRESENT(pv_r2d) ) THEN ; idims = 3 ; idimid(1:idims) = (/1,2 ,4/)
  331. ELSEIF( PRESENT(pv_r3d) ) THEN ; idims = 4 ; idimid(1:idims) = (/1,2,3,4/)
  332. ENDIF
  333. IF( PRESENT(ktype) ) THEN ! variable external type
  334. SELECT CASE (ktype)
  335. CASE (jp_r8) ; itype = flio_r8
  336. CASE (jp_r4) ; itype = flio_r4
  337. CASE (jp_i4) ; itype = flio_i4
  338. CASE (jp_i2) ; itype = flio_i2
  339. CASE (jp_i1) ; itype = flio_i1 ! fliocom does not handle i1 type of variable
  340. CASE DEFAULT ; CALL ctl_stop( TRIM(clinfo)//' unknown variable type' )
  341. END SELECT
  342. ELSE
  343. itype = flio_r8
  344. ENDIF
  345. IF( PRESENT(pv_r0d) ) THEN ; CALL fliodefv (ioipslid, TRIM(cdvar) , v_t = itype)
  346. ELSE ; CALL fliodefv (ioipslid, TRIM(cdvar), idimid(1:idims), v_t = itype)
  347. ENDIF
  348. ! update informations structure related the new variable we want to add...
  349. idvar = iom_file(kiomid)%nvars + 1
  350. iom_file(kiomid)%nvars = idvar
  351. iom_file(kiomid)%cn_var(idvar) = TRIM(cdvar)
  352. iom_file(kiomid)%nvid(idvar) = -1 ! netcdf variable id is not available in ioipsl
  353. iom_file(kiomid)%scf(idvar) = 1.
  354. iom_file(kiomid)%ofs(idvar) = 0.
  355. iom_file(kiomid)%ndims(idvar) = idims
  356. IF( .NOT. PRESENT(pv_r0d) ) THEN
  357. iom_file(kiomid)%luld(idvar) = .TRUE.
  358. CALL flioinqf( ioipslid, ln_dim = idimsz )
  359. iom_file(kiomid)%dimsz(1:idims-1,idvar) = idimsz(idimid(1:idims-1))
  360. ELSE
  361. iom_file(kiomid)%luld(idvar) = .FALSE.
  362. ENDIF
  363. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' defined ok'
  364. ELSE
  365. idvar = kvid
  366. ENDIF
  367. ! time step kwrite : write the variable
  368. IF( kt == kwrite ) THEN
  369. ! on what kind of domain must the data be written?
  370. IF( PRESENT(pv_r2d) .OR. PRESENT(pv_r3d) ) THEN
  371. idimsz(1:2) = iom_file(kiomid)%dimsz(1:2,idvar)
  372. IF( idimsz(1) == (nlei - nldi + 1) .AND. idimsz(2) == (nlej - nldj + 1) ) THEN
  373. ix1 = nldi ; ix2 = nlei ; iy1 = nldj ; iy2 = nlej
  374. ELSEIF( idimsz(1) == nlci .AND. idimsz(2) == nlcj ) THEN
  375. ix1 = 1 ; ix2 = nlci ; iy1 = 1 ; iy2 = nlcj
  376. ELSEIF( idimsz(1) == jpi .AND. idimsz(2) == jpj ) THEN
  377. ix1 = 1 ; ix2 = jpi ; iy1 = 1 ; iy2 = jpj
  378. ELSE
  379. CALL ctl_stop( 'iom_ioipsl_rp0123d: should have been an impossible case...' )
  380. ENDIF
  381. ! write dimension variables if it is not already done
  382. ! =============
  383. ! trick: is defined to 0 => dimension variable are defined but not yet written
  384. IF( iom_file(kiomid)%dimsz(1, 1) == 0 ) THEN
  385. CALL flioputv( ioipslid, 'nav_lon' , glamt(ix1:ix2, iy1:iy2) )
  386. CALL flioputv( ioipslid, 'nav_lat' , gphit(ix1:ix2, iy1:iy2) )
  387. CALL flioputv( ioipslid, 'nav_lev' , gdept_1d )
  388. ! +++ WRONG VALUE: to be improved but not really useful...
  389. CALL flioputv( ioipslid, 'time_counter', kt )
  390. ! update the values of the variables dimensions size
  391. CALL flioinqf( ioipslid, ln_dim = idimsz )
  392. iom_file(kiomid)%dimsz(1:2, 1) = idimsz(1:2)
  393. iom_file(kiomid)%dimsz(1:2, 2) = idimsz(1:2)
  394. iom_file(kiomid)%dimsz(1, 3:4) = (/idimsz(3), 1/)
  395. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' write dimension variables done'
  396. ENDIF
  397. ENDIF
  398. ! write the data
  399. ! =============
  400. IF( PRESENT(pv_r0d) ) THEN ; CALL flioputv( ioipslid, cdvar, pv_r0d )
  401. ELSEIF( PRESENT(pv_r1d) ) THEN ; CALL flioputv( ioipslid, cdvar, pv_r1d( :) )
  402. ELSEIF( PRESENT(pv_r2d) ) THEN ; CALL flioputv( ioipslid, cdvar, pv_r2d(ix1:ix2, iy1:iy2 ) )
  403. ELSEIF( PRESENT(pv_r3d) ) THEN ; CALL flioputv( ioipslid, cdvar, pv_r3d(ix1:ix2, iy1:iy2, :) )
  404. ENDIF
  405. ! add 1 to the size of the temporal dimension (not really useful...)
  406. IF( iom_file(kiomid)%luld(idvar) ) iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) &
  407. & = iom_file(kiomid)%dimsz(iom_file(kiomid)%ndims(idvar), idvar) + 1
  408. IF(lwp) WRITE(numout,*) TRIM(clinfo)//' written ok'
  409. ENDIF
  410. !
  411. END SUBROUTINE iom_ioipsl_rp0123d
  412. !!======================================================================
  413. END MODULE iom_ioipsl