[1682] | 1 | !> @file close_file.f90 |
---|
[1036] | 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 | ! |
---|
[1818] | 16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
[1036] | 17 | !--------------------------------------------------------------------------------! |
---|
| 18 | ! |
---|
[263] | 19 | ! Current revisions: |
---|
[1] | 20 | ! ----------------- |
---|
[1993] | 21 | ! |
---|
| 22 | ! |
---|
[1321] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: close_file.f90 1993 2016-08-12 15:16:41Z knoop $ |
---|
| 26 | ! |
---|
[1993] | 27 | ! 1992 2016-08-12 15:14:59Z suehring |
---|
| 28 | ! -Close file containing flight data |
---|
| 29 | ! -Some tabs removed. |
---|
| 30 | ! |
---|
[1784] | 31 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
| 32 | ! name change of netcdf routines and module + related changes |
---|
| 33 | ! |
---|
[1683] | 34 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 35 | ! Code annotations made doxygen readable |
---|
| 36 | ! |
---|
[1329] | 37 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
| 38 | ! parts concerning iso2d and avs output removed |
---|
| 39 | ! |
---|
[1321] | 40 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 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 |
---|
[1] | 47 | ! |
---|
[1093] | 48 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 49 | ! unused variables removed |
---|
| 50 | ! |
---|
[1037] | 51 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 52 | ! code put under GPL (PALM 3.9) |
---|
| 53 | ! |
---|
[1035] | 54 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
| 55 | ! netCDF4 without parallel file support implemented |
---|
| 56 | ! |
---|
[965] | 57 | ! 964 2012-07-26 09:14:24Z raasch |
---|
| 58 | ! old profil-units (40:49) and respective code removed |
---|
| 59 | ! |
---|
[1] | 60 | ! Revision 1.1 (close_files) 1997/08/11 06:11:18 raasch |
---|
| 61 | ! Initial revision |
---|
| 62 | ! |
---|
| 63 | ! |
---|
| 64 | ! Description: |
---|
| 65 | ! ------------ |
---|
[1682] | 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. |
---|
[1] | 69 | !------------------------------------------------------------------------------! |
---|
[1682] | 70 | SUBROUTINE close_file( file_id ) |
---|
| 71 | |
---|
[1] | 72 | |
---|
[1320] | 73 | USE control_parameters, & |
---|
[1783] | 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 |
---|
[1320] | 76 | |
---|
| 77 | USE grid_variables, & |
---|
| 78 | ONLY: dy |
---|
| 79 | |
---|
| 80 | USE indices, & |
---|
| 81 | ONLY: nx, ny, nz |
---|
| 82 | |
---|
| 83 | USE kinds |
---|
| 84 | |
---|
[1783] | 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, & |
---|
[1992] | 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 |
---|
[1320] | 93 | |
---|
| 94 | USE pegrid |
---|
[1] | 95 | |
---|
| 96 | IMPLICIT NONE |
---|
| 97 | |
---|
[1682] | 98 | CHARACTER (LEN=10) :: datform = 'lit_endian' !< |
---|
| 99 | CHARACTER (LEN=80) :: title !< |
---|
[1] | 100 | |
---|
[1682] | 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 !< |
---|
[1] | 107 | |
---|
[1682] | 108 | LOGICAL :: checkuf = .TRUE. !< |
---|
| 109 | LOGICAL :: datleg = .TRUE. !< |
---|
| 110 | LOGICAL :: dbp = .FALSE. !< |
---|
[1] | 111 | |
---|
[1682] | 112 | REAL(wp) :: sizex !< |
---|
| 113 | REAL(wp) :: sizey !< |
---|
| 114 | REAL(wp) :: yright !< |
---|
[1] | 115 | |
---|
[1320] | 116 | NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dbp, planz, & |
---|
[964] | 117 | title |
---|
[1092] | 118 | NAMELIST /RAHMEN/ datleg |
---|
[1] | 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 |
---|
[564] | 134 | DO fid = 1, 200+2*max_masks |
---|
[1] | 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 | |
---|
[1327] | 144 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 145 | nc_stat = NF90_CLOSE( id_set_xy(0) ) |
---|
[1783] | 146 | CALL netcdf_handle_error( 'close_file', 44 ) |
---|
[1] | 147 | ENDIF |
---|
| 148 | |
---|
| 149 | CASE ( 102 ) |
---|
| 150 | |
---|
[1327] | 151 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 152 | nc_stat = NF90_CLOSE( id_set_xz(0) ) |
---|
[1783] | 153 | CALL netcdf_handle_error( 'close_file', 45 ) |
---|
[1] | 154 | ENDIF |
---|
| 155 | |
---|
| 156 | CASE ( 103 ) |
---|
| 157 | |
---|
[1327] | 158 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 159 | nc_stat = NF90_CLOSE( id_set_yz(0) ) |
---|
[1783] | 160 | CALL netcdf_handle_error( 'close_file', 46 ) |
---|
[1] | 161 | ENDIF |
---|
| 162 | |
---|
| 163 | CASE ( 104 ) |
---|
| 164 | |
---|
[1327] | 165 | IF ( myid == 0 ) THEN |
---|
[1] | 166 | nc_stat = NF90_CLOSE( id_set_pr ) |
---|
[1783] | 167 | CALL netcdf_handle_error( 'close_file', 47 ) |
---|
[1] | 168 | ENDIF |
---|
| 169 | |
---|
| 170 | CASE ( 105 ) |
---|
| 171 | |
---|
[1327] | 172 | IF ( myid == 0 ) THEN |
---|
[1] | 173 | nc_stat = NF90_CLOSE( id_set_ts ) |
---|
[1783] | 174 | CALL netcdf_handle_error( 'close_file', 48 ) |
---|
[1] | 175 | ENDIF |
---|
| 176 | |
---|
| 177 | CASE ( 106 ) |
---|
| 178 | |
---|
[1327] | 179 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 180 | nc_stat = NF90_CLOSE( id_set_3d(0) ) |
---|
[1783] | 181 | CALL netcdf_handle_error( 'close_file', 49 ) |
---|
[1] | 182 | ENDIF |
---|
| 183 | |
---|
| 184 | CASE ( 107 ) |
---|
| 185 | |
---|
[1327] | 186 | IF ( myid == 0 ) THEN |
---|
[1] | 187 | nc_stat = NF90_CLOSE( id_set_sp ) |
---|
[1783] | 188 | CALL netcdf_handle_error( 'close_file', 50 ) |
---|
[1] | 189 | ENDIF |
---|
| 190 | |
---|
| 191 | CASE ( 108 ) |
---|
| 192 | |
---|
[1327] | 193 | nc_stat = NF90_CLOSE( id_set_prt ) |
---|
[1783] | 194 | CALL netcdf_handle_error( 'close_file', 51 ) |
---|
[1] | 195 | |
---|
| 196 | CASE ( 109 ) |
---|
| 197 | |
---|
[1327] | 198 | nc_stat = NF90_CLOSE( id_set_pts ) |
---|
[1783] | 199 | CALL netcdf_handle_error( 'close_file', 412 ) |
---|
[1] | 200 | |
---|
| 201 | CASE ( 111 ) |
---|
| 202 | |
---|
[1327] | 203 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 204 | nc_stat = NF90_CLOSE( id_set_xy(1) ) |
---|
[1783] | 205 | CALL netcdf_handle_error( 'close_file', 52 ) |
---|
[1] | 206 | ENDIF |
---|
| 207 | |
---|
| 208 | CASE ( 112 ) |
---|
| 209 | |
---|
[1327] | 210 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 211 | nc_stat = NF90_CLOSE( id_set_xz(1) ) |
---|
[1783] | 212 | CALL netcdf_handle_error( 'close_file', 352 ) |
---|
[1] | 213 | ENDIF |
---|
| 214 | |
---|
| 215 | CASE ( 113 ) |
---|
| 216 | |
---|
[1327] | 217 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 218 | nc_stat = NF90_CLOSE( id_set_yz(1) ) |
---|
[1783] | 219 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
[1] | 220 | ENDIF |
---|
| 221 | |
---|
| 222 | CASE ( 116 ) |
---|
| 223 | |
---|
[1327] | 224 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 225 | nc_stat = NF90_CLOSE( id_set_3d(1) ) |
---|
[1783] | 226 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
[1] | 227 | ENDIF |
---|
| 228 | |
---|
[1992] | 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 | |
---|
[564] | 236 | CASE ( 201:200+2*max_masks ) |
---|
[1992] | 237 | |
---|
[1327] | 238 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[410] | 239 | ! |
---|
| 240 | !-- decompose fid into mid and av |
---|
[564] | 241 | IF ( fid <= 200+max_masks ) THEN |
---|
| 242 | mid = fid - 200 |
---|
[410] | 243 | av = 0 |
---|
| 244 | ELSE |
---|
[564] | 245 | mid = fid - (200+max_masks) |
---|
[410] | 246 | av = 1 |
---|
| 247 | ENDIF |
---|
| 248 | nc_stat = NF90_CLOSE( id_set_mask(mid,av) ) |
---|
[1783] | 249 | CALL netcdf_handle_error( 'close_file', 459 ) |
---|
[1992] | 250 | |
---|
[410] | 251 | ENDIF |
---|
| 252 | |
---|
[1] | 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 |
---|
[1320] | 266 | 3200 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'/ & |
---|
[1] | 276 | 'field=rectilinear') |
---|
| 277 | 4000 FORMAT ('time averaged over',F7.1,' s') |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | END SUBROUTINE close_file |
---|