Index: palm/trunk/UTIL/Makefile_utilities
===================================================================
--- palm/trunk/UTIL/Makefile_utilities	(revision 3499)
+++ palm/trunk/UTIL/Makefile_utilities	(revision 3523)
@@ -23,4 +23,8 @@
 # -----------------
 # $Id$
+# Enable compilation of post-processing tool for surface output - interface
+# for posix conform sytemcalls is implemented.
+# 
+# 3499 2018-11-07 10:55:15Z suehring
 # Temporarily avoid compilation of post-processing tool for surface output
 # until a workaround for compiler-specific intrinsic functions is found.
@@ -61,10 +65,10 @@
 PROG2 =  compare_palm_logs.x
 PROG3 =  agent_preprocessing
-#PROG4 =  surface_output_to_vtk
+PROG4 =  surface_output_to_vtk
 
 OBJS1 =  combine_plot_fields.o
 OBJS2 =  compare_palm_logs.o
 OBJS3 =  agent_preprocessing.o
-#OBJS4 =  surface_output_to_vtk.o
+OBJS4 =  surface_output_to_vtk.o
 
 CC = cc
@@ -91,6 +95,6 @@
 	$(F90_SER) -o $(PROG3) $(OBJS3) $(LDFLAGS)
 
-#$(PROG4): $(OBJS4)
-#	$(F90_SER) -o $(PROG4) $(OBJS4) $(LDFLAGS)
+$(PROG4): $(OBJS4)
+	$(F90_SER) -o $(PROG4) $(OBJS4) $(LDFLAGS)
 
 .f90.o:
Index: palm/trunk/UTIL/surface_output_processing/surface_output_to_vtk.f90
===================================================================
--- palm/trunk/UTIL/surface_output_processing/surface_output_to_vtk.f90	(revision 3499)
+++ palm/trunk/UTIL/surface_output_processing/surface_output_to_vtk.f90	(revision 3523)
@@ -25,4 +25,8 @@
 ! -----------------
 ! $Id$
+! Implement interface for posix conform C-systemcalls in order to replace
+! non-standard FORTRAN functions ftell and fseek. 
+! 
+! 3496 2018-11-06 15:59:50Z suehring
 ! Use subroutine call for fseek instead of function call. gfortran has some
 ! problems with this.
@@ -34,4 +38,91 @@
 ! --------
 ! @author Matthias Suehring and Klaus Ketelsen
+!
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Interface to posix systemcalls. The module allows to call the following
+!> C system calls from FORTRAN: ftell, lseek.
+!------------------------------------------------------------------------------!
+ MODULE posix_interface
+ 
+    INTERFACE
+       INTEGER (C_SIZE_T) FUNCTION C_LSEEK (fd, offset, whence)                &
+                                   BIND(C, NAME='lseek')
+          
+          USE ISO_C_BINDING
+          
+          IMPLICIT NONE
+          
+          INTEGER(KIND=C_INT),    VALUE ::  fd
+          INTEGER(KIND=C_SIZE_T), VALUE ::  offset
+          INTEGER(KIND=C_INT),    VALUE ::  whence
+          
+       END FUNCTION C_LSEEK
+       
+    END INTERFACE
+    
+    INTERFACE
+       INTEGER (C_SIZE_T) FUNCTION C_FTELL ( fd )                              &
+                                   BIND(C, NAME='ftell')
+          
+          USE ISO_C_BINDING
+          
+          IMPLICIT NONE
+          
+          INTEGER(KIND=C_INT),    VALUE ::  fd
+
+       END FUNCTION C_FTELL
+       
+    END INTERFACE
+    
+    PUBLIC posix_lseek, posix_ftell
+    
+    CONTAINS
+!
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Interface for the C-routine lseek. 
+!------------------------------------------------------------------------------! 
+    SUBROUTINE posix_lseek( fid, offset )
+    
+       USE ISO_C_BINDING
+    
+       IMPLICIT NONE
+
+       INTEGER,INTENT(IN)                     ::  fid    !< file unit
+       INTEGER(KIND=C_SIZE_T),INTENT(IN)      ::  offset !< file offset from the beginning
+
+       INTEGER(KIND=C_INT)                    ::  my_fid !< file unit
+       INTEGER(KIND=C_SIZE_T)                 ::  retval !< return value
+       INTEGER(KIND=C_INT)                    ::  whence !< mode, here start from the beginning
+
+       my_fid = fid
+       whence = 0
+
+       retval = C_LSEEK( fid, offset, whence )
+       
+    END SUBROUTINE posix_lseek
+!
+!------------------------------------------------------------------------------!
+! Description:
+! ------------
+!> Interface for the C-routine ftell. 
+!------------------------------------------------------------------------------!
+    SUBROUTINE posix_ftell( fid, filepos )
+    
+       USE ISO_C_BINDING
+    
+       IMPLICIT NONE
+
+       INTEGER,INTENT(IN)      ::  fid                     !< file unit
+       INTEGER(KIND=C_SIZE_T), INTENT(INOUT)   ::  filepos !< file position
+
+       filepos = C_FTELL( fid )
+       
+    END SUBROUTINE posix_ftell
+
+ END MODULE posix_interface
 !
 !------------------------------------------------------------------------------!
@@ -45,37 +136,40 @@
 !------------------------------------------------------------------------------!
  PROGRAM surface_output_to_vtk
+ 
+    USE, INTRINSIC ::  ISO_C_BINDING
+ 
+    USE posix_interface,                                                       &
+        ONLY:  posix_ftell, posix_lseek
 
     IMPLICIT NONE
     
-    CHARACTER(LEN=4)   ::  char_time            !< string indicating simulated time
-    CHARACTER(LEN=4)   ::  file_suffix = '.bin' !< string which contain the suffix indicating surface data
-    
-    CHARACTER(LEN=10)  ::  char_dum             !< dummy string
-    
-    CHARACTER(LEN=30)  ::  myid_char            !< combined string indicating binary file
-    
-    CHARACTER(LEN=100) ::  path                 !< path to the binary data 
-    CHARACTER(LEN=100) ::  run                  !< name of the run
-    CHARACTER(LEN=100) ::  variable_name        !< name of the processed output variable    
-    
-    INTEGER(4)   ::  ftell                      !< intrinsic function, get current position in file
-!     INTEGER(4)   ::  fseek                      !< intrinsic function, go to given position in file
-    INTEGER(4)   ::  ndum                       !< return parameter of intrinsic function fseek
-    
-    INTEGER, PARAMETER ::  iwp = 4              !< integer precision
-    INTEGER, PARAMETER ::  wp  = 8              !< float precision
-    
-    INTEGER(iwp) ::  cycle_number               !< cycle number
-    INTEGER(iwp) ::  f                          !< running index over all binary files
-    INTEGER(iwp) ::  file_id_in = 18            !< file unit for input binaray file    
-    INTEGER(iwp) ::  file_id_out = 20           !< file unit for output VTK file        
-    INTEGER(iwp) ::  file_id_out_header = 19    !< file unit for temporary header file
-    INTEGER(iwp) ::  length                     !< length of string on file
-    INTEGER(iwp) ::  n                          !< running index over all points and polygons
-    INTEGER(iwp) ::  npoints_total              !< total number of points
-    INTEGER(iwp) ::  ns_total                   !< total number of polygons
-    INTEGER(iwp) ::  num_pe                     !< number of processors of the run
-    
-    INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  filepos !< current fileposition in binary file
+    CHARACTER(LEN=4)   ::  char_time              !< string indicating simulated time
+    CHARACTER(LEN=4)   ::  file_suffix = '.bin'   !< string which contain the suffix indicating surface data
+    
+    CHARACTER(LEN=10)  ::  char_dum               !< dummy string
+    
+    CHARACTER(LEN=30)  ::  myid_char              !< combined string indicating binary file
+    
+    CHARACTER(LEN=100) ::  path                   !< path to the binary data 
+    CHARACTER(LEN=100) ::  run                    !< name of the run
+    CHARACTER(LEN=100) ::  variable_name          !< name of the processed output variable    
+       
+    INTEGER, PARAMETER ::  iwp = 4                !< integer precision
+    INTEGER, PARAMETER ::  wp  = 8                !< float precision
+    INTEGER, PARAMETER ::  OFFSET_KIND = C_SIZE_T !< unsigned integer for the C-interface
+    
+    INTEGER(iwp) ::  cycle_number                 !< cycle number
+    INTEGER(iwp) ::  f                            !< running index over all binary files
+    INTEGER(iwp) ::  file_id_in = 18              !< file unit for input binaray file    
+    INTEGER(iwp) ::  file_id_out = 20             !< file unit for output VTK file        
+    INTEGER(iwp) ::  file_id_out_header = 19      !< file unit for temporary header file
+    INTEGER(iwp) ::  length                       !< length of string on file
+    INTEGER(iwp) ::  n                            !< running index over all points and polygons
+    INTEGER(iwp) ::  npoints_total                !< total number of points
+    INTEGER(iwp) ::  ns_total                     !< total number of polygons
+    INTEGER(iwp) ::  num_pe                       !< number of processors of the run
+    
+    INTEGER(OFFSET_KIND),DIMENSION(:), ALLOCATABLE ::  filepos !< current fileposition in binary file
+    
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  npoints !< number of points/vertices in a binaray file
     INTEGER(iwp), DIMENSION(:), ALLOCATABLE ::  ns      !< number of surface elements in a binaray file 
@@ -148,6 +242,5 @@
 !
 !--    Obtain current file position. Will be stored for next file opening.
-       filepos(f) = ftell( file_id_in )
-!        CALL FTELL( file_id_in, filepos(f) )
+       CALL posix_ftell( file_id_in, filepos(f) )
 !
 !--    Write header information. Only one time required.
@@ -183,6 +276,5 @@
 !
 !--    Move to last postion. 
-!        ndum = fseek( file_id_in, filepos(f), 0 )
-       CALL FSEEK( file_id_in, filepos(f), 0, ndum )
+       CALL posix_lseek( file_id_in, filepos(f) )
 !
 !--    Allocate array for polygon data
@@ -194,6 +286,5 @@
 !--    Obtain current file position after reading the local polygon data. 
 !--    Will be used for next file opening.
-       filepos(f) = ftell( file_id_in )
-!        CALL FTELL( file_id_in, filepos(f) )
+       CALL posix_ftell( file_id_in, filepos(f) )
 !
 !--    Write further header information. Only one time required.
@@ -254,5 +345,6 @@
 !--       Move to last postion. 
 !           ndum = fseek( file_id_in, filepos(f), 0 )
-          CALL FSEEK( file_id_in, filepos(f), 0, ndum )
+          CALL posix_lseek( file_id_in, filepos(f) )
+!           CALL FSEEK( file_id_in, filepos(f), 0, ndum )
 !
 !--       Read string length and string indicating the output time step. 
@@ -317,6 +409,5 @@
 !
 !--       Remember file position in binary file and close it.
-          filepos(f) = ftell( file_id_in )
-!           CALL FTELL( file_id_in, filepos(f) )
+          CALL posix_ftell( file_id_in, filepos(f) )
        
           CLOSE ( file_id_in )
