obsprof_io.h90 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  1. !!----------------------------------------------------------------------
  2. !! NEMO/OPA 3.3 , NEMO Consortium (2010)
  3. !! $Id: obsprof_io.h90 2287 2010-10-18 07:53:52Z smasson $
  4. !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
  5. !!----------------------------------------------------------------------
  6. SUBROUTINE read_enactfile( cdfilename, inpfile, kunit, ldwp, ldgrid )
  7. !!---------------------------------------------------------------------
  8. !!
  9. !! ** ROUTINE read_enactfile **
  10. !!
  11. !! ** Purpose : Read from file the profile ENACT observations.
  12. !!
  13. !! ** Method : The data file is a NetCDF file.
  14. !!
  15. !! ** Action :
  16. !!
  17. !! History :
  18. !! ! 09-01 (K. Mogensen) Original based on old versions
  19. !!----------------------------------------------------------------------
  20. !! * Arguments
  21. CHARACTER(LEN=*) :: cdfilename ! Input filename
  22. TYPE(obfbdata) :: inpfile ! Output obfbdata structure
  23. INTEGER :: kunit ! Unit for output
  24. LOGICAL :: ldwp ! Print info
  25. LOGICAL :: ldgrid ! Save grid info in data structure
  26. !! * Local declarations
  27. INTEGER :: iobs ! Number of observations
  28. INTEGER :: ilev ! Number of levels
  29. INTEGER :: i_file_id
  30. INTEGER :: i_obs_id
  31. INTEGER :: i_lev_id
  32. INTEGER :: i_phi_id
  33. INTEGER :: i_lam_id
  34. INTEGER :: i_depth_id
  35. INTEGER :: i_var_id
  36. INTEGER :: i_pl_num_id
  37. INTEGER :: i_reference_date_time_id
  38. INTEGER :: i_format_version_id
  39. INTEGER :: i_juld_id
  40. INTEGER :: i_data_type_id
  41. INTEGER :: i_wmo_inst_type_id
  42. INTEGER :: i_qc_var_id
  43. INTEGER :: i_dc_ref_id
  44. INTEGER :: i_qc_flag_id
  45. CHARACTER(LEN=40) :: cl_fld_lam
  46. CHARACTER(LEN=40) :: cl_fld_phi
  47. CHARACTER(LEN=40) :: cl_fld_depth
  48. CHARACTER(LEN=40) :: cl_fld_var_tp
  49. CHARACTER(LEN=40) :: cl_fld_var_s
  50. CHARACTER(LEN=40) :: cl_fld_var_ti
  51. CHARACTER(LEN=40) :: cl_fld_var_juld_qc
  52. CHARACTER(LEN=40) :: cl_fld_var_pos_qc
  53. CHARACTER(LEN=40) :: cl_fld_var_depth_qc
  54. CHARACTER(LEN=40) :: cl_fld_var_qc_t
  55. CHARACTER(LEN=40) :: cl_fld_var_qc_s
  56. CHARACTER(LEN=40) :: cl_fld_var_prof_qc_t
  57. CHARACTER(LEN=40) :: cl_fld_var_prof_qc_s
  58. CHARACTER(LEN=40) :: cl_fld_reference_date_time
  59. CHARACTER(LEN=40) :: cl_fld_juld
  60. CHARACTER(LEN=40) :: cl_fld_data_type
  61. CHARACTER(LEN=40) :: cl_fld_pl_num
  62. CHARACTER(LEN=40) :: cl_fld_format_version
  63. CHARACTER(LEN=40) :: cl_fld_wmo_inst_type
  64. CHARACTER(LEN=40) :: cl_fld_qc_flags_profiles
  65. CHARACTER(LEN=40) :: cl_fld_qc_flags_levels
  66. CHARACTER(LEN=14), PARAMETER :: cl_name = 'read_enactfile'
  67. CHARACTER(LEN=16) :: cl_data_type = ''
  68. CHARACTER(LEN=4 ) :: cl_format_version = ''
  69. INTEGER, DIMENSION(1) :: istart1, icount1
  70. INTEGER, DIMENSION(2) :: istart2, icount2
  71. CHARACTER(len=imaxlev) :: clqc
  72. CHARACTER(len=1) :: cqc
  73. INTEGER :: ji, jk
  74. INTEGER, ALLOCATABLE, DIMENSION(:) :: iqc1
  75. INTEGER, ALLOCATABLE, DIMENSION(:,:) :: iqc2
  76. !-----------------------------------------------------------------------
  77. ! Initialization
  78. !-----------------------------------------------------------------------
  79. cl_fld_lam = 'LONGITUDE'
  80. cl_fld_phi = 'LATITUDE'
  81. cl_fld_depth = 'DEPH_CORRECTED'
  82. cl_fld_reference_date_time = 'REFERENCE_DATE_TIME'
  83. cl_fld_juld = 'JULD'
  84. cl_fld_data_type = 'DATA_TYPE'
  85. cl_fld_format_version = 'FORMAT_VERSION'
  86. cl_fld_wmo_inst_type = 'WMO_INST_TYPE'
  87. cl_fld_pl_num = 'PLATFORM_NUMBER'
  88. cl_fld_var_qc_t = 'POTM_CORRECTED_QC'
  89. cl_fld_var_prof_qc_t = 'PROFILE_POTM_QC'
  90. cl_fld_var_tp = 'POTM_CORRECTED'
  91. cl_fld_var_qc_s = 'PSAL_CORRECTED_QC'
  92. cl_fld_var_prof_qc_s = 'PROFILE_PSAL_QC'
  93. cl_fld_var_s = 'PSAL_CORRECTED'
  94. cl_fld_var_depth_qc = 'DEPH_CORRECTED_QC'
  95. cl_fld_var_juld_qc = 'JULD_QC'
  96. cl_fld_var_pos_qc = 'POSITION_QC'
  97. cl_fld_var_ti = 'TEMP'
  98. cl_fld_qc_flags_profiles = 'QC_FLAGS_PROFILES'
  99. cl_fld_qc_flags_levels = 'QC_FLAGS_LEVELS'
  100. icount1(1) = 1
  101. !-----------------------------------------------------------------------
  102. ! Open file
  103. !-----------------------------------------------------------------------
  104. CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
  105. & i_file_id ), cl_name, __LINE__ )
  106. !-----------------------------------------------------------------------
  107. ! Read the heading of the file
  108. !-----------------------------------------------------------------------
  109. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_data_type, &
  110. & i_data_type_id ), cl_name, __LINE__ )
  111. CALL chkerr( nf90_get_var ( i_file_id, i_data_type_id, &
  112. & cl_data_type ), cl_name, __LINE__ )
  113. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_format_version, &
  114. & i_format_version_id ), cl_name, __LINE__ )
  115. CALL chkerr( nf90_get_var ( i_file_id, i_format_version_id, &
  116. & cl_format_version ), cl_name, __LINE__ )
  117. CALL str_c_to_for( cl_data_type )
  118. CALL str_c_to_for( cl_format_version )
  119. IF(ldwp)WRITE(kunit,*)
  120. IF(ldwp)WRITE(kunit,*) ' read_enactfile :'
  121. IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
  122. IF(ldwp)WRITE(kunit,*) ' Data type = ', &
  123. & TRIM( ADJUSTL( cl_data_type ) )
  124. IF(ldwp)WRITE(kunit,*) ' Format version = ', &
  125. & TRIM( ADJUSTL( cl_format_version ) )
  126. IF ( ( ( INDEX( cl_data_type,"ENACT v1.0" ) == 1 ) .OR. &
  127. & ( INDEX( cl_data_type,"ENACT v1.4" ) == 1 ) .OR. &
  128. & ( INDEX( cl_data_type,"ENACT v1.5" ) == 1 ) .OR. &
  129. & ( INDEX( cl_data_type,"ENSEMBLES EN3 v1" ) == 1 ) ) &
  130. & .AND. &
  131. & ( INDEX( cl_format_version,"2.0" ) == 1 ) ) THEN
  132. IF(ldwp)WRITE(kunit,*)' Valid input file'
  133. ELSE
  134. CALL fatal_error( 'Invalid input file', __LINE__ )
  135. ENDIF
  136. !---------------------------------------------------------------------
  137. ! Read the number of observations and levels to allocate arrays
  138. !---------------------------------------------------------------------
  139. CALL chkerr( nf90_inq_dimid ( i_file_id, 'N_PROF', i_obs_id ), &
  140. & cl_name, __LINE__ )
  141. CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ), &
  142. & cl_name, __LINE__ )
  143. CALL chkerr( nf90_inq_dimid ( i_file_id, 'N_LEVELS', i_lev_id ), &
  144. & cl_name, __LINE__ )
  145. CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
  146. & cl_name, __LINE__ )
  147. IF(ldwp)WRITE(kunit,*) ' No. of data records = ', iobs
  148. IF(ldwp)WRITE(kunit,*) ' No. of levels = ', ilev
  149. IF(ldwp)WRITE(kunit,*)
  150. IF (ilev > imaxlev) THEN
  151. CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
  152. ENDIF
  153. !---------------------------------------------------------------------
  154. ! Allocate arrays
  155. !---------------------------------------------------------------------
  156. CALL init_obfbdata( inpfile )
  157. CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
  158. inpfile%cname(1) = 'POTM'
  159. inpfile%cname(2) = 'PSAL'
  160. inpfile%coblong(1) = 'Potential temperature'
  161. inpfile%coblong(2) = 'Practical salinity'
  162. inpfile%cobunit(1) = 'Degrees Celsius'
  163. inpfile%cobunit(2) = 'PSU'
  164. inpfile%cextname(1) = 'TEMP'
  165. inpfile%cextlong(1) = 'Insitu temperature'
  166. inpfile%cextunit(1) = 'Degrees Celsius'
  167. !---------------------------------------------------------------------
  168. ! Read the QC atributes
  169. !---------------------------------------------------------------------
  170. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ), &
  171. & cl_name, __LINE__ )
  172. istart2(1) = 1
  173. icount2(2) = 1
  174. icount2(1) = ilev
  175. DO ji = 1, iobs
  176. istart2(2) = ji
  177. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, clqc, &
  178. & start = istart2, count = icount2), &
  179. & cl_name, __LINE__ )
  180. DO jk = 1, ilev
  181. inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
  182. END DO
  183. END DO
  184. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ), &
  185. & cl_name, __LINE__ )
  186. DO ji = 1, iobs
  187. istart2(2) = ji
  188. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, clqc, &
  189. & start = istart2, count = icount2), &
  190. & cl_name, __LINE__ )
  191. DO jk = 1, ilev
  192. inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
  193. END DO
  194. END DO
  195. ! No depth QC in files
  196. DO ji = 1, iobs
  197. DO jk = 1, ilev
  198. inpfile%idqc(jk,ji) = 1
  199. inpfile%idqcf(:,jk,ji) = 0
  200. END DO
  201. END DO
  202. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ), &
  203. & cl_name, __LINE__ )
  204. DO ji = 1,iobs
  205. istart1(1) = ji
  206. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  207. & start = istart1, count = icount1), &
  208. & cl_name, __LINE__ )
  209. inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
  210. END DO
  211. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ), &
  212. & cl_name, __LINE__ )
  213. DO ji = 1,iobs
  214. istart1(1) = ji
  215. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  216. & start = istart1, count = icount1), &
  217. & cl_name, __LINE__ )
  218. inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
  219. END DO
  220. !! CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_juld_qc, i_qc_var_id ), &
  221. !! & cl_name, __LINE__ )
  222. !! !DO ji = 1,iobs
  223. !! istart1(1) = ji
  224. !! CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  225. !! & start = istart1, count = icount1), &
  226. !! & cl_name, __LINE__ )
  227. !! inpfile%itqc(ji) = IACHAR( cqc ) - IACHAR( '0' )
  228. !! inpfile%itqcf(:,ji) = 0
  229. !! END DO
  230. ! Since the flags are not set in the ENACT files we reset them to 0
  231. inpfile%itqc(:) = 1
  232. inpfile%itqcf(:,:) = 0
  233. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ), &
  234. & cl_name, __LINE__ )
  235. DO ji = 1,iobs
  236. istart1(1) = ji
  237. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  238. & start = istart1, count = icount1), &
  239. & cl_name, __LINE__ )
  240. inpfile%ipqc(ji) = IACHAR( cqc ) - IACHAR( '0' )
  241. inpfile%ipqcf(:,ji) = 0
  242. END DO
  243. DO ji = 1,iobs
  244. inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
  245. END DO
  246. IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_profiles, i_qc_flag_id ) == nf90_noerr ) THEN
  247. ALLOCATE( &
  248. & iqc1(iobs) &
  249. & )
  250. CALL chkerr( nf90_get_var ( i_file_id, i_qc_flag_id, iqc1 ), &
  251. & cl_name, __LINE__ )
  252. DO ji = 1,iobs
  253. inpfile%ioqcf(1,ji) = iqc1(ji)
  254. inpfile%ivqcf(1,ji,:) = iqc1(ji)
  255. inpfile%ioqcf(2,ji) = 0
  256. inpfile%ivqcf(2,ji,:) = 0
  257. END DO
  258. DEALLOCATE( &
  259. & iqc1 &
  260. & )
  261. ELSE
  262. IF(ldwp) WRITE(kunit,*)'No QC profile flags in file'
  263. inpfile%ioqcf(:,:) = 0
  264. inpfile%ivqcf(:,:,:) = 0
  265. ENDIF
  266. IF ( nf90_inq_varid( i_file_id, cl_fld_qc_flags_levels, i_qc_flag_id ) == nf90_noerr ) THEN
  267. ALLOCATE( &
  268. & iqc2(ilev,iobs) &
  269. & )
  270. CALL chkerr( nf90_get_var ( i_file_id, i_qc_flag_id, iqc2 ), &
  271. & cl_name, __LINE__ )
  272. DO ji = 1,iobs
  273. DO jk = 1,ilev
  274. inpfile%ivlqcf(1,jk,ji,:) = iqc2(jk,ji)
  275. inpfile%ivlqcf(2,jk,ji,:) = 0
  276. END DO
  277. END DO
  278. DEALLOCATE( &
  279. & iqc2 &
  280. & )
  281. ELSE
  282. IF(ldwp) WRITE(kunit,*)'No QC level flags in file'
  283. inpfile%ivlqcf(:,:,:,:) = 0
  284. ENDIF
  285. !---------------------------------------------------------------------
  286. ! Read the time/position variables
  287. !---------------------------------------------------------------------
  288. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ), &
  289. & cl_name, __LINE__ )
  290. CALL chkerr( nf90_get_var ( i_file_id, i_juld_id, inpfile%ptim ), &
  291. & cl_name, __LINE__ )
  292. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ), &
  293. & cl_name, __LINE__ )
  294. CALL chkerr( nf90_get_var ( i_file_id, i_depth_id, inpfile%pdep ), &
  295. & cl_name, __LINE__ )
  296. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ), &
  297. & cl_name, __LINE__ )
  298. CALL chkerr( nf90_get_var ( i_file_id, i_phi_id, inpfile%pphi ), &
  299. & cl_name, __LINE__ )
  300. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ), &
  301. & cl_name, __LINE__ )
  302. CALL chkerr( nf90_get_var ( i_file_id, i_lam_id, inpfile%plam ), &
  303. & cl_name, __LINE__ )
  304. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_reference_date_time, i_reference_date_time_id ), &
  305. & cl_name, __LINE__ )
  306. CALL chkerr( nf90_get_var ( i_file_id, i_reference_date_time_id, inpfile%cdjuldref ), &
  307. & cl_name, __LINE__ )
  308. !---------------------------------------------------------------------
  309. ! Read the platform information
  310. !---------------------------------------------------------------------
  311. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ), &
  312. & cl_name, __LINE__ )
  313. CALL chkerr( nf90_get_var ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ), &
  314. & cl_name, __LINE__ )
  315. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ), &
  316. & cl_name, __LINE__ )
  317. CALL chkerr( nf90_get_var ( i_file_id, i_pl_num_id, inpfile%cdwmo ), &
  318. & cl_name, __LINE__ )
  319. !---------------------------------------------------------------------
  320. ! Read the variables
  321. !---------------------------------------------------------------------
  322. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_tp, i_var_id ), &
  323. & cl_name, __LINE__ )
  324. CALL chkerr( nf90_get_var ( i_file_id, i_var_id, inpfile%pob(:,:,1) ), &
  325. & cl_name, __LINE__ )
  326. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ), &
  327. & cl_name, __LINE__ )
  328. CALL chkerr( nf90_get_var ( i_file_id, i_var_id, inpfile%pob(:,:,2) ), &
  329. & cl_name, __LINE__ )
  330. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_ti, i_var_id ), &
  331. & cl_name, __LINE__ )
  332. CALL chkerr( nf90_get_var ( i_file_id, i_var_id, inpfile%pext(:,:,1) ), &
  333. & cl_name, __LINE__ )
  334. !---------------------------------------------------------------------
  335. ! Close file
  336. !---------------------------------------------------------------------
  337. CALL chkerr( nf90_close( i_file_id ), cl_name, __LINE__ )
  338. !---------------------------------------------------------------------
  339. ! Set file indexes
  340. !---------------------------------------------------------------------
  341. DO ji = 1, inpfile%nobs
  342. inpfile%kindex(ji) = ji
  343. END DO
  344. END SUBROUTINE read_enactfile
  345. SUBROUTINE read_coriofile( cdfilename, inpfile, kunit, ldwp, ldgrid )
  346. !!---------------------------------------------------------------------
  347. !!
  348. !! ** ROUTINE read_coriofile **
  349. !!
  350. !! ** Purpose : Read from file the profile CORIO observations.
  351. !!
  352. !! ** Method : The data file is a NetCDF file.
  353. !!
  354. !! ** Action :
  355. !!
  356. !! History :
  357. !! ! 09-01 (K. Mogensen) Original based on old versions
  358. !!----------------------------------------------------------------------
  359. !! * Arguments
  360. CHARACTER(LEN=*) :: cdfilename ! Input filename
  361. TYPE(obfbdata) :: inpfile ! Output enactfile structure
  362. INTEGER :: kunit ! Unit for output
  363. LOGICAL :: ldwp ! Print info
  364. LOGICAL :: ldgrid ! Save grid info in data structure
  365. INTEGER :: &
  366. & iobs, &
  367. & ilev
  368. !! * Local declarations
  369. INTEGER :: &
  370. & i_file_id, &
  371. & i_obs_id, &
  372. & i_lev_id, &
  373. & i_phi_id, &
  374. & i_lam_id, &
  375. & i_depth_id, &
  376. & i_pres_id, &
  377. & i_var_id, &
  378. & i_pl_num_id, &
  379. & i_format_version_id, &
  380. & i_juld_id, &
  381. & i_data_type_id, &
  382. & i_wmo_inst_type_id, &
  383. & i_qc_var_id, &
  384. & i_dc_ref_id
  385. CHARACTER(LEN=40) :: &
  386. & cl_fld_lam, &
  387. & cl_fld_phi, &
  388. & cl_fld_depth, &
  389. & cl_fld_depth_qc, &
  390. & cl_fld_pres, &
  391. & cl_fld_pres_qc, &
  392. & cl_fld_var_t, &
  393. & cl_fld_var_s, &
  394. & cl_fld_var_ti, &
  395. & cl_fld_var_pos_qc, &
  396. & cl_fld_var_qc_t, &
  397. & cl_fld_var_qc_s, &
  398. & cl_fld_var_prof_qc_t, &
  399. & cl_fld_var_prof_qc_s, &
  400. & cl_fld_dc_ref, &
  401. & cl_fld_juld, &
  402. & cl_fld_pl_num, &
  403. & cl_fld_wmo_inst_type
  404. CHARACTER(LEN=14), PARAMETER :: &
  405. & cl_name = 'read_coriofile'
  406. CHARACTER(LEN=4 ) :: &
  407. & cl_format_version = ''
  408. INTEGER, DIMENSION(1) :: &
  409. & istart1, icount1
  410. INTEGER, DIMENSION(2) :: &
  411. & istart2, icount2
  412. CHARACTER(len=imaxlev) :: &
  413. & clqc
  414. CHARACTER(len=1) :: &
  415. & cqc
  416. CHARACTER(len=256) :: &
  417. & cdjulref
  418. INTEGER :: &
  419. & ji, jk
  420. INTEGER :: &
  421. & iformat
  422. LOGICAL :: &
  423. & lsal
  424. REAL(fbdp), DIMENSION(:,:), ALLOCATABLE :: &
  425. & zpres
  426. INTEGER, DIMENSION(:,:), ALLOCATABLE :: &
  427. & ipresqc
  428. CHARACTER(len=256) :: &
  429. & cerr
  430. !-----------------------------------------------------------------------
  431. ! Initialization
  432. !-----------------------------------------------------------------------
  433. icount1(1) = 1
  434. lsal = .TRUE.
  435. !-----------------------------------------------------------------------
  436. ! Open file
  437. !-----------------------------------------------------------------------
  438. CALL chkerr( nf90_open( TRIM( cdfilename ), nf90_nowrite, &
  439. & i_file_id ), cl_name, __LINE__ )
  440. !-----------------------------------------------------------------------
  441. ! Check format and set variables accordingly
  442. !-----------------------------------------------------------------------
  443. IF ( ( nf90_inq_dimid( i_file_id, 'N_PROF', i_obs_id ) == nf90_noerr ) .AND. &
  444. & ( nf90_inq_dimid( i_file_id, 'N_LEVELS', i_lev_id ) == nf90_noerr ) ) THEN
  445. iformat = 1
  446. ELSEIF ( ( nf90_inq_dimid( i_file_id, 'mN_PROF', i_obs_id ) == nf90_noerr ) .AND. &
  447. & ( nf90_inq_dimid( i_file_id, 'mN_ZLEV', i_lev_id ) == nf90_noerr ) ) THEN
  448. iformat = 2
  449. ELSE
  450. WRITE(cerr,'(2A)')'Invalid data format in ',cl_name
  451. CALL fatal_error( cerr, __LINE__ )
  452. ENDIF
  453. IF ( iformat == 1 ) THEN
  454. cl_fld_lam = 'LONGITUDE'
  455. cl_fld_phi = 'LATITUDE'
  456. cl_fld_depth = 'DEPH'
  457. cl_fld_depth_qc = 'DEPH_QC'
  458. cl_fld_pres = 'PRES'
  459. cl_fld_pres_qc = 'PRES_QC'
  460. cl_fld_juld = 'JULD'
  461. cl_fld_wmo_inst_type = 'WMO_INST_TYPE'
  462. cl_fld_dc_ref = 'DC_REFERENCE'
  463. cl_fld_pl_num = 'PLATFORM_NUMBER'
  464. cl_fld_var_qc_t = 'TEMP_QC'
  465. cl_fld_var_prof_qc_t = 'PROFILE_TEMP_QC'
  466. cl_fld_var_t = 'TEMP'
  467. cl_fld_var_qc_s = 'PSAL_QC'
  468. cl_fld_var_prof_qc_s = 'PROFILE_PSAL_QC'
  469. cl_fld_var_s = 'PSAL'
  470. cl_fld_var_pos_qc = 'POSITION_QC'
  471. ELSEIF ( iformat==2 ) THEN
  472. cl_fld_lam = 'LONGITUDE'
  473. cl_fld_phi = 'LATITUDE'
  474. cl_fld_depth = 'DEPH'
  475. cl_fld_depth_qc = 'QC_DEPH'
  476. cl_fld_pres = 'PRES'
  477. cl_fld_pres_qc = 'QC_PRES'
  478. cl_fld_juld = 'JULD'
  479. cl_fld_wmo_inst_type = 'INST_TYPE'
  480. cl_fld_dc_ref = 'REFERENCE'
  481. cl_fld_pl_num = 'PLATFORM_NUMBER'
  482. cl_fld_var_qc_t = 'QC_TEMP'
  483. cl_fld_var_prof_qc_t = 'Q_PROFILE_TEMP'
  484. cl_fld_var_t = 'TEMP'
  485. cl_fld_var_qc_s = 'QC_PSAL'
  486. cl_fld_var_prof_qc_s = 'Q_PROFILE_PSAL'
  487. cl_fld_var_s = 'PSAL'
  488. cl_fld_var_pos_qc = 'Q_POSITION'
  489. ENDIF
  490. !-----------------------------------------------------------------------
  491. ! Read the heading of the file
  492. !-----------------------------------------------------------------------
  493. IF(ldwp)WRITE(kunit,*)
  494. IF(ldwp)WRITE(kunit,*) ' read_coriofile :'
  495. IF(ldwp)WRITE(kunit,*) ' ~~~~~~~~~~~~~~~~'
  496. IF(ldwp)WRITE(kunit,*) ' Format version = ', iformat
  497. !---------------------------------------------------------------------
  498. ! Read the number of observations and levels to allocate arrays
  499. !---------------------------------------------------------------------
  500. CALL chkerr( nf90_inquire_dimension( i_file_id, i_obs_id, len = iobs ), &
  501. & cl_name, __LINE__ )
  502. CALL chkerr( nf90_inquire_dimension( i_file_id, i_lev_id, len = ilev ), &
  503. & cl_name, __LINE__ )
  504. IF(ldwp)WRITE(kunit,*) ' No. of data records = ', iobs
  505. IF(ldwp)WRITE(kunit,*) ' No. of levels = ', ilev
  506. IF(ldwp)WRITE(kunit,*)
  507. IF (ilev > imaxlev) THEN
  508. CALL fatal_error( 'Increase imaxlev in obs_prof_io.F90', __LINE__ )
  509. ENDIF
  510. !---------------------------------------------------------------------
  511. ! Allocate arrays
  512. !---------------------------------------------------------------------
  513. CALL init_obfbdata( inpfile )
  514. CALL alloc_obfbdata( inpfile, 2, iobs, ilev, 0, 1, ldgrid )
  515. inpfile%cname(1) = 'POTM'
  516. inpfile%cname(2) = 'PSAL'
  517. inpfile%coblong(1) = 'Potential temperature'
  518. inpfile%coblong(2) = 'Practical salinity'
  519. inpfile%cobunit(1) = 'Degrees Celsius'
  520. inpfile%cobunit(2) = 'PSU'
  521. inpfile%cextname(1) = 'TEMP'
  522. inpfile%cextlong(1) = 'Insitu temperature'
  523. inpfile%cextunit(1) = 'Degrees Celsius'
  524. ALLOCATE( &
  525. & zpres(ilev,iobs), &
  526. & ipresqc(ilev,iobs) &
  527. & )
  528. !---------------------------------------------------------------------
  529. ! Get julian data reference (iformat==2)
  530. !---------------------------------------------------------------------
  531. IF (iformat==2) THEN
  532. CALL chkerr ( nf90_get_att( i_file_id, nf90_global, &
  533. & "Reference_date_time", cdjulref ), &
  534. & cl_name, __LINE__ )
  535. inpfile%cdjuldref = cdjulref(7:10)//cdjulref(4:5)// &
  536. & cdjulref(1:2)//cdjulref(12:13)//cdjulref(15:16)//cdjulref(18:19)
  537. ENDIF
  538. !---------------------------------------------------------------------
  539. ! Read the QC attributes
  540. !---------------------------------------------------------------------
  541. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_qc_t, i_qc_var_id ), &
  542. & cl_name, __LINE__ )
  543. istart2(1) = 1
  544. icount2(2) = 1
  545. icount2(1) = ilev
  546. DO ji = 1, iobs
  547. istart2(2) = ji
  548. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, clqc, &
  549. & start = istart2, count = icount2), &
  550. & cl_name, __LINE__ )
  551. DO jk = 1, ilev
  552. inpfile%ivlqc(jk,ji,1) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
  553. END DO
  554. END DO
  555. IF ( nf90_inq_varid( i_file_id, cl_fld_var_qc_s, i_qc_var_id ) == nf90_noerr ) THEN
  556. DO ji = 1, iobs
  557. istart2(2) = ji
  558. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, clqc, &
  559. & start = istart2, count = icount2), &
  560. & cl_name, __LINE__ )
  561. DO jk = 1, ilev
  562. inpfile%ivlqc(jk,ji,2) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
  563. END DO
  564. END DO
  565. ELSE
  566. inpfile%ivlqc(:,:,2) = 4
  567. inpfile%pob(:,:,2) = fbrmdi
  568. lsal = .FALSE.
  569. ENDIF
  570. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_t, i_qc_var_id ), &
  571. & cl_name, __LINE__ )
  572. DO ji = 1,iobs
  573. istart1(1) = ji
  574. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  575. & start = istart1, count = icount1), &
  576. & cl_name, __LINE__ )
  577. inpfile%ivqc(ji,1) = IACHAR( cqc ) - IACHAR( '0' )
  578. END DO
  579. IF (lsal) THEN
  580. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_prof_qc_s, i_qc_var_id ), &
  581. & cl_name, __LINE__ )
  582. DO ji = 1,iobs
  583. istart1(1) = ji
  584. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  585. & start = istart1, count = icount1), &
  586. & cl_name, __LINE__ )
  587. inpfile%ivqc(ji,2) = IACHAR( cqc ) - IACHAR( '0' )
  588. END DO
  589. ELSE
  590. inpfile%ivqc(:,2) = 4
  591. ENDIF
  592. DO ji = 1,iobs
  593. inpfile%ioqc(ji) = MIN( inpfile%ivqc(ji,1), inpfile%ivqc(ji,2) )
  594. END DO
  595. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_pos_qc, i_qc_var_id ), &
  596. & cl_name, __LINE__ )
  597. DO ji = 1, iobs
  598. istart1(1) = ji
  599. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, cqc, &
  600. & start = istart1, count = icount1), &
  601. & cl_name, __LINE__ )
  602. inpfile%ipqc(ji) = IACHAR( cqc ) - IACHAR( '0' )
  603. END DO
  604. !---------------------------------------------------------------------
  605. ! Read the time/position variables
  606. !---------------------------------------------------------------------
  607. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_juld, i_juld_id ), &
  608. & cl_name, __LINE__ )
  609. CALL chkerr( nf90_get_var ( i_file_id, i_juld_id, inpfile%ptim ), &
  610. & cl_name, __LINE__ )
  611. IF (iformat==1) THEN
  612. CALL chkerr ( nf90_get_att( i_file_id, i_juld_id, &
  613. & "units", cdjulref ), &
  614. & cl_name, __LINE__ )
  615. inpfile%cdjuldref = cdjulref(12:15)//cdjulref(17:18)// &
  616. & cdjulref(20:21)//cdjulref(23:24)//cdjulref(26:27)//&
  617. & cdjulref(29:30)
  618. ENDIF
  619. IF ( nf90_inq_varid( i_file_id, cl_fld_depth, i_depth_id ) == nf90_noerr ) THEN
  620. CALL chkerr( nf90_get_var ( i_file_id, i_depth_id, inpfile%pdep ), &
  621. & cl_name, __LINE__ )
  622. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_depth_qc, i_qc_var_id ), &
  623. & cl_name, __LINE__ )
  624. DO ji = 1, iobs
  625. istart2(2) = ji
  626. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, clqc, &
  627. & start = istart2, count = icount2), &
  628. & cl_name, __LINE__ )
  629. DO jk = 1, ilev
  630. inpfile%idqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
  631. END DO
  632. END DO
  633. ELSE
  634. inpfile%pdep(:,:) = fbrmdi
  635. inpfile%idqc(:,:) = 4
  636. ENDIF
  637. IF ( nf90_inq_varid( i_file_id, cl_fld_pres, i_pres_id ) == nf90_noerr ) THEN
  638. CALL chkerr( nf90_get_var ( i_file_id, i_pres_id, zpres ), &
  639. & cl_name, __LINE__ )
  640. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pres_qc, i_qc_var_id ), &
  641. & cl_name, __LINE__ )
  642. DO ji = 1, iobs
  643. istart2(2) = ji
  644. CALL chkerr( nf90_get_var ( i_file_id, i_qc_var_id, clqc, &
  645. & start = istart2, count = icount2), &
  646. & cl_name, __LINE__ )
  647. DO jk = 1, ilev
  648. ipresqc(jk,ji) = IACHAR( clqc(jk:jk) ) - IACHAR( '0' )
  649. END DO
  650. END DO
  651. ELSE
  652. zpres(:,:) = fbrmdi
  653. ipresqc(:,:) = 4
  654. ENDIF
  655. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_phi, i_phi_id ), &
  656. & cl_name, __LINE__ )
  657. CALL chkerr( nf90_get_var ( i_file_id, i_phi_id, inpfile%pphi ), &
  658. & cl_name, __LINE__ )
  659. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_lam, i_lam_id ), &
  660. & cl_name, __LINE__ )
  661. CALL chkerr( nf90_get_var ( i_file_id, i_lam_id, inpfile%plam ), &
  662. & cl_name, __LINE__ )
  663. !---------------------------------------------------------------------
  664. ! Read the platform information
  665. !---------------------------------------------------------------------
  666. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_wmo_inst_type, i_wmo_inst_type_id ), &
  667. & cl_name, __LINE__ )
  668. CALL chkerr( nf90_get_var ( i_file_id, i_wmo_inst_type_id, inpfile%cdtyp ), &
  669. & cl_name, __LINE__ )
  670. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_pl_num, i_pl_num_id ), &
  671. & cl_name, __LINE__ )
  672. CALL chkerr( nf90_get_var ( i_file_id, i_pl_num_id, inpfile%cdwmo ), &
  673. & cl_name, __LINE__ )
  674. !---------------------------------------------------------------------
  675. ! Read the variables
  676. !---------------------------------------------------------------------
  677. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_t, i_var_id ), &
  678. & cl_name, __LINE__ )
  679. CALL chkerr( nf90_get_var ( i_file_id, i_var_id, inpfile%pext(:,:,1) ), &
  680. & cl_name, __LINE__ )
  681. IF (lsal) THEN
  682. CALL chkerr( nf90_inq_varid( i_file_id, cl_fld_var_s, i_var_id ), &
  683. & cl_name, __LINE__ )
  684. CALL chkerr( nf90_get_var ( i_file_id, i_var_id, inpfile%pob(:,:,2) ), &
  685. & cl_name, __LINE__ )
  686. ENDIF
  687. !---------------------------------------------------------------------
  688. ! Close file
  689. !---------------------------------------------------------------------
  690. CALL chkerr( nf90_close( i_file_id ), cl_name, __LINE__ )
  691. !---------------------------------------------------------------------
  692. ! Set file indexes
  693. !---------------------------------------------------------------------
  694. DO ji = 1, inpfile%nobs
  695. inpfile%kindex(ji) = ji
  696. END DO
  697. !---------------------------------------------------------------------
  698. ! Coriolis data conversion from insitu to potential temperature
  699. !---------------------------------------------------------------------
  700. !---------------------------------------------------------------------
  701. ! Convert pressure to depth if depth not present
  702. !---------------------------------------------------------------------
  703. DO ji = 1, inpfile%nobs
  704. IF ( inpfile%pphi(ji) < 9999.0 ) THEN
  705. DO jk = 1, inpfile%nlev
  706. IF ( inpfile%pdep(jk,ji) >= 9999.0 ) THEN
  707. IF ( zpres(jk,ji) < 9999.0 ) THEN
  708. inpfile%pdep(jk,ji) = &
  709. & p_to_dep( REAL(zpres(jk,ji),wp), REAL(inpfile%pphi(ji),wp) )
  710. inpfile%idqc(jk,ji) = ipresqc(jk,ji)
  711. ENDIF
  712. ENDIF
  713. END DO
  714. ENDIF
  715. END DO
  716. !---------------------------------------------------------------------
  717. ! Convert depth to pressure if pressure not present
  718. !---------------------------------------------------------------------
  719. DO ji = 1, inpfile%nobs
  720. IF ( inpfile%pphi(ji) < 9999.0 ) THEN
  721. DO jk = 1, inpfile%nlev
  722. IF ( zpres(jk,ji) >= 9999.0 ) THEN
  723. IF ( inpfile%pdep(jk,ji) < 9999.0 ) THEN
  724. zpres(jk,ji) = dep_to_p( REAL(inpfile%pdep(jk,ji),wp), &
  725. & REAL(inpfile%pphi(ji),wp) )
  726. ipresqc(jk,ji) = inpfile%idqc(jk,ji)
  727. ENDIF
  728. ENDIF
  729. END DO
  730. ENDIF
  731. END DO
  732. !---------------------------------------------------------------------
  733. ! Convert insitu temperature to potential temperature if
  734. ! salinity, insitu temperature and pressure are present
  735. !---------------------------------------------------------------------
  736. DO ji = 1, inpfile%nobs
  737. DO jk = 1, inpfile%nlev
  738. IF (( inpfile%pob(jk,ji,2) < 9999.0 ) .AND. &
  739. &( inpfile%pext(jk,ji,1) < 9999.0 ) .AND. &
  740. &( zpres(jk,ji) < 9999.0 ) ) THEN
  741. inpfile%pob(jk,ji,1) = potemp( REAL(inpfile%pob(jk,ji,2), wp), &
  742. & REAL(inpfile%pext(jk,ji,1), wp), &
  743. & REAL(zpres(jk,ji),wp), &
  744. & 0.0_wp )
  745. ELSE
  746. inpfile%pob(jk,ji,1) = fbrmdi
  747. ENDIF
  748. END DO
  749. END DO
  750. !---------------------------------------------------------------------
  751. ! Initialize flags since they are not in the CORIOLIS input files
  752. !---------------------------------------------------------------------
  753. inpfile%ioqcf(:,:) = 0
  754. inpfile%ipqcf(:,:) = 0
  755. inpfile%itqcf(:,:) = 0
  756. inpfile%idqcf(:,:,:) = 0
  757. inpfile%ivqcf(:,:,:) = 0
  758. inpfile%ivlqcf(:,:,:,:) = 0
  759. END SUBROUTINE read_coriofile