HOMEWORK  - FORTRAN Lab 1

You will write your fortran code in stages, a little  at a time.  This is the top-down approach to programming.  To ensure that you do this, I ask that you give a different name to each version of your code.  You must get each version of the code compiled and running, before you enhance the code to create the next version.  This is a form of version control.  This way, the marker can see all the versions of your code, can confirm that each version compiled and ran successfully, and can mark each one separately.  As is stated at the end of this web page, to earn full marks for this assignment, you need to save (and we need to see) all the versions of your code.

The HW assignments for Fortran weeks 1 and 2 all involve the wind-power (wp.f95) fortran code.  We are completing most of these assignments together in class, but there are a few additional ones that you need to finish.  Below are the assignments for FORTRAN week 1.    

Assignment (based on your in-lab work)

  1. In this part, we learn about main programs, writing to the screen, commenting, compiling, and running your code.  You do this by demonstrating that you successfully created the first version of fortran code for wind power, that we all did together during Lab (see online lab PowerPoint notes for detailed instructions).

    We also start by learning about the "emacs" text editing program, and will use emacs to write all our fortran source code.
     
    This first piece of code holds the main fortran program (windpowermain), and writes one line to the screen that says "Welcome to Wind Power".  

    Save this file with the name "wp01.f95" , where the "01" tells me that it is version 1.  

  1. Next, we learn about type declarations.  
  2. Here, we learn about debugging, the value of "version control", and about arrays.  Here is help on interpreting error messages.
  1. Next, we learn about operators and subroutines.  We will divide the whole wind-power problem into smaller parts, each part of which is handled by a separate subroutine.  We will create all needed subroutines, but initially they will be "stubs" that just give debugging printout to the screen to help you see which subroutines are running.  We will also insert into the main program the calls to these subroutines.

    Start by creating a new version of your source code (namely, start with wp03.f95 and Save As wp04.f95).   Again, follow the directions from the PowerPoint slides.  We will make subroutines for :
  2. Next, we learn more about input and output (I/O).  We will learn how to write lines to the screen to prompt the user to enter something, and then read what the user enters.  
    Create a new version 05.  Within subroutine getturbinespecs, we will ask the user to enter the specifications of the wind turbine (its hub height zhub and turbine radius r).  After reading these values, echo (print) them to the screen to ensure the user that the values have been read successfully.  Save, compile, debug, run, debug, save.  Do this as a new version (version 05).  See PowerPoints from lecture to learn details.  
  3. Similar to the previous exercise, but as a new version 06, in subroutine getsounding prompt the user to enter the name of the file holding the sounding (the list of winds at different heights), and then read that name as a variable called soundingfilename, and echo it to the screen.  Save, compile, debug, run, debug, save.  Do this as a new version (version 06).  See PowerPoints from lecture to learn details.  At this stage, we are just asking for the name of the sounding file, but are not opening or reading it.
  4. Next, learn about opening data files that are on disk.  (See details in PowerPoints for lab).  Do this as a new version 07.  In the getsounding subroutine, open the file that is saved in the soundingfilename variable, and display any I/O error flag to the screen.  Save, compile, debug, run, debug, save.
  5. Next, learn about conditionals (if tests).    (See details in PowerPoints for lab).  Do this as a new version 08.  In the getsounding subroutine, add code to use the I/O error flag, and write one statement to the screen if the file was not openable, and write a different statement if the file was openable.  Save, compile, debug, run, debug, save.
  6. Similar to the previous exercise, but as new version 09.   In subroutine getturbinespecs, add code to check that the turbine blade radius is less than the the hub height (because if the blade radius is too long, then the blade will hit the ground).  If the radius is too large, allow the user to enter a new radius.  Save, compile, debug, run, debug, save.
  7. Next, learn about "while" loops, and about reading lines from disk files.  As new version 10, modify getsounding to create a loop to read every line of the file, check for I/O errors (and exit the loop if it is an error), and write each line to the screen as you read it.  (see PowerPoint for details).  Save, compile, debug, run, debug, save.
  8. Learn about the "do while" loop, and use it in getturbinespecs to allow the user to continue entering new turbine radius values until a valid one is finally entered.  This is version 11  (see PowerPoint for details).  Save, compile, debug, run, debug, save.
  9. Learn about counting do loops, and about rewinding the disk file.  As version 12, add code to getsounding to reset the file back to the beginning, and read only the first 5 lines of the file.  (These are the heading lines that don't have any sounding numbers in them, so this counting do loop allows us to skip past them.)

Marking:

The bottom line is that we will look for the following files in the "fortran" directory under your user directory on eidolon:

  1. Twelve ascii text files holding your fortran code versions:
  2. ... and twelve executable files:

Deadline is 11:59 pm on Friday at the end of the Fortran-1 week.  The marker will grade your work by looking at EACH of your fortran wp versions on eidolon, and compiling them himself/herself to be sure they run.  Also, marks will be deducted if your code is not adequately documented with in-line comments.  See the online PowerPoint lab notes for details.  

It is important that you finish all 12 steps by the start of the next week of FORTRAN, because we will expand upon this past work to continue writing the wind-power program.

Hints:


Reading Assignment  

-end-


Copyright © 2010 by Roland Stull.
UBC.