02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Data types and data objects<br />

Intrinsic data types<br />

In standard-conforming programs, a logical value of .TRUE. is represented by 1, and .FALSE.<br />

is represented by 0. In nonstandard-conforming programs involving arithmetic operators with<br />

logical operands, a logical variable may be assigned a value other than 0 or 1. In this case, any<br />

nonzero value is .TRUE., and only the value zero is .FALSE.<br />

Character substrings<br />

A character substring is a contiguous subset of a character string. The substring is defined by<br />

the character positions of its start and end within the string, formatted as follows:<br />

string ([ starting-position ] : [ ending-position ])<br />

starting-position<br />

ending-position<br />

The length of the substring is:<br />

38<br />

is a scalar expression. If starting-position is omitted, a value of 1 is<br />

assumed. The starting-position must be greater than or equal to 1,<br />

unless the substring has zero length.<br />

is a scalar integer expression. If ending-position is omitted, the value of<br />

the length of the character string is assumed.<br />

MAX (ending-position - starting-position + 1, 0)<br />

The following example, substring.f90, illustrates the basic operation on a substring.<br />

Example 3-1 substring.f90<br />

PROGRAM main<br />

CHARACTER(LEN=15) :: city_name<br />

city_name = 'CopXXXagen'<br />

PRINT *, “The city's name is: “, city_name<br />

city_name(4:6) = 'enh' ! assign to a substring of city_name<br />

PRINT *, “The city's name is: “, city_name<br />

END PROGRAM main<br />

Here are the command lines to compile and execute the program, along with the output from<br />

asamplerun:<br />

$ f90 substring.f90<br />

$ a.out<br />

The city’s name is: CopXXXagen<br />

The city’s name is: Copenhagen<br />

Chapter 3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!