{"id":14140,"date":"2026-05-13T03:00:00","date_gmt":"2026-05-13T07:00:00","guid":{"rendered":"https:\/\/www.both.org\/?p=14140"},"modified":"2026-05-02T19:31:25","modified_gmt":"2026-05-02T23:31:25","slug":"a-look-back-f2c","status":"publish","type":"post","link":"https:\/\/www.both.org\/?p=14140","title":{"rendered":"A look back: f2c"},"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=\"14140\" 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 an undergraduate physics student in the early 1990s, the standard programming language for scientific programming was FORTRAN 77. Actually, Fortran 90 (with the new capitalization) had just been released around that time, but my university still used FORTRAN 77.<\/p>\n\n\n\n<p>Every physics student in my program had to learn FORTRAN 77 to do their lab analysis. Not everything can be done in a spreadsheet; if you needed to discover the parameters of a damped pendulum, the best way to do that was to enter the data and run a <em>numerical analysis<\/em> where you can tweak the parameters until the simulation matches the data you collected. And while you could probably do that in C, it was much easier to do it using FORTRAN 77.<\/p>\n\n\n\n<p>At university, I had a few accounts on the campus computer labs: the VAX lab where the FORTRAN compiler was installed, and the Unix lab where we had a C compiler. I also ran DOS at home, and dual-booted into Linux, but I only had a C compiler: Turbo C on DOS, and GCC on Linux. It would be years before GNU added <strong>gfortran<\/strong> to compile FORTRAN programs.<\/p>\n\n\n\n<p>The only reason I had an account on the VAX was to write FORTRAN 77 programs. The systems administrator said it was too expensive to purchase a FORTRAN compiler for the Unix systems. If I wanted to work on FORTRAN programs for my lab analysis, <em>I was stuck using the VAX.<\/em><\/p>\n\n\n\n<p>That is, until I discovered an early open source program called <a href=\"http:\/\/www.netlib.org\/f2c\/\">f2c<\/a> from Bell Labs. As the name might imply, <strong>f2c<\/strong> converted FORTRAN programs to C. You weren&#8217;t meant to <em>maintain<\/em> the generated C source files, it was an intermediate step to compile FORTRAN programs with just a C compiler. That meant I could finally compile FORTRAN 77 programs on my Linux system, using <strong>f2c<\/strong> to convert the original source and GCC to compile it into a program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"exploring-the-past\">Exploring the past<\/h2>\n\n\n\n<p>I thought it would be fun to go back and explore <strong>f2c<\/strong> on modern Linux. While GNU has since released <strong>gfortran<\/strong> to compile new-style Fortran and old-style FORTRAN programs, I think it&#8217;s good to see what programming looked like in the early days of Linux.<\/p>\n\n\n\n<p>Download both <strong>src.tgz<\/strong> and <strong>libf2c.zip<\/strong> from the <a href=\"http:\/\/www.netlib.org\/f2c\/\">f2c<\/a> repository at Netlib, and extract them on your system. Note that <strong>src<\/strong> is a <strong>gzip<\/strong>-compressed tar file (tgz) and <strong>libf2c<\/strong> is a zip file. It doesn&#8217;t matter where you extract these; I unpacked them in the <em>Downloads<\/em> folder where I downloaded the files:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ tar xzf src.tgz\n$ unzip -q libf2c.zip -d libf2c<\/code><\/pre>\n\n\n\n<p>The zip file doesn&#8217;t contain a directory, so you need to tell the <strong>zip<\/strong> program where to put the files using the <code>-d<\/code> option. The extra <code>-q<\/code> option is to make the program run <em>quietly<\/em>; otherwise, <strong>unzip<\/strong> will print the filenames as they are extracted from the zip file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"the-f2c-library\">The f2c library<\/h3>\n\n\n\n<p>Go into the <code>libf2c<\/code> directory, which is the source to the <code>f2c<\/code> library. The <code>README<\/code> file is usually where you learn how to compile a program. However, this <code>README<\/code> was written at a time when Linux was still quite &#8220;young,&#8221; so it has a few unnecessary steps to compile on a modern Linux system. These are the steps I used:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Copy the <code>makefile.u<\/code> file to <code>Makefile<\/code><\/li>\n\n\n\n<li><code>make hadd<\/code> (this creates the <code>f2c.h<\/code> file)<\/li>\n\n\n\n<li><code>make<\/code> (this creates the <code>libf2c.a<\/code> library)<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"the-f2c-program\">The f2c program<\/h3>\n\n\n\n<p>Now go into the <code>src<\/code> directory, which has the source to the <strong>f2c<\/strong> program. Again, the <code>README<\/code> file here is a bit dated, and isn&#8217;t correct for a modern Linux system. Fortunately, compiling <strong>f2c<\/strong> requires just two steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Copy the <code>makefile.u<\/code> file to <code>Makefile<\/code><\/li>\n\n\n\n<li><code>make<\/code> (this creates the <strong>f2c<\/strong> program)<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"compiling-a-fortran-program\">Compiling a FORTRAN program<\/h2>\n\n\n\n<p>Let&#8217;s see how to compile a FORTRAN 77 using <strong>f2c<\/strong>, just like it was the early 1990s. FORTRAN 77 was a popular programming language for scientific computing because the language made it very easy to translate equations and other mathematical statements into computer code; the &#8220;FORTRAN&#8221; name is an abbreviation of <strong>for<\/strong>mula <strong>tran<\/strong>slation.<\/p>\n\n\n\n<p>FORTRAN 77 and earlier versions of the language used a strict column syntax: <code>C<\/code> or <code>*<\/code> in column 1 meant the line was a comment. Columns 1 to 5 were otherwise reserved for numbers, which were used as <em>line labels<\/em>. Almost any character in column 6 indicated a <em>continuation<\/em> line; this line was &#8220;glued&#8221; to the line before it. Program instructions went in columns 7 to 72; columns 73 and beyond were ignored.<\/p>\n\n\n\n<p>With this basic understanding of FORTRAN&#8217;s columns, we can write a simple test program. This program prints the numbers 1 to 10, as <em>double precision<\/em> floating point values, plus the <em>square root<\/em> for each:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      PROGRAM LOOP\n      DOUBLE PRECISION X\n      X=1D0\n\n10    PRINT 99, X, DSQRT(X)\n99    FORMAT(F6.3,' ',F6.3)\n\n      X = X + 1D0\n      IF (X.GT.10D0) GOTO 20\n      GOTO 10\n\n20    END<\/code><\/pre>\n\n\n\n<p>I saved my sample program as <code>loop.f<\/code> in my <em>Downloads<\/em> folder, which has the <code>libf2c<\/code> and <code>src<\/code> directories for the <strong>f2c<\/strong> library and program. That makes it easy to reference the <strong>f2c<\/strong> program when I compile my test program, as well as the <code>f2c.h<\/code> header file and the <code>libf2c.a<\/code> library:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ src\/f2c loop.f\nloop.f:\n   MAIN loop:\n\n$ gcc -I.\/libf2c -L.\/libf2c -o loop loop.c -lf2c -lm<\/code><\/pre>\n\n\n\n<p>While not every program requires the <code>m<\/code> (<em>math<\/em>) library, it&#8217;s good practice to include <code>-lm<\/code> to link your FORTRAN 77 programs anyway. The <em>math<\/em> library won&#8217;t be used if it&#8217;s not needed, and it&#8217;s there for the programs that use certain functions like <code>SQRT<\/code>.<\/p>\n\n\n\n<p>With these two commands, I&#8217;ve successfully compiled a FORTRAN 77 program using the <strong>f2c<\/strong> translator and the GCC compiler. The output prints the numbers from 1 to 10 and their <em>square root<\/em>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ .\/loop\n 1.000  1.000\n 2.000  1.414\n 3.000  1.732\n 4.000  2.000\n 5.000  2.236\n 6.000  2.449\n 7.000  2.646\n 8.000  2.828\n 9.000  3.000\n10.000  3.162<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"fortran-on-early-linux\">FORTRAN on early Linux<\/h2>\n\n\n\n<p>The <strong>f2c<\/strong> program made it possible to compile FORTRAN 77 programs on Linux, even though I didn&#8217;t actually have a FORTRAN 77 compiler. The <strong>f2c<\/strong> program converted the FORTRAN 77 code into C, which could be compiled using GCC, <em>as long as you provided the<\/em> <code>f2c.h<\/code> <em>header file and<\/em> <code>libf2c.a<\/code> <em>library file.<\/em> Compiling was always a two-step process: convert, then compile. But it was a simple series of steps that could be easily managed, either with a clever Makefile or Bash script.<\/p>\n\n\n\n<p>If you don&#8217;t want to provide the path to the <em>header<\/em> file (with <code>-I<\/code>) or the path to the <em>library<\/em> file (with <code>-L<\/code>) then you can install the files into the <em>systemwide<\/em> directories. I don&#8217;t recommend installing them to <code>\/bin<\/code> or <code>\/usr\/include<\/code> or <code>\/usr\/lib<\/code>, since those are best reserved for <em>system-installed<\/em> programs and libraries. Instead, put them under <code>\/usr\/local<\/code>, where you would usually expect to copy <em>local<\/em> programs and libraries. You can do that as root using the <strong>install<\/strong> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo install src\/f2c \/usr\/local\/bin\/f2c\n$ sudo install libf2c\/f2c.h \/usr\/local\/include\/f2c.h\n$ sudo install libf2c\/libf2c.a \/usr\/local\/lib\/libf2c.a<\/code><\/pre>\n\n\n\n<p>With these files installed in the correct locations, and assuming you have <code>\/usr\/local\/bin<\/code> in your <code>PATH<\/code> variable, you should be able to compile any FORTRAN 77 program without the extra paths:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ f2c loop.f\nloop.f:\n   MAIN loop:\n\n$ gcc -o loop loop.c -lf2c -lm\n\n$ .\/loop\n 1.000  1.000\n 2.000  1.414\n 3.000  1.732\n 4.000  2.000\n 5.000  2.236\n 6.000  2.449\n 7.000  2.646\n 8.000  2.828\n 9.000  3.000\n10.000  3.162<\/code><\/pre>\n\n\n\n<p>That&#8217;s how I compiled my FORTRAN 77 programs as an undergraduate student, from the comfort of my Linux system at home. Using <strong>f2c<\/strong> meant I could edit and run FORTRAN 77 programs using my own computer, which was usually faster than the VAX system because I was the only person using it. That was a huge step forward for Linux to run like the <em>Big Unix<\/em> systems, without buying an expensive FORTRAN 77 compiler. That&#8217;s the power of open source, and one more reason that Linux continued to impress me in those early days.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I was an undergraduate physics student in the early 1990s, the standard programming language for scientific programming<\/p>\n","protected":false},"author":33,"featured_media":3545,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[798,106,5],"tags":[522,91],"class_list":["post-14140","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-fortran-77","category-history","category-linux","tag-fortran77","tag-linux"],"modified_by":"Jim Hall","_links":{"self":[{"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14140","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=14140"}],"version-history":[{"count":1,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14140\/revisions"}],"predecessor-version":[{"id":14141,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/posts\/14140\/revisions\/14141"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=\/wp\/v2\/media\/3545"}],"wp:attachment":[{"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.both.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}