Fortran Programming

In my last semester of college, I decided to take a class in Fortran programming just for fun (because who really uses Fortran anymore). The following is a collection of the projects I completed during said class; they range from simple I/O programs to data structure manipulation programs. Documentation for these programs is also provided where available. All programs were compiled using Absoft’s Fortran compiler for Windows, and as such I can only guarantee successful compilation on that platform. If you’ve had success or failure with other compilers, please leave a comment regarding it.

I’m mainly making this code available because I was appalled by the lack of Fortran examples there are on the web. If you need further help with the language, I’d recommend obtaining a copy of the Fortran 90 Handbook (ISBN 0070004064); it’s particularly useful when trying to figure out the archaic I/O and formatting options.

Projects

  • Arithmetic #1
    Files: Code
    Simple program that adds two numbers then outputs
  • Arithmetic #2
    Files: Code

    Simple program that adds and subtracts two numbers then outputs
  • Pythagorean Triples
    Files: Code

    Calculates Pythagorean Triples from input given
  • Triangle Perimeter and Area
    Files: Code

    Calculates triangle perimeter and area from input given
  • Triangle Validity and Typing
    Files: Code

    Determines from given input whether a triangle is valid or not and, if so, what its type is (i.e. equilateral, isosceles, or scalene)
  • Fibonacci with Do Loops
    Files: Code

    Outputs X number of terms in the Fibonacci Sequence
  • Fibonacci with Do Loops continued
    Files: Code

    Same as the last program except that output is formatted and also contains the ratio between two terms
  • First 10 Partial Sums of 1/k!
    Files: Code

    Outputs the first ten partial sums of the series 1/k! (1 divided by k factorial) with formatting
  • Multiplication and Division Formatting
    Files: Code

    Outputs the product, quotient, and remainder of the given input with heavy formatting
  • Bacterial Growth
    Files: Code

    Calculates the population of bacteria given a certain starting count and growth rate
  • Student Record GPA Calculator with File I/O
    Files: Code

    Reads a data file of student course records and writes a file with calculated GPA
  • Round Function
    Files: Code

    Uses a custom round function to output some rounded test numbers
  • Prime Test Function
    Files: Code

    Tests if the given input number is a prime number using a custom function
  • Perfect Square Test Function
    Files: Code

    Tests if the given input number is a perfect square using a custom function
  • L-Grid Path Counter
    Files: Code | Documentation

    Recursively finds the number of paths through an L-shaped grid (square grid with an area removed from the upper right) from the upper left to the bottom right
  • Drunkard’s Walk
    Files: Code | Pseudo-code | Documentation

    Calculates several statistics for X runs of the Drunkard’s Walk algorithm
  • Shell Sort
    Files: Code | Documentation

    Creates a random array of numbers and then uses a shell sort subroutine to sort them
  • Magic Square
    Files: Code

    Uses a recursive function to generate a Magic Square
  • Angle Class
    Files: Test Program | Class Module | Documentation

    Tests a class (or the best equivalent to a class in Fortran) for working with angle data, which includes operator overloads and constructors
  • Random Binary File
    Files: Main Program | Random Number Module | Documentation

    Writes an array of random numbers to both a text and binary file
  • Random Binary File Reader
    Files: Code | Documentation

    Outputs every 100th record from a binary file (typically created with the previous program)
  • Random Binary File Search
    Files: Code | Documentation

    Looks for records in a binary file that match the given input
  • Queue Class
    Files: Test Program | Class Module | Documentation

    Tests a class that implements a queue–uses pointers, of course
  • Huffman Encoding/Decoding
    Files: Source Archive | Library Module | Documentation

    A series of test programs that call subprograms in a library module to perform the various steps of Huffman Encoding: counting the number of character occurrences, building a tree, encoding, and decoding. (Unfortunately, the decoding portion wasn’t completed due to end-of-semester time constraints.)

Download

All the source code and documentation from this page is available in the following archive:

340

Fortran Source

103 kB - ZIP

4 Responses to Fortran Programming

  1. Mick AUS says:

    Hey mate,

    Just wanted to say thanks for putting up your Fortran examples. I’m doing a Fortran course at Uni at the moment and our lecturer is a bit sparse on providing examples and the few he does put up don’t seem to compile so it’s really hard to get anything to work.

    I’m managing to work it out though because of the stuff you’ve put up, helped clear up a lot of things he left out. Thanks again.

  2. Krishna Kiran IND says:

    Hello

    I found your website on the web while I was searchin for the magic squares program in fortran.

    I did try your code, it gives me an error something like.’ severe segmentation fault’ ; did u get this error too?
    also iam trying to use compile it as .f90 file..is tht the problem?

    BTW..you do have a very cool website…

    Ill appreciate your help in this regard.

    Best Regards

    • Snake USA says:

      hi krishna,
      your problem is probably completely to do with the compiler. i used Absoft’s fortran compiler for windows, so that’s all i can guarantee. but i don’t see why any standards-based compiler like gfortran wouldn’t work. i should probably add a note about my compiler on the webpage, though.

      i would just attempt to isolate the error-producing code (e.g. using periodic prints) and then find a workaround that pleases your compiler. my guess would be around the array allocation. please let me know if you find anything out so i can note it in the source code.

      good luck

      also, i just noticed an error in my code at line 58. i’m betting that’s supposed to be:
      else if (y > square_size) then
      but as i note in the comments, that statement is probably inconsequential.

Leave a Reply