473,569 Members | 2,611 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 5198

"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
4448
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
4159
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
2806
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
1638
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
2767
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
3560
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
3992
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
1463
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
7701
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
7615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
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
7677
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
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2115
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
1223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
940
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.