Calling fortran subroutine from c

B

Bigdakine

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."
 
F

Fred L. Kleinschmidt

Bigdakine said:
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.
 
M

Mark R.Bannister

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.
 
E

E. Robert Tisdale

Bigdakine said:
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));
 
K

Kenny McCormack

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.
 
B

Bigdakine

Subject: Re: Calling fortran subroutine from c
From: "E. Robert Tisdale" (e-mail address removed)
Date: 9/1/04 7:56 AM Hawaiian Standard Time
Message-id: <[email protected]>
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."
 
E

E. Robert Tisdale

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.
 
C

CBFalconer

Kenny said:
.... 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.
 
K

Kenny McCormack

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)
 
K

Kenny McCormack

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.
 
T

Tim Prince

Kenny McCormack said:
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.
 
M

Mark McIntyre

On Thu, 02 Sep 2004 12:02:41 GMT, in comp.lang.c ,
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)
 
M

Mark L Pappin

(apologies for the late reply - catching up)

Fred L. Kleinschmidt said:
Bigdakine wrote:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top