By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,309 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,309 IT Pros & Developers. It's quick & easy.

Calling fortran subroutine from c

P: n/a

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."
Nov 14 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a


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
Nov 14 '05 #2

P: n/a
bi*******@aol.comGetaGrip (Bigdakine) wrote in message news:<20***************************@mb-m17.aol.com>...
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.
Nov 14 '05 #3

P: n/a
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));
Nov 14 '05 #4

P: n/a
In article <ch**********@nntp1.jpl.nasa.gov>,
E. Robert Tisdale <E.**************@jpl.nasa.gov> 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.

Nov 14 '05 #5

P: n/a
>Subject: Re: Calling fortran subroutine from c
From: "E. Robert Tisdale" E.**************@jpl.nasa.gov
Date: 9/1/04 7:56 AM Hawaiian Standard Time
Message-id: <ch**********@nntp1.jpl.nasa.gov>

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."
Nov 14 '05 #6

P: n/a
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.
Nov 14 '05 #7

P: n/a
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?
Nov 14 '05 #8

P: n/a
In article <41***************@yahoo.com>,
CBFalconer <cb********@worldnet.att.net> 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)

Nov 14 '05 #9

P: n/a
Kenny McCormack wrote:
CBFalconer <cb********@worldnet.att.net> 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?

Nov 14 '05 #10

P: n/a
In article <41***************@yahoo.com>,
CBFalconer <cb********@worldnet.att.net> wrote:
Kenny McCormack wrote:
CBFalconer <cb********@worldnet.att.net> 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.

Nov 14 '05 #11

P: n/a

"Kenny McCormack" <ga*****@yin.interaccess.com> wrote in message
news:ch**********@yin.interaccess.com...
In article <41***************@yahoo.com>,
CBFalconer <cb********@worldnet.att.net> wrote:
Kenny McCormack wrote:
CBFalconer <cb********@worldnet.att.net> 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.
Nov 14 '05 #12

P: n/a
On Thu, 02 Sep 2004 12:02:41 GMT, in comp.lang.c ,
ga*****@yin.interaccess.com (Kenny McCormack) wrote:
In article <41***************@yahoo.com>,
CBFalconer <cb********@worldnet.att.net> wrote:
Kenny McCormack wrote:
CBFalconer <cb********@worldnet.att.net> 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 =---
Nov 14 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.