473,581 Members | 2,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5199

"Anonymous" <no****@noISP.c om> wrote in message
news:19yzb.4165 00$Fm2.424825@a ttbi_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.c om> wrote in message
news:QfJzb.2256 85$Dw6.802230@a ttbi_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.c om> 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.c om> wrote in message
news:19yzb.4165 00$Fm2.424825@a ttbi_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
5725
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 xml.Also through Exsl ,had finished the multiple output html files. The problem is while reading through the worddoc paragraph,the special characters are not identified. So in the xml file,it's...
2
4454
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 suggestions would be appreciated. Thanks in Advance sp
72
4167
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 something different for the same values of a, b and c?
25
2817
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 MyTableRow( ) ; row << new MyTableCell( "cell1 text contents" ) ; row << new MyTableCell( "cell2 text contents" ) ; table << row ; thanks,
4
1081
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 single to convert to a string. i thought the .parse class would do it? maybe im using it wrong? -- Message posted via http://www.dotnetmonster.com
5
1640
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, sizeof(XXX);
11
2771
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 JavaScript code contains certain characters, such as & or < or several others, it converts them to html, such as &amp; or &lt; which can sometimes cause my scripts not to work. How can I prevent ASP.NET from...
28
3567
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 basic, called "Thoroughbred Basic", a type of business basic. I need to re-write it, bring it kicking and screaming to run on Windows XP. This is for a video rental place, tracks movie and game...
3
3993
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 PHP to write a SQL UPDATE command that gets written to my MySQL database. I can later view this data back in the form. One thing I've noticed happening is if I enter code such as &lt; it gets...
7
1466
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 surprise unsigned char bug4_a(void) { return 1<<(1?1:1) < 0x9999;
0
7883
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8158
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7917
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2311
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1413
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.