CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Main CFD Forum (
-   -   'C' or FORTRAN or 'C++' (

Yogesh Talekar September 30, 1999 03:14

'C' or FORTRAN or 'C++'
Dear Gurus,

I want your advice on which langauge for programming and visualisaing CFD is good.. C or FORTRAN.

I know 'C' quite well but not the adnaced versions of FORTRAN like fortran-90 or fortran-95. I have learnt fortran-77 NOT fortran-90. Can anybody figure out the difference in them.

Also i want some advice about graphics-visualisation. Can anybody tell 'C' is better or 'fortran' is better in this respect.

Please help me about the THREE questions above.

thank you


Q. Liu September 30, 1999 21:02

Re: 'C' or FORTRAN or 'C++'
I think fortran is better for calculation, but C++ or OPENGL is better for graphics and CFD visualization. You can take a look at any book about F77 and F90. Not big difference. F90 is better but F70 is good too.

John C. Chien October 1, 1999 00:53

Re: 'C' or FORTRAN or 'C++'
(1). The computer does not care, it works on "0" and "1". It can only execute programs written in "0" and "1".

Thomas Wolfanger October 1, 1999 11:45

Re: 'C' or FORTRAN or 'C++'
Hello, I would say that the programming langauge depends somewhat on the goal you want to reach. For a "simple" flow solver using structured grids, "simple" language like FORTRAN is well suited. For more complex tasks, i.e. unstructured, adaptive grids, I would prefer C or C++ as it supports better the necessary data structures. I don't know what the new F90 or F95 can do. For Postprocessing, C or C++ is definfitely the language of choice. Hope this helps.

Shi Xuefeng October 1, 1999 12:31

Re: 'C' or FORTRAN or 'C++'
1. FORTRAN for programming and C++(C) for visualisaing CFD 2. a little difference. find a book to know. 3. C++(C) good for graphics-visualisation. good luck

Shi Xuefeng October 1, 1999 12:34

Re: 'C' or FORTRAN or 'C++'
Although the computer does not care, it works on "0" and "1". Some people like rice and some like other.

John C. Chien October 1, 1999 13:28

Re: 'C' or FORTRAN or 'C++'
(1). The rice has nothing to do with CFD. (2). The computer does not care, and also the users do not care. (3). The users' goal is to solve his problem, he does not care whether you like rice or not. (4). This simply says that the ability to satisfy the customers need is not a function of the languages used.(spoken languages and programming languages as well) There are people using JAVA and there are people using BASIC. Which one is better? From the user's point of view, JAVA is better, because it is more portable and the user does not have to worry about the type of computers he is using. (5). The questions and answers should be directed toward the user's goal of solving his problems.

Shi Xuefeng October 1, 1999 14:01

Re: 'C' or FORTRAN or 'C++'
Hi, John:

You maybe make a mistake of the meaning "rice".

Although the computer does not care what the languages is used, in general speaking, every languages has the advantage to use it. As you mentioned the JAVA, in some case it is not good compared with C++ in some situation. So, for CFD, I think the FORTRAN is better than C++(C) in the calculation. C++(C) is better in graphics-visualisation.

Peter Cavallo October 1, 1999 22:55

Re: 'C' or FORTRAN or 'C++'
The upgrades made in Fortran 90 and Fortran 95 certainly give the language many more "C-like" qualities and capabilities. In fact, mach of the new syntax and commands are borrowed from C, such as the switch/case construct. Other capabilities include creating data structures and linked lists, modules which allow common arrays to be allocated/reallocated/deallocated anywhere, among others. Memory allocation is very straightforward as there are no pointers, malloc's, etc.

Other old-style Fortran practices such as parameter statements, common blocks, DO constructs with labels, etc. are done away with and obsolete with Fortran 90 and 95. With Fortran 95, even the sometimes irritating fixed-format source form is done away with. No more worrying about whether you're past column 72 or not.

Bottom line is that the recent Fortran standards have been designed with the power of C in mind.

Another factor I feel should be considered is readability, particularly if you are sharing the code with others or are working on it with others. Personally I find the incessant punctuations of C (parentheses, brackets, semicolons) distracting when sifting through code.

clifford Bradford October 2, 1999 16:51

Re: 'C' or FORTRAN or 'C++'
i'd like to add my two cents. first i am a C programmer but i read fortran (esp. F90). i'll answer your questions first. (1) for writing CFD solvers their is no difference whether you use C or Fortran90. but be forewarned that if you'd like to interface with another analysis code written by someone else it's likely to be in fortran. (2) the difference between f77 and f90 is large but if you already know f77 it's no problem (3)C/C++ is the choice for visualization although i don't see why you write your own code to do this as there are many pre/post processors out there for you to use. the above has several caveats though, and mostly from the fortran side. because most f90/f95 compilers also will compile f77 code there is a tendency for people who write fortran90 to have lots of old f77 crap in their codes. i've seen this first hand. while the new versions of fortran have much of the functionality of C/C++ the code to do the same thing often ends up being bulky. what i'm saying is that their is a lot of baggage from the f77 days left in f90/f95. example i have a friend who learned f90 but likes to write it fixed format! i would make these generalizations though: (a)most structured grid stuff out there is in fortran (b) a lot of unstructured and adaptive mesh generation stuff out there is C. (c)all or most of the visualization stuff out there is in C/C++.(d)from MY experience I've never read a fortran CFD code that was well coded. i think that it is really easy to write bad fortran code but not as easy to write bad C code. so i think if you'd like to write your own codes C will keep you in good stead, just remember don't let you pointers dangle :)

andy October 2, 1999 17:57

Re: 'C' or FORTRAN or 'C++'
If you intend to write a set of program for your own personal use then I would advise choosing the language which will take you the least amount of time. Ease of writing such programs usually far outweighs loss of efficiency in execution. Go with the language you feel most comfortable about. If you have access to high level language and know it well then use that.

Beyond this, your question is difficult to answer because decisions about which language to use are rarely based on something as straightforward as the technical merits of the language. Such an assessment for numerical computation is unlikely to put Fortran at the top of the list given the existence of better languages like ADA. C is almost certain to be somewhere near the bottom of the list since it was designed a long time ago and for substantially different tasks. One almost needs to start with the conclusion that C++ is the tool to use before a case can be made for it because it is such a big and flawed language. Nonetheless, given the will and lots of time and effort it is probable that it will eventually get there because a vast number of people clearly want it to happen (e.g. the significant number of conferences on the subject).

The visualization question is relatively straightforward. Assuming you are going to use a library for most of the graphics then use the language the graphics library wants (almost certainly C).

Fortran's attraction over C for computation is that it is a higher level language and orientated towards numerical analysis. Generally, one can write numerical code faster and more reliably in Fortran. The code will also execute faster given access to a reasonable Fortran compiler. The absence of recursion, support for complex data structures, support for large scale programs, etc... is rarely a problem in practice for numerical simulation. (But if you know C well and Fortran less well then write in C).

C's strengths relative to Fortran come from it being a lower level language (I certainly would not describe this as "powerful"). Broadly, this enables one to do things in C that cannot be done sensibly in Fortran. However, this is at the cost of extra code and a substantial decrease in reliability.

andy October 2, 1999 18:52

Re: 'C' or FORTRAN or 'C++'
A few points to chew on:

Optimised C code executes slower than optimised Fortran code mainly because C does not handle arrays in the same way as Fortran. I hope the C9X directives (to allow the compiler to use the Fortran array tricks) will help redress the balance but generally there does not seem to be much support in the C/C++ community for fast array processing. (I believe the C++ committee actually rejected the array directives initially!). A language cannot be well suited to all tasks and C/C++ is simply not geared towards numerical analysis.

The widespread availability of efficient, heavily used (thoroughly checked) Fortran code for numerical analysis is one of the most attractive features of the language. Many of these routines were developed in the 60s and 70s in Fortran IV (Fortran 66) and not Fortran 77. To describe this as baggage is absurd. It is probably the richest resource on the internet for people involved is solving numerical problems.

I would also disagree with the comments concerning the relative ease of generating bad C code and bad Fortran code. Because of the low level, implementation-orientated nature of C a programmer has to be very disciplined in imposing a sound way of coding to avoid generating bad code. Fortran is a higher level language with a cleaner syntax and this helps in the avoidance of bad code. I would suspect your views may have been formed by comparing C code written by programmers with Fortran code written by non-programmers. (If a non-programmer cannot use BASIC then Fortran is probably the next choice - all programmers are taught C whether they like it or not). I am guessing of course and not disagreeing with your experience just trying to indicate that there may be another explanation.

Mohan Varma October 3, 1999 16:47

Re: 'C' or FORTRAN or 'C++'
Fortran is designed long time ago, and is designed specifically for scientific computing. The advantange of using fortran is the availability of highly optimized compilers. Few language constructs of Fortran and years of experience in using and developing of Fortran compilers made it possible to develop highly optimized compilers. These compilers are generating highly optimzed and faster codes. However it is not easy to develop big projects using Fortran. It takes hell lot of time to do so, and the codes are not easy to understand.

'C' also has a lot of backgroud, and its compilers are also considerably optimized. But the problem with 'C' compilers is that they are not able to produce codes comparable with Fortran codes in performance because of the bulkiness of 'C' language and some of its constructs like pointers. But my experience is that the development of the big projects using 'C' is far more faster than using 'Fortran'. I found that, the C codes are far more easy to understand than Fortran codes.

Coming to 'C++', it is a fairly new language. It is very recent and is specifically designed for building huge projects. It is more for a serious programmer who is involved in generating huge codes. The compilers are yet in development stage and hasn't been optimized properly. Even though these compilers are expected to become better and better, they may not be able to produce codes as fast as codes written in fortran. This is because of some of the constructs of C++ like templates and virtual class tables which require run time decisions and operator overloading which some time leads to highly inefficients codes and its bulkiness. However, recent efforts in development of C++ are focused in improving C++ coding, and some of the new constructs like "expression templates" and "name spaces" are able to make writing efficient codes easier. The recent compilers are generating much more faster codes. The codes written in C++ are much easier to understand.

Coming to Java, the biggest problem is that it is a byte code interpreter and because of it, it is much more slower than any other language. The recent Just-in-Time compilers are much faster and may able to compete with C++ compilers in near future. Some constructs of java, like its Garbage collector, security mechanism and its runtime checking of bounds are making it a lot more slower.

The recent developments in Fortran series, like F90 have neither the performance of Fortran nor the elegance and flexibility of C++ or Java. This is the language which disappointed me very much.

I think the choice of the programming language depends upon the experience of the programmer, the size of the project, and time available for the development. If it is a small project which involves hardly somthing like 5000 lines code, then the programmer can choose the language he likes. Fortran has an edge in this case, if the programmer is either novice or an expert in any of these languages. For handling bigger codes, I feel there is no other option than coding in C++ esp. if the desired development time is less. It's worth learning because having the idea of object oriented programming improves the quality of the codes written in even non-oo languages.

Yogesh Talekar October 4, 1999 01:02

THNAK YOU: 'C' or FORTRAN or 'C++'

Thank you very much for all your valuable suggections. A young beginner like me is always benifitted through such suggestions and discussions.


thank you


clifford bradford October 4, 1999 11:16

Re: 'C' or FORTRAN or 'C++'
i've been told all your points before and i agree with them for the most part but i think you misinterpretted some of my points.

i've been told this about C vs Fortran compilers before and it is probably true for C codes that use a large amount of pointers and large data structures. when i program in C for scientific computing i avoid these and my optimised code tends to perform as well as or better than some of my fortran writing collegues (this is compiler dependent but i get good results with the AIX cc compiler).

your second point is valid and is probably the most important advantage of Fortran over C. but that was not the baggage to while i was referring. what i was referring to was the tendency for fortran programmers to write composite f90/f77 codes which are hard to read. in my opinion 'pure' F90 is not inferior to C in any way but when you start writing hodgepodge code it can become difficult to understand. also many good libraries are available for C now.

my comments about the ease of writing bad fortran is only my experience. it comes from comparing C code i and other grad students write compared to fortran i read from other grad students. to extend this the general programming population would not be appropriate. also some of my colleagues who write fortran tell me the same thing: that they read a lot of poorly written fortran code.

most of my comments are not performance oriented. they center mostly around readability and maintainability of code. yogesh also asked if it made sense for him to learn fortran90 so he could write his own codes. my thinking is that it probably wouldn't make sense to do so since (1)he might end up using some C anyway (since he seems to want to do mesh generation and graphics) (2)it'd take him some time to learn f90 that he could be spending writing code.

John C. Chien October 4, 1999 13:09

Re: 'C' or FORTRAN or 'C++'
(1). You are right, it is extremely important to write the code in a simple, and easy to understand fashion. This will reduce un-necessary errors. (2). It is not a good idea to mix the languages and concepts. (3). Even if one is a professional, the optimized code should be reserved for special occasions. When optimized for speed, the code tends to be very large and less portable. When optimized for memory, the code tends to be very hard to read and can run into trouble easily (such as variables in COMMON used for various definitions in different parts of the code.) (4). A code with complex programming style is hard to read and maintain, and will soon become obsolete.

Rainer Kurz October 4, 1999 18:28

Re: 'C' or FORTRAN or 'C++'
We've decided to use FORTRAN for code development, because evidence suggests that FORTRAN code is easier to read, and more elegant when it comes to programming equations. Lahey , who provide FORTRAN compilers for PC's (they have a web site) can provide evidence that for numerical applications a FORTRAN90 or 95 code runs as fast or faster than C/C++.

Yogesh Talekar October 4, 1999 23:42

Re: 'C' or FORTRAN or 'C++'
Dear Mr. Kurz

Can you tell me the address of the web-site

Thank you


Oliver Gloth October 5, 1999 05:06

Re: 'C' or FORTRAN or 'C++'

We are using C++ for CFD developments. C++, however, has some drawbacks in terms of performance. The reasons for this have been mentioned many times in this discussion, I think. We just dare to be optimistic and hope that this becomes better in the future. There is a growing community using C++, or object oriented programming in general, for numerical purposes (see Our code is public and you might want to take a look at it as well ( There are, however, many things which still have to be done for this code. If you are interested in visualisation take a look at VTK ( which is a C++ visulisation library you can download for free.

Rainer Kurz October 5, 1999 22:06

Re: 'C' or FORTRAN or 'C++'

All times are GMT -4. The time now is 09:14.