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

Last change on this file since 5157 was 5144, checked in by abarral, 3 months ago

Put YOMCST.h into modules

File size: 4.0 KB
RevLine 
[2227]1! $Id$
[5099]2
[3298]3!--This routine is to be tested with MPI / OMP parallelism
4!--OB 26/03/2018
[2227]5
[3298]6SUBROUTINE readchlorophyll(debut)
[2227]7
[5111]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
[5112]16  USE lmdz_print_control, ONLY: prt_level, lunout
[5111]17  USE lmdz_abort_physic, ONLY: abort_physic
[5144]18  USE lmdz_yomcst
[2227]19
[5111]20  IMPLICIT NONE
[2227]21
[5111]22  ! Variable input
23  LOGICAL debut
[2227]24
[5111]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)
[2227]36
[5111]37  ! Champs reconstitues
38  REAL, ALLOCATABLE :: chlorocon(:, :, :)
39  REAL, ALLOCATABLE :: chlorocon_mois(:, :)
40  REAL, ALLOCATABLE :: chlorocon_mois_glo(:)
[2227]41
[5111]42  ! For NetCDF:
43  INTEGER ncid_in  ! IDs for input files
44  INTEGER varid, ncerr
[2227]45
[5111]46  !--------------------------------------------------------
47  CHARACTER (len = 20) :: modname = 'readchlorophyll'
48  CHARACTER (len = 80) :: abort_message
[2227]49
[5111]50  !--only read file if beginning of run or start of new month
51  IF (debut.OR.mth_cur/=mth_pre) THEN
[2227]52
[3298]53    IF (is_mpi_root.AND.is_omp_root) THEN
[2227]54
[5111]55      CALL nf95_open("chlorophyll.nc", nf90_nowrite, ncid_in)
[2227]56
[5111]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
[2227]64
[5111]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
[2227]72
[5111]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
[2227]80
[5117]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))
[2227]84
[5111]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
[2227]89
[5111]90      CALL nf95_close(ncid_in)
[2227]91
[5111]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)
[2227]97
[5111]98      !---reduce to a klon_glo grid
99      CALL grid2dTo1d_glo(chlorocon_mois, chlorocon_mois_glo)
[2227]100
[5111]101      WRITE(lunout, *)"chrolophyll current month", mth_cur
102      DO i = 1, klon_glo
[5116]103        !      IF(isnan(chlorocon_mois_glo(i)))then ! isnan() is not in the Fortran standard...
[5111]104        !      Another way to check for NaN:
105        IF (chlorocon_mois_glo(i)/=chlorocon_mois_glo(i)) chlorocon_mois_glo(i) = 0.
106      ENDDO
[2227]107
[5111]108      !    DEALLOCATE(chlorocon)
109      !    DEALLOCATE(chlorocon_mois)
110      !    DEALLOCATE(chlorocon_mois_glo)
111
[3298]112    ENDIF !--is_mpi_root and is_omp_root
[2227]113
[5111]114    !--scatter on all proc
115    CALL scatter(chlorocon_mois_glo, chl_con)
[2227]116
[5111]117    !--keep memory of previous month
118    mth_pre = mth_cur
[2227]119
[5111]120  ENDIF !--debut ou nouveau mois
[2227]121
[3298]122END SUBROUTINE readchlorophyll
Note: See TracBrowser for help on using the repository browser.