computers and programming ingeosciences soee 1160

36
Computers and Programming Computers and Programming in in Geosciences Geosciences SOEE 1160 SOEE 1160

Upload: philip-cobb

Post on 25-Dec-2015

229 views

Category:

Documents


1 download

TRANSCRIPT

Computers and ProgrammingComputers and Programminginin

GeosciencesGeosciences

SOEE 1160SOEE 1160

LecturesTuesday 10:00 to 11:00 SR B22

PracticalWednesday 09:00 to 11:00 EFC

(Environment Building)

Lecturer/Module ManagerSebastian Rost

DemonstratorKuishuang Feng

Rost ContactRost Contact

Office: 8.15b Office: 8.15b Geophysics Corridor Geophysics Corridor

Email: [email protected]: [email protected]

Web: http://earth.leeds.ac.uk/SOEE1160.htmlWeb: http://earth.leeds.ac.uk/SOEE1160.html

Module SummaryModule Summary

Computers are an important research tool in all Computers are an important research tool in all geosciences. This course is designed to teach how geosciences. This course is designed to teach how computers can be used to solve problems in the computers can be used to solve problems in the geosciences. The students will get an introduction geosciences. The students will get an introduction to the SEE computer system and will learn how to to the SEE computer system and will learn how to use a LINUX/UNIX operating system effectively. We use a LINUX/UNIX operating system effectively. We will introduce two programming languages, will introduce two programming languages, FORTRAN and MATLAB and will learn how to use FORTRAN and MATLAB and will learn how to use these languages in structured computer programs. these languages in structured computer programs. This module is taught through lectures and This module is taught through lectures and practicals and will be assessed through practicals practicals and will be assessed through practicals and a two-hour exam.and a two-hour exam.

Syllabus1. SEE computer system 2. UNIX filesystem structure3. Shells and UNIX commands, shell utilities and text editor 4. Structured programming5. Fortran program structure and compiling.

5.1 Declarations5.2 Operators and internal functions5.3 Input and output. 5.4 Conditional testing. 5.5 Loops. 5.6 Subroutines and external functions

6. Matlab programming6.1 Array basics6.2 Vector and matrices6.3 Operators and array arithmetic6.4 Input/Output6.5 Flow control structure

Week TuesdayLecture

WednesdayPractical

Week 1 22.01.2008

UNIX IntroductionUnix login

ls, pipes, filesystemtext editors

Week 229.01.2008

UNIX Shells & Tool awk, grep and shell scripts

Week 305.02.2008

Structured Programming Flow diagrams

Week 412.02.2008

FORTRAN 1Simple ProgramsVariable Types

Week 519.02.2008

FORTRAN 2Input OutputIF Structures

Week 626.02.2008

FORTRAN 3 Loops

Week 704.03.2008

FORTRAN 4 Programming

Week 811.03.2008

FORTRAN 5 Programming

Week 915.04.2008

MATLAB 1 Simple Matlab scripts

Week 1022.04.2008

MATLAB 2 Matlab Programming

Week 1129.04.2008

MATLAB 3 Matlab Programming

AssessmentAssessment

50% Marking of practicals.

50% unseen examination

BooksBooksUNIX System V: A Practical Guide

Mark G. Sobell Addison Wesley; 3 edition (1994)

ISBN: 080537566X

Get it used!Get it used!

Fortran 90/95 for Scientists and Engineers (Paperback) Chapman Stephen J.

McGraw Hill Higher Education

ISBN: 0071232338

Fortran 77 Programming

T. M. R. Ellis

Addison-Wesley; 2 Sub edition

ISBN: 0201416387

Getting Started with MATLAB 7: A Quick Introduction for Scientists and Engineers (Paperback) Rudra Pratap

Oxford University PressOxford University Press

ISBN: 0195179374

Questions Questions ??

Computer HardwareComputer Hardware

Image courtesy of WikipediaImage courtesy of Wikipedia

MotherboardMotherboard

Central Processing UnitCentral Processing Unit CPUCPU

http://www.intel.comhttp://www.intel.com

CPU ComponentsCPU Components

1)1)Core Core

2)2)Branch predictorBranch predictor

3)3)Floating Point UnitFloating Point Unit

4)4)Level 1 CacheLevel 1 Cache

5)5)Bus InterfaceBus InterfaceDifferent ArchitecturesDifferent ArchitecturesRISC: SUN – MotorolaRISC: SUN – MotorolaCISC:CISC: IntelIntel

RAM: Random Access MemoryRAM: Random Access MemoryRandom access memory (usually known by its acronym, RAM) is a type of computer data storage. It today takes the form of integrated circuits that allow the stored data to be accessed in any order, i.e. at random. The word random thus refers to the fact that any piece of data can be returned in a constant time, regardless of its physical location and whether or not it is related to the previous piece of data. (wikipedia)

110 MB110 MB

6495 MB6495 MB

HarddiskHarddisk

Physics Nobel Prize 2007!Physics Nobel Prize 2007! Images: WikipediaImages: Wikipedia

Operating SystemsOperating Systems

• Resource Manager Resource Manager

• Balances software and resourcesBalances software and resources

• KernelKernel

direct control of hardwaredirect control of hardware

UNIX only in this module !UNIX only in this module !

Unix historyUnix history

File SystemsFile Systems

WindowsWindows

UnixUnix

Home DirectoryHome Directory

Moving around in the filesystemMoving around in the filesystem

cd location(change directory)

cd (blank) change directory to your main home directorycd ~ change directory to your main home directory – same as abovecd ~earsro change to rost’s main home directory (earsro is my login)cd ~/HW change to a directory called “HW” just below your main home dir(.)cd ../ go UP one level to the directory above youcd ../../ go UP 2 directories (and so on …)cd ../graphics go up one directory, then down into a directory called “graphics”cd /nfs/see-fs-01_t1 go to the networked file system see-fs-01_t1

. The present (active) working directory

.. The directory above the present working directory / A divider between hierarchal directories when listing paths * A wildcard that matches any sequence of characters ? A wildcard that matches any single character ; separates separate UNIX commands on one line ! Relates to history (past typed commands) ~ Location of a main home directory & Causes a command or program to run in the "background" | Routes standard output from a command to the next command ("pipe") > Routes standard output from a command to create a new specified file >! Same as above: however, if file already exists, replace it >> Routes standard output from a command to append to the specified file < Routes a specified file to be input to a command SPACE Yes, a space... spaces are important in UNIX, they act as field separators

Special Unix charactersSpecial Unix characters

What’s there?What’s there?

ls location and/of filename info(list)

Some ls flag options

ls –a list all entries, including those that begin with a dot (.) that are normally hiddenls –l list in long format, giving mode, ACL indication (see below) number of links, owner, group, size in bytes, and time of last modification for each filels –s give size in blocks, including indirect blocks for each entryls –sa combines the above flags –s and –a (you can combine as many flags as you wish)

Complete File Information (ls –l)Complete File Information (ls –l)

type: d – directory, - - ordinary file, l – linktype: d – directory, - - ordinary file, l – linkpermissions: rwx for 3 groups (ugo)permissions: rwx for 3 groups (ugo)links: number of links pointing to this filelinks: number of links pointing to this fileowner:owner:group: group: size: length of file in bytes size: length of file in bytes date: last modified (use –u to see date of last access)date: last modified (use –u to see date of last access)name: Name of file name: Name of file

ls ~ list what's in your main home directory

ls ~/SOEE1160 list what's in your “SOEE1160“

directory, which is in your main home

directory

ls .. list what is in the directory directly above

you

ls ../.. list what's UP 2 directories

ls ~earsro list what's in my main home directory

ls examplesls examples

More commands to look at filesMore commands to look at files

ls -flags We just covered this one.

more location/filename(s) Display contents of a file 1 page at a time to the standard output, the terminal screen. Hit the space bar to go to the next page if there is one, hit b to go back a page at a time

cat location/filename(s) Scroll the whole file to the screen

head location/filename(s) Display the 1st 10 lines of a file (see man page for more)

wc location/filename(s) Word count: displays the number of lines, words, and characters in a file

tail location/filename Display the last 10 lines of a file

file location/filename(s) Display the type of the file if determinable

emacs location/filename Very powerful editor. Works both graphically and in a non-graphical shell. You can use the mouse to do things, but everything is available through keystrokes. Possibility to define macros.

vi location/filename Edit the file with the "vi" (VIsual editor). I only mention it briefly in this class. It is very powerful, but comes with a steep learning curve.

Copying and Moving filesCopying and Moving files

cp present_location/present_name new_location/new_name(copy)

mv present_location/present_name new_location/new_name(move)

Creating new directoriesCreating new directories

mkdir newdirectory(make directory)

Where are you? Where are you?

pwd(print working directory)

mkdir test First we will make a directory called "test", then we can copy files there

cp ~earsro/.cshrc ~/test/.cshrc_earsro Assuming you successfully created a directory called "test" in your main

directory, you are copying the file ".cshrc" from rost’s main directory to your directory "test", and you are renaming the file to be ".cshrc_earsro". Thus, here you copied and renamed in one fell swoop. Now check to make sure it worked. Look at the contents of directory test with ls test

mv ~/test/.cshrc_earsro ~/junk Now you are moving the file you just copied to the test directory to your present working directory, and renaming it "junk". You will notice that directory test is now empty. You can delete this directory with rmdir test.

moving/copying examples

The ShellThe Shell

• UNIX system command processor

• part of the UNIX OS that deals with interpreting user inputpart of the UNIX OS that deals with interpreting user input

• liaison between you, the user, and all programs/processes/liaison between you, the user, and all programs/processes/

resources resources

• C shell, Bourne shellC shell, Bourne shell and the and the Korn shellKorn shell

How does the Shell process User input?How does the Shell process User input?

Standard Input / OutputStandard Input / Output

Redirecting OutputRedirecting Output

redirect output to a file by using the “>” symbol

overwrite a possible existing file with “>!”

append to an existing file using “>>”

command {arguments} > output_file

command {arguments} >! output_file

command {arguments} >> output_file

ls ~earsro/BMP/* > images

Example using lsExample using ls

Redirecting InputRedirecting Input

command < input_file

command < command < input_fileinput_file > > output_fileoutput_file

Combining Input and Output redirectionCombining Input and Output redirection

Simple Shell scriptsSimple Shell scripts

• A shell script always starts with #!/bin/cshA shell script always starts with #!/bin/csh

• List of commands to be executedList of commands to be executed

Example snoop:Example snoop:

#!/bin/csh#!/bin/cshdatedate >! sneaky >! sneakywhowho >> sneaky >> sneakycal cal >> sneaky>> sneaky

Making script executable (only once needed) – check with ls -lMaking script executable (only once needed) – check with ls -l

chmod +x snoop