source: LMDZ6/branches/Amaury_dev/libf/phylmd/readchlorophyll.F90 @ 5185

Last change on this file since 5185 was 5144, checked in by abarral, 5 months ago

Put YOMCST.h into modules

File size: 4.0 KB
Line 
1! $Id$
2
3!--This routine is to be tested with MPI / OMP parallelism
4!--OB 26/03/2018
5
6SUBROUTINE readchlorophyll(debut)
7
8  USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, nf95_inq_varid, nf95_open
9  USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite
10  USE phys_cal_mod, ONLY: mth_cur
11  USE lmdz_grid_phy, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dto1d_glo
12  USE lmdz_phys_mpi_data, ONLY: is_mpi_root
13  USE lmdz_phys_omp_data, ONLY: is_omp_root
14  USE lmdz_phys_para, ONLY: scatter
15  USE phys_state_var_mod, ONLY: chl_con
16  USE lmdz_print_control, ONLY: prt_level, lunout
17  USE lmdz_abort_physic, ONLY: abort_physic
18  USE lmdz_yomcst
19
20  IMPLICIT NONE
21
22  ! Variable input
23  LOGICAL debut
24
25  ! Variables locales
26  INTEGER n_lat   ! number of latitudes in the input data
27  INTEGER n_lon   ! number of longitudes in the input data
28  INTEGER n_lev   ! number of levels in the input data
29  INTEGER n_month ! number of months in the input data
30  REAL, ALLOCATABLE :: latitude(:)
31  REAL, ALLOCATABLE :: longitude(:)
32  REAL, ALLOCATABLE :: time(:)
33  INTEGER i, k
34  INTEGER, SAVE :: mth_pre
35  !$OMP THREADPRIVATE(mth_pre)
36
37  ! Champs reconstitues
38  REAL, ALLOCATABLE :: chlorocon(:, :, :)
39  REAL, ALLOCATABLE :: chlorocon_mois(:, :)
40  REAL, ALLOCATABLE :: chlorocon_mois_glo(:)
41
42  ! For NetCDF:
43  INTEGER ncid_in  ! IDs for input files
44  INTEGER varid, ncerr
45
46  !--------------------------------------------------------
47  CHARACTER (len = 20) :: modname = 'readchlorophyll'
48  CHARACTER (len = 80) :: abort_message
49
50  !--only read file if beginning of run or start of new month
51  IF (debut.OR.mth_cur/=mth_pre) THEN
52
53    IF (is_mpi_root.AND.is_omp_root) THEN
54
55      CALL nf95_open("chlorophyll.nc", nf90_nowrite, ncid_in)
56
57      CALL nf95_inq_varid(ncid_in, "lon", varid)
58      CALL nf95_gw_var(ncid_in, varid, longitude)
59      n_lon = size(longitude)
60      IF (n_lon/=nbp_lon) THEN
61        abort_message = 'Le nombre de lon n est pas egal a nbp_lon'
62        CALL abort_physic(modname, abort_message, 1)
63      ENDIF
64
65      CALL nf95_inq_varid(ncid_in, "lat", varid)
66      CALL nf95_gw_var(ncid_in, varid, latitude)
67      n_lat = size(latitude)
68      IF (n_lat/=nbp_lat) THEN
69        abort_message = 'Le nombre de lat n est pas egal a jnbp_lat'
70        CALL abort_physic(modname, abort_message, 1)
71      ENDIF
72
73      CALL nf95_inq_varid(ncid_in, "time", varid)
74      CALL nf95_gw_var(ncid_in, varid, time)
75      n_month = size(time)
76      IF (n_month/=12) THEN
77        abort_message = 'Le nombre de month n est pas egal a 12'
78        CALL abort_physic(modname, abort_message, 1)
79      ENDIF
80
81      IF (.NOT.ALLOCATED(chlorocon))          ALLOCATE(chlorocon(n_lon, n_lat, n_month))
82      IF (.NOT.ALLOCATED(chlorocon_mois))     ALLOCATE(chlorocon_mois(n_lon, n_lat))
83      IF (.NOT.ALLOCATED(chlorocon_mois_glo)) ALLOCATE(chlorocon_mois_glo(klon_glo))
84
85      !--reading stratospheric AOD at 550 nm
86      CALL nf95_inq_varid(ncid_in, "CHL", varid)
87      ncerr = nf90_get_var(ncid_in, varid, chlorocon)
88      WRITE(lunout, *)'code erreur readchlorophyll=', ncerr, varid
89
90      CALL nf95_close(ncid_in)
91
92      !---select the correct month
93      IF (mth_cur<1.OR.mth_cur>12) THEN
94        WRITE(lunout, *)'probleme avec le mois dans readchlorophyll =', mth_cur
95      ENDIF
96      chlorocon_mois(:, :) = chlorocon(:, :, mth_cur)
97
98      !---reduce to a klon_glo grid
99      CALL grid2dTo1d_glo(chlorocon_mois, chlorocon_mois_glo)
100
101      WRITE(lunout, *)"chrolophyll current month", mth_cur
102      DO i = 1, klon_glo
103        !      IF(isnan(chlorocon_mois_glo(i)))then ! isnan() is not in the Fortran standard...
104        !      Another way to check for NaN:
105        IF (chlorocon_mois_glo(i)/=chlorocon_mois_glo(i)) chlorocon_mois_glo(i) = 0.
106      ENDDO
107
108      !    DEALLOCATE(chlorocon)
109      !    DEALLOCATE(chlorocon_mois)
110      !    DEALLOCATE(chlorocon_mois_glo)
111
112    ENDIF !--is_mpi_root and is_omp_root
113
114    !--scatter on all proc
115    CALL scatter(chlorocon_mois_glo, chl_con)
116
117    !--keep memory of previous month
118    mth_pre = mth_cur
119
120  ENDIF !--debut ou nouveau mois
121
122END SUBROUTINE readchlorophyll
Note: See TracBrowser for help on using the repository browser.