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