LAB #2


Objectives


Tasks

  1. Set up the development environment as explained in Lab1 (ending with an editor window and a DOS window).
  2. Type the following program in the editor exactly as shown:
    program Convert
    implicit none
    ! -----------------------------------------------Declare
    real*4 tempC, tempF, FACTOR
    integer*2 ZERO_SHIFT
    parameter (ZERO_SHIFT = 32, FACTOR = 5./9.)
    ! -----------------------------------------------Input
    print*, "Enter the temperature in Fahrenheit ..."
    read*, tempF
    ! -----------------------------------------------Compute
    tempC = FACTOR * (tempF - ZERO_SHIFT)
    ! -----------------------------------------------Output
    print*, "The corresponding Centigrade temperature is "
    print*, tempC, " degrees."
    end
    
  3. Compile the program as you learned in Lab1. If any compiler errors are reported, switch to the editor, fix the errors, save the program, then re-compile. Repeat until you get a clean compilation.
  4. Run the program.

Questions

  1. When run, the program prompts you to enter a temperature in F. Supply the number 32. What does the program print in return?
  2. Repeat by inputting 212 and then 77. Record the two corresponding outputs.
  3. Repeat by inputting -460 and record the output.
  4. Repeat by entering the string "York". What is the output?
  5. Edit the program and miss-spell the word "corresponding" by omitting the letter "i"; i.e. write it as: "correspondng". Re-compile the program and try to re-run it. What happens? Remember to save the program after modifying it.
  6. Edit the program and miss-spell the word "print" by omitting the letter "i"; i.e. write it as: "prnt". Re-compile the program and try to re-run it. What happens?
  7. Edit the original program and remove the two decimal points in the factor (5./9.), making it (5/9). Recompile and re-run and supply some inputs and record the outputs. Any observations? What if you remove only one of the two decimal points?
  8. Edit the original program and replace each occurrence of print*, by write(*,*). Recompile and re-run and supply some inputs and record the outputs. Any difference?
  9. Edit the last version of the program by replacing the last write(*,*) by write(*,12). Furthermore, add the following statement to the program anywhere before the END statement:

    12 format(10x, F6.1, A)

    Recompile and re-run the program and observe the effect. Experiment by changing the numbers 10 and 6.1 to understand their significance.

Fall2002/HR