FORTRAN - CHARACTERS

Similar documents
This tutorial is designed for the readers who wish to learn the basics of Fortran.

PYTHON MOCK TEST PYTHON MOCK TEST III

DOCUMENT SECURITY IN WORD 2010

TCL - STRINGS. Boolean value can be represented as 1, yes or true for true and 0, no, or false for false.

Source: Fortran 90 3 Day Course (Univ. of Liverpool) URL: Ngo Van Thanh, NIMS Oct. 4, 2010

Characters & Strings in C

C# MOCK TEST C# MOCK TEST I

Information technology Programming languages Fortran. Part 2: Varying length character strings. [This page to be replaced by ISO CS.

1 Characters & Strings in Fortran

AWK - PRETTY PRINTING

Personal SE. Arrays Pointers Strings

Introduction to Python. Data Structures

Surprising behaviour of Fortran (90/95)

Introduction to Computer Programming for Non-Majors

RTL Reference 1. JVM. 2. Lexical Conventions

Introduction to string

CSc Introduction to Computing

Data Types and Basic Calculation

Watcom FORTRAN 77. Language Reference. Edition 11.0c

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

VHDL Lexical Elements

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

8. Characters and Arrays

String and list processing

Basic Language Constructs of VHDL

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

FORTRAN - ARRAYS. For example, to declare a one-dimensional array named number, of real numbers containing 5 elements, you write,

Exercise: Inventing Language

To declare an array in C, a programmer specifies the type of the elements and the number of elements required by an array as follows

C# MOCK TEST C# MOCK TEST II

SCALA ARRAYS. Following picture represents array mylist. Here, mylist holds ten double values and the indices are from 0 to 9.

DEPARTMENT OF MATHS, MJ COLLEGE

Introduction to Computer Programming for Non-Majors

CPE Summer 2015 Exam I (150 pts) June 18, 2015

Expressions and Variables

Strings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.

Arrays. Lecture 9 COP 3014 Fall October 16, 2017

Chapter 2 REXX STATEMENTS. SYS-ED/ Computer Education Techniques, Inc.

Cellular Automata Language (CAL) Language Reference Manual

DB2 MOCK TEST DB2 MOCK TEST I

Duhok Polytechnic University Amedi Technical Institute/ IT Dept. Halkawt Rajab Hussain

Introduction to Programming in Turing. Input, Output, and Variables

Eng. Mohammed Abdualal

Our Strategy for Learning Fortran 90

Ex: If you use a program to record sales, you will want to remember data:

Introduction to Lexical Analysis

Text. Text Actions. String Contains

UNIT- 3 Introduction to C++

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

"Hello" " This " + "is String " + "concatenation"

Variables and numeric types

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

CPS 506 Comparative Programming Languages. Syntax Specification

COMP 110/L Lecture 4. Kyle Dewey

Should you know scanf and printf?

Language Reference Manual

Lecture 2 Tao Wang 1

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

Variable and Data Type I

Lecture 2 FORTRAN Basics. Lubna Ahmed

appreciate the difference between a char and a string understand and use the String class methods

CST242 Strings and Characters Page 1

Visual C# Instructor s Manual Table of Contents

PYTHON- AN INNOVATION

Syntax and Variables

Creating Strings. String Length

Programming in C++ 4. The lexical basis of C++

gcc hello.c a.out Hello, world gcc -o hello hello.c hello Hello, world

Java s String Class. in simplest form, just quoted text. used as parameters to. "This is a string" "So is this" "hi"

Definition Matching (10 Points)

1 Lexical Considerations

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Differentiate Between Keywords and Identifiers

AP Computer Science Unit 1. Writing Programs Using BlueJ

Java Identifiers, Data Types & Variables

String Class in C++ When the above code is compiled and executed, it produces result something as follows: cin and strings

Lexical Structure (Chapter 3, JLS)

ME1107 Computing Y Yan.

Variable initialization and assignment

Getting started with Java

Honors Computer Science C++ Mr. Clausen Program 3A, 3B, 3C

Engineering Problem Solving with C++, Etter

Strings, Strings and characters, String class methods. JAVA Standard Edition

8. Characters, Strings and Files

Fortran Introduction

2 Input and Output The input of your program is any file with text. The output of your program will be a description of the strings that the program r

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CoCo Processor - Copyright (c) 1996 Imagine1, Inc.!!!!!!!!

SYSC 2006 C Winter String Processing in C. D.L. Bailey, Systems and Computer Engineering, Carleton University

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Lexical Analysis. Lecture 3. January 10, 2018

COMPUTER PROGRAMMING LOOPS

SAS 9 Programming Enhancements Marje Fecht, Prowerk Consulting Ltd Mississauga, Ontario, Canada

Introduction. For instance, if we need to store three whole numbers we can create two integer (int) variables called N1, N2 and tot. tot.

Principles of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Modern Programming Languages Lecture An Introduction to SNOBOL Programming Language

Chapter 8 Character Arrays and Strings

Transcription:

FORTRAN - CHARACTERS http://www.tutorialspoint.com/fortran/fortran_characters.htm Copyright tutorialspoint.com The Fortran language can treat characters as single character or contiguous strings. Characters could be any symbol taken from the basic character set, i.e., from the letters, the decimal digits, the underscore, and 21 special characters. A character constant is a fixed valued character string. The intrinsic data type character stores characters and strings. The length of the string can be specified by len specifier. If no length is specified, it is 1. You can refer individual characters within a string referring by position; the left most character is at position 1. Character Declaration Declaring a character type data is same as other variables: type-specifier :: variable_name For example, character :: reply, sex you can assign a value like, reply = N sex = F The following example demonstrates declaration and use of character data type: character(len=15) :: surname, firstname title = 'Mr. ' firstname = 'Rowan ' greetings = 'A big hello from Mr. Beans' print *, 'Here is ', title, firstname, surname print *, greetings end A big hello from Mr. Bean Concatenation of Characters The concatenation operator //, concatenates characters. The following example demonstrates this:

character(len=15) :: surname, firstname character(len=40):: name title = 'Mr. ' firstname = 'Rowan ' name = title//firstname//surname greetings = 'A big hello from Mr. Beans' print *, 'Here is ', name print *, greetings end Here is Mr.Rowan Atkinson A big hello from Mr.Bean Some Character Functions The following table shows some commonly used character functions along with the description: Function lenstring index string, sustring acharint iacharc trimstring scan string, chars verify string, chars adjustlstring adjustrstring len_trim string repeat string, ncopy Description It returns the length of a character string It finds the location of a substring in another string, returns 0 if not found. It converts an integer into a character It converts a character into an integer It returns the string with the trailing blanks removed. It searches the "string" from left to right unlessback =. true. for the first occurrence of any character contained in "chars". It returns an integer giving the position of that character, or zero if none of the characters in "chars" have been found. It scans the "string" from left to right unlessback =. true. for the first occurrence of any character not contained in "chars". It returns an integer giving the position of that character, or zero if only the characters in "chars" have been found It left justifies characters contained in the "string" It right justifies characters contained in the "string" It returns an integer equal to the length of "string" len(string) minus the number of trailing blanks It returns a string with length equal to "ncopy" times the length of "string", and containing "ncopy" concatenated copies of "string" Example 1 This example shows the use of the index function:

character (80) :: text integer :: i text = 'The intrinsic data type character stores characters and i=index(text,'character') strings.' if (i /= 0) then print *, ' The word character found at position ',i print *, ' in text: ', text end The word character found at position 25 in text : The intrinsic data type character stores characters and strings. Example 2 This example demonstrates the use of the trim function: character(len=15) :: surname, firstname title = 'Mr.' firstname = 'Rowan' print *, 'Here is', title, firstname, surname print *, 'Here is', trim(title),' ',trim(firstname),' ', trim(surname) end Example 3 This example demonstrates the use of achar function character:: ch integer:: i do i=65, 90 ch = achar(i) print*, i, ' ', ch end do end 65 A 66 B 67 C 68 D

69 E 70 F 71 G 72 H 73 I 74 J 75 K 76 L 77 M 78 N 79 O 80 P 81 Q 82 R 83 S 84 T 85 U 86 V 87 W 88 X 89 Y 90 Z Checking Lexical Order of Characters The following functions determine the lexical sequence of characters: Function llechar, char lgechar, char lgtchar, char lltchar, char Description Compares whether the first character is lexically less than or equal to the second Compares whether the first character is lexically greater than or equal to the second Compares whether the first character is lexically greater than the second Compares whether the first character is lexically less than the second Example 4 The following function demonstrates the use: character:: a, b, c a = 'A' b = 'a' c = 'B' if(lgt(a,b)) then print *, 'A is lexically greater than a' else print *, 'a is lexically greater than A' if(lgt(a,c)) then print *, 'A is lexically greater than B' else print *, 'B is lexically greater than A' if(llt(a,b)) then print *, 'A is lexically less than a'

if(llt(a,c)) then print *, 'A is lexically less than B' end a is lexically greater than A B is lexically greater than A A is lexically less than a A is lexically less than B Loading [MathJax]/jax/output/HTML-CSS/jax.js