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

Last change on this file since 1327 was 1327, checked in by raasch, 10 years ago

Changed:


-s real64 removed (.mrun.config.hlrnIII)
-r8 removed (.mrun.config.imuk)
deleted: .mrun.config.imuk_ice2_netcdf4 .mrun.config.imuk_hlrn

REAL constants defined as wp-kind in modules

"baroclinicity" renamed "baroclinity", "ocean version" replaced by
"ocean mode"

code parts concerning old output formats "iso2d" and "avs" removed.
netCDF is the only remaining output format.

Errors:


bugfix: duplicate error message 56 removed

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