473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

convert fortran real to...

Al
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?

Jul 23 '05 #1
5 6002
Al wrote:
I am about to start rewriting a fortran program to ansi C++.


Step 1: use f2c, to translate Fortran source into complete C source that
compiles and runs. F2C is so stable that many use it as their Fortran
compiler. They never read the C intermediate.

Step 2: Read the C intermediate. It is not that bad, once you learn how
stereotypically it wraps all the Fortran nuances. But it won't be C++. Don't
ask it to be and you'l do fine. You can make minor tweaks to code in this
state.

Step 3: Write a billion unit tests that completely characterize this legacy
code. Many tests can pass sample data, collect sample results, and compare
them to golden references.

Step 4: Erase the source, and make each unit test pass by writing new
source.

Notice that at each step you can stop and have something useful to work
with.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #2
Al wrote:
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?

It depends on the precision that you want. I would begin with double.

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #3

"Al" <al********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?


To be on the safe side I'd go with double.

Cheers
Chris
Jul 23 '05 #4
Chris Theis wrote:
"Al" <al********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?


To be on the safe side I'd go with double.


I agree, but let me note that most Fortran compilers on 32-bit
platforms use 4-byte reals, which corresponds to a C/C++ float. If the
Fortran programmer thought 8 byte variables were necessary, he would
have declared them as DOUBLE PRECISION or the nonstandard, but common,
REAL*8. Many Fortran compilers have an option to "promote" REAL
variables to double precision. If one has a make file or build script
showing that this option was used, then the corresponding C++ variables
should be double.

Jul 23 '05 #5
Chris Theis wrote:
"Al" <al********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I am about to start rewriting a fortran program to ansi C++.

Would it be best to convert the variables that are 'real' to float?
double? long double?

To be on the safe side I'd go with double.


Actually, if you're lucky, then they're already declared in fortran as
either
REAL*4 or REAL*8, in which case the decision for float or double is made
for you. Otherwise, I'd agree with Chris and go with double.

It's been ages since I did FORTRAN (back in the ancient WATFOR/WATFIV
days), but didn't it also have an explicit DOUBLE PRECISION declaration?
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Santosh | last post by:
Hello all, I am trying to interface c++ and fortran, the fortran code is already there and I was successful in calling the subroutines and functions, but was not able to send the fortran module...
2
by: NM | last post by:
Hello all, I am supposed to do some mixed programming with c++ and fortran. I was succeeful in exchanging the 2D arrays from fortran to c++ and the other way, but was unable to that same with...
12
by: Bigdakine | last post by:
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 ...
26
by: sam | last post by:
Hi, Can anyone help me find a software that can convert a code in 'C' to 'Fortran77/90' automatically? Thanks in advance. Sam.
9
by: travisperkins03 | last post by:
Hi, I have read somewhere that C code sometimes cannot be compiled to be as efficient as FORTRAN, eg for matrix multiplication, because a C compiler cannot make the assumptions about arrays that...
3
by: Holger (David) Wagner | last post by:
Hi all, we're currently developing an application in the .NET environment that needs to access a DLL implemented in Fortran. There is one procedure with about 17 parameters, most of them arrays....
3
by: David Dvali | last post by:
Hello. I have one small program which I need to convert in C#. The original source codes are written in Fortran 77. Can anybody advice me what is the easy way to do this task? Or may be there...
52
by: Nomad.C | last post by:
Hi I've been thinking of learning Fortran as number crunching kinda language for my Physics degree......but then looking around the internet, people are saying that the libraries/ Algorithms once...
2
by: luis | last post by:
I'm using ctypes to call a fortran dll from python. I have no problems passing integer and double arryas, but I have an error with str arrys. For example: ..... StringVector = c_char_p *...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.