SUBROUTINE close_file( file_id ) !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! Output of NetCDF messages with aid of message handling routine. ! ! Former revisions: ! ----------------- ! $Id: close_file.f90 263 2009-03-18 12:26:04Z weinreis $ ! 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, utext = '', xtext = '', ytext = '' INTEGER :: anzzeile, cranz, cross_count, cross_numbers, dimx, dimy, & fid, file_id, j, k, legpos = 1, planz, timodex = 1 INTEGER, DIMENSION(100) :: klist, lstyle, cucol LOGICAL :: checkuf = .TRUE., datleg = .TRUE., dp = .FALSE., & grid = .TRUE., rand = .TRUE., swap, twoxa = .TRUE., & twoya = .TRUE. REAL :: ansx = -999.999, ansy = -999.999, gwid = 0.1, rlegfak, & sizex, sizey, texfac, utmove = 50.0, uxmax, uxmin, uymax, & uymin, yright REAL, DIMENSION(100) :: lwid, normx, normy NAMELIST /CROSS/ ansx, ansy, cucol, grid, gwid, klist, legpos, lstyle, & lwid, normx, normy, rand, rlegfak, sizex, sizey, & texfac, timodex, twoxa, twoya, utext, utmove, uxmax, & uxmin, uymax, uymin, xtext, ytext NAMELIST /GLOBAL/ checkuf, datform, dimx, dimy, dp, planz, sizex, sizey, & title, yright NAMELIST /RAHMEN/ anzzeile, cranz, 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, 116 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 CASE ( 40:49 ) ! !-- Write PROFIL namelist parameters for 1D profiles. !-- First determine, how many crosses are to be drawn. IF ( myid == 0 ) THEN cross_numbers = 0 DO j = 1, crmax IF ( cross_profile_number_count(j) /= 0 ) THEN cross_numbers = cross_numbers + 1 ENDIF ENDDO IF ( cross_numbers /= 0 ) THEN ! !-- Determine remaining RAHMEN parameters swap = .FALSE. rtext = '\0.5 ' // TRIM( run_description_header ) // & ' ' // TRIM( region( fid - 40 ) ) ! !-- Write RAHMEN parameters IF ( statistic_regions == 0 .AND. fid == 40 ) THEN suffix = '' ELSE WRITE ( suffix, '(''_'',I1)' ) fid - 40 ENDIF OPEN ( 90, FILE='PLOT1D_PAR' // TRIM( suffix ), & FORM='FORMATTED', DELIM='APOSTROPHE' ) ! !-- Subtitle for crosses with time averaging IF ( averaging_interval_pr /= 0.0 ) THEN WRITE ( utext, 4000 ) averaging_interval_pr ENDIF ! !-- Determine and write CROSS parameters for each individual !-- cross cross_count = 0 DO j = 1, crmax k = cross_profile_number_count(j) IF ( k /= 0 ) THEN cross_count = cross_count + 1 ! !-- Write RAHMEN parameters IF ( MOD( cross_count-1, & profile_rows*profile_columns ) == 0 ) & THEN ! !-- Determine number of crosses still to be drawn cranz = MIN( cross_numbers - cross_count + 1, & profile_rows * profile_columns ) ! !-- If the first line cannot be filled with crosses !-- completely, the default number of crosses per !-- line has to be reduced. IF ( cranz < profile_columns ) THEN anzzeile = cranz ELSE anzzeile = profile_columns ENDIF WRITE ( 90, RAHMEN ) ENDIF ! !-- Store graph numbers klist(1:k) = cross_profile_numbers(1:k,j) klist(k+1:100) = 999999 ! !-- Store graph attributes cucol = cross_linecolors(:,j) lstyle = cross_linestyles(:,j) lwid = 0.6 ! !-- Sizes, text etc. sizex = 100.0; sizey = 120.0 rlegfak = 0.7; texfac = 1.0 ! !-- Determine range of x-axis values IF ( cross_normalized_x(j) == ' ' ) THEN ! !-- Non-normalized profiles IF ( cross_uxmin(j) == 0.0 .AND. & cross_uxmax(j) == 0.0 ) THEN uxmin = cross_uxmin_computed(j) uxmax = cross_uxmax_computed(j) IF ( uxmin == uxmax ) uxmax = uxmin + 1.0 ELSE ! !-- Values set in check_parameters are used here uxmin = cross_uxmin(j); uxmax = cross_uxmax(j) ENDIF ELSE ! !-- Normalized profiles IF ( cross_uxmin_normalized(j) == 0.0 .AND. & cross_uxmax_normalized(j) == 0.0 ) THEN uxmin = cross_uxmin_normalized_computed(j) uxmax = cross_uxmax_normalized_computed(j) IF ( uxmin == uxmax ) uxmax = uxmin + 1.0 ELSE ! !-- Values set in check_parameters are used here uxmin = cross_uxmin_normalized(j) uxmax = cross_uxmax_normalized(j) ENDIF ENDIF ! !-- Range of y-axis values !-- may be re-adjusted during normalization if required uymin = cross_uymin(j); uymax = cross_uymax(j) ytext = 'height in m' ! !-- Normalization of the axes normx = cross_normx_factor(:,j) normy = cross_normy_factor(:,j) ! !-- Labelling of the axes IF ( cross_normalized_x(j) == ' ' ) THEN xtext = cross_xtext(j) ELSE xtext = TRIM( cross_xtext(j) ) // ' / ' // & cross_normalized_x(j) ENDIF IF ( cross_normalized_y(j) == ' ' ) THEN ytext = 'height in m' ELSE ytext = 'height in m' // ' / ' // & cross_normalized_y(j) ! !-- Determine upper limit of value range IF ( z_max_do1d_normalized /= -1.0 ) THEN uymax = z_max_do1d_normalized ENDIF ENDIF WRITE ( 90, CROSS ) ENDIF ENDDO CLOSE ( 90 ) ENDIF ENDIF CASE ( 50:59 ) ! !-- Write PROFIL namelist parameters for time series !-- first determine number of crosses to be drawn IF ( myid == 0 ) THEN cranz = 0 DO j = 1, 12 IF ( cross_ts_number_count(j) /= 0 ) cranz = cranz+1 ENDDO IF ( cranz /= 0 ) THEN ! !-- Determine RAHMEN parameters anzzeile = 1 swap = .TRUE. rtext = '\1.0 ' // TRIM( run_description_header ) // & ' ' // TRIM( region( fid - 50 ) ) ! !-- Write RAHMEN parameters IF ( statistic_regions == 0 .AND. fid == 50 ) THEN suffix = '' ELSE WRITE ( suffix, '(''_'',I1)' ) fid - 50 ENDIF OPEN ( 90, FILE='PLOTTS_PAR' // TRIM( suffix ), & FORM='FORMATTED', DELIM='APOSTROPHE' ) WRITE ( 90, RAHMEN ) ! !-- Determine and write CROSS parameters for each individual !-- cross DO j = 1, 12 k = cross_ts_number_count(j) IF ( k /= 0 ) THEN ! !-- Store graph numbers klist(1:k) = cross_ts_numbers(1:k,j) klist(k+1:100) = 999999 ! !-- Store graph attributes cucol(1:k) = linecolors(1:k) lstyle(1:k) = linestyles(1:k) lwid = 0.4 ! !-- Sizes, text etc. sizex = 250.0; sizey = 40.0 rlegfak = 1.5; texfac = 1.5 xtext = 'time in s' ytext = '' utext = '' ! !-- Determine range of y-axis values IF ( cross_ts_uymin(j) == 999.999 ) THEN uymin = cross_ts_uymin_computed(j) ELSE uymin = cross_ts_uymin(j) ENDIF IF ( cross_ts_uymax(j) == 999.999 ) THEN uymax = cross_ts_uymax_computed(j) ELSE uymax = cross_ts_uymax(j) ENDIF IF ( uymin == uymax ) uymax = uymin + 1.0 ! !-- Range of x-axis values uxmin = 0.0; uxmax = simulated_time ! !-- Normalizations normx = 1.0; normy = 1.0 WRITE ( 90, CROSS ) ENDIF ENDDO CLOSE ( 90 ) ENDIF ENDIF #if defined( __netcdf ) CASE ( 101 ) IF ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_xy(0) ) CALL handle_netcdf_error( 'close_file', 44 ) ENDIF CASE ( 102 ) IF ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_xz(0) ) CALL handle_netcdf_error( 'close_file', 45 ) ENDIF CASE ( 103 ) IF ( myid == 0 .AND. netcdf_output ) 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 ( myid == 0 .AND. netcdf_output ) 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 ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_xy(1) ) CALL handle_netcdf_error( 'close_file', 52 ) ENDIF CASE ( 112 ) IF ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_xz(1) ) CALL handle_netcdf_error( 'close_file', 352 ) ENDIF CASE ( 113 ) IF ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_yz(1) ) CALL handle_netcdf_error( 'close_file', 353 ) ENDIF CASE ( 116 ) IF ( myid == 0 .AND. netcdf_output ) THEN nc_stat = NF90_CLOSE( id_set_3d(1) ) CALL handle_netcdf_error( 'close_file', 353 ) 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