

Physics: Year 1.	FORTRAN90: GETTING STARTED		2004/05


1. The material for this course is provided entirely 'online'. It is in the 
form of illustrative Fortran90 programs which you can compile and execute. 
Each program introduces new concepts explained as comments appended to the 
program. 

You will make your own copy of these programs and work through them at your 
own pace. 

2. We will use the Computational Physics Laboratory server `Ludwig' to compile
and run programs. To log on to this machine click on the `Ludwig' icon. This 
machine runs the `linux' operating system, a PC flavour of Unix. A list of 
basic unix commands is appended to this file. You will also need to create 
and edit files (your programs). To do this we use a simple text editor 
(not a fancy word-processing package like Word!) such as `nedit'; an 
introduction to this is also appended to this file. 

You can also program in Fortran90 using the campus Unix machine `tower'.

3. Create your own directory (folder) for all work related to this course by 
typing
		mkdir fortran

Type `ls' to check that this directory exists. Now move into this directory 
by typing
		cd fortran

Now make copies of my files as follows. First make a copy of my file 
`readmefirst' (what you are reading now) as follows:

		cp /usr/local/labexp/fortran/readmefirst   readmefirst

You can read this file page by page by typing 

		more readmefirst

[Later, you can read this using 'nedit'.]

Now make a copy of my directory called 'f90_intro' by typing:

		cp -r /usr/local/labexp/fortran/f90_intro   f90_intro

You now have your own directory 'f90_intro'. Change to this directory 
(cd f90_intro) and list its contents (ls f90_intro). This should contain 
13 files: readme, 11 example programs (with extension .f90) and an exercise. 
Return to the fortran directory by typing (the parent directory of the one 
you are currently in):

		cd   ..

Finally, make a copy of my directory called `fortran90' by typing:

	 	cp -r /usr/local/labexp/fortran/fortran90    fortran90

You now have your own directory 'fortran90'. Change to this directory 
(cd fortran90) and list its contents (ls fortran90). This should contain 
23 fortran90 programs (with extension .f90). These files form the substance 
of the course.

You now have all the files necessary for this course.

4. Start by reading the file 'readmefirst' (this file). Next look at the 
files in the directory 'f90_intro' which will give you a quick start to 
fortran90 programming. Read the file `readme' to find out how to proceed.

5. Next, work through the programs in the directory fortran90 in sequence. 
They are named and numbered, eg read1.f90 is the first. Use your editor 
to view the program in one window, while compiling and executing the program 
in another window. Study the effect of executing the program against your 
expectations. Make sure you understand all features used in the programs. 
Read the comments for explanation of new features. Do the exercises at the 
end of each program. 

6. Unix/linux. The server 'Ludwig' uses a flavour of Unix called `linux'.
Therefore, you will need a limited knowledge of Unix commands. I will 
supply you with a sheet containing the most useful commands and other 
basic features of Unix. If you wish to extend your knowledge of Unix 
further, consult the website

	http://www-users.york.ac.uk/~hcb1/computing.html

where you will find links to the `twenty most commonly used Unix commands', 
a `Unixhelp for Users' and a `quick reference guide'. In addition, I have 
available a set of files on Unix in the directory `unixses'. To copy these 
perform the same operation as for the `fortran90' files above but replace 
`fortran90' by `unixses'. If you choose to study these, you must do it in 
your own time. 

7. Email. I intend to communicate with you by email so make sure you check 
your email regularly. Exercises/assignments will be set, submitted and 
returned by email. I am 
			hcb1@york.ac.uk

The simplest way of mailing the file 'filename' to me is to type

			mail hcb1@york.ac.uk < filename

IMPORTANT: PLEASE NOTE/
I will require each exercise to be submitted as a SINGLE fortran program 
with extension .f90 which I can immediately compile and execute. Do NOT 
include more than one program per email. And: files must always be in 
plain text format and not be an attachment. I will not mark work which 
does not follow these rules.

8. The recommended text book for this course is `Fortran90 Programming' by 
`Ellis, Philips and Lahey' (Addison-Wesley).

9. Assessment: this will be on the basis of four weekly exercises which 
will require you to construct a Fortran90 program utilising a wide range 
of Fortran90 features and which adheres to good programming practice. 

Now, let's get started! Have fun.

!!	End of file: readmefirst





*************************************************************************
*				UNIX					*
*************************************************************************

In addition to 'Windows', the other major operating system is Unix. You 
need to (and in my opinion should have) a basic working knowledge of it.
You can find a short course in the form of a series of files in the Ludwig 
directory /usr/local/labexp/fortran/unixses. To make a copy for yourself type
cp -r /usr/local/labexp/fortran/unixses unixses. Below is a glossary of the 
most used Unix commands and other information.

*************************A UNIX GLOSSARY*********************************

pwd			print working directory (if you can't remember where 
			you are in the file system hierarchy)
ls			list the files in your curent directory
ls -l			a 'long' listing of the files in your current directory

mkdir dirname		makes a new directory with name 'dirname'
rmdir dirname		removes the directory with name 'dirname'
cd    dirname		moves into the directory with name 'dirname'
cd			cd on its own takes you back to your home directory
cd  ..			moves up one level in directory hierarchy
			(the .. always means the parent directory to the one
			you presently occupy; a single . refers to the 
			directory yu currently occupy)

cp file1 file2		makes a copy of file1 and calls it file2
mv file1 file2		moves (deletes) file1 to (creates new file) file2
rm file1		removes (deletes) file 1
rm -i file1		asks for confirmation that you want to delete file1

history			lists your last 10 (variable) commands and numbers them.
!!			repeats your last unix command
!23			repeats the command numbered 23
!f90			repeats the last command beginning with a 'f90'.
!!addtext		appends 'addtext' to previous command line
^string1^string2	substitutes 'string2' for 'string1' in previous command

*			this is a wild card which stands for any string of 
			characters (be careful in its use!)
?			a wild card standing for any single character

more file1		displays the file 'file1' a page at a time
less file1		displays the file 'file1' a page at a time

man utilityname		manual pages for the utility 'utilityname' 
			(for further info on any of this list of commands 
			consult the online manual)

|			this allows you to 'pipe' the output of one command 
			to the input of a second command

command > file1		redirects the output of 'command' to 'file1' instead 
			of to standard output (screen)
command >> file1	appends the output of 'command' to 'file1' instead 
			of to standard output (screen)
command < file1		takes the input for 'command' from file1
_______________________________________________________________________________

Other items you should know about:

1. The Unix file hierarchy. Know how to navigate this. Know about PATHS 
(e.g. the full path name of my fortran90 file 'read1.f90' 
is /usr/fsb/phys/hcb1/fortran90/read1.f90)

/		the root directory
~		your home directory
. 		current directory
..		parent directory

2. Permissions. When you perform a long listing of files (ls -l) you will see 
in the first ten character spaces various combinations of 'd,r,w,x,-' 
The first space indicates whether a directory (d) or a file (-).
The remaining 9 spaces are grouped into 3 groups of 3. 
Each group of 3 refers to the user (u) i.e. you, the group (g), and others (o) 
namely anyone.
Within each group permission to read (r), write (w) and execute (x) may be 
granted (rwx) or not (-) in any combination.

chmod  ugo+/-rwx file1	The ugo and rwx may appear in any combination depending 
on which permissions you wish to give to (+) or remove from (-) whomever.

2. ctrl C. This is an important command. Interrupts whatever is currently 
running. It can get you out of trouble at embarrassing moments. 

3. Various other commands you might care to try:

who, who am i, wc, date, cal (try cal 1752 and look at September!), 
grep, sort, 
head, tail,
lp -Pprintername file1		prints file1 to printer 'printername
lpq -Pprinternmame		enquiry, print queue
lprm -Pprintername jobnumber	removes from print queue

Consult the manual pages for details of these and other commands.






*************************************************************************
*			Introduction to NEdit				*
*************************************************************************

			

This is a very brief description of useful features of NEdit when programming 
in Fortran 90.

1. On Ludwig the command line looks like this:

Ludwig:

The $ symbol will denote the command line.  Also when using drop down 
menus the | symbol will be used to denote the need for another menu 
(i.e. clicking File then Open will be written as File|Open etc.)


2. Basic Commands


NEdit is loaded up from an xterm window in Ludwig with the command:

$ nedit

This will open a blank document.

If you wanted to open an existing file, e.g. readme.txt:

$ nedit readme.txt  

or 

$ nedit readme.txt &

You could also;

$ nedit

then use File|Open... to open the file you want.

The & symbol allows the xterm to be used whilst nedit is being used. If the &
symbol is not typed when nedit is loaded the xterm is out of use until the
nedit program being run by that window is closed down.

You can also open more than one file in the same command

$ nedit readme.txt program.f90

The file extension does not matter when opening files, as long as the file
contains text or numbers. It can also open very large files, some a big as 
130 Mb or more, or files with literally a million lines. However it does 
take a while to load these large files.

3. Search. In Search there are a number of usefull commands:

	Search|Find 
	Search|Find Again
	Search|Replace
	Search|Replace Again 

When programming 

	Search|Goto Line Number 

is especially helpful. 

These commands also have their keyboard shortcuts which are listed next to 
them in the menus.

The standard Ctrl+x,c,v (cut, copy, paste) also work.


4. Using NEdit to program in Fortran 90.

NEdit was designed with programming in mind. Preferences|Language Mode will
allow you to select the language that NEdit recognises. However before that 
you may have to select the colouring and style that NEdit uses.

Go to: Preferences|Default Settings|Syntax Highlighting|Text Drawing Styles...

You will have a list of different types of text, e.g. New, Plain, Comment,
Keyword etc. These may already have options in them, but they can be changed.
Personally I prefer:

Plain : Black (font=plain)
Comment: Red (font=italic)
Keyword: Blue (font=bold)
String: darkGreen (font=plain)

After changing click OK

There are a number of other options but these are the ones which are most used.

After changing the setting you will have to save them:

	Preferences|Save Defaults... - Click OK. 

This saves the defaults to the .nedit file in your home directory and is 
loaded each time nedit is loaded.

You will also have to tell NEdit to use the above changes when programming:

	Preferences|Default Settings|Syntax Highlighting|On 

When you first start programming without saving the file you will have to
manually tell NEdit which language you are using (and therefore which words 
to highlight etc.); Preferences|Language Mode|Fortran ;but when you save 
your file (or load a file) with the correct file extension NEdit 
automatically impliments the language mode.

I can also direct you to the Help files which are clearly labeled from the 
Help menu in the top right corner.
 
