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