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

Converting Fortran module<->C++ structure

P: n/a
I have a mixed-language pgm (Fortran and C++) which needs to pass a few
hundred values from C++ to Fortran. One way to do this is to have a
Fortran module and a C++ structure (or class) with an identical data
layout. I have used this idea with no problem, but it necessitates
making changes very carefully to the Fortran module and the C++
structure to keep them "in sync".

I am looking for a program which translates source files between these
two formats; i e, takes a Fortran module source as input and produces a
C++ structure source file as output, or vice versa. Then I will maintain
one source file and run this hypothetical program before each build to
produce the other source file.

Anyone know of such a program?

Thanks for any tips.

sh************@computer.org (remove caps to get e-mail)

Jul 22 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Anonymous" <no****@noISP.com> wrote in message
news:19yzb.416500$Fm2.424825@attbi_s04...
I have a mixed-language pgm (Fortran and C++) which needs to pass a few hundred values from C++ to Fortran. One way to do this is to have a
Fortran module and a C++ structure (or class) with an identical data
layout. I have used this idea with no problem, but it necessitates
making changes very carefully to the Fortran module and the C++
structure to keep them "in sync".

I am looking for a program which translates source files between these two formats; i e, takes a Fortran module source as input and produces a C++ structure source file as output, or vice versa. Then I will maintain one source file and run this hypothetical program before each build to produce the other source file.

Anyone know of such a program?

Thanks for any tips.

sh************@computer.org (remove caps to get e-mail)


If your C++ data declarations are C compatible
perhaps C2F can create a module from them.

http://home.cfl.rr.com/davegemini/C2F.ZIP

C2F.exe is a windows program
Jul 22 '05 #2

P: n/a
Anonymous wrote:

I have a mixed-language pgm (Fortran and C++) which needs to pass a few
hundred values from C++ to Fortran. One way to do this is to have a
Fortran module and a C++ structure (or class) with an identical data
layout. I have used this idea with no problem, but it necessitates
making changes very carefully to the Fortran module and the C++
structure to keep them "in sync".

I am looking for a program which translates source files between these
two formats; i e, takes a Fortran module source as input and produces a
C++ structure source file as output, or vice versa. Then I will maintain
one source file and run this hypothetical program before each build to
produce the other source file.

I personally don't know of any that does specifically this, but should
not be too difficult to write one if your definitions are fairly simple
(and even easier if you follow a consistent structure/format).

Maybe you could use both C2F and F2C. They're both "free".
Anyone know of such a program?

Thanks for any tips.

sh************@computer.org (remove caps to get e-mail)

--

Gary Scott
mailto:ga*******@ev1.net

Fortran Library
http://www.fortranlib.com

Support the GNU Fortran G95 Project: http://g95.sourceforge.net
Jul 22 '05 #3

P: n/a
David Frank wrote:
If your C++ data declarations are C compatible
perhaps C2F can create a module from them.

http://home.cfl.rr.com/davegemini/C2F.ZIP

C2F.exe is a windows program


C2F produces no output when given a .h file with #defines as input, so
this pgm is not useful for my task.

sh************@computer.org (remove caps to get e-mail)
Jul 22 '05 #4

P: n/a

"Anonymous" <no****@noISP.com> wrote in message
news:QfJzb.225685$Dw6.802230@attbi_s02...
David Frank wrote:
If your C++ data declarations are C compatible
perhaps C2F can create a module from them.

http://home.cfl.rr.com/davegemini/C2F.ZIP

C2F.exe is a windows program
C2F produces no output when given a .h file with #defines as input,

so this pgm is not useful for my task.

sh************@computer.org (remove caps to get e-mail)


try copying your .h file to a .c file
and when solicited for a filename dont include the .c extension
(its assumed)

and/or you can send me the file if you want me to try it..
Jul 22 '05 #5

P: n/a
Anonymous <no****@noISP.com> writes:
I have a mixed-language pgm (Fortran and C++) which needs to pass a
few hundred values from C++ to Fortran. One way to do this is to have
a Fortran module and a C++ structure (or class) with an identical data
layout.


Presumably you mean a Fortran derived type (aka structure). Fortran
modules don't *HAVE* a data layout; they are not comparable to C/C++
structures in any particularly useful ways.

I don't have a handy translator for such things (though I'll note that
in the draft f2003 you can do a Fortran derived type that is interoperable
with a C struct in a way that is directly comparable enough that a
translator would be simple).

--
Richard Maine
email: my last name at domain
domain: sumertriangle dot net
Jul 22 '05 #6

P: n/a
Richard Maine wrote:
Anonymous writes:
I have a mixed-language pgm (Fortran and C++)
which needs to pass a few hundred values from C++ to Fortran.
One way to do this is to have a Fortran module
and a C++ structure (or class) with an identical data layout.
Presumably, you mean a Fortran derived type (aka structure).
Fortran modules don't *HAVE* a data layout;
they are not comparable to C/C++ structures
in any particularly useful ways.


A header file is as close as you can get to a module in C or C++.
I don't have a handy translator for such things (though I'll note
that, in the draft f2003, you can do a Fortran derived type
that is interoperable with a C struct
in a way that is directly comparable enough that
a translator would be simple).


Fortran 90 derived type:

type:: type_t
sequence
integer:: i
real:: x
end type type_t

Equivalent C or C++ structure:

#include <stdint.h>
typedef int32_t f77_integer; // f90 implementation dependent
typedef float f77_single; // f90 implementation dependent
typedef void f77_subroutine; // f90 implementation dependent

typedef struct type_t {
f77_integer i;
f77_single x;
} type_t;

Different Fortran 90 compilers "mangle" the names
of functions contained in modules in different ways
to form the symbols that it leaves behind in object files
for the link editor.
You will need Fortran 90 "helper" functions
to access them reliably.
For example, if the module module_h contains

subroutine f(t)
type(type_t), intent(in):: t
! do something with t
end subroutine f

you will need

subroutine help_f(t)
use module_h
type(type_t), intent(in):: t
f(t)
end subroutine help_f

Then, you can write

#ifdef __cplusplus
extern "C" {
#endif/*__cplusplus */
f77_subroutine f(const type_t* pT) {
extern f77_subroutine help_f_(const type_t*);
help_f_(pT);
}
#ifdef __cplusplus
}
#endif/*__cplusplus */

Jul 22 '05 #7

P: n/a
"Anonymous" <no****@noISP.com> wrote in message
news:19yzb.416500$Fm2.424825@attbi_s04...
I have a mixed-language pgm (Fortran and C++) which needs to pass a few
hundred values from C++ to Fortran. One way to do this is to have a
Fortran module and a C++ structure (or class) with an identical data
layout. I have used this idea with no problem, but it necessitates
making changes very carefully to the Fortran module and the C++
structure to keep them "in sync".

I am looking for a program which translates source files between these
two formats; i e, takes a Fortran module source as input and produces a
C++ structure source file as output, or vice versa. Then I will maintain
one source file and run this hypothetical program before each build to
produce the other source file.

Anyone know of such a program?


Our DMS Software Reengineering Toolkit is generalized compiler
technology capable of parsing/transforming/prettyprinting many
languages, including Fortran and C++. By giving it various
transformation rules, you could transform your Fortran "module"
into an arbitrary corresponding set of C++ definitions.
See http://www.semanticdesigns.com/Produ...MSToolkit.html.
--
Ira D. Baxter, Ph.D., CTO 512-250-1018
Semantic Designs, Inc. www.semdesigns.com


----== 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 =---
Jul 22 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.