Introduction to Programming. Dr Ben Dudson University of York

Similar documents
Programming with Python

IDL Primer - Week 1 John Rausch

Programming. Dr Ben Dudson University of York

CS1110 Lab 1 (Jan 27-28, 2015)

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

IDL Lab #6: The IDL Command Line

Unit II Graphing Functions and Data

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Python lab session 1

CS 1110, LAB 2: ASSIGNMENTS AND STRINGS

CS 1110, LAB 1: PYTHON EXPRESSIONS.

Lecture 1. Course Overview, Python Basics

cs1114 REVIEW of details test closed laptop period

CSC148H Week 1 >> COURSE INFORMATION, RECAP, OOP. Sadia Rain Sharmin Week of May 7, 2018

Level 3 Computing Year 2 Lecturer: Phil Smith

Expressions, Statements, Variables, Assignments, Types

Lecture 2: Variables & Assignments

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Lecture 1. Course Overview, Python Basics

CS 1110, LAB 1: EXPRESSIONS AND ASSIGNMENTS First Name: Last Name: NetID:

CITS2401 Computer Analysis & Visualisation

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Week - 01 Lecture - 04 Downloading and installing Python

ERTH3021 Exploration and Mining Geophysics

ENGR 102 Engineering Lab I - Computation

Objectives. Structure. Munster Programming Training

2. Getting Started When you start GeoGebra, you will see a version of the following window. 1

Lecture 1. Types, Expressions, & Variables

MITOCW watch?v=se4p7ivcune

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

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

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Expressions and Casting

Numerical Practical in Astronomy. Visualisation. Nigel Mitchell

Watch the video below to learn more about number formats in Excel. *Video removed from printing pages. Why use number formats?

252 APPENDIX D EXPERIMENT 1 Introduction to Computer Tools and Uncertainties

Chapter 1 Section 3. Page 22. A graph is a visual display of information or data. There are three types of graphs.

Motion I. Goals and Introduction

Visual Basic for Applications

Python Games. Session 1 By Declan Fox

Graphical Presentation of Data

Lecture 2. Variables & Assignment

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

SAMS Programming - Section C. Lecture 1: Introduction + Basic Building Blocks of Programming

Use the Move tool to drag A around and see how the automatically constructed objects (like G or the perpendicular and parallel lines) are updated.

What is a Database? CMPSCI 105: Lecture #15 Introduction to Databases. Spreadsheets vs. Databases. One Skill You Will Develop

Getting Started With Linux and Fortran Part 2

CS109A ML Notes for the Week of 1/16/96. Using ML. ML can be used as an interactive language. We. shall use a version running under UNIX, called

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

Programming for Engineers in Python. Recitation 1

COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

What did we talk about last time? Examples switch statements

Name & Recitation Section:

Biology 345: Biometry Fall 2005 SONOMA STATE UNIVERSITY Lab Exercise 2 Working with data in Excel and exporting to JMP Introduction

Macros I Use Every Day (And You Can, Too!)

Module 201 Object Oriented Programming Lecture 10 - Arrays. Len Shand

IDL 5.3. Things you need to know. On Windows, select Start > Programs -> Research Systems IDL 5.3 -> IDL Online Manuals

Introduction to Java Programming

Lecture 3. Input, Output and Data Types

A model is built by VORSIM from this Model Builder control screen that loads when the VORSIM desktop icon is clicked. One starts by defining a new

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Algorithms and Programming I. Lecture#12 Spring 2015

AMath 483/583 Lecture 11. Notes: Notes: Comments on Homework. Notes: AMath 483/583 Lecture 11

AMath 483/583 Lecture 11

Computing Seminar Introduction Oct

Integer Representation

Ch.2: Loops and lists

Introduction Building and Using Databases for historical research December 2012

Skill 1: Multiplying Polynomials

Introduction to C++ Dr Alex Martin Room 6.10

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

The SAS interface is shown in the following screen shot:

CS 1110, LAB 2: FUNCTIONS AND ASSIGNMENTS

Intro. Scheme Basics. scm> 5 5. scm>

Bourne Shell Reference

Introduction to MATLAB

LABVIEW LAB SKILLS ACTIVITY 1 PROGRAMING ENVIRONMENT

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

URLs and web servers. Server side basics. URLs and web servers (cont.) URLs and web servers (cont.) Usually when you type a URL in your browser:

Data Visualisation with Google Fusion Tables

ENGR 102 Engineering Lab I - Computation

Statistical Computing (36-350)

CMSC201 Computer Science I for Majors

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

ENCM 501 Winter 2016 Assignment 1 for the Week of January 25

EXCEL SPREADSHEET TUTORIAL

Basic Programming Language Syntax

Maple for Math Majors. 12. Data Structures in Maple

CSC108: Introduction to Computer Programming. Lecture 1

Programming language components

Chapter 1. Data types. Data types. In this chapter you will: learn about data types. learn about tuples, lists and dictionaries

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

CSC148 Intro. to Computer Science

Software Development. Integrated Software Environment

Fundamentals: Expressions and Assignment

CSE 140 wrapup. Michael Ernst CSE 140 University of Washington

Transcription:

Introduction to Programming Dr Ben Dudson University of York

Programming course (this term) Aim Learn how to use Linux, IDL and either C or FORTRAN IDL needed in experimental labs (ICF and MCF) C or FORTRAN needed next term for computational lab

Programming course (this term) Aim Learn how to use Linux, IDL and either C or FORTRAN IDL needed in experimental labs (ICF and MCF) C or FORTRAN needed next term for computational lab The course Weekly problems 10 credits total. Part of Fusion Lab Office hour to discuss problems Wednesday 13:15 14:15, room A019 Online forum to discuss issues: http://plasmaforum.york.ac.uk

Why programming? Computers do not get bored, and don't make mistakes Perform calculations phenomenally quickly: A typical desktop performs nearly a billion additions/multiplications per second. Fastest supercomputers perform about a million times more. Why write code? Why not use existing tools like spreadsheets?

Why programming? Computers do not get bored, and don't make mistakes Perform calculations phenomenally quickly: A typical desktop performs nearly a billion additions/multiplications per second. Fastest supercomputers perform about a million times more. Why write code? Why not use existing tools like spreadsheets? Hard to extend: Try handling 4D arrays in Excel. For large problems these tools become too slow and/or cumbersome Research is often about doing something new. Often no program exists which will do exactly what you need.

Why programming? Programming is hard, and will take an effort to learn Requires attention to detail, creativity and abstract thought Can actually be very satisfying, even enjoyable! Problem-solving (like crossword, sudoku etc.) Get to see results of your work quickly A very marketable skill Widens your choice of projects and careers Shows general problem-solving ability

Programming Languages Way to specify computations and express algorithms precisely A human-readable language which can be automatically translated into processor operation codes (op-codes)

Programming Languages Way to specify computations and express algorithms precisely A human-readable language which can be automatically translated into processor operation codes (op-codes) Many different languages Approach problem solving in different ways so good to learn several Have evolved as different approaches have been tried, and technology has improved Each language has it's advantages and disadvantages for a particular application

Interactive Data Language Installed on your laptops (under Linux) A proprietary system created by Research Systems Inc Designed with scientists and engineers in mind, so very similar to FORTRAN. First version released 1979. Provides ways to visualise large amounts of data relatively easily, and create publication-quality plots. Used widely in space and plasma science: Culham, RAL, ESA, NASA,...

IDL on your laptops Start up IDL on your laptops. In a terminal window:

IDL expressions IDL can be used as a glorified calculator

IDL expressions IDL can be used as a glorified calculator Watch out for missing commas!

Variables labels for values, similar to x, y, z in maths Have a type : String Hello World! Integer 16-bit number (-32,767 to +32,767) Long 32-bit number (+/- 2 billion) Float Single precision (about 7 digits) Double Double precision (about 16 digits) Complex Single precision complex number Dcomplex Double precision complex Names can be descriptive names Can be given (assigned) a value In most languages this value can be changed

Variables in IDL To create a variable in IDL, just give it a value Variable names are case insensitive myvar is the same as MyvAr This is also true for FORTRAN, but not C

Variables in IDL To create a variable in IDL, just give it a value The help command tells you which variables are defined

Using variables Variables can be combined using operators (+ - * / ^ ) To print several quantities, separate with commas

Built-in IDL functions IDL comes with lots of built-in functions for things like sin(), cos() and tan()

IDL procedures and functions IDL makes a distinction between procedures like PRINT PRINT, var1, var2, These don't give (return) a result, so you couldn't have a = PRINT, var1, var2,... IDL functions do return a result, and need brackets a = SIN(x) If you don't do something with the result (e.g. store in a variable or print it) then IDL will complain If you're unsure, check the help pages...

Typing '?' gets to the help system. Reference guide with all built-in commands Getting help

Making decisions Often want run different commands depending on some criterion. Statements to do this are called conditionals Condition can be a combination of A < 10 yes no Note: Also called branching Numerical comparisons: Equal (EQ), greater than (GT), less than (LT), greater than or equal (GE) and less than or equal (LE) Boolean operators (AND, OR, NOT, XOR)

Conditionals in IDL Compare variables and values: EQ, GT, LT, GE, LE Used in IF statements to decide what code to run

Going round in circles Repeat operations, either a fixed number of times...

Going round in circles Repeat operations, either a fixed number of times or until a condition is met

Arrays When performing operations on lots of data, one way is to use loops. The (better) way is to use arrays Collection of variables of the same type Each component is labelled with a number (an index)

Arrays When performing operations on lots of data, one way is to use loops. The (better) way is to use arrays Collection of variables of the same type Each component is labelled with a number (an index) Array creation: INDGEN An array of integers FINDGEN Floating point numbers DINDGEN Double precision floats INTARR LONARR FLTARR Integers, all zero Long integers, all zero Floats, all zero

Array operations In IDL, operations on arrays apply to each element in the array: IDL> a = findgen(5) IDL> print, a 0.0 1.0 2.0 3.0 4.0 IDL> a = a + 1 IDL> print, a 1.0 2.0 3.0 4.0 5.0 This is also true in FORTRAN, but not in C. There are ways to do this in C++.

Extending arrays Arrays can also be joined together (concatenated) and extended

Indexing and slicing arrays Array elements or ranges can be extracted Individual variables can also be changed Missing brackets result in error

WHERE command Allows you to select and manipulate parts of an array, depending on some criterion. Like IF for arrays More complicated conditions using AND, OR, XOR and NOT

Programming components Several components are found in (almost) all languages Variables: Storage locations for values Expressions: Perform a calculation using variables Branching: Check if a condition is true, and if so perform some operation Loops: Repeat a set of operations until some condition is true Functions: A group of operations which can be applied to input variables and produce some result

Summary Programming requires thinking about algorithms, and is something best learnt through practice This week you have lectures and classes on IDL Problem sheets this term in IDL and C or FORTRAN IDL is a relatively easy language to learn, and will be vital for your experimental labs later this term and next. We have covered the basic building blocks of programming Go through programming handout Make a start at the IDL exercises http://www-users.york.ac.uk/~bd512/teaching.shtml for course information and links