Calling fortran subroutine from c

Discussion in 'C Programming' started by Bigdakine, Sep 1, 2004.

  1. Bigdakine

    Bigdakine Guest

    I don't know if this is the right forum for this, and if not please suggest one
    which fits.

    I have to call a fortran sub routine from a C main program.

    The fortran subroutine statement is

    wload(starttime, duration, station, component, dataray, nsamp, calib, srate,
    samplength, datadir)

    And the variables are defined

    real*8 starttime
    real duration
    character*(*) sta
    character*(*) component
    integer*4 dataray(1)
    integer nsamp,samplength
    real calib,srate
    character*100 datadir

    Of these, starttime, duration, station, component are inputs. dataray is an
    integer vector created in the C-program via dataray = calloc(65000,
    sizeof(int))

    In the C-code I have the following variable defs..
    double starttime
    char sta[5], component[4]
    char *datadir
    float duration, calib, srate

    But I can't get the call to the fortran sub to work with robustness. Do you
    have any pointers as to how the c-variables should be defined and a function
    prototype for wload_ that could accomplish that?

    If you know of a good FAQ on this, that would work for me too...

    Yours,

    Stuart


    Dr. Stuart A. Weinstein
    Ewa Beach Institute of Tectonics
    "To err is human, but to really foul things up requires a creationist"


    "Creationists aren't impervious to Logic: They're oblivious to it."
     
    Bigdakine, Sep 1, 2004
    #1
    1. Advertising

  2. Bigdakine wrote:
    >
    > I don't know if this is the right forum for this, and if not please suggest one
    > which fits.
    >
    > I have to call a fortran sub routine from a C main program.
    >
    > The fortran subroutine statement is
    >
    > wload(starttime, duration, station, component, dataray, nsamp, calib, srate,
    > samplength, datadir)
    >
    > And the variables are defined
    >
    > real*8 starttime
    > real duration
    > character*(*) sta
    > character*(*) component
    > integer*4 dataray(1)
    > integer nsamp,samplength
    > real calib,srate
    > character*100 datadir
    >
    > Of these, starttime, duration, station, component are inputs. dataray is an
    > integer vector created in the C-program via dataray = calloc(65000,
    > sizeof(int))
    >
    > In the C-code I have the following variable defs..
    > double starttime
    > char sta[5], component[4]
    > char *datadir
    > float duration, calib, srate
    >
    > But I can't get the call to the fortran sub to work with robustness. Do you
    > have any pointers as to how the c-variables should be defined and a function
    > prototype for wload_ that could accomplish that?
    >
    > If you know of a good FAQ on this, that would work for me too...
    >
    > Yours,
    >
    > Stuart
    >
    > Dr. Stuart A. Weinstein
    > Ewa Beach Institute of Tectonics
    > "To err is human, but to really foul things up requires a creationist"
    >
    >
    > "Creationists aren't impervious to Logic: They're oblivious to it."


    The answer will depend on your platform and what compilers you are
    using. You need to look at the C and Fortran compiler manuals for your
    platform. Note that the solution will probably not be portable.
    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Common User Interface Services
    M/S 2R-94 (206)544-5225
     
    Fred L. Kleinschmidt, Sep 1, 2004
    #2
    1. Advertising

  3. etaGrip (Bigdakine) wrote in message news:<>...
    > I don't know if this is the right forum for this, and if not please suggest one
    > which fits.
    >
    > I have to call a fortran sub routine from a C main program.
    >
    > The fortran subroutine statement is
    >
    > wload(starttime, duration, station, component, dataray, nsamp, calib, srate,
    > samplength, datadir)
    >
    > And the variables are defined
    >
    > real*8 starttime
    > real duration
    > character*(*) sta
    > character*(*) component
    > integer*4 dataray(1)
    > integer nsamp,samplength
    > real calib,srate
    > character*100 datadir
    >
    > Of these, starttime, duration, station, component are inputs. dataray is an
    > integer vector created in the C-program via dataray = calloc(65000,
    > sizeof(int))
    >
    > In the C-code I have the following variable defs..
    > double starttime
    > char sta[5], component[4]
    > char *datadir
    > float duration, calib, srate
    >
    > But I can't get the call to the fortran sub to work with robustness. Do you
    > have any pointers as to how the c-variables should be defined and a function
    > prototype for wload_ that could accomplish that?
    >
    > If you know of a good FAQ on this, that would work for me too...


    A quick search on Google revealed ...

    http://www.aei.mpg.de/~jthorn/c2f.html

    Regards,
    Mark.
     
    Mark R.Bannister, Sep 1, 2004
    #3
  4. Bigdakine wrote:

    > I don't know if this is the right forum for this
    > and, if not, please suggest one which fits.


    comp.lang.fortran

    > I need to call a fortran subroutine from a C main program.
    >
    > The fortran subroutine statement is
    >
    > wload(starttime, duration, station, component, dataray, nsamp, calib, srate,
    > samplength, datadir)
    >
    > And the variables are defined
    >
    > real*8 starttime
    > real duration
    > character*(*) station
    > character*(*) component
    > integer*4 dataray(1)
    > integer nsamp,samplength
    > real calib,srate
    > character*100 datadir
    >
    > Of these, starttime, duration, station, component are inputs. dataray is an
    > integer vector created in the C-program via dataray = calloc(65000,
    > sizeof(int))
    >
    > In the C-code I have the following variable defs..
    > double starttime
    > char sta[5], component[4]
    > char *datadir
    > float duration, calib, srate
    >
    > But I can't get the call to the fortran sub to work with robustness.
    > Do you have any pointers as to how the c-variables should be defined
    > and a function prototype for wload_ that could accomplish that?


    void wload_(double*, float*, char*, char*, int*, int*,
    float*, float*, int*, char*, int, int, int);

    wload_(&starttime, &duration, sta, component, dataray,
    &nsamp, &calib, &srate, &samplength, datadir,
    strlen(sta), strlen(component), strlen(datadir));
     
    E. Robert Tisdale, Sep 1, 2004
    #4
  5. In article <ch52f5$jum$>,
    E. Robert Tisdale <> wrote:
    >Bigdakine wrote:
    >
    >> I don't know if this is the right forum for this
    >> and, if not, please suggest one which fits.

    >
    > comp.lang.fortran


    Unclear. I suspect the main reason this advice is given is b/c clf is not
    anal about topicality, as clc, almost uniquely so, is.

    Really, this question, how do I interface foo with bat, isn't topical for
    either the followers of foo or the followers of bar. It falls in between,
    in a land that neither wants to touch (*). In fact, it is really is
    a vendor issue - it concerns the vendors of the two products in question
    (i.e., the vendors of foo and bar together can answer the question).

    (*) Somewhat related: I've often wondered where on Usenet, one could ask
    questions about Cygwin. Talk about neither fish nor fowl! Neither the
    Unix people or the Windows people would want to touch it.
     
    Kenny McCormack, Sep 1, 2004
    #5
  6. Bigdakine

    Bigdakine Guest

    >Subject: Re: Calling fortran subroutine from c
    >From: "E. Robert Tisdale"
    >Date: 9/1/04 7:56 AM Hawaiian Standard Time
    >Message-id: <ch52f5$jum$>
    >
    >Bigdakine wrote:
    >
    >> I don't know if this is the right forum for this
    >> and, if not, please suggest one which fits.

    >
    > comp.lang.fortran
    >
    >> I need to call a fortran subroutine from a C main program.
    >>
    >> The fortran subroutine statement is
    >>
    >> wload(starttime, duration, station, component, dataray, nsamp, calib,

    >srate,
    >> samplength, datadir)
    >>
    >> And the variables are defined
    >>
    >> real*8 starttime
    >> real duration
    >> character*(*) station
    >> character*(*) component
    >> integer*4 dataray(1)
    >> integer nsamp,samplength
    >> real calib,srate
    >> character*100 datadir
    >>
    >> Of these, starttime, duration, station, component are inputs. dataray is an
    >> integer vector created in the C-program via dataray = calloc(65000,
    >> sizeof(int))
    >>
    >> In the C-code I have the following variable defs..
    >> double starttime
    >> char sta[5], component[4]
    >> char *datadir
    >> float duration, calib, srate
    >>
    >> But I can't get the call to the fortran sub to work with robustness.
    >> Do you have any pointers as to how the c-variables should be defined
    >> and a function prototype for wload_ that could accomplish that?

    >
    > void wload_(double*, float*, char*, char*, int*, int*,
    > float*, float*, int*, char*, int, int, int);
    >
    > wload_(&starttime, &duration, sta, component, dataray,
    > &nsamp, &calib, &srate, &samplength, datadir,
    > strlen(sta), strlen(component), strlen(datadir));
    >


    Ahhh. Yes. I had forgotten that. Its been a while since I had to do this. The
    dimensions get appeneded to the end.

    Thanks! I'm sure that will do the trick!

    Stuart
    Dr. Stuart A. Weinstein
    Ewa Beach Institute of Tectonics
    "To err is human, but to really foul things up requires a creationist"


    "Creationists aren't impervious to Logic: They're oblivious to it."
     
    Bigdakine, Sep 1, 2004
    #6
  7. Kenny McCormack wrote:

    > E. Robert Tisdale wrote:
    >
    >>Bigdakine wrote:
    >>
    >>>I don't know if this is the right forum for this
    >>>and, if not, please suggest one which fits.

    >>
    >> comp.lang.fortran


    Language interoperability *is* topical in comp.lang.fortran
    Platform specific questions are accepted in comp.lang.fortran
    only because there is no other appropriate forum.
    Platform specific questions are handled in comp.lang.c
    by redirecting them to a more appropriate forum.
    >
    > Unclear.
    > I suspect the main reason this advice is given is b/c clf is not
    > anal about topicality, as clc, almost uniquely so, is.


    Responding to off-topic posts is inappropriate behavior.
    If you must respond, please try to be polite and helpful.
    Redirect the post to a more appropriate forum.

    > Really, this question, how do I interface foo with bat, isn't topical for
    > either the followers of foo or the followers of bar. It falls in between,
    > in a land that neither wants to touch (*). In fact, it is really is
    > a vendor issue - it concerns the vendors of the two products in question
    > (i.e., the vendors of foo and bar together can answer the question).
    >
    > (*) Somewhat related: I've often wondered where on Usenet,
    > one could ask questions about Cygwin. Talk about neither fish nor fowl!
    > Neither the Unix people or the Windows people would want to touch it.


    In my opinion, language interoperability is *always* topical
    in the comp.lang.c as well as in the comp.lang.fortran newsgroup
    but Fortran programmers have more experience with it
    because it is more important to them.
     
    E. Robert Tisdale, Sep 1, 2004
    #7
  8. Bigdakine

    CBFalconer Guest

    Kenny McCormack wrote:
    >

    .... snip ...
    >
    > (*) Somewhat related: I've often wondered where on Usenet, one
    > could ask questions about Cygwin. Talk about neither fish nor
    > fowl! Neither the Unix people or the Windows people would want
    > to touch it.


    The cygwin mailing list. Much more restrictive than here, and you
    also have no idea what the problem is.

    --
    A: Because it fouls the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    CBFalconer, Sep 2, 2004
    #8
  9. In article <>,
    CBFalconer <> wrote:
    >Kenny McCormack wrote:
    >>

    >... snip ...
    >>
    >> (*) Somewhat related: I've often wondered where on Usenet, one
    >> could ask questions about Cygwin. Talk about neither fish nor
    >> fowl! Neither the Unix people or the Windows people would want
    >> to touch it.

    >
    >The cygwin mailing list. Much more restrictive than here, and you
    >also have no idea what the problem is.


    (I have no idea what your post means)
     
    Kenny McCormack, Sep 2, 2004
    #9
  10. Bigdakine

    CBFalconer Guest

    Kenny McCormack wrote:
    > CBFalconer <> wrote:
    >> Kenny McCormack wrote:
    >>>

    >>... snip ...
    >>>
    >>> (*) Somewhat related: I've often wondered where on Usenet, one
    >>> could ask questions about Cygwin. Talk about neither fish nor
    >>> fowl! Neither the Unix people or the Windows people would want
    >>> to touch it.

    >>
    >> The cygwin mailing list. Much more restrictive than here, and you
    >> also have no idea what the problem is.

    >
    > (I have no idea what your post means)


    You wanted to know where to ask questions about Cygwin. I told
    you.

    --
    A: Because it fouls the order in which people normally read text.
    Q: Why is top-posting such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    CBFalconer, Sep 2, 2004
    #10
  11. In article <>,
    CBFalconer <> wrote:
    >Kenny McCormack wrote:
    >> CBFalconer <> wrote:
    >>> Kenny McCormack wrote:
    >>>>
    >>>... snip ...
    >>>>
    >>>> (*) Somewhat related: I've often wondered where on Usenet, one
    >>>> could ask questions about Cygwin. Talk about neither fish nor
    >>>> fowl! Neither the Unix people or the Windows people would want
    >>>> to touch it.
    >>>
    >>> The cygwin mailing list. Much more restrictive than here, and you
    >>> also have no idea what the problem is.

    >>
    >> (I have no idea what your post means)

    >
    >You wanted to know where to ask questions about Cygwin. I told
    >you.


    No, I didn't. I see now that you misinterpreted "I've often wondered..."
    as a request for help. OK, so noted.

    Further, even if we grant that misinterpretation, note that I said "...
    where on Usenet ...", and the cygwin mailing list isn't Usenet. It is
    a vendor-run forum. And, therein is the point. I had argued earlier (in
    the parts that are now snipped) that linking C & Fortran was a vendor
    issue, just as cygwin is. The point is that neither topic has the "generic
    cred" needed for discussion on the Usenet. The Usenet is, at least in
    theory, vendor neutral.
     
    Kenny McCormack, Sep 2, 2004
    #11
  12. Bigdakine

    Tim Prince Guest

    "Kenny McCormack" <> wrote in message
    news:ch72i0$ne1$...
    > In article <>,
    > CBFalconer <> wrote:
    > >Kenny McCormack wrote:
    > >> CBFalconer <> wrote:
    > >>> Kenny McCormack wrote:
    > >>>>
    > >>>... snip ...
    > >>>>
    > >>>> (*) Somewhat related: I've often wondered where on Usenet, one
    > >>>> could ask questions about Cygwin. Talk about neither fish nor
    > >>>> fowl! Neither the Unix people or the Windows people would want
    > >>>> to touch it.
    > >>>
    > >>> The cygwin mailing list. Much more restrictive than here, and you
    > >>> also have no idea what the problem is.
    > >>
    > >> (I have no idea what your post means)

    > >
    > >You wanted to know where to ask questions about Cygwin. I told
    > >you.

    >
    > No, I didn't. I see now that you misinterpreted "I've often wondered..."
    > as a request for help. OK, so noted.
    >
    > Further, even if we grant that misinterpretation, note that I said "...
    > where on Usenet ...", and the cygwin mailing list isn't Usenet. It is
    > a vendor-run forum. And, therein is the point. I had argued earlier (in
    > the parts that are now snipped) that linking C & Fortran was a vendor
    > issue, just as cygwin is. The point is that neither topic has the

    "generic
    > cred" needed for discussion on the Usenet. The Usenet is, at least in
    > theory, vendor neutral.
    >

    So, now you're confirming that your posts have been Off Topic for C. If you
    see a need, why don't you start a Fortran newsgroup? C to Fortran
    interoperability, for simple cases, is covered by the Fortran 2003 standard.
    You could start quibbling about where to draw the line between discussion of
    compliant and non-compliant implementations.
     
    Tim Prince, Sep 2, 2004
    #12
  13. On Thu, 02 Sep 2004 12:02:41 GMT, in comp.lang.c ,
    (Kenny McCormack) wrote:

    >In article <>,
    >CBFalconer <> wrote:
    >>Kenny McCormack wrote:
    >>> CBFalconer <> wrote:
    >>>> Kenny McCormack wrote:
    >>>>>
    >>>>... snip ...
    >>>>>
    >>>>> (*) Somewhat related: I've often wondered where on Usenet, one
    >>>>> could ask questions about Cygwin.
    >>>>
    >>>> The cygwin mailing list.
    >>>
    >>> (I have no idea what your post means)

    >>
    >>You wanted to know where to ask questions about Cygwin. I told
    >>you.

    >
    >No, I didn't. I see now that you misinterpreted "I've often wondered..."
    >as a request for help. OK, so noted.


    You might also want to note that "I've often wondered..." is generally
    regarded (in English) as a request for information. YMMV but you're likely
    to get people answering the unstated question when you use that phrase.

    (more pedantry snipped)
    --
    Mark McIntyre
    CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
    CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>


    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    Mark McIntyre, Sep 2, 2004
    #13
  14. (apologies for the late reply - catching up)

    "Fred L. Kleinschmidt" <fred.l.kleinschmidt@nospam_boeing.com> writes:
    > Bigdakine wrote:


    >> I don't know if this is the right forum for this, and if not please
    >> suggest one which fits.


    >> I have to call a fortran sub routine from a C main program.


    > The answer will depend on your platform and what compilers you are
    > using. You need to look at the C and Fortran compiler manuals for your
    > platform. Note that the solution will probably not be portable.


    Google for "cfortran.h"

    It is, of course, almost entirely in the realms of Undefined,
    Unspecified, and Implementation-defined Behaviour, but may just solve
    your problem. It (well, the version extant at the time) worked for me
    under VMS in 1990 or thereabouts.

    mlp
     
    Mark L Pappin, Sep 25, 2004
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pinchedez
    Replies:
    0
    Views:
    426
    Pinchedez
    Dec 5, 2003
  2. Amit

    Calling subroutine in fortran module

    Amit, Jan 30, 2005, in forum: C Programming
    Replies:
    5
    Views:
    1,737
    Dave Thompson
    Feb 7, 2005
  3. Madhusudan Singh
    Replies:
    4
    Views:
    505
    CBFalconer
    Apr 6, 2005
  4. Luna Moon
    Replies:
    9
    Views:
    648
    Guest
    Sep 4, 2007
  5. deadpickle
    Replies:
    1
    Views:
    1,098
    Jens Thoms Toerring
    Nov 7, 2010
Loading...

Share This Page