[1682] | 1 | !> @file close_file.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 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 | ! |
---|
[3655] | 17 | ! Copyright 1997-2019 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 4180 2019-08-21 14:37:54Z scharf $ |
---|
[4069] | 27 | ! Masked output running index mid has been introduced as a local variable to |
---|
| 28 | ! avoid runtime error (Loop variable has been modified) in time_integration |
---|
| 29 | ! |
---|
| 30 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3241] | 31 | ! unused variables and format statements removed |
---|
| 32 | ! |
---|
[2716] | 33 | ! |
---|
[1] | 34 | ! Description: |
---|
| 35 | ! ------------ |
---|
[1682] | 36 | !> Close specified file or all open files, if "0" has been given as the |
---|
| 37 | !> calling argument. In that case, execute last actions for certain unit |
---|
| 38 | !> numbers, if required. |
---|
[1] | 39 | !------------------------------------------------------------------------------! |
---|
[1682] | 40 | SUBROUTINE close_file( file_id ) |
---|
| 41 | |
---|
[1] | 42 | |
---|
[1320] | 43 | USE control_parameters, & |
---|
[4069] | 44 | ONLY: max_masks, openfile |
---|
[1320] | 45 | |
---|
| 46 | USE kinds |
---|
| 47 | |
---|
[1783] | 48 | #if defined( __netcdf ) |
---|
| 49 | USE NETCDF |
---|
| 50 | #endif |
---|
| 51 | |
---|
| 52 | USE netcdf_interface, & |
---|
[3241] | 53 | ONLY: id_set_mask, id_set_pr, id_set_pts, id_set_sp, & |
---|
[1992] | 54 | id_set_ts, id_set_xy, id_set_xz, id_set_yz, id_set_3d, & |
---|
| 55 | id_set_fl, nc_stat, netcdf_data_format, netcdf_handle_error |
---|
[1320] | 56 | |
---|
| 57 | USE pegrid |
---|
[1] | 58 | |
---|
| 59 | IMPLICIT NONE |
---|
| 60 | |
---|
[1682] | 61 | CHARACTER (LEN=10) :: datform = 'lit_endian' !< |
---|
| 62 | CHARACTER (LEN=80) :: title !< |
---|
[1] | 63 | |
---|
[1682] | 64 | INTEGER(iwp) :: av !< |
---|
| 65 | INTEGER(iwp) :: dimx !< |
---|
| 66 | INTEGER(iwp) :: dimy !< |
---|
| 67 | INTEGER(iwp) :: fid !< |
---|
| 68 | INTEGER(iwp) :: file_id !< |
---|
[4069] | 69 | INTEGER(iwp) :: mid !< masked output running index |
---|
[1682] | 70 | INTEGER(iwp) :: planz !< |
---|
[1] | 71 | |
---|
[1682] | 72 | LOGICAL :: checkuf = .TRUE. !< |
---|
| 73 | LOGICAL :: datleg = .TRUE. !< |
---|
| 74 | LOGICAL :: dbp = .FALSE. !< |
---|
[1] | 75 | |
---|
[1320] | 76 | NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dbp, planz, & |
---|
[964] | 77 | title |
---|
[1092] | 78 | NAMELIST /RAHMEN/ datleg |
---|
[1] | 79 | |
---|
| 80 | ! |
---|
| 81 | !-- Close specified unit number (if opened) and set a flag that it has |
---|
| 82 | !-- been opened one time at least |
---|
| 83 | IF ( file_id /= 0 ) THEN |
---|
| 84 | IF ( openfile(file_id)%opened ) THEN |
---|
| 85 | CLOSE ( file_id ) |
---|
| 86 | openfile(file_id)%opened = .FALSE. |
---|
| 87 | openfile(file_id)%opened_before = .TRUE. |
---|
| 88 | ENDIF |
---|
| 89 | RETURN |
---|
| 90 | ENDIF |
---|
| 91 | |
---|
| 92 | ! |
---|
| 93 | !-- Close all open unit numbers |
---|
[564] | 94 | DO fid = 1, 200+2*max_masks |
---|
[1] | 95 | |
---|
| 96 | IF ( openfile(fid)%opened .OR. openfile(fid)%opened_before ) THEN |
---|
| 97 | ! |
---|
| 98 | !-- Last actions for certain unit numbers |
---|
| 99 | SELECT CASE ( fid ) |
---|
| 100 | |
---|
| 101 | #if defined( __netcdf ) |
---|
| 102 | CASE ( 101 ) |
---|
| 103 | |
---|
[1327] | 104 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 105 | nc_stat = NF90_CLOSE( id_set_xy(0) ) |
---|
[1783] | 106 | CALL netcdf_handle_error( 'close_file', 44 ) |
---|
[1] | 107 | ENDIF |
---|
| 108 | |
---|
| 109 | CASE ( 102 ) |
---|
| 110 | |
---|
[1327] | 111 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 112 | nc_stat = NF90_CLOSE( id_set_xz(0) ) |
---|
[1783] | 113 | CALL netcdf_handle_error( 'close_file', 45 ) |
---|
[1] | 114 | ENDIF |
---|
| 115 | |
---|
| 116 | CASE ( 103 ) |
---|
| 117 | |
---|
[1327] | 118 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 119 | nc_stat = NF90_CLOSE( id_set_yz(0) ) |
---|
[1783] | 120 | CALL netcdf_handle_error( 'close_file', 46 ) |
---|
[1] | 121 | ENDIF |
---|
| 122 | |
---|
| 123 | CASE ( 104 ) |
---|
| 124 | |
---|
[1327] | 125 | IF ( myid == 0 ) THEN |
---|
[1] | 126 | nc_stat = NF90_CLOSE( id_set_pr ) |
---|
[1783] | 127 | CALL netcdf_handle_error( 'close_file', 47 ) |
---|
[1] | 128 | ENDIF |
---|
| 129 | |
---|
| 130 | CASE ( 105 ) |
---|
| 131 | |
---|
[1327] | 132 | IF ( myid == 0 ) THEN |
---|
[1] | 133 | nc_stat = NF90_CLOSE( id_set_ts ) |
---|
[1783] | 134 | CALL netcdf_handle_error( 'close_file', 48 ) |
---|
[1] | 135 | ENDIF |
---|
| 136 | |
---|
| 137 | CASE ( 106 ) |
---|
| 138 | |
---|
[1327] | 139 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 140 | nc_stat = NF90_CLOSE( id_set_3d(0) ) |
---|
[1783] | 141 | CALL netcdf_handle_error( 'close_file', 49 ) |
---|
[1] | 142 | ENDIF |
---|
| 143 | |
---|
| 144 | CASE ( 107 ) |
---|
| 145 | |
---|
[1327] | 146 | IF ( myid == 0 ) THEN |
---|
[1] | 147 | nc_stat = NF90_CLOSE( id_set_sp ) |
---|
[1783] | 148 | CALL netcdf_handle_error( 'close_file', 50 ) |
---|
[1] | 149 | ENDIF |
---|
| 150 | |
---|
[3045] | 151 | ! |
---|
| 152 | !-- Currently disabled |
---|
| 153 | ! CASE ( 108 ) |
---|
[1] | 154 | |
---|
[3045] | 155 | ! nc_stat = NF90_CLOSE( id_set_prt ) |
---|
| 156 | ! CALL netcdf_handle_error( 'close_file', 51 ) |
---|
[1] | 157 | |
---|
| 158 | CASE ( 109 ) |
---|
| 159 | |
---|
[1327] | 160 | nc_stat = NF90_CLOSE( id_set_pts ) |
---|
[1783] | 161 | CALL netcdf_handle_error( 'close_file', 412 ) |
---|
[1] | 162 | |
---|
| 163 | CASE ( 111 ) |
---|
| 164 | |
---|
[1327] | 165 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 166 | nc_stat = NF90_CLOSE( id_set_xy(1) ) |
---|
[1783] | 167 | CALL netcdf_handle_error( 'close_file', 52 ) |
---|
[1] | 168 | ENDIF |
---|
| 169 | |
---|
| 170 | CASE ( 112 ) |
---|
| 171 | |
---|
[1327] | 172 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 173 | nc_stat = NF90_CLOSE( id_set_xz(1) ) |
---|
[1783] | 174 | CALL netcdf_handle_error( 'close_file', 352 ) |
---|
[1] | 175 | ENDIF |
---|
| 176 | |
---|
| 177 | CASE ( 113 ) |
---|
| 178 | |
---|
[1327] | 179 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 180 | nc_stat = NF90_CLOSE( id_set_yz(1) ) |
---|
[1783] | 181 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
[1] | 182 | ENDIF |
---|
| 183 | |
---|
| 184 | CASE ( 116 ) |
---|
| 185 | |
---|
[1327] | 186 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[1] | 187 | nc_stat = NF90_CLOSE( id_set_3d(1) ) |
---|
[1783] | 188 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
[1] | 189 | ENDIF |
---|
| 190 | |
---|
[1992] | 191 | CASE ( 199 ) |
---|
| 192 | |
---|
| 193 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
| 194 | nc_stat = NF90_CLOSE( id_set_fl ) |
---|
| 195 | CALL netcdf_handle_error( 'close_file', 353 ) |
---|
| 196 | ENDIF |
---|
| 197 | |
---|
[564] | 198 | CASE ( 201:200+2*max_masks ) |
---|
[1992] | 199 | |
---|
[1327] | 200 | IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN |
---|
[410] | 201 | ! |
---|
| 202 | !-- decompose fid into mid and av |
---|
[564] | 203 | IF ( fid <= 200+max_masks ) THEN |
---|
| 204 | mid = fid - 200 |
---|
[410] | 205 | av = 0 |
---|
| 206 | ELSE |
---|
[564] | 207 | mid = fid - (200+max_masks) |
---|
[410] | 208 | av = 1 |
---|
| 209 | ENDIF |
---|
| 210 | nc_stat = NF90_CLOSE( id_set_mask(mid,av) ) |
---|
[1783] | 211 | CALL netcdf_handle_error( 'close_file', 459 ) |
---|
[1992] | 212 | |
---|
[410] | 213 | ENDIF |
---|
| 214 | |
---|
[1] | 215 | #endif |
---|
| 216 | |
---|
| 217 | END SELECT |
---|
| 218 | ! |
---|
| 219 | !-- Close file |
---|
| 220 | IF ( openfile(fid)%opened ) CLOSE ( fid ) |
---|
| 221 | |
---|
| 222 | ENDIF |
---|
| 223 | |
---|
| 224 | ENDDO |
---|
| 225 | |
---|
| 226 | END SUBROUTINE close_file |
---|