1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Is it possible to call Fortran function in C# using wrapper?

Discussion in 'C#' started by Achiever, Jul 18, 2017.

  1. #1
    Hello,

    I am looking for the building a wrapper class for fortran function or subroutine. is there any way to get a proper implementation of c# wrapper class? As per my research, Microsoft's system runtime interopservices provides a wrapper interface for fortran function.
    so is there anyone who did similar ?


    regards!
     
    Achiever, Jul 18, 2017 IP
  2. Achiever

    Achiever Well-Known Member

    Messages:
    2,206
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #2
    I have several messages regarding this received. but there is no proper implementation. cause, as per documentation we need to pack it up in dll and then we can use it as a service in .net platform. so is it possible to call without packing fortran function in dll.

    any replies to this thread would be appriciated.

    regards !
     
    Achiever, Jul 18, 2017 IP
  3. necko16

    necko16 Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #3
    hi,

    The Fortran main program uses the C attribute to call the C functions.
    The C attribute causes Fortran to generate all-lowercase names, so the ALIAS attribute must be used to preserve mixed case.


    C File FORMAIN.FOR
    C
    INTERFACE TO INTEGER*4 FUNCTION Fact [C,ALIAS:'_Fact'] (n)
    INTEGER*4 n [VALUE]
    END

    INTERFACE TO SUBROUTINE Pythagoras [C,ALIAS:'_Pythagoras'] (a,b,c)
    REAL*4 a [VALUE]
    REAL*4 b [VALUE]
    REAL*4 c [REFERENCE]
    END

    INTEGER*4 Fact
    REAL*4 c
    WRITE (*,*) 'Factorial of 7 is ', Fact (7)
    CALL Pythagoras (30, 40, c)
    WRITE (*,*) 'Hypotenuse if sides 30, 40 is ', c
    END

    /* File CSUBS.C */

    #include <math.h>

    int Fact( int n )
    {
    if (n > 1)
    return( n * Fact( n - 1 ));
    return 1;
    }

    void Pythagoras( float a, float b, float *c)
    {
    *c = sqrt( a * a + b * b );
    }
     
    necko16, Nov 29, 2017 IP