Instructions for Emacs text editor on a Linux operating system, and the Fortran compiler.

Overview

Emacs is a text editor used to write computer programs and scripts.  It uses a graphic user interface similar to popular windows and mac environments.  Namely, you use the mouse a lot.  It is an alternative to using VI, the line text editor that your already learned.

Versions of emacs exist that can run on linux, Windows, and MacOSX computers.  They are free.  We already have a version installed on our eidolon server, which you will access remotely using the NX Client.   For this lab, we want you all to use the emacs that is already on eidolon (namely, no need to install it on your own laptop).  If you are using your own laptop during lab, be sure to install the NX Client.   

The main reason for using emacs is when you are working in a linux environment and need to create or edit ascii text for computer programs (Fortran, C) or scripts (PERL, python). 

The GNU Project has created a body of free software that runs linux operating systems.  We will use the gnu Fortran Compiler in this section of the course.  In other sections we will use other gnu software.  There are versions that run on many different computers.  Again, we want you to use the gfortran compiler already installed on eidolon, so no need to install it on your own laptop.  

This guide has you use emacs to write some fortran code, then  use the gnu fortran compiler (gfortran) to compile the code into an executable object, and finally run that code under linux.


Emacs on Linux Box

Use your PC or Macintosh to set up a remote terminal to the linux computer called "eidolon".  (see eidolon_tips if you forgot how)

Run the text-editing program called emacs.

  1. A powerful feature of many text editors, including emacs, is the ability to automatically color-code different parts of the fortran syntax with different colors.  This is called "syntax highlighting" and is extremely valuable when you write and debug computer programs.  However, many people are color-blind to red, for whom the syntax highlighting makes the computer program extremely hard to read.  So here are two alternative ways to open emacs depending on your preference on the color highlighting:
    .
    1. For people who prefer to view their computer program as only black text, open the emacs program by double clicking the icon of an ox at the bottom of the NX client window .  
      .
    2. For people who prefer to use the color highlighting of syntax, do NOT double-click the emacs ox icon.   Instead, in the Terminal window, type the linux command
        emacs wp01.f95 & 
      The extra "space ampersand" after the emacs command is nice, because it allows both the command-line terminal and the emacs editing window to both be open on your screen.  If file wp01.f95 didn't already exist, this method will automatically create it as soon as you save your work in emacs.
  2. If you opened emacs without indicating which file to work on, then go to the File menu of emacs, and select Open File (which will create a New file if you don't give it an existing one to open).  Name the new file "~/fortran/wp01.f95", and save it into your "fortran" folder on the linux machine.  
Write your FORTRAN code in emacs:
  1. Type the demo wind-power wp01.f95 fortran file into emacs.  Save your results periodically as you write.   You can make the emacs window larger if you wish.  Here is wp01.f95. (Note that your colors might be different than the ones shown here.)
    .
    !Estimate wind power
    program windpowermain
      write(*,*) "Welcome to Wind Power"   !welcome the user
    end program windpowermain
    .
  2. Don't forget to type all the comments (starting with exclamation points) as you write the code.  Don't wait to add them later, otherwise you might loose points.  
  3. If your program does not automatically highlight the different syntax in different colours, then under the Options menu of emacs, check the box for "syntax highlighting".  (Note, the colours on your screen will be different than the colours in the example above.)
  4. Proofread your code, and then save it when done. 
  5. Move the emacs window a bit off to the side, so you can see the terminal window.
Compile your FORTRAN code
  1. in the NX terminal window, type:
  2. "gfortran wp01.f95 -o runwp01", and hit return
  3. If the compiler found any errors, it will automatically display a lot of error messages.  If it compiled successfully, you will just see the usual linux prompt.
  4. type "ls" and hit return.  Your list of files should now include the new file "runwp01".  This is your executable program.
Running your program
  1. type "./runwp01" without the quotation marks, and hit return.
  2. if successful, your program will write some output to the screen, and will automatically end and display the linux prompt again.
  3. Find the emacs window on your screen, and move it back to the front center where you can use it again.
Modifying, editing, and/or debugging your fortran
  1. In emacs, fix any bugs that you found while compiling or running the program, and then test by compiling and running again (see the Compile and Run steps above).
  2. Enhance the wp program by adding more lines, following the examples given in class.  
  3. Continue compiling, running, and debugging, and writing more of the wind power program.


Copyright © 2012 by Roland Stull
.