Ignore:
Timestamp:
Jul 19, 2019 8:54:42 AM (5 years ago)
Author:
gronemeier
Message:

combine new netcdf4 output modules into a single module; improvements of DOM error messages; check initialization state of file before defining/writing anything; improvements in binary output

File:
1 edited

Legend:

Unmodified
Added
Removed
  • palm/trunk/SOURCE/data_output_module.f90

    r4070 r4106  
    2020! Current revisions:
    2121! ------------------
    22 ! 
    23 ! 
     22!
     23!
    2424! Former revisions:
    2525! -----------------
     
    4343!>
    4444!> @todo Convert variable if type of given values do not fit specified type.
    45 !> @todo Remove unused variables
    46 !> @todo How to deal with definition calls after dom_start_output is called? Should it be allowed
    47 !>       to define new files after that (which is technically possible)?
    4845!> @todo Remove iwp from index (and similar) variables.
    4946!--------------------------------------------------------------------------------------------------!
     
    5249   USE kinds
    5350
    54    USE data_output_netcdf4_serial_module, &
    55       ONLY: netcdf4_serial_init_dimension, &
    56             netcdf4_serial_get_error_message, &
    57             netcdf4_serial_init_end, &
    58             netcdf4_serial_init_module, &
    59             netcdf4_serial_init_variable, &
    60             netcdf4_serial_finalize, &
    61             netcdf4_serial_open_file, &
    62             netcdf4_serial_write_attribute, &
    63             netcdf4_serial_write_variable
    64 
    65    USE data_output_netcdf4_parallel_module, &
    66       ONLY: netcdf4_parallel_init_dimension, &
    67             netcdf4_parallel_get_error_message, &
    68             netcdf4_parallel_init_end, &
    69             netcdf4_parallel_init_module, &
    70             netcdf4_parallel_init_variable, &
    71             netcdf4_parallel_finalize, &
    72             netcdf4_parallel_open_file, &
    73             netcdf4_parallel_write_attribute, &
    74             netcdf4_parallel_write_variable
     51   USE data_output_netcdf4_module, &
     52      ONLY: netcdf4_init_dimension, &
     53            netcdf4_get_error_message, &
     54            netcdf4_init_end, &
     55            netcdf4_init_module, &
     56            netcdf4_init_variable, &
     57            netcdf4_finalize, &
     58            netcdf4_open_file, &
     59            netcdf4_write_attribute, &
     60            netcdf4_write_variable
    7561
    7662   USE data_output_binary_module, &
     
    10591      INTEGER(iwp)           ::  id = 0               !< id within file
    10692      LOGICAL                ::  is_global = .FALSE.  !< true if global variable
    107       LOGICAL                ::  is_init = .FALSE.    !< true if initialized
    10893      CHARACTER(LEN=charlen), DIMENSION(:), ALLOCATABLE ::  dimension_names  !< list of dimension names
    10994      INTEGER(iwp),           DIMENSION(:), ALLOCATABLE ::  dimension_ids    !< list of dimension ids
     
    118103      INTEGER(iwp)           ::  length_mask          !< length of masked dimension
    119104      INTEGER(iwp)           ::  var_id = 0           !< associated variable id within file
    120       LOGICAL                ::  is_init = .FALSE.    !< true if initialized
    121105      LOGICAL                ::  is_masked = .FALSE.  !< true if masked
    122106      INTEGER(iwp),    DIMENSION(2)              ::  bounds                !< lower and upper bound of dimension
     
    125109      INTEGER(KIND=2), DIMENSION(:), ALLOCATABLE ::  masked_values_int16   !< masked dimension values if 16bit integer
    126110      INTEGER(KIND=4), DIMENSION(:), ALLOCATABLE ::  masked_values_int32   !< masked dimension values if 32bit integer
    127       INTEGER(iwp),    DIMENSION(:), ALLOCATABLE ::  masked_values_intwp   !< masked dimension values if working-precision integer
     111      INTEGER(iwp),    DIMENSION(:), ALLOCATABLE ::  masked_values_intwp   !< masked dimension values if working-precision int
    128112      INTEGER(KIND=1), DIMENSION(:), ALLOCATABLE ::  values_int8           !< dimension values if 16bit integer
    129113      INTEGER(KIND=2), DIMENSION(:), ALLOCATABLE ::  values_int16          !< dimension values if 16bit integer
     
    252236   CALL binary_init_module( debug_output_unit, debug_output, no_var_id )
    253237
    254    CALL netcdf4_serial_init_module( debug_output_unit, debug_output, no_var_id )
    255 
    256    CALL netcdf4_parallel_init_module( debug_output_unit, debug_output, no_var_id )
     238   CALL netcdf4_init_module( debug_output_unit, debug_output, no_var_id )
    257239
    258240END SUBROUTINE dom_init
     
    310292   !             WRITE(*,'(10X,5(I5,1X),A)') files(f)%dimensions(d)%values_int32(0:MIN(4,files(f)%dimensions(d)%length)), '...'
    311293   !          ELSE
    312    !             WRITE(*,'(10X,5(F8.2,1X),A)') files(f)%dimensions(d)%values_real64(0:MIN(4,files(f)%dimensions(d)%length)), '...'
     294   !             WRITE(*,'(10X,5(F8.2,1X),A)')  &
     295   !                files(f)%dimensions(d)%values_real64(0:MIN(4,files(f)%dimensions(d)%length)), '...'
    313296   !          ENDIF
    314297   !          IF ( ALLOCATED(files(f)%dimensions(d)%mask) )  THEN
     
    716699
    717700      return_value = 1
    718       CALL internal_message( 'error', routine_name //                   &
    719                                       ': dimension ' // TRIM( name ) // &
    720                                       ': At least one but no more than two bounds must be given' )
     701      CALL internal_message( 'error', routine_name //          &
     702                             ': dimension ' // TRIM( name ) // &
     703                             ': At least one but no more than two bounds must be given' )
    721704
    722705   ENDIF
     
    729712         IF ( TRIM( filename ) == files(f)%name )  THEN
    730713
    731             IF ( .NOT. ALLOCATED( files(f)%dimensions ) )  THEN
     714            IF ( files(f)%is_init )  THEN
     715
     716               return_value = 1
     717               CALL internal_message( 'error',                           &
     718                       routine_name // ': file "' // TRIM( filename ) // &
     719                       '" is already initialized. No further dimension definition allowed!' )
     720               EXIT
     721
     722            ELSEIF ( .NOT. ALLOCATED( files(f)%dimensions ) )  THEN
    732723
    733724               ndim = 1
     
    736727            ELSE
    737728
    738                ndim = SIZE( files(f)%dimensions )
    739 
    740                !-- Check if dimension already exists in file
    741                DO  d = 1, ndim
    742                   IF ( files(f)%dimensions(d)%name == dimension%name )  THEN
    743                      return_value = 1
    744                      CALL internal_message( 'error',            &
    745                              routine_name //                    &
    746                              ': dimension "' // TRIM( name ) // &
    747                              '" already exists in file "' // TRIM( filename ) // '"' )
    748                      EXIT
     729               !-- Check if any variable of the same name as the new dimension is already defined
     730               IF ( ALLOCATED( files(f)%variables ) )  THEN
     731                  DO  i = 1, SIZE( files(f)%variables )
     732                     IF ( files(f)%variables(i)%name == dimension%name )  THEN
     733                        return_value = 1
     734                        CALL internal_message( 'error', routine_name //                   &
     735                                               ': file "' // TRIM( filename ) //          &
     736                                               '" already has a variable of name "' //    &
     737                                               TRIM( dimension%name ) // '" defined. ' // &
     738                                               'Defining a dimension of the same ' //     &
     739                                               'name is not allowed.' )
     740                        EXIT
     741                     ENDIF
     742                  ENDDO
     743               ENDIF
     744
     745               IF ( return_value == 0 )  THEN
     746                  !-- Check if dimension already exists in file
     747                  ndim = SIZE( files(f)%dimensions )
     748
     749                  DO  d = 1, ndim
     750                     IF ( files(f)%dimensions(d)%name == dimension%name )  THEN
     751                        return_value = 1
     752                        CALL internal_message( 'error',            &
     753                                routine_name //                    &
     754                                ': dimension "' // TRIM( name ) // &
     755                                '" already exists in file "' // TRIM( filename ) // '"' )
     756                        EXIT
     757                     ENDIF
     758                  ENDDO
     759
     760                  !-- Extend dimension list
     761                  IF ( return_value == 0 )  THEN
     762                     ALLOCATE( dims_tmp(ndim) )
     763                     dims_tmp = files(f)%dimensions
     764                     DEALLOCATE( files(f)%dimensions )
     765                     ndim = ndim + 1
     766                     ALLOCATE( files(f)%dimensions(ndim) )
     767                     files(f)%dimensions(:ndim-1) = dims_tmp
     768                     DEALLOCATE( dims_tmp )
    749769                  ENDIF
    750                ENDDO
    751 
    752                !-- Extend dimension list
    753                IF ( return_value == 0 )  THEN
    754                   ALLOCATE( dims_tmp(ndim) )
    755                   dims_tmp = files(f)%dimensions
    756                   DEALLOCATE( files(f)%dimensions )
    757                   ndim = ndim + 1
    758                   ALLOCATE( files(f)%dimensions(ndim) )
    759                   files(f)%dimensions(:ndim-1) = dims_tmp
    760                   DEALLOCATE( dims_tmp )
    761770               ENDIF
    762771
     
    832841      IF ( TRIM( filename ) == files(f)%name )  THEN
    833842
    834          !-- Check if dimensions assigned to variable are defined within file
    835          IF ( ALLOCATED( files(f)%dimensions ) )  THEN
    836 
    837             DO  i = 1, SIZE( variable%dimension_names )
    838                found = .FALSE.
    839                DO  d = 1, SIZE( files(f)%dimensions )
    840                   IF ( files(f)%dimensions(d)%name == variable%dimension_names(i) )  THEN
    841                      found = .TRUE.
     843         IF ( files(f)%is_init )  THEN
     844
     845            return_value = 1
     846            CALL internal_message( 'error', routine_name // ': file "' // TRIM( filename ) // &
     847                    '" is already initialized. No further variable definition allowed!' )
     848            EXIT
     849
     850         ELSEIF ( ALLOCATED( files(f)%dimensions ) )  THEN
     851
     852            !-- Check if any dimension of the same name as the new variable is already defined
     853            DO  d = 1, SIZE( files(f)%dimensions )
     854               IF ( files(f)%dimensions(d)%name == variable%name )  THEN
     855                  return_value = 1
     856                  CALL internal_message( 'error', routine_name //                  &
     857                                         ': file "' // TRIM( filename ) //         &
     858                                         '" already has a dimension of name "' //  &
     859                                         TRIM( variable%name ) // '" defined. ' // &
     860                                         'Defining a variable of the same name is not allowed.' )
     861                  EXIT
     862               ENDIF
     863            ENDDO
     864
     865            !-- Check if dimensions assigned to variable are defined within file
     866            IF ( return_value == 0 )  THEN
     867               DO  i = 1, SIZE( variable%dimension_names )
     868                  found = .FALSE.
     869                  DO  d = 1, SIZE( files(f)%dimensions )
     870                     IF ( files(f)%dimensions(d)%name == variable%dimension_names(i) )  THEN
     871                        found = .TRUE.
     872                        EXIT
     873                     ENDIF
     874                  ENDDO
     875                  IF ( .NOT. found )  THEN
     876                     return_value = 1
     877                     CALL internal_message( 'error',                               &
     878                                            routine_name //                        &
     879                                            ': variable "' // TRIM( name ) //      &
     880                                            '" in file "' // TRIM( filename ) //   &
     881                                            '": required dimension "' //           &
     882                                            TRIM( variable%dimension_names(i) ) // &
     883                                            '" not defined' )
    842884                     EXIT
    843885                  ENDIF
    844886               ENDDO
    845                IF ( .NOT. found )  THEN
    846                   return_value = 1
    847                   CALL internal_message( 'error', &
    848                                          routine_name //                      &
    849                                          ': variable "' // TRIM( name ) //    &
    850                                          '" in file "' // TRIM( filename ) // &
    851                                          '": required dimension "' //         &
    852                                          TRIM( variable%dimension_names(i) ) // '" not defined' )
    853                   EXIT
    854                ENDIF
    855             ENDDO
     887            ENDIF
    856888
    857889         ELSE
     
    12631295
    12641296      IF ( TRIM( filename ) == files(f)%name )  THEN
     1297
     1298         IF ( files(f)%is_init )  THEN
     1299            return_value = 1
     1300            CALL internal_message( 'error', routine_name // ': file "' // TRIM( filename ) // &
     1301                    '" is already initialized. No further attribute definition allowed!' )
     1302            EXIT
     1303         ENDIF
    12651304
    12661305         !-- Add attribute to file
     
    13281367                        !-- Check if attribute already exists
    13291368                        DO  a = 1, natt
    1330                            IF ( files(f)%dimensions(d)%attributes(a)%name == attribute%name )  THEN
     1369                           IF ( files(f)%dimensions(d)%attributes(a)%name == attribute%name ) &
     1370                           THEN
    13311371                              IF ( append )  THEN
    13321372                                 !-- Append existing character attribute
     
    13851425                        !-- Check if attribute already exists
    13861426                        DO  a = 1, natt
    1387                            IF ( files(f)%variables(d)%attributes(a)%name == attribute%name )  THEN
     1427                           IF ( files(f)%variables(d)%attributes(a)%name == attribute%name )  &
     1428                           THEN
    13881429                              IF ( append )  THEN
    13891430                                 !-- Append existing character attribute
     
    14971538      DO  f = 1, nf
    14981539
     1540         !-- Skip initialization if file is already initialized
     1541         IF ( files(f)%is_init )  CYCLE
     1542
     1543         CALL internal_message( 'debug', routine_name // ': initialize file "' // &
     1544                                TRIM( files(f)%name ) // '"' )
     1545
    14991546         !-- Open file
    15001547         CALL open_output_file( files(f)%format, files(f)%name, files(f)%id, &
    1501                                 files(f)%is_init, return_value=return_value )
     1548                                return_value=return_value )
    15021549
    15031550         !-- Initialize file header:
     
    15081555         !-- End file definition
    15091556         IF ( return_value == 0 )  &
    1510             CALL dom_init_end( files(f)%format, files(f)%id, return_value=return_value )
    1511 
    1512          !-- Write dimension values into file
     1557            CALL dom_init_end( files(f)%format, files(f)%id, files(f)%name, return_value )
     1558
    15131559         IF ( return_value == 0 )  THEN
    15141560
     1561            !-- Flag file as initialized
     1562            files(f)%is_init = .TRUE.
     1563
     1564            !-- Write dimension values into file
    15151565            DO  d = 1, SIZE( files(f)%dimensions )
    15161566               IF ( ALLOCATED( files(f)%dimensions(d)%values_int8 ) )  THEN
     
    16281678   return_value = 0
    16291679
    1630    !-- Set flag for files to be initialized
     1680   !-- Flag files which contain output variables as used
    16311681   file_is_used(:) = .FALSE.
    16321682   DO  f = 1, nf
     
    16571707   DO  f = 1, nf
    16581708
     1709      !-- If a file is already initialized, it was already checked previously
     1710      IF ( files(f)%is_init )  CYCLE
     1711
    16591712      !-- Get number of defined dimensions
    16601713      ndim = SIZE( files(f)%dimensions )
     
    16991752!> Open requested output file.
    17001753!--------------------------------------------------------------------------------------------------!
    1701 SUBROUTINE open_output_file( file_format, filename, file_id, is_init, return_value )
     1754SUBROUTINE open_output_file( file_format, filename, file_id, return_value )
    17021755
    17031756   CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format chosen for file
     
    17061759   CHARACTER(LEN=*), PARAMETER ::  routine_name = 'open_output_file'  !< name of routine
    17071760
    1708    INTEGER(iwp), INTENT(OUT) ::  file_id       !< file ID
    1709    INTEGER(iwp), INTENT(OUT) ::  return_value  !< return value
    1710 
    1711    LOGICAL, INTENT(OUT) ::  is_init  !< true if file is opened
    1712 
     1761   INTEGER(iwp), INTENT(OUT) ::  file_id              !< file ID
     1762   INTEGER(iwp)              ::  output_return_value  !< return value of a called output routine
     1763   INTEGER(iwp), INTENT(OUT) ::  return_value         !< return value
     1764
     1765
     1766   return_value = 0
     1767   output_return_value = 0
    17131768
    17141769   SELECT CASE ( TRIM( file_format ) )
    17151770
    17161771      CASE ( 'binary' )
    1717          CALL binary_open_file( filename, file_id, return_value )
     1772         CALL binary_open_file( 'binary', filename, file_id, output_return_value )
    17181773
    17191774      CASE ( 'netcdf4-serial' )
    1720          CALL netcdf4_serial_open_file( filename, file_id, return_value )
     1775         CALL netcdf4_open_file( 'serial', filename, file_id, output_return_value )
    17211776
    17221777      CASE ( 'netcdf4-parallel' )
    1723          CALL netcdf4_parallel_open_file( filename, file_id, return_value )
     1778         CALL netcdf4_open_file( 'parallel', filename, file_id, output_return_value )
    17241779
    17251780      CASE DEFAULT
    17261781         return_value = 1
    1727          CALL internal_message( 'error', routine_name //                              &
    1728                                          ': file "' // TRIM( filename ) //            &
    1729                                          '": file format "' // TRIM( file_format ) // &
    1730                                          '" not supported' )
    17311782
    17321783   END SELECT
    17331784
    1734    is_init = return_value == 0
     1785   IF ( output_return_value /= 0 )  THEN
     1786      return_value = output_return_value
     1787      CALL internal_message( 'error', routine_name // &
     1788                             ': error while opening file "' // TRIM( filename ) // '"' )
     1789   ELSEIF ( return_value /= 0 )  THEN
     1790      CALL internal_message( 'error', routine_name //                              &
     1791                                      ': file "' // TRIM( filename ) //            &
     1792                                      '": file format "' // TRIM( file_format ) // &
     1793                                      '" not supported' )
     1794   ENDIF
    17351795
    17361796END SUBROUTINE open_output_file
     
    17571817   IF ( ALLOCATED( file%attributes ) )  THEN
    17581818      DO  a = 1, SIZE( file%attributes )
    1759          return_value = write_attribute( file%format, file%id, var_id=no_var_id, &
    1760                                 attribute=file%attributes(a) )
     1819         return_value = write_attribute( file%format, file%id, file%name, var_id=no_var_id, &
     1820                                         attribute=file%attributes(a) )
    17611821         IF ( return_value /= 0 )  EXIT
    17621822      ENDDO
     
    17711831
    17721832            !-- Initialize non-masked dimension
    1773             CALL init_file_dimension( file%format,                             &
    1774                     file%id, file%dimensions(d)%id, file%dimensions(d)%var_id, &
    1775                     file%dimensions(d)%name, file%dimensions(d)%data_type,     &
    1776                     file%dimensions(d)%length, file%dimensions(d)%is_init, return_value )
     1833            CALL init_file_dimension( file%format, file%id, file%name,     &
     1834                    file%dimensions(d)%id, file%dimensions(d)%var_id,      &
     1835                    file%dimensions(d)%name, file%dimensions(d)%data_type, &
     1836                    file%dimensions(d)%length, return_value )
    17771837
    17781838         ELSE
    17791839
    17801840            !-- Initialize masked dimension
    1781             CALL init_file_dimension( file%format,                             &
    1782                     file%id, file%dimensions(d)%id, file%dimensions(d)%var_id, &
    1783                     file%dimensions(d)%name, file%dimensions(d)%data_type,     &
    1784                     file%dimensions(d)%length_mask, file%dimensions(d)%is_init, return_value )
     1841            CALL init_file_dimension( file%format, file%id, file%name,     &
     1842                    file%dimensions(d)%id, file%dimensions(d)%var_id,      &
     1843                    file%dimensions(d)%name, file%dimensions(d)%data_type, &
     1844                    file%dimensions(d)%length_mask, return_value )
    17851845
    17861846         ENDIF
     
    17891849            !-- Write dimension attributes
    17901850            DO  a = 1, SIZE( file%dimensions(d)%attributes )
    1791                return_value = write_attribute( file%format, file%id, file%dimensions(d)%var_id, &
     1851               return_value = write_attribute( file%format, file%id, file%name, &
     1852                                 var_id=file%dimensions(d)%var_id,              &
     1853                                 var_name=file%dimensions(d)%name,              &
    17921854                                 attribute=file%dimensions(d)%attributes(a) )
    17931855               IF ( return_value /= 0 )  EXIT
     
    18071869         DO  d = 1, SIZE( file%variables )
    18081870
    1809             CALL init_file_variable( file%format, file%id, file%variables(d)%id, &
    1810                     file%variables(d)%name, file%variables(d)%data_type,        &
    1811                     file%variables(d)%dimension_ids,                             &
    1812                     file%variables(d)%is_init, file%variables(d)%is_global, return_value )
     1871            CALL init_file_variable( file%format, file%id, file%name,                          &
     1872                    file%variables(d)%id, file%variables(d)%name, file%variables(d)%data_type, &
     1873                    file%variables(d)%dimension_ids,                                           &
     1874                    file%variables(d)%is_global, return_value )
    18131875
    18141876            IF ( return_value == 0  .AND.  ALLOCATED( file%variables(d)%attributes ) )  THEN
    18151877               !-- Write variable attribures
    18161878               DO  a = 1, SIZE( file%variables(d)%attributes )
    1817                   return_value = write_attribute( file%format, file%id, file%variables(d)%id, &
     1879                  return_value = write_attribute( file%format, file%id, file%name, &
     1880                                    var_id=file%variables(d)%id,                   &
     1881                                    var_name=file%variables(d)%name,               &
    18181882                                    attribute=file%variables(d)%attributes(a) )
    18191883                  IF ( return_value /= 0 )  EXIT
     
    18351899!> Write attribute to file.
    18361900!--------------------------------------------------------------------------------------------------!
    1837 FUNCTION write_attribute( file_format, file_id, var_id, attribute ) RESULT( return_value )
     1901FUNCTION write_attribute( file_format, file_id, file_name, var_id, var_name, attribute ) RESULT( return_value )
    18381902
    18391903   CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format chosen for file
     1904   CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< file name
     1905   CHARACTER(LEN=*), INTENT(IN), OPTIONAL ::  var_name     !< variable name
    18401906
    18411907   CHARACTER(LEN=*), PARAMETER ::  routine_name = 'write_attribute'  !< file format chosen for file
    18421908
    1843    INTEGER(iwp) ::  file_id       !< file ID
    1844    INTEGER(iwp) ::  return_value  !< return value
    1845    INTEGER(iwp) ::  var_id        !< variable ID
     1909   INTEGER(iwp), INTENT(IN) ::  file_id              !< file ID
     1910   INTEGER(iwp)             ::  return_value         !< return value
     1911   INTEGER(iwp)             ::  output_return_value  !< return value of a called output routine
     1912   INTEGER(iwp), INTENT(IN) ::  var_id               !< variable ID
    18461913
    18471914   TYPE(attribute_type), INTENT(IN) ::  attribute  !< attribute to be written
    18481915
    18491916
     1917   return_value = 0
     1918   output_return_value = 0
     1919
     1920   !-- Prepare for possible error message
     1921   IF ( PRESENT( var_name ) )  THEN
     1922      temp_string = '(file "' // TRIM( file_name ) //      &
     1923                    '", variable "' // TRIM( var_name ) // &
     1924                    '", attribute "' // TRIM( attribute%name ) // '")'
     1925   ELSE
     1926      temp_string = '(file "' // TRIM( file_name ) // &
     1927                    '", attribute "' // TRIM( attribute%name ) // '")'
     1928   ENDIF
     1929
     1930   !-- Write attribute to file
    18501931   SELECT CASE ( TRIM( file_format ) )
    18511932
     
    18571938               CALL binary_write_attribute( file_id=file_id, var_id=var_id,          &
    18581939                       att_name=attribute%name, att_value_char=attribute%value_char, &
    1859                        return_value=return_value )
     1940                       return_value=output_return_value )
    18601941
    18611942            CASE( 'int8' )
    18621943               CALL binary_write_attribute( file_id=file_id, var_id=var_id,          &
    18631944                       att_name=attribute%name, att_value_int8=attribute%value_int8, &
    1864                        return_value=return_value )
     1945                       return_value=output_return_value )
    18651946
    18661947            CASE( 'int16' )
    18671948               CALL binary_write_attribute( file_id=file_id, var_id=var_id,            &
    18681949                       att_name=attribute%name, att_value_int16=attribute%value_int16, &
    1869                        return_value=return_value )
     1950                       return_value=output_return_value )
    18701951
    18711952            CASE( 'int32' )
    18721953               CALL binary_write_attribute( file_id=file_id, var_id=var_id,            &
    18731954                       att_name=attribute%name, att_value_int32=attribute%value_int32, &
    1874                        return_value=return_value )
     1955                       return_value=output_return_value )
    18751956
    18761957            CASE( 'real32' )
    18771958               CALL binary_write_attribute( file_id=file_id, var_id=var_id,              &
    18781959                       att_name=attribute%name, att_value_real32=attribute%value_real32, &
    1879                        return_value=return_value )
     1960                       return_value=output_return_value )
    18801961
    18811962            CASE( 'real64' )
    18821963               CALL binary_write_attribute( file_id=file_id, var_id=var_id,              &
    18831964                       att_name=attribute%name, att_value_real64=attribute%value_real64, &
    1884                        return_value=return_value )
     1965                       return_value=output_return_value )
    18851966
    18861967            CASE DEFAULT
    18871968               return_value = 1
    1888                CALL internal_message( 'error',                                          &
    1889                                       routine_name //                                   &
    1890                                       ': attribute "' // TRIM( attribute%name ) //      &
    1891                                       '": data type "'// TRIM( attribute%data_type ) // &
    1892                                       '" not supported for file format "binary".' )
     1969               CALL internal_message( 'error', routine_name //                     &
     1970                                      ': file format "' // TRIM( file_format ) //  &
     1971                                      '" does not support attribute data type "'// &
     1972                                      TRIM( attribute%data_type ) //              &
     1973                                      '" ' // TRIM( temp_string ) )
    18931974
    18941975         END SELECT
    18951976
    1896       CASE ( 'netcdf4-serial' )
     1977      CASE ( 'netcdf4-parallel', 'netcdf4-serial' )
    18971978
    18981979         SELECT CASE ( TRIM( attribute%data_type ) )
    18991980
    19001981            CASE( 'char' )
    1901                CALL netcdf4_serial_write_attribute( file_id=file_id, var_id=var_id,  &
     1982               CALL netcdf4_write_attribute( file_id=file_id, var_id=var_id,  &
    19021983                       att_name=attribute%name, att_value_char=attribute%value_char, &
    1903                        return_value=return_value )
     1984                       return_value=output_return_value )
    19041985
    19051986            CASE( 'int8' )
    1906                CALL netcdf4_serial_write_attribute( file_id=file_id, var_id=var_id,  &
     1987               CALL netcdf4_write_attribute( file_id=file_id, var_id=var_id,  &
    19071988                       att_name=attribute%name, att_value_int8=attribute%value_int8, &
    1908                        return_value=return_value )
     1989                       return_value=output_return_value )
    19091990
    19101991            CASE( 'int16' )
    1911                CALL netcdf4_serial_write_attribute( file_id=file_id, var_id=var_id,    &
     1992               CALL netcdf4_write_attribute( file_id=file_id, var_id=var_id,    &
    19121993                       att_name=attribute%name, att_value_int16=attribute%value_int16, &
    1913                        return_value=return_value )
     1994                       return_value=output_return_value )
    19141995
    19151996            CASE( 'int32' )
    1916                CALL netcdf4_serial_write_attribute( file_id=file_id, var_id=var_id,    &
     1997               CALL netcdf4_write_attribute( file_id=file_id, var_id=var_id,    &
    19171998                       att_name=attribute%name, att_value_int32=attribute%value_int32, &
    1918                        return_value=return_value )
     1999                       return_value=output_return_value )
    19192000
    19202001            CASE( 'real32' )
    1921                CALL netcdf4_serial_write_attribute( file_id=file_id, var_id=var_id,      &
     2002               CALL netcdf4_write_attribute( file_id=file_id, var_id=var_id,      &
    19222003                       att_name=attribute%name, att_value_real32=attribute%value_real32, &
    1923                        return_value=return_value )
     2004                       return_value=output_return_value )
    19242005
    19252006            CASE( 'real64' )
    1926                CALL netcdf4_serial_write_attribute( file_id=file_id, var_id=var_id,      &
     2007               CALL netcdf4_write_attribute( file_id=file_id, var_id=var_id,      &
    19272008                       att_name=attribute%name, att_value_real64=attribute%value_real64, &
    1928                        return_value=return_value )
     2009                       return_value=output_return_value )
    19292010
    19302011            CASE DEFAULT
    19312012               return_value = 1
    1932                CALL internal_message( 'error',                                          &
    1933                                       routine_name //                                   &
    1934                                       ': attribute "' // TRIM( attribute%name ) //      &
    1935                                       '": data type "'// TRIM( attribute%data_type ) // &
    1936                                       '" not supported for file format "netcdf4-serial".' )
    1937 
    1938          END SELECT
    1939 
    1940       CASE ( 'netcdf4-parallel' )
    1941 
    1942          SELECT CASE ( TRIM( attribute%data_type ) )
    1943 
    1944             CASE( 'char' )
    1945                CALL netcdf4_parallel_write_attribute( file_id=file_id, var_id=var_id, &
    1946                        att_name=attribute%name, att_value_char=attribute%value_char,  &
    1947                        return_value=return_value )
    1948 
    1949             CASE( 'int8' )
    1950                CALL netcdf4_parallel_write_attribute( file_id=file_id, var_id=var_id, &
    1951                        att_name=attribute%name, att_value_int8=attribute%value_int8,  &
    1952                        return_value=return_value )
    1953 
    1954             CASE( 'int16' )
    1955                CALL netcdf4_parallel_write_attribute( file_id=file_id, var_id=var_id,  &
    1956                        att_name=attribute%name, att_value_int16=attribute%value_int16, &
    1957                        return_value=return_value )
    1958 
    1959             CASE( 'int32' )
    1960                CALL netcdf4_parallel_write_attribute( file_id=file_id, var_id=var_id,  &
    1961                        att_name=attribute%name, att_value_int32=attribute%value_int32, &
    1962                        return_value=return_value )
    1963 
    1964             CASE( 'real32' )
    1965                CALL netcdf4_parallel_write_attribute( file_id=file_id, var_id=var_id,    &
    1966                        att_name=attribute%name, att_value_real32=attribute%value_real32, &
    1967                        return_value=return_value )
    1968 
    1969             CASE( 'real64' )
    1970                CALL netcdf4_parallel_write_attribute( file_id=file_id, var_id=var_id,    &
    1971                        att_name=attribute%name, att_value_real64=attribute%value_real64, &
    1972                        return_value=return_value )
    1973 
    1974             CASE DEFAULT
    1975                return_value = 1
    1976                CALL internal_message( 'error',                                          &
    1977                                       routine_name //                                   &
    1978                                       ': attribute "' // TRIM( attribute%name ) //      &
    1979                                       '": data type "'// TRIM( attribute%data_type ) // &
    1980                                       '" not supported for file format "netcdf4-parallel".' )
     2013               CALL internal_message( 'error', routine_name //                     &
     2014                                      ': file format "' // TRIM( file_format ) //  &
     2015                                      '" does not support attribute data type "'// &
     2016                                      TRIM( attribute%data_type ) //               &
     2017                                      '" ' // TRIM( temp_string ) )
    19812018
    19822019         END SELECT
     
    19862023         CALL internal_message( 'error',        &
    19872024                                routine_name // &
    1988                                 ': unsupported file format "' // TRIM( file_format ) // '"' )
     2025                                ': unsupported file format "' // TRIM( file_format ) // &
     2026                                '" ' // TRIM( temp_string ) )
    19892027
    19902028   END SELECT
     2029   
     2030   IF ( output_return_value /= 0 )  THEN
     2031      return_value = output_return_value
     2032      CALL internal_message( 'error',        &
     2033                             routine_name // &
     2034                             ': error while writing attribute ' // TRIM( temp_string ) )
     2035   ENDIF
    19912036
    19922037END FUNCTION write_attribute
     
    19972042!> Initialize dimension in file.
    19982043!--------------------------------------------------------------------------------------------------!
    1999 SUBROUTINE init_file_dimension( file_format, file_id, dim_id, var_id,        &
    2000                                 dim_name, dim_type, dim_length, is_init, return_value )
     2044SUBROUTINE init_file_dimension( file_format, file_id, file_name, dim_id, var_id, &
     2045                                dim_name, dim_type, dim_length, return_value )
    20012046
    20022047   CHARACTER(LEN=*), INTENT(IN) ::  dim_name     !< name of dimension
    20032048   CHARACTER(LEN=*), INTENT(IN) ::  dim_type     !< data type of dimension
    20042049   CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format chosen for file
     2050   CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< name of file
    20052051
    20062052   CHARACTER(LEN=*), PARAMETER ::  routine_name = 'init_file_dimension'  !< file format chosen for file
    20072053
    2008    INTEGER(iwp), INTENT(OUT) ::  dim_id        !< dimension ID
    2009    INTEGER(iwp), INTENT(IN)  ::  dim_length    !< length of dimension
    2010    INTEGER(iwp), INTENT(IN)  ::  file_id       !< file ID
    2011    INTEGER(iwp), INTENT(OUT) ::  return_value  !< return value
    2012    INTEGER(iwp), INTENT(OUT) ::  var_id        !< associated variable ID
    2013 
    2014    LOGICAL, INTENT(OUT) ::  is_init  !< true if dimension is initialized
    2015 
     2054   INTEGER(iwp), INTENT(OUT) ::  dim_id               !< dimension ID
     2055   INTEGER(iwp), INTENT(IN)  ::  dim_length           !< length of dimension
     2056   INTEGER(iwp), INTENT(IN)  ::  file_id              !< file ID
     2057   INTEGER(iwp)              ::  output_return_value  !< return value of a called output routine
     2058   INTEGER(iwp), INTENT(OUT) ::  return_value         !< return value
     2059   INTEGER(iwp), INTENT(OUT) ::  var_id               !< associated variable ID
     2060
     2061
     2062   return_value = 0
     2063   output_return_value = 0
     2064
     2065   temp_string = '(file "' // TRIM( file_name ) // &
     2066                 '", dimension "' // TRIM( dim_name ) // '")'
    20162067
    20172068   SELECT CASE ( TRIM( file_format ) )
    20182069
    20192070      CASE ( 'binary' )
    2020          CALL binary_init_dimension( file_id, dim_id, var_id, &
    2021                  dim_name, dim_type, dim_length, is_init, return_value )
     2071         CALL binary_init_dimension( 'binary', file_id, dim_id, var_id, &
     2072                 dim_name, dim_type, dim_length, return_value=output_return_value )
    20222073
    20232074      CASE ( 'netcdf4-serial' )
    2024          CALL netcdf4_serial_init_dimension( file_id, dim_id, var_id, &
    2025                  dim_name, dim_type, dim_length, is_init, return_value )
     2075         CALL netcdf4_init_dimension( 'serial', file_id, dim_id, var_id, &
     2076                 dim_name, dim_type, dim_length, return_value=output_return_value )
    20262077
    20272078      CASE ( 'netcdf4-parallel' )
    2028          CALL netcdf4_parallel_init_dimension( file_id, dim_id, var_id, &
    2029                  dim_name, dim_type, dim_length, is_init, return_value )
     2079         CALL netcdf4_init_dimension( 'parallel', file_id, dim_id, var_id, &
     2080                 dim_name, dim_type, dim_length, return_value=output_return_value )
    20302081
    20312082      CASE DEFAULT
    20322083         return_value = 1
    2033          WRITE( temp_string, * ) file_id
    2034          CALL internal_message( 'error', routine_name //                              &
    2035                                          ': file id = ' // TRIM( temp_string ) //     &
    2036                                          '": file format "' // TRIM( file_format ) // &
    2037                                          '" not supported' )
     2084         CALL internal_message( 'error', routine_name //                    &
     2085                                ': file format "' // TRIM( file_format ) // &
     2086                                '" not supported ' // TRIM( temp_string ) )
    20382087
    20392088   END SELECT
     2089
     2090   IF ( output_return_value /= 0 )  THEN
     2091      return_value = output_return_value
     2092      CALL internal_message( 'error', routine_name // &
     2093                             ': error while defining dimension ' // TRIM( temp_string ) )
     2094   ENDIF
    20402095
    20412096END SUBROUTINE init_file_dimension
     
    20972152!> Initialize variable.
    20982153!--------------------------------------------------------------------------------------------------!
    2099 SUBROUTINE init_file_variable( file_format, file_id, var_id,   &
    2100                                var_name, var_type, var_dim_id, &
    2101                                is_init, is_global, return_value )
     2154SUBROUTINE init_file_variable( file_format, file_id, file_name,        &
     2155                               var_id, var_name, var_type, var_dim_id, &
     2156                               is_global, return_value )
    21022157
    21032158   CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format chosen for file
     2159   CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< file name
    21042160   CHARACTER(LEN=*), INTENT(IN) ::  var_name     !< name of variable
    21052161   CHARACTER(LEN=*), INTENT(IN) ::  var_type     !< data type of variable
     
    21072163   CHARACTER(LEN=*), PARAMETER ::  routine_name = 'init_file_variable'  !< file format chosen for file
    21082164
    2109    INTEGER(iwp), INTENT(IN)  ::  file_id       !< file ID
    2110    INTEGER(iwp), INTENT(OUT) ::  return_value  !< return value
    2111    INTEGER(iwp), INTENT(OUT) ::  var_id        !< variable ID
     2165   INTEGER(iwp), INTENT(IN)  ::  file_id              !< file ID
     2166   INTEGER(iwp)              ::  output_return_value  !< return value of a called output routine
     2167   INTEGER(iwp), INTENT(OUT) ::  return_value         !< return value
     2168   INTEGER(iwp), INTENT(OUT) ::  var_id               !< variable ID
    21122169
    21132170   INTEGER(iwp), DIMENSION(:), INTENT(IN) ::  var_dim_id  !< list of dimension IDs used by variable
    21142171
    21152172   LOGICAL, INTENT(IN)  ::  is_global  !< true if variable is global
    2116    LOGICAL, INTENT(OUT) ::  is_init    !< true if variable is initialized
    2117 
     2173
     2174
     2175   return_value = 0
     2176   output_return_value = 0
     2177
     2178   temp_string = '(file "' // TRIM( file_name ) // &
     2179                 '", variable "' // TRIM( var_name ) // '")'
    21182180
    21192181   SELECT CASE ( TRIM( file_format ) )
    21202182
    21212183      CASE ( 'binary' )
    2122          CALL binary_init_variable( file_id, var_id, var_name, var_type, var_dim_id, &
    2123                                     is_init, is_global, return_value )
     2184         CALL binary_init_variable( 'binary', file_id, var_id, var_name, var_type, &
     2185                                    var_dim_id, is_global, return_value=output_return_value )
    21242186
    21252187      CASE ( 'netcdf4-serial' )
    2126          CALL netcdf4_serial_init_variable( file_id, var_id, var_name, var_type, var_dim_id, &
    2127                                             is_init, is_global, return_value )
     2188         CALL netcdf4_init_variable( 'serial', file_id, var_id, var_name, var_type, &
     2189                                     var_dim_id, is_global, return_value=output_return_value )
    21282190
    21292191      CASE ( 'netcdf4-parallel' )
    2130          CALL netcdf4_parallel_init_variable( file_id, var_id, var_name, var_type, var_dim_id, &
    2131                                               is_init, is_global, return_value )
     2192         CALL netcdf4_init_variable( 'parallel', file_id, var_id, var_name, var_type, &
     2193                                     var_dim_id, is_global, return_value=output_return_value )
    21322194
    21332195      CASE DEFAULT
    21342196         return_value = 1
    2135          is_init = .FALSE.
    2136          CALL internal_message( 'error', routine_name // &
    2137                                 ': unsupported file format "' // TRIM( file_format ) )
     2197         CALL internal_message( 'error', routine_name //                    &
     2198                                ': file format "' // TRIM( file_format ) // &
     2199                                '" not supported ' // TRIM( temp_string ) )
    21382200
    21392201   END SELECT
     2202
     2203   IF ( output_return_value /= 0 )  THEN
     2204      return_value = output_return_value
     2205      CALL internal_message( 'error', routine_name // &
     2206                             ': error while defining variable ' // TRIM( temp_string ) )
     2207   ENDIF
    21402208
    21412209END SUBROUTINE init_file_variable
     
    21482216!> @todo Do we need an MPI barrier at the end?
    21492217!--------------------------------------------------------------------------------------------------!
    2150 SUBROUTINE dom_init_end( file_format, file_id, return_value )
     2218SUBROUTINE dom_init_end( file_format, file_id, file_name, return_value )
    21512219
    21522220   CHARACTER(LEN=*), INTENT(IN) ::  file_format  !< file format
     2221   CHARACTER(LEN=*), INTENT(IN) ::  file_name    !< file name
    21532222
    21542223   CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_init_end'  !< name of routine
    21552224
    2156    INTEGER(iwp), INTENT(IN)  ::  file_id       !< file id
    2157    INTEGER(iwp), INTENT(OUT) ::  return_value  !< return value
    2158 
     2225   INTEGER(iwp), INTENT(IN)  ::  file_id              !< file id
     2226   INTEGER(iwp)              ::  output_return_value  !< return value of a called output routine
     2227   INTEGER(iwp), INTENT(OUT) ::  return_value         !< return value
     2228
     2229
     2230   return_value = 0
     2231   output_return_value = 0
     2232
     2233   temp_string = '(file "' // TRIM( file_name ) // '")'
    21592234
    21602235   SELECT CASE ( TRIM( file_format ) )
    21612236
    21622237      CASE ( 'binary' )
    2163          CALL binary_init_end( file_id, return_value )
    2164 
    2165       CASE ( 'netcdf4-serial' )
    2166          CALL netcdf4_serial_init_end( file_id, return_value )
    2167 
    2168       CASE ( 'netcdf4-parallel' )
    2169          CALL netcdf4_parallel_init_end( file_id, return_value )
     2238         CALL binary_init_end( file_id, output_return_value )
     2239
     2240      CASE ( 'netcdf4-parallel', 'netcdf4-serial' )
     2241         CALL netcdf4_init_end( file_id, output_return_value )
    21702242
    21712243      CASE DEFAULT
    21722244         return_value = 1
    2173          WRITE( temp_string, * ) file_id
    2174          CALL internal_message( 'error', routine_name //                             &
    2175                                          ': file id = ' // TRIM( temp_string ) //    &
    2176                                          ': file format "' // TRIM( file_format ) // &
    2177                                          '" not supported' )
     2245         CALL internal_message( 'error', routine_name //                    &
     2246                                ': file format "' // TRIM( file_format ) // &
     2247                                '" not supported ' // TRIM( temp_string ) )
    21782248
    21792249   END SELECT
     2250
     2251   IF ( output_return_value /= 0 )  THEN
     2252      return_value = output_return_value
     2253      CALL internal_message( 'error', routine_name // &
     2254                             ': error while leaving file-definition state ' // &
     2255                             TRIM( temp_string ) )
     2256   ENDIF
    21802257
    21812258   ! CALL MPI_Barrier( MPI_COMM_WORLD, return_value )
     
    22112288   CHARACTER(LEN=*), PARAMETER ::  routine_name = 'dom_write_var'  !< name of routine
    22122289
    2213    INTEGER(iwp) ::  d             !< loop index
    2214    INTEGER(iwp) ::  file_id       !< file ID
    2215    INTEGER(iwp) ::  i             !< loop index
    2216    INTEGER(iwp) ::  j             !< loop index
    2217    INTEGER(iwp) ::  k             !< loop index
    2218    INTEGER(iwp) ::  return_value  !< return value
    2219    INTEGER(iwp) ::  var_id        !< variable ID
     2290   INTEGER(iwp) ::  d                    !< loop index
     2291   INTEGER(iwp) ::  file_id              !< file ID
     2292   INTEGER(iwp) ::  i                    !< loop index
     2293   INTEGER(iwp) ::  j                    !< loop index
     2294   INTEGER(iwp) ::  k                    !< loop index
     2295   INTEGER(iwp) ::  output_return_value  !< return value of a called output routine
     2296   INTEGER(iwp) ::  return_value         !< return value
     2297   INTEGER(iwp) ::  var_id               !< variable ID
    22202298
    22212299   INTEGER(iwp), DIMENSION(:),   INTENT(IN)  ::  bounds_end        !< end index (upper bound) of variable at each dimension
    22222300   INTEGER(iwp), DIMENSION(:),   INTENT(IN)  ::  bounds_start      !< start index (lower bound) of variable at each dimension
    22232301   INTEGER(iwp), DIMENSION(:),   ALLOCATABLE ::  bounds_dim_start  !< start index (lower bound) of each dimension of variable
    2224    INTEGER(iwp), DIMENSION(:),   ALLOCATABLE ::  bounds_end_new    !< start index (upper bound) of masked variable at each dimension
    2225    INTEGER(iwp), DIMENSION(:),   ALLOCATABLE ::  bounds_start_new  !< start index (lower bound) of masked variable at each dimension
     2302   INTEGER(iwp), DIMENSION(:),   ALLOCATABLE ::  bounds_end_new    !< start index (upper bound) of msked var at each dim
     2303   INTEGER(iwp), DIMENSION(:),   ALLOCATABLE ::  bounds_start_new  !< start index (lower bound) of msked var at each dim
    22262304   INTEGER(iwp), DIMENSION(:,:), ALLOCATABLE ::  masked_indices    !< dummy list holding all masked indices along a dimension
    22272305
     
    23302408
    23312409
     2410   return_value = 0
     2411   output_return_value = 0
     2412
    23322413   CALL internal_message( 'debug', routine_name // ': write ' // TRIM( name ) // &
    23332414                                   ' into file ' // TRIM( filename ) )
     
    23432424           SIZE( bounds_end ) /= SIZE( dimension_list ) )  THEN
    23442425         return_value = 1
    2345          CALL internal_message( 'error', routine_name //                      &
    2346                                          ': variable "' // TRIM( name ) //    &
    2347                                          '" in file "' // TRIM( filename ) // &
    2348                                          '": given bounds do not match with number of dimensions' )
     2426         CALL internal_message( 'error', routine_name //             &
     2427                                ': variable "' // TRIM( name ) //    &
     2428                                '" in file "' // TRIM( filename ) // &
     2429                                '": given bounds do not match with number of dimensions' )
    23492430      ENDIF
    23502431
     
    28192900               CALL binary_write_variable( file_id, var_id,                                      &
    28202901                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2821                        var_int8_0d=var_int8_0d_pointer, return_value=return_value )
     2902                       var_int8_0d=var_int8_0d_pointer, return_value=output_return_value )
    28222903            ELSEIF ( PRESENT( var_int8_1d ) )  THEN
    28232904               CALL binary_write_variable( file_id, var_id,                                      &
    28242905                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2825                        var_int8_1d=var_int8_1d_pointer, return_value=return_value )
     2906                       var_int8_1d=var_int8_1d_pointer, return_value=output_return_value )
    28262907            ELSEIF ( PRESENT( var_int8_2d ) )  THEN
    28272908               CALL binary_write_variable( file_id, var_id,                                      &
    28282909                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2829                        var_int8_2d=var_int8_2d_pointer, return_value=return_value )
     2910                       var_int8_2d=var_int8_2d_pointer, return_value=output_return_value )
    28302911            ELSEIF ( PRESENT( var_int8_3d ) )  THEN
    28312912               CALL binary_write_variable( file_id, var_id,                                      &
    28322913                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2833                        var_int8_3d=var_int8_3d_pointer, return_value=return_value )
     2914                       var_int8_3d=var_int8_3d_pointer, return_value=output_return_value )
    28342915            !-- 16bit integer output
    28352916            ELSEIF ( PRESENT( var_int16_0d ) )  THEN
    28362917               CALL binary_write_variable( file_id, var_id,                                      &
    28372918                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2838                        var_int16_0d=var_int16_0d_pointer, return_value=return_value )
     2919                       var_int16_0d=var_int16_0d_pointer, return_value=output_return_value )
    28392920            ELSEIF ( PRESENT( var_int16_1d ) )  THEN
    28402921               CALL binary_write_variable( file_id, var_id,                                      &
    28412922                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2842                        var_int16_1d=var_int16_1d_pointer, return_value=return_value )
     2923                       var_int16_1d=var_int16_1d_pointer, return_value=output_return_value )
    28432924            ELSEIF ( PRESENT( var_int16_2d ) )  THEN
    28442925               CALL binary_write_variable( file_id, var_id,                                      &
    28452926                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2846                        var_int16_2d=var_int16_2d_pointer, return_value=return_value )
     2927                       var_int16_2d=var_int16_2d_pointer, return_value=output_return_value )
    28472928            ELSEIF ( PRESENT( var_int16_3d ) )  THEN
    28482929               CALL binary_write_variable( file_id, var_id,                                      &
    28492930                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2850                        var_int16_3d=var_int16_3d_pointer, return_value=return_value )
     2931                       var_int16_3d=var_int16_3d_pointer, return_value=output_return_value )
    28512932            !-- 32bit integer output
    28522933            ELSEIF ( PRESENT( var_int32_0d ) )  THEN
    28532934               CALL binary_write_variable( file_id, var_id,                                      &
    28542935                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2855                        var_int32_0d=var_int32_0d_pointer, return_value=return_value )
     2936                       var_int32_0d=var_int32_0d_pointer, return_value=output_return_value )
    28562937            ELSEIF ( PRESENT( var_int32_1d ) )  THEN
    28572938               CALL binary_write_variable( file_id, var_id,                                      &
    28582939                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2859                        var_int32_1d=var_int32_1d_pointer, return_value=return_value )
     2940                       var_int32_1d=var_int32_1d_pointer, return_value=output_return_value )
    28602941            ELSEIF ( PRESENT( var_int32_2d ) )  THEN
    28612942               CALL binary_write_variable( file_id, var_id,                                      &
    28622943                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2863                        var_int32_2d=var_int32_2d_pointer, return_value=return_value )
     2944                       var_int32_2d=var_int32_2d_pointer, return_value=output_return_value )
    28642945            ELSEIF ( PRESENT( var_int32_3d ) )  THEN
    28652946               CALL binary_write_variable( file_id, var_id,                                      &
    28662947                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2867                        var_int32_3d=var_int32_3d_pointer, return_value=return_value )
     2948                       var_int32_3d=var_int32_3d_pointer, return_value=output_return_value )
    28682949            !-- working-precision integer output
    28692950            ELSEIF ( PRESENT( var_intwp_0d ) )  THEN
    28702951               CALL binary_write_variable( file_id, var_id,                                      &
    28712952                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2872                        var_intwp_0d=var_intwp_0d_pointer, return_value=return_value )
     2953                       var_intwp_0d=var_intwp_0d_pointer, return_value=output_return_value )
    28732954            ELSEIF ( PRESENT( var_intwp_1d ) )  THEN
    28742955               CALL binary_write_variable( file_id, var_id,                                      &
    28752956                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2876                        var_intwp_1d=var_intwp_1d_pointer, return_value=return_value )
     2957                       var_intwp_1d=var_intwp_1d_pointer, return_value=output_return_value )
    28772958            ELSEIF ( PRESENT( var_intwp_2d ) )  THEN
    28782959               CALL binary_write_variable( file_id, var_id,                                      &
    28792960                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2880                        var_intwp_2d=var_intwp_2d_pointer, return_value=return_value )
     2961                       var_intwp_2d=var_intwp_2d_pointer, return_value=output_return_value )
    28812962            ELSEIF ( PRESENT( var_intwp_3d ) )  THEN
    28822963               CALL binary_write_variable( file_id, var_id,                                      &
    28832964                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2884                        var_intwp_3d=var_intwp_3d_pointer, return_value=return_value )
     2965                       var_intwp_3d=var_intwp_3d_pointer, return_value=output_return_value )
    28852966            !-- 32bit real output
    28862967            ELSEIF ( PRESENT( var_real32_0d ) )  THEN
    28872968               CALL binary_write_variable( file_id, var_id,                                      &
    28882969                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2889                        var_real32_0d=var_real32_0d_pointer, return_value=return_value )
     2970                       var_real32_0d=var_real32_0d_pointer, return_value=output_return_value )
    28902971            ELSEIF ( PRESENT( var_real32_1d ) )  THEN
    28912972               CALL binary_write_variable( file_id, var_id,                                      &
    28922973                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2893                        var_real32_1d=var_real32_1d_pointer, return_value=return_value )
     2974                       var_real32_1d=var_real32_1d_pointer, return_value=output_return_value )
    28942975            ELSEIF ( PRESENT( var_real32_2d ) )  THEN
    28952976               CALL binary_write_variable( file_id, var_id,                                      &
    28962977                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2897                        var_real32_2d=var_real32_2d_pointer, return_value=return_value )
     2978                       var_real32_2d=var_real32_2d_pointer, return_value=output_return_value )
    28982979            ELSEIF ( PRESENT( var_real32_3d ) )  THEN
    28992980               CALL binary_write_variable( file_id, var_id,                                      &
    29002981                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2901                        var_real32_3d=var_real32_3d_pointer, return_value=return_value )
     2982                       var_real32_3d=var_real32_3d_pointer, return_value=output_return_value )
    29022983            !-- 64bit real output
    29032984            ELSEIF ( PRESENT( var_real64_0d ) )  THEN
    29042985               CALL binary_write_variable( file_id, var_id,                                      &
    29052986                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2906                        var_real64_0d=var_real64_0d_pointer, return_value=return_value )
     2987                       var_real64_0d=var_real64_0d_pointer, return_value=output_return_value )
    29072988            ELSEIF ( PRESENT( var_real64_1d ) )  THEN
    29082989               CALL binary_write_variable( file_id, var_id,                                      &
    29092990                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2910                        var_real64_1d=var_real64_1d_pointer, return_value=return_value )
     2991                       var_real64_1d=var_real64_1d_pointer, return_value=output_return_value )
    29112992            ELSEIF ( PRESENT( var_real64_2d ) )  THEN
    29122993               CALL binary_write_variable( file_id, var_id,                                      &
    29132994                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2914                        var_real64_2d=var_real64_2d_pointer, return_value=return_value )
     2995                       var_real64_2d=var_real64_2d_pointer, return_value=output_return_value )
    29152996            ELSEIF ( PRESENT( var_real64_3d ) )  THEN
    29162997               CALL binary_write_variable( file_id, var_id,                                      &
    29172998                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2918                        var_real64_3d=var_real64_3d_pointer, return_value=return_value )
     2999                       var_real64_3d=var_real64_3d_pointer, return_value=output_return_value )
    29193000            !-- working-precision real output
    29203001            ELSEIF ( PRESENT( var_realwp_0d ) )  THEN
    29213002               CALL binary_write_variable( file_id, var_id,                                      &
    29223003                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2923                        var_realwp_0d=var_realwp_0d_pointer, return_value=return_value )
     3004                       var_realwp_0d=var_realwp_0d_pointer, return_value=output_return_value )
    29243005            ELSEIF ( PRESENT( var_realwp_1d ) )  THEN
    29253006               CALL binary_write_variable( file_id, var_id,                                      &
    29263007                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2927                        var_realwp_1d=var_realwp_1d_pointer, return_value=return_value )
     3008                       var_realwp_1d=var_realwp_1d_pointer, return_value=output_return_value )
    29283009            ELSEIF ( PRESENT( var_realwp_2d ) )  THEN
    29293010               CALL binary_write_variable( file_id, var_id,                                      &
    29303011                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2931                        var_realwp_2d=var_realwp_2d_pointer, return_value=return_value )
     3012                       var_realwp_2d=var_realwp_2d_pointer, return_value=output_return_value )
    29323013            ELSEIF ( PRESENT( var_realwp_3d ) )  THEN
    29333014               CALL binary_write_variable( file_id, var_id,                                      &
    29343015                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2935                        var_realwp_3d=var_realwp_3d_pointer, return_value=return_value )
     3016                       var_realwp_3d=var_realwp_3d_pointer, return_value=output_return_value )
    29363017            ELSE
    29373018               return_value = 1
    2938                CALL internal_message( 'error', routine_name //                                    &
    2939                                                ': variable "' // TRIM( name ) //                  &
    2940                                                '" in file "' // TRIM( filename ) //               &
    2941                                                '": output_type not supported by file format "' // &
    2942                                                TRIM( file_format ) // '"' )
     3019               CALL internal_message( 'error', routine_name //                           &
     3020                                      ': variable "' // TRIM( name ) //                  &
     3021                                      '" in file "' // TRIM( filename ) //               &
     3022                                      '": output_type not supported by file format "' // &
     3023                                      TRIM( file_format ) // '"' )
    29433024            ENDIF
    29443025
    2945          CASE ( 'netcdf4-serial' )
     3026         CASE ( 'netcdf4-parallel', 'netcdf4-serial' )
    29463027            !-- 8bit integer output
    29473028            IF ( PRESENT( var_int8_0d ) )  THEN
    2948                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2949                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2950                        var_int8_0d=var_int8_0d_pointer, return_value=return_value )
     3029               CALL netcdf4_write_variable( file_id, var_id,                              &
     3030                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3031                       var_int8_0d=var_int8_0d_pointer, return_value=output_return_value )
    29513032            ELSEIF ( PRESENT( var_int8_1d ) )  THEN
    2952                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2953                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2954                        var_int8_1d=var_int8_1d_pointer, return_value=return_value )
     3033               CALL netcdf4_write_variable( file_id, var_id,                              &
     3034                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3035                       var_int8_1d=var_int8_1d_pointer, return_value=output_return_value )
    29553036            ELSEIF ( PRESENT( var_int8_2d ) )  THEN
    2956                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2957                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2958                        var_int8_2d=var_int8_2d_pointer, return_value=return_value )
     3037               CALL netcdf4_write_variable( file_id, var_id,                              &
     3038                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3039                       var_int8_2d=var_int8_2d_pointer, return_value=output_return_value )
    29593040            ELSEIF ( PRESENT( var_int8_3d ) )  THEN
    2960                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2961                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2962                        var_int8_3d=var_int8_3d_pointer, return_value=return_value )
     3041               CALL netcdf4_write_variable( file_id, var_id,                              &
     3042                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3043                       var_int8_3d=var_int8_3d_pointer, return_value=output_return_value )
    29633044            !-- 16bit integer output
    29643045            ELSEIF ( PRESENT( var_int16_0d ) )  THEN
    2965                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2966                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2967                        var_int16_0d=var_int16_0d_pointer, return_value=return_value )
     3046               CALL netcdf4_write_variable( file_id, var_id,                              &
     3047                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3048                       var_int16_0d=var_int16_0d_pointer, return_value=output_return_value )
    29683049            ELSEIF ( PRESENT( var_int16_1d ) )  THEN
    2969                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2970                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2971                        var_int16_1d=var_int16_1d_pointer, return_value=return_value )
     3050               CALL netcdf4_write_variable( file_id, var_id,                              &
     3051                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3052                       var_int16_1d=var_int16_1d_pointer, return_value=output_return_value )
    29723053            ELSEIF ( PRESENT( var_int16_2d ) )  THEN
    2973                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2974                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2975                        var_int16_2d=var_int16_2d_pointer, return_value=return_value )
     3054               CALL netcdf4_write_variable( file_id, var_id,                              &
     3055                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3056                       var_int16_2d=var_int16_2d_pointer, return_value=output_return_value )
    29763057            ELSEIF ( PRESENT( var_int16_3d ) )  THEN
    2977                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2978                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2979                        var_int16_3d=var_int16_3d_pointer, return_value=return_value )
     3058               CALL netcdf4_write_variable( file_id, var_id,                              &
     3059                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3060                       var_int16_3d=var_int16_3d_pointer, return_value=output_return_value )
    29803061            !-- 32bit integer output
    29813062            ELSEIF ( PRESENT( var_int32_0d ) )  THEN
    2982                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2983                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2984                        var_int32_0d=var_int32_0d_pointer, return_value=return_value )
     3063               CALL netcdf4_write_variable( file_id, var_id,                              &
     3064                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3065                       var_int32_0d=var_int32_0d_pointer, return_value=output_return_value )
    29853066            ELSEIF ( PRESENT( var_int32_1d ) )  THEN
    2986                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2987                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2988                        var_int32_1d=var_int32_1d_pointer, return_value=return_value )
     3067               CALL netcdf4_write_variable( file_id, var_id,                              &
     3068                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3069                       var_int32_1d=var_int32_1d_pointer, return_value=output_return_value )
    29893070            ELSEIF ( PRESENT( var_int32_2d ) )  THEN
    2990                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2991                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2992                        var_int32_2d=var_int32_2d_pointer, return_value=return_value )
     3071               CALL netcdf4_write_variable( file_id, var_id,                              &
     3072                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3073                       var_int32_2d=var_int32_2d_pointer, return_value=output_return_value )
    29933074            ELSEIF ( PRESENT( var_int32_3d ) )  THEN
    2994                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    2995                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    2996                        var_int32_3d=var_int32_3d_pointer, return_value=return_value )
     3075               CALL netcdf4_write_variable( file_id, var_id,                              &
     3076                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3077                       var_int32_3d=var_int32_3d_pointer, return_value=output_return_value )
    29973078            !-- working-precision integer output
    29983079            ELSEIF ( PRESENT( var_intwp_0d ) )  THEN
    2999                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3000                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3001                        var_intwp_0d=var_intwp_0d_pointer, return_value=return_value )
     3080               CALL netcdf4_write_variable( file_id, var_id,                              &
     3081                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3082                       var_intwp_0d=var_intwp_0d_pointer, return_value=output_return_value )
    30023083            ELSEIF ( PRESENT( var_intwp_1d ) )  THEN
    3003                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3004                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3005                        var_intwp_1d=var_intwp_1d_pointer, return_value=return_value )
     3084               CALL netcdf4_write_variable( file_id, var_id,                              &
     3085                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3086                       var_intwp_1d=var_intwp_1d_pointer, return_value=output_return_value )
    30063087            ELSEIF ( PRESENT( var_intwp_2d ) )  THEN
    3007                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3008                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3009                        var_intwp_2d=var_intwp_2d_pointer, return_value=return_value )
     3088               CALL netcdf4_write_variable( file_id, var_id,                              &
     3089                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3090                       var_intwp_2d=var_intwp_2d_pointer, return_value=output_return_value )
    30103091            ELSEIF ( PRESENT( var_intwp_3d ) )  THEN
    3011                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3012                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3013                        var_intwp_3d=var_intwp_3d_pointer, return_value=return_value )
     3092               CALL netcdf4_write_variable( file_id, var_id,                              &
     3093                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3094                       var_intwp_3d=var_intwp_3d_pointer, return_value=output_return_value )
    30143095            !-- 32bit real output
    30153096            ELSEIF ( PRESENT( var_real32_0d ) )  THEN
    3016                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3017                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3018                        var_real32_0d=var_real32_0d_pointer, return_value=return_value )
     3097               CALL netcdf4_write_variable( file_id, var_id,                              &
     3098                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3099                       var_real32_0d=var_real32_0d_pointer, return_value=output_return_value )
    30193100            ELSEIF ( PRESENT( var_real32_1d ) )  THEN
    3020                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3021                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3022                        var_real32_1d=var_real32_1d_pointer, return_value=return_value )
     3101               CALL netcdf4_write_variable( file_id, var_id,                              &
     3102                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3103                       var_real32_1d=var_real32_1d_pointer, return_value=output_return_value )
    30233104            ELSEIF ( PRESENT( var_real32_2d ) )  THEN
    3024                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3025                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3026                        var_real32_2d=var_real32_2d_pointer, return_value=return_value )
     3105               CALL netcdf4_write_variable( file_id, var_id,                              &
     3106                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3107                       var_real32_2d=var_real32_2d_pointer, return_value=output_return_value )
    30273108            ELSEIF ( PRESENT( var_real32_3d ) )  THEN
    3028                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3029                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3030                        var_real32_3d=var_real32_3d_pointer, return_value=return_value )
     3109               CALL netcdf4_write_variable( file_id, var_id,                              &
     3110                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3111                       var_real32_3d=var_real32_3d_pointer, return_value=output_return_value )
    30313112            !-- 64bit real output
    30323113            ELSEIF ( PRESENT( var_real64_0d ) )  THEN
    3033                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3034                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3035                        var_real64_0d=var_real64_0d_pointer, return_value=return_value )
     3114               CALL netcdf4_write_variable( file_id, var_id,                              &
     3115                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3116                       var_real64_0d=var_real64_0d_pointer, return_value=output_return_value )
    30363117            ELSEIF ( PRESENT( var_real64_1d ) )  THEN
    3037                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3038                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3039                        var_real64_1d=var_real64_1d_pointer, return_value=return_value )
     3118               CALL netcdf4_write_variable( file_id, var_id,                              &
     3119                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3120                       var_real64_1d=var_real64_1d_pointer, return_value=output_return_value )
    30403121            ELSEIF ( PRESENT( var_real64_2d ) )  THEN
    3041                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3042                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3043                        var_real64_2d=var_real64_2d_pointer, return_value=return_value )
     3122               CALL netcdf4_write_variable( file_id, var_id,                              &
     3123                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3124                       var_real64_2d=var_real64_2d_pointer, return_value=output_return_value )
    30443125            ELSEIF ( PRESENT( var_real64_3d ) )  THEN
    3045                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3046                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3047                        var_real64_3d=var_real64_3d_pointer, return_value=return_value )
     3126               CALL netcdf4_write_variable( file_id, var_id,                              &
     3127                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3128                       var_real64_3d=var_real64_3d_pointer, return_value=output_return_value )
    30483129            !-- working-precision real output
    30493130            ELSEIF ( PRESENT( var_realwp_0d ) )  THEN
    3050                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3051                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3052                        var_realwp_0d=var_realwp_0d_pointer, return_value=return_value )
     3131               CALL netcdf4_write_variable( file_id, var_id,                              &
     3132                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3133                       var_realwp_0d=var_realwp_0d_pointer, return_value=output_return_value )
    30533134            ELSEIF ( PRESENT( var_realwp_1d ) )  THEN
    3054                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3055                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3056                        var_realwp_1d=var_realwp_1d_pointer, return_value=return_value )
     3135               CALL netcdf4_write_variable( file_id, var_id,                              &
     3136                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3137                       var_realwp_1d=var_realwp_1d_pointer, return_value=output_return_value )
    30573138            ELSEIF ( PRESENT( var_realwp_2d ) )  THEN
    3058                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3059                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3060                        var_realwp_2d=var_realwp_2d_pointer, return_value=return_value )
     3139               CALL netcdf4_write_variable( file_id, var_id,                              &
     3140                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3141                       var_realwp_2d=var_realwp_2d_pointer, return_value=output_return_value )
    30613142            ELSEIF ( PRESENT( var_realwp_3d ) )  THEN
    3062                CALL netcdf4_serial_write_variable( file_id, var_id,                              &
    3063                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3064                        var_realwp_3d=var_realwp_3d_pointer, return_value=return_value )
     3143               CALL netcdf4_write_variable( file_id, var_id,                              &
     3144                       bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
     3145                       var_realwp_3d=var_realwp_3d_pointer, return_value=output_return_value )
    30653146            ELSE
    30663147               return_value = 1
    3067                CALL internal_message( 'error', routine_name //                                    &
    3068                                                ': variable "' // TRIM( name ) //                  &
    3069                                                '" in file "' // TRIM( filename ) //               &
    3070                                                '": output_type not supported by file format "' // &
    3071                                                TRIM( file_format ) // '"' )
    3072             ENDIF
    3073 
    3074          CASE ( 'netcdf4-parallel' )
    3075             !-- 8bit integer output
    3076             IF ( PRESENT( var_int8_0d ) )  THEN
    3077                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3078                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3079                        var_int8_0d=var_int8_0d_pointer, return_value=return_value )
    3080             ELSEIF ( PRESENT( var_int8_1d ) )  THEN
    3081                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3082                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3083                        var_int8_1d=var_int8_1d_pointer, return_value=return_value )
    3084             ELSEIF ( PRESENT( var_int8_2d ) )  THEN
    3085                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3086                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3087                        var_int8_2d=var_int8_2d_pointer, return_value=return_value )
    3088             ELSEIF ( PRESENT( var_int8_3d ) )  THEN
    3089                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3090                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3091                        var_int8_3d=var_int8_3d_pointer, return_value=return_value )
    3092             !-- 16bit integer output
    3093             ELSEIF ( PRESENT( var_int16_0d ) )  THEN
    3094                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3095                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3096                        var_int16_0d=var_int16_0d_pointer, return_value=return_value )
    3097             ELSEIF ( PRESENT( var_int16_1d ) )  THEN
    3098                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3099                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3100                        var_int16_1d=var_int16_1d_pointer, return_value=return_value )
    3101             ELSEIF ( PRESENT( var_int16_2d ) )  THEN
    3102                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3103                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3104                        var_int16_2d=var_int16_2d_pointer, return_value=return_value )
    3105             ELSEIF ( PRESENT( var_int16_3d ) )  THEN
    3106                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3107                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3108                        var_int16_3d=var_int16_3d_pointer, return_value=return_value )
    3109             !-- 32bit integer output
    3110             ELSEIF ( PRESENT( var_int32_0d ) )  THEN
    3111                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3112                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3113                        var_int32_0d=var_int32_0d_pointer, return_value=return_value )
    3114             ELSEIF ( PRESENT( var_int32_1d ) )  THEN
    3115                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3116                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3117                        var_int32_1d=var_int32_1d_pointer, return_value=return_value )
    3118             ELSEIF ( PRESENT( var_int32_2d ) )  THEN
    3119                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3120                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3121                        var_int32_2d=var_int32_2d_pointer, return_value=return_value )
    3122             ELSEIF ( PRESENT( var_int32_3d ) )  THEN
    3123                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3124                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3125                        var_int32_3d=var_int32_3d_pointer, return_value=return_value )
    3126             !-- working-precision integer output
    3127             ELSEIF ( PRESENT( var_intwp_0d ) )  THEN
    3128                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3129                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3130                        var_intwp_0d=var_intwp_0d_pointer, return_value=return_value )
    3131             ELSEIF ( PRESENT( var_intwp_1d ) )  THEN
    3132                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3133                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3134                        var_intwp_1d=var_intwp_1d_pointer, return_value=return_value )
    3135             ELSEIF ( PRESENT( var_intwp_2d ) )  THEN
    3136                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3137                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3138                        var_intwp_2d=var_intwp_2d_pointer, return_value=return_value )
    3139             ELSEIF ( PRESENT( var_intwp_3d ) )  THEN
    3140                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3141                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3142                        var_intwp_3d=var_intwp_3d_pointer, return_value=return_value )
    3143             !-- 32bit real output
    3144             ELSEIF ( PRESENT( var_real32_0d ) )  THEN
    3145                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3146                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3147                        var_real32_0d=var_real32_0d_pointer, return_value=return_value )
    3148             ELSEIF ( PRESENT( var_real32_1d ) )  THEN
    3149                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3150                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3151                        var_real32_1d=var_real32_1d_pointer, return_value=return_value )
    3152             ELSEIF ( PRESENT( var_real32_2d ) )  THEN
    3153                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3154                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3155                        var_real32_2d=var_real32_2d_pointer, return_value=return_value )
    3156             ELSEIF ( PRESENT( var_real32_3d ) )  THEN
    3157                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3158                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3159                        var_real32_3d=var_real32_3d_pointer, return_value=return_value )
    3160             !-- 64bit real output
    3161             ELSEIF ( PRESENT( var_real64_0d ) )  THEN
    3162                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3163                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3164                        var_real64_0d=var_real64_0d_pointer, return_value=return_value )
    3165             ELSEIF ( PRESENT( var_real64_1d ) )  THEN
    3166                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3167                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3168                        var_real64_1d=var_real64_1d_pointer, return_value=return_value )
    3169             ELSEIF ( PRESENT( var_real64_2d ) )  THEN
    3170                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3171                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3172                        var_real64_2d=var_real64_2d_pointer, return_value=return_value )
    3173             ELSEIF ( PRESENT( var_real64_3d ) )  THEN
    3174                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3175                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3176                        var_real64_3d=var_real64_3d_pointer, return_value=return_value )
    3177             !-- working-precision real output
    3178             ELSEIF ( PRESENT( var_realwp_0d ) )  THEN
    3179                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3180                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3181                        var_realwp_0d=var_realwp_0d_pointer, return_value=return_value )
    3182             ELSEIF ( PRESENT( var_realwp_1d ) )  THEN
    3183                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3184                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3185                        var_realwp_1d=var_realwp_1d_pointer, return_value=return_value )
    3186             ELSEIF ( PRESENT( var_realwp_2d ) )  THEN
    3187                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3188                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3189                        var_realwp_2d=var_realwp_2d_pointer, return_value=return_value )
    3190             ELSEIF ( PRESENT( var_realwp_3d ) )  THEN
    3191                CALL netcdf4_parallel_write_variable( file_id, var_id,                            &
    3192                        bounds_start_new, bounds_end_new, bounds_dim_start, do_output, is_global, &
    3193                        var_realwp_3d=var_realwp_3d_pointer, return_value=return_value )
    3194             ELSE
    3195                return_value = 1
    3196                CALL internal_message( 'error', routine_name //                                    &
    3197                                                ': variable "' // TRIM( name ) //                  &
    3198                                                '" in file "' // TRIM( filename ) //               &
    3199                                                '": output_type not supported by file format "' // &
    3200                                                TRIM( file_format ) // '"' )
     3148               CALL internal_message( 'error', routine_name //                           &
     3149                                      ': variable "' // TRIM( name ) //                  &
     3150                                      '" in file "' // TRIM( filename ) //               &
     3151                                      '": output_type not supported by file format "' // &
     3152                                      TRIM( file_format ) // '"' )
    32013153            ENDIF
    32023154
     
    32103162      END SELECT
    32113163
     3164      IF ( return_value == 0  .AND.  output_return_value /= 0 )  THEN
     3165         return_value = 1
     3166         CALL internal_message( 'error', routine_name //                              &
     3167                                ': error while writing variable "' // TRIM( name ) // &
     3168                                '" in file "' // TRIM( filename ) // '"' )
     3169      ENDIF
     3170
    32123171   ENDIF
    32133172
     
    32483207   DO  f = 1, nf
    32493208      IF ( TRIM( filename ) == TRIM( files(f)%name ) )  THEN
     3209         
     3210         IF ( .NOT. files(f)%is_init )  THEN
     3211            return_value = 1
     3212            CALL internal_message( 'error', routine_name //                    &
     3213                                   ': file "' // TRIM( filename ) //           &
     3214                                   '" is not initialized. ' //                 &
     3215                                   'Writing variable "' // TRIM( var_name ) // &
     3216                                   '" to file is impossible.' )
     3217            EXIT
     3218         ENDIF
     3219         
    32503220         file_id     = files(f)%id
    32513221         file_format = files(f)%format
     
    34213391
    34223392   INTEGER(iwp) ::  return_value           !< return value
    3423    INTEGER(iwp) ::  return_value_internal  !< return value from called routines
     3393   INTEGER(iwp) ::  return_value_internal  !< error code after closing a single file
     3394   INTEGER(iwp) ::  output_return_value    !< return value from called routines
    34243395   INTEGER(iwp) ::  f                      !< loop index
    34253396
     
    34293400   DO  f = 1, nf
    34303401
    3431       return_value_internal = 0
    3432 
    3433       SELECT CASE ( TRIM( files(f)%format ) )
    3434 
    3435          CASE ( 'binary' )
    3436             CALL binary_finalize( files(f)%id, return_value_internal )
    3437 
    3438          CASE ( 'netcdf4-serial' )
    3439             CALL netcdf4_serial_finalize( files(f)%id, return_value_internal )
    3440 
    3441          CASE ( 'netcdf4-parallel' )
    3442             CALL netcdf4_parallel_finalize( files(f)%id, return_value_internal )
    3443 
    3444          CASE DEFAULT
    3445             return_value_internal = 1
    3446             CALL internal_message( 'error', routine_name // &
    3447                                    ': unsupported file format "' // TRIM( files(f)%format ) )
    3448 
    3449       END SELECT
    3450 
    3451       IF ( return_value_internal /= 0 )  return_value = return_value_internal
     3402      IF ( files(f)%is_init )  THEN
     3403
     3404         output_return_value = 0
     3405         return_value_internal = 0
     3406
     3407         SELECT CASE ( TRIM( files(f)%format ) )
     3408
     3409            CASE ( 'binary' )
     3410               CALL binary_finalize( files(f)%id, output_return_value )
     3411
     3412            CASE ( 'netcdf4-parallel', 'netcdf4-serial' )
     3413               CALL netcdf4_finalize( files(f)%id, output_return_value )
     3414
     3415            CASE DEFAULT
     3416               return_value_internal = 1
     3417
     3418         END SELECT
     3419
     3420         IF ( output_return_value /= 0 )  THEN
     3421            return_value = output_return_value
     3422            CALL internal_message( 'error', routine_name //             &
     3423                                   ': error while finalizing file "' // &
     3424                                   TRIM( files(f)%name ) // '"' )
     3425         ELSEIF ( return_value_internal /= 0 )  THEN
     3426            return_value = return_value_internal
     3427            CALL internal_message( 'error', routine_name //         &
     3428                                   ': unsupported file format "' // &
     3429                                   TRIM( files(f)%format ) // '"' )
     3430         ENDIF
     3431
     3432      ENDIF
    34523433
    34533434   ENDDO
     
    34883469
    34893470   CHARACTER(LEN=800), INTENT(OUT) ::  error_message         !< return error message to main program
    3490    CHARACTER(LEN=800)              ::  module_error_message  !< error message created by other module
    3491 
    3492 
    3493    CALL binary_get_error_message( module_error_message )
    3494    internal_error_message = TRIM( internal_error_message ) // module_error_message
    3495 
    3496    CALL netcdf4_serial_get_error_message( module_error_message )
    3497    internal_error_message = TRIM( internal_error_message ) // module_error_message
    3498 
    3499    CALL netcdf4_parallel_get_error_message( module_error_message )
    3500    internal_error_message = TRIM( internal_error_message ) // module_error_message
     3471   CHARACTER(LEN=800)              ::  output_error_message  !< error message created by other module
     3472
     3473
     3474   CALL binary_get_error_message( output_error_message )
     3475   internal_error_message = TRIM( internal_error_message ) // output_error_message
     3476
     3477   CALL netcdf4_get_error_message( output_error_message )
     3478   internal_error_message = TRIM( internal_error_message ) // output_error_message
    35013479
    35023480   error_message = internal_error_message
Note: See TracChangeset for help on using the changeset viewer.