4 |
|
|
5 |
contains |
contains |
6 |
|
|
7 |
SUBROUTINE interfoce_lim(itime, dtime, jour, & |
SUBROUTINE interfoce_lim(itime, dtime, jour, knindex, debut, lmt_sst, & |
8 |
klon, nisurf, knon, knindex, & |
pctsrf_new) |
9 |
debut, & |
|
10 |
lmt_sst, pctsrf_new) |
! lecture conditions limites |
11 |
|
! Cette routine sert d'interface entre le modèle atmosphérique et |
12 |
! Cette routine sert d'interface entre le modele atmospherique et |
! un fichier de conditions aux limites. |
13 |
! un fichier de conditions aux limites |
|
14 |
|
! Laurent FAIRHEAD, February 2000 |
15 |
! L. Fairhead 02/2000 |
|
16 |
|
USE dimphy, ONLY: klon |
17 |
use abort_gcm_m, only: abort_gcm |
USE indicesol, ONLY: is_lic, is_oce, is_sic, is_ter, nbsrf |
18 |
use indicesol |
USE netcdf, ONLY: nf90_nowrite |
19 |
|
use netcdf95, only: NF95_CLOSE, nf95_get_var, NF95_INQ_VARID, nf95_open |
20 |
integer, intent(IN) :: itime ! numero du pas de temps courant |
use nr_util, only: assert |
21 |
real , intent(IN) :: dtime ! pas de temps de la physique (en s) |
|
22 |
integer, intent(IN) :: jour ! jour a lire dans l'annee |
integer, intent(IN):: itime ! numero du pas de temps courant |
23 |
integer, intent(IN) :: nisurf ! index de la surface a traiter (1 = sol continental) |
real, intent(IN):: dtime ! pas de temps de la physique (en s) |
24 |
integer, intent(IN) :: knon ! nombre de points dans le domaine a traiter |
integer, intent(IN):: jour ! jour a lire dans l'annee |
25 |
integer, intent(IN) :: klon ! taille de la grille |
|
26 |
integer, dimension(klon), intent(in) :: knindex ! index des points de la surface a traiter |
integer, intent(in):: knindex(:) ! (knon) |
27 |
logical, intent(IN) :: debut ! logical: 1er appel a la physique (initialisation) |
! index des points de la surface a traiter |
28 |
|
|
29 |
! Parametres de sortie |
logical, intent(IN):: debut ! 1er appel a la physique (initialisation) |
30 |
! output: |
|
31 |
! lmt_sst SST lues dans le fichier de CL |
real, intent(out):: lmt_sst(:) ! (knon) |
32 |
! pctsrf_new sous-maille fractionnelle |
! SST lues dans le fichier de conditions aux limites |
33 |
real, intent(out), dimension(klon) :: lmt_sst |
|
34 |
real, intent(out), dimension(klon, nbsrf) :: pctsrf_new |
real, intent(out):: pctsrf_new(:, :) ! (klon, nbsrf) |
35 |
|
! sous-maille fractionnelle |
36 |
! Variables locales |
|
37 |
integer :: ii |
! Local: |
38 |
INTEGER, save :: lmt_pas ! frequence de lecture des conditions limites |
|
39 |
|
INTEGER, save:: lmt_pas ! frequence de lecture des conditions limites |
40 |
! (en pas de physique) |
! (en pas de physique) |
41 |
logical, save :: deja_lu ! pour indiquer que le jour a lire a deja |
|
42 |
! lu pour une surface precedente |
logical, save:: deja_lu |
43 |
integer, save :: jour_lu |
! pour indiquer que le jour à lire a déjà été lu pour une surface |
44 |
integer :: ierr |
! précédente |
45 |
character (len = 20) :: modname = 'interfoce_lim' |
|
46 |
character (len = 80) :: abort_message |
integer, save:: jour_lu |
47 |
logical, save :: newlmt = .TRUE. |
|
48 |
logical, save :: check = .FALSE. |
! Champs lus dans le fichier de conditions aux limites : |
49 |
! Champs lus dans le fichier de CL |
real, allocatable, save:: sst_lu(:) |
50 |
real, allocatable , save, dimension(:) :: sst_lu, rug_lu, nat_lu |
real, allocatable, save:: pct_tmp(:, :) |
51 |
real, allocatable , save, dimension(:, :) :: pct_tmp |
|
52 |
|
integer ncid, varid ! pour NetCDF |
|
! quelques variables pour netcdf |
|
|
|
|
|
include "netcdf.inc" |
|
|
integer :: nid, nvarid |
|
|
integer, dimension(2) :: start, epais |
|
53 |
|
|
54 |
! -------------------------------------------------- |
! -------------------------------------------------- |
55 |
|
|
56 |
|
call assert(size(knindex) == size(lmt_sst), "interfoce_lim knon") |
57 |
|
|
58 |
if (debut .and. .not. allocated(sst_lu)) then |
if (debut .and. .not. allocated(sst_lu)) then |
59 |
lmt_pas = nint(86400./dtime * 1.0) ! pour une lecture une fois par jour |
lmt_pas = nint(86400. / dtime) ! pour une lecture une fois par jour |
60 |
jour_lu = jour - 1 |
jour_lu = jour - 1 |
61 |
allocate(sst_lu(klon)) |
allocate(sst_lu(klon)) |
|
allocate(nat_lu(klon)) |
|
62 |
allocate(pct_tmp(klon, nbsrf)) |
allocate(pct_tmp(klon, nbsrf)) |
63 |
endif |
endif |
64 |
|
|
65 |
if ((jour - jour_lu) /= 0) deja_lu = .false. |
if ((jour - jour_lu) /= 0) deja_lu = .false. |
66 |
|
|
|
if (check) write(*, *)modname, ' :: jour, jour_lu, deja_lu', jour, jour_lu, & |
|
|
deja_lu |
|
|
if (check) write(*, *)modname, ' :: itime, lmt_pas ', itime, lmt_pas, dtime |
|
|
|
|
67 |
! Tester d'abord si c'est le moment de lire le fichier |
! Tester d'abord si c'est le moment de lire le fichier |
68 |
if (mod(itime-1, lmt_pas) == 0 .and. .not. deja_lu) then |
if (mod(itime - 1, lmt_pas) == 0 .and. .not. deja_lu) then |
69 |
|
call NF95_OPEN ('limit.nc', NF90_NOWRITE, ncid) |
70 |
|
|
71 |
|
! Fraction "ocean" |
72 |
|
call NF95_INQ_VARID(ncid, 'FOCE', varid) |
73 |
|
call NF95_GET_VAR(ncid, varid, pct_tmp(:, is_oce), start = (/1, jour/)) |
74 |
|
|
75 |
! Ouverture du fichier |
! Fraction "glace de mer" |
76 |
|
call NF95_INQ_VARID(ncid, 'FSIC', varid) |
77 |
|
call NF95_GET_VAR(ncid, varid, pct_tmp(:, is_sic), start = (/1, jour/)) |
78 |
|
|
79 |
ierr = NF_OPEN ('limit.nc', NF_NOWRITE, nid) |
! Fraction "terre" |
80 |
if (ierr.NE.NF_NOERR) then |
call NF95_INQ_VARID(ncid, 'FTER', varid) |
81 |
abort_message & |
call NF95_GET_VAR(ncid, varid, pct_tmp(:, is_ter), start = (/1, jour/)) |
|
= 'Pb d''ouverture du fichier de conditions aux limites' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
|
|
|
! La tranche de donnees a lire: |
|
|
|
|
|
start(1) = 1 |
|
|
start(2) = jour |
|
|
epais(1) = klon |
|
|
epais(2) = 1 |
|
|
|
|
|
if (newlmt) then |
|
|
|
|
|
! Fraction "ocean" |
|
|
|
|
|
ierr = NF_INQ_VARID(nid, 'FOCE', nvarid) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Le champ <FOCE> est absent' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
ierr = NF_GET_VARA_REAL(nid, nvarid, start, epais, pct_tmp(1, is_oce)) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Lecture echouee pour <FOCE>' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
|
|
|
! Fraction "glace de mer" |
|
|
|
|
|
ierr = NF_INQ_VARID(nid, 'FSIC', nvarid) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Le champ <FSIC> est absent' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
ierr = NF_GET_VARA_REAL(nid, nvarid, start, epais, pct_tmp(1, is_sic)) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Lecture echouee pour <FSIC>' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
|
|
|
! Fraction "terre" |
|
|
|
|
|
ierr = NF_INQ_VARID(nid, 'FTER', nvarid) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Le champ <FTER> est absent' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
ierr = NF_GET_VARA_REAL(nid, nvarid, start, epais, pct_tmp(1, is_ter)) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Lecture echouee pour <FTER>' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
|
|
|
! Fraction "glacier terre" |
|
|
|
|
|
ierr = NF_INQ_VARID(nid, 'FLIC', nvarid) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Le champ <FLIC> est absent' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
ierr = NF_GET_VARA_REAL(nid, nvarid, start, epais, pct_tmp(1, is_lic)) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Lecture echouee pour <FLIC>' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
|
|
|
else ! on en est toujours a rnatur |
|
|
|
|
|
ierr = NF_INQ_VARID(nid, 'NAT', nvarid) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Le champ <NAT> est absent' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
ierr = NF_GET_VARA_REAL(nid, nvarid, start, epais, nat_lu) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Lecture echouee pour <NAT>' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
|
|
|
! Remplissage des fractions de surface |
|
|
! nat = 0, 1, 2, 3 pour ocean, terre, glacier, seaice |
|
|
|
|
|
pct_tmp = 0.0 |
|
|
do ii = 1, klon |
|
|
pct_tmp(ii, nint(nat_lu(ii)) + 1) = 1. |
|
|
enddo |
|
|
|
|
|
|
|
|
! On se retrouve avec ocean en 1 et terre en 2 alors qu'on veut le contraire |
|
|
|
|
|
pctsrf_new = pct_tmp |
|
|
pctsrf_new (:, 2)= pct_tmp (:, 1) |
|
|
pctsrf_new (:, 1)= pct_tmp (:, 2) |
|
|
pct_tmp = pctsrf_new |
|
|
endif ! fin test sur newlmt |
|
|
|
|
|
! Lecture SST |
|
|
|
|
|
ierr = NF_INQ_VARID(nid, 'SST', nvarid) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Le champ <SST> est absent' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
|
ierr = NF_GET_VARA_REAL(nid, nvarid, start, epais, sst_lu) |
|
|
if (ierr /= NF_NOERR) then |
|
|
abort_message = 'Lecture echouee pour <SST>' |
|
|
call abort_gcm(modname, abort_message, 1) |
|
|
endif |
|
82 |
|
|
83 |
|
! Fraction "glacier terre" |
84 |
|
call NF95_INQ_VARID(ncid, 'FLIC', varid) |
85 |
|
call NF95_GET_VAR(ncid, varid, pct_tmp(:, is_lic), start = (/1, jour/)) |
86 |
|
|
87 |
! Fin de lecture |
call NF95_INQ_VARID(ncid, 'SST', varid) |
88 |
|
call NF95_GET_VAR(ncid, varid, sst_lu, start = (/1, jour/)) |
89 |
|
|
90 |
ierr = NF_CLOSE(nid) |
call NF95_CLOSE(ncid) |
91 |
deja_lu = .true. |
deja_lu = .true. |
92 |
jour_lu = jour |
jour_lu = jour |
93 |
endif |
endif |
94 |
|
|
95 |
! Recopie des variables dans les champs de sortie |
! Recopie des variables dans les champs de sortie |
96 |
|
lmt_sst = sst_lu(knindex) |
|
lmt_sst = 999999999. |
|
|
do ii = 1, knon |
|
|
lmt_sst(ii) = sst_lu(knindex(ii)) |
|
|
enddo |
|
|
|
|
97 |
pctsrf_new(:, is_oce) = pct_tmp(:, is_oce) |
pctsrf_new(:, is_oce) = pct_tmp(:, is_oce) |
98 |
pctsrf_new(:, is_sic) = pct_tmp(:, is_sic) |
pctsrf_new(:, is_sic) = pct_tmp(:, is_sic) |
99 |
|
|