LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   FORTRAN? Any reason to learn it? (https://www.linuxquestions.org/questions/programming-9/fortran-any-reason-to-learn-it-4175608371/)

rtmistler 06-23-2017 07:56 AM

I learned FORTRAN in college. I've always been given the perception that it's better for scientific and mathematics computations.

I personally have always used C and assembler. The original DSP chips were always assembler. These days, I use C and C++ for signal processing code.

The varieties of computing I've done have been digital filtering, and NxM complex matrices upwards of 16x16. Never had any problems with finding available instructions in a language or CPU instruction set. For a period of time it was important to pay attention to fixed vs. non-fixed calculation types because of the processors used. Slowly fixed vs. non-fixed became less of an issue. It always is an issue to pay attention to maintaining precision, however I do not feel that FORTRAN specifically helps there. In other words, you divide by a large number, but then need to multiply back, such as divide by 8 then multiply by 7, the risk is that you do the divide first you truncate by right shifting, however if you multiply first you run the risk of overflowing. Various solutions are there, such as using larger variable types than needed to avoid OV, shifting over in advance so the divides do not truncate and then adjusting at the end of the calculations.

The impressions I've been led to are that for things like astronomical calculations, FORTRAN is the language of choice. However the two or three things I've noticed are that physicists, thereby some of them involved with astronomy, who do have large calculations, also have legacy functions, macros, or computing methods, and have kept FORTRAN code around because it started there and they do not wish to rock the boat to reinvent the wheel. I do not argue their validity if the work is sufficiently complicated. The other observation is that where they'll do modelling of things with numerous and huge variables, like flow of something around something, be that ions around spacecraft, water around submarines and propellers, or airflow around planes or various parts of planes ... well who's going to argue that we need to throw out these well refined libraries or collections of code which have been proven to be correct for 50+ years? And if it is in FORTRAN, then it stays in place. That is a "perception" I've been led too when the subject of FORTRAN comes up and the very invested supporters of it defend the retention of FORTRAN. I may be incorrect with my perceptions.

It is a perfectly valid programming language.

Problem is that it seems rare, tools for it seem rare, but they do exist. I mainly do see very old code and the related problems are that someone can't find an interpreter/compiler for it for a certain machine type and they need to/want to because they wish to maintain the very old code collections they have.

Long winded, yes.

Shorter answer is .... "You know C? I feel you can contend with FORTRAN very easily since I feel the languages are highly similar."

I do not feel there is a compelling reason to learn FORTRAN for the sake of it, and can guarantee you that I've forgotten all of it from college.

I also feel that if you do get involved with one of the situations involving very intense mathematical computations and they are using FORTRAN:
  1. Your existing C knowledge will help you fine and you'll come up to speed with the language rapidly
  2. FORTRAN will be the LEAST of your problems! Unless you are a real mathematician, your problem will be contending with the mathematicians. To the effect that if you change anything, you best be 100.000000% correct! :D Sorry, no insult intended to anyone, I'm clearly someone who decided long ago that I'm never going to argue math with a mathematician, because I'm never going to be that good to contend with them.
EDIT: The amazing thing is I can probably head down to my basement and dig out my FORTRAN book from 30 years ago! :p

sundialsvcs 06-23-2017 08:34 AM

I think that it's always sensible to be aware of other programming technologies, old and new, because you never know when you're going to encounter one. Of course, compilers and language-design are a "special interest" to me anyway. But, that doesn't mean that you actually have to immerse yourself in the process without actual provocation.

Laserbeak 06-23-2017 09:06 AM

I was playing around with it last night and found it to be quite interesting... I'm going to work on making a FORTRAN version of that Narcissistic Number thing. It seems like it'll be easier in FORTRAN than in C.

makyo 06-24-2017 10:58 AM

Hi.

Agree with "it depends on your goal", and generally with "scientific and engineering problems".

However, there are many modern languages to learn that may be more useful. I have a grep work-alike that is written on Go, and it is the fastest of the grep family so far: https://sift-tool.org/

I had forgotten that I had written a short note https://groups.google.com/forum/#!to...an/t3HtW-YpIxc , mentioning that I had implemented many of the Software Tools in MNF/M77 from RATFOR, translating while I was typing -- not that I'm so good, but that it was just that easy provided one knew Fortran.

I also had written "the longest SNOBOL program ever written" ( according to a languages colleague -- probably a slight exaggeration :) ) that translated PL/1 into Fortran.

These days, one can crack CLI arguments, call C codes, etc., from Fortran (see below). A good book if you are serious about Fortran is https://www.amazon.com/Explained-Num...dp/0199601429/ although one might want a tutorial and practice if one does not know anything about Fortran.

As with any language, once you have written 100 non-trivial programs, you probably have a good foundation in it.

Best wishes ... cheers, makyo

Code:

program f1

! @(#) f1      Demonstrate Fortran-90.

! http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gfortran/
!  GET_005fCOMMAND.html TRIM.html GET_005fCOMMAND_005fARGUMENT.html

    integer :: i
    character (len=32) :: arg
    integer :: count
    character (len=255) :: cmd, line
!1234567890123456789012345678901234567890123456789012345678901234567890
! Default unit numbers:  0 STDERR, 5 STDIN, 6 STDOUT
! open(0,file="/dev/null")        ! comment out to get debugging output
    call get_command (cmd)
    write (0,*) " Command line  = ", trim (cmd)

    count = command_argument_count ()
    write (line, fmt="(a,i2)") " Argument count = ", count
    write (0,*) trim (line)

    if (count <= 0) then
      write (0,*) " Hello, world from Fortran-90."
    else
      do i = 1, count
        call get_command_argument (i, arg)
        write (line, fmt="(a,i2,a,a,a)") " Argument    ", i, " = ", trim &
      & (arg)
        write (0,*) trim (line)
      end do
    end if
!234567890123456789012345678901234567890123456789012345678901234567890
    do 11111 i = 1, 3
      write (*,*) " i = ", i
11111 continue
end


Laserbeak 06-26-2017 05:47 AM

I did come up with the basic "Armstrong number" program as posted here:

http://www.linuxquestions.org/questi...ml#post5726989

But it isn't very elegant and limited to the original description + 99 :)


All times are GMT -5. The time now is 11:40 AM.