SUBROUTINE close_file( file_id ) !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! netCDF4 without parallel file support implemented ! ! Former revisions: ! ----------------- ! $Id: close_file.f90 1031 2012-10-19 14:35:30Z raasch $ ! ! 964 2012-07-26 09:14:24Z raasch ! old profil-units (40:49) and respective code removed ! ! 564 2010-09-30 13:18:59Z helmke ! start number of mask output files changed to 201, netcdf message identifiers ! of masked output changed ! ! 493 2010-03-01 08:30:24Z raasch ! Adjustments for NetCDF parallel data output ! ! 410 2009-12-04 17:05:40Z letzel ! masked data output ! ! 263 2009-03-18 12:26:04Z heinze ! Output of NetCDF messages with aid of message handling routine. ! ! Feb. 2007 ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.10 2006/08/22 13:50:01 raasch ! xz and yz cross sections now up to nzt+1 ! ! Revision 1.1 2001/01/02 17:23:41 raasch ! Initial revision ! ! Last revision before renaming subroutine 2001/01/01 raasch ! Subroutine name changed from close_files to close_file. Closing of a single ! file is allowed by passing its file-id as an argument. Variable openfile now ! is of type file_status and contains a flag which indicates if a file has ! been opened before. Old revision remarks deleted. ! ! Revision 1.13 (close_files) 2000/12/20 09:10:24 letzel ! All comments translated into English. ! ! Revision 1.12 (close_files) 1999/03/02 09:22:46 raasch ! FLD-Header fuer komprimierte 3D-Daten ! ! 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 USE grid_variables USE indices USE netcdf_control USE pegrid USE profil_parameter USE statistics IMPLICIT NONE CHARACTER (LEN=2) :: suffix CHARACTER (LEN=10) :: datform = 'lit_endian' CHARACTER (LEN=80) :: rtext, title INTEGER :: av, anzzeile, dimx, dimy, & fid, file_id, j, k, planz LOGICAL :: checkuf = .TRUE., datleg = .TRUE., dp = .FALSE., swap REAL :: sizex, sizey, yright NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dp, planz, & title NAMELIST /RAHMEN/ anzzeile, datleg, rtext, swap ! !-- 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 ) CASE ( 21 ) ! !-- Write ISO2D global parameters IF ( myid == 0 .AND. iso2d_output ) THEN planz = do2d_xy_n dimx = nx + 2 dimy = ny + 2 sizex = 100.0 sizey = 100.0 title = run_description_header yright = ( ny + 1.0 ) * dy IF ( host(1:3) == 'ibm' .OR. host(1:3) == 't3e' ) THEN checkuf = .FALSE.; dp = .TRUE. ENDIF IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' ) THEN datform = 'big_endian' ENDIF OPEN ( 90, FILE='PLOT2D_XY_GLOBAL', FORM='FORMATTED', & DELIM='APOSTROPHE' ) WRITE ( 90, GLOBAL ) CLOSE ( 90 ) ENDIF CASE ( 22 ) ! !-- Write ISO2D global parameters IF ( myid == 0 ) THEN planz = do2d_xz_n dimx = nx + 2 dimy = nz + 2 sizex = 100.0 sizey = 65.0 title = run_description_header yright = z_max_do2d IF ( host(1:3) == 'ibm' .OR. host(1:3) == 't3e' ) THEN checkuf = .FALSE.; dp = .TRUE. ENDIF IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' ) THEN datform = 'big_endian' ENDIF OPEN ( 90, FILE='PLOT2D_XZ_GLOBAL', FORM='FORMATTED', & DELIM='APOSTROPHE' ) WRITE ( 90, GLOBAL ) CLOSE ( 90 ) ENDIF CASE ( 23 ) ! !-- Write ISO2D global parameters IF ( myid == 0 ) THEN planz = do2d_yz_n dimx = ny + 2 dimy = nz + 2 sizex = 100.0 sizey = 65.0 title = run_description_header yright = z_max_do2d IF ( host(1:3) == 'ibm' .OR. host(1:3) == 't3e' ) THEN checkuf = .FALSE.; dp = .TRUE. ENDIF IF ( host(1:3) == 'ibm' .OR. host(1:3) == 'nec' ) THEN datform = 'big_endian' ENDIF OPEN ( 90, FILE='PLOT2D_YZ_GLOBAL', FORM='FORMATTED', & DELIM='APOSTROPHE' ) WRITE ( 90, GLOBAL ) CLOSE ( 90 ) ENDIF CASE ( 32 ) ! !-- Write header for FLD-file IF ( do3d_compress ) THEN WRITE ( 32, 3200) ' compressed ', & TRIM( run_description_header ), nx+2, & ny+2, nz_do3d+1, do3d_avs_n ELSE WRITE ( 32, 3200) ' ', TRIM( run_description_header ), & nx+2, ny+2, nz_do3d+1, do3d_avs_n ENDIF #if defined( __netcdf ) CASE ( 101 ) IF ( netcdf_output .AND. & ( 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 ( netcdf_output .AND. & ( 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 ( netcdf_output .AND. & ( 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 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_pr ) CALL handle_netcdf_error( 'close_file', 47 ) ENDIF CASE ( 105 ) IF ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_ts ) CALL handle_netcdf_error( 'close_file', 48 ) ENDIF CASE ( 106 ) IF ( netcdf_output .AND. & ( 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 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_sp ) CALL handle_netcdf_error( 'close_file', 50 ) ENDIF CASE ( 108 ) IF ( netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_prt ) CALL handle_netcdf_error( 'close_file', 51 ) ENDIF CASE ( 109 ) IF ( netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_pts ) CALL handle_netcdf_error( 'close_file', 412 ) ENDIF CASE ( 111 ) IF ( netcdf_output .AND. & ( 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 ( netcdf_output .AND. & ( 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 ( netcdf_output .AND. & ( 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 ( netcdf_output .AND. & ( 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 ( netcdf_output .AND. & ( 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