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