CHARACTER DATA MET 50. Character data We have extensively used REAL and INTEGER data types. There is also: CHARACTER data COMPLEX data LOGICAL data 12/1/2011.

Slides:



Advertisements
Similar presentations
Fortran 4- Reading and Writing from Data Files Chapter 4 of your Fortran book.
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
MORE ON… MAKING YOUR OUTPUT LOOK NICE! MET 50. Pretty output Recall the more sophisticated PRINT statement: PRINT nn, GRAV nn FORMAT (stuff) We use the.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
MAKING YOUR OUTPUT LOOK NICE! MET 50. The “IF” statement Suppose we have the statements: REAL, parameter :: GRAV = 9.81 PRINT*, ‘Value of GRAV is:’,GRAV.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Introduction to a Programming Environment
Chapter 5 Input / Output. 2 Control over input & output  The input and output are basically facilitates a communication between the user and the program.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
Assignment #2, 12- month Calendar CS-2301, B-Term Programming Assignment #2 12-Month Calendar CS-2301, System Programming for Non-Majors (Slides.
FORTRAN PROGRAMMING BASICS MET 50. Programming Basics The basic layout of all programs is as follows (p.33) PROGRAM name = heading (i.e., title) Specifications.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Homework Reading Programming Assignments
Fortran 1- Basics Chapters 1-2 in your Fortran book.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
How to Write a Fortran Jiffy (C)2005 Mark Rould University of Vermont.
Lecture #5 Introduction to C++
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Other data types. Standard type sizes b Most machines store integers and reals in 4 bytes (32 bits) b Integers run from -2,147,483,648 to 2,147,483,647.
INPUT / OUTPUT STATEMENTS
Data types  CHAR (size): This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters.
1 Information Representation in Computer Lecture Nine.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
Beginning Fortran Introduction 13 October 2009 *Black text on white background provided for easy printing.
صياغة البرنامج Coding the Program. خرائط التدفق Flowchart ويطلق عليها أيضاً خرائط سير العمليات وهي مجموعة من الرموز المتعارف عليها تستخدم لتوضيح الخطوات.
Basic Java Syntax Comments Basic data types Operators and assignment.
Python Lesson 1 1. Starter Create the following Excel spreadsheet and complete the calculations using formulae: 2 Add A1 and B1 A2 minus B2 A3 times B3.
Introduction to Programming Python Lab 5: Strings and Output 05 February PythonLab5 lecture slides.ppt Ping Brennan
Characters and Strings
MIT AITI Lecture 2 The of Java In the following lectures you will learn the basic structures that make up the Java programming language: »Variables.
Announcements Assignment 1 due Wednesday at 11:59PM Quiz 1 on Thursday 1.
CIS 338: VB Variables Dr. Ralph D. Westfall April, 2011.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Expressions and Data Types Professor Robin Burke.
Fundamental of Fortran Part 1 Dr.Entesar Ganash. Numerical types: An integer: is a number which do not has any decimal point. In Fortran, the integer.
CSCE Do Loops Simplest form DO j = 1,100 PRINT *,j END DO Variable j runs from 1 to 100 counting by ones.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Numbers in ‘C’ Two general categories: Integers Floats
Introduction to Programming
How Computers Store Variables
Chapter 6: Data Types Lectures # 10.
JavaScript Syntax and Semantics
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
More C++ Basics October 4, 2017.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computational Methods of Scientific Programming
Introduction to the C Language
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Introduction to Python
WEEK-2.
B065: PROGRAMMING Variables 1.
File Compression Even though disks have gotten bigger, we are still running short on disk space A common technique is to compress files so that they take.
FILE PROCESSING Opening Files Why Files?
Primitive Types and Expressions
Unit 3: Variables in Java
OUTPUT DESIGN PRINT K, expression list K FORMAT (specification list)
Presentation transcript:

CHARACTER DATA MET 50

Character data We have extensively used REAL and INTEGER data types. There is also: CHARACTER data COMPLEX data LOGICAL data 12/1/2011 MET 50, FALL

Character data COMPLEX numbers take the form: Z = X + iY where X and Y are both real numbers and i 2 = -1, so that i =  (-1) 12/1/2011 MET 50, FALL

Character data Z = X + iY X is called the real part of Z {denoted Re(Z)} REAL (X)  value Y is called the imaginary part of Z {denoted Im(Z)} AIMAG (X)  value 12/1/2011 MET 50, FALL

Character data Fortran stores Z as two real numbers: X and Y When you write PRINT*,Z You get:(12.0, -9.0) 12/1/2011 MET 50, FALL

Character data CHARACTER DATA Letters, spaces, punctuation marks Combined into something called a STRING 12/1/2011 MET 50, FALL

Character data Written in code as follows: “STRING” or ‘STRING’ 12/1/2011 MET 50, FALL

Character data Declared as follows: CHARACTER (n) :: string Where “n” is the length = number of characters in the string 12/1/2011 MET 50, FALL

Character data example: CHARACTER (3) :: month Then “month” is type character with 3 elements, such as jan feb mar Perhaps you want to print a table of results with the month printed at the top … see later for format! 12/1/2011 MET 50, FALL

Character data Other ways to declare: CHARACTER (LEN=n) :: string1 CHARACTER :: string2  Length in 2 nd example is assumed to be ONE!!! 12/1/2011 MET 50, FALL

Character data Other ways to declare: CHARACTER :: stringa*10, stringb*20, stringc*25 12/1/2011 MET 50, FALL

Character data To specify the value of a string: CHARACTER (8) :: name name=“John Doe” Note that the space counts as a character!! CHARACTER (21) :: filename filename=“temperature_data_2005” 12/1/2011 MET 50, FALL

Character data Formatted read/write of a string: In the FORMAT statement, use the descriptor: “An” As in: format (1x, I5, A20, F10.2) Options: “I”, “F”, “E”, and now…”A” (also “D”…last slides) 12/1/2011 MET 50, FALL

Character data Unformatted read/write: CHARACTER (3) :: MONTH INTEGER :: NUMBER READ*,MONTH, NUMBER You might enter: “JAN” /1/2011 MET 50, FALL

Character data Defects of character (hahaha!) If a string is read in that is too long, it is truncated on the right. CHARACTER (6) :: DAY DAY = “WEDNESDAY” DAY is stored as WEDNES 12/1/2011 MET 50, FALL

Character data If a string is read in that is too short, it is padded with blanks on the right. CHARACTER (12) :: DAY DAY = “WEDNESDAY” DAY is stored as “WEDNESDAY ” 12/1/2011 MET 50, FALL

Character data Character data can be “added” !!! The operation is called: concatenation “cat” for short character :: first*5, second*6, third*11 first = ‘minor’ second = ‘ thing’ third = first // second produces… third = ‘minor thing’ 12/1/2011 MET 50, FALL

Character data Useful??? Creation of file names inside some code… character :: first*9, second*4, third*9 character :: title*22 first = ‘data-for-’ third = ‘-smoothed’ DO YEAR = 1,10 if (year == 10) then second = ‘2010’ title = first // second // third endif ! Produces title = ‘data-for-2010-smoothed’ OPEN (15, file=‘title’) END DO 12/1/2011 MET 50, FALL

Character data DOUBLE PRECISION data… Suppose you declare: REAL :: TEMP and later print a value with PRINT*,TEMP  a number with certain number of digits after the decimal. 12/1/2011 MET 50, FALL

Character data Instead if you declare: DOUBLE PRECISION:: TEMP and later print a value with PRINT*,TEMP  a number with DOUBLE the number of digits after the decimal.  Double precision! 12/1/2011 MET 50, FALL

Character data This may happen if you get some code that has run on a high- end machine (e.g., 64-bit) and you now want to run it on a cheapo workstation (e.g., 16- bit) … less resolution of numbers … less accuracy See page 230 !! 12/1/2011 MET 50, FALL