[4213] | 1 | !---------------------------------------------------------------------- |
---|
| 2 | ! NEMO system team, System and Interface for oceanic RElocable Nesting |
---|
| 3 | !---------------------------------------------------------------------- |
---|
| 4 | ! |
---|
| 5 | ! MODULE: iom |
---|
| 6 | ! |
---|
| 7 | ! DESCRIPTION: |
---|
[5037] | 8 | !> @brief Input/Output manager : Library to read input files |
---|
[4213] | 9 | !> |
---|
| 10 | !> @details |
---|
| 11 | !> to open file:<br/> |
---|
[5037] | 12 | !> @code |
---|
[4213] | 13 | !> CALL iom_open(td_file) |
---|
[5037] | 14 | !> @endcode |
---|
[4213] | 15 | !> - td_file is file structure |
---|
| 16 | !> |
---|
[5037] | 17 | !> to create file:<br/> |
---|
| 18 | !> @code |
---|
| 19 | !> CALL iom_create(td_file) |
---|
| 20 | !> @endcode |
---|
| 21 | !> - td_file is file structure |
---|
| 22 | !> |
---|
[4213] | 23 | !> to write in file:<br/> |
---|
[5037] | 24 | !> @code |
---|
[4213] | 25 | !> CALL iom_write_file(td_file) |
---|
[5037] | 26 | !> @endcode |
---|
[4213] | 27 | !> |
---|
| 28 | !> to close file:<br/> |
---|
[5037] | 29 | !> @code |
---|
[4213] | 30 | !> CALL iom_close(tl_file) |
---|
[5037] | 31 | !> @endcode |
---|
[4213] | 32 | !> |
---|
| 33 | !> to read one dimension in file:<br/> |
---|
[5037] | 34 | !> @code |
---|
| 35 | !> tl_dim = iom_read_dim(tl_file, id_dimid) |
---|
| 36 | !> @endcode |
---|
[4213] | 37 | !> or<br/> |
---|
[5037] | 38 | !> @code |
---|
| 39 | !> tl_dim = iom_read_dim(tl_file, cd_name) |
---|
| 40 | !> @endcode |
---|
[4213] | 41 | !> - id_dimid is dimension id |
---|
| 42 | !> - cd_name is dimension name |
---|
| 43 | !> |
---|
| 44 | !> to read variable or global attribute in file:<br/> |
---|
[5037] | 45 | !> @code |
---|
| 46 | !> tl_att = iom_read_att(tl_file, id_varid, id_attid) |
---|
| 47 | !> @endcode |
---|
| 48 | !> or |
---|
| 49 | !> @code |
---|
| 50 | !> tl_att = iom_read_att(tl_file, id_varid, cd_attname) |
---|
| 51 | !> @endcode |
---|
| 52 | !> or |
---|
| 53 | !> @code |
---|
| 54 | !> tl_att = iom_read_att(tl_file, cd_varname, id_attid) |
---|
| 55 | !> @endcode |
---|
| 56 | !> or |
---|
| 57 | !> @code |
---|
| 58 | !> tl_att = iom_read_att(tl_file, cd_varname, cd_attname) |
---|
| 59 | !> @endcode |
---|
[4213] | 60 | !> - id_varid is variable id |
---|
| 61 | !> - id_attid is attribute id |
---|
| 62 | !> - cd_attname is attribute name |
---|
[5037] | 63 | !> - cd_varname is variable name or standard name |
---|
[4213] | 64 | !> |
---|
| 65 | !> to read one variable in file:<br/> |
---|
[5037] | 66 | !> @code |
---|
| 67 | !> tl_var = iom_read_var(td_file, id_varid, [id_start, id_count]) |
---|
| 68 | !> @endcode |
---|
| 69 | !> or |
---|
| 70 | !> @code |
---|
| 71 | !> tl_var = iom_read_var(td_file, cd_name, [id_start, [id_count,]]) |
---|
| 72 | !> @endcode |
---|
[4213] | 73 | !> - id_varid is variabale id |
---|
[5037] | 74 | !> - cd_name is variabale name or standard name. |
---|
| 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] |
---|
[4213] | 79 | !> |
---|
| 80 | !> @author |
---|
| 81 | !> J.Paul |
---|
| 82 | ! REVISION HISTORY: |
---|
[5037] | 83 | !> @date November, 2013 - Initial Version |
---|
| 84 | !> |
---|
[4213] | 85 | !> @todo |
---|
| 86 | !> - see lbc_lnk |
---|
| 87 | !> - see goup netcdf4 |
---|
[5037] | 88 | !> |
---|
| 89 | !> @note Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt) |
---|
[4213] | 90 | !---------------------------------------------------------------------- |
---|
| 91 | MODULE iom |
---|
| 92 | USE netcdf ! nf90 library |
---|
[5037] | 93 | USE global ! global parameter |
---|
[4213] | 94 | USE kind ! F90 kind parameter |
---|
| 95 | USE fct ! basic useful function |
---|
[5037] | 96 | USE logger ! log file manager |
---|
[4213] | 97 | USE dim ! dimension manager |
---|
| 98 | USE att ! attribute manager |
---|
| 99 | USE var ! variable manager |
---|
| 100 | USE file ! file manager |
---|
| 101 | USE iom_cdf ! netcdf I/O manager |
---|
| 102 | USE iom_rstdimg ! restart dimg I/O manager |
---|
| 103 | IMPLICIT NONE |
---|
| 104 | ! NOTE_avoid_public_variables_if_possible |
---|
| 105 | |
---|
| 106 | ! function and subroutine |
---|
| 107 | PUBLIC :: iom_open !< open or create file, fill file structure |
---|
| 108 | PUBLIC :: iom_create !< create file, fill file structure |
---|
| 109 | PUBLIC :: iom_close !< close file |
---|
| 110 | PUBLIC :: iom_read_dim !< read one dimension in an opened file |
---|
| 111 | PUBLIC :: iom_read_att !< read one attribute in an opened file |
---|
| 112 | PUBLIC :: iom_read_var !< read one variable in an opened file |
---|
| 113 | PUBLIC :: iom_write_file !< write file structure contents in an opened file |
---|
| 114 | |
---|
[5037] | 115 | ! read variable or global attribute in an opened file |
---|
| 116 | PRIVATE :: iom__read_att_varname_id ! given variable name or standard name and attribute id. |
---|
| 117 | PRIVATE :: iom__read_att_varid_id ! given variable id and attribute id. |
---|
| 118 | PRIVATE :: iom__read_att_varname_name ! given variable name or standard name, and attribute name. |
---|
| 119 | PRIVATE :: iom__read_att_varid_name ! given variable id and attribute name. |
---|
[4213] | 120 | |
---|
[5037] | 121 | PRIVATE :: iom__read_dim_id ! read one dimension in an opened file, given dimension id. |
---|
| 122 | PRIVATE :: iom__read_dim_name ! read one dimension in an opened netcdf file, given dimension name. |
---|
| 123 | PRIVATE :: iom__read_var_id ! read variable value in an opened file, given variable id. |
---|
| 124 | PRIVATE :: iom__read_var_name ! read variable value in an opened file, given variable name or standard name. |
---|
[4213] | 125 | |
---|
| 126 | INTERFACE iom_read_var |
---|
| 127 | MODULE PROCEDURE iom__read_var_id |
---|
| 128 | MODULE PROCEDURE iom__read_var_name |
---|
| 129 | END INTERFACE iom_read_var |
---|
| 130 | |
---|
| 131 | INTERFACE iom_read_dim |
---|
| 132 | MODULE PROCEDURE iom__read_dim_id |
---|
| 133 | MODULE PROCEDURE iom__read_dim_name |
---|
| 134 | END INTERFACE iom_read_dim |
---|
| 135 | |
---|
| 136 | INTERFACE iom_read_att !< read variable or global attribute in an opened file |
---|
[5037] | 137 | MODULE PROCEDURE iom__read_att_varname_id !< given variable name or standard name and attribute id. |
---|
| 138 | MODULE PROCEDURE iom__read_att_varid_id !< given variable id and attribute id. |
---|
| 139 | MODULE PROCEDURE iom__read_att_varname_name !< given variable name or standard name, and attribute name. |
---|
| 140 | MODULE PROCEDURE iom__read_att_varid_name !< given variable id and attribute name. |
---|
[4213] | 141 | END INTERFACE iom_read_att |
---|
| 142 | |
---|
| 143 | CONTAINS |
---|
| 144 | !------------------------------------------------------------------- |
---|
[5037] | 145 | !> @brief This function open a file in read or write mode |
---|
| 146 | !> @details |
---|
[4213] | 147 | !> If try to open a file in write mode that did not exist, create it.<br/> |
---|
| 148 | !> |
---|
[5037] | 149 | !> If file exist, get information about: |
---|
[4213] | 150 | !> - the number of variables |
---|
| 151 | !> - the number of dimensions |
---|
| 152 | !> - the number of global attributes |
---|
| 153 | !> - the ID of the unlimited dimension |
---|
| 154 | !> - the file format |
---|
| 155 | !> and finally read dimensions. |
---|
| 156 | !> |
---|
| 157 | !> @author J.Paul |
---|
[5617] | 158 | !> @date November, 2013 - Initial Version |
---|
[4213] | 159 | ! |
---|
[5037] | 160 | !> @param[inout] td_file file structure |
---|
[4213] | 161 | !------------------------------------------------------------------- |
---|
| 162 | SUBROUTINE iom_open(td_file) |
---|
| 163 | IMPLICIT NONE |
---|
| 164 | ! Argument |
---|
| 165 | TYPE(TFILE), INTENT(INOUT) :: td_file |
---|
| 166 | !---------------------------------------------------------------- |
---|
| 167 | |
---|
| 168 | ! add suffix to file name |
---|
| 169 | td_file%c_name = file_add_suffix( TRIM(td_file%c_name), & |
---|
| 170 | & TRIM(td_file%c_type) ) |
---|
| 171 | ! check type |
---|
| 172 | SELECT CASE(TRIM(ADJUSTL(fct_lower(td_file%c_type)))) |
---|
| 173 | |
---|
| 174 | CASE('cdf') |
---|
| 175 | CALL iom_cdf_open(td_file) |
---|
| 176 | CASE('dimg') |
---|
| 177 | CALL iom_rstdimg_open(td_file) |
---|
| 178 | CASE DEFAULT |
---|
[5037] | 179 | CALL logger_error("IOM OPEN: unknow type : "//TRIM(td_file%c_name)) |
---|
[4213] | 180 | |
---|
| 181 | END SELECT |
---|
| 182 | |
---|
| 183 | END SUBROUTINE iom_open |
---|
| 184 | !------------------------------------------------------------------- |
---|
[5037] | 185 | !> @brief This function create a file. |
---|
[4213] | 186 | !> |
---|
| 187 | !> @author J.Paul |
---|
[5617] | 188 | !> @date November, 2013 - Initial Version |
---|
[4213] | 189 | ! |
---|
[5037] | 190 | !> @param[inout] td_file file structure |
---|
[4213] | 191 | !------------------------------------------------------------------- |
---|
| 192 | SUBROUTINE iom_create(td_file) |
---|
| 193 | IMPLICIT NONE |
---|
| 194 | ! Argument |
---|
| 195 | TYPE(TFILE), INTENT(INOUT) :: td_file |
---|
| 196 | |
---|
| 197 | ! local variable |
---|
| 198 | LOGICAL :: ll_exist |
---|
| 199 | !---------------------------------------------------------------- |
---|
| 200 | |
---|
| 201 | INQUIRE(FILE=TRIM(td_file%c_name), EXIST=ll_exist ) |
---|
| 202 | IF( ll_exist )THEN |
---|
| 203 | CALL logger_fatal("IOM CREATE: can not create file "//& |
---|
| 204 | & TRIM(td_file%c_name)//". file exist already.") |
---|
| 205 | ENDIF |
---|
| 206 | |
---|
| 207 | ! forced to open in write mode |
---|
| 208 | td_file%l_wrt=.TRUE. |
---|
| 209 | ! check type |
---|
| 210 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 211 | CASE('cdf') |
---|
| 212 | CALL iom_cdf_open(td_file) |
---|
| 213 | CASE('dimg') |
---|
| 214 | CALL iom_rstdimg_open(td_file) |
---|
| 215 | CASE DEFAULT |
---|
[5037] | 216 | CALL logger_error( "IOM CREATE: can't create file "//& |
---|
[4213] | 217 | & TRIM(td_file%c_name)//": type unknown " ) |
---|
| 218 | END SELECT |
---|
| 219 | |
---|
| 220 | END SUBROUTINE iom_create |
---|
| 221 | !------------------------------------------------------------------- |
---|
| 222 | !> @brief This subroutine close file |
---|
| 223 | !> |
---|
| 224 | !> @author J.Paul |
---|
[5617] | 225 | !> @date November, 2013 - Initial Version |
---|
[4213] | 226 | ! |
---|
[5037] | 227 | !> @param[inout] td_file file structure |
---|
[4213] | 228 | !------------------------------------------------------------------- |
---|
| 229 | SUBROUTINE iom_close(td_file) |
---|
| 230 | IMPLICIT NONE |
---|
| 231 | ! Argument |
---|
| 232 | TYPE(TFILE), INTENT(INOUT) :: td_file |
---|
| 233 | !---------------------------------------------------------------- |
---|
| 234 | |
---|
| 235 | ! open file |
---|
| 236 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 237 | CASE('cdf') |
---|
| 238 | CALL iom_cdf_close(td_file) |
---|
| 239 | CASE('dimg') |
---|
| 240 | CALL iom_rstdimg_close(td_file) |
---|
| 241 | CASE DEFAULT |
---|
[5037] | 242 | CALL logger_error( "IOM CLOSE: can't close file "//& |
---|
[4213] | 243 | & TRIM(td_file%c_name)//": type unknown " ) |
---|
| 244 | END SELECT |
---|
| 245 | |
---|
| 246 | END SUBROUTINE iom_close |
---|
| 247 | !------------------------------------------------------------------- |
---|
| 248 | !> @brief This function read attribute (of variable or global) in an opened |
---|
| 249 | !> file, given variable name or standard name and attribute id. |
---|
[5037] | 250 | !> @details |
---|
| 251 | !> - to get global attribute use 'GLOBAL' as variable name. |
---|
[4213] | 252 | ! |
---|
| 253 | !> @author J.Paul |
---|
[5617] | 254 | !> @date November, 2013 - Initial Version |
---|
[4213] | 255 | ! |
---|
[5037] | 256 | !> @param[in] td_file file structure |
---|
| 257 | !> @param[in] cd_varname variable name. use 'GLOBAL' to read global |
---|
[4213] | 258 | !> attribute in a file |
---|
[5037] | 259 | !> @param[in] id_attid attribute id |
---|
[4213] | 260 | !> @return attribute structure |
---|
| 261 | !------------------------------------------------------------------- |
---|
[5037] | 262 | TYPE(TATT) FUNCTION iom__read_att_varname_id( td_file, cd_varname, & |
---|
| 263 | & id_attid) |
---|
[4213] | 264 | IMPLICIT NONE |
---|
| 265 | ! Argument |
---|
| 266 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 267 | CHARACTER(LEN=lc), INTENT(IN) :: cd_varname |
---|
| 268 | INTEGER(i4), INTENT(IN) :: id_attid |
---|
| 269 | |
---|
| 270 | ! local variable |
---|
| 271 | INTEGER(i4) :: il_varid |
---|
| 272 | !---------------------------------------------------------------- |
---|
| 273 | |
---|
| 274 | ! get variable id |
---|
| 275 | IF( TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN |
---|
| 276 | il_varid=NF90_GLOBAL |
---|
| 277 | ELSE |
---|
| 278 | il_varid=var_get_id(td_file%t_var(:), cd_varname) |
---|
| 279 | ENDIF |
---|
| 280 | |
---|
| 281 | IF( il_varid /= 0 .OR. TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN |
---|
| 282 | ! open file |
---|
| 283 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 284 | CASE('cdf') |
---|
[5037] | 285 | iom__read_att_varname_id=iom_read_att( td_file, il_varid, & |
---|
[4213] | 286 | & id_attid) |
---|
| 287 | CASE('dimg') |
---|
[5037] | 288 | CALL logger_warn( " IOM READ ATT: can't read attribute "//& |
---|
[4213] | 289 | & "in dimg file : "//TRIM(td_file%c_name) ) |
---|
| 290 | CASE DEFAULT |
---|
[5037] | 291 | CALL logger_error( " IOM READ ATT: can't read attribute "//& |
---|
| 292 | & " in file "//TRIM(td_file%c_name)//" : type unknown " ) |
---|
[4213] | 293 | END SELECT |
---|
| 294 | ENDIF |
---|
| 295 | |
---|
[5037] | 296 | END FUNCTION iom__read_att_varname_id |
---|
[4213] | 297 | !------------------------------------------------------------------- |
---|
| 298 | !> @brief This function read attribute (of variable or global) in an opened |
---|
| 299 | !> file, given variable id and attribute id. |
---|
| 300 | !> |
---|
| 301 | !> @author J.Paul |
---|
[5617] | 302 | !> @date November, 2013 - Initial Version |
---|
[4213] | 303 | ! |
---|
[5037] | 304 | !> @param[in] td_file file structure |
---|
| 305 | !> @param[in] id_varid variable id. use NF90_GLOBAL to read global |
---|
[4213] | 306 | !> attribute in a file |
---|
[5037] | 307 | !> @param[in] id_attid attribute id |
---|
[4213] | 308 | !> @return attribute structure |
---|
| 309 | !------------------------------------------------------------------- |
---|
[5037] | 310 | TYPE(TATT) FUNCTION iom__read_att_varid_id( td_file, id_varid, & |
---|
[4213] | 311 | & id_attid) |
---|
| 312 | IMPLICIT NONE |
---|
| 313 | ! Argument |
---|
| 314 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 315 | INTEGER(i4), INTENT(IN) :: id_varid |
---|
| 316 | INTEGER(i4), INTENT(IN) :: id_attid |
---|
| 317 | !---------------------------------------------------------------- |
---|
| 318 | |
---|
| 319 | ! open file |
---|
| 320 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 321 | CASE('cdf') |
---|
[5037] | 322 | iom__read_att_varid_id=iom_cdf_read_att( td_file, id_varid, & |
---|
[4213] | 323 | & id_attid) |
---|
| 324 | CASE('dimg') |
---|
[5037] | 325 | CALL logger_warn( " IOM READ ATT: can't read attribute in dimg file "//& |
---|
[4213] | 326 | & TRIM(td_file%c_name) ) |
---|
| 327 | CASE DEFAULT |
---|
[5037] | 328 | CALL logger_error( " IOM READ ATT: can't read attribute in file "//& |
---|
[4213] | 329 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 330 | END SELECT |
---|
| 331 | |
---|
[5037] | 332 | END FUNCTION iom__read_att_varid_id |
---|
[4213] | 333 | !------------------------------------------------------------------- |
---|
| 334 | !> @brief This function read attribute (of variable or global) in an opened |
---|
| 335 | !> file, given variable name or standard name, and attribute name. |
---|
[5037] | 336 | !> @details |
---|
| 337 | !> - to get global attribute use 'GLOBAL' as variable name. |
---|
[4213] | 338 | ! |
---|
| 339 | !> @author J.Paul |
---|
[5617] | 340 | !> @date November, 2013 - Initial Version |
---|
[4213] | 341 | ! |
---|
[5037] | 342 | !> @param[in] td_file file structure |
---|
| 343 | !> @param[in] cd_varname variable name or standard name. use 'GLOBAL' to read global |
---|
[4213] | 344 | !> attribute in a file |
---|
[5037] | 345 | !> @param[in] cd_attname attribute name |
---|
[4213] | 346 | !> @return attribute structure |
---|
| 347 | !------------------------------------------------------------------- |
---|
[5037] | 348 | TYPE(TATT) FUNCTION iom__read_att_varname_name( td_file, cd_varname, & |
---|
[4213] | 349 | & cd_attname) |
---|
| 350 | IMPLICIT NONE |
---|
| 351 | ! Argument |
---|
| 352 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 353 | CHARACTER(LEN=*), INTENT(IN) :: cd_varname |
---|
| 354 | CHARACTER(LEN=*), INTENT(IN) :: cd_attname |
---|
| 355 | |
---|
| 356 | ! local variable |
---|
| 357 | INTEGER(i4) :: il_varid |
---|
| 358 | !---------------------------------------------------------------- |
---|
| 359 | |
---|
| 360 | ! get variable id |
---|
| 361 | IF( TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN |
---|
| 362 | il_varid=NF90_GLOBAL |
---|
| 363 | ELSE |
---|
| 364 | il_varid=var_get_id(td_file%t_var(:), cd_varname) |
---|
| 365 | ENDIF |
---|
| 366 | |
---|
| 367 | IF( il_varid /= 0 .OR. TRIM(fct_upper(cd_varname)) == 'GLOBAL' )THEN |
---|
| 368 | ! open file |
---|
| 369 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 370 | CASE('cdf') |
---|
[5037] | 371 | iom__read_att_varname_name=iom_cdf_read_att( td_file, il_varid, & |
---|
[4213] | 372 | & cd_attname) |
---|
| 373 | CASE('dimg') |
---|
[5037] | 374 | CALL logger_warn( " IOM READ ATT: can't read attribute "//& |
---|
[4213] | 375 | & "in dimg file :"//TRIM(td_file%c_name) ) |
---|
| 376 | CASE DEFAULT |
---|
[5037] | 377 | CALL logger_error( " IOM READ ATT: can't read attribute in file "//& |
---|
[4213] | 378 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 379 | END SELECT |
---|
| 380 | ENDIF |
---|
| 381 | |
---|
[5037] | 382 | END FUNCTION iom__read_att_varname_name |
---|
[4213] | 383 | !------------------------------------------------------------------- |
---|
| 384 | !> @brief This function read attribute (of variable or global) in an opened |
---|
| 385 | !> file, given variable id and attribute name. |
---|
| 386 | ! |
---|
| 387 | !> @author J.Paul |
---|
[5617] | 388 | !> @date November, 2013 - Initial Version |
---|
[4213] | 389 | ! |
---|
[5037] | 390 | !> @param[in] td_file file structure |
---|
| 391 | !> @param[in] id_varid variable id. use NF90_GLOBAL to read global |
---|
[4213] | 392 | !> attribute in a file |
---|
[5037] | 393 | !> @param[in] cd_attname attribute name |
---|
[4213] | 394 | !> @return attribute structure |
---|
| 395 | !------------------------------------------------------------------- |
---|
[5037] | 396 | TYPE(TATT) FUNCTION iom__read_att_varid_name( td_file, id_varid, & |
---|
[4213] | 397 | & cd_attname) |
---|
| 398 | IMPLICIT NONE |
---|
| 399 | ! Argument |
---|
| 400 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 401 | INTEGER(i4), INTENT(IN) :: id_varid |
---|
| 402 | CHARACTER(LEN=*), INTENT(IN) :: cd_attname |
---|
| 403 | !---------------------------------------------------------------- |
---|
| 404 | |
---|
| 405 | ! open file |
---|
| 406 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 407 | CASE('cdf') |
---|
[5037] | 408 | iom__read_att_varid_name=iom_cdf_read_att( td_file, id_varid, & |
---|
[4213] | 409 | & cd_attname) |
---|
| 410 | CASE('dimg') |
---|
[5037] | 411 | CALL logger_warn( " IOM READ ATT: can't read attribute in dimg file :"& |
---|
[4213] | 412 | & //TRIM(td_file%c_name) ) |
---|
| 413 | CASE DEFAULT |
---|
[5037] | 414 | CALL logger_error( " IOM READ ATT: can't read attribute in file "//& |
---|
[4213] | 415 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 416 | END SELECT |
---|
| 417 | |
---|
[5037] | 418 | END FUNCTION iom__read_att_varid_name |
---|
[4213] | 419 | !------------------------------------------------------------------- |
---|
| 420 | !> @brief This function read one dimension in an opened file, |
---|
| 421 | !> given dimension id. |
---|
| 422 | ! |
---|
| 423 | !> @author J.Paul |
---|
[5617] | 424 | !> @date November, 2013 - Initial Version |
---|
[4213] | 425 | ! |
---|
[5037] | 426 | !> @param[in] td_file file structure |
---|
| 427 | !> @param[in] id_dimid dimension id |
---|
[4213] | 428 | !> @return dimension structure |
---|
| 429 | !------------------------------------------------------------------- |
---|
| 430 | TYPE(TDIM) FUNCTION iom__read_dim_id(td_file, id_dimid) |
---|
| 431 | IMPLICIT NONE |
---|
| 432 | ! Argument |
---|
| 433 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 434 | INTEGER(i4), INTENT(IN) :: id_dimid |
---|
| 435 | !---------------------------------------------------------------- |
---|
| 436 | |
---|
| 437 | ! open file |
---|
| 438 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 439 | CASE('cdf') |
---|
| 440 | iom__read_dim_id=iom_cdf_read_dim(td_file, id_dimid) |
---|
| 441 | CASE('dimg') |
---|
| 442 | iom__read_dim_id=iom_rstdimg_read_dim(td_file, id_dimid) |
---|
| 443 | CASE DEFAULT |
---|
[5037] | 444 | CALL logger_error( " IOM READ DIM: can't read dimension in file "//& |
---|
[4213] | 445 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 446 | END SELECT |
---|
| 447 | |
---|
| 448 | END FUNCTION iom__read_dim_id |
---|
| 449 | !------------------------------------------------------------------- |
---|
| 450 | !> @brief This function read one dimension in an opened netcdf file, |
---|
| 451 | !> given dimension name. |
---|
| 452 | ! |
---|
| 453 | !> @author J.Paul |
---|
[5617] | 454 | !> @date November, 2013 - Initial Version |
---|
[4213] | 455 | ! |
---|
[5037] | 456 | !> @param[in] td_file file structure |
---|
| 457 | !> @param[in] cd_name dimension name |
---|
[4213] | 458 | !> @return dimension structure |
---|
| 459 | !------------------------------------------------------------------- |
---|
| 460 | TYPE(TDIM) FUNCTION iom__read_dim_name(td_file, cd_name) |
---|
| 461 | IMPLICIT NONE |
---|
| 462 | ! Argument |
---|
| 463 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 464 | CHARACTER(LEN=*), INTENT(IN) :: cd_name |
---|
| 465 | !---------------------------------------------------------------- |
---|
| 466 | |
---|
| 467 | ! open file |
---|
| 468 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 469 | CASE('cdf') |
---|
| 470 | iom__read_dim_name=iom_cdf_read_dim(td_file, cd_name) |
---|
| 471 | CASE('dimg') |
---|
| 472 | iom__read_dim_name=iom_rstdimg_read_dim(td_file, cd_name) |
---|
| 473 | CASE DEFAULT |
---|
[5037] | 474 | CALL logger_error( " IOM READ DIM: can't read dimension in file "//& |
---|
[4213] | 475 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 476 | END SELECT |
---|
| 477 | |
---|
| 478 | END FUNCTION iom__read_dim_name |
---|
| 479 | !------------------------------------------------------------------- |
---|
| 480 | !> @brief This function read variable value in an opened |
---|
[5037] | 481 | !> file, given variable id. |
---|
| 482 | !> @details |
---|
[4213] | 483 | !> start indices and number of indices selected along each dimension |
---|
[5037] | 484 | !> could be specify in a 4 dimension array (/'x','y','z','t'/) |
---|
[4213] | 485 | ! |
---|
| 486 | !> @author J.Paul |
---|
[5617] | 487 | !> @date November, 2013 - Initial Version |
---|
[4213] | 488 | ! |
---|
[5037] | 489 | !> @param[in] td_file file structure |
---|
| 490 | !> @param[in] id_varid variable id |
---|
| 491 | !> @param[in] id_start index in the variable from which the data values |
---|
[4213] | 492 | !> will be read |
---|
[5037] | 493 | !> @param[in] id_count number of indices selected along each dimension |
---|
[4213] | 494 | !> @return variable structure |
---|
| 495 | !------------------------------------------------------------------- |
---|
| 496 | TYPE(TVAR) FUNCTION iom__read_var_id( td_file, id_varid,& |
---|
| 497 | & id_start, id_count) |
---|
| 498 | IMPLICIT NONE |
---|
| 499 | ! Argument |
---|
| 500 | TYPE(TFILE), INTENT(IN) :: td_file |
---|
| 501 | INTEGER(i4), INTENT(IN) :: id_varid |
---|
| 502 | INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_start |
---|
| 503 | INTEGER(i4), DIMENSION(ip_maxdim), INTENT(IN), OPTIONAL :: id_count |
---|
| 504 | !---------------------------------------------------------------- |
---|
| 505 | |
---|
| 506 | ! open file |
---|
| 507 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 508 | CASE('cdf') |
---|
| 509 | iom__read_var_id=iom_cdf_read_var(td_file, id_varid, & |
---|
| 510 | & id_start, id_count) |
---|
| 511 | CASE('dimg') |
---|
| 512 | iom__read_var_id=iom_rstdimg_read_var(td_file, id_varid, & |
---|
| 513 | & id_start, id_count) |
---|
| 514 | CASE DEFAULT |
---|
[5037] | 515 | CALL logger_error( " IOM READ VAR: can't read variable in file "//& |
---|
[4213] | 516 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 517 | END SELECT |
---|
| 518 | |
---|
| 519 | END FUNCTION iom__read_var_id |
---|
| 520 | !------------------------------------------------------------------- |
---|
| 521 | !> @brief This function read variable value in an opened |
---|
[5037] | 522 | !> file, given variable name or standard name. |
---|
| 523 | !> @details |
---|
[4213] | 524 | !> start indices and number of indices selected along each dimension |
---|
[5037] | 525 | !> could be specify in a 4 dimension array (/'x','y','z','t'/) |
---|
| 526 | !> |
---|
[4213] | 527 | !> look first for variable name. If it doesn't |
---|
| 528 | !> exist in file, look for variable standard name.<br/> |
---|
| 529 | ! |
---|
| 530 | !> @author J.Paul |
---|
[5617] | 531 | !> @date November, 2013 - Initial Version |
---|
[4213] | 532 | ! |
---|
[5037] | 533 | !> @param[in] td_file file structure |
---|
| 534 | !> @param[in] cd_name variable name or standard name |
---|
| 535 | !> @param[in] id_start index in the variable from which the data values |
---|
[4213] | 536 | !> will be read |
---|
[5037] | 537 | !> @param[in] id_count number of indices selected along each dimension |
---|
[4213] | 538 | !> @return variable structure |
---|
| 539 | !------------------------------------------------------------------- |
---|
| 540 | TYPE(TVAR) FUNCTION iom__read_var_name(td_file, cd_name, & |
---|
| 541 | & id_start, id_count ) |
---|
| 542 | IMPLICIT NONE |
---|
| 543 | ! Argument |
---|
| 544 | TYPE(TFILE) , INTENT(IN) :: td_file |
---|
[5037] | 545 | CHARACTER(LEN=*) , INTENT(IN) :: cd_name |
---|
[4213] | 546 | INTEGER(i4) , DIMENSION(:), INTENT(IN), OPTIONAL :: id_start |
---|
| 547 | INTEGER(i4) , DIMENSION(:), INTENT(IN), OPTIONAL :: id_count |
---|
| 548 | !---------------------------------------------------------------- |
---|
| 549 | |
---|
| 550 | ! open file |
---|
| 551 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 552 | CASE('cdf') |
---|
| 553 | iom__read_var_name=iom_cdf_read_var(td_file, cd_name, & |
---|
| 554 | & id_start, id_count ) |
---|
| 555 | CASE('dimg') |
---|
| 556 | iom__read_var_name=iom_rstdimg_read_var(td_file, cd_name, & |
---|
| 557 | & id_start, id_count ) |
---|
| 558 | CASE DEFAULT |
---|
[5037] | 559 | CALL logger_error( " IOM READ VAR: can't read variable in file "//& |
---|
[4213] | 560 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 561 | END SELECT |
---|
| 562 | |
---|
| 563 | END FUNCTION iom__read_var_name |
---|
| 564 | !------------------------------------------------------------------- |
---|
| 565 | !> @brief This subroutine write file structure in an opened file. |
---|
[5609] | 566 | !> |
---|
| 567 | !> @details |
---|
| 568 | !> optionally, you could specify dimension order (default 'xyzt') |
---|
| 569 | !> |
---|
[4213] | 570 | !> @author J.Paul |
---|
[5617] | 571 | !> @date November, 2013 - Initial Version |
---|
[5609] | 572 | !> @date July, 2015 - add dimension order option |
---|
[4213] | 573 | ! |
---|
[5037] | 574 | !> @param[in] td_file file structure |
---|
[4213] | 575 | !------------------------------------------------------------------- |
---|
[5609] | 576 | SUBROUTINE iom_write_file(td_file, cd_dimorder) |
---|
[4213] | 577 | IMPLICIT NONE |
---|
| 578 | ! Argument |
---|
[5609] | 579 | TYPE(TFILE) , INTENT(INOUT) :: td_file |
---|
| 580 | CHARACTER(LEN=*), INTENT(IN ), OPTIONAL :: cd_dimorder |
---|
[4213] | 581 | !---------------------------------------------------------------- |
---|
| 582 | |
---|
| 583 | ! open file |
---|
| 584 | SELECT CASE(TRIM(td_file%c_type)) |
---|
| 585 | CASE('cdf') |
---|
[5609] | 586 | CALL iom_cdf_write_file(td_file, cd_dimorder) |
---|
[4213] | 587 | CASE('dimg') |
---|
[5609] | 588 | ! note: can not change dimension order in restart dimg file |
---|
[4213] | 589 | CALL iom_rstdimg_write_file(td_file) |
---|
| 590 | CASE DEFAULT |
---|
[5037] | 591 | CALL logger_error( " IOM WRITE: can't write file "//& |
---|
[4213] | 592 | & TRIM(td_file%c_name)//" : type unknown " ) |
---|
| 593 | END SELECT |
---|
| 594 | |
---|
| 595 | END SUBROUTINE iom_write_file |
---|
| 596 | END MODULE iom |
---|
| 597 | |
---|