1 | !> @file close_file.f90 |
---|
2 | !--------------------------------------------------------------------------------! |
---|
3 | ! This file is part of PALM. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
7 | ! either version 3 of the License, or (at your option) any later version. |
---|
8 | ! |
---|
9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
12 | ! |
---|
13 | ! You should have received a copy of the GNU General Public License along with |
---|
14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | ! |
---|
16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: close_file.f90 1818 2016-04-06 15:53:27Z hoffmann $ |
---|
26 | ! |
---|
27 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
28 | ! name change of netcdf routines and module + related changes |
---|
29 | ! |
---|
30 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
31 | ! Code annotations made doxygen readable |
---|
32 | ! |
---|
33 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
34 | ! parts concerning iso2d and avs output removed |
---|
35 | ! |
---|
36 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
37 | ! ONLY-attribute added to USE-statements, |
---|
38 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
39 | ! kinds are defined in new module kinds, |
---|
40 | ! revision history before 2012 removed, |
---|
41 | ! comment fields (!:) to be used for variable explanations added to |
---|
42 | ! all variable declaration statements |
---|
43 | ! |
---|
44 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
45 | ! unused variables removed |
---|
46 | ! |
---|
47 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
48 | ! code put under GPL (PALM 3.9) |
---|
49 | ! |
---|
50 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
51 | ! netCDF4 without parallel file support implemented |
---|
52 | ! |
---|
53 | ! 964 2012-07-26 09:14:24Z raasch |
---|
54 | ! old profil-units (40:49) and respective code removed |
---|
55 | ! |
---|
56 | ! Revision 1.1 (close_files) 1997/08/11 06:11:18 raasch |
---|
57 | ! Initial revision |
---|
58 | ! |
---|
59 | ! |
---|
60 | ! Description: |
---|
61 | ! ------------ |
---|
62 | !> Close specified file or all open files, if "0" has been given as the |
---|
63 | !> calling argument. In that case, execute last actions for certain unit |
---|
64 | !> numbers, if required. |
---|
65 | !------------------------------------------------------------------------------! |
---|
66 | SUBROUTINE close_file( file_id ) |
---|
67 | |
---|
68 | |
---|
69 | USE control_parameters, & |
---|
70 | ONLY: do2d_xz_n, do2d_xy_n, do2d_yz_n, do3d_avs_n, host, max_masks, & |
---|
71 | mid, nz_do3d, openfile, run_description_header, z_max_do2d |
---|
72 | |
---|
73 | USE grid_variables, & |
---|
74 | ONLY: dy |
---|
75 | |
---|
76 | USE indices, & |
---|
77 | ONLY: nx, ny, nz |
---|
78 | |
---|
79 | USE kinds |
---|
80 | |
---|
81 | #if defined( __netcdf ) |
---|
82 | USE NETCDF |
---|
83 | #endif |
---|
84 | |
---|
85 | USE netcdf_interface, & |
---|
86 | ONLY: id_set_mask, id_set_pr, id_set_prt, id_set_pts, id_set_sp, & |
---|
87 | id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d, nc_stat, & |
---|
88 | netcdf_data_format, netcdf_handle_error |
---|
89 | |
---|
90 | USE pegrid |
---|
91 | |
---|
92 | IMPLICIT NONE |
---|
93 | |
---|
94 | CHARACTER (LEN=10) :: datform = 'lit_endian' !< |
---|
95 | CHARACTER (LEN=80) :: title !< |
---|
96 | |
---|
97 | INTEGER(iwp) :: av !< |
---|
98 | INTEGER(iwp) :: dimx !< |
---|
99 | INTEGER(iwp) :: dimy !< |
---|
100 | INTEGER(iwp) :: fid !< |
---|
101 | INTEGER(iwp) :: file_id !< |
---|
102 | INTEGER(iwp) :: planz !< |
---|
103 | |
---|
104 | LOGICAL :: checkuf = .TRUE. !< |
---|
105 | LOGICAL :: datleg = .TRUE. !< |
---|
106 | LOGICAL :: dbp = .FALSE. !< |
---|
107 | |
---|
108 | REAL(wp) :: sizex !< |
---|
109 | REAL(wp) :: sizey !< |
---|
110 | REAL(wp) :: yright !< |
---|
111 | |
---|
112 | NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dbp, planz, & |
---|
113 | title |
---|
114 | NAMELIST /RAHMEN/ datleg |
---|
115 | |
---|
116 | ! |
---|
117 | !-- Close specified unit number (if opened) and set a flag that it has |
---|
118 | !-- been opened one time at least |
---|
119 | IF ( file_id /= 0 ) THEN |
---|
120 | IF ( openfile(file_id)%opened ) THEN |
---|
121 | CLOSE ( file_id ) |
---|
122 | openfile(file_id)%opened = .FALSE. |
---|
123 | openfile(file_id)%opened_before = .TRUE. |
---|
124 | ENDIF |
---|
125 | RETURN |
---|
126 | ENDIF |
---|
127 | |
---|
128 | ! |
---|
129 | !-- Close all open unit numbers |
---|
130 | DO fid = 1, 200+2*max_masks |
---|
131 | |
---|
132 | IF ( openfile(fid)%opened .OR. openfile(fid)%opened_before ) THEN |
---|
133 | ! |
---|
134 | !-- Last actions for certain unit numbers |
---|
135 | SELECT CASE ( fid ) |
---|
136 | |
---|
137 | #if defined( __netcdf ) |
---|
138 | CASE ( 101 ) |
---|
139 | |
---|
140 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
141 | nc_stat = NF90_CLOSE( id_set_xy(0) ) |
---|
142 | CALL netcdf_handle_error( 'close_file', 44 ) |
---|
143 | ENDIF |
---|
144 | |
---|
145 | CASE ( 102 ) |
---|
146 | |
---|
147 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
148 | nc_stat = NF90_CLOSE( id_set_xz(0) ) |
---|
149 | CALL netcdf_handle_error( 'close_file', 45 ) |
---|
150 | ENDIF |
---|
151 | |
---|
152 | CASE ( 103 ) |
---|
153 | |
---|
154 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
155 | nc_stat = NF90_CLOSE( id_set_yz(0) ) |
---|
156 | CALL netcdf_handle_error( 'close_file', 46 ) |
---|
157 | ENDIF |
---|
158 | |
---|
159 | CASE ( 104 ) |
---|
160 | |
---|
161 | IF ( myid == 0 ) THEN |
---|
162 | nc_stat = NF90_CLOSE( id_set_pr ) |
---|
163 | CALL netcdf_handle_error( 'close_file', 47 ) |
---|
164 | ENDIF |
---|
165 | |
---|
166 | CASE ( 105 ) |
---|
167 | |
---|
168 | IF ( myid == 0 ) THEN |
---|
169 | nc_stat = NF90_CLOSE( id_set_ts ) |
---|
170 | CALL netcdf_handle_error( 'close_file', 48 ) |
---|
171 | ENDIF |
---|
172 | |
---|
173 | CASE ( 106 ) |
---|
174 | |
---|
175 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
176 | nc_stat = NF90_CLOSE( id_set_3d(0) ) |
---|
177 | CALL netcdf_handle_error( 'close_file', 49 ) |
---|
178 | ENDIF |
---|
179 | |
---|
180 | CASE ( 107 ) |
---|
181 | |
---|
182 | IF ( myid == 0 ) THEN |
---|
183 | nc_stat = NF90_CLOSE( id_set_sp ) |
---|
184 | CALL netcdf_handle_error( 'close_file', 50 ) |
---|
185 | ENDIF |
---|
186 | |
---|
187 | CASE ( 108 ) |
---|
188 | |
---|
189 | nc_stat = NF90_CLOSE( id_set_prt ) |
---|
190 | CALL netcdf_handle_error( 'close_file', 51 ) |
---|
191 | |
---|
192 | CASE ( 109 ) |
---|
193 | |
---|
194 | nc_stat = NF90_CLOSE( id_set_pts ) |
---|
195 | CALL netcdf_handle_error( 'close_file', 412 ) |
---|
196 | |
---|
197 | CASE ( 111 ) |
---|
198 | |
---|
199 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
200 | nc_stat = NF90_CLOSE( id_set_xy(1) ) |
---|
201 | CALL netcdf_handle_error( 'close_file', 52 ) |
---|
202 | ENDIF |
---|
203 | |
---|
204 | CASE ( 112 ) |
---|
205 | |
---|
206 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
207 | nc_stat = NF90_CLOSE( id_set_xz(1) ) |
---|
208 | CALL netcdf_handle_error( 'close_file', 352 ) |
---|
209 | ENDIF |
---|
210 | |
---|
211 | CASE ( 113 ) |
---|
212 | |
---|
213 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
214 | nc_stat = NF90_CLOSE( id_set_yz(1) ) |
---|
215 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
216 | ENDIF |
---|
217 | |
---|
218 | CASE ( 116 ) |
---|
219 | |
---|
220 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
221 | nc_stat = NF90_CLOSE( id_set_3d(1) ) |
---|
222 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
223 | ENDIF |
---|
224 | |
---|
225 | CASE ( 201:200+2*max_masks ) |
---|
226 | |
---|
227 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
228 | ! |
---|
229 | !-- decompose fid into mid and av |
---|
230 | IF ( fid <= 200+max_masks ) THEN |
---|
231 | mid = fid - 200 |
---|
232 | av = 0 |
---|
233 | ELSE |
---|
234 | mid = fid - (200+max_masks) |
---|
235 | av = 1 |
---|
236 | ENDIF |
---|
237 | nc_stat = NF90_CLOSE( id_set_mask(mid,av) ) |
---|
238 | CALL netcdf_handle_error( 'close_file', 459 ) |
---|
239 | |
---|
240 | ENDIF |
---|
241 | |
---|
242 | #endif |
---|
243 | |
---|
244 | END SELECT |
---|
245 | ! |
---|
246 | !-- Close file |
---|
247 | IF ( openfile(fid)%opened ) CLOSE ( fid ) |
---|
248 | |
---|
249 | ENDIF |
---|
250 | |
---|
251 | ENDDO |
---|
252 | |
---|
253 | ! |
---|
254 | !-- Formats |
---|
255 | 3200 FORMAT ('# AVS',A,'field file'/ & |
---|
256 | '#'/ & |
---|
257 | '# ',A/ & |
---|
258 | 'ndim=3'/ & |
---|
259 | 'dim1=',I5/ & |
---|
260 | 'dim2=',I5/ & |
---|
261 | 'dim3=',I5/ & |
---|
262 | 'nspace=3'/ & |
---|
263 | 'veclen=',I5/ & |
---|
264 | 'data=xdr_float'/ & |
---|
265 | 'field=rectilinear') |
---|
266 | 4000 FORMAT ('time averaged over',F7.1,' s') |
---|
267 | |
---|
268 | |
---|
269 | END SUBROUTINE close_file |
---|