In this lab you learn how to operate in a terminal-based
computing environment based on Unix (Linux), and how to use a
compilable programming environment (in contrast, MATLAB is an
interpretive environemnt). Since most students work in MLC on
Windows-based machines, we will actually use Cygwin which is a Unix
emulator under Windows.
Rules:
Synopsis:
-
We use Cygwin and Cygwin-X which emulate Unix and X-Windows on Windows
machines. This is useful to us because
-
You will use Cygwin to implement your first programs in Fortran or/and
in C in a Unix environment.
Implement = write Fortran/C code +
compile it + run it.
Steps and project(s):
- Get familiar with Unix environment
- Click on the icon Cygwin on your Desktop to
start Cygwin.
- Where are you ... ? ... move within your file system (and home directory)
pwd
mkdir lab2
ls
cd lab2
pwd
go back to where you started
cd ..
pwd
ls
Now move to the Desktop. Ha !
- Learn how to create a text file, see its contents, and copy and
move files:
Explore (use man pages) commands cat, cp, mv, rm, rmdir
cat > myfile.txt
type anything you want ... and finish with Ctrl-D
cat myfile.txt
- Now copy a few files, move between folders ...
Now you are
an expert, find out who you are and on which system you really are...
whoami ; uname
-
Project 1.
Run a baby example code written in Fortran or in C
- download the file code to Desktop
and place it in your cygwin lab2 folder (the one you created)
- compile the code (and link)
(NOTE: the program has intentional mistakes which you have to correct)
g77 hellof.f
- run: (the program has now a default name: a.exe, on Unix it gets the name a.out)
./a.exe
- compile and link and give it a name
g77 -o hellof.exe hellof.f
- run:
./hellof.exe
The program computes the norm inefficiently. Please correct. EXPLAIN.
Make it compute also the L1, Linfty norm of your birthday as well as the average of the random numbers.
The program draws from uniform distribution
and computes ... ? EXPLAIN what you expect to see.
Helpful hints
- memory allocation in Fortran 77 is static
- Fortran code MUST start in column 7
- put a character in the first column for lines with comments
- you can also put comments after a ! in the middle of the line
- use IMPLICIT NONE: this has saved many from mismatched type death
- This is an useful when comuting Linfty norm
if (mymax.lt.mynumber) then
mymax = mynumber
endif
|
|