473,698 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6025
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********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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********@hot mail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.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
3692
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 data into my C++ code and viceversa. I used gcc 3.3 and g95 for c++ and fortran resp. Here is a little made up sample code so that u could understand my problem. $cat fort.f90
2
3319
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 the 3D arrays, the values passed are not all the same. I am also pasting the fortran and c++ codes so that you could have a look at them. ////C++ Code
12
2896
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 wload(starttime, duration, station, component, dataray, nsamp, calib, srate, samplength, datadir)
26
13554
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
3817
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 a FORTRAN compiler can. But I don't understand the example, not least because I don't understand FORTRAN. I also don't understand why it is more efficient in this case for a compiler to choose the order of evaluation (or whatever it is that it...
3
5819
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. After some trial and error experiments, we've found out that a) the parameters must be ordered by type, i.e. we cannot mix double, integers and Strings (char-Arrays) - instead, we first need to put all the float-Arrays and Int32-Arrays, and...
3
11461
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 is some tools for it? Thank you.
52
5108
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 used for number crunching is now slowly converting into C, so do you think I should stick with C, since I know C already, or should I proceed learning fortran?? Any advice?? Thanks
2
4432
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 * len(id) # id is a list of strings Id_dat=StringVector() for i in range(len(Id)): ....Id_dat=id
0
8611
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8876
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6531
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
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
3
2007
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.