[1] | 1 | SUBROUTINE close_file( file_id ) |
---|
| 2 | |
---|
[1036] | 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 | ! |
---|
[1310] | 17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1036] | 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[263] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1320] | 22 | ! ONLY-attribute added to USE-statements, |
---|
| 23 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 24 | ! kinds are defined in new module kinds, |
---|
| 25 | ! old module precision_kind is removed, |
---|
| 26 | ! revision history before 2012 removed, |
---|
| 27 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 28 | ! all variable declaration statements |
---|
[1] | 29 | ! |
---|
| 30 | ! Former revisions: |
---|
| 31 | ! ----------------- |
---|
[3] | 32 | ! $Id: close_file.f90 1320 2014-03-20 08:40:49Z raasch $ |
---|
[392] | 33 | ! |
---|
[1093] | 34 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 35 | ! unused variables removed |
---|
| 36 | ! |
---|
[1037] | 37 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 38 | ! code put under GPL (PALM 3.9) |
---|
| 39 | ! |
---|
[1035] | 40 | ! 1031 2012-10-19 14:35:30Z raasch |
---|
| 41 | ! netCDF4 without parallel file support implemented |
---|
| 42 | ! |
---|
[965] | 43 | ! 964 2012-07-26 09:14:24Z raasch |
---|
| 44 | ! old profil-units (40:49) and respective code removed |
---|
| 45 | ! |
---|
[1] | 46 | ! Revision 1.1 (close_files) 1997/08/11 06:11:18 raasch |
---|
| 47 | ! Initial revision |
---|
| 48 | ! |
---|
| 49 | ! |
---|
| 50 | ! Description: |
---|
| 51 | ! ------------ |
---|
| 52 | ! Close specified file or all open files, if "0" has been given as the |
---|
| 53 | ! calling argument. In that case, execute last actions for certain unit |
---|
| 54 | ! numbers, if required. |
---|
| 55 | !------------------------------------------------------------------------------! |
---|
| 56 | |
---|
[1320] | 57 | USE control_parameters, & |
---|
| 58 | ONLY: do2d_xz_n, do2d_xy_n, do2d_yz_n, do3d_avs_n, do3d_compress, & |
---|
| 59 | host, iso2d_output, max_masks, mid, netcdf_data_format, & |
---|
| 60 | netcdf_output, nz_do3d, openfile, run_description_header, & |
---|
| 61 | z_max_do2d |
---|
| 62 | |
---|
| 63 | USE grid_variables, & |
---|
| 64 | ONLY: dy |
---|
| 65 | |
---|
| 66 | USE indices, & |
---|
| 67 | ONLY: nx, ny, nz |
---|
| 68 | |
---|
| 69 | USE kinds |
---|
| 70 | |
---|
[1] | 71 | USE netcdf_control |
---|
[1320] | 72 | |
---|
| 73 | USE pegrid |
---|
[1] | 74 | |
---|
| 75 | IMPLICIT NONE |
---|
| 76 | |
---|
[1320] | 77 | CHARACTER (LEN=10) :: datform = 'lit_endian' !: |
---|
| 78 | CHARACTER (LEN=80) :: title !: |
---|
[1] | 79 | |
---|
[1320] | 80 | INTEGER(iwp) :: av !: |
---|
| 81 | INTEGER(iwp) :: dimx !: |
---|
| 82 | INTEGER(iwp) :: dimy !: |
---|
| 83 | INTEGER(iwp) :: fid !: |
---|
| 84 | INTEGER(iwp) :: file_id !: |
---|
| 85 | INTEGER(iwp) :: planz !: |
---|
[1] | 86 | |
---|
[1320] | 87 | LOGICAL :: checkuf = .TRUE. !: |
---|
| 88 | LOGICAL :: datleg = .TRUE. !: |
---|
| 89 | LOGICAL :: dbp = .FALSE. !: |
---|
[1] | 90 | |
---|
[1320] | 91 | REAL(wp) :: sizex !: |
---|
| 92 | REAL(wp) :: sizey !: |
---|
| 93 | REAL(wp) :: yright !: |
---|
[1] | 94 | |
---|
[1320] | 95 | NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dbp, planz, & |
---|
[964] | 96 | title |
---|
[1092] | 97 | NAMELIST /RAHMEN/ datleg |
---|
[1] | 98 | |
---|
| 99 | ! |
---|
| 100 | !-- Close specified unit number (if opened) and set a flag that it has |
---|
| 101 | !-- been opened one time at least |
---|
| 102 | IF ( file_id /= 0 ) THEN |
---|
| 103 | IF ( openfile(file_id)%opened ) THEN |
---|
| 104 | CLOSE ( file_id ) |
---|
| 105 | openfile(file_id)%opened = .FALSE. |
---|
| 106 | openfile(file_id)%opened_before = .TRUE. |
---|
| 107 | ENDIF |
---|
| 108 | RETURN |
---|
| 109 | ENDIF |
---|
| 110 | |
---|
| 111 | ! |
---|
| 112 | !-- Close all open unit numbers |
---|
[564] | 113 | DO fid = 1, 200+2*max_masks |
---|
[1] | 114 | |
---|
| 115 | IF ( openfile(fid)%opened .OR. openfile(fid)%opened_before ) THEN |
---|
| 116 | ! |
---|
| 117 | !-- Last actions for certain unit numbers |
---|
| 118 | SELECT CASE ( fid ) |
---|
| 119 | |
---|
| 120 | CASE ( 21 ) |
---|
| 121 | ! |
---|
| 122 | !-- Write ISO2D global parameters |
---|
| 123 | IF ( myid == 0 .AND. iso2d_output ) THEN |
---|
| 124 | planz = do2d_xy_n |
---|
| 125 | dimx = nx + 2 |
---|
| 126 | dimy = ny + 2 |
---|
| 127 | sizex = 100.0 |
---|
| 128 | sizey = 100.0 |
---|
| 129 | title = run_description_header |
---|
| 130 | yright = ( ny + 1.0 ) * dy |
---|
| 131 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 't3e' ) THEN |
---|
[1320] | 132 | checkuf = .FALSE.; dbp = .TRUE. |
---|
[1] | 133 | ENDIF |
---|
| 134 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' ) THEN |
---|
| 135 | datform = 'big_endian' |
---|
| 136 | ENDIF |
---|
[1320] | 137 | OPEN ( 90, FILE='PLOT2D_XY_GLOBAL', FORM='FORMATTED', & |
---|
[1] | 138 | DELIM='APOSTROPHE' ) |
---|
| 139 | WRITE ( 90, GLOBAL ) |
---|
| 140 | CLOSE ( 90 ) |
---|
| 141 | ENDIF |
---|
| 142 | |
---|
| 143 | CASE ( 22 ) |
---|
| 144 | ! |
---|
| 145 | !-- Write ISO2D global parameters |
---|
| 146 | IF ( myid == 0 ) THEN |
---|
| 147 | planz = do2d_xz_n |
---|
| 148 | dimx = nx + 2 |
---|
| 149 | dimy = nz + 2 |
---|
| 150 | sizex = 100.0 |
---|
| 151 | sizey = 65.0 |
---|
| 152 | title = run_description_header |
---|
| 153 | yright = z_max_do2d |
---|
| 154 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 't3e' ) THEN |
---|
[1320] | 155 | checkuf = .FALSE.; dbp = .TRUE. |
---|
[1] | 156 | ENDIF |
---|
| 157 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' ) THEN |
---|
| 158 | datform = 'big_endian' |
---|
| 159 | ENDIF |
---|
[1320] | 160 | OPEN ( 90, FILE='PLOT2D_XZ_GLOBAL', FORM='FORMATTED', & |
---|
[1] | 161 | DELIM='APOSTROPHE' ) |
---|
| 162 | WRITE ( 90, GLOBAL ) |
---|
| 163 | CLOSE ( 90 ) |
---|
| 164 | ENDIF |
---|
| 165 | |
---|
| 166 | CASE ( 23 ) |
---|
| 167 | ! |
---|
| 168 | !-- Write ISO2D global parameters |
---|
| 169 | IF ( myid == 0 ) THEN |
---|
| 170 | planz = do2d_yz_n |
---|
| 171 | dimx = ny + 2 |
---|
| 172 | dimy = nz + 2 |
---|
| 173 | sizex = 100.0 |
---|
| 174 | sizey = 65.0 |
---|
| 175 | title = run_description_header |
---|
| 176 | yright = z_max_do2d |
---|
| 177 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 't3e' ) THEN |
---|
[1320] | 178 | checkuf = .FALSE.; dbp = .TRUE. |
---|
[1] | 179 | ENDIF |
---|
| 180 | IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' ) THEN |
---|
| 181 | datform = 'big_endian' |
---|
| 182 | ENDIF |
---|
[1320] | 183 | OPEN ( 90, FILE='PLOT2D_YZ_GLOBAL', FORM='FORMATTED', & |
---|
[1] | 184 | DELIM='APOSTROPHE' ) |
---|
| 185 | WRITE ( 90, GLOBAL ) |
---|
| 186 | CLOSE ( 90 ) |
---|
| 187 | ENDIF |
---|
| 188 | |
---|
| 189 | CASE ( 32 ) |
---|
| 190 | ! |
---|
| 191 | !-- Write header for FLD-file |
---|
| 192 | IF ( do3d_compress ) THEN |
---|
[1320] | 193 | WRITE ( 32, 3200) ' compressed ', & |
---|
| 194 | TRIM( run_description_header ), nx+2, & |
---|
[1] | 195 | ny+2, nz_do3d+1, do3d_avs_n |
---|
| 196 | ELSE |
---|
[1320] | 197 | WRITE ( 32, 3200) ' ', TRIM( run_description_header ), & |
---|
[1] | 198 | nx+2, ny+2, nz_do3d+1, do3d_avs_n |
---|
| 199 | ENDIF |
---|
| 200 | |
---|
| 201 | #if defined( __netcdf ) |
---|
| 202 | CASE ( 101 ) |
---|
| 203 | |
---|
[1320] | 204 | IF ( netcdf_output .AND. & |
---|
[1031] | 205 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 206 | nc_stat = NF90_CLOSE( id_set_xy(0) ) |
---|
[263] | 207 | CALL handle_netcdf_error( 'close_file', 44 ) |
---|
[1] | 208 | ENDIF |
---|
| 209 | |
---|
| 210 | CASE ( 102 ) |
---|
| 211 | |
---|
[1320] | 212 | IF ( netcdf_output .AND. & |
---|
[1031] | 213 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 214 | nc_stat = NF90_CLOSE( id_set_xz(0) ) |
---|
[263] | 215 | CALL handle_netcdf_error( 'close_file', 45 ) |
---|
[1] | 216 | ENDIF |
---|
| 217 | |
---|
| 218 | CASE ( 103 ) |
---|
| 219 | |
---|
[1320] | 220 | IF ( netcdf_output .AND. & |
---|
[1031] | 221 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 222 | nc_stat = NF90_CLOSE( id_set_yz(0) ) |
---|
[263] | 223 | CALL handle_netcdf_error( 'close_file', 46 ) |
---|
[1] | 224 | ENDIF |
---|
| 225 | |
---|
| 226 | CASE ( 104 ) |
---|
| 227 | |
---|
| 228 | IF ( myid == 0 .AND. netcdf_output ) THEN |
---|
| 229 | nc_stat = NF90_CLOSE( id_set_pr ) |
---|
[263] | 230 | CALL handle_netcdf_error( 'close_file', 47 ) |
---|
[1] | 231 | ENDIF |
---|
| 232 | |
---|
| 233 | CASE ( 105 ) |
---|
| 234 | |
---|
| 235 | IF ( myid == 0 .AND. netcdf_output ) THEN |
---|
| 236 | nc_stat = NF90_CLOSE( id_set_ts ) |
---|
[263] | 237 | CALL handle_netcdf_error( 'close_file', 48 ) |
---|
[1] | 238 | ENDIF |
---|
| 239 | |
---|
| 240 | CASE ( 106 ) |
---|
| 241 | |
---|
[493] | 242 | IF ( netcdf_output .AND. & |
---|
[1031] | 243 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 244 | nc_stat = NF90_CLOSE( id_set_3d(0) ) |
---|
[263] | 245 | CALL handle_netcdf_error( 'close_file', 49 ) |
---|
[1] | 246 | ENDIF |
---|
| 247 | |
---|
| 248 | CASE ( 107 ) |
---|
| 249 | |
---|
| 250 | IF ( myid == 0 .AND. netcdf_output ) THEN |
---|
| 251 | nc_stat = NF90_CLOSE( id_set_sp ) |
---|
[263] | 252 | CALL handle_netcdf_error( 'close_file', 50 ) |
---|
[1] | 253 | ENDIF |
---|
| 254 | |
---|
| 255 | CASE ( 108 ) |
---|
| 256 | |
---|
| 257 | IF ( netcdf_output ) THEN |
---|
| 258 | nc_stat = NF90_CLOSE( id_set_prt ) |
---|
[263] | 259 | CALL handle_netcdf_error( 'close_file', 51 ) |
---|
[1] | 260 | ENDIF |
---|
| 261 | |
---|
| 262 | CASE ( 109 ) |
---|
| 263 | |
---|
| 264 | IF ( netcdf_output ) THEN |
---|
| 265 | nc_stat = NF90_CLOSE( id_set_pts ) |
---|
[263] | 266 | CALL handle_netcdf_error( 'close_file', 412 ) |
---|
[1] | 267 | ENDIF |
---|
| 268 | |
---|
| 269 | CASE ( 111 ) |
---|
| 270 | |
---|
[1320] | 271 | IF ( netcdf_output .AND. & |
---|
[1031] | 272 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 273 | nc_stat = NF90_CLOSE( id_set_xy(1) ) |
---|
[263] | 274 | CALL handle_netcdf_error( 'close_file', 52 ) |
---|
[1] | 275 | ENDIF |
---|
| 276 | |
---|
| 277 | CASE ( 112 ) |
---|
| 278 | |
---|
[1320] | 279 | IF ( netcdf_output .AND. & |
---|
[1031] | 280 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 281 | nc_stat = NF90_CLOSE( id_set_xz(1) ) |
---|
[263] | 282 | CALL handle_netcdf_error( 'close_file', 352 ) |
---|
[1] | 283 | ENDIF |
---|
| 284 | |
---|
| 285 | CASE ( 113 ) |
---|
| 286 | |
---|
[1320] | 287 | IF ( netcdf_output .AND. & |
---|
[1031] | 288 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 289 | nc_stat = NF90_CLOSE( id_set_yz(1) ) |
---|
[263] | 290 | CALL handle_netcdf_error( 'close_file', 353 ) |
---|
[1] | 291 | ENDIF |
---|
| 292 | |
---|
| 293 | CASE ( 116 ) |
---|
| 294 | |
---|
[1320] | 295 | IF ( netcdf_output .AND. & |
---|
[1031] | 296 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[1] | 297 | nc_stat = NF90_CLOSE( id_set_3d(1) ) |
---|
[263] | 298 | CALL handle_netcdf_error( 'close_file', 353 ) |
---|
[1] | 299 | ENDIF |
---|
| 300 | |
---|
[564] | 301 | CASE ( 201:200+2*max_masks ) |
---|
[410] | 302 | |
---|
[1320] | 303 | IF ( netcdf_output .AND. & |
---|
[1031] | 304 | ( myid == 0 .OR. netcdf_data_format > 4 ) ) THEN |
---|
[410] | 305 | ! |
---|
| 306 | !-- decompose fid into mid and av |
---|
[564] | 307 | IF ( fid <= 200+max_masks ) THEN |
---|
| 308 | mid = fid - 200 |
---|
[410] | 309 | av = 0 |
---|
| 310 | ELSE |
---|
[564] | 311 | mid = fid - (200+max_masks) |
---|
[410] | 312 | av = 1 |
---|
| 313 | ENDIF |
---|
| 314 | nc_stat = NF90_CLOSE( id_set_mask(mid,av) ) |
---|
[564] | 315 | CALL handle_netcdf_error( 'close_file', 459 ) |
---|
[410] | 316 | |
---|
| 317 | ENDIF |
---|
| 318 | |
---|
[1] | 319 | #endif |
---|
| 320 | |
---|
| 321 | END SELECT |
---|
| 322 | ! |
---|
| 323 | !-- Close file |
---|
| 324 | IF ( openfile(fid)%opened ) CLOSE ( fid ) |
---|
| 325 | |
---|
| 326 | ENDIF |
---|
| 327 | |
---|
| 328 | ENDDO |
---|
| 329 | |
---|
| 330 | ! |
---|
| 331 | !-- Formats |
---|
[1320] | 332 | 3200 FORMAT ('# AVS',A,'field file'/ & |
---|
| 333 | '#'/ & |
---|
| 334 | '# ',A/ & |
---|
| 335 | 'ndim=3'/ & |
---|
| 336 | 'dim1=',I5/ & |
---|
| 337 | 'dim2=',I5/ & |
---|
| 338 | 'dim3=',I5/ & |
---|
| 339 | 'nspace=3'/ & |
---|
| 340 | 'veclen=',I5/ & |
---|
| 341 | 'data=xdr_float'/ & |
---|
[1] | 342 | 'field=rectilinear') |
---|
| 343 | 4000 FORMAT ('time averaged over',F7.1,' s') |
---|
| 344 | |
---|
| 345 | |
---|
| 346 | END SUBROUTINE close_file |
---|