[1575] | 1 | ! $Id$ |
---|
[1019] | 2 | #ifdef CPP_XIOS |
---|
| 3 | MODULE wxios |
---|
| 4 | USE xios |
---|
| 5 | USE iaxis |
---|
| 6 | USE iaxis_attr |
---|
| 7 | USE icontext_attr |
---|
| 8 | USE idate |
---|
| 9 | USE idomain_attr |
---|
| 10 | USE ifield_attr |
---|
| 11 | USE ifile_attr |
---|
| 12 | USE ixml_tree |
---|
| 13 | |
---|
| 14 | !Variables disponibles pendant toute l'execution du programme: |
---|
| 15 | |
---|
| 16 | INTEGER, SAVE :: g_comm |
---|
[1682] | 17 | CHARACTER(len=100), SAVE :: g_ctx_name ="LMDZ" |
---|
[1019] | 18 | TYPE(xios_context), SAVE :: g_ctx |
---|
| 19 | !$OMP THREADPRIVATE(g_comm,g_cts_name,g_ctx) |
---|
[1300] | 20 | LOGICAL, SAVE :: g_flag_xml = .FALSE. |
---|
| 21 | CHARACTER(len=100) :: g_field_name = "nofield" |
---|
| 22 | !$OMP THREADPRIVATE(g_flag_xml,g_field_name) |
---|
[1508] | 23 | REAL :: missing_val_omp |
---|
| 24 | REAL :: missing_val |
---|
| 25 | !$OMP THREADPRIVATE(missing_val) |
---|
[1019] | 26 | |
---|
[1650] | 27 | #ifdef XIOS1 |
---|
| 28 | #error "XIOS v1 no longer supported, use XIOS v2." |
---|
| 29 | #endif |
---|
| 30 | |
---|
[1019] | 31 | CONTAINS |
---|
| 32 | |
---|
| 33 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 34 | ! 36day => 36d etc !!!!!!!!!!!!!!!!!!!! |
---|
| 35 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 36 | |
---|
| 37 | SUBROUTINE reformadate(odate, ndate) |
---|
| 38 | CHARACTER(len=*), INTENT(IN) :: odate |
---|
[1575] | 39 | TYPE(xios_duration) :: ndate |
---|
[1019] | 40 | |
---|
| 41 | INTEGER :: i = 0 |
---|
[1300] | 42 | !!!!!!!!!!!!!!!!!! |
---|
| 43 | ! Pour XIOS: |
---|
| 44 | ! year : y |
---|
| 45 | ! month : mo |
---|
| 46 | ! day : d |
---|
| 47 | ! hour : h |
---|
| 48 | ! minute : mi |
---|
| 49 | ! second : s |
---|
| 50 | !!!!!!!!!!!!!!!!!! |
---|
| 51 | |
---|
[1019] | 52 | i = INDEX(odate, "day") |
---|
| 53 | IF (i > 0) THEN |
---|
[1575] | 54 | read(odate(1:i-1),*) ndate%day |
---|
[1019] | 55 | END IF |
---|
[1300] | 56 | |
---|
| 57 | i = INDEX(odate, "hr") |
---|
| 58 | IF (i > 0) THEN |
---|
[1575] | 59 | read(odate(1:i-1),*) ndate%hour |
---|
[1300] | 60 | END IF |
---|
| 61 | |
---|
| 62 | i = INDEX(odate, "mth") |
---|
| 63 | IF (i > 0) THEN |
---|
[1575] | 64 | read(odate(1:i-1),*) ndate%month |
---|
[1300] | 65 | END IF |
---|
[1019] | 66 | |
---|
[1300] | 67 | !IF (prt_level >= 10) WRITE(lunout,*) "Xios. ", odate, " => ", ndate |
---|
[1019] | 68 | END SUBROUTINE reformadate |
---|
| 69 | |
---|
| 70 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 71 | ! ave(X) => average etc !!!!!!!!!!!!!!! |
---|
| 72 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 73 | |
---|
| 74 | CHARACTER(len=7) FUNCTION reformaop(op) |
---|
| 75 | CHARACTER(len=*), INTENT(IN) :: op |
---|
| 76 | |
---|
| 77 | INTEGER :: i = 0 |
---|
| 78 | reformaop = "average" |
---|
| 79 | |
---|
| 80 | IF (op.EQ."inst(X)") THEN |
---|
| 81 | reformaop = "instant" |
---|
| 82 | END IF |
---|
| 83 | |
---|
| 84 | IF (op.EQ."once") THEN |
---|
| 85 | reformaop = "once" |
---|
| 86 | END IF |
---|
| 87 | |
---|
| 88 | IF (op.EQ."t_max(X)") THEN |
---|
| 89 | reformaop = "maximum" |
---|
| 90 | END IF |
---|
| 91 | |
---|
| 92 | IF (op.EQ."t_min(X)") THEN |
---|
| 93 | reformaop = "minimum" |
---|
| 94 | END IF |
---|
| 95 | |
---|
[1300] | 96 | !IF (prt_level >= 10) WRITE(lunout,*) "Xios. ", op, " => ", reformaop |
---|
[1019] | 97 | END FUNCTION reformaop |
---|
| 98 | |
---|
| 99 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 100 | ! Routine d'initialisation !!!!!!!!!!!!! |
---|
[1441] | 101 | ! A lancer juste après mpi_init !!!!!!!!!!!!! |
---|
[1019] | 102 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 103 | |
---|
[1302] | 104 | SUBROUTINE wxios_init(xios_ctx_name, locom, outcom, type_ocean) |
---|
[1575] | 105 | USE print_control_mod, ONLY : prt_level, lunout |
---|
[1300] | 106 | IMPLICIT NONE |
---|
| 107 | |
---|
[1019] | 108 | CHARACTER(len=*), INTENT(IN) :: xios_ctx_name |
---|
[1300] | 109 | INTEGER, INTENT(IN), OPTIONAL :: locom |
---|
| 110 | INTEGER, INTENT(OUT), OPTIONAL :: outcom |
---|
[1302] | 111 | CHARACTER(len=6), INTENT(IN), OPTIONAL :: type_ocean |
---|
[1300] | 112 | |
---|
| 113 | |
---|
[1019] | 114 | TYPE(xios_context) :: xios_ctx |
---|
[1300] | 115 | INTEGER :: xios_comm |
---|
[1019] | 116 | |
---|
[1300] | 117 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_init: Initialization" |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | IF (PRESENT(locom)) THEN |
---|
| 122 | CALL xios_initialize(xios_ctx_name, local_comm = locom, return_comm = xios_comm ) |
---|
| 123 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_init: ctx=",xios_ctx_name," local_comm=",locom,", return_comm=",xios_comm |
---|
| 124 | ELSE |
---|
| 125 | CALL xios_initialize(xios_ctx_name, return_comm = xios_comm ) |
---|
| 126 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_init: ctx=",xios_ctx_name," return_comm=",xios_comm |
---|
| 127 | END IF |
---|
[1019] | 128 | |
---|
[1300] | 129 | IF (PRESENT(outcom)) THEN |
---|
| 130 | outcom = xios_comm |
---|
| 131 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_init: ctx=",xios_ctx_name," outcom=",outcom |
---|
| 132 | END IF |
---|
[1019] | 133 | |
---|
| 134 | !Enregistrement des variables globales: |
---|
| 135 | g_comm = xios_comm |
---|
| 136 | g_ctx_name = xios_ctx_name |
---|
| 137 | |
---|
[1682] | 138 | ! ! Si couple alors init fait dans cpl_init |
---|
| 139 | ! IF (.not. PRESENT(type_ocean)) THEN |
---|
| 140 | ! CALL wxios_context_init() |
---|
| 141 | ! ENDIF |
---|
[1302] | 142 | |
---|
[1019] | 143 | END SUBROUTINE wxios_init |
---|
| 144 | |
---|
[1300] | 145 | SUBROUTINE wxios_context_init() |
---|
[1575] | 146 | USE print_control_mod, ONLY : prt_level, lunout |
---|
[1682] | 147 | USE mod_phys_lmdz_mpi_data, ONLY : COMM_LMDZ_PHY |
---|
[1300] | 148 | IMPLICIT NONE |
---|
| 149 | |
---|
| 150 | TYPE(xios_context) :: xios_ctx |
---|
| 151 | |
---|
[1575] | 152 | !$OMP MASTER |
---|
[1300] | 153 | !Initialisation du contexte: |
---|
[1682] | 154 | CALL xios_context_initialize(g_ctx_name, COMM_LMDZ_PHY) |
---|
[1441] | 155 | CALL xios_get_handle(g_ctx_name, xios_ctx) !Récupération |
---|
[1300] | 156 | CALL xios_set_current_context(xios_ctx) !Activation |
---|
| 157 | g_ctx = xios_ctx |
---|
| 158 | |
---|
[1302] | 159 | IF (prt_level >= 10) THEN |
---|
| 160 | WRITE(lunout,*) "wxios_context_init: Current context is ",trim(g_ctx_name) |
---|
| 161 | WRITE(lunout,*) " now call xios_solve_inheritance()" |
---|
| 162 | ENDIF |
---|
[1441] | 163 | !Une première analyse des héritages: |
---|
[1300] | 164 | CALL xios_solve_inheritance() |
---|
[1575] | 165 | !$OMP END MASTER |
---|
[1300] | 166 | END SUBROUTINE wxios_context_init |
---|
| 167 | |
---|
[1682] | 168 | |
---|
| 169 | SUBROUTINE wxios_set_context() |
---|
| 170 | IMPLICIT NONE |
---|
| 171 | TYPE(xios_context) :: xios_ctx |
---|
| 172 | |
---|
| 173 | !$OMP MASTER |
---|
| 174 | CALL xios_get_handle(g_ctx_name, xios_ctx) !Récupération |
---|
| 175 | CALL xios_set_current_context(xios_ctx) !Activation |
---|
| 176 | !$OMP END MASTER |
---|
| 177 | |
---|
| 178 | END SUBROUTINE wxios_set_context |
---|
| 179 | |
---|
[1019] | 180 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1441] | 181 | ! Routine de paramétrisation !!!!!!!!!!!!!!!!!! |
---|
[1019] | 182 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 183 | |
---|
[1441] | 184 | SUBROUTINE wxios_set_cal(pasdetemps, calendrier, annee, mois, jour, heure, ini_an, ini_mois, ini_jour, ini_heure) |
---|
[1575] | 185 | USE print_control_mod, ONLY : prt_level, lunout |
---|
[1300] | 186 | IMPLICIT NONE |
---|
| 187 | |
---|
[1441] | 188 | !Paramètres: |
---|
[1019] | 189 | CHARACTER(len=*), INTENT(IN) :: calendrier |
---|
[1441] | 190 | INTEGER, INTENT(IN) :: annee, mois, jour, ini_an, ini_mois, ini_jour |
---|
| 191 | REAL, INTENT(IN) :: pasdetemps, heure, ini_heure |
---|
[1019] | 192 | |
---|
| 193 | !Variables: |
---|
| 194 | CHARACTER(len=80) :: abort_message |
---|
| 195 | CHARACTER(len=19) :: date |
---|
| 196 | INTEGER :: njour = 1 |
---|
| 197 | |
---|
| 198 | !Variables pour xios: |
---|
[1575] | 199 | TYPE(xios_duration) :: mdtime |
---|
[1019] | 200 | !REAL(kind = 8) :: year=0, month=0, day=0, hour=0, minute=0, second=0 |
---|
| 201 | |
---|
[1575] | 202 | mdtime%second=pasdetemps |
---|
[1019] | 203 | |
---|
[1441] | 204 | !Réglage du calendrier: |
---|
[1019] | 205 | SELECT CASE (calendrier) |
---|
| 206 | CASE('earth_360d') |
---|
[1575] | 207 | CALL xios_define_calendar("D360") |
---|
| 208 | IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 360 jours/an' |
---|
| 209 | CASE('earth_365d') |
---|
| 210 | CALL xios_define_calendar("NoLeap") |
---|
| 211 | IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier terrestre a 365 jours/an' |
---|
| 212 | CASE('gregorian') |
---|
| 213 | CALL xios_define_calendar("Gregorian") |
---|
| 214 | IF (prt_level >= 10) WRITE(lunout,*) 'wxios_set_cal: Calendrier gregorien' |
---|
| 215 | CASE DEFAULT |
---|
| 216 | abort_message = 'wxios_set_cal: Mauvais choix de calendrier' |
---|
[1682] | 217 | CALL abort_physic('Gcm:Xios',abort_message,1) |
---|
[1575] | 218 | END SELECT |
---|
[1019] | 219 | |
---|
[1441] | 220 | !Formatage de la date d'origine: |
---|
[1575] | 221 | WRITE(date, "(i4.4,'-',i2.2,'-',i2.2,' ',i2.2,':00:00')") annee, mois, jour, int(heure) |
---|
[1019] | 222 | |
---|
[1441] | 223 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: Time origin: ", date |
---|
[1682] | 224 | |
---|
[1575] | 225 | CALL xios_set_time_origin(xios_date(annee,mois,jour,int(heure),0,0)) |
---|
[1441] | 226 | |
---|
| 227 | !Formatage de la date de debut: |
---|
| 228 | |
---|
| 229 | WRITE(date, "(i4.4,'-',i2.2,'-',i2.2,' ',i2.2,':00:00')") ini_an, ini_mois, ini_jour, int(ini_heure) |
---|
[1019] | 230 | |
---|
[1441] | 231 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: Start date: ", date |
---|
| 232 | |
---|
[1575] | 233 | CALL xios_set_start_date(xios_date(ini_an,ini_mois,ini_jour,int(ini_heure),0,0)) |
---|
[1441] | 234 | |
---|
[1019] | 235 | !Et enfin,le pas de temps: |
---|
| 236 | CALL xios_set_timestep(mdtime) |
---|
[1300] | 237 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_set_cal: ts=",mdtime |
---|
[1019] | 238 | END SUBROUTINE wxios_set_cal |
---|
| 239 | |
---|
[1300] | 240 | SUBROUTINE wxios_set_timestep(ts) |
---|
| 241 | REAL, INTENT(IN) :: ts |
---|
[1575] | 242 | TYPE(xios_duration) :: mdtime |
---|
[1300] | 243 | |
---|
[1575] | 244 | mdtime%timestep = ts |
---|
| 245 | |
---|
[1300] | 246 | CALL xios_set_timestep(mdtime) |
---|
| 247 | END SUBROUTINE wxios_set_timestep |
---|
| 248 | |
---|
[1019] | 249 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 250 | ! Pour initialiser un domaine !!!!!!!!!!!!!!!!!!!! |
---|
| 251 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1682] | 252 | SUBROUTINE wxios_domain_param(dom_id,flip_coordinates) |
---|
| 253 | USE dimphy, only: klon |
---|
| 254 | USE mod_phys_lmdz_transfert_para, ONLY: gather, bcast |
---|
| 255 | USE mod_phys_lmdz_para, only: jj_nb, jj_begin, jj_end, ii_begin, ii_end, & |
---|
| 256 | mpi_size, mpi_rank, klon_mpi, & |
---|
| 257 | is_sequential, is_south_pole_dyn |
---|
| 258 | USE mod_grid_phy_lmdz, only: nbp_lon, nbp_lat, klon_glo |
---|
| 259 | USE print_control_mod, ONLY : prt_level, lunout |
---|
| 260 | USE geometry_mod |
---|
[1300] | 261 | |
---|
[1682] | 262 | IMPLICIT NONE |
---|
[1300] | 263 | CHARACTER(len=*),INTENT(IN) :: dom_id ! domain identifier |
---|
[1682] | 264 | LOGICAL,OPTIONAL,INTENT(IN) :: flip_coordinates ! .true. to change signs |
---|
| 265 | ! of coordinates |
---|
| 266 | LOGICAL :: flip_axes=.false. ! default; do not swap axes |
---|
| 267 | REAL :: rlat_glo(klon_glo) |
---|
| 268 | REAL :: rlon_glo(klon_glo) |
---|
| 269 | REAL :: io_lat(nbp_lat) |
---|
| 270 | REAL :: io_lon(nbp_lon) |
---|
| 271 | LOGICAL :: mask(nbp_lon,jj_nb) !Masque pour les problèmes de recouvrement MPI |
---|
[1019] | 272 | TYPE(xios_domain) :: dom |
---|
[1682] | 273 | INTEGER :: i |
---|
[1300] | 274 | LOGICAL :: boool |
---|
[1019] | 275 | |
---|
[1682] | 276 | |
---|
[1693] | 277 | IF (PRESENT(flip_coordinates)) flip_axes=flip_coordinates |
---|
| 278 | |
---|
[1682] | 279 | IF (flip_axes) THEN |
---|
| 280 | ! change signs of axes |
---|
| 281 | CALL gather(-latitude_deg,rlat_glo) |
---|
| 282 | CALL bcast(rlat_glo) |
---|
| 283 | CALL gather(-longitude_deg,rlon_glo) |
---|
| 284 | CALL bcast(rlon_glo) |
---|
| 285 | ELSE |
---|
| 286 | CALL gather(latitude_deg,rlat_glo) |
---|
| 287 | CALL bcast(rlat_glo) |
---|
| 288 | CALL gather(longitude_deg,rlon_glo) |
---|
| 289 | CALL bcast(rlon_glo) |
---|
| 290 | ENDIF |
---|
| 291 | |
---|
| 292 | !$OMP MASTER |
---|
| 293 | io_lat(1)=rlat_glo(1) |
---|
| 294 | io_lat(nbp_lat)=rlat_glo(klon_glo) |
---|
| 295 | IF ((nbp_lon*nbp_lat) > 1) then |
---|
| 296 | DO i=2,nbp_lat-1 |
---|
| 297 | io_lat(i)=rlat_glo(2+(i-2)*nbp_lon) |
---|
| 298 | ENDDO |
---|
| 299 | ENDIF |
---|
| 300 | |
---|
| 301 | IF (klon_glo == 1) THEN |
---|
| 302 | io_lon(1)=rlon_glo(1) |
---|
| 303 | ELSE |
---|
| 304 | io_lon(1:nbp_lon)=rlon_glo(2:nbp_lon+1) |
---|
| 305 | ENDIF |
---|
| 306 | |
---|
[1019] | 307 | |
---|
[1441] | 308 | !On récupère le handle: |
---|
[1019] | 309 | CALL xios_get_domain_handle(dom_id, dom) |
---|
| 310 | |
---|
| 311 | !On parametrise le domaine: |
---|
[1682] | 312 | CALL xios_set_domain_attr_hdl(dom, ni_glo=nbp_lon, ibegin=0, ni=nbp_lon, type="rectilinear") |
---|
| 313 | CALL xios_set_domain_attr_hdl(dom, nj_glo=nbp_lat, jbegin=jj_begin-1, nj=jj_nb, data_dim=2) |
---|
| 314 | CALL xios_set_domain_attr_hdl(dom, lonvalue_1d=io_lon(1:nbp_lon), latvalue_1d=io_lat(jj_begin:jj_end)) |
---|
| 315 | |
---|
[1300] | 316 | IF (.NOT.is_sequential) THEN |
---|
| 317 | mask(:,:)=.TRUE. |
---|
| 318 | if (ii_begin>1) mask(1:ii_begin-1,1) = .FALSE. |
---|
[1682] | 319 | if (ii_end<nbp_lon) mask(ii_end+1:nbp_lon,jj_nb) = .FALSE. |
---|
[1300] | 320 | ! special case for south pole |
---|
[1682] | 321 | if ((ii_end==1).and.(is_south_pole_dyn)) mask(1:nbp_lon,jj_nb)=.true. |
---|
[1300] | 322 | IF (prt_level >= 10) THEN |
---|
| 323 | WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,1)=",mask(:,1) |
---|
[1682] | 324 | WRITE(lunout,*) "wxios_domain_param: mpirank=",mpi_rank," mask(:,jj_nb)=",mask(:,jj_nb) |
---|
[1300] | 325 | ENDIF |
---|
[1575] | 326 | CALL xios_set_domain_attr_hdl(dom, mask_2d=mask) |
---|
[1300] | 327 | END IF |
---|
| 328 | |
---|
[1019] | 329 | CALL xios_is_defined_domain_attr_hdl(dom,ni_glo=boool) |
---|
[1441] | 330 | !Vérification: |
---|
[1019] | 331 | IF (xios_is_valid_domain(dom_id)) THEN |
---|
[1300] | 332 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_domain_param: Domain initialized: ", trim(dom_id), boool |
---|
[1019] | 333 | ELSE |
---|
[1300] | 334 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_domain_param: Invalid domain: ", trim(dom_id) |
---|
[1019] | 335 | END IF |
---|
[1682] | 336 | !$OMP END MASTER |
---|
| 337 | |
---|
[1019] | 338 | END SUBROUTINE wxios_domain_param |
---|
| 339 | |
---|
[1682] | 340 | |
---|
| 341 | SUBROUTINE wxios_domain_param_unstructured(dom_id,flip_coordinates) |
---|
| 342 | USE geometry_mod, ONLY : longitude, latitude, boundslon, boundslat,ind_cell_glo |
---|
| 343 | USE mod_grid_phy_lmdz, ONLY : nvertex, klon_glo |
---|
| 344 | USE mod_phys_lmdz_para |
---|
| 345 | USE nrtype, ONLY : PI |
---|
| 346 | IMPLICIT NONE |
---|
| 347 | CHARACTER(len=*),INTENT(IN) :: dom_id ! domain identifier |
---|
| 348 | LOGICAL,OPTIONAL,INTENT(IN) :: flip_coordinates ! .true. to change signs |
---|
| 349 | ! of coordinates |
---|
| 350 | LOGICAL :: flip_axes=.false. ! default; do not swap axes |
---|
| 351 | REAL :: lon_mpi(klon_mpi) |
---|
| 352 | REAL :: lat_mpi(klon_mpi) |
---|
| 353 | REAL :: boundslon_mpi(klon_mpi,nvertex) |
---|
| 354 | REAL :: boundslat_mpi(klon_mpi,nvertex) |
---|
| 355 | INTEGER :: ind_cell_glo_mpi(klon_mpi) |
---|
| 356 | TYPE(xios_domaingroup) :: dom |
---|
| 357 | |
---|
| 358 | IF (PRESENT(flip_coordinates)) flip_axes=flip_coordinates |
---|
| 359 | |
---|
| 360 | IF (flip_axes) THEN |
---|
| 361 | ! change signs of axes and boundaries |
---|
| 362 | CALL gather_omp(-longitude*180/PI,lon_mpi) |
---|
| 363 | CALL gather_omp(-latitude*180/PI,lat_mpi) |
---|
| 364 | CALL gather_omp(-boundslon*180/PI,boundslon_mpi) |
---|
| 365 | CALL gather_omp(-boundslat*180/PI,boundslat_mpi) |
---|
| 366 | ELSE |
---|
| 367 | CALL gather_omp(longitude*180/PI,lon_mpi) |
---|
| 368 | CALL gather_omp(latitude*180/PI,lat_mpi) |
---|
| 369 | CALL gather_omp(boundslon*180/PI,boundslon_mpi) |
---|
| 370 | CALL gather_omp(boundslat*180/PI,boundslat_mpi) |
---|
| 371 | ENDIF |
---|
| 372 | CALL gather_omp(ind_cell_glo,ind_cell_glo_mpi) |
---|
| 373 | |
---|
| 374 | |
---|
| 375 | !$OMP MASTER |
---|
| 376 | CALL xios_get_domaingroup_handle(dom_id, dom) |
---|
| 377 | |
---|
| 378 | !On parametrise le domaine: |
---|
| 379 | CALL xios_set_attr(dom, ni_glo=klon_glo, ibegin=ij_begin-1, ni=ij_nb, type="unstructured") |
---|
| 380 | CALL xios_set_attr(dom, nvertex=nvertex, lonvalue_1d=lon_mpi, latvalue_1d=lat_mpi, & |
---|
| 381 | bounds_lon_1d=TRANSPOSE(boundslon_mpi), bounds_lat_1d=TRANSPOSE(boundslat_mpi) ) |
---|
| 382 | CALL xios_set_attr(dom, i_index=ind_cell_glo_mpi(:)-1) |
---|
| 383 | !$OMP END MASTER |
---|
| 384 | |
---|
| 385 | END SUBROUTINE wxios_domain_param_unstructured |
---|
| 386 | |
---|
| 387 | |
---|
| 388 | |
---|
| 389 | |
---|
[1019] | 390 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1441] | 391 | ! Pour déclarer un axe vertical !!!!!!!!!!!!!!! |
---|
[1019] | 392 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1302] | 393 | SUBROUTINE wxios_add_vaxis(axis_id, axis_size, axis_value) |
---|
[1575] | 394 | USE print_control_mod, ONLY : prt_level, lunout |
---|
[1300] | 395 | IMPLICIT NONE |
---|
| 396 | |
---|
[1302] | 397 | CHARACTER (len=*), INTENT(IN) :: axis_id |
---|
[1300] | 398 | INTEGER, INTENT(IN) :: axis_size |
---|
[1019] | 399 | REAL, DIMENSION(axis_size), INTENT(IN) :: axis_value |
---|
| 400 | |
---|
[1302] | 401 | ! TYPE(xios_axisgroup) :: axgroup |
---|
| 402 | ! TYPE(xios_axis) :: ax |
---|
| 403 | ! CHARACTER(len=50) :: axis_id |
---|
[1019] | 404 | |
---|
[1302] | 405 | ! IF (len_trim(axisgroup_id).gt.len(axis_id)) THEN |
---|
| 406 | ! WRITE(lunout,*) "wxios_add_vaxis: error, size of axis_id too small!!" |
---|
| 407 | ! WRITE(lunout,*) " increase it to at least ",len_trim(axisgroup_id) |
---|
| 408 | ! CALL abort_gcm("wxios_add_vaxis","len(axis_id) too small",1) |
---|
| 409 | ! ENDIF |
---|
| 410 | ! axis_id=trim(axisgroup_id) |
---|
[1019] | 411 | |
---|
[1441] | 412 | !On récupère le groupe d'axes qui va bien: |
---|
[1302] | 413 | !CALL xios_get_axisgroup_handle(axisgroup_id, axgroup) |
---|
[1019] | 414 | |
---|
[1441] | 415 | !On ajoute l'axe correspondant à ce fichier: |
---|
[1302] | 416 | !CALL xios_add_axis(axgroup, ax, TRIM(ADJUSTL(axis_id))) |
---|
[1019] | 417 | |
---|
| 418 | !Et on le parametrise: |
---|
[1302] | 419 | !CALL xios_set_axis_attr_hdl(ax, size=axis_size, value=axis_value) |
---|
[1019] | 420 | |
---|
[1302] | 421 | ! Ehouarn: New way to declare axis, without axis_group: |
---|
[1575] | 422 | CALL xios_set_axis_attr(trim(axis_id),n_glo=axis_size,value=axis_value) |
---|
[1650] | 423 | |
---|
[1441] | 424 | !Vérification: |
---|
[1300] | 425 | IF (xios_is_valid_axis(TRIM(ADJUSTL(axis_id)))) THEN |
---|
| 426 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_vaxis: Axis created: ", TRIM(ADJUSTL(axis_id)) |
---|
[1019] | 427 | ELSE |
---|
[1302] | 428 | WRITE(lunout,*) "wxios_add_vaxis: Invalid axis: ", TRIM(ADJUSTL(axis_id)) |
---|
[1019] | 429 | END IF |
---|
| 430 | |
---|
| 431 | END SUBROUTINE wxios_add_vaxis |
---|
| 432 | |
---|
| 433 | |
---|
| 434 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1441] | 435 | ! Pour déclarer un fichier !!!!!!!!!!!!!!!!!!! |
---|
[1019] | 436 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 437 | SUBROUTINE wxios_add_file(fname, ffreq, flvl) |
---|
[1575] | 438 | USE print_control_mod, ONLY : prt_level, lunout |
---|
[1300] | 439 | IMPLICIT NONE |
---|
| 440 | |
---|
[1019] | 441 | CHARACTER(len=*), INTENT(IN) :: fname |
---|
| 442 | CHARACTER(len=*), INTENT(IN) :: ffreq |
---|
| 443 | INTEGER, INTENT(IN) :: flvl |
---|
| 444 | |
---|
| 445 | TYPE(xios_file) :: x_file |
---|
| 446 | TYPE(xios_filegroup) :: x_fg |
---|
[1575] | 447 | TYPE(xios_duration) :: nffreq |
---|
[1019] | 448 | |
---|
[1441] | 449 | !On regarde si le fichier n'est pas défini par XML: |
---|
[1300] | 450 | IF (.NOT.xios_is_valid_file(fname)) THEN |
---|
[1441] | 451 | !On créé le noeud: |
---|
[1300] | 452 | CALL xios_get_filegroup_handle("defile", x_fg) |
---|
| 453 | CALL xios_add_file(x_fg, x_file, fname) |
---|
[1019] | 454 | |
---|
[1441] | 455 | !On reformate la fréquence: |
---|
[1300] | 456 | CALL reformadate(ffreq, nffreq) |
---|
[1019] | 457 | |
---|
[1300] | 458 | !On configure: |
---|
| 459 | CALL xios_set_file_attr_hdl(x_file, name="X"//fname,& |
---|
[1575] | 460 | output_freq=nffreq, output_level=flvl, enabled=.TRUE.) |
---|
| 461 | |
---|
[1300] | 462 | IF (xios_is_valid_file("X"//fname)) THEN |
---|
[1302] | 463 | IF (prt_level >= 10) THEN |
---|
| 464 | WRITE(lunout,*) "wxios_add_file: New file: ", "X"//fname |
---|
[1575] | 465 | WRITE(lunout,*) "wxios_add_file: output_freq=",nffreq,"; output_lvl=",flvl |
---|
[1302] | 466 | ENDIF |
---|
[1300] | 467 | ELSE |
---|
[1302] | 468 | WRITE(lunout,*) "wxios_add_file: Error, invalid file: ", "X"//trim(fname) |
---|
[1575] | 469 | WRITE(lunout,*) "wxios_add_file: output_freq=",nffreq,"; output_lvl=",flvl |
---|
[1300] | 470 | END IF |
---|
[1019] | 471 | ELSE |
---|
[1302] | 472 | IF (prt_level >= 10) THEN |
---|
[1441] | 473 | WRITE(lunout,*) "wxios_add_file: File ",trim(fname), " défined using XML." |
---|
[1302] | 474 | ENDIF |
---|
| 475 | ! Ehouarn: add an enable=.true. on top of xml definitions... why??? |
---|
| 476 | CALL xios_set_file_attr(fname, enabled=.TRUE.) |
---|
[1019] | 477 | END IF |
---|
| 478 | END SUBROUTINE wxios_add_file |
---|
| 479 | |
---|
| 480 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1441] | 481 | ! Pour créer un champ !!!!!!!!!!!!!!!!!!!! |
---|
[1019] | 482 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
| 483 | SUBROUTINE wxios_add_field(fieldname, fieldgroup, fieldlongname, fieldunit) |
---|
[1300] | 484 | USE netcdf, only: nf90_fill_real |
---|
| 485 | |
---|
| 486 | IMPLICIT NONE |
---|
| 487 | INCLUDE 'iniprint.h' |
---|
[1019] | 488 | |
---|
| 489 | CHARACTER(len=*), INTENT(IN) :: fieldname |
---|
| 490 | TYPE(xios_fieldgroup), INTENT(IN) :: fieldgroup |
---|
| 491 | CHARACTER(len=*), INTENT(IN) :: fieldlongname |
---|
| 492 | CHARACTER(len=*), INTENT(IN) :: fieldunit |
---|
| 493 | |
---|
| 494 | TYPE(xios_field) :: field |
---|
| 495 | CHARACTER(len=10) :: newunit |
---|
| 496 | REAL(KIND=8) :: def |
---|
| 497 | |
---|
[1441] | 498 | !La valeur par défaut des champs non définis: |
---|
[1019] | 499 | def = nf90_fill_real |
---|
| 500 | |
---|
| 501 | IF (fieldunit .EQ. " ") THEN |
---|
| 502 | newunit = "-" |
---|
| 503 | ELSE |
---|
| 504 | newunit = fieldunit |
---|
| 505 | ENDIF |
---|
| 506 | |
---|
| 507 | !On ajoute le champ: |
---|
| 508 | CALL xios_add_field(fieldgroup, field, fieldname) |
---|
[1300] | 509 | !IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field: ",fieldname,fieldgroup, fieldlongname, fieldunit |
---|
[1019] | 510 | |
---|
[1441] | 511 | !On rentre ses paramètres: |
---|
[1019] | 512 | CALL xios_set_field_attr_hdl(field, standard_name=fieldlongname, unit=newunit, default_value=def) |
---|
[1300] | 513 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field: Field ",trim(fieldname), "cree:" |
---|
| 514 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field: long_name=",trim(fieldlongname),"; unit=",trim(newunit),"; default_value=",nf90_fill_real |
---|
[1019] | 515 | |
---|
| 516 | END SUBROUTINE wxios_add_field |
---|
| 517 | |
---|
| 518 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1441] | 519 | ! Pour déclarer un champ !!!!!!!!!!!!!!!!! |
---|
[1019] | 520 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
---|
[1441] | 521 | SUBROUTINE wxios_add_field_to_file(fieldname, fdim, fid, fname, fieldlongname, fieldunit, field_level, op, nam_axvert) |
---|
[1575] | 522 | USE print_control_mod, ONLY : prt_level, lunout |
---|
[1300] | 523 | IMPLICIT NONE |
---|
| 524 | |
---|
[1019] | 525 | CHARACTER(len=*), INTENT(IN) :: fieldname |
---|
| 526 | INTEGER, INTENT(IN) :: fdim, fid |
---|
| 527 | CHARACTER(len=*), INTENT(IN) :: fname |
---|
| 528 | CHARACTER(len=*), INTENT(IN) :: fieldlongname |
---|
| 529 | CHARACTER(len=*), INTENT(IN) :: fieldunit |
---|
| 530 | INTEGER, INTENT(IN) :: field_level |
---|
| 531 | CHARACTER(len=*), INTENT(IN) :: op |
---|
| 532 | |
---|
[1302] | 533 | CHARACTER(len=20) :: axis_id ! Ehouarn: dangerous... |
---|
[1441] | 534 | CHARACTER(len=20), INTENT(IN), OPTIONAL :: nam_axvert |
---|
[1019] | 535 | CHARACTER(len=100) :: operation |
---|
| 536 | TYPE(xios_file) :: f |
---|
| 537 | TYPE(xios_field) :: field |
---|
| 538 | TYPE(xios_fieldgroup) :: fieldgroup |
---|
[1575] | 539 | TYPE(xios_duration) :: freq_op |
---|
[1650] | 540 | |
---|
[1300] | 541 | LOGICAL :: bool=.FALSE. |
---|
| 542 | INTEGER :: lvl =0 |
---|
[1019] | 543 | |
---|
| 544 | |
---|
[1302] | 545 | ! Ajout Abd pour NMC: |
---|
| 546 | IF (fid.LE.6) THEN |
---|
| 547 | axis_id="presnivs" |
---|
| 548 | ELSE |
---|
| 549 | axis_id="plev" |
---|
| 550 | ENDIF |
---|
[1441] | 551 | |
---|
| 552 | IF (PRESENT(nam_axvert)) THEN |
---|
| 553 | axis_id=nam_axvert |
---|
| 554 | print*,'nam_axvert=',axis_id |
---|
| 555 | ENDIF |
---|
[1019] | 556 | |
---|
[1441] | 557 | !on prépare le nom de l'opération: |
---|
[1019] | 558 | operation = reformaop(op) |
---|
| 559 | |
---|
| 560 | |
---|
| 561 | !On selectionne le bon groupe de champs: |
---|
| 562 | IF (fdim.EQ.2) THEN |
---|
[1302] | 563 | CALL xios_get_fieldgroup_handle("fields_2D", fieldgroup) |
---|
[1019] | 564 | ELSE |
---|
| 565 | CALL xios_get_fieldgroup_handle("fields_3D", fieldgroup) |
---|
| 566 | ENDIF |
---|
| 567 | |
---|
[1441] | 568 | !On regarde si le champ à déjà été créé ou non: |
---|
[1300] | 569 | IF (xios_is_valid_field(fieldname) .AND. .NOT. g_field_name == fieldname) THEN |
---|
[1441] | 570 | !Si ce champ existe via XML (ie, dès le premier passage, ie g_field_name != fieldname) alors rien d'autre à faire |
---|
[1300] | 571 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field_to_file: Field ", trim(fieldname), "exists via XML" |
---|
| 572 | g_flag_xml = .TRUE. |
---|
| 573 | g_field_name = fieldname |
---|
| 574 | |
---|
| 575 | ELSE IF (.NOT. g_field_name == fieldname) THEN |
---|
[1441] | 576 | !Si premier pssage et champ indéfini, alors on le créé |
---|
[1300] | 577 | |
---|
| 578 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field_to_file: Field ", trim(fieldname), "does not exist" |
---|
[1019] | 579 | |
---|
[1441] | 580 | !On le créé: |
---|
[1019] | 581 | CALL wxios_add_field(fieldname, fieldgroup, fieldlongname, fieldunit) |
---|
| 582 | IF (xios_is_valid_field(fieldname)) THEN |
---|
[1300] | 583 | IF (prt_level >= 10) WRITE(lunout,*) "wxios_add_field_to_file: Field ", trim(fieldname), "created" |
---|
[1019] | 584 | ENDIF |
---|
| 585 | |
---|
[1300] | 586 | g_flag_xml = .FALSE. |
---|
| 587 | g_field_name = fieldname |
---|
| 588 | |
---|
| 589 | END IF |
---|
| 590 | |
---|
| 591 | IF (.NOT. g_flag_xml) THEN |
---|
[1441] | 592 | !Champ existe déjà, mais pas XML, alors on l'ajoute |
---|
[1300] | 593 | !On ajoute le champ: |
---|
| 594 | CALL xios_get_file_handle(fname, f) |
---|
| 595 | CALL xios_add_fieldtofile(f, field) |
---|
| 596 | |
---|
| 597 | |
---|
| 598 | !L'operation, sa frequence: |
---|
[1575] | 599 | freq_op%timestep=1 |
---|
| 600 | CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op=freq_op, prec=4) |
---|
[1300] | 601 | |
---|
| 602 | |
---|
[1441] | 603 | !On rentre ses paramètres: |
---|
[1300] | 604 | CALL xios_set_field_attr_hdl(field, level=field_level, enabled=.TRUE.) |
---|
| 605 | |
---|
| 606 | IF (fdim.EQ.2) THEN |
---|
| 607 | !Si c'est un champ 2D: |
---|
| 608 | IF (prt_level >= 10) THEN |
---|
| 609 | WRITE(lunout,*) "wxios_add_field_to_file: 2D Field ", trim(fieldname), " in ", "X"//trim(fname) ," configured with:" |
---|
| 610 | WRITE(lunout,*) "wxios_add_field_to_file: op=", TRIM(ADJUSTL(operation)) |
---|
| 611 | WRITE(lunout,*) "wxios_add_field_to_file: freq_op=1ts","; lvl=",field_level |
---|
| 612 | ENDIF |
---|
| 613 | ELSE |
---|
| 614 | !Si 3D : |
---|
| 615 | !On ajoute l'axe vertical qui va bien: |
---|
| 616 | CALL xios_set_field_attr_hdl(field, axis_ref=TRIM(ADJUSTL(axis_id))) |
---|
| 617 | |
---|
| 618 | IF (prt_level >= 10) THEN |
---|
| 619 | WRITE(lunout,*) "wxios_add_field_to_file: 3D Field",trim(fieldname), " in ", "X"//trim(fname), "configured with:" |
---|
| 620 | WRITE(lunout,*) "wxios_add_field_to_file: freq_op=1ts","; lvl=",field_level |
---|
| 621 | WRITE(lunout,*) "wxios_add_field_to_file: axis=",TRIM(ADJUSTL(axis_id)) |
---|
| 622 | ENDIF |
---|
| 623 | END IF |
---|
[1019] | 624 | |
---|
| 625 | ELSE |
---|
[1300] | 626 | !Sinon on se contente de l'activer: |
---|
| 627 | CALL xios_set_field_attr(fieldname, enabled=.TRUE.) |
---|
[1302] | 628 | !NB: This will override an enable=.false. set by a user in the xml file; |
---|
| 629 | ! then the only way to not output the field is by changing its |
---|
| 630 | ! output level |
---|
[1300] | 631 | ENDIF |
---|
[1019] | 632 | |
---|
| 633 | END SUBROUTINE wxios_add_field_to_file |
---|
| 634 | |
---|
[1302] | 635 | ! SUBROUTINE wxios_update_calendar(ito) |
---|
| 636 | ! INTEGER, INTENT(IN) :: ito |
---|
| 637 | ! CALL xios_update_calendar(ito) |
---|
| 638 | ! END SUBROUTINE wxios_update_calendar |
---|
| 639 | ! |
---|
| 640 | ! SUBROUTINE wxios_write_2D(fieldname, fdata) |
---|
| 641 | ! CHARACTER(len=*), INTENT(IN) :: fieldname |
---|
| 642 | ! REAL, DIMENSION(:,:), INTENT(IN) :: fdata |
---|
| 643 | ! |
---|
| 644 | ! CALL xios_send_field(fieldname, fdata) |
---|
| 645 | ! END SUBROUTINE wxios_write_2D |
---|
[1019] | 646 | |
---|
[1302] | 647 | ! SUBROUTINE wxios_write_3D(fieldname, fdata) |
---|
| 648 | ! CHARACTER(len=*), INTENT(IN) :: fieldname |
---|
| 649 | ! REAL, DIMENSION(:,:,:), INTENT(IN) :: fdata |
---|
| 650 | ! |
---|
| 651 | ! CALL xios_send_field(fieldname, fdata) |
---|
| 652 | ! END SUBROUTINE wxios_write_3D |
---|
[1019] | 653 | |
---|
| 654 | SUBROUTINE wxios_closedef() |
---|
| 655 | CALL xios_close_context_definition() |
---|
[1441] | 656 | ! CALL xios_update_calendar(0) |
---|
[1019] | 657 | END SUBROUTINE wxios_closedef |
---|
| 658 | |
---|
| 659 | SUBROUTINE wxios_close() |
---|
| 660 | CALL xios_context_finalize() |
---|
| 661 | CALL xios_finalize() |
---|
| 662 | END SUBROUTINE wxios_close |
---|
| 663 | END MODULE wxios |
---|
| 664 | #endif |
---|