SUBROUTINE close_file( file_id ) !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2014 Leibniz Universitaet Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: close_file.f90 1329 2014-03-21 11:09:15Z witha $ ! ! 1327 2014-03-21 11:00:16Z raasch ! parts concerning iso2d and avs output removed ! ! 1320 2014-03-20 08:40:49Z raasch ! ONLY-attribute added to USE-statements, ! kind-parameters added to all INTEGER and REAL declaration statements, ! kinds are defined in new module kinds, ! revision history before 2012 removed, ! comment fields (!:) to be used for variable explanations added to ! all variable declaration statements ! ! 1092 2013-02-02 11:24:22Z raasch ! unused variables removed ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1031 2012-10-19 14:35:30Z raasch ! netCDF4 without parallel file support implemented ! ! 964 2012-07-26 09:14:24Z raasch ! old profil-units (40:49) and respective code removed ! ! Revision 1.1 (close_files) 1997/08/11 06:11:18 raasch ! Initial revision ! ! ! Description: ! ------------ ! Close specified file or all open files, if "0" has been given as the ! calling argument. In that case, execute last actions for certain unit ! numbers, if required. !------------------------------------------------------------------------------! USE control_parameters, & ONLY: do2d_xz_n, do2d_xy_n, do2d_yz_n, do3d_avs_n, & host, max_masks, mid, netcdf_data_format, & nz_do3d, openfile, run_description_header, & z_max_do2d USE grid_variables, & ONLY: dy USE indices, & ONLY: nx, ny, nz USE kinds USE netcdf_control USE pegrid IMPLICIT NONE CHARACTER (LEN=10) :: datform = 'lit_endian' !: CHARACTER (LEN=80) :: title !: INTEGER(iwp) :: av !: INTEGER(iwp) :: dimx !: INTEGER(iwp) :: dimy !: INTEGER(iwp) :: fid !: INTEGER(iwp) :: file_id !: INTEGER(iwp) :: planz !: LOGICAL :: checkuf = .TRUE. !: LOGICAL :: datleg = .TRUE. !: LOGICAL :: dbp = .FALSE. !: REAL(wp) :: sizex !: REAL(wp) :: sizey !: REAL(wp) :: yright !: NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dbp, planz, & title NAMELIST /RAHMEN/ datleg ! !-- Close specified unit number (if opened) and set a flag that it has !-- been opened one time at least IF ( file_id /= 0 ) THEN IF ( openfile(file_id)%opened ) THEN CLOSE ( file_id ) openfile(file_id)%opened = .FALSE. openfile(file_id)%opened_before = .TRUE. ENDIF RETURN ENDIF ! !-- Close all open unit numbers DO fid = 1, 200+2*max_masks IF ( openfile(fid)%opened .OR. openfile(fid)%opened_before ) THEN ! !-- Last actions for certain unit numbers SELECT CASE ( fid ) #if defined( __netcdf ) CASE ( 101 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_xy(0) ) CALL handle_netcdf_error( 'close_file', 44 ) ENDIF CASE ( 102 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_xz(0) ) CALL handle_netcdf_error( 'close_file', 45 ) ENDIF CASE ( 103 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_yz(0) ) CALL handle_netcdf_error( 'close_file', 46 ) ENDIF CASE ( 104 ) IF ( myid == 0 ) THEN nc_stat = NF90_CLOSE( id_set_pr ) CALL handle_netcdf_error( 'close_file', 47 ) ENDIF CASE ( 105 ) IF ( myid == 0 ) THEN nc_stat = NF90_CLOSE( id_set_ts ) CALL handle_netcdf_error( 'close_file', 48 ) ENDIF CASE ( 106 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_3d(0) ) CALL handle_netcdf_error( 'close_file', 49 ) ENDIF CASE ( 107 ) IF ( myid == 0 ) THEN nc_stat = NF90_CLOSE( id_set_sp ) CALL handle_netcdf_error( 'close_file', 50 ) ENDIF CASE ( 108 ) nc_stat = NF90_CLOSE( id_set_prt ) CALL handle_netcdf_error( 'close_file', 51 ) CASE ( 109 ) nc_stat = NF90_CLOSE( id_set_pts ) CALL handle_netcdf_error( 'close_file', 412 ) CASE ( 111 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_xy(1) ) CALL handle_netcdf_error( 'close_file', 52 ) ENDIF CASE ( 112 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_xz(1) ) CALL handle_netcdf_error( 'close_file', 352 ) ENDIF CASE ( 113 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_yz(1) ) CALL handle_netcdf_error( 'close_file', 353 ) ENDIF CASE ( 116 ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN nc_stat = NF90_CLOSE( id_set_3d(1) ) CALL handle_netcdf_error( 'close_file', 353 ) ENDIF CASE ( 201:200+2*max_masks ) IF ( myid == 0 .OR. netcdf_data_format > 4 ) THEN ! !-- decompose fid into mid and av IF ( fid <= 200+max_masks ) THEN mid = fid - 200 av = 0 ELSE mid = fid - (200+max_masks) av = 1 ENDIF nc_stat = NF90_CLOSE( id_set_mask(mid,av) ) CALL handle_netcdf_error( 'close_file', 459 ) ENDIF #endif END SELECT ! !-- Close file IF ( openfile(fid)%opened ) CLOSE ( fid ) ENDIF ENDDO ! !-- Formats 3200 FORMAT ('# AVS',A,'field file'/ & '#'/ & '# ',A/ & 'ndim=3'/ & 'dim1=',I5/ & 'dim2=',I5/ & 'dim3=',I5/ & 'nspace=3'/ & 'veclen=',I5/ & 'data=xdr_float'/ & 'field=rectilinear') 4000 FORMAT ('time averaged over',F7.1,' s') END SUBROUTINE close_file