[4213] | 1 | !---------------------------------------------------------------------- |
---|
| 2 | ! NEMO system team, System and Interface for oceanic RElocable Nesting |
---|
| 3 | !---------------------------------------------------------------------- |
---|
| 4 | ! |
---|
| 5 | ! MODULE: iom_mpp |
---|
| 6 | ! |
---|
| 7 | ! DESCRIPTION: |
---|
[5602] | 8 | !> @brief This module manage massively parallel processing Input/Output manager. |
---|
| 9 | !> Library to read/write mpp files. |
---|
[4213] | 10 | !> |
---|
| 11 | !> @details |
---|
| 12 | !> to open mpp files (only file to be used (see mpp_get_use) |
---|
| 13 | !> will be open):<br/> |
---|
[5602] | 14 | !> @code |
---|
[4213] | 15 | !> CALL iom_mpp_open(td_mpp) |
---|
[5602] | 16 | !> @endcode |
---|
[4213] | 17 | !> - td_mpp is a mpp structure |
---|
| 18 | !> |
---|
| 19 | !> to creates mpp files:<br/> |
---|
[5602] | 20 | !> @code |
---|
[4213] | 21 | !> CALL iom_mpp_create(td_mpp) |
---|
[5602] | 22 | !> @endcode |
---|
[4213] | 23 | !> - td_mpp is a mpp structure |
---|
| 24 | !> |
---|
| 25 | !> to write in mpp files :<br/> |
---|
[5602] | 26 | !> @code |
---|
[4213] | 27 | !> CALL iom_mpp_write_file(td_mpp) |
---|
[5602] | 28 | !> @endcode |
---|
[4213] | 29 | !> - td_mpp is a mpp structure |
---|
| 30 | !> |
---|
| 31 | !> to close mpp files:<br/> |
---|
[5602] | 32 | !> @code |
---|
[4213] | 33 | !> CALL iom_mpp_close(td_mpp) |
---|
[5602] | 34 | !> @endcode |
---|
[4213] | 35 | !> |
---|
| 36 | !> to read one variable in an mpp files:<br/> |
---|
[5602] | 37 | !> @code |
---|
| 38 | !> tl_var=iom_mpp_read_var( td_mpp, id_varid, [id_start, id_count] [,id_ew] ) |
---|
| 39 | !> @endcode |
---|
| 40 | !> or |
---|
| 41 | !> @code |
---|
| 42 | !> tl_var=iom_mpp_read_var( td_mpp, cd_name, [id_start, id_count] [,id_ew] ) |
---|
| 43 | !> @endcode |
---|
[4213] | 44 | !> - td_mpp is a mpp structure |
---|
| 45 | !> - id_varid is a variable id |
---|
[5602] | 46 | !> - cd_name is variable name or standard name |
---|
| 47 | !> - id_start is a integer(4) 1D array of index from which the data |
---|
| 48 | !> values will be read [optional] |
---|
| 49 | !> - id_count is a integer(4) 1D array of the number of indices selected |
---|
| 50 | !> along each dimension [optional] |
---|
| 51 | !> - id_ew East West overlap [optional] |
---|
[4213] | 52 | !> |
---|
[5602] | 53 | !> to fill variable value in mpp structure:<br/> |
---|
| 54 | !> @code |
---|
| 55 | !> CALL iom_mpp_fill_var(td_mpp, id_varid, [id_start, id_count] [,id_ew] ) |
---|
| 56 | !> @endcode |
---|
| 57 | !> or<br/> |
---|
| 58 | !> @code |
---|
| 59 | !> CALL iom_mpp_fill_var(td_mpp, cd_name, [id_start, id_count] [,id_ew] ) |
---|
| 60 | !> @endcode |
---|
| 61 | !> - td_mpp is mpp structure |
---|
| 62 | !> - id_varid is variable id |
---|
| 63 | !> - cd_name is variable name or standard name |
---|
| 64 | !> - id_start is a integer(4) 1D array of index from which the data |
---|
| 65 | !> values will be read [optional] |
---|
| 66 | !> - id_count is a integer(4) 1D array of the number of indices selected |
---|
| 67 | !> along each dimension [optional] |
---|
| 68 | !> - id_ew East West overlap [optional] |
---|
[4213] | 69 | !> |
---|
[5602] | 70 | !> to fill all variable in mpp structure:<br/> |
---|
| 71 | !> @code |
---|
| 72 | !> CALL iom_mpp_fill_var(td_mpp, [id_start, id_count] [,id_ew] ) |
---|
| 73 | !> @endcode |
---|
| 74 | !> - td_mpp is mpp structure |
---|
| 75 | !> - id_start is a integer(4) 1D array of index from which the data |
---|
| 76 | !> values will be read [optional] |
---|
| 77 | !> - id_count is a integer(4) 1D array of the number of indices selected |
---|
| 78 | !> along each dimension [optional] |
---|
| 79 | !> - id_ew East West overlap |
---|
| 80 | !> |
---|
| 81 | !> to write files composong mpp strucutre:<br/> |
---|
| 82 | !> @code |
---|
| 83 | !> CALL iom_mpp_write_file(td_mpp) |
---|
| 84 | !> @endcode |
---|
| 85 | !> |
---|
[4213] | 86 | !> @author |
---|
| 87 | !> J.Paul |
---|
| 88 | ! REVISION HISTORY: |
---|
| 89 | !> @date Nov, 2013 - Initial Version |
---|
[5602] | 90 | !> |
---|
[4213] | 91 | !> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
| 92 | !---------------------------------------------------------------------- |
---|
| 93 | MODULE iom_mpp |
---|
| 94 | USE netcdf ! nf90 library |
---|
[5602] | 95 | USE global ! global parameter |
---|
[4213] | 96 | USE kind ! F90 kind parameter |
---|
| 97 | USE fct ! basic useful function |
---|
[5602] | 98 | USE logger ! log file manager |
---|
[4213] | 99 | USE dim ! dimension manager |
---|
| 100 | USE att ! attribute manager |
---|
| 101 | USE var ! variable manager |
---|
| 102 | USE file ! file manager |
---|
| 103 | USE iom ! I/O manager |
---|
| 104 | USE mpp ! mpp manager |
---|
| 105 | IMPLICIT NONE |
---|
| 106 | ! NOTE_avoid_public_variables_if_possible |
---|
| 107 | |
---|
| 108 | ! function and subroutine |
---|
[5602] | 109 | PUBLIC :: iom_mpp_open !< open all files composing mpp structure |
---|
| 110 | PUBLIC :: iom_mpp_create !< creates files composing mpp structure |
---|
[4213] | 111 | PUBLIC :: iom_mpp_close !< close file composing mpp structure |
---|
| 112 | PUBLIC :: iom_mpp_read_var !< read one variable in an mpp structure |
---|
| 113 | PUBLIC :: iom_mpp_write_file !< write mpp structure in files |
---|
| 114 | |
---|
[5602] | 115 | PRIVATE :: iom_mpp__read_var_id ! read one variable in an mpp structure, given variable id |
---|
| 116 | PRIVATE :: iom_mpp__read_var_name ! read one variable in an mpp structure, given variable name |
---|
| 117 | PRIVATE :: iom_mpp__read_var_value ! read variable value in an mpp structure |
---|
[4213] | 118 | |
---|
[5602] | 119 | INTERFACE iom_mpp_read_var ! read one variable in an mpp structure |
---|
| 120 | MODULE PROCEDURE iom_mpp__read_var_id ! given variable id |
---|
| 121 | MODULE PROCEDURE iom_mpp__read_var_name ! given variable name |
---|
[4213] | 122 | END INTERFACE iom_mpp_read_var |
---|
| 123 | |
---|
| 124 | CONTAINS |
---|
| 125 | !------------------------------------------------------------------- |
---|
[5602] | 126 | !> @brief This subroutine open files composing mpp structure to be used. |
---|
| 127 | !> @details |
---|
[4213] | 128 | !> If try to open a file in write mode that did not exist, create it.<br/> |
---|
| 129 | !> |
---|
| 130 | !> If file already exist, get information about: |
---|
| 131 | !> - the number of variables |
---|
| 132 | !> - the number of dimensions |
---|
| 133 | !> - the number of global attributes |
---|
| 134 | !> - the ID of the unlimited dimension |
---|
| 135 | !> - the file format |
---|
| 136 | !> and finally read dimensions. |
---|
| 137 | !> |
---|
| 138 | !> @author J.Paul |
---|
[5602] | 139 | !> - November, 2013- Initial Version |
---|
[4213] | 140 | ! |
---|
[5602] | 141 | !> @param[inout] td_mpp mpp structure |
---|
[4213] | 142 | !------------------------------------------------------------------- |
---|
[5602] | 143 | SUBROUTINE iom_mpp_open(td_mpp, id_perio, id_ew) |
---|
[4213] | 144 | IMPLICIT NONE |
---|
| 145 | ! Argument |
---|
[5602] | 146 | TYPE(TMPP) , INTENT(INOUT) :: td_mpp |
---|
| 147 | INTEGER(i4), INTENT(IN), OPTIONAL :: id_perio |
---|
| 148 | INTEGER(i4), INTENT(IN), OPTIONAL :: id_ew |
---|
[4213] | 149 | |
---|
| 150 | ! local variable |
---|
| 151 | CHARACTER(LEN=lc) :: cl_name |
---|
| 152 | |
---|
| 153 | ! loop indices |
---|
| 154 | INTEGER(i4) :: ji |
---|
| 155 | !---------------------------------------------------------------- |
---|
| 156 | ! check if mpp exist |
---|
| 157 | IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN |
---|
| 158 | |
---|
| 159 | CALL logger_error( " IOM MPP OPEN: domain decomposition not define "//& |
---|
| 160 | & " in mpp strcuture "//TRIM(td_mpp%c_name)) |
---|
| 161 | |
---|
| 162 | ELSE |
---|
[5602] | 163 | ! if no processor file selected |
---|
| 164 | ! force to open all files |
---|
| 165 | IF( .NOT. ANY( td_mpp%t_proc(:)%l_use ) )THEN |
---|
| 166 | td_mpp%t_proc(:)%l_use=.TRUE. |
---|
| 167 | ENDIF |
---|
[4213] | 168 | |
---|
[5602] | 169 | ! add suffix to mpp name |
---|
| 170 | td_mpp%c_name=file_add_suffix( TRIM(td_mpp%c_name), & |
---|
| 171 | & TRIM(td_mpp%c_type) ) |
---|
[4213] | 172 | |
---|
[5602] | 173 | td_mpp%t_proc(:)%c_type=TRIM(td_mpp%c_type) |
---|
| 174 | IF( td_mpp%i_nproc > 1 )THEN |
---|
| 175 | DO ji=1,td_mpp%i_nproc |
---|
| 176 | IF( td_mpp%t_proc(ji)%l_use )THEN |
---|
[4213] | 177 | |
---|
[5602] | 178 | SELECT CASE(TRIM(td_mpp%c_type)) |
---|
| 179 | CASE('cdf') |
---|
| 180 | cl_name=TRIM( file_rename(td_mpp%c_name, ji-1) ) |
---|
| 181 | CASE('dimg') |
---|
[4213] | 182 | cl_name=TRIM( file_rename(td_mpp%c_name, ji) ) |
---|
[5602] | 183 | CASE DEFAULT |
---|
| 184 | CALL logger_fatal("IOM MPP OPEN: can not open file "//& |
---|
| 185 | & "of type "//TRIM(td_mpp%c_type)) |
---|
| 186 | END SELECT |
---|
[4213] | 187 | |
---|
[5602] | 188 | td_mpp%t_proc(ji)%c_name=TRIM(cl_name) |
---|
[4213] | 189 | |
---|
[5602] | 190 | CALL iom_open(td_mpp%t_proc(ji)) |
---|
[4213] | 191 | |
---|
[5602] | 192 | ENDIF |
---|
| 193 | ENDDO |
---|
| 194 | ELSE ! td_mpp%i_nproc == 1 |
---|
| 195 | cl_name=TRIM( file_rename(td_mpp%c_name) ) |
---|
| 196 | td_mpp%t_proc(1)%c_name=TRIM(cl_name) |
---|
[4213] | 197 | |
---|
[5602] | 198 | CALL iom_open(td_mpp%t_proc(1)) |
---|
| 199 | ENDIF |
---|
[4213] | 200 | |
---|
[5602] | 201 | IF( PRESENT(id_ew) )THEN |
---|
| 202 | td_mpp%i_ew=id_ew |
---|
| 203 | ! add east west overlap to each variable |
---|
| 204 | DO ji=1,td_mpp%i_nproc |
---|
| 205 | WHERE(td_mpp%t_proc(ji)%t_var(:)%t_dim(1)%l_use) |
---|
| 206 | td_mpp%t_proc(ji)%t_var(:)%i_ew=td_mpp%i_ew |
---|
| 207 | ENDWHERE |
---|
| 208 | ENDDO |
---|
| 209 | ENDIF |
---|
[4213] | 210 | |
---|
[5602] | 211 | IF( PRESENT(id_perio) )THEN |
---|
| 212 | td_mpp%i_perio=id_perio |
---|
| 213 | ENDIF |
---|
[4213] | 214 | |
---|
| 215 | ENDIF |
---|
| 216 | |
---|
| 217 | END SUBROUTINE iom_mpp_open |
---|
| 218 | !------------------------------------------------------------------- |
---|
| 219 | !> @brief This subroutine create files, composing mpp structure to be used, |
---|
[5602] | 220 | !> in write mode. |
---|
[4213] | 221 | !> |
---|
| 222 | !> @author J.Paul |
---|
[5602] | 223 | !> - November, 2013- Initial Version |
---|
[4213] | 224 | ! |
---|
[5602] | 225 | !> @param[inout] td_mpp mpp structure |
---|
[4213] | 226 | !------------------------------------------------------------------- |
---|
| 227 | SUBROUTINE iom_mpp_create(td_mpp) |
---|
| 228 | IMPLICIT NONE |
---|
| 229 | ! Argument |
---|
| 230 | TYPE(TMPP), INTENT(INOUT) :: td_mpp |
---|
| 231 | !---------------------------------------------------------------- |
---|
| 232 | ! check if mpp exist |
---|
| 233 | IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN |
---|
| 234 | |
---|
| 235 | CALL logger_error( " IOM MPP CREATE: domain decomposition not define "//& |
---|
| 236 | & " in mpp strcuture "//TRIM(td_mpp%c_name)) |
---|
| 237 | |
---|
| 238 | ELSE |
---|
| 239 | ! forced to open in write mode |
---|
| 240 | td_mpp%t_proc(:)%l_wrt=.TRUE. |
---|
| 241 | td_mpp%t_proc(:)%l_use=.TRUE. |
---|
| 242 | CALL iom_mpp_open(td_mpp) |
---|
| 243 | ENDIF |
---|
| 244 | |
---|
| 245 | END SUBROUTINE iom_mpp_create |
---|
| 246 | !------------------------------------------------------------------- |
---|
| 247 | !> @brief This subroutine close files composing mpp structure. |
---|
| 248 | !> |
---|
| 249 | !> @author J.Paul |
---|
[5602] | 250 | !> - November, 2013- Initial Version |
---|
[4213] | 251 | ! |
---|
[5602] | 252 | !> @param[in] td_mpp mpp structure |
---|
[4213] | 253 | !------------------------------------------------------------------- |
---|
| 254 | SUBROUTINE iom_mpp_close(td_mpp) |
---|
| 255 | IMPLICIT NONE |
---|
| 256 | ! Argument |
---|
| 257 | TYPE(TMPP), INTENT(INOUT) :: td_mpp |
---|
| 258 | |
---|
| 259 | ! loop indices |
---|
| 260 | INTEGER(i4) :: ji |
---|
| 261 | !---------------------------------------------------------------- |
---|
| 262 | ! check if mpp exist |
---|
| 263 | IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN |
---|
| 264 | |
---|
| 265 | CALL logger_error( " IOM MPP CLOSE: domain decomposition not define "//& |
---|
| 266 | & " in mpp strcuture "//TRIM(td_mpp%c_name)) |
---|
| 267 | |
---|
| 268 | ELSE |
---|
| 269 | DO ji=1,td_mpp%i_nproc |
---|
| 270 | IF( td_mpp%t_proc(ji)%i_id /= 0 )THEN |
---|
| 271 | CALL iom_close(td_mpp%t_proc(ji)) |
---|
| 272 | ENDIF |
---|
| 273 | ENDDO |
---|
[5602] | 274 | td_mpp%t_proc(:)%l_use=.FALSE. |
---|
[4213] | 275 | ENDIF |
---|
| 276 | |
---|
| 277 | END SUBROUTINE iom_mpp_close |
---|
| 278 | !------------------------------------------------------------------- |
---|
| 279 | !> @brief This function read variable value in opened mpp files, |
---|
[5602] | 280 | !> given variable id. |
---|
[4213] | 281 | !> |
---|
| 282 | !> @details |
---|
[5602] | 283 | !> Optionally start indices and number of point to be read could be specify. |
---|
| 284 | !> as well as East West ovelap of the global domain. |
---|
[4213] | 285 | !> |
---|
| 286 | !> @author J.Paul |
---|
[5602] | 287 | !> - November, 2013- Initial Version |
---|
| 288 | !> @date October, 2014 |
---|
| 289 | !> - use start and count array instead of domain structure. |
---|
| 290 | !> |
---|
| 291 | !> @param[in] td_mpp mpp structure |
---|
| 292 | !> @param[in] id_varid variable id |
---|
| 293 | !> @param[in] id_start index in the variable from which the data values |
---|
| 294 | !> will be read |
---|
| 295 | !> @param[in] id_count number of indices selected along each dimension |
---|
[4213] | 296 | !> @return variable structure |
---|
| 297 | !------------------------------------------------------------------- |
---|
| 298 | TYPE(TVAR) FUNCTION iom_mpp__read_var_id(td_mpp, id_varid,& |
---|
[5602] | 299 | & id_start, id_count) |
---|
[4213] | 300 | IMPLICIT NONE |
---|
| 301 | ! Argument |
---|
[5602] | 302 | TYPE(TMPP), INTENT(IN) :: td_mpp |
---|
| 303 | INTEGER(i4), INTENT(IN) :: id_varid |
---|
| 304 | INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_start |
---|
| 305 | INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_count |
---|
[4213] | 306 | |
---|
| 307 | ! local variable |
---|
| 308 | INTEGER(i4), DIMENSION(1) :: il_ind |
---|
| 309 | !---------------------------------------------------------------- |
---|
| 310 | ! check if mpp exist |
---|
| 311 | IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN |
---|
| 312 | |
---|
| 313 | CALL logger_error( " IOM MPP READ VAR: domain decomposition not define "//& |
---|
| 314 | & " in mpp strcuture "//TRIM(td_mpp%c_name)) |
---|
| 315 | |
---|
| 316 | ELSE |
---|
| 317 | |
---|
| 318 | IF( ANY(td_mpp%t_proc(:)%i_id /= 0) )THEN |
---|
| 319 | ! look for variable id |
---|
| 320 | il_ind(:)=MINLOC( td_mpp%t_proc(1)%t_var(:)%i_id, & |
---|
| 321 | & mask=(td_mpp%t_proc(1)%t_var(:)%i_id==id_varid)) |
---|
| 322 | IF( il_ind(1) /= 0 )THEN |
---|
| 323 | |
---|
[5602] | 324 | iom_mpp__read_var_id=var_copy(td_mpp%t_proc(1)%t_var(il_ind(1))) |
---|
[4213] | 325 | |
---|
| 326 | !!! read variable value |
---|
| 327 | CALL iom_mpp__read_var_value(td_mpp, iom_mpp__read_var_id, & |
---|
[5602] | 328 | & id_start, id_count) |
---|
[4213] | 329 | |
---|
| 330 | ELSE |
---|
| 331 | CALL logger_error( & |
---|
| 332 | & " IOM MPP READ VAR: there is no variable with id "//& |
---|
| 333 | & TRIM(fct_str(id_varid))//" in processor/file "//& |
---|
| 334 | & TRIM(td_mpp%t_proc(1)%c_name)) |
---|
| 335 | ENDIF |
---|
| 336 | ELSE |
---|
| 337 | CALL logger_error(" IOM MPP READ VAR: can't read variable, mpp "//& |
---|
| 338 | & TRIM(td_mpp%c_name)//" not opened") |
---|
| 339 | ENDIF |
---|
| 340 | |
---|
| 341 | ENDIF |
---|
| 342 | |
---|
| 343 | END FUNCTION iom_mpp__read_var_id |
---|
| 344 | !------------------------------------------------------------------- |
---|
| 345 | !> @brief This function read variable value in opened mpp files, |
---|
[5602] | 346 | !> given variable name or standard name. |
---|
| 347 | !> |
---|
[4213] | 348 | !> @details |
---|
[5602] | 349 | !> Optionally start indices and number of point to be read could be specify. |
---|
| 350 | !> as well as East West ovelap of the global domain. |
---|
| 351 | !> |
---|
[4213] | 352 | !> look first for variable name. If it doesn't |
---|
| 353 | !> exist in file, look for variable standard name.<br/> |
---|
| 354 | !> If variable name is not present, check variable standard name.<br/> |
---|
| 355 | ! |
---|
| 356 | !> @author J.Paul |
---|
[5602] | 357 | !> - November, 2013- Initial Version |
---|
| 358 | !> @date October, 2014 |
---|
| 359 | !> - use start and count array instead of domain structure. |
---|
[4213] | 360 | ! |
---|
[5602] | 361 | !> @param[in] td_mpp mpp structure |
---|
| 362 | !> @param[in] cd_name variable name |
---|
| 363 | !> @param[in] id_start index in the variable from which the data values |
---|
| 364 | !> will be read |
---|
| 365 | !> @param[in] id_count number of indices selected along each dimension |
---|
[4213] | 366 | !> @return variable structure |
---|
| 367 | !------------------------------------------------------------------- |
---|
| 368 | TYPE(TVAR) FUNCTION iom_mpp__read_var_name(td_mpp, cd_name, & |
---|
[5602] | 369 | & id_start, id_count ) |
---|
[4213] | 370 | IMPLICIT NONE |
---|
| 371 | ! Argument |
---|
[5602] | 372 | TYPE(TMPP), INTENT(IN) :: td_mpp |
---|
| 373 | CHARACTER(LEN=*), INTENT(IN) :: cd_name |
---|
| 374 | INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_start |
---|
| 375 | INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_count |
---|
[4213] | 376 | |
---|
| 377 | ! local variable |
---|
[5602] | 378 | INTEGER(i4) :: il_ind |
---|
[4213] | 379 | !---------------------------------------------------------------- |
---|
| 380 | ! check if mpp exist |
---|
| 381 | IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN |
---|
| 382 | |
---|
| 383 | CALL logger_error( " IOM MPP READ VAR: domain decomposition not define "//& |
---|
| 384 | & " in mpp strcuture "//TRIM(td_mpp%c_name)) |
---|
| 385 | |
---|
| 386 | ELSE |
---|
| 387 | |
---|
[5602] | 388 | il_ind=var_get_index( td_mpp%t_proc(1)%t_var(:), cd_name) |
---|
| 389 | IF( il_ind /= 0 )THEN |
---|
[4213] | 390 | |
---|
[5602] | 391 | iom_mpp__read_var_name=var_copy(td_mpp%t_proc(1)%t_var(il_ind)) |
---|
[4213] | 392 | |
---|
| 393 | !!! read variable value |
---|
| 394 | CALL iom_mpp__read_var_value( td_mpp, & |
---|
| 395 | & iom_mpp__read_var_name, & |
---|
[5602] | 396 | & id_start, id_count) |
---|
[4213] | 397 | |
---|
| 398 | ELSE |
---|
| 399 | |
---|
| 400 | CALL logger_error( & |
---|
| 401 | & " IOM MPP READ VAR: there is no variable with "//& |
---|
| 402 | & "name or standard name"//TRIM(cd_name)//& |
---|
| 403 | & " in processor/file "//TRIM(td_mpp%t_proc(1)%c_name)) |
---|
| 404 | ENDIF |
---|
| 405 | |
---|
| 406 | ENDIF |
---|
| 407 | |
---|
| 408 | END FUNCTION iom_mpp__read_var_name |
---|
| 409 | !------------------------------------------------------------------- |
---|
| 410 | !> @brief This subroutine read variable value |
---|
| 411 | !> in an mpp structure. |
---|
| 412 | !> |
---|
| 413 | !> @details |
---|
[5602] | 414 | !> Optionally start indices and number of point to be read could be specify. |
---|
| 415 | !> as well as East West ovelap of the global domain. |
---|
[4213] | 416 | ! |
---|
| 417 | !> @author J.Paul |
---|
[5602] | 418 | !> - November, 2013- Initial Version |
---|
| 419 | !> @date October, 2014 |
---|
| 420 | !> - use start and count array instead of domain structure. |
---|
| 421 | !> |
---|
| 422 | !> @param[in] td_mpp mpp structure |
---|
| 423 | !> @param[inout] td_var variable structure |
---|
| 424 | !> @param[in] id_start index in the variable from which the data values |
---|
| 425 | !> will be read |
---|
| 426 | !> @param[in] id_count number of indices selected along each dimension |
---|
[4213] | 427 | !------------------------------------------------------------------- |
---|
| 428 | SUBROUTINE iom_mpp__read_var_value(td_mpp, td_var, & |
---|
[5602] | 429 | & id_start, id_count ) |
---|
[4213] | 430 | IMPLICIT NONE |
---|
| 431 | ! Argument |
---|
| 432 | TYPE(TMPP), INTENT(IN) :: td_mpp |
---|
| 433 | TYPE(TVAR), INTENT(INOUT) :: td_var |
---|
[5602] | 434 | INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_start |
---|
| 435 | INTEGER(i4), DIMENSION(:), INTENT(IN), OPTIONAL :: id_count |
---|
[4213] | 436 | |
---|
| 437 | ! local variable |
---|
| 438 | INTEGER(i4) :: il_status |
---|
| 439 | INTEGER(i4), DIMENSION(4) :: il_ind |
---|
| 440 | INTEGER(i4) :: il_i1p |
---|
| 441 | INTEGER(i4) :: il_i2p |
---|
| 442 | INTEGER(i4) :: il_j1p |
---|
| 443 | INTEGER(i4) :: il_j2p |
---|
[5602] | 444 | INTEGER(i4) :: il_i1 |
---|
| 445 | INTEGER(i4) :: il_i2 |
---|
| 446 | INTEGER(i4) :: il_j1 |
---|
| 447 | INTEGER(i4) :: il_j2 |
---|
[4213] | 448 | |
---|
[5602] | 449 | INTEGER(i4), DIMENSION(ip_maxdim) :: il_start |
---|
| 450 | INTEGER(i4), DIMENSION(ip_maxdim) :: il_end |
---|
| 451 | INTEGER(i4), DIMENSION(ip_maxdim) :: il_count |
---|
| 452 | |
---|
| 453 | INTEGER(i4), DIMENSION(ip_maxdim) :: il_strt |
---|
| 454 | INTEGER(i4), DIMENSION(ip_maxdim) :: il_cnt |
---|
| 455 | |
---|
| 456 | TYPE(TATT) :: tl_att |
---|
[4213] | 457 | TYPE(TVAR) :: tl_var |
---|
| 458 | |
---|
| 459 | ! loop indices |
---|
| 460 | INTEGER(i4) :: jk |
---|
| 461 | !---------------------------------------------------------------- |
---|
| 462 | |
---|
[5602] | 463 | il_start(:)=1 |
---|
| 464 | IF( PRESENT(id_start) ) il_start(:)=id_start(:) |
---|
[4213] | 465 | |
---|
[5602] | 466 | il_count(:)=td_mpp%t_dim(:)%i_len |
---|
| 467 | IF( PRESENT(id_count) ) il_count(:)=id_count(:) |
---|
[4213] | 468 | |
---|
[5602] | 469 | DO jk=1,ip_maxdim |
---|
| 470 | IF( .NOT. td_var%t_dim(jk)%l_use )THEN |
---|
| 471 | il_start(jk) = 1 |
---|
| 472 | il_count(jk) = 1 |
---|
[4213] | 473 | ENDIF |
---|
| 474 | |
---|
[5602] | 475 | il_end(jk)=il_start(jk)+il_count(jk)-1 |
---|
| 476 | ENDDO |
---|
[4213] | 477 | |
---|
| 478 | |
---|
[5602] | 479 | IF( ANY(il_end(:) > td_mpp%t_dim(:)%i_len) )THEN |
---|
| 480 | CALL logger_fatal("IOM MPP READ VAR VALUE: start + count "//& |
---|
| 481 | & "exceed dimension bound.") |
---|
[4213] | 482 | ENDIF |
---|
| 483 | |
---|
[5602] | 484 | ! use domain dimension |
---|
| 485 | td_var%t_dim(:)%i_len=il_count(:) |
---|
[4213] | 486 | |
---|
[5602] | 487 | ! Allocate space to hold variable value in structure |
---|
| 488 | IF( ASSOCIATED(td_var%d_value) )THEN |
---|
| 489 | DEALLOCATE(td_var%d_value) |
---|
[4213] | 490 | ENDIF |
---|
| 491 | |
---|
[5602] | 492 | ALLOCATE(td_var%d_value( il_count(1), & |
---|
| 493 | & il_count(2), & |
---|
| 494 | & il_count(3), & |
---|
| 495 | & il_count(4)),& |
---|
| 496 | & stat=il_status) |
---|
| 497 | IF(il_status /= 0 )THEN |
---|
[4213] | 498 | |
---|
[5602] | 499 | CALL logger_error( & |
---|
| 500 | & " IOM MPP READ VAR VALUE: not enough space to put variable "//& |
---|
| 501 | & TRIM(td_var%c_name)//& |
---|
| 502 | & " in variable structure") |
---|
[4213] | 503 | |
---|
| 504 | ENDIF |
---|
| 505 | |
---|
[5602] | 506 | CALL logger_debug("IOM MPP READ VAR VALUE: shape ("//& |
---|
| 507 | & TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=1)))//","//& |
---|
| 508 | & TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=2)))//","//& |
---|
| 509 | & TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=3)))//","//& |
---|
| 510 | & TRIM(fct_str(SIZE(td_var%d_value(:,:,:,:),DIM=4)))//")" ) |
---|
| 511 | ! FillValue by default |
---|
| 512 | td_var%d_value(:,:,:,:)=td_var%d_fill |
---|
[4213] | 513 | |
---|
| 514 | ! read processor |
---|
| 515 | DO jk=1,td_mpp%i_nproc |
---|
| 516 | IF( td_mpp%t_proc(jk)%l_use )THEN |
---|
| 517 | |
---|
| 518 | ! get processor indices |
---|
| 519 | il_ind(:)=mpp_get_proc_index( td_mpp, jk ) |
---|
| 520 | il_i1p = il_ind(1) |
---|
| 521 | il_i2p = il_ind(2) |
---|
| 522 | il_j1p = il_ind(3) |
---|
| 523 | il_j2p = il_ind(4) |
---|
[5602] | 524 | |
---|
[4213] | 525 | IF( .NOT. td_var%t_dim(1)%l_use )THEN |
---|
[5602] | 526 | il_i1p=il_start(1) ; il_i2p=il_end(1) |
---|
[4213] | 527 | ENDIF |
---|
| 528 | IF( .NOT. td_var%t_dim(2)%l_use )THEN |
---|
[5602] | 529 | il_j1p=il_start(2) ; il_j2p=il_end(2) |
---|
| 530 | ENDIF |
---|
| 531 | |
---|
| 532 | il_i1=MAX(il_i1p, il_start(1)) |
---|
| 533 | il_i2=MIN(il_i2p, il_end(1)) |
---|
[4213] | 534 | |
---|
[5602] | 535 | il_j1=MAX(il_j1p, il_start(2)) |
---|
| 536 | il_j2=MIN(il_j2p, il_end(2)) |
---|
[4213] | 537 | |
---|
| 538 | IF( (il_i1<=il_i2).AND.(il_j1<=il_j2) )THEN |
---|
[5602] | 539 | il_strt(:)=(/ il_i1-il_i1p+1, & |
---|
| 540 | & il_j1-il_j1p+1, & |
---|
| 541 | & 1,1 /) |
---|
[4213] | 542 | |
---|
[5602] | 543 | il_cnt(:)=(/ il_i2-il_i1+1, & |
---|
| 544 | & il_j2-il_j1+1, & |
---|
| 545 | & td_var%t_dim(3)%i_len, & |
---|
| 546 | & td_var%t_dim(4)%i_len /) |
---|
[4213] | 547 | |
---|
| 548 | tl_var=iom_read_var( td_mpp%t_proc(jk), td_var%c_name,& |
---|
[5602] | 549 | & il_strt(:), il_cnt(:) ) |
---|
[4213] | 550 | ! replace value in output variable structure |
---|
[5602] | 551 | td_var%d_value( il_i1 - il_start(1) + 1 : & |
---|
| 552 | & il_i2 - il_start(1) + 1, & |
---|
| 553 | & il_j1 - il_start(2) + 1 : & |
---|
| 554 | & il_j2 - il_start(2) + 1, & |
---|
[4213] | 555 | & :,:) = tl_var%d_value(:,:,:,:) |
---|
| 556 | |
---|
[5602] | 557 | ! clean |
---|
| 558 | CALL var_clean(tl_var) |
---|
[4213] | 559 | ENDIF |
---|
| 560 | |
---|
| 561 | ENDIF |
---|
| 562 | ENDDO |
---|
| 563 | |
---|
[5602] | 564 | IF( td_var%t_dim(1)%l_use .AND. & |
---|
| 565 | & td_var%t_dim(1)%i_len == td_mpp%t_dim(1)%i_len )THEN |
---|
| 566 | IF( td_mpp%i_ew >= 0 )THEN |
---|
| 567 | tl_att=att_init("ew_overlap",td_mpp%i_ew) |
---|
| 568 | CALL var_move_att(td_var,tl_att) |
---|
| 569 | ! clean |
---|
| 570 | CALL att_clean(tl_att) |
---|
| 571 | ENDIF |
---|
[4213] | 572 | ENDIF |
---|
| 573 | |
---|
[5602] | 574 | ! force to change _FillValue to avoid mistake |
---|
| 575 | ! with dummy zero _FillValue |
---|
| 576 | IF( td_var%d_fill == 0._dp )THEN |
---|
| 577 | CALL var_chg_FillValue(td_var) |
---|
| 578 | ENDIF |
---|
[4213] | 579 | |
---|
[5602] | 580 | END SUBROUTINE iom_mpp__read_var_value |
---|
[4213] | 581 | !------------------------------------------------------------------- |
---|
[5602] | 582 | !> @brief This subroutine write files composing mpp structure. |
---|
[4213] | 583 | ! |
---|
| 584 | !> @details |
---|
| 585 | ! |
---|
| 586 | !> @author J.Paul |
---|
[5602] | 587 | !> - November, 2013- Initial Version |
---|
[4213] | 588 | ! |
---|
[5602] | 589 | !> @param[inout] td_mpp mpp structure |
---|
[4213] | 590 | !------------------------------------------------------------------- |
---|
| 591 | SUBROUTINE iom_mpp_write_file(td_mpp) |
---|
| 592 | IMPLICIT NONE |
---|
| 593 | ! Argument |
---|
| 594 | TYPE(TMPP), INTENT(INOUT) :: td_mpp |
---|
| 595 | |
---|
[5602] | 596 | ! local variable |
---|
[4213] | 597 | ! loop indices |
---|
| 598 | INTEGER(i4) :: ji |
---|
| 599 | !---------------------------------------------------------------- |
---|
| 600 | ! check if mpp exist |
---|
| 601 | IF( .NOT. ASSOCIATED(td_mpp%t_proc) )THEN |
---|
| 602 | |
---|
| 603 | CALL logger_error( " MPP WRITE: domain decomposition not define "//& |
---|
| 604 | & " in mpp strcuture "//TRIM(td_mpp%c_name)) |
---|
| 605 | |
---|
| 606 | ELSE |
---|
| 607 | DO ji=1, td_mpp%i_nproc |
---|
| 608 | IF( td_mpp%t_proc(ji)%i_id /= 0 )THEN |
---|
[5602] | 609 | !CALL file_del_att(td_mpp%t_proc(ji), 'periodicity') |
---|
| 610 | !CALL file_del_att(td_mpp%t_proc(ji), 'ew_overlap') |
---|
| 611 | |
---|
[4213] | 612 | CALL iom_write_file(td_mpp%t_proc(ji)) |
---|
| 613 | ELSE |
---|
| 614 | CALL logger_debug( " MPP WRITE: no id associated to file "//& |
---|
| 615 | & TRIM(td_mpp%t_proc(ji)%c_name) ) |
---|
| 616 | ENDIF |
---|
| 617 | ENDDO |
---|
| 618 | ENDIF |
---|
| 619 | END SUBROUTINE iom_mpp_write_file |
---|
| 620 | END MODULE iom_mpp |
---|