obs_read_prof.F90 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. MODULE obs_read_prof
  2. !!======================================================================
  3. !! *** MODULE obs_read_prof ***
  4. !! Observation diagnostics: Read the T and S profile observations
  5. !!======================================================================
  6. !!----------------------------------------------------------------------
  7. !! obs_rea_pro_dri : Driver for reading profile obs
  8. !!----------------------------------------------------------------------
  9. !! * Modules used
  10. USE par_kind ! Precision variables
  11. USE par_oce ! Ocean parameters
  12. USE in_out_manager ! I/O manager
  13. USE dom_oce ! Ocean space and time domain variables
  14. USE obs_mpp ! MPP support routines for observation diagnostics
  15. USE julian ! Julian date routines
  16. USE obs_utils ! Observation operator utility functions
  17. USE obs_prep ! Prepare observation arrays
  18. USE obs_grid ! Grid search
  19. USE obs_sort ! Sorting observation arrays
  20. USE obs_profiles_def ! Profile definitions
  21. USE obs_conv ! Various conversion routines
  22. USE obs_types ! Observation type definitions
  23. USE netcdf ! NetCDF library
  24. USE obs_oper ! Observation operators
  25. USE obs_prof_io ! Profile files I/O (non-FB files)
  26. USE lib_mpp ! For ctl_warn/stop
  27. IMPLICIT NONE
  28. !! * Routine accessibility
  29. PRIVATE
  30. PUBLIC obs_rea_pro_dri ! Read the profile observations
  31. !!----------------------------------------------------------------------
  32. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  33. !! $Id: obs_read_prof.F90 4990 2014-12-15 16:42:49Z timgraham $
  34. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  35. !!----------------------------------------------------------------------
  36. CONTAINS
  37. SUBROUTINE obs_rea_pro_dri( kformat, &
  38. & profdata, knumfiles, cfilenames, &
  39. & kvars, kextr, kstp, ddobsini, ddobsend, &
  40. & ldt3d, lds3d, ldignmis, ldsatt, ldavtimset, &
  41. & ldmod, kdailyavtypes )
  42. !!---------------------------------------------------------------------
  43. !!
  44. !! *** ROUTINE obs_rea_pro_dri ***
  45. !!
  46. !! ** Purpose : Read from file the profile observations
  47. !!
  48. !! ** Method : Depending on kformat either ENACT, CORIOLIS or
  49. !! feedback data files are read
  50. !!
  51. !! ** Action :
  52. !!
  53. !! References :
  54. !!
  55. !! History :
  56. !! ! : 2009-09 (K. Mogensen) : New merged version of old routines
  57. !!----------------------------------------------------------------------
  58. !! * Modules used
  59. !! * Arguments
  60. INTEGER :: kformat ! Format of input data
  61. ! ! 1: ENACT
  62. ! ! 2: Coriolis
  63. TYPE(obs_prof), INTENT(OUT) :: profdata ! Profile data to be read
  64. INTEGER, INTENT(IN) :: knumfiles ! Number of files to read in
  65. CHARACTER(LEN=128), INTENT(IN) :: &
  66. & cfilenames(knumfiles) ! File names to read in
  67. INTEGER, INTENT(IN) :: kvars ! Number of variables in profdata
  68. INTEGER, INTENT(IN) :: kextr ! Number of extra fields for each var in profdata
  69. INTEGER, INTENT(IN) :: kstp ! Ocean time-step index
  70. LOGICAL, INTENT(IN) :: ldt3d ! Observed variables switches
  71. LOGICAL, INTENT(IN) :: lds3d
  72. LOGICAL, INTENT(IN) :: ldignmis ! Ignore missing files
  73. LOGICAL, INTENT(IN) :: ldsatt ! Compute salinity at all temperature points
  74. LOGICAL, INTENT(IN) :: ldavtimset ! Correct time for daily averaged data
  75. LOGICAL, INTENT(IN) :: ldmod ! Initialize model from input data
  76. REAL(KIND=dp), INTENT(IN) :: ddobsini ! Obs. ini time in YYYYMMDD.HHMMSS
  77. REAL(KIND=dp), INTENT(IN) :: ddobsend ! Obs. end time in YYYYMMDD.HHMMSS
  78. INTEGER, DIMENSION(imaxavtypes), OPTIONAL :: &
  79. & kdailyavtypes
  80. !! * Local declarations
  81. CHARACTER(LEN=15), PARAMETER :: cpname='obs_rea_pro_dri'
  82. INTEGER :: jvar
  83. INTEGER :: ji
  84. INTEGER :: jj
  85. INTEGER :: jk
  86. INTEGER :: ij
  87. INTEGER :: iflag
  88. INTEGER :: inobf
  89. INTEGER :: i_file_id
  90. INTEGER :: inowin
  91. INTEGER :: iyea
  92. INTEGER :: imon
  93. INTEGER :: iday
  94. INTEGER :: ihou
  95. INTEGER :: imin
  96. INTEGER :: isec
  97. INTEGER, DIMENSION(knumfiles) :: &
  98. & irefdate
  99. INTEGER, DIMENSION(ntyp1770+1) :: &
  100. & itypt, &
  101. & ityptmpp, &
  102. & ityps, &
  103. & itypsmpp
  104. INTEGER :: it3dtmpp
  105. INTEGER :: is3dtmpp
  106. INTEGER :: ip3dtmpp
  107. INTEGER, DIMENSION(:), ALLOCATABLE :: &
  108. & iobsi, &
  109. & iobsj, &
  110. & iproc, &
  111. & iindx, &
  112. & ifileidx, &
  113. & iprofidx
  114. INTEGER :: itype
  115. INTEGER, DIMENSION(imaxavtypes) :: &
  116. & idailyavtypes
  117. REAL(wp), DIMENSION(:), ALLOCATABLE :: &
  118. & zphi, &
  119. & zlam
  120. real(wp), DIMENSION(:), ALLOCATABLE :: &
  121. & zdat
  122. LOGICAL :: llvalprof
  123. TYPE(obfbdata), POINTER, DIMENSION(:) :: &
  124. & inpfiles
  125. real(wp), DIMENSION(knumfiles) :: &
  126. & djulini, &
  127. & djulend
  128. INTEGER :: iprof
  129. INTEGER :: iproftot
  130. INTEGER :: it3dt0
  131. INTEGER :: is3dt0
  132. INTEGER :: it3dt
  133. INTEGER :: is3dt
  134. INTEGER :: ip3dt
  135. INTEGER :: ios
  136. INTEGER :: ioserrcount
  137. INTEGER, DIMENSION(kvars) :: &
  138. & iv3dt
  139. CHARACTER(len=8) :: cl_refdate
  140. ! Local initialization
  141. iprof = 0
  142. it3dt0 = 0
  143. is3dt0 = 0
  144. ip3dt = 0
  145. ! Daily average types
  146. IF ( PRESENT(kdailyavtypes) ) THEN
  147. idailyavtypes(:) = kdailyavtypes(:)
  148. ELSE
  149. idailyavtypes(:) = -1
  150. ENDIF
  151. !-----------------------------------------------------------------------
  152. ! Check data the model part is just with feedback data files
  153. !-----------------------------------------------------------------------
  154. IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
  155. CALL ctl_stop( 'Model can only be read from feedback data' )
  156. RETURN
  157. ENDIF
  158. !-----------------------------------------------------------------------
  159. ! Count the number of files needed and allocate the obfbdata type
  160. !-----------------------------------------------------------------------
  161. inobf = knumfiles
  162. ALLOCATE( inpfiles(inobf) )
  163. prof_files : DO jj = 1, inobf
  164. !---------------------------------------------------------------------
  165. ! Prints
  166. !---------------------------------------------------------------------
  167. IF(lwp) THEN
  168. WRITE(numout,*)
  169. WRITE(numout,*) ' obs_rea_pro_dri : Reading from file = ', &
  170. & TRIM( TRIM( cfilenames(jj) ) )
  171. WRITE(numout,*) ' ~~~~~~~~~~~~~~~'
  172. WRITE(numout,*)
  173. ENDIF
  174. !---------------------------------------------------------------------
  175. ! Initialization: Open file and get dimensions only
  176. !---------------------------------------------------------------------
  177. iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
  178. & i_file_id )
  179. IF ( iflag /= nf90_noerr ) THEN
  180. IF ( ldignmis ) THEN
  181. inpfiles(jj)%nobs = 0
  182. CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
  183. & ' not found' )
  184. ELSE
  185. CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
  186. & ' not found' )
  187. ENDIF
  188. ELSE
  189. !------------------------------------------------------------------
  190. ! Close the file since it is opened in read_proffile
  191. !------------------------------------------------------------------
  192. iflag = nf90_close( i_file_id )
  193. !------------------------------------------------------------------
  194. ! Read the profile file into inpfiles
  195. !------------------------------------------------------------------
  196. IF ( kformat == 0 ) THEN
  197. CALL init_obfbdata( inpfiles(jj) )
  198. IF(lwp) THEN
  199. WRITE(numout,*)
  200. WRITE(numout,*)'Reading from feedback file :', &
  201. & TRIM( cfilenames(jj) )
  202. ENDIF
  203. CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
  204. & ldgrid = .TRUE. )
  205. IF ( inpfiles(jj)%nvar < 2 ) THEN
  206. CALL ctl_stop( 'Feedback format error' )
  207. RETURN
  208. ENDIF
  209. IF ( TRIM(inpfiles(jj)%cname(1)) /= 'POTM' ) THEN
  210. CALL ctl_stop( 'Feedback format error' )
  211. RETURN
  212. ENDIF
  213. IF ( TRIM(inpfiles(jj)%cname(2)) /= 'PSAL' ) THEN
  214. CALL ctl_stop( 'Feedback format error' )
  215. RETURN
  216. ENDIF
  217. IF ( ldmod .AND. ( inpfiles(jj)%nadd == 0 ) ) THEN
  218. CALL ctl_stop( 'Model not in input data' )
  219. RETURN
  220. ENDIF
  221. ELSEIF ( kformat == 1 ) THEN
  222. CALL read_enactfile( TRIM( cfilenames(jj) ), inpfiles(jj), &
  223. & numout, lwp, .TRUE. )
  224. ELSEIF ( kformat == 2 ) THEN
  225. CALL read_coriofile( TRIM( cfilenames(jj) ), inpfiles(jj), &
  226. & numout, lwp, .TRUE. )
  227. ELSE
  228. CALL ctl_stop( 'File format unknown' )
  229. ENDIF
  230. !------------------------------------------------------------------
  231. ! Change longitude (-180,180)
  232. !------------------------------------------------------------------
  233. DO ji = 1, inpfiles(jj)%nobs
  234. IF ( inpfiles(jj)%plam(ji) < -180. ) &
  235. & inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
  236. IF ( inpfiles(jj)%plam(ji) > 180. ) &
  237. & inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
  238. END DO
  239. !------------------------------------------------------------------
  240. ! Calculate the date (change eventually)
  241. !------------------------------------------------------------------
  242. cl_refdate=inpfiles(jj)%cdjuldref(1:8)
  243. READ(cl_refdate,'(I8)') irefdate(jj)
  244. CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
  245. CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
  246. & krefdate = irefdate(jj) )
  247. CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
  248. CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
  249. & krefdate = irefdate(jj) )
  250. ioserrcount=0
  251. IF ( ldavtimset ) THEN
  252. DO ji = 1, inpfiles(jj)%nobs
  253. !
  254. ! for daily averaged data for example
  255. ! MRB data (itype==820) force the time
  256. ! to be the end of the day
  257. !
  258. READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 900 ) itype
  259. 900 IF ( ios /= 0 ) THEN
  260. itype = 0 ! Set type to zero if there is a problem in the string conversion
  261. ENDIF
  262. IF ( ANY (idailyavtypes == itype ) ) THEN
  263. inpfiles(jj)%ptim(ji) = &
  264. & INT(inpfiles(jj)%ptim(ji)) + 1
  265. ENDIF
  266. END DO
  267. ENDIF
  268. IF ( inpfiles(jj)%nobs > 0 ) THEN
  269. inpfiles(jj)%iproc = -1
  270. inpfiles(jj)%iobsi = -1
  271. inpfiles(jj)%iobsj = -1
  272. ENDIF
  273. inowin = 0
  274. DO ji = 1, inpfiles(jj)%nobs
  275. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  276. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  277. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  278. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  279. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  280. inowin = inowin + 1
  281. ENDIF
  282. END DO
  283. ALLOCATE( zlam(inowin) )
  284. ALLOCATE( zphi(inowin) )
  285. ALLOCATE( iobsi(inowin) )
  286. ALLOCATE( iobsj(inowin) )
  287. ALLOCATE( iproc(inowin) )
  288. inowin = 0
  289. DO ji = 1, inpfiles(jj)%nobs
  290. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  291. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  292. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  293. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  294. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  295. inowin = inowin + 1
  296. zlam(inowin) = inpfiles(jj)%plam(ji)
  297. zphi(inowin) = inpfiles(jj)%pphi(ji)
  298. ENDIF
  299. END DO
  300. CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
  301. inowin = 0
  302. DO ji = 1, inpfiles(jj)%nobs
  303. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  304. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  305. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  306. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  307. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  308. inowin = inowin + 1
  309. inpfiles(jj)%iproc(ji,1) = iproc(inowin)
  310. inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
  311. inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
  312. ENDIF
  313. END DO
  314. DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
  315. DO ji = 1, inpfiles(jj)%nobs
  316. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  317. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  318. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  319. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  320. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  321. IF ( nproc == 0 ) THEN
  322. IF ( inpfiles(jj)%iproc(ji,1) > nproc ) CYCLE
  323. ELSE
  324. IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
  325. ENDIF
  326. llvalprof = .FALSE.
  327. IF ( ldt3d ) THEN
  328. loop_t_count : DO ij = 1,inpfiles(jj)%nlev
  329. IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
  330. & CYCLE
  331. IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
  332. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
  333. it3dt0 = it3dt0 + 1
  334. ENDIF
  335. END DO loop_t_count
  336. ENDIF
  337. IF ( lds3d ) THEN
  338. loop_s_count : DO ij = 1,inpfiles(jj)%nlev
  339. IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
  340. & CYCLE
  341. IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
  342. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
  343. is3dt0 = is3dt0 + 1
  344. ENDIF
  345. END DO loop_s_count
  346. ENDIF
  347. loop_p_count : DO ij = 1,inpfiles(jj)%nlev
  348. IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
  349. & CYCLE
  350. IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
  351. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
  352. & ldt3d ) .OR. &
  353. & ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
  354. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
  355. & lds3d ) ) THEN
  356. ip3dt = ip3dt + 1
  357. llvalprof = .TRUE.
  358. ENDIF
  359. END DO loop_p_count
  360. IF ( llvalprof ) iprof = iprof + 1
  361. ENDIF
  362. END DO
  363. ENDIF
  364. END DO prof_files
  365. !-----------------------------------------------------------------------
  366. ! Get the time ordered indices of the input data
  367. !-----------------------------------------------------------------------
  368. !---------------------------------------------------------------------
  369. ! Loop over input data files to count total number of profiles
  370. !---------------------------------------------------------------------
  371. iproftot = 0
  372. DO jj = 1, inobf
  373. DO ji = 1, inpfiles(jj)%nobs
  374. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  375. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  376. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  377. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  378. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  379. iproftot = iproftot + 1
  380. ENDIF
  381. END DO
  382. END DO
  383. ALLOCATE( iindx(iproftot), ifileidx(iproftot), &
  384. & iprofidx(iproftot), zdat(iproftot) )
  385. jk = 0
  386. DO jj = 1, inobf
  387. DO ji = 1, inpfiles(jj)%nobs
  388. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  389. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  390. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  391. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  392. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  393. jk = jk + 1
  394. ifileidx(jk) = jj
  395. iprofidx(jk) = ji
  396. zdat(jk) = inpfiles(jj)%ptim(ji)
  397. ENDIF
  398. END DO
  399. END DO
  400. CALL sort_dp_indx( iproftot, &
  401. & zdat, &
  402. & iindx )
  403. iv3dt(:) = -1
  404. IF (ldsatt) THEN
  405. iv3dt(1) = ip3dt
  406. iv3dt(2) = ip3dt
  407. ELSE
  408. iv3dt(1) = it3dt0
  409. iv3dt(2) = is3dt0
  410. ENDIF
  411. CALL obs_prof_alloc( profdata, kvars, kextr, iprof, iv3dt, &
  412. & kstp, jpi, jpj, jpk )
  413. ! * Read obs/positions, QC, all variable and assign to profdata
  414. profdata%nprof = 0
  415. profdata%nvprot(:) = 0
  416. iprof = 0
  417. ip3dt = 0
  418. it3dt = 0
  419. is3dt = 0
  420. itypt (:) = 0
  421. ityptmpp(:) = 0
  422. ityps (:) = 0
  423. itypsmpp(:) = 0
  424. ioserrcount = 0
  425. DO jk = 1, iproftot
  426. jj = ifileidx(iindx(jk))
  427. ji = iprofidx(iindx(jk))
  428. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  429. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  430. & ( inpfiles(jj)%ivqc(ji,2) > 2 )) CYCLE
  431. IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
  432. & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
  433. IF ( nproc == 0 ) THEN
  434. IF ( inpfiles(jj)%iproc(ji,1) > nproc ) CYCLE
  435. ELSE
  436. IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
  437. ENDIF
  438. llvalprof = .FALSE.
  439. IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
  440. IF ( ( inpfiles(jj)%ivqc(ji,1) > 2 ) .AND. &
  441. & ( inpfiles(jj)%ivqc(ji,2) > 2 ) ) CYCLE
  442. loop_prof : DO ij = 1, inpfiles(jj)%nlev
  443. IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
  444. & CYCLE
  445. IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
  446. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
  447. llvalprof = .TRUE.
  448. EXIT loop_prof
  449. ENDIF
  450. IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
  451. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
  452. llvalprof = .TRUE.
  453. EXIT loop_prof
  454. ENDIF
  455. END DO loop_prof
  456. ! Set profile information
  457. IF ( llvalprof ) THEN
  458. iprof = iprof + 1
  459. CALL jul2greg( isec, &
  460. & imin, &
  461. & ihou, &
  462. & iday, &
  463. & imon, &
  464. & iyea, &
  465. & inpfiles(jj)%ptim(ji), &
  466. & irefdate(jj) )
  467. ! Profile time coordinates
  468. profdata%nyea(iprof) = iyea
  469. profdata%nmon(iprof) = imon
  470. profdata%nday(iprof) = iday
  471. profdata%nhou(iprof) = ihou
  472. profdata%nmin(iprof) = imin
  473. ! Profile space coordinates
  474. profdata%rlam(iprof) = inpfiles(jj)%plam(ji)
  475. profdata%rphi(iprof) = inpfiles(jj)%pphi(ji)
  476. ! Coordinate search parameters
  477. profdata%mi (iprof,:) = inpfiles(jj)%iobsi(ji,1)
  478. profdata%mj (iprof,:) = inpfiles(jj)%iobsj(ji,1)
  479. ! Profile WMO number
  480. profdata%cwmo(iprof) = inpfiles(jj)%cdwmo(ji)
  481. ! Instrument type
  482. READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
  483. 901 IF ( ios /= 0 ) THEN
  484. IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' )
  485. ioserrcount = ioserrcount + 1
  486. itype = 0
  487. ENDIF
  488. profdata%ntyp(iprof) = itype
  489. ! QC stuff
  490. profdata%nqc(iprof) = inpfiles(jj)%ioqc(ji)
  491. profdata%nqcf(:,iprof) = inpfiles(jj)%ioqcf(:,ji)
  492. profdata%ipqc(iprof) = inpfiles(jj)%ipqc(ji)
  493. profdata%ipqcf(:,iprof) = inpfiles(jj)%ipqcf(:,ji)
  494. profdata%itqc(iprof) = inpfiles(jj)%itqc(ji)
  495. profdata%itqcf(:,iprof) = inpfiles(jj)%itqcf(:,ji)
  496. profdata%ivqc(iprof,:) = inpfiles(jj)%ivqc(ji,:)
  497. profdata%ivqcf(:,iprof,:) = inpfiles(jj)%ivqcf(:,ji,:)
  498. ! Bookkeeping data to match profiles
  499. profdata%npidx(iprof) = iprof
  500. profdata%npfil(iprof) = iindx(jk)
  501. ! Observation QC flag (whole profile)
  502. profdata%nqc(iprof) = 0 !TODO
  503. loop_p : DO ij = 1, inpfiles(jj)%nlev
  504. IF ( inpfiles(jj)%pdep(ij,ji) >= 6000. ) &
  505. & CYCLE
  506. IF (ldsatt) THEN
  507. IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
  508. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
  509. & ldt3d ) .OR. &
  510. & ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
  511. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
  512. & lds3d ) ) THEN
  513. ip3dt = ip3dt + 1
  514. ELSE
  515. CYCLE
  516. ENDIF
  517. ENDIF
  518. IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
  519. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
  520. & ldt3d ) .OR. ldsatt ) THEN
  521. IF (ldsatt) THEN
  522. it3dt = ip3dt
  523. ELSE
  524. it3dt = it3dt + 1
  525. ENDIF
  526. ! Depth of T observation
  527. profdata%var(1)%vdep(it3dt) = &
  528. & inpfiles(jj)%pdep(ij,ji)
  529. ! Depth of T observation QC
  530. profdata%var(1)%idqc(it3dt) = &
  531. & inpfiles(jj)%idqc(ij,ji)
  532. ! Depth of T observation QC flags
  533. profdata%var(1)%idqcf(:,it3dt) = &
  534. & inpfiles(jj)%idqcf(:,ij,ji)
  535. ! Profile index
  536. profdata%var(1)%nvpidx(it3dt) = iprof
  537. ! Vertical index in original profile
  538. profdata%var(1)%nvlidx(it3dt) = ij
  539. ! Profile potential T value
  540. IF ( ( inpfiles(jj)%ivlqc(ij,ji,1) <= 2 ) .AND. &
  541. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
  542. profdata%var(1)%vobs(it3dt) = &
  543. & inpfiles(jj)%pob(ij,ji,1)
  544. IF ( ldmod ) THEN
  545. profdata%var(1)%vmod(it3dt) = &
  546. & inpfiles(jj)%padd(ij,ji,1,1)
  547. ENDIF
  548. ! Count number of profile T data as function of type
  549. itypt( profdata%ntyp(iprof) + 1 ) = &
  550. & itypt( profdata%ntyp(iprof) + 1 ) + 1
  551. ELSE
  552. profdata%var(1)%vobs(it3dt) = fbrmdi
  553. ENDIF
  554. ! Profile T qc
  555. profdata%var(1)%nvqc(it3dt) = &
  556. & inpfiles(jj)%ivlqc(ij,ji,1)
  557. ! Profile T qc flags
  558. profdata%var(1)%nvqcf(:,it3dt) = &
  559. & inpfiles(jj)%ivlqcf(:,ij,ji,1)
  560. ! Profile insitu T value
  561. profdata%var(1)%vext(it3dt,1) = &
  562. & inpfiles(jj)%pext(ij,ji,1)
  563. ENDIF
  564. IF ( ( ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
  565. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) .AND. &
  566. & lds3d ) .OR. ldsatt ) THEN
  567. IF (ldsatt) THEN
  568. is3dt = ip3dt
  569. ELSE
  570. is3dt = is3dt + 1
  571. ENDIF
  572. ! Depth of S observation
  573. profdata%var(2)%vdep(is3dt) = &
  574. & inpfiles(jj)%pdep(ij,ji)
  575. ! Depth of S observation QC
  576. profdata%var(2)%idqc(is3dt) = &
  577. & inpfiles(jj)%idqc(ij,ji)
  578. ! Depth of S observation QC flags
  579. profdata%var(2)%idqcf(:,is3dt) = &
  580. & inpfiles(jj)%idqcf(:,ij,ji)
  581. ! Profile index
  582. profdata%var(2)%nvpidx(is3dt) = iprof
  583. ! Vertical index in original profile
  584. profdata%var(2)%nvlidx(is3dt) = ij
  585. ! Profile S value
  586. IF ( ( inpfiles(jj)%ivlqc(ij,ji,2) <= 2 ) .AND. &
  587. & ( inpfiles(jj)%idqc(ij,ji) <= 2 ) ) THEN
  588. profdata%var(2)%vobs(is3dt) = &
  589. & inpfiles(jj)%pob(ij,ji,2)
  590. IF ( ldmod ) THEN
  591. profdata%var(2)%vmod(is3dt) = &
  592. & inpfiles(jj)%padd(ij,ji,1,2)
  593. ENDIF
  594. ! Count number of profile S data as function of type
  595. ityps( profdata%ntyp(iprof) + 1 ) = &
  596. & ityps( profdata%ntyp(iprof) + 1 ) + 1
  597. ELSE
  598. profdata%var(2)%vobs(is3dt) = fbrmdi
  599. ENDIF
  600. ! Profile S qc
  601. profdata%var(2)%nvqc(is3dt) = &
  602. & inpfiles(jj)%ivlqc(ij,ji,2)
  603. ! Profile S qc flags
  604. profdata%var(2)%nvqcf(:,is3dt) = &
  605. & inpfiles(jj)%ivlqcf(:,ij,ji,2)
  606. ENDIF
  607. END DO loop_p
  608. ENDIF
  609. ENDIF
  610. END DO
  611. !-----------------------------------------------------------------------
  612. ! Sum up over processors
  613. !-----------------------------------------------------------------------
  614. CALL obs_mpp_sum_integer ( it3dt0, it3dtmpp )
  615. CALL obs_mpp_sum_integer ( is3dt0, is3dtmpp )
  616. CALL obs_mpp_sum_integer ( ip3dt, ip3dtmpp )
  617. CALL obs_mpp_sum_integers( itypt, ityptmpp, ntyp1770 + 1 )
  618. CALL obs_mpp_sum_integers( ityps, itypsmpp, ntyp1770 + 1 )
  619. !-----------------------------------------------------------------------
  620. ! Output number of observations.
  621. !-----------------------------------------------------------------------
  622. IF(lwp) THEN
  623. WRITE(numout,*)
  624. WRITE(numout,'(1X,A)') 'Profile data'
  625. WRITE(numout,'(1X,A)') '------------'
  626. WRITE(numout,*)
  627. WRITE(numout,'(1X,A)') 'Profile T data'
  628. WRITE(numout,'(1X,A)') '--------------'
  629. DO ji = 0, ntyp1770
  630. IF ( ityptmpp(ji+1) > 0 ) THEN
  631. WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
  632. & cwmonam1770(ji)(1:52),' = ', &
  633. & ityptmpp(ji+1)
  634. ENDIF
  635. END DO
  636. WRITE(numout,'(1X,A)') &
  637. & '---------------------------------------------------------------'
  638. WRITE(numout,'(1X,A55,I8)') &
  639. & 'Total profile T data = ',&
  640. & it3dtmpp
  641. WRITE(numout,'(1X,A)') &
  642. & '---------------------------------------------------------------'
  643. WRITE(numout,*)
  644. WRITE(numout,'(1X,A)') 'Profile S data'
  645. WRITE(numout,'(1X,A)') '--------------'
  646. DO ji = 0, ntyp1770
  647. IF ( itypsmpp(ji+1) > 0 ) THEN
  648. WRITE(numout,'(1X,A3,1X,A48,A3,I8)') ctypshort(ji), &
  649. & cwmonam1770(ji)(1:52),' = ', &
  650. & itypsmpp(ji+1)
  651. ENDIF
  652. END DO
  653. WRITE(numout,'(1X,A)') &
  654. & '---------------------------------------------------------------'
  655. WRITE(numout,'(1X,A55,I8)') &
  656. & 'Total profile S data = ',&
  657. & is3dtmpp
  658. WRITE(numout,'(1X,A)') &
  659. & '---------------------------------------------------------------'
  660. WRITE(numout,*)
  661. ENDIF
  662. IF (ldsatt) THEN
  663. profdata%nvprot(1) = ip3dt
  664. profdata%nvprot(2) = ip3dt
  665. profdata%nvprotmpp(1) = ip3dtmpp
  666. profdata%nvprotmpp(2) = ip3dtmpp
  667. ELSE
  668. profdata%nvprot(1) = it3dt
  669. profdata%nvprot(2) = is3dt
  670. profdata%nvprotmpp(1) = it3dtmpp
  671. profdata%nvprotmpp(2) = is3dtmpp
  672. ENDIF
  673. profdata%nprof = iprof
  674. !-----------------------------------------------------------------------
  675. ! Model level search
  676. !-----------------------------------------------------------------------
  677. IF ( ldt3d ) THEN
  678. CALL obs_level_search( jpk, gdept_1d, &
  679. & profdata%nvprot(1), profdata%var(1)%vdep, &
  680. & profdata%var(1)%mvk )
  681. ENDIF
  682. IF ( lds3d ) THEN
  683. CALL obs_level_search( jpk, gdept_1d, &
  684. & profdata%nvprot(2), profdata%var(2)%vdep, &
  685. & profdata%var(2)%mvk )
  686. ENDIF
  687. !-----------------------------------------------------------------------
  688. ! Set model equivalent to 99999
  689. !-----------------------------------------------------------------------
  690. IF ( .NOT. ldmod ) THEN
  691. DO jvar = 1, kvars
  692. profdata%var(jvar)%vmod(:) = fbrmdi
  693. END DO
  694. ENDIF
  695. !-----------------------------------------------------------------------
  696. ! Deallocate temporary data
  697. !-----------------------------------------------------------------------
  698. DEALLOCATE( ifileidx, iprofidx, zdat )
  699. !-----------------------------------------------------------------------
  700. ! Deallocate input data
  701. !-----------------------------------------------------------------------
  702. DO jj = 1, inobf
  703. CALL dealloc_obfbdata( inpfiles(jj) )
  704. END DO
  705. DEALLOCATE( inpfiles )
  706. END SUBROUTINE obs_rea_pro_dri
  707. END MODULE obs_read_prof