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