MODULE condiviso USE ISO_C_BINDING IMPLICIT NONE INTEGER(C_INT) :: quanti BIND(C, NAME='Conta') :: quanti END MODULE condiviso PROGRAM Calc_f ! ! Esempio di programma che richiama una procedura C ! USE condiviso IMPLICIT NONE REAL(C_DOUBLE), DIMENSION(:,:), ALLOCATABLE :: a, b INTEGER(C_INT) :: ld, ll INTEGER :: st INTERFACE SUBROUTINE calcola(a,b,ld,ll) BIND(C, NAME='Calc_c') USE, INTRINSIC :: ISO_C_BINDING IMPLICIT NONE INTEGER(C_INT), VALUE :: ld, ll REAL(C_DOUBLE), DIMENSION(ld,ll), INTENT(IN) :: b REAL(C_DOUBLE), DIMENSION(ld,ll) :: a END SUBROUTINE calcola END INTERFACE PRINT*,"ld, ll?" READ*,ld, ll ALLOCATE(a(ld,ll), b(ld,ll), STAT=st) IF ( st /= 0 ) THEN PRINT*,"Errore allocazione A(",ld,",",ll,"), B(",ld,",",ll,") " STOP ELSE PRINT*,"Allocati A(",ld,",",ll,"), B(",ld,",",ll,") " ENDIF quanti = 0 a(:,1) = 1; a(:,2) = 2; a(:,3) = 3 b(:,1) = .1; b(:,2) = .2; b(:,3) = .3 PRINT*,"A(:,:) [parziale] = ",a(1:MIN(10,ld),1:MIN(3,ll)) CALL calcola(a,b,ld,ll) PRINT*,"quante volte = ",quanti CALL calcola(a,b,ld,ll) PRINT*,"quante volte = ",quanti CALL calcola(a,b,ld,ll) PRINT*,"quante volte = ",quanti PRINT*,"A(:,:) [parziale] = ",a(1:MIN(10,ld),1:MIN(3,ll)) STOP END PROGRAM Calc_f