Atmospheric Modeling (5 ECTS)

Similar documents
ME1107 Computing Y Yan.

Fortran 90 Two Commonly Used Statements

Computer Science II Lecture 1 Introduction and Background

Welcome to Python 3. Some history

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Our Strategy for Learning Fortran 90

2 Making Decisions. Store the value 3 in memory location y

TACi: Three-Address Code Interpreter (version 1.0)

Section A Arithmetic ( 5) Exercise A

Scientific Computing

C++ Programming Lecture 11 Functions Part I

Object-Oriented Programming

Counting Loop: DO-END DO. DO var = initial-value, final-value, step-size

CS 11 java track: lecture 1

Control Structures. CIS 118 Intro to LINUX

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Goals for This Lecture:

Data Types and Basic Calculation

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

2. Basic Elements of Fortran

CS111: PROGRAMMING LANGUAGE II

Introduction to Computer Science Unit 2. Notes

Programming (ERIM) Lecture 1: Introduction to programming paradigms and typing systems. Tommi Tervonen

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat.

Algorithms and Programming I. Lecture#12 Spring 2015

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

INFO Object-Oriented Programming

CS 106 Introduction to Computer Science I

Building Java Programs

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Python Programming Exercises 1

Research Group. 2: More types, Methods, Conditionals

CSCI 3136 Principles of Programming Languages

Introduction to Programming using C++

C++ Programming: From Problem Analysis to Program Design, Third Edition

AP Computer Science Summer Work Mrs. Kaelin

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

Building Java Programs

Expressions. Eric McCreath

Computational Physics Operating systems

Introduction to Engineering gii

Shell programming. Introduction to Operating Systems

UEE1302(1066) F12: Introduction to Computers and Programming Function (II) - Parameter

PIC 10A. Lecture 3: More About Variables, Arithmetic, Casting, Assignment

Lecture 2 FORTRAN Basics. Lubna Ahmed

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Software and Programming 1

From Pseudcode Algorithms directly to C++ programs

Chapter 3. Computer Science & Engineering 155E Computer Science I: Systems Engineering Focus. Existing Information.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

CA4003 Compiler Construction Assignment Language Definition

Lecture 2: Intro to Java

7 Control Structures, Logical Statements

UNIT- 3 Introduction to C++

Introduction to Computer Science Unit 2. Notes

Welcome to the Primitives and Expressions Lab!

Lecture Set 2: Starting Java

Monty Python and the Holy Grail (1975) BBM 101. Introduction to Programming I. Lecture #03 Introduction to Python and Programming, Control Flow

Unit 1 Lesson 4. Introduction to Control Statements

COMP-202: Foundations of Programming

Question 2. [5 points] Given the following symbolic constant definition

10. Additional Intrinsic Data Types

Lecture Set 2: Starting Java

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Introduction to the course and basic programming concepts

COSE212: Programming Languages. Lecture 3 Functional Programming in OCaml

4 Programming Fundamentals. Introduction to Programming 1 1

Python Unit

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 1 IDL Operators

Rational numbers as decimals and as integer fractions

Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Computer Science & Engineering 150A Problem Solving Using Computers

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Computer Science & Engineering 150A Problem Solving Using Computers. Chapter 3. Existing Information. Notes. Notes. Notes. Lecture 03 - Functions

Who and what can help? Inf1-OP. Lecturer: Timothy Hospedales TA: Natalia Zon

Elementary Programming

Introduction to FORTRAN

1.1 Your First Program

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Lec 3. Compilers, Debugging, Hello World, and Variables

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Variables and Operators 2/20/01 Lecture #

Program Structure and Format

7COM1023 Programming Paradigms

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

Department of Computer Science COMP The Programming Competency Test

Floating-point representation

Getting Started Values, Expressions, and Statements CS GMU

Computer Components. Software{ User Programs. Operating System. Hardware

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Programming Language Concepts: Lecture 2

Getting started with Java

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

JAVA OPERATORS GENERAL

Transcription:

Atmospheric Modeling (5 ECTS) Lectures: Mon 10.15-12.00, Physicum D105 Tue 10.15-12.00, Physicum D104 Exercises: Mon 14.15-16.00, Physicum D105

Atmospheric Modeling (5 ECTS) Teachers Michael Boy, Dynamicum 1D01b Sampo Smolander, Dynamicum 1D09a Kenty Ortega, Dynamicum 1D16b Risto Makkonen, Physicum B415 Course web page http://www.courses.physics.helsinki.fi/fys/atmodel/ slides, links to Fortran-guides, timetable

Preceding studies: A basic knowledge in one programming language (Fortran, MATLAB, C+, ) is required. However, we will use the first two lectures and exercises to give a short and comprehensive introduction and training to Fortran. Each student should have access to one computer and we will help to install a Fortran compiler if not already available.

Course content Introduction to Fortran Introduction to boundary layer meteorology modeling Including chemistry in the model Implementing emissions Modeling aerosol dynamical processes Overview of atmospheric models and complex modeling techniques

Course structure Lectures Exercise Developing a chemical transport model including biogenic emissions, chemistry and aerosol dynamics Bring your exercise material to the exercise session on memory stick, paper, or your laptop Exam Based on lecture content Your model must be ready before the exam

Mon 10.15-12.00 Timetable for first week introduction to course starting Fortran introduction 1st exercise given (small Fortran task) Mon 14.15-16.00 Checking that everyone has an environment for editing, compiling and running Fortran Tue 10.15-12.00 Fortran introduction continues Checking 1st exercise Example of solving an equation in Fortran

Atmospheric modeling

Atmospheric modeling

Atmospheric modeling

Atmospheric modeling Meteorology -transport, radiative fluxes,... Chemistry & aerosols -OH, O 3, photolysis,... -aerosol formation, condensation,... Emissions -anthropogenic (SO 2, black carbon,...) -natural (organic compounds, dust,...)

Atmospheric particle formation chemistry chemistry nucleation condensation Emissions

How to make the computer solve our equations?

Modern programming languages C, C++ Python Java Perl Actionscript Matlab OCaml

Why would we use a programming language from the 50's?

Fortran (FORmula TRANslation) Simple to learn, less mistakes by beginners Almost all current scientific computational code is written in Fortran Availability of well tested libraries, especially for mathematics More space for compiler optimization, fast code Portability of code

The classic Hello World! example. Fortran program hello print *,"Hello World!" end program hello Java public class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); } } C++ Python #include <iostream> print "Hello, World!" int main() { std::cout << "Hello World!" << return 0; } std::endl;

PROGRAM squarerootexample! Comments start with an exclamation point.! Some exponentiation and squareroot computations.! You will find data type declarations, couple arithmetic operations! and an interface that will ask values for these computations. IMPLICIT NONE!do not use implicit variable declarations REAL :: x, y! Command line interface. Ask a number and read it in WRITE (*,*) 'Give a value (number) for x:' READ (*,*) x y=x**2+1! exponentiation and addition arithmetic WRITE (*,*) 'given value for x:', x WRITE (*,*) 'computed value of x**2 + 1:', y! SQRT(y), Return the square root of the argument y WRITE (*,*) 'computed value of SQRT(x**2 + 1):', SQRT(y) END PROGRAM squarerootexample

Data types INTEGER An integer number REAL A real number COMPLEX A pair of real numbers used in complex arithmetic LOGICAL TRUE or FALSE CHARACTER A string consisting one or more characters

!Variables can be initialized at their declaration IMPLICIT NONE! After declaration and initialization the value of a variable can be! changed whenever needed INTEGER :: n0 INTEGER :: n1=0 REAL :: a, b REAL :: r1=0.0 COMPLEX :: c COMPLEX :: imag_unit=(0.1, 1.0) CHARACTER(LEN=80) :: place CHARACTER(LEN=80) :: name='james Bond' LOGICAL :: test0 =.TRUE. LOGICAL :: test1 =.FALSE.! How to define constants? After declaration it can not be changed REAL, PARAMETER :: pi=3.14159

Precision The precision of a variable may be declared using the KIND-statement 1) SELECTED_INT_KIND(r) 2) SELECTED_REAL_KIND(p) 3) SELECTED_REAL_KIND(p,r) Explanations: 1) integer, range between -10 r < n < 10 r 2) real, precision at least p decimals 3) real, range -10 r < x < 10 r and precision at least p decimals INTEGER, PARAMETER :: short=selected_int_kind(4) INTEGER, PARAMETER :: double=selected_real_kind(12,100) INTEGER (KIND=short) :: index REAL (KIND=double) :: x,y,z COMPLEX (KIND=double) :: c x=1.0_double; y=2.0_double * ACOS(x)

Operators Arithmetic operators REAL :: x,y INTEGER :: i = 10 x=2.0**(-i)!exponentiation and negation precedence: first x=x*real(i)!multiplication and type change precedence: second x=x/2.0!division precedence: second i=i+1!addition precedence: third i=i-1!subtraction precedence: third Relational operators.lt. or <.LE. or <=.EQ. or ==.NE. or /=.GT. or >.GE. or >=!less than!less than or equal to!equal to!not equal to!greater than!greater than or equal to Logical operators.not.!logical negation precedence: first.and.!logical conjunction precedence: second.or.!logical inclusive disjunction precedence: third.eqv.!logical equivalence precedence: fourth.neqv.!logical nonequivalence precedence: fourth

Logical operators LOGICAL :: L1, L2! How to determine the values of logical expressions! F means.false. T means.true. L1 L2.AND..OR..EQV..NEQV. F F F F T F F T F T F T T F F T F T T T T T T F

Control structures 1) IF THEN ELSE (branching) 2) SELECT CASE (selecting) 3) DO (looping) PROGRAM test_if IMPLICIT NONE REAL :: x,y,eps,t WRITE(*,*)' Give x and y :' READ(*,*)x, y eps = EPSILON(x) IF (ABS(x) > eps) THEN t=y/x ELSE WRITE(*,*)'division by zero' t=0.0 END IF WRITE(*,*)' y/x = ',t END PROGRAM

Control structures: IF, ELSE, ELSE IF PROGRAM test_if IMPLICIT NONE REAL :: x,y,eps,t WRITE(*,*)' Give x and y :' READ(*,*)x, y eps = EPSILON(x) IF (ABS(x) > eps) THEN IF (y > eps) THEN t=y/x ELSE IF (ABS(y) < eps) THEN t = 0.0 ELSE t = 1.0 END IF END IF END PROGRAM

Control structures: SELECT CASE -SELECT CASE statements matches the entries of a list against the case index. Only one found match is allowed. -Usually arguments are character strings or integers. -DEFAULT-branch if no match found. -If there is no CASE DEFAULT and no match found then the statement following END SELECT is executed... INTEGER :: i LOGICAL :: isprimenumber... SELECT CASE (i) CASE (2,3,5,7)! variables are not allowed on the list isprimenumber =.TRUE. CASE (1,4,6,8:10)! case value range, form low:high isprimenumber =.FALSE. CASE DEFAULT! DEFAULT-branch isprimenumber = testprinumber(i)! function call END SELECT...

Control structures: DO, DO WHILE 1) DO-loop with an integer counter (count controlled) INTEGER :: i, stepsize, NumberOfPoints INTEGER, PARAMETER :: max_points=100000 REAL :: x_coodinate(max_points), x, totalsum... stepsize=2 DO i = 1, NumberOfPoints, stepsize x_coordinate(i) = i*stepsize*0.05 END DO 2) DO WHILE-construct (condition controlled loop) totalsum = 0.0 READ(*,*) x DO WHILE (x > 0) totalsum = totalsum + x; READ(*,*) x END DO

Control structures: DO, DO WHILE 3) DO-loop without loop control REAL :: x, totalsum, eps totalsum = 0.0 DO READ(*,*) x IF (x < 0) THEN EXIT! inside loop control, exit the loop END IF totalsum = totalsum + x END DO 4) DO-loop, repeat until style eps = 1000.0*EPSILON(1.0) DO...!Iterative loop body where ABS(x) is getting smaller and smaller IF (ABS(x) < eps) THEN EXIT END IF END DO! inside loop control, exit the loop

Control structures: example PROGRAM gcd! Computes the greatest common divisor, EUCLIDEAN ALGORITHM IMPLICIT NONE INTEGER, PARAMETER :: long = SELECTED_INT_KIND(9) INTEGER (KIND=long) :: m, n, t WRITE(*,*)' Give positive integers m and n :' READ(*,*) m, n WRITE(*,*)'m:', m,' n:', n positivecheck: IF (m > 0.AND. n > 0) THEN main_algorithm: DO WHILE (n /= 0) t = MOD(m,n) m = n n = t END DO main_algorithm WRITE(*,*)'Greatest common divisor: ',m ELSE WRITE(*,*)'Negative value entered' END IF positivecheck END PROGRAM gcd

Exercise #1 Create a Fortran program that reads a real number from a file calls a subroutine, which multiplies the value with pi (subroutine should be in a separate module-file) prints the multiplied value to screen The whole program is about 15-20 lines