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.
- 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:
. - 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 .
. - 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.
- 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:
- 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
.
- 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.
- 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.)
- Proofread your code, and then save it when done.
- Move the emacs window a bit off to the side, so you can see the terminal window.
Compile your FORTRAN code
- in the NX terminal window, type:
- "gfortran wp01.f95 -o runwp01", and hit return
- 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.
- type "ls" and hit return. Your list of files should now
include the new file "runwp01". This is your executable program.
Running your program
- type "./runwp01" without the quotation marks, and hit return.
- if successful, your program will write some output to the screen, and will automatically end and display the linux prompt again.
- 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
- 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).
- Enhance the wp program by adding more lines, following the examples given in class.
- Continue compiling, running, and debugging, and writing more of the wind power program.
Copyright © 2012 by Roland Stull
.