Instructions for Emacs text editor, Linux operating system, and 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).
The first section of info below shows how to use emacs on a linux
machine. The second shows how to use it on our Windows
machine (after which we upload the results to the linux machine).
We will focus on the only first method (emacs on a linux machine)
here, but if it doesn't work for you, then try the second.
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
Set up files and shortcuts. While using windows explorer:
- Create a folder called "fortran" on your Z drive of your windows
machine. This will hold the input and output files for your
program.
- Run your web browser (Mozilla, Firefox, IE, etc), and go to the
course web site, Labs, Fortran 1. From this page, first open
the sounding ascii text input file for porthardy.txt, and view the ascii
text.
- Put a copy of this file into your ""fortran"" folder.
- Do the same for the darwin.txt sounding ascii text.
Upload your fortan file and contents from the Windows machine to the linux box via secure ftp
- Run the FileZilla program
- under the
FileZilla "file" menu, select site manager, and then double click on
"eidolon" to connect to that machine. (If it doesn't work, its
because you changed your password on eidolon. So in the FileZilla
Site Manager, enter the new password and click OK. Then close the
Site Manager window. Open the connection to eidolon using the
site icon on the toolbar.)
- upload your "fortran" directory and its contents to eidolon
- Don't
log out of FileZilla -- instead, just minimize it. (We might use
it later, such as to back up your work from eidolon onto your local
disk drive.)
Use your Windows machine as a remote terminal to the linux machine:
- Activate the "eidolon" NX client from your Windows desktop (the icon that says eidolon under it).
- Log in with your password when prompted.
- Wait a long time, for autorun to finish.
- Click
on the "terminal" icon that is in the NX dock (along the bottom of the
NX window), to run the terminal program. You are now in Linux.
Linux review
- type "ls" and hit return, you will see a list of files in your user directory on eidolon
- in this file list, you should see your directly called "fortran"
that you had copied from your lab computer. (Ignore all the other
stuff in your user directory, and DON'T delete it.)
- If
you had previously created a directory called "Fortran" (remember that
linux is case-sensitive, so "Fortran" is different from "fortran") from
earlier in the course, then carefully delete the one called "Fortran"
by using linux command rm -ri Fortran and then respond to it's yes/no questions.
- type "cd fortran", to change directory to "fortran"
- type "ls" again and hit return, to see a list of files inside your "fortran" directly.
- in this file list, you should see the input files you already copied, for porthardy.txt and darwin.txt .
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.
-or-
Emacs on Windows Machine
(Skip this section, unless you couldn't get Emacs to work directly on the linux machine.)
Set up files and shortcuts. While using windows explorer:
- Find the program "emacs" from the list of programs, and put a shortcut to it on your desktop.
- Create a folder called "fortran" on your Z drive. This will hold your fortran input and output.
- Run your web browser (Mozilla, Firefox, IE, etc), and go to the
course web site, Labs, Fortran 1. From this page, first open
the sounding ascii text input file for Port Hardy, and view the ascii
text.
- Put a copy of this file into your "fortran" folder.
- Do the same for the Dawson sounding ascii text.
Run the text-editing program called emacs.
- From your desktop, run "emacs" by double clicking on it.
- Ignore the text that appears in the window. Instead, 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 "wp01.f95", and save it into your "fortran" folder on your Z
drive.
Write your FORTRAN code in emacs:
- Type the demo wind-power fortran file into emacs. Follow
the example given above. Save your results periodically as you
write.
- 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.
- Proofread your code, and then save it when done. (Note, it is being saved on your Windows machine, in the Z drive.)
- Minimize the emacs program, but don't quit it.
Upload your FORTRAN code from the Windows machine to the linux box via secure ftp
- Run the FileZilla program
- connect to eidolon
- upload your "fortran" directory and its contents "wp01.f95" to eidolon
- Don't log out of FileZilla -- instead, must minimize it.
Use your Windows machine as a remote terminal to the linux machine:
- Activate the NX client from your Windows desktop (the icon that says eidolon under it).
- Log in with your password when prompted.
- Wait a long time, for autorun to finish.
- Click on the "terminal" icon, second from the bottom left, to run the terminal program. You are now in Linux.
Linux fundamentals (see your plastic QuickStudy sheet for more info)
- type ""ls"" and hit return, you will see a list of files in your user directory on eidolon
- in this file list, you should see your directly called "fortran"
that you had copied from your lab computer. (Ignore all the other
stuff in your user directory, and DON'T delete it.)
- type "cd fortran", to change directory to "fortran"
- type ""ls"" again and hit return, to see a list of files inside your "fortran" directly.
- in this file list, you should see your file called "wp01.f95"
Compile your FORTRAN code
- while still using the NX terminal client to talk with eidolon, 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.
- Minimize the NX terminal.
Modifying, editing, and/or debugging your fortran
- Expand the minimized "emacs" program
- Fix any bugs that you found while compiling or running the
program, and then upload using FileZilla, and 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 wp program.
-or-
Emacs on a Macintosh
Don't bother with Emacs on a Mac. Instead, use the much nicer program called TextWrangler. It is also free.
Also, instead of FileZilla, and nice program for file transfer to/from the Mac is called CyberDuck. Also free.
Copyright © 2010 by Roland Stull
.