SURFEX  V8_0
Surfex V8_0 release
 All Classes Files Functions Variables
init_output_ncn.F90
Go to the documentation of this file.
1 !SFX_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier
2 !SFX_LIC This is part of the SURFEX software governed by the CeCILL-C licence
3 !SFX_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4 !SFX_LIC for details. version 1.
5 ! #########
6  SUBROUTINE init_output_nc_n (BDD, CHE, CHN, CHU, DTS, DTT, DTZ, I, UG, U, DGU)
7 ! ######################
8 !
9 !!**** *INIT_OUTPUT_NC* Keep in memory the netcdf ID of the output files
10 !!
11 !! PURPOSE
12 !! -------
13 !
14 !!
15 !!** IMPLICIT ARGUMENTS
16 !! ------------------
17 !! None
18 !!
19 !! REFERENCE
20 !! ---------
21 !!
22 !! AUTHOR
23 !! ------
24 !! F. Habets *Meteo France*
25 !!
26 !! MODIFICATIONS
27 !! -------------
28 !! modified 05/04 by P. LeMoigne *Meteo France*
29 !! modified 06/10 by S. Faroux *Meteo France*
30 !!=================================================================
31 !
32 !* 0. DECLARATIONS
33 ! ------------
34 !
39 USE modd_ch_surf_n, ONLY : ch_surf_t
41 USE modd_data_teb_n, ONLY : data_teb_t
42 USE modd_data_tsz0_n, ONLY : data_tsz0_t
43 USE modd_isba_n, ONLY : isba_t
45 USE modd_surf_atm_n, ONLY : surf_atm_t
46 !
47 USE modd_surf_conf, ONLY : csoftware
48 !
49 USE modd_surfex_mpi, ONLY : npio, nrank
50 !
51 USE modd_ol_fileid, ONLY : xvar_to_fileout, xid, xout
52 !
53 USE modd_data_cover, ONLY : ldata_irrig
54 USE modd_data_cover_par, ONLY : nvegtype, jpcover
55 !
56 !
57 !
58 !
59 USE modd_io_surf_nc, ONLY : cfileout_nc, nid_nc, &
60  lcreated, cfileout_nc_save, ldef
61 !
62 USE modn_io_offline, ONLY : lrestart, lwrite_coord
63 !
65 !
66 USE modi_get_bld_conf_n
67 USE modi_get_data_seaflux_conf_n
68 USE modi_get_isba_conf_n
69 USE modi_ol_define_dim
70 USE modi_create_file
71 !
72 USE modi_get_dim_full_n
73 USE modi_def_var_netcdf
74 !
75 USE yomhook ,ONLY : lhook, dr_hook
76 USE parkind1 ,ONLY : jprb
77 !
78 IMPLICIT NONE
79 !
80 include "netcdf.inc"
81 !
82 !
83 TYPE(bld_desc_t), INTENT(INOUT) :: bdd
84 TYPE(ch_emis_field_t), INTENT(INOUT) :: che
85 TYPE(ch_emis_snap_t), INTENT(INOUT) :: chn
86 TYPE(ch_surf_t), INTENT(INOUT) :: chu
87 TYPE(data_seaflux_t), INTENT(INOUT) :: dts
88 TYPE(data_teb_t), INTENT(INOUT) :: dtt
89 TYPE(data_tsz0_t), INTENT(INOUT) :: dtz
90 TYPE(isba_t), INTENT(INOUT) :: i
91 TYPE(surf_atm_grid_t), INTENT(INOUT) :: ug
92 TYPE(surf_atm_t), INTENT(INOUT) :: u
93 TYPE(diag_surf_atm_t), INTENT(INOUT) :: dgu
94 !
95  CHARACTER(LEN=100), DIMENSION(:), POINTER :: yname_dim
96  CHARACTER(LEN=100), DIMENSION(1) :: yatt_title, yatt
97  CHARACTER(LEN=13),DIMENSION(1) :: yunit1, yunit2
98  CHARACTER(LEN=3) :: yisba
99 !
100 REAL,DIMENSION(:), POINTER :: zx, zy
101 !
102 INTEGER, DIMENSION(:), POINTER :: idims, iddim
103 INTEGER :: idim1, indims
104 INTEGER :: ini, inpatch, inlvld, inlvls, inbiomass, &
105  inlitter, inlittlevs, insoilcarb
106 INTEGER :: idesc_roof_layer, idesc_road_layer, idesc_wall_layer, &
107  idesc_floor_layer, idesc_code, idesc_use, idesc_age, idesc_bld
108 INTEGER :: iret, il, ifull, isnap, inlati
109 INTEGER :: iluout, idimid, itime, itot
110 INTEGER :: id0
111 !
112 LOGICAL :: gexist, gopened, gsst_data
113 LOGICAL :: gdata_bldtype, gdata_bld_age, gdata_usetype
114 !
115 REAL(KIND=JPRB) :: zhook_handle
116 !------------------------------------------------------------------------------
117 IF (lhook) CALL dr_hook('INIT_OUTPUT_NC_N',0,zhook_handle)
118 !
119  CALL get_dim_full_n(u, &
120  ifull)
121 
122 IF (nrank==npio) THEN
123  INQUIRE(file=cfileout_nc,exist=gexist)
124  INQUIRE(file=cfileout_nc,opened=gopened)
125  IF (.NOT.gopened) THEN
126  iret = nf_open(cfileout_nc,nf_write,nid_nc)
127  ENDIF
128  IF (.NOT.gexist .OR. .NOT.lcreated .OR. cfileout_nc/=cfileout_nc_save) THEN
129  IF (csoftware=='PREP' .OR. csoftware=='OFFLINE' .OR. csoftware=='SODA') THEN
130  CALL get_isba_conf_n(i, &
131  yisba, inpatch, inlvld, inlvls, inbiomass, &
132  inlitter, inlittlevs, insoilcarb)
133  ELSEIF (csoftware=='PGD') THEN
134  inpatch = nvegtype
135  ENDIF
136  IF (ug%CGRID=='IGN') lwrite_coord = .true.
137  CALL ol_define_dim(ug, u, &
138  'NOTIME ', iluout, ifull, idim1, yunit1, yunit2, &
139  zx, zy, idims, iddim, yname_dim, knpatch=inpatch)
140  IF (ALLOCATED(xvar_to_fileout)) DEALLOCATE(xvar_to_fileout)
141  IF (ALLOCATED(xid)) DEALLOCATE(xid)
142  ALLOCATE(xid(0))
143  xout=0
144  CALL create_file(cfileout_nc,idims,yname_dim,nid_nc,iddim)
145  IF (ug%CGRID=='IGN') THEN
146  yatt_title(1) = "comment"
147  yatt(1) = "longitude"
148  CALL def_var_netcdf(dgu,nid_nc,'XLON','XLON',iddim(1:1),yatt_title,yatt,id0,nf_double)
149  yatt(1) = "latitude"
150  CALL def_var_netcdf(dgu,nid_nc,'XLAT','XLAT',iddim(1:1),yatt_title,yatt,id0,nf_double)
151  ENDIF
152  cfileout_nc_save = cfileout_nc
153  lcreated = .true.
154  IF (csoftware=='PGD' .OR. ( csoftware=='OFFLINE' .AND. lrestart ) ) THEN
155  iret = nf_def_dim(nid_nc,"Number_of_covers",jpcover,idimid)
156  IF (ldata_irrig) iret = nf_def_dim(nid_nc,"Irrig_parameters",6,idimid)
157  CALL get_isba_conf_n(i, &
158  yisba, inpatch, inlvld, inlvls, inbiomass, &
159  inlitter, inlittlevs, insoilcarb)
160  IF (yisba=='DIF') iret = nf_def_dim(nid_nc,"Nground_layers",inlvld,idimid)
161  CALL get_data_seaflux_conf_n(dts, &
162  gsst_data,itime)
163  IF (gsst_data) iret = nf_def_dim(nid_nc,"Number_of_dates",itime,idimid)
164  CALL get_bld_conf_n(bdd, dtt, &
165  gdata_bldtype, gdata_bld_age, gdata_usetype, &
166  idesc_roof_layer, idesc_road_layer, idesc_wall_layer, &
167  idesc_floor_layer, idesc_code, idesc_use, idesc_age, idesc_bld)
168  IF (gdata_bldtype .OR. gdata_bld_age .OR. gdata_usetype) THEN
169  itot = (21+3*idesc_roof_layer+3*idesc_road_layer+3*idesc_wall_layer+3*idesc_floor_layer)&
170  *idesc_code + 9*idesc_use+2*idesc_age+idesc_bld
171  iret = nf_def_dim(nid_nc,"Bld_dimensions ",7,idimid)
172  iret = nf_def_dim(nid_nc,"Bld_parameters ",itot,idimid)
173  ENDIF
174  IF (chu%LCH_EMIS) THEN
175  IF (chu%CCH_EMIS=='AGGR') THEN
176  IF (che%NEMIS_NBR/=0) iret = nf_def_dim(nid_nc,"Temporal_emiss ",che%NTIME_MAX,idimid)
177  ELSE IF (chu%CCH_EMIS=='SNAP') THEN
178  isnap = max(chn%NSNAP_M,chn%NSNAP_D,chn%NSNAP_H)
179  IF (isnap/=0 .AND. chn%NEMIS_SNAP/=0) THEN
180  iret = nf_def_dim(nid_nc,"Nemis_snap",chn%NEMIS_SNAP,idimid)
181  iret = nf_def_dim(nid_nc,"Nsnap_temp",isnap,idimid)
182  ENDIF
183  ENDIF
184  ENDIF
185  IF (ASSOCIATED(dtz%XDATA_DTS)) THEN
186  itime = SIZE(dtz%XDATA_DTS)
187  IF (itime/=0) iret = nf_def_dim(nid_nc,"Nforc_tsz0",itime,idimid)
188  ENDIF
189  ENDIF
190  IF (ug%CGRID=='GAUSS') THEN
191  CALL get_gridtype_gauss(ug%XGRID_PAR,inlati)
192  iret = nf_def_dim(nid_nc,"Nlati",inlati,idimid)
193  ENDIF
194  ELSE
195  IF (ldef) iret = nf_redef(nid_nc)
196  ENDIF
197  IF (ldef) iret = nf_enddef(nid_nc)
198  iret = nf_close(nid_nc)
199 ENDIF
200 !
201 !------------------------------------------------------------------------------
202 IF (lhook) CALL dr_hook('INIT_OUTPUT_NC_N',1,zhook_handle)
203 !------------------------------------------------------------------------------
204 !
205 END SUBROUTINE init_output_nc_n
subroutine create_file(HFILE, KDIMS, HNAME_DIM, KFILE_ID, KDIM_ID)
Definition: create_file.F90:6
subroutine init_output_nc_n(BDD, CHE, CHN, CHU, DTS, DTT, DTZ, I, UG, U, DGU)
subroutine get_data_seaflux_conf_n(DTS, OSST_DATA, KTIME)
subroutine get_dim_full_n(U, KDIM_FULL)
subroutine get_isba_conf_n(I, HISBA, KPATCH, KGROUND_LAYER, KSNOW_LAYER, KNBIOMASS, KNLITTER, KNLITTLEVS, KNSOILCARB)
subroutine get_gridtype_gauss(PGRID_PAR, KNLATI, PLAPO, PLOPO, PCODIL, KNLOPA, KL, PLAT, PLON, PLAT_XY, PLON_XY, PMESH_SIZE, PLONINF, PLATINF, PLONSUP, PLATSUP)
subroutine ol_define_dim(UG, U, HPROGRAM, KLUOUT, KNI, KDIM1, HUNIT1, HUNIT2, PX, PY, KDIMS, KDDIM, HNAME_DIM, KNPATCH)
subroutine def_var_netcdf(DGU, KFILE_ID, HNAME, HLONG_NAME, KDIM_ID, HATT_TITLE, HATT_TEXT, KVAR_ID, KTYPE, KLEN)
subroutine get_bld_conf_n(BDD, DTT, ODATA_BLDTYPE, ODATA_BLD_AGE, ODATA_USETYPE, KDESC_ROOF_LAYER, KDESC_ROAD_LAYER, KDESC_WALL_LAYER, KDESC_FLOOR_LAYER, KDESC_CODE, KDESC_USE, KDESC_AGE, KDESC_BLD)