Lab 0
Intro to Linux, vi, and Fortran
The purpose of this lab is simply to help you to become familiar with the Linux command line,
the vi and/or nano editor, and the GNU Fortran compiler. Only the basics of each are included.
- Start SecureCRT (found under the Start button's menu or perhaps a desktop icon).
It is used to connect to a remote server, in this case to our Linux server.
- A Connect dialog box should pop up. Under Sessions click on
"CIS Dept Linux Server (normal font)".
- Log in using your Linux account information.
- Try the following commands:
- topic
- topic 1
- topic 2
- topic 4
- topic 12
- For that last one, topic 12, you may have read this information already. However, skim through it again to see if
you can remember some of these basic Linux commands. We will use a few of them in this lab. If you see something
that does not work as described, let me know so that I can revise the topic 12 text or fix something that is broken.
- In connection with topic 4, also glance through our
Unix Text Editors web page.
- Try the following commands to display your files and show your current working directory:
- ls -l (that's the letter l, not the digit 1)
- ls -la
- pwd (this means "print working directory" and is helpful for finding out where you are)
- Let's make a directory for this course and change into it:
- mkdir cs270
- cd cs270
- pwd
- ls -l
- Copies of many of our example Fortran programs are located in /home/cs270. Let's
see what is in that directory and copy one of the programs using the cp copy command:
- ls -l /home/cs270
- If that list is too long, you can use the vertical scroll bar to see more.
- cp /home/cs270/multiply1.f90 .
- Don't forget the dot at the end of that last command. It is necessary to specify
the destination for the copy. The dot means your current working directory, which
should be the cs270 directory that you just created above.
- Next, we try the vi editor to look at and modify your copy of the multiply1.f90 program.
You should learn the basics of vi as every Linux and Unix system in the world seems to have it.
However, you may use nano instead if you prefer after you try out vi in this section.
You may like nano better as it tends to be easier to use, but it is not as powerful as vi.
- ls -l
- vi multiply1.f90
- The vi editor is a "modal" editor. You have to remember whether you are in edit
mode or command mode. You start in command mode.
- In command mode you can use the 4 arrow keys to move around in the file. Try it.
If you cannot move any further to the right, it is because there is nothing else
on this particular line.
- Move to the line where it says "Programmer:" and then go into edit mode so as to insert
new text by pressing the i key. You can still use the arrow keys to move around.
Move to the end of the line and backspace over the name that is there. Then type
in your name. Press the ESC key to get out of edit mode and back to command mode.
- To save your work thus far, press :w and the ENTER key. Note well that the command is a colon symbol and then w.
- Move to the line that says "Revised" and press the letter o key to open a new line below
this one. Simply put an ! on this line so that it is a comment. Press ENTER to get
another new line. Make this line contain the following:
! Last Revised: (fill in today's date here)
- Press ESC to get back to command mode and use :w to save your work.
- For your last modification, go to the last WRITE line. Change it to the following
by using i to get into insert mode and then backspace over items you need to change:
WRITE (*,*) 'Product of ', first, ' and ', second, ' is ', product
- Go back to command mode. Use :wq to save your changes and exit from (quit) the vi editor.
- Now we will compile your multiply1.f90 program. But before doing that let's see what the
build90 script does for you:
- cat /usr/local/bin/build90
- Essentially it calls upon the gfortran compiler with some convenient options.
- build90 multiply1
- Note that you do NOT use the .f90 in the filename when using build90.
- If you get error messsages, ask your instructor for assistance.
- Next, we run your compiled program. Note that the ./ is used to specify that we are looking
for a program in the current directory. (In both Linux and Windows, the . means the current directory.)
- ls -l
- ./multiply1
- If the program does not work correctly, check with your instructor.
- Use the up arrow key to bring back the last command. It should be the ./multiply1 command.
Press ENTER to run your program again.
- Enter the command history to see the list of commands that you have used recently.
- Email a copy of your program to your instructor by using the senddc script as follows:
senddc multiply1.f90
Be SURE you do use the .f90 in this command, as I want to see your Fortran file, not the
compiled executable (which is unreadable and which is named multiply, with no extension).
You will often be asked to submit your homework by using this senddc script.
- Log off and close down SecureCRT by using the following 2 steps. Always be sure to log off from Linux and Windows both. Remember
that an account left logged in is an invitation to someone to damage your files, do nasty stuff in
your name, etc.
- exit
- Close the SecureCRT program.
- WARNING: In SecureCRT, never use Options, Save Settings Now. This saves the settings for SecureCRT and
does not save your Fortran program. Worse yet, the SecureCRT settings for all users are saved in one location.
Thus, whatever you save may mess up the settings for others.