472,342 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

Converting Fortran module<->C++ structure

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
7 5021

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

"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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: prabha | last post by:
Hello Everybody, I have to conert the word doc to multiple html files,according to the templates in the word doc. I had converted the word to...
2
by: sp | last post by:
Hello Everybody, I need to convert xml that we get from sqlserver For xml auto to my own xml format using asp.net classes. Any ideas and...
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to...
25
by: Steve Richter | last post by:
is it possible to overload the << operator in c# similar to the way it is done in c++ ? MyTable table = new MyTable( ) ; MyTableRow row = new...
4
by: joshua barrett via DotNetMonster.com | last post by:
hey guys im new to programming in general, i was doing fine till i started to work with option strict on, now i can;lt figure out hwo to get a...
5
by: TOMERDR | last post by:
Hi, I was requested to write a code similar to this: CArchive ar; //Not mfc CArchive..... .... void * vp = &XXX; // any object. ar << vp,...
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the...
28
by: Randy Reimers | last post by:
(Hope I'm posting this correctly, otherwise - sorry!, don't know what else to do) I wrote a set of programs "many" years ago, running in a type of...
3
by: webmasterATflymagnetic.com | last post by:
Folks, I'm struggling to put the question together, but I have this problem. I have written an HTML form that I can use for data entry. This uses...
7
by: Francois Grieu | last post by:
Hello, one of my C compiler (Keil C51) evaluates the constant expression 1<<(1?1:1) < 0x9999 to the value 1. // this returns 0, much to my...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.