[2227] | 1 | ! |
---|
| 2 | ! $Id$ |
---|
| 3 | ! |
---|
[3298] | 4 | !--This routine is to be tested with MPI / OMP parallelism |
---|
| 5 | !--OB 26/03/2018 |
---|
[2227] | 6 | |
---|
[3298] | 7 | SUBROUTINE readchlorophyll(debut) |
---|
[2227] | 8 | |
---|
[3298] | 9 | USE netcdf95, ONLY: nf95_close, nf95_gw_var, nf95_inq_dimid, nf95_inq_varid, nf95_open |
---|
| 10 | USE netcdf, ONLY: nf90_get_var, nf90_noerr, nf90_nowrite |
---|
| 11 | USE phys_cal_mod, ONLY: mth_cur |
---|
| 12 | USE mod_grid_phy_lmdz, ONLY: nbp_lon, nbp_lat, klon_glo, grid2dto1d_glo |
---|
| 13 | USE mod_phys_lmdz_mpi_data, ONLY: is_mpi_root |
---|
| 14 | USE mod_phys_lmdz_omp_data, ONLY: is_omp_root |
---|
[2391] | 15 | USE mod_phys_lmdz_para, ONLY: scatter |
---|
| 16 | USE phys_state_var_mod, ONLY: chl_con |
---|
[2227] | 17 | |
---|
[3298] | 18 | IMPLICIT NONE |
---|
[2227] | 19 | |
---|
[3298] | 20 | INCLUDE "YOMCST.h" |
---|
[2227] | 21 | |
---|
| 22 | ! Variable input |
---|
[3298] | 23 | LOGICAL debut |
---|
[2227] | 24 | |
---|
| 25 | ! Variables locales |
---|
[3298] | 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, POINTER :: latitude(:) |
---|
| 31 | REAL, POINTER :: longitude(:) |
---|
| 32 | REAL, POINTER :: time(:) |
---|
| 33 | INTEGER i, k |
---|
| 34 | INTEGER, SAVE :: mth_pre |
---|
[2227] | 35 | !$OMP THREADPRIVATE(mth_pre) |
---|
| 36 | |
---|
| 37 | ! Champs reconstitues |
---|
[3298] | 38 | REAL, ALLOCATABLE :: chlorocon(:, :, :) |
---|
| 39 | REAL, ALLOCATABLE :: chlorocon_mois(:, :) |
---|
| 40 | REAL, ALLOCATABLE :: chlorocon_mois_glo(:) |
---|
[2227] | 41 | |
---|
| 42 | ! For NetCDF: |
---|
[3298] | 43 | INTEGER ncid_in ! IDs for input files |
---|
| 44 | INTEGER varid, ncerr |
---|
[2227] | 45 | |
---|
| 46 | !-------------------------------------------------------- |
---|
| 47 | |
---|
| 48 | !--only read file if beginning of run or start of new month |
---|
| 49 | IF (debut.OR.mth_cur.NE.mth_pre) THEN |
---|
| 50 | |
---|
[3298] | 51 | IF (is_mpi_root.AND.is_omp_root) THEN |
---|
[2227] | 52 | |
---|
| 53 | CALL nf95_open("chlorophyll.nc", nf90_nowrite, ncid_in) |
---|
| 54 | |
---|
| 55 | CALL nf95_inq_varid(ncid_in, "lon", varid) |
---|
| 56 | CALL nf95_gw_var(ncid_in, varid, longitude) |
---|
| 57 | n_lon = size(longitude) |
---|
| 58 | ! print *, 'LON chlorophyll=', n_lon, longitude |
---|
[2346] | 59 | IF (n_lon.NE.nbp_lon) THEN |
---|
| 60 | print *,'Le nombre de lon n est pas egal a nbp_lon' |
---|
[2227] | 61 | STOP |
---|
| 62 | ENDIF |
---|
| 63 | |
---|
| 64 | CALL nf95_inq_varid(ncid_in, "lat", varid) |
---|
| 65 | CALL nf95_gw_var(ncid_in, varid, latitude) |
---|
| 66 | n_lat = size(latitude) |
---|
| 67 | ! print *, 'LAT chlorophyll=', n_lat, latitude |
---|
[2346] | 68 | IF (n_lat.NE.nbp_lat) THEN |
---|
| 69 | print *,'Le nombre de lat n est pas egal a jnbp_lat' |
---|
[2227] | 70 | STOP |
---|
| 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 | ! print *, 'TIME aerosol strato=', n_month, time |
---|
| 77 | IF (n_month.NE.12) THEN |
---|
| 78 | print *,'Le nombre de month n est pas egal a 12' |
---|
| 79 | STOP |
---|
| 80 | ENDIF |
---|
| 81 | |
---|
| 82 | IF (.not.ALLOCATED(chlorocon)) ALLOCATE(chlorocon(n_lon, n_lat, n_month)) |
---|
| 83 | IF (.not.ALLOCATED(chlorocon_mois)) ALLOCATE(chlorocon_mois(n_lon, n_lat)) |
---|
| 84 | IF (.not.ALLOCATED(chlorocon_mois_glo)) ALLOCATE(chlorocon_mois_glo(klon_glo)) |
---|
| 85 | |
---|
| 86 | !--reading stratospheric AOD at 550 nm |
---|
| 87 | CALL nf95_inq_varid(ncid_in, "CHL", varid) |
---|
| 88 | ncerr = nf90_get_var(ncid_in, varid, chlorocon) |
---|
[2391] | 89 | print *,'code erreur readchlorophyll=', ncerr, varid |
---|
[2227] | 90 | |
---|
| 91 | CALL nf95_close(ncid_in) |
---|
| 92 | |
---|
| 93 | !---select the correct month |
---|
| 94 | IF (mth_cur.LT.1.OR.mth_cur.GT.12) THEN |
---|
[2391] | 95 | print *,'probleme avec le mois dans readchlorophyll =', mth_cur |
---|
[2227] | 96 | ENDIF |
---|
| 97 | chlorocon_mois(:,:) = chlorocon(:,:,mth_cur) |
---|
| 98 | |
---|
| 99 | !---reduce to a klon_glo grid |
---|
| 100 | CALL grid2dTo1d_glo(chlorocon_mois,chlorocon_mois_glo) |
---|
| 101 | |
---|
[3298] | 102 | print *,"chrolophyll current month",mth_cur |
---|
| 103 | DO i=1,klon_glo |
---|
[2391] | 104 | ! if(isnan(chlorocon_mois_glo(i)))then ! isnan() is not in the Fortran standard... |
---|
| 105 | ! Another way to check for NaN: |
---|
[3298] | 106 | IF (chlorocon_mois_glo(i).NE.chlorocon_mois_glo(i)) chlorocon_mois_glo(i)=0. |
---|
| 107 | ENDDO |
---|
[2227] | 108 | |
---|
| 109 | ! DEALLOCATE(chlorocon) |
---|
| 110 | ! DEALLOCATE(chlorocon_mois) |
---|
| 111 | ! DEALLOCATE(chlorocon_mois_glo) |
---|
| 112 | |
---|
[3298] | 113 | ENDIF !--is_mpi_root and is_omp_root |
---|
[2227] | 114 | |
---|
| 115 | !--scatter on all proc |
---|
| 116 | CALL scatter(chlorocon_mois_glo,chl_con) |
---|
| 117 | |
---|
| 118 | !--keep memory of previous month |
---|
| 119 | mth_pre=mth_cur |
---|
| 120 | |
---|
| 121 | ENDIF !--debut ou nouveau mois |
---|
| 122 | |
---|
[3298] | 123 | END SUBROUTINE readchlorophyll |
---|