source: palm/trunk/SOURCE/close_file.f90 @ 1993

Last change on this file since 1993 was 1993, checked in by suehring, 8 years ago

last commit documented

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