       MODULE InterfaceMicroscope
!*********************************************************************
      INTERFACE
        INTEGER(C_INT) FUNCTION toReadMicroscopeVector(&
&                      valuesC, values_size,&
&                      absdatesC, absdates_size,&
&                      datesC, dates_size,&
&                      absmaskC, absmask_size,&
&                      maskC, mask_size,&
&                      file_in)&
&                      BIND(C, name='toReadMicroscopeVector')
          USE, INTRINSIC :: ISO_C_BINDING
          IMPLICIT NONE
          TYPE(C_PTR) :: valuesC,absdatesC,datesC,absmaskC,maskC
          INTEGER(C_INT) :: values_size,absdates_size,dates_size,&
&                           absmask_size,mask_size
          CHARACTER(C_CHAR), DIMENSION(*) :: file_in
        END FUNCTION toReadMicroscopeVector
      END INTERFACE
!*********************************************************************
      INTERFACE
        INTEGER(C_INT) FUNCTION toWriteMicroscopeVector(&
&                      values, values_size,&
&                      dates, namec, maskname, dir)&
&                      BIND(C, name='toWriteMicroscopeVector')
          USE, INTRINSIC :: ISO_C_BINDING
          IMPLICIT NONE
          REAL(C_DOUBLE), DIMENSION(*) :: values
          INTEGER(C_INT), VALUE, INTENT(IN) :: values_size
          CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*) :: dates,&
&                                            namec,maskname,dir
        END FUNCTION toWriteMicroscopeVector
      END INTERFACE
!*********************************************************************
      INTERFACE
        INTEGER(C_INT) FUNCTION toWriteTest(&
&                      values, values_size,&
&                      dates, namec, maskname, dir)&
&                      BIND(C, name='toWriteTest')
          USE, INTRINSIC :: ISO_C_BINDING
          IMPLICIT NONE
          REAL(C_DOUBLE), DIMENSION(*) :: values
          INTEGER(C_INT), VALUE, INTENT(IN) :: values_size
          CHARACTER(LEN=1, KIND=C_CHAR), DIMENSION(*) :: dates,&
&                                            namec,maskname,dir
        END FUNCTION toWriteTest
      END INTERFACE
!*********************************************************************
      INTERFACE
        INTEGER(C_INT) FUNCTION toDeAllocateMicroscope(&
&                      valuesC, absdatesC, datesC, absmaskC, maskC)&
&                      BIND(C, name='toDeAllocateMicroscope')
          USE, INTRINSIC :: ISO_C_BINDING
          IMPLICIT NONE
          TYPE(C_PTR) :: valuesC,absdatesC,datesC,absmaskC,maskC
        END FUNCTION toDeAllocateMicroscope
      END INTERFACE
!*********************************************************************
      CONTAINS
!*********************************************************************
      FUNCTION ReadMicroscopeVector(values, values_size,&
&                                   absdates, absdates_size,&
&                                   dates, dates_size,&
&                                   absmask, absmask_size,&
&                                   mask, mask_size,&
&                                   file_in)
!
      USE, INTRINSIC :: ISO_C_BINDING
      IMPLICIT NONE
      INTEGER :: ReadMicroscopeVector
      INTEGER(C_INT) :: values_size,absdates_size,dates_size,&
&                       absmask_size,mask_size
      TYPE(C_PTR) :: valuesC,absdatesC,datesC,absmaskC,maskC
      REAL(C_DOUBLE), POINTER :: values(:) => NULL()
      CHARACTER(C_CHAR), POINTER :: absdates(:) => NULL()
      CHARACTER(C_CHAR), POINTER :: dates(:) => NULL()
      CHARACTER(C_CHAR), POINTER :: absmask(:) => NULL()
      CHARACTER(C_CHAR), POINTER :: mask(:) => NULL()
      CHARACTER(LEN=120) :: file_in
!
      file_in = TRIM(file_in) // C_NULL_CHAR
!

      ReadMicroscopeVector = toReadMicroscopeVector(&
&                            valuesC, values_size,&
&                            absdatesC, absdates_size,&
&                            datesC, dates_size,&
&                            absmaskC, absmask_size,&
&                            maskC, mask_size,&
&                            file_in)

      IF (ReadMicroscopeVector > 0)&
&        WRITE(*,*) "Call toReadMicroscopeVector error"
      CALL C_F_POINTER(valuesC, values, [values_size])
      CALL C_F_POINTER(absdatesC, absdates, [absdates_size])
      CALL C_F_POINTER(datesC, dates, [dates_size])
      CALL C_F_POINTER(absmaskC, absmask, [absmask_size])
      CALL C_F_POINTER(maskC, mask, [mask_size])
!
      END FUNCTION ReadMicroscopeVector
!*********************************************************************
      FUNCTION WriteMicroscopeVector(values, values_size, dates,&
&                                    mask, filename, filepath)
!
      USE, INTRINSIC :: ISO_C_BINDING
      IMPLICIT NONE
      INTEGER :: WriteMicroscopeVector
      INTEGER(C_INT) :: values_size
      REAL(C_DOUBLE), POINTER :: values(:)
      CHARACTER(C_CHAR), POINTER :: dates(:)
      CHARACTER(C_CHAR), POINTER :: mask(:)
      CHARACTER(LEN=120) :: filename,filepath
!
      filename = TRIM(filename) // C_NULL_CHAR
      filepath = TRIM(filepath) // C_NULL_CHAR
!

      WriteMicroscopeVector = toWriteMicroscopeVector(&
&               values, values_size, dates, mask, filename, filepath)

      IF (WriteMicroscopeVector > 0)&
&        WRITE(*,*) "Call toWriteMicroscopeVector error"
!
      WriteMicroscopeVector = toWriteTest(values, values_size,&
&                                    dates, mask, filename, filepath)
      IF (WriteMicroscopeVector > 0)&
&        WRITE(*,*) "Call toWriteTest error"
!
      END FUNCTION WriteMicroscopeVector
!*********************************************************************
      FUNCTION DeAllocateMicroscope(values, absdates, dates,&
&                                   absmask, mask)
!
      USE, INTRINSIC :: ISO_C_BINDING
      IMPLICIT NONE
      INTEGER :: DeAllocateMicroscope
      REAL(C_DOUBLE), POINTER :: values(:)
      CHARACTER(C_CHAR), POINTER :: absdates(:)
      CHARACTER(C_CHAR), POINTER :: dates(:)
      CHARACTER(C_CHAR), POINTER :: absmask(:)
      CHARACTER(C_CHAR), POINTER :: mask(:)
!

      DeAllocateMicroscope = toDeAllocateMicroscope(C_LOC(values(1)),&
&                            C_LOC(absdates(1)), C_LOC(dates(1)),&
&                            C_LOC(absmask(1)), C_LOC(mask(1)))

      IF (DeAllocateMicroscope > 0)&
&       WRITE(*,*) "Call toDeAllocateInC error"
!
      END FUNCTION DeAllocateMicroscope
!*********************************************************************
      end MODULE InterfaceMicroscope
