Quantcast
Channel: Recent posts
Viewing all articles
Browse latest Browse all 415

C call Fortran function with optional argument

$
0
0

Hi! I have interoperable  Fortran code that C can call ODRPACK95. At least it works without passing optional argument from C. And now is it possbile way to pass optional argument from C?

Fortran code:

subroutine wrapper_ODR(FCN,N,M,NP,NQ,BETA,Y,X,&
        DELTA,WE,WD,IFIXB,IFIXX,JOB,NDIGIT,TAUFAC,&
        SSTOL,PARTOL,MAXIT,IPRINT,LUNERR,LUNRPT,&
     STPB,STPD,SCLB,SCLD,WORK,IWORK,INFO,LOWER,UPPER) bind(C, name='wrapper_ODR')
!DEC$ ATTRIBUTES DLLEXPORT :: wrapper_ODR
    use iso_c_binding
    use ODRPACK95
    implicit none

    interface
        subroutine FCN(N,M,NP,NQ,LDN,LDM,LDNP,BETA,XPLUSD,IFIXB,IFIXX,LDIFX,&
        IDEVAL,F,FJACB,FJACD,ISTOP) bind(C)

        use, intrinsic :: iso_c_binding
        implicit none

        integer(c_int) :: IDEVAL,ISTOP,LDIFX,LDM,LDN,LDNP,M,N,NP,NQ

        real (c_double) :: BETA(1:NP),F(1:LDN,1:NQ),FJACB(1:LDN,1:LDNP,1:NQ), &
        FJACD(1:LDN,1:LDM,1:NQ),XPLUSD(1:LDN,1:M)

        integer(c_int) :: IFIXB(1:NP),IFIXX(1:LDIFX,1:M)

        end subroutine
    end interface

    integer(c_int),value :: N,M,NP,NQ
    real(c_double) :: BETA(1:NP),Y(1:N,1:NQ),X(1:N,1:M)

!!!!!Optional variable
    !!!!!!!!Unfinished
    !
    !integer(c_int), optional :: IFIXB(:),IFIXX(:,:),JOB,NDIGIT,MAXIT&
    !,IPRINT,LUNERR,LUNRPT,INFO
    !
    !real(c_double),  optional :: WE(:,:,:),WD(:,:,:),&
    !    TAUFAC,SSTOL,PARTOL,STPB(:),STPD(:,:),&
    !    SCLB(:),SCLD(:,:),LOWER(:),UPPER(:)
    !
    ! integer(c_int), optional,pointer :: IWORK(:)
    !real(c_double), optional, pointer :: DELTA(:,:),WORK(:)

!!!!!Call ODR
    call ODR(FCN,N,M,NP,NQ,BETA,Y,X,&
        DELTA,WE,WD,IFIXB,IFIXX,JOB,NDIGIT,TAUFAC,&
        SSTOL,PARTOL,MAXIT,IPRINT,LUNERR,LUNRPT,&
     STPB,STPD,SCLB,SCLD,WORK,IWORK,INFO,LOWER,UPPER)

end subroutine wrapper_ODR    

wrapper_ODR in C code:

wrapper_ODR(&FCN, N, M, NP, NQ, BETA, Y, X, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \
        NULL, NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL, NULL, \
        NULL, NULL);

 


Viewing all articles
Browse latest Browse all 415

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>