| 1 | ! $Id: wxios.F90 $ |
|---|
| 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) |
|---|
| 20 | LOGICAL, SAVE :: g_flag_xml = .FALSE. |
|---|
| 21 | CHARACTER(len=100) :: g_field_name = "nofield" |
|---|
| 22 | !$OMP THREADPRIVATE(g_flag_xml,g_field_name) |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | CONTAINS |
|---|
| 26 | |
|---|
| 27 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 28 | ! str + i => str_i !!!!!!!!!!!!!!!!!!!! |
|---|
| 29 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 30 | |
|---|
| 31 | SUBROUTINE concat(str, str2, str_str2) |
|---|
| 32 | CHARACTER(len=*), INTENT(IN) :: str, str2 |
|---|
| 33 | CHARACTER(len=20), INTENT(OUT) :: str_str2 |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | str_str2 = TRIM(ADJUSTL(str//"_"//TRIM(ADJUSTL(str2)))) |
|---|
| 37 | !IF (prt_level >= 10) WRITE(lunout,*) "Xios. ",str,"+",str2,"=",str_str2 |
|---|
| 38 | END SUBROUTINE concat |
|---|
| 39 | |
|---|
| 40 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 41 | ! 36day => 36d etc !!!!!!!!!!!!!!!!!!!! |
|---|
| 42 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 43 | |
|---|
| 44 | SUBROUTINE reformadate(odate, ndate) |
|---|
| 45 | CHARACTER(len=*), INTENT(IN) :: odate |
|---|
| 46 | CHARACTER(len=100), INTENT(OUT) :: ndate |
|---|
| 47 | |
|---|
| 48 | INTEGER :: i = 0 |
|---|
| 49 | !!!!!!!!!!!!!!!!!! |
|---|
| 50 | ! Pour XIOS: |
|---|
| 51 | ! year : y |
|---|
| 52 | ! month : mo |
|---|
| 53 | ! day : d |
|---|
| 54 | ! hour : h |
|---|
| 55 | ! minute : mi |
|---|
| 56 | ! second : s |
|---|
| 57 | !!!!!!!!!!!!!!!!!! |
|---|
| 58 | |
|---|
| 59 | i = INDEX(odate, "day") |
|---|
| 60 | IF (i > 0) THEN |
|---|
| 61 | ndate = odate(1:i-1)//"d" |
|---|
| 62 | END IF |
|---|
| 63 | |
|---|
| 64 | i = INDEX(odate, "hr") |
|---|
| 65 | IF (i > 0) THEN |
|---|
| 66 | ndate = odate(1:i-1)//"h" |
|---|
| 67 | END IF |
|---|
| 68 | |
|---|
| 69 | i = INDEX(odate, "mth") |
|---|
| 70 | IF (i > 0) THEN |
|---|
| 71 | ndate = odate(1:i-1)//"mo" |
|---|
| 72 | END IF |
|---|
| 73 | |
|---|
| 74 | !IF (prt_level >= 10) WRITE(lunout,*) "Xios. ", odate, " => ", ndate |
|---|
| 75 | END SUBROUTINE reformadate |
|---|
| 76 | |
|---|
| 77 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 78 | ! ave(X) => average etc !!!!!!!!!!!!!!! |
|---|
| 79 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 80 | |
|---|
| 81 | CHARACTER(len=7) FUNCTION reformaop(op) |
|---|
| 82 | CHARACTER(len=*), INTENT(IN) :: op |
|---|
| 83 | |
|---|
| 84 | INTEGER :: i = 0 |
|---|
| 85 | reformaop = "average" |
|---|
| 86 | |
|---|
| 87 | IF (op.EQ."inst(X)") THEN |
|---|
| 88 | reformaop = "instant" |
|---|
| 89 | END IF |
|---|
| 90 | |
|---|
| 91 | IF (op.EQ."once") THEN |
|---|
| 92 | reformaop = "once" |
|---|
| 93 | END IF |
|---|
| 94 | |
|---|
| 95 | IF (op.EQ."t_max(X)") THEN |
|---|
| 96 | reformaop = "maximum" |
|---|
| 97 | END IF |
|---|
| 98 | |
|---|
| 99 | IF (op.EQ."t_min(X)") THEN |
|---|
| 100 | reformaop = "minimum" |
|---|
| 101 | END IF |
|---|
| 102 | |
|---|
| 103 | !IF (prt_level >= 10) WRITE(lunout,*) "Xios. ", op, " => ", reformaop |
|---|
| 104 | END FUNCTION reformaop |
|---|
| 105 | |
|---|
| 106 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 107 | ! Routine d'initialisation !!!!!!!!!!!!! |
|---|
| 108 | ! A lancer juste après mpi_init !!!!!!!!!!!!! |
|---|
| 109 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 110 | |
|---|
| 111 | SUBROUTINE wxios_init(xios_ctx_name, locom, outcom) |
|---|
| 112 | IMPLICIT NONE |
|---|
| 113 | INCLUDE 'iniprint.h' |
|---|
| 114 | |
|---|
| 115 | CHARACTER(len=*), INTENT(IN) :: xios_ctx_name |
|---|
| 116 | INTEGER, INTENT(IN), OPTIONAL :: locom |
|---|
| 117 | INTEGER, INTENT(OUT), OPTIONAL :: outcom |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | TYPE(xios_context) :: xios_ctx |
|---|
| 121 | INTEGER :: xios_comm |
|---|
| 122 | |
|---|
| 123 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Initialization" |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | IF (PRESENT(locom)) THEN |
|---|
| 128 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. ctx=",xios_ctx_name,"local_comm=",locom,",return_comm=",xios_comm |
|---|
| 129 | CALL xios_initialize(xios_ctx_name, local_comm = locom, return_comm = xios_comm ) |
|---|
| 130 | ELSE |
|---|
| 131 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. ctx=",xios_ctx_name,"return_comm=",outcom |
|---|
| 132 | CALL xios_initialize(xios_ctx_name, return_comm = xios_comm ) |
|---|
| 133 | END IF |
|---|
| 134 | |
|---|
| 135 | IF (PRESENT(outcom)) THEN |
|---|
| 136 | outcom = xios_comm |
|---|
| 137 | END IF |
|---|
| 138 | |
|---|
| 139 | !Enregistrement des variables globales: |
|---|
| 140 | g_comm = xios_comm |
|---|
| 141 | g_ctx_name = xios_ctx_name |
|---|
| 142 | |
|---|
| 143 | CALL wxios_context_init() |
|---|
| 144 | |
|---|
| 145 | END SUBROUTINE wxios_init |
|---|
| 146 | |
|---|
| 147 | SUBROUTINE wxios_context_init() |
|---|
| 148 | IMPLICIT NONE |
|---|
| 149 | INCLUDE 'iniprint.h' |
|---|
| 150 | |
|---|
| 151 | TYPE(xios_context) :: xios_ctx |
|---|
| 152 | |
|---|
| 153 | !Initialisation du contexte: |
|---|
| 154 | CALL xios_context_initialize(g_ctx_name, g_comm) |
|---|
| 155 | CALL xios_get_handle(g_ctx_name, xios_ctx) !Récupération |
|---|
| 156 | CALL xios_set_current_context(xios_ctx) !Activation |
|---|
| 157 | g_ctx = xios_ctx |
|---|
| 158 | |
|---|
| 159 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Current context is ", g_ctx_name |
|---|
| 160 | |
|---|
| 161 | !Une première analyse des héritages: |
|---|
| 162 | CALL xios_solve_inheritance() |
|---|
| 163 | END SUBROUTINE wxios_context_init |
|---|
| 164 | |
|---|
| 165 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 166 | ! Routine de paramétrisation !!!!!!!!!!!!!!!!!! |
|---|
| 167 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 168 | |
|---|
| 169 | SUBROUTINE wxios_set_cal(pasdetemps, calendrier, annee, mois, jour, heure) |
|---|
| 170 | IMPLICIT NONE |
|---|
| 171 | INCLUDE 'iniprint.h' |
|---|
| 172 | |
|---|
| 173 | !Paramètres: |
|---|
| 174 | CHARACTER(len=*), INTENT(IN) :: calendrier |
|---|
| 175 | INTEGER, INTENT(IN) :: annee, mois, jour |
|---|
| 176 | REAL, INTENT(IN) :: pasdetemps, heure |
|---|
| 177 | |
|---|
| 178 | !Variables: |
|---|
| 179 | CHARACTER(len=80) :: abort_message |
|---|
| 180 | CHARACTER(len=19) :: date |
|---|
| 181 | INTEGER :: njour = 1 |
|---|
| 182 | |
|---|
| 183 | !Variables pour xios: |
|---|
| 184 | TYPE(xios_time) :: mdtime |
|---|
| 185 | !REAL(kind = 8) :: year=0, month=0, day=0, hour=0, minute=0, second=0 |
|---|
| 186 | |
|---|
| 187 | mdtime = xios_time(0, 0, 0, 0, 0, pasdetemps) |
|---|
| 188 | |
|---|
| 189 | !Réglage du calendrier: |
|---|
| 190 | SELECT CASE (calendrier) |
|---|
| 191 | CASE('earth_360d') |
|---|
| 192 | CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "D360") |
|---|
| 193 | IF (prt_level >= 10) WRITE(lunout,*) 'Xios. Calendrier terrestre a 360 jours/an' |
|---|
| 194 | CASE('earth_365d') |
|---|
| 195 | CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "NoLeap") |
|---|
| 196 | IF (prt_level >= 10) WRITE(lunout,*) 'Xios. Calendrier terrestre a 365 jours/an' |
|---|
| 197 | CASE('earth_366d') |
|---|
| 198 | CALL xios_set_context_attr_hdl(g_ctx, calendar_type= "Gregorian") |
|---|
| 199 | IF (prt_level >= 10) WRITE(lunout,*) 'Xios. Calendrier gregorien' |
|---|
| 200 | CASE DEFAULT |
|---|
| 201 | abort_message = 'Xios. Mauvais choix de calendrier' |
|---|
| 202 | CALL abort_gcm('Gcm:Xios',abort_message,1) |
|---|
| 203 | END SELECT |
|---|
| 204 | |
|---|
| 205 | !Formatage de la date de départ: |
|---|
| 206 | WRITE(date, "(i4.4,'-',i2.2,'-',i2.2,' 00:00:00')") annee, mois, jour |
|---|
| 207 | |
|---|
| 208 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Initial time: ", date |
|---|
| 209 | |
|---|
| 210 | CALL xios_set_context_attr_hdl(g_ctx, start_date= date) |
|---|
| 211 | |
|---|
| 212 | !Et enfin,le pas de temps: |
|---|
| 213 | CALL xios_set_timestep(mdtime) |
|---|
| 214 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. ts=",mdtime |
|---|
| 215 | END SUBROUTINE wxios_set_cal |
|---|
| 216 | |
|---|
| 217 | SUBROUTINE wxios_set_timestep(ts) |
|---|
| 218 | REAL, INTENT(IN) :: ts |
|---|
| 219 | TYPE(xios_time) :: mdtime |
|---|
| 220 | |
|---|
| 221 | mdtime = xios_time(0, 0, 0, 0, 0, ts) |
|---|
| 222 | |
|---|
| 223 | CALL xios_set_timestep(mdtime) |
|---|
| 224 | END SUBROUTINE wxios_set_timestep |
|---|
| 225 | |
|---|
| 226 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 227 | ! Pour initialiser un domaine !!!!!!!!!!!!!!!!!!!! |
|---|
| 228 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 229 | SUBROUTINE wxios_domain_param(dom_id, is_sequential, ni, nj, ni_glo, nj_glo, & |
|---|
| 230 | ibegin, iend, ii_begin, ii_end, jbegin, jend, & |
|---|
| 231 | data_ni, data_ibegin, data_iend, & |
|---|
| 232 | io_lat, io_lon) |
|---|
| 233 | |
|---|
| 234 | IMPLICIT NONE |
|---|
| 235 | INCLUDE 'iniprint.h' |
|---|
| 236 | |
|---|
| 237 | CHARACTER (len=*), INTENT(IN) :: dom_id |
|---|
| 238 | LOGICAL, INTENT(IN) :: is_sequential |
|---|
| 239 | INTEGER, INTENT(IN) :: ni, nj, ni_glo, nj_glo, ibegin, iend, ii_begin, ii_end, jbegin, jend |
|---|
| 240 | INTEGER, INTENT(IN) :: data_ni, data_ibegin, data_iend |
|---|
| 241 | REAL, DIMENSION(:) :: io_lat, io_lon |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | TYPE(xios_domain) :: dom |
|---|
| 245 | LOGICAL :: boool |
|---|
| 246 | |
|---|
| 247 | !Masque pour les problèmes de recouvrement MPI: |
|---|
| 248 | LOGICAL :: mask(ni,nj) |
|---|
| 249 | |
|---|
| 250 | !On récupère le handle: |
|---|
| 251 | CALL xios_get_domain_handle(dom_id, dom) |
|---|
| 252 | |
|---|
| 253 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. ni:",ni," ni_glo:", ni_glo, " nj:", nj, " nj_glo:", nj_glo |
|---|
| 254 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. ibegin:",ibegin," iend:", iend, " jbegin:", jbegin, " jend:", jend |
|---|
| 255 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Size lon:", SIZE(io_lon(ibegin:iend)), " lat:", SIZE(io_lat(jbegin:jend)) |
|---|
| 256 | |
|---|
| 257 | !On parametrise le domaine: |
|---|
| 258 | CALL xios_set_domain_attr_hdl(dom, ni_glo=ni_glo, ibegin=ibegin, ni=ni) |
|---|
| 259 | CALL xios_set_domain_attr_hdl(dom, nj_glo=nj_glo, jbegin=jbegin, nj=nj, data_dim=2) |
|---|
| 260 | CALL xios_set_domain_attr_hdl(dom, lonvalue=io_lon(ibegin:iend), latvalue=io_lat(jbegin:jend)) |
|---|
| 261 | |
|---|
| 262 | IF (.NOT.is_sequential) THEN |
|---|
| 263 | mask(:,:)=.TRUE. |
|---|
| 264 | mask(1:ii_begin-1,1) = .FALSE. |
|---|
| 265 | mask(ii_end+1:ni,nj) = .FALSE. |
|---|
| 266 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. mask" |
|---|
| 267 | !CALL xios_set_domain_attr_hdl(dom, mask=mask) |
|---|
| 268 | END IF |
|---|
| 269 | |
|---|
| 270 | CALL xios_is_defined_domain_attr_hdl(dom,ni_glo=boool) |
|---|
| 271 | !Vérification: |
|---|
| 272 | IF (xios_is_valid_domain(dom_id)) THEN |
|---|
| 273 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Domain initialized: ", dom_id, boool |
|---|
| 274 | ELSE |
|---|
| 275 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Invalid domain: ", dom_id |
|---|
| 276 | END IF |
|---|
| 277 | END SUBROUTINE wxios_domain_param |
|---|
| 278 | |
|---|
| 279 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 280 | ! Pour déclarer un axe vertical !!!!!!!!!!!!!!! |
|---|
| 281 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 282 | SUBROUTINE wxios_add_vaxis(axisgroup_id, axis_file, axis_size, axis_value) |
|---|
| 283 | IMPLICIT NONE |
|---|
| 284 | INCLUDE 'iniprint.h' |
|---|
| 285 | |
|---|
| 286 | CHARACTER (len=*), INTENT(IN) :: axisgroup_id, axis_file |
|---|
| 287 | INTEGER, INTENT(IN) :: axis_size |
|---|
| 288 | REAL, DIMENSION(axis_size), INTENT(IN) :: axis_value |
|---|
| 289 | |
|---|
| 290 | TYPE(xios_axisgroup) :: axgroup |
|---|
| 291 | TYPE(xios_axis) :: ax |
|---|
| 292 | CHARACTER(len=20) :: axis_id |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | !Préparation du nom de l'axe: |
|---|
| 296 | CALL concat(axisgroup_id, axis_file, axis_id) |
|---|
| 297 | |
|---|
| 298 | !On récupère le groupe d'axes qui va bien: |
|---|
| 299 | CALL xios_get_axisgroup_handle(axisgroup_id, axgroup) |
|---|
| 300 | |
|---|
| 301 | !On ajoute l'axe correspondant à ce fichier: |
|---|
| 302 | CALL xios_add_axis(axgroup, ax, TRIM(ADJUSTL(axis_id))) |
|---|
| 303 | |
|---|
| 304 | !Et on le parametrise: |
|---|
| 305 | CALL xios_set_axis_attr_hdl(ax, size=axis_size, value=axis_value) |
|---|
| 306 | |
|---|
| 307 | !Vérification: |
|---|
| 308 | IF (xios_is_valid_axis(TRIM(ADJUSTL(axis_id)))) THEN |
|---|
| 309 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Axis created: ", TRIM(ADJUSTL(axis_id)) |
|---|
| 310 | ELSE |
|---|
| 311 | WRITE(*,*) "Xios. Invalid axis: ", TRIM(ADJUSTL(axis_id)) |
|---|
| 312 | END IF |
|---|
| 313 | |
|---|
| 314 | END SUBROUTINE wxios_add_vaxis |
|---|
| 315 | |
|---|
| 316 | |
|---|
| 317 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 318 | ! Pour déclarer un fichier !!!!!!!!!!!!!!!!!!! |
|---|
| 319 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 320 | SUBROUTINE wxios_add_file(fname, ffreq, flvl) |
|---|
| 321 | IMPLICIT NONE |
|---|
| 322 | INCLUDE 'iniprint.h' |
|---|
| 323 | |
|---|
| 324 | CHARACTER(len=*), INTENT(IN) :: fname |
|---|
| 325 | CHARACTER(len=*), INTENT(IN) :: ffreq |
|---|
| 326 | INTEGER, INTENT(IN) :: flvl |
|---|
| 327 | |
|---|
| 328 | TYPE(xios_file) :: x_file |
|---|
| 329 | TYPE(xios_filegroup) :: x_fg |
|---|
| 330 | CHARACTER(len=100) :: nffreq |
|---|
| 331 | |
|---|
| 332 | !On regarde si le fichier n'est pas défini par XML: |
|---|
| 333 | IF (.NOT.xios_is_valid_file(fname)) THEN |
|---|
| 334 | !On créé le noeud: |
|---|
| 335 | CALL xios_get_filegroup_handle("defile", x_fg) |
|---|
| 336 | CALL xios_add_file(x_fg, x_file, fname) |
|---|
| 337 | |
|---|
| 338 | !On reformate la fréquence: |
|---|
| 339 | CALL reformadate(ffreq, nffreq) |
|---|
| 340 | |
|---|
| 341 | !On configure: |
|---|
| 342 | CALL xios_set_file_attr_hdl(x_file, name="X"//fname,& |
|---|
| 343 | output_freq=TRIM(ADJUSTL(nffreq)), output_level=flvl, enabled=.TRUE.) |
|---|
| 344 | |
|---|
| 345 | IF (xios_is_valid_file("X"//fname)) THEN |
|---|
| 346 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. New file: ", "X"//fname |
|---|
| 347 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. output_freq=",TRIM(ADJUSTL(nffreq)),"; output_lvl=",flvl |
|---|
| 348 | ELSE |
|---|
| 349 | WRITE(*,*) "Xios. Error, invalid file: ", "X"//fname |
|---|
| 350 | WRITE(*,*) "Xios. output_freq=",TRIM(ADJUSTL(nffreq)),"; output_lvl=",flvl |
|---|
| 351 | END IF |
|---|
| 352 | ELSE |
|---|
| 353 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Fichier ", fname, " défini par XML." |
|---|
| 354 | CALL xios_set_file_attr(fname, enabled=.TRUE.) |
|---|
| 355 | END IF |
|---|
| 356 | END SUBROUTINE wxios_add_file |
|---|
| 357 | |
|---|
| 358 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 359 | ! Pour créer un champ !!!!!!!!!!!!!!!!!!!! |
|---|
| 360 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 361 | SUBROUTINE wxios_add_field(fieldname, fieldgroup, fieldlongname, fieldunit) |
|---|
| 362 | USE netcdf |
|---|
| 363 | |
|---|
| 364 | IMPLICIT NONE |
|---|
| 365 | INCLUDE 'iniprint.h' |
|---|
| 366 | |
|---|
| 367 | CHARACTER(len=*), INTENT(IN) :: fieldname |
|---|
| 368 | TYPE(xios_fieldgroup), INTENT(IN) :: fieldgroup |
|---|
| 369 | CHARACTER(len=*), INTENT(IN) :: fieldlongname |
|---|
| 370 | CHARACTER(len=*), INTENT(IN) :: fieldunit |
|---|
| 371 | |
|---|
| 372 | TYPE(xios_field) :: field |
|---|
| 373 | CHARACTER(len=10) :: newunit |
|---|
| 374 | REAL(KIND=8) :: def |
|---|
| 375 | |
|---|
| 376 | !La valeur par défaut des champs non définis: |
|---|
| 377 | def = nf90_fill_real |
|---|
| 378 | |
|---|
| 379 | IF (fieldunit .EQ. " ") THEN |
|---|
| 380 | newunit = "-" |
|---|
| 381 | ELSE |
|---|
| 382 | newunit = fieldunit |
|---|
| 383 | ENDIF |
|---|
| 384 | |
|---|
| 385 | !On ajoute le champ: |
|---|
| 386 | CALL xios_add_field(fieldgroup, field, fieldname) |
|---|
| 387 | !IF (prt_level >= 10) WRITE(lunout,*) "Xios. ",fieldname,fieldgroup, fieldlongname, fieldunit |
|---|
| 388 | |
|---|
| 389 | !On rentre ses paramètres: |
|---|
| 390 | CALL xios_set_field_attr_hdl(field, standard_name=fieldlongname, unit=newunit, default_value=def) |
|---|
| 391 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Champ ", fieldname, "cree:" |
|---|
| 392 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. long_name=",fieldlongname,"; unit=",newunit,"; default_value=",nf90_fill_real |
|---|
| 393 | |
|---|
| 394 | END SUBROUTINE wxios_add_field |
|---|
| 395 | |
|---|
| 396 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 397 | ! Pour déclarer un champ !!!!!!!!!!!!!!!!! |
|---|
| 398 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
|---|
| 399 | SUBROUTINE wxios_add_field_to_file(fieldname, fdim, fid, fname, fieldlongname, fieldunit, field_level, op) |
|---|
| 400 | IMPLICIT NONE |
|---|
| 401 | INCLUDE 'iniprint.h' |
|---|
| 402 | |
|---|
| 403 | CHARACTER(len=*), INTENT(IN) :: fieldname |
|---|
| 404 | INTEGER, INTENT(IN) :: fdim, fid |
|---|
| 405 | CHARACTER(len=*), INTENT(IN) :: fname |
|---|
| 406 | CHARACTER(len=*), INTENT(IN) :: fieldlongname |
|---|
| 407 | CHARACTER(len=*), INTENT(IN) :: fieldunit |
|---|
| 408 | INTEGER, INTENT(IN) :: field_level |
|---|
| 409 | CHARACTER(len=*), INTENT(IN) :: op |
|---|
| 410 | |
|---|
| 411 | CHARACTER(len=20) :: axis_id |
|---|
| 412 | CHARACTER(len=100) :: operation |
|---|
| 413 | TYPE(xios_file) :: f |
|---|
| 414 | TYPE(xios_field) :: field |
|---|
| 415 | TYPE(xios_fieldgroup) :: fieldgroup |
|---|
| 416 | LOGICAL :: bool=.FALSE. |
|---|
| 417 | INTEGER :: lvl =0 |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | !Préparation du nom de l'axe: |
|---|
| 421 | CALL concat("presnivs", fname, axis_id) |
|---|
| 422 | |
|---|
| 423 | !on prépare le nom de l'opération: |
|---|
| 424 | operation = reformaop(op) |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | !On selectionne le bon groupe de champs: |
|---|
| 429 | IF (fdim.EQ.2) THEN |
|---|
| 430 | CALL xios_get_fieldgroup_handle("fields_2D", fieldgroup) |
|---|
| 431 | ELSE |
|---|
| 432 | CALL xios_get_fieldgroup_handle("fields_3D", fieldgroup) |
|---|
| 433 | ENDIF |
|---|
| 434 | |
|---|
| 435 | !On regarde si le champ à déjà été créé ou non: |
|---|
| 436 | IF (xios_is_valid_field(fieldname) .AND. .NOT. g_field_name == fieldname) THEN |
|---|
| 437 | !Si ce champ existe via XML (ie, dès le premier passage, ie g_field_name != fieldname) alors rien d'autre à faire |
|---|
| 438 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Champ ", fieldname, "existe via XML" |
|---|
| 439 | g_flag_xml = .TRUE. |
|---|
| 440 | g_field_name = fieldname |
|---|
| 441 | |
|---|
| 442 | ELSE IF (.NOT. g_field_name == fieldname) THEN |
|---|
| 443 | !Si premier pssage et champ indéfini, alors on le créé |
|---|
| 444 | |
|---|
| 445 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Champ ", fieldname, "nexiste pas" |
|---|
| 446 | |
|---|
| 447 | !On le créé: |
|---|
| 448 | CALL wxios_add_field(fieldname, fieldgroup, fieldlongname, fieldunit) |
|---|
| 449 | IF (xios_is_valid_field(fieldname)) THEN |
|---|
| 450 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Champ ", fieldname, "cree" |
|---|
| 451 | ENDIF |
|---|
| 452 | |
|---|
| 453 | g_flag_xml = .FALSE. |
|---|
| 454 | g_field_name = fieldname |
|---|
| 455 | |
|---|
| 456 | END IF |
|---|
| 457 | |
|---|
| 458 | IF (.NOT. g_flag_xml) THEN |
|---|
| 459 | !Champ existe déjà, mais pas XML, alors on l'ajoute |
|---|
| 460 | !On ajoute le champ: |
|---|
| 461 | CALL xios_get_file_handle(fname, f) |
|---|
| 462 | CALL xios_add_fieldtofile(f, field) |
|---|
| 463 | |
|---|
| 464 | |
|---|
| 465 | !L'operation, sa frequence: |
|---|
| 466 | CALL xios_set_field_attr_hdl(field, field_ref=fieldname, operation=TRIM(ADJUSTL(operation)), freq_op="1ts", prec=4) |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | !On rentre ses paramètres: |
|---|
| 470 | CALL xios_set_field_attr_hdl(field, level=field_level, enabled=.TRUE.) |
|---|
| 471 | |
|---|
| 472 | IF (fdim.EQ.2) THEN |
|---|
| 473 | !Si c'est un champ 2D: |
|---|
| 474 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Champ 2D ", fieldname, " de ", "X"//fname ," configure:" |
|---|
| 475 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. op=", TRIM(ADJUSTL(operation)) |
|---|
| 476 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. freq_op=1ts","; lvl=",field_level |
|---|
| 477 | ELSE |
|---|
| 478 | !Si 3D : |
|---|
| 479 | !On ajoute l'axe vertical qui va bien: |
|---|
| 480 | CALL xios_set_field_attr_hdl(field, axis_ref=TRIM(ADJUSTL(axis_id))) |
|---|
| 481 | |
|---|
| 482 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. Champ 3D ", fieldname, " de ", "X"//fname, "configure:" |
|---|
| 483 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. freq_op=1ts","; lvl=",field_level |
|---|
| 484 | IF (prt_level >= 10) WRITE(lunout,*) "Xios. axe=",TRIM(ADJUSTL(axis_id)) |
|---|
| 485 | END IF |
|---|
| 486 | |
|---|
| 487 | ELSE |
|---|
| 488 | !Sinon on se contente de l'activer: |
|---|
| 489 | CALL xios_set_field_attr(fieldname, enabled=.TRUE.) |
|---|
| 490 | ENDIF |
|---|
| 491 | |
|---|
| 492 | END SUBROUTINE wxios_add_field_to_file |
|---|
| 493 | |
|---|
| 494 | SUBROUTINE wxios_update_calendar(ito) |
|---|
| 495 | INTEGER, INTENT(IN) :: ito |
|---|
| 496 | CALL xios_update_calendar(ito) |
|---|
| 497 | END SUBROUTINE wxios_update_calendar |
|---|
| 498 | |
|---|
| 499 | SUBROUTINE wxios_write_2D(fieldname, fdata) |
|---|
| 500 | CHARACTER(len=*), INTENT(IN) :: fieldname |
|---|
| 501 | REAL, DIMENSION(:,:), INTENT(IN) :: fdata |
|---|
| 502 | |
|---|
| 503 | CALL xios_send_field(fieldname, fdata) |
|---|
| 504 | END SUBROUTINE wxios_write_2D |
|---|
| 505 | |
|---|
| 506 | SUBROUTINE wxios_write_3D(fieldname, fdata) |
|---|
| 507 | CHARACTER(len=*), INTENT(IN) :: fieldname |
|---|
| 508 | REAL, DIMENSION(:,:,:), INTENT(IN) :: fdata |
|---|
| 509 | |
|---|
| 510 | CALL xios_send_field(fieldname, fdata) |
|---|
| 511 | END SUBROUTINE wxios_write_3D |
|---|
| 512 | |
|---|
| 513 | SUBROUTINE wxios_closedef() |
|---|
| 514 | CALL xios_close_context_definition() |
|---|
| 515 | CALL xios_update_calendar(0) |
|---|
| 516 | END SUBROUTINE wxios_closedef |
|---|
| 517 | |
|---|
| 518 | SUBROUTINE wxios_close() |
|---|
| 519 | CALL xios_context_finalize() |
|---|
| 520 | CALL xios_finalize() |
|---|
| 521 | END SUBROUTINE wxios_close |
|---|
| 522 | END MODULE wxios |
|---|
| 523 | #endif |
|---|