Changeset 4357


Ignore:
Timestamp:
Nov 29, 2022, 8:34:05 PM (2 years ago)
Author:
asima
Message:

Tidying code & grilles_gcm.nc.
In grilles_gcm.nc :

  • some variable arguments are corrected/clarified ;
  • grille_u and grille_v are filled (instead of "NaN") with "checkerboard" values, same as grille_s.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • LMDZ6/trunk/libf/dyn3d_common/grilles_gcm_netcdf_sub.F90

    r4356 r4357  
    22! $Id: $
    33!
    4 ! This subroutine creates the file grilles_gcm.nc containg longitudes and
    5 ! latitudes in degrees for grid u and v. This subroutine is called from
    6 ! ce0l. This subroutine corresponds to the first
    7 ! part in the program create_fausse_var.
     4! This subroutine creates the grilles_gcm.nc file, containing:
     5! -> longitudes and latitudes in degrees for dynamical grids u, v and scalaire,
     6! and the following variables added for INCA (informative anyway)
     7! -> vertical levels "presnivs"
     8! -> mask (land/sea), area (grid), phis=surface geopotential height = phis/g
    89!
     10! The subroutine is called in dynphy_lonlat/phylmd/ce0l.F90.
     11
    912SUBROUTINE grilles_gcm_netcdf_sub(masque,phis)
    1013
     
    2023  INCLUDE "netcdf.inc"
    2124
    22 
     25!========================
    2326  REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: masque ! masque terre/mer
    2427  REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: phis   ! geopotentiel au sol
    2528
    26   REAL temp(iim+1,jjm+1)
    27   ! Attributs netcdf sortie
     29  INTEGER status,i,j
     30 
     31  ! Attributs netcdf output
    2832  INTEGER ncid_out,rcode_out
     33 
    2934  INTEGER out_lonuid,out_lonvid,out_latuid,out_latvid
    30   INTEGER out_varid
     35  INTEGER out_uid,out_vid,out_tempid
    3136  INTEGER out_lonudim,out_lonvdim
    3237  INTEGER out_latudim,out_latvdim,out_dim(2)
    3338  INTEGER out_levdim
    34 
    35   INTEGER start(4),COUNT(4)
    36 
    37   INTEGER status,i,j
    38   REAL rlatudeg(jjp1),rlatvdeg(jjm),rlevdeg(llm)
     39  !
     40  INTEGER :: presnivs_id
     41  INTEGER :: mask_id,area_id,phis_id
     42  !
     43  INTEGER start(2),COUNT(2)
     44
     45  ! Variables
     46  REAL rlatudeg(jjp1),rlatvdeg(jjm),rlev(llm)
    3947  REAL rlonudeg(iip1),rlonvdeg(iip1)
    40 
    41   REAL dlon1(iip1),dlon2(iip1),dlat1(jjp1),dlat2(jjp1)
    42   REAL acoslat,dxkm,dykm,resol(iip1,jjp1)
    43   REAL,DIMENSION(iip1,jjp1)  :: phis_loc
     48  REAL uwnd(iip1,jjp1),vwnd(iip1,jjm),temp(iip1,jjp1)
     49  !
    4450  INTEGER masque_int(iip1,jjp1)
    45   INTEGER :: phis_id
    46   INTEGER :: area_id
    47   INTEGER :: mask_id
    48   INTEGER :: presnivs_id
    49  
     51  REAL :: phis_loc(iip1,jjp1)
     52 
     53  !========================
     54  ! CALCULATION of latu, latv, lonu, lonv in deg.
     55  ! ---------------------------------------------------
    5056  rad = 6400000
    5157  omeg = 7.272205e-05
     
    6571     rlatudeg(j)=rlatu(j)*180./pi
    6672  ENDDO
     73 
    6774  DO j=1,jjm
    6875     rlatvdeg(j)=rlatv(j)*180./pi
     
    7380     rlonvdeg(i)=rlonv(i)*180./pi + 360.
    7481  ENDDO
    75 
    76 
    77   !  2 ----- OUVERTURE DE LA SORTIE NETCDF
    78   ! ---------------------------------------------------
    79   ! CREATION OUTPUT
    80   ! ouverture fichier netcdf de sortie out
     82 
     83  ! CALCULATION of "false" variables on u, v, s grids
     84  ! ---------------------------------------------------
     85   DO i=1,iip1
     86     DO j=1,jjp1
     87        uwnd(i,j)=MOD(i,2)+MOD(j,2)
     88        temp(i,j)=MOD(i,2)+MOD(j,2)
     89     ENDDO
     90     DO j=1,jjm
     91        vwnd(i,j)=MOD(i,2)+MOD(j,2)
     92     END DO
     93  ENDDO 
     94
     95  ! CALCULATION of local vars for presnivs, mask, sfc. geopot. height
     96  ! ---------------------------------------------------
     97  rlev(:) = presnivs(:)
     98  phis_loc(:,:) = phis(:,:)/g
     99  masque_int(:,:) = nINT(masque(:,:))
     100
     101
     102  ! OPEN output netcdf file
     103  !-------------------------
    81104  status=NF_CREATE('grilles_gcm.nc',IOR(NF_CLOBBER,NF_64BIT_OFFSET),ncid_out)
    82105  CALL handle_err(status)
     106 
     107  ! DEFINE output dimensions
     108  !-------------------------
    83109  status=NF_DEF_DIM(ncid_out,'lonu',iim+1,out_lonudim)
    84110  CALL handle_err(status)
     
    89115  status=NF_DEF_DIM(ncid_out,'latv',jjm,out_latvdim)
    90116  CALL handle_err(status)
    91 
    92 
    93   !   Longitudes en u
     117  !
     118  status=NF_DEF_DIM(ncid_out,'lev',llm,out_levdim)
     119  CALL handle_err(status)
     120 
     121  ! DEFINE output variables
     122  !-------------------------
     123  !   Longitudes on "u" dynamical grid
    94124  status=NF90_DEF_VAR(ncid_out,'lonu',NF90_FLOAT,out_lonudim, out_lonuid)
    95125  CALL handle_err(status)
    96126  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'units', 12,'degrees_east')
    97   status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',9,'Longitude en u')
    98 
    99   !   Longitudes en v
     127  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',19,'Longitude on u grid')
     128  !   Longitudes on "v" dynamical grid
    100129  status=NF90_DEF_VAR(ncid_out,'lonv',NF90_FLOAT,out_lonvdim, out_lonvid)
    101130  CALL handle_err(status)
    102131  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'units', 12,'degrees_east')
    103   status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name', 9,'Longitude en v')
    104 
    105   !   Latitude en u
     132  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name', 19,'Longitude on v grid')
     133  !   Latitudes on "u" dynamical grid
    106134  status=NF90_DEF_VAR(ncid_out,'latu',NF90_FLOAT,out_latudim, out_latuid)
    107135  CALL handle_err(status)
    108136  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'units', 13,'degrees_north')
    109   status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name', 8,'Latitude en u')
    110 
    111   !  Latitude en v
     137  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name', 18,'Latitude on u grid')
     138  !  Latitudes on "v" dynamical grid
    112139  status=NF90_DEF_VAR(ncid_out,'latv',NF90_FLOAT,out_latvdim, out_latvid)
    113140  CALL handle_err(status)
    114141  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'units', 13,'degrees_north')
    115   status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name', 8,'Latitude en v')
    116 
    117   !   ecriture de la grille u
     142  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name', 18,'Latitude on v grid')
     143  !  "u" lat/lon dynamical grid
    118144  out_dim(1)=out_lonudim
    119145  out_dim(2)=out_latudim
    120   status=NF90_DEF_VAR(ncid_out,'grille_u',NF90_FLOAT,out_dim, out_varid)
    121   CALL handle_err(status)
    122   status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
    123   status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point u')
    124 
    125   !   ecriture de la grille v
     146  status=NF90_DEF_VAR(ncid_out,'grille_u',NF90_FLOAT,out_dim, out_uid)
     147  CALL handle_err(status)
     148  status=NF_PUT_ATT_TEXT(ncid_out,out_uid,'units', 3,'m/s')
     149  status=NF_PUT_ATT_TEXT(ncid_out,out_uid,'long_name', 21,'u-wind dynamical grid')
     150  !  "v" lat/lon dynamical grid
    126151  out_dim(1)=out_lonvdim
    127152  out_dim(2)=out_latvdim
    128   status=NF90_DEF_VAR(ncid_out,'grille_v',NF90_FLOAT,out_dim, out_varid)
    129   CALL handle_err(status)
    130   status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
    131   status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point v')
    132 
    133   !   ecriture de la grille u
     153  status=NF90_DEF_VAR(ncid_out,'grille_v',NF90_FLOAT,out_dim, out_vid)
     154  CALL handle_err(status)
     155  status=NF_PUT_ATT_TEXT(ncid_out,out_vid,'units', 3,'m/s')
     156  status=NF_PUT_ATT_TEXT(ncid_out,out_vid,'long_name', 21,'v-wind dynamical grid')
     157  !  "s" (scalar) lat/lon dynamical grid
    134158  out_dim(1)=out_lonvdim
    135159  out_dim(2)=out_latudim
    136   status=NF90_DEF_VAR(ncid_out,'grille_s',NF90_FLOAT,out_dim, out_varid)
    137   CALL handle_err(status)
    138   status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
    139   status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',16,'Grille aux point u')
    140 
    141   status=NF_ENDDEF(ncid_out)
    142   write(*,*) "COUCOU 6"
    143   CALL handle_err(status)
    144   ! 5) ----- FERMETURE DES FICHIERS NETCDF------------------
    145   ! --------------------------------------------------------
    146   ! 3-b- Ecriture de la grille pour la sortie
    147   ! rajoute l'ecriture de la grille
    148 
    149   status=NF90_PUT_VAR(ncid_out,out_lonuid,rlonudeg,[1],[iim+1])
    150   CALL handle_err(status)
    151   status=NF90_PUT_VAR(ncid_out,out_lonvid,rlonvdeg,[1],[iim+1])
    152   CALL handle_err(status)
    153   status=NF90_PUT_VAR(ncid_out,out_latuid,rlatudeg,[1],[jjm+1])
    154   CALL handle_err(status)
    155   status=NF90_PUT_VAR(ncid_out,out_latvid,rlatvdeg,[1],[jjm])
    156   CALL handle_err(status)
    157 
    158   start(1)=1
    159   start(2)=1
    160   start(3)=1
    161   start(4)=1
    162 
    163   COUNT(1)=iim+1
    164   COUNT(2)=jjm+1
    165   COUNT(3)=1
    166   COUNT(4)=1
    167 
    168   DO j=1,jjm+1
    169      DO i=1,iim+1
    170         temp(i,j)=MOD(i,2)+MOD(j,2)
    171      ENDDO
    172   ENDDO
    173 
    174   status=NF90_PUT_VAR(ncid_out,out_varid,temp,start, count)
    175   CALL handle_err(status)
    176 
    177   ! On re-ouvre le fichier pour rajouter 4 nouvelles variables necessaire pour INCA
    178 ! lev - phis - aire - mask
    179 ! rlevdeg(:) = presnivs
    180   rlevdeg(:) = presnivs(:)
    181   phis_loc(:,:) = phis(:,:)/g
    182 
    183 ! niveaux de pression verticaux
    184   status = NF_REDEF (ncid_out)
    185   CALL handle_err(status)
    186   status=NF_DEF_DIM(ncid_out,'lev',llm,out_levdim)
    187   CALL handle_err(status)
    188   status=NF90_DEF_VAR(ncid_out,'presnivs',NF90_FLOAT,out_levdim,&
    189                     presnivs_id)
    190   CALL handle_err(status)
    191  
    192 ! fields
     160  status=NF90_DEF_VAR(ncid_out,'grille_s',NF90_FLOAT,out_dim, out_tempid)
     161  CALL handle_err(status)
     162  status=NF_PUT_ATT_TEXT(ncid_out,out_tempid,'units', 6,'Kelvin')
     163  status=NF_PUT_ATT_TEXT(ncid_out,out_tempid,'long_name',21,'scalar dynamical grid')
     164  !
     165  ! for INCA :
     166  ! vertical levels "presnivs"
     167  status=NF90_DEF_VAR(ncid_out,'presnivs',NF90_FLOAT,out_levdim, presnivs_id)
     168  CALL handle_err(status)
     169  status=NF_PUT_ATT_TEXT(ncid_out,presnivs_id,'units', 2,'Pa')
     170  status=NF_PUT_ATT_TEXT(ncid_out,presnivs_id,'long_name',15,'Vertical levels')
     171  ! surface geopotential height: named "phis" as the sfc geopotential, is actually phis/g
    193172  out_dim(1)=out_lonvdim
    194173  out_dim(2)=out_latudim
    195 
    196174  status = nf90_def_var(ncid_out,'phis',NF90_FLOAT,out_dim,phis_id)
    197175  CALL handle_err(status)
     176  status=NF_PUT_ATT_TEXT(ncid_out,phis_id,'units', 1,'m')
     177  status=NF_PUT_ATT_TEXT(ncid_out,phis_id,'long_name',27,'surface geopotential height')
     178  ! gridcell area
    198179  status = nf90_def_var(ncid_out,'aire',NF90_FLOAT,out_dim,area_id)
    199180  CALL handle_err(status)
     181  status=NF_PUT_ATT_TEXT(ncid_out,area_id,'units', 2,'m2')
     182  status=NF_PUT_ATT_TEXT(ncid_out,area_id,'long_name',13,'gridcell area')
     183  ! land-sea mask (nearest integer approx)
    200184  status = nf90_def_var(ncid_out,'mask',NF90_INT,out_dim,mask_id)
    201185  CALL handle_err(status)
    202 
    203   status=NF_ENDDEF(ncid_out)
    204   CALL handle_err(status)
    205 
    206   ! ecriture des variables
    207   status=NF90_PUT_VAR(ncid_out,presnivs_id,rlevdeg,[1],[llm])
    208   CALL handle_err(status)
    209 
    210   start(1)=1
    211   start(2)=1
    212   start(3)=1
    213   start(4)=0
     186  status=NF_PUT_ATT_TEXT(ncid_out,mask_id,'long_name',27,'land-sea mask (nINT approx)')
     187 
     188  ! END the 'define' mode in netCDF file
     189  status=NF_ENDDEF(ncid_out) 
     190  CALL handle_err(status)
     191 
     192  ! WRITE the variables
     193  !-------------------------
     194  ! 1D : lonu, lonv,latu,latv ; INCA : presnivs
     195  status=NF90_PUT_VAR(ncid_out,out_lonuid,rlonudeg,[1],[iip1])
     196  CALL handle_err(status)
     197  status=NF90_PUT_VAR(ncid_out,out_lonvid,rlonvdeg,[1],[iip1])
     198  CALL handle_err(status)
     199  status=NF90_PUT_VAR(ncid_out,out_latuid,rlatudeg,[1],[jjp1])
     200  CALL handle_err(status)
     201  status=NF90_PUT_VAR(ncid_out,out_latvid,rlatvdeg,[1],[jjm])
     202  CALL handle_err(status)
     203  status=NF90_PUT_VAR(ncid_out,presnivs_id,rlev,[1],[llm])
     204  CALL handle_err(status)
     205
     206  ! 2D : grille_u,grille_v,grille_s ; INCA: phis,aire,mask
     207  start(:)=1
    214208  COUNT(1)=iip1
    215   COUNT(2)=jjp1
    216   COUNT(3)=1
    217   COUNT(4)=0
    218 
     209 
     210  COUNT(2)=jjp1  ! for "u" and "s" grids
     211  status=NF90_PUT_VAR(ncid_out,out_uid,uwnd,start, count)
     212  CALL handle_err(status)
     213  COUNT(2)=jjm  ! for "v" grid
     214  status=NF90_PUT_VAR(ncid_out,out_vid,vwnd,start, count)
     215  CALL handle_err(status)
     216  COUNT(2)=jjp1  ! as "s" grid, for all the following vars
     217  status=NF90_PUT_VAR(ncid_out,out_tempid,temp,start, count)
     218  CALL handle_err(status)
    219219  status = nf90_put_var(ncid_out, phis_id, phis_loc,start,count)
    220   CALL handle_err(status)
     220  CALL handle_err(status) 
    221221  status = nf90_put_var(ncid_out, area_id, aire,start,count)
    222   CALL handle_err(status)
    223   masque_int(:,:) = nINT(masque(:,:))
     222  CALL handle_err(status)
    224223  status = nf90_put_var(ncid_out, mask_id,masque_int,start,count)
    225224  CALL handle_err(status)
    226225 
    227   ! fermeture du fichier netcdf
     226  ! CLOSE netcdf file
    228227  CALL ncclos(ncid_out,rcode_out)
     228  write(*,*) "END grilles_gcm_netcdf_sub OK"
    229229
    230230END SUBROUTINE grilles_gcm_netcdf_sub
    231 
    232231
    233232
Note: See TracChangeset for help on using the changeset viewer.