source: LMDZ5/trunk/libf/dyn3d_common/grilles_gcm_netcdf_sub.F90 @ 2198

Last change on this file since 2198 was 1984, checked in by Ehouarn Millour, 11 years ago

Cleanup and update of "grilles_gcm_netcdf_sub": removed old version, removed flag "grilles_gcm_netcdf" used to trigger output of grilles_gcm.nc file (file will now always be created) and fixed writing vertical levels presnivs in the file.
JBM+EM

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
File size: 7.6 KB
Line 
1!
2! $Id: $
3!
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.
8!
9SUBROUTINE grilles_gcm_netcdf_sub(masque,phis)
10
11  IMPLICIT NONE
12
13  INCLUDE "dimensions.h"
14  INCLUDE "paramet.h"
15  INCLUDE "comconst.h"
16  INCLUDE "comgeom.h"
17  INCLUDE "comvert.h"
18  INCLUDE "netcdf.inc"
19  INCLUDE "serre.h"
20
21
22  REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: masque ! masque terre/mer
23  REAL,DIMENSION(iip1,jjp1),INTENT(IN)  :: phis   ! geopotentiel au sol
24
25  REAL temp(iim+1,jjm+1)
26  ! Attributs netcdf sortie
27  INTEGER ncid_out,rcode_out
28  INTEGER out_lonuid,out_lonvid,out_latuid,out_latvid,out_levid
29  INTEGER out_varid
30  INTEGER out_lonudim,out_lonvdim
31  INTEGER out_latudim,out_latvdim,out_dim(3)
32  INTEGER out_levdim
33
34  INTEGER, PARAMETER :: longcles = 20
35  REAL  clesphy0(longcles)
36
37  INTEGER start(4),COUNT(4)
38
39  INTEGER status,i,j
40  REAL rlatudeg(jjp1),rlatvdeg(jjm),rlevdeg(llm)
41  REAL rlonudeg(iip1),rlonvdeg(iip1)
42
43  REAL dlon1(iip1),dlon2(iip1),dlat1(jjp1),dlat2(jjp1)
44  REAL acoslat,dxkm,dykm,resol(iip1,jjp1)
45  REAL,DIMENSION(iip1,jjp1)  :: phis_loc
46  INTEGER masque_int(iip1,jjp1)
47  INTEGER :: phis_id
48  INTEGER :: area_id
49  INTEGER :: mask_id
50  INTEGER :: presnivs_id
51 
52  rad = 6400000
53  omeg = 7.272205e-05
54  g = 9.8
55  kappa = 0.285716
56  daysec = 86400
57  cpp = 1004.70885
58
59  preff = 101325.
60  pa= 50000.
61
62  CALL conf_gcm( 99, .TRUE. , clesphy0 )
63  CALL iniconst
64  CALL inigeom
65
66  DO j=1,jjp1
67     rlatudeg(j)=rlatu(j)*180./pi
68  ENDDO
69  DO j=1,jjm
70     rlatvdeg(j)=rlatv(j)*180./pi
71  ENDDO
72
73  DO i=1,iip1
74     rlonudeg(i)=rlonu(i)*180./pi + 360.
75     rlonvdeg(i)=rlonv(i)*180./pi + 360.
76  ENDDO
77
78
79  !  2 ----- OUVERTURE DE LA SORTIE NETCDF
80  ! ---------------------------------------------------
81  ! CREATION OUTPUT
82  ! ouverture fichier netcdf de sortie out
83  status=NF_CREATE('grilles_gcm.nc',NF_CLOBBER,ncid_out)
84  CALL handle_err(status)
85  status=NF_DEF_DIM(ncid_out,'lonu',iim+1,out_lonudim)
86  CALL handle_err(status)
87  status=NF_DEF_DIM(ncid_out,'lonv',iim+1,out_lonvdim)
88  CALL handle_err(status)
89  status=NF_DEF_DIM(ncid_out,'latu',jjm+1,out_latudim)
90  CALL handle_err(status)
91  status=NF_DEF_DIM(ncid_out,'latv',jjm,out_latvdim)
92  CALL handle_err(status)
93
94
95  !   Longitudes en u
96  status=NF_DEF_VAR(ncid_out,'lonu',NF_FLOAT,1,out_lonudim, out_lonuid)
97  CALL handle_err(status)
98  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'units', 12,'degrees_east')
99  status=NF_PUT_ATT_TEXT(ncid_out,out_lonuid,'long_name',9,'Longitude en u')
100
101  !   Longitudes en v
102  status=NF_DEF_VAR(ncid_out,'lonv',NF_FLOAT,1,out_lonvdim, out_lonvid)
103  CALL handle_err(status)
104  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'units', 12,'degrees_east')
105  status=NF_PUT_ATT_TEXT(ncid_out,out_lonvid,'long_name', 9,'Longitude en v')
106
107  !   Latitude en u
108  status=NF_DEF_VAR(ncid_out,'latu',NF_FLOAT,1,out_latudim, out_latuid)
109  CALL handle_err(status)
110  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'units', 13,'degrees_north')
111  status=NF_PUT_ATT_TEXT(ncid_out,out_latuid,'long_name', 8,'Latitude en u')
112
113  !  Latitude en v
114  status=NF_DEF_VAR(ncid_out,'latv',NF_FLOAT,1,out_latvdim, out_latvid)
115  CALL handle_err(status)
116  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'units', 13,'degrees_north')
117  status=NF_PUT_ATT_TEXT(ncid_out,out_latvid,'long_name', 8,'Latitude en v')
118
119  !   ecriture de la grille u
120  out_dim(1)=out_lonudim
121  out_dim(2)=out_latudim
122  status=NF_DEF_VAR(ncid_out,'grille_u',NF_FLOAT,2,out_dim, out_varid)
123  CALL handle_err(status)
124  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
125  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point u')
126
127  !   ecriture de la grille v
128  out_dim(1)=out_lonvdim
129  out_dim(2)=out_latvdim
130  status=NF_DEF_VAR(ncid_out,'grille_v',NF_FLOAT,2,out_dim, out_varid)
131  CALL handle_err(status)
132  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
133  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name', 16,'Grille aux point v')
134
135  !   ecriture de la grille u
136  out_dim(1)=out_lonvdim
137  out_dim(2)=out_latudim
138  status=NF_DEF_VAR(ncid_out,'grille_s',NF_FLOAT,2,out_dim, out_varid)
139  CALL handle_err(status)
140  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'units', 6,'Kelvin')
141  status=NF_PUT_ATT_TEXT(ncid_out,out_varid,'long_name',16,'Grille aux point u')
142
143  status=NF_ENDDEF(ncid_out)
144  write(*,*) "COUCOU 6"
145  CALL handle_err(status)
146  ! 5) ----- FERMETURE DES FICHIERS NETCDF------------------
147  ! --------------------------------------------------------
148  ! 3-b- Ecriture de la grille pour la sortie
149  ! rajoute l'ecriture de la grille
150
151#ifdef NC_DOUBLE
152  status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonuid,1,iim+1,rlonudeg)
153  CALL handle_err(status)
154  status=NF_PUT_VARA_DOUBLE(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
155  CALL handle_err(status)
156  status=NF_PUT_VARA_DOUBLE(ncid_out,out_latuid,1,jjm+1,rlatudeg)
157  CALL handle_err(status)
158  status=NF_PUT_VARA_DOUBLE(ncid_out,out_latvid,1,jjm,rlatvdeg)
159  CALL handle_err(status)
160#else
161  status=NF_PUT_VARA_REAL(ncid_out,out_lonuid,1,iim+1,rlonudeg)
162  CALL handle_err(status)
163  status=NF_PUT_VARA_REAL(ncid_out,out_lonvid,1,iim+1,rlonvdeg)
164  CALL handle_err(status)
165  status=NF_PUT_VARA_REAL(ncid_out,out_latuid,1,jjm+1,rlatudeg)
166  CALL handle_err(status)
167  status=NF_PUT_VARA_REAL(ncid_out,out_latvid,1,jjm,rlatvdeg)
168  CALL handle_err(status)
169#endif
170
171  start(1)=1
172  start(2)=1
173  start(3)=1
174  start(4)=1
175
176  COUNT(1)=iim+1
177  COUNT(2)=jjm+1
178  COUNT(3)=1
179  COUNT(4)=1
180
181  DO j=1,jjm+1
182     DO i=1,iim+1
183        temp(i,j)=MOD(i,2)+MOD(j,2)
184     ENDDO
185  ENDDO
186
187#ifdef NC_DOUBLE
188  status=NF_PUT_VARA_DOUBLE(ncid_out,out_varid,start, count,temp)
189  CALL handle_err(status)
190#else
191  status=NF_PUT_VARA_REAL(ncid_out,out_varid,start, count,temp)
192  CALL handle_err(status)
193#endif
194
195  ! On re-ouvre le fichier pour rajouter 4 nouvelles variables necessaire pour INCA
196! lev - phis - aire - mask
197! rlevdeg(:) = presnivs
198  rlevdeg(:) = presnivs(:)
199  phis_loc(:,:) = phis(:,:)/g
200
201! niveaux de pression verticaux
202  status = NF_REDEF (ncid_out)
203  CALL handle_err(status)
204  status=NF_DEF_DIM(ncid_out,'lev',llm,out_levdim)
205  CALL handle_err(status)
206  status=NF_DEF_VAR(ncid_out,'presnivs',NF_FLOAT,1,out_levdim,&
207                    presnivs_id)
208  CALL handle_err(status)
209 
210! fields
211  out_dim(1)=out_lonvdim
212  out_dim(2)=out_latudim
213
214  status = nf_def_var(ncid_out,'phis',NF_FLOAT,2,out_dim,phis_id)
215  CALL handle_err(status)
216  status = nf_def_var(ncid_out,'aire',NF_FLOAT,2,out_dim,area_id)
217  CALL handle_err(status)
218  status = nf_def_var(ncid_out,'mask',NF_INT  ,2,out_dim,mask_id)
219  CALL handle_err(status)
220
221  status=NF_ENDDEF(ncid_out)
222  CALL handle_err(status)
223
224  ! ecriture des variables
225#ifdef NC_DOUBLE
226  status=NF_PUT_VARA_DOUBLE(ncid_out,presnivs_id,1,llm,rlevdeg)
227  CALL handle_err(status)
228#else
229  status=NF_PUT_VARA_REAL(ncid_out,out_levid,1,llm,rlevdeg)
230  CALL handle_err(status)
231#endif
232
233  start(1)=1
234  start(2)=1
235  start(3)=1
236  start(4)=0
237  COUNT(1)=iip1
238  COUNT(2)=jjp1
239  COUNT(3)=1
240  COUNT(4)=0
241
242  status = nf_put_vara_double(ncid_out, phis_id,start,count, phis_loc)
243  CALL handle_err(status)
244  status = nf_put_vara_double(ncid_out, area_id,start,count, aire)
245  CALL handle_err(status)
246  masque_int(:,:) = nINT(masque(:,:))
247  status = nf_put_vara_int(ncid_out, mask_id,start,count,masque_int)
248  CALL handle_err(status)
249 
250  ! fermeture du fichier netcdf
251  CALL ncclos(ncid_out,rcode_out)
252
253END SUBROUTINE grilles_gcm_netcdf_sub
254
255
256
257SUBROUTINE handle_err(status)
258  INCLUDE "netcdf.inc"
259
260  INTEGER status
261  IF (status.NE.nf_noerr) THEN
262     PRINT *,NF_STRERROR(status)
263     CALL abort_gcm('grilles_gcm_netcdf','netcdf error',1)
264  ENDIF
265END SUBROUTINE handle_err
266
Note: See TracBrowser for help on using the repository browser.