{"id":14100,"date":"2026-05-06T03:00:00","date_gmt":"2026-05-06T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14100"},"modified":"2026-04-25T19:01:27","modified_gmt":"2026-04-25T23:01:27","slug":"5-things-to-know-when-learning-fortran-77","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14100","title":{"rendered":"5 things to know when learning FORTRAN 77"},"content":{"rendered":"<div class=\"pld-like-dislike-wrap pld-template-1\">\r\n    <div class=\"pld-like-wrap  pld-common-wrap\">\r\n    <a href=\"javascript:void(0)\" class=\"pld-like-trigger pld-like-dislike-trigger  \" title=\"\" data-post-id=\"14100\" data-trigger-type=\"like\" data-restriction=\"cookie\" data-already-liked=\"0\">\r\n                        <i class=\"fas fa-thumbs-up\"><\/i>\r\n                <\/a>\r\n    <span class=\"pld-like-count-wrap pld-count-wrap\">    <\/span>\r\n<\/div><\/div>\n<p>When I was a physics undergraduate in the early 1990s, FORTRAN 77 was the standard programming language for <em>scientific computing<\/em>. The Fortran 90 specification had just been published, but new compilers that supported the new standard were quite expensive, so FORTRAN 77 was what we learned. Every physics student at my university was required to learn FORTRAN 77 programming so we could write our own programs to help analyze lab data, such as numerical solutions to certain lab problems (like a circular pendulum under friction) that couldn&#8217;t otherwise be solved in a spreadsheet.<\/p>\n\n\n\n<p>By the time I graduated in the mid 1990s, I had picked up a few other programming languages, such as C for <em>systems programming<\/em>. Since I didn&#8217;t go into a &#8220;lab&#8221; career, I assumed I would never write another FORTRAN 77 program.<\/p>\n\n\n\n<p>But what&#8217;s old is new again. A few years ago, I started seeing more posts from people who were curious to learn this &#8220;antique&#8221; programming language. And to be fair, FORTRAN 77 is quite old; each &#8220;iteration&#8221; of the language since FORTRAN 66 indicates the year the standard was adopted: FORTRAN 66 in 1966, FORTRAN 77 in 1977, Fortran 90 (with a new capitalization) in 1990, then Fortran 95, Fortran 2003, Fortran 2008, Fortran 2018, and Fortran 2023. I don&#8217;t know any of these more recent versions of Fortran, but I still remember a few things about FORTRAN 77 programming. If you&#8217;re interested in learning FORTRAN 77, here a few things to know:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"programs-are-column-sensitive\">1. Programs are column sensitive<\/h2>\n\n\n\n<p>Original FORTRAN programs were loaded into a computer using a stack of <em>punched cards<\/em>. These cards stored only 80 columns of text, which isn&#8217;t a lot. To get the most out of each &#8220;line&#8221; on a card, FORTRAN adopted a column specific syntax:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A <code>*<\/code> or <code>C<\/code> in column 1 is a comment<\/li>\n\n\n\n<li>Otherwise, columns 1-5 are reserved for line labels (numbers only)<\/li>\n\n\n\n<li>Almost any character in column 6 indicates a <em>continuation<\/em> from the previous line<\/li>\n\n\n\n<li>Columns 7-72 are for program statements<\/li>\n\n\n\n<li>Columns 73 and beyond are ignored (these were reserved for <em>card sorting<\/em>, to put a deck back into order if you dropped it)<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"767\" height=\"345\" src=\"http:\/\/www.both.org\/wp-content\/uploads\/2026\/04\/f77card.png\" alt=\"Fortran punch card showing a single Format statement\" class=\"wp-image-14102\"\/><figcaption class=\"wp-element-caption\">A sample FORTRAN 77 punched card<\/figcaption><\/figure>\n\n\n\n<p>FORTRAN 77 only recognizes upper case letters and a few standard symbols. For example, here&#8217;s a simple program that prints the text <code>HELLO WORLD<\/code>, but splits the <code>PRINT<\/code> instruction across two lines. This is a really awkward way to write this program, since the lines are so short they don&#8217;t need to be split, but it shows how to use continuation lines:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM HELLO\nC PRINT A MESSAGE\n      PRINT *,\n     +'HELLO WORLD'\n      END<\/code><\/pre>\n\n\n\n<p>Save this as <code>hello.f<\/code> and compile it using a FORTRAN 77 compiler such as GNU Fortran on Linux or Open Watcom FORTRAN on FreeDOS. To install GNU Fortran, install the <strong>gcc-gfortran<\/strong> package. Compile the program like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gfortran -std=legacy -o hello hello.f<\/code><\/pre>\n\n\n\n<p>The <code>-std=legacy<\/code> command line option tells GNU Fortran to use the old-style FORTRAN syntax, which is what you need to compile FORTRAN 77 programs. This should give you a program called <strong>hello<\/strong> that you can run to print the text:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/hello\n HELLO WORLD<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"do-loops-have-a-specific-syntax\">2. <code>DO<\/code> loops have a specific syntax<\/h2>\n\n\n\n<p>One feature I actually really like in FORTRAN is the <code>DO<\/code> loop. To me, it&#8217;s somewhat reminiscent of the <code>for<\/code> loop in BASIC, but with a tidy syntax. To create a loop across a range of values, specify the start, end, and &#8220;step&#8221; values, separated by commas. The loop will execute between the <code>DO<\/code> statement and the line label you indicate as part of the <code>DO<\/code> statement.<\/p>\n\n\n\n<p>Here&#8217;s an example program that counts the numbers from 2 to 10, counting &#8220;up&#8221; by 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM COUNT\n      INTEGER I\n      DO 10 I = 2, 10, 2\n10    PRINT *, I\n      END<\/code><\/pre>\n\n\n\n<p>If you save this as <code>count.f<\/code>, compile it, and run it, you will see a list of numbers from 2 to 10, even numbers only:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gfortran -std=legacy -o count count.f\n$ .\/count\n           2\n           4\n           6\n           8\n          10<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"there-is-no-while-loop\">3. There is no <code>WHILE<\/code> loop<\/h2>\n\n\n\n<p>FORTRAN 77 has very few loop structures. The <code>DO<\/code> loop is the equivalent of the <code>for<\/code> loop in other programming languages. One loop feature that&#8217;s missing in FORTRAN 77 is a <code>while<\/code> loop. Instead, you have to &#8220;build&#8221; it yourself with a <code>GOTO<\/code> statement.<\/p>\n\n\n\n<p>For example, let&#8217;s rewrite the <code>count.f<\/code> program to use a <code>while<\/code>-like loop. In this kind of loop, the program <em>starts<\/em> with a current value, and continues the loop only <em>while<\/em> a condition is met. In this case, the &#8220;end&#8221; value should be less than or equal to 10:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM WHILE\n      INTEGER I\n      I=2\n20    PRINT *, I\n      I=I+2\n      IF (I.LE.10) GOTO 20\n      END<\/code><\/pre>\n\n\n\n<p>This has a few extra lines in it, but it otherwise does the same thing as the <code>count.f<\/code> program. Note that it starts the <code>I<\/code> variable with the value 2. Then the program prints the new value and increments <code>I<\/code> by 2. If the <code>I<\/code> variable is <em>less than or equal to<\/em> (<code>.LE.<\/code>) 2, then the program jumps back to line label 20, which prints the value. And so on until the program prints 10, then <code>I<\/code> is incremented to 12, which no longer meets the <code>IF<\/code> condition, so the program ends.<\/p>\n\n\n\n<p>Save this program as <code>while.f<\/code> and compile it to see the list of numbers from 2 to 10, even numbers only:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gfortran -std=legacy -o while while.f\n$ .\/while\n           2\n           4\n           6\n           8\n          10<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"double-precision-values-are-handy\">4. <code>DOUBLE PRECISION<\/code> values are handy<\/h2>\n\n\n\n<p>FORTRAN has the expected variable types like integers, floating point values, characters, and strings. These are useful in many kinds of programs. But as a physics student, we used FORTRAN 77 to perform lab analysis, and that required higher precision than <code>REAL<\/code>, the standard floating point variable type.<\/p>\n\n\n\n<p>Instead, we used <code>DOUBLE PRECISION<\/code> variables. Since FORTRAN doesn&#8217;t treat spaces with any special value, you might also see this variable type written as one word: <code>DOUBLEPRECISION<\/code>. Double precision variables look like floating point values, in that they have a decimal point, but you need to be careful. The calculation <code>1.0 \/ 3.0<\/code> to divide 1 by 3 is actually division between two <code>REAL<\/code> values. To ensure that values are treated as <code>DOUBLE PRECISION<\/code>, you need to add the <code>D<\/code> exponent.<\/p>\n\n\n\n<p>For example, for the number <strong>100<\/strong>, you could also hand-write that as &#8220;1 x 10^2&#8221; or &#8220;1 times 10-squared.&#8221; Using &#8220;engineering&#8221; notation, you would type that as <code>1E2<\/code>, because the <code>E<\/code><em>n<\/em> means &#8220;x 10^n&#8221;. To make that a <code>DOUBLE PRECISION<\/code> value, replace <code>E<\/code> with <code>D<\/code>.<\/p>\n\n\n\n<p>Here&#8217;s a short program that shows the same calculation for one-third, using <code>REAL<\/code> and <code>DOUBLE PRECISION<\/code> values:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM THIRD\n      REAL A\n      DOUBLE PRECISION X\nC REAL VARIABLE CALCULATION\n      A = 1.0\n      A=A\/3.0\n      PRINT*,A\nC DOUBLE PRECISION VARIABLE CALCULATION\n      X = 1.0D0\n      X=X\/3.0D0\n      PRINT*,X\n      END<\/code><\/pre>\n\n\n\n<p>Save this as <code>third.f<\/code> and compile it using GNU Fortran. When you run the program, you&#8217;ll first see the one-third calculation as performed with <code>REAL<\/code> values, then <code>DOUBLE PRECISION<\/code> values. The results are slightly different:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gfortran -std=legacy -o third third.f\n$ .\/third\n  0.333333343\n  0.33333333333333331<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"formatted-output-with-format\">5. Formatted output with <code>FORMAT<\/code><\/h2>\n\n\n\n<p>Using the <code>*<\/code> in the <code>PRINT<\/code> statement indicates that the program should print values using a &#8220;default&#8221; format. That means <code>REAL<\/code> and <code>DOUBLE PRECISION<\/code> values will be printed using whatever number of decimal places the compiler chooses.<\/p>\n\n\n\n<p>If you want more control over how your values are printed, use the <code>FORMAT<\/code> statement. This is a special line in a FORTRAN program that doesn&#8217;t actually do anything, but is <em>referenced<\/em> as the format that the <code>PRINT<\/code> statement should use to print values.<\/p>\n\n\n\n<p>Here&#8217;s the same one-third program, adding a <code>FORMAT<\/code> statement. Note that <code>FORMAT<\/code> statements can go anywhere in a program where you can otherwise use a program statement, but most programmers put them towards the end of a program:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM THIRD\n      REAL A\n      DOUBLEPRECISION X\nC REAL VARIABLE CALCULATION\n      A = 1.0\n      A=A\/3.0\n      PRINT 99,A\nC DOUBLEPRECISION VARIABLE CALCULATION\n      X = 1.0D0\n      X=X\/3.0D0\n      PRINT 99,X\n99    FORMAT(F6.4)\n      END<\/code><\/pre>\n\n\n\n<p>The <code>F6.4<\/code> format specification says that this is a <em>floating point<\/em> value that is 6 characters wide, with 4 digits after the decimal place. That means one-third should be printed as <strong>0.3333<\/strong> because that&#8217;s 6 digits, with 4 digits after the decimal.<\/p>\n\n\n\n<p>Save this new program as <code>thirdf.f<\/code> and compile it to see the numbers printed using a formatted output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ gfortran -std=legacy -o thirdf thirdf.f\n$ .\/thirdf\n0.3333\n0.3333<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>FORTRAN 77 is an old programming language, but it can solve a lot of interesting math programs in a way that might be difficult in other programming languages. After all, the name literally means &#8220;<strong>for<\/strong>mula <strong>tran<\/strong>slation.&#8221;<\/p>\n\n\n\n<p>And while there are more recent versions of the Fortran language, &#8220;retro programming&#8221; means that FORTRAN 77 has become popular again. Maybe it&#8217;s time you tried writing your first FORTRAN 77 program.<\/p>\n\n\n\n<p>To learn more about the FORTRAN 77 programming language, check out Oracle&#8217;s complete <a href=\"https:\/\/docs.oracle.com\/cd\/E19957-01\/805-4939\/index.html\">FORTRAN 77 programming reference<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I was a physics undergraduate in the early 1990s, FORTRAN 77 was the standard programming language for<\/p>\n","protected":false},"author":33,"featured_media":2803,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[798,5,150],"tags":[147,152],"class_list":["post-14100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fortran-77","category-linux","category-programming","tag-fun","tag-programming"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14100"}],"version-history":[{"count":2,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14100\/revisions"}],"predecessor-version":[{"id":14103,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14100\/revisions\/14103"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/2803"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}