Showing posts with label Fortran. Show all posts
Showing posts with label Fortran. Show all posts

Fortran Data Types, Storage and Numeric Ranges

The following text is taken from http://h71000.www7.hp.com/doc/82final/6443/6443pro_026.html
Table 8-1 HP Fortran Intrinsic Data Types, Storage, and Numeric Ranges
Data Type Bytes Description
BYTE (INTEGER*1) 1 (8 bits) A BYTE declaration is a signed integer data type equivalent to INTEGER*1 or INTEGER (KIND=1).
INTEGER 1, 2, 4, or 8 Signed integer whose size is controlled by a kind type parameter or, if a kind type parameter (or size specifier) is omitted, certain FORTRAN command qualifiers (see Section 8.2.1).
INTEGER (KIND=1)
INTEGER*1
1 (8 bits)
Signed integer value from --128 to 127 (--2**7 to 2**7--1). Unsigned values from 0 to 255 (2**8-1)
INTEGER (KIND=2)
INTEGER*2
2 (16 bits)
Signed integer value from --32,768 to 32,767 (--2**15 to 2**15--1). Unsigned values from 0 to 65535 (2**16-1) 1.
INTEGER (KIND=4)
INTEGER*4
4 (32 bits)
Signed integer value from --2,147,483,648 to 2,147,483,647 (--2**31 to 2**31--1). Unsigned values from 0 to 4,294,967,295 (2**32-1) 1.
INTEGER (KIND=8)
INTEGER*8
8 (64 bits)
Signed integer value from --9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (--2**63 to 2**63--1).
LOGICAL
1, 2, 4, or 8
Logical value whose size is controlled by a kind type parameter or, if a kind type parameter (or size specifier) is omitted, certain FORTRAN command qualifiers (see Section 8.3).
LOGICAL (KIND=1)
LOGICAL*1
1 (8 bits)
Logical values .TRUE. or .FALSE.
LOGICAL (KIND=2)
LOGICAL*2
2 (16 bits)
Logical values .TRUE. or .FALSE. 2
LOGICAL (KIND=4)
LOGICAL*4
4 (32 bits)
Logical values .TRUE. or .FALSE. 2
LOGICAL (KIND=8)
LOGICAL*8
8 (64 bits)
Logical values .TRUE. or .FALSE. 2
REAL
4 or 8
Real floating-point numbers whose size is controlled by a kind type parameter or, if a kind type parameter (or size specifier) is omitted, by using the FORTRAN command /REAL_SIZE qualifier. To control the floating-point format used in memory, use the FORTRAN command /FLOAT qualifier.
REAL (KIND=4)
REAL*4
4 (32 bits)
Single-precision real floating-point values in IEEE S_float or VAX F_float formats. IEEE S_float normalized values range from 1.17549435E--38 to 3.40282347E38. Values between 1.17549429E--38 and 1.40129846E--45 are denormalized 3.
VAX F_float values range from 0.293873588E--38 to 1.7014117E38.
DOUBLE PRECISION
REAL (KIND=8)
REAL*8
8 (64 bits)
Double-precision real floating-point values in IEEE T_float, VAX G_float, or VAX D_float formats. IEEE T_float normalized values range from 2.2250738585072013D--308 to 1.7976931348623158D308. Values between 2.2250738585072008D--308 and 4.94065645841246544D--324 are denormalized 3.
VAX G_float values range from 0.5562684646268004D--308 to 0.89884656743115785407D308.
VAX D_float values range from 0.2938735877055719D--38 to 1.70141183460469229D38.
You can change the data size of DOUBLE PRECISION declarations from REAL (KIND=8) to REAL (KIND=16) with the FORTRAN command /DOUBLE_SIZE qualifier.
REAL (KIND=16)
REAL*16
16 (128 bits)
Extended-precision real floating-point values in IEEE-like X_float format ranging from
6.475175119438025110924 4389582276465524996Q-4966
to
1.189731495357231765085 759326628007016196477Q4932. The smallest normalized number is
3.362103143112093506262 677817321753Q-4932.
COMPLEX
8, 16, or 32
Complex floating-point numbers whose size is controlled by a kind type parameter or, if a kind type parameter (or size specifier) is omitted, the FORTRAN command /REAL_SIZE qualifier. To control the floating-point format used in memory, use the FORTRAN command /FLOAT qualifier.
COMPLEX (KIND=4)
COMPLEX*8
8 (64 bits)
Single-precision complex floating-point values in a pair of floating-point parts: real and imaginary. Use the IEEE S_float or VAX F_float format. IEEE S_float real and imaginary parts range from 1.17549435E--38 to 3.40282347E38. Values between 1.17549429E--38 and 1.40129846E--45 are denormalized 3.
VAX F_float real and imaginary parts range from 0.293873588E--38 to 1.7014117E38.
DOUBLE COMPLEX
COMPLEX (KIND=8)
COMPLEX*16
16 (128 bits)
Double-precision complex floating-point values in a pair of parts: real and imaginary. Use the IEEE T_float, VAX G_float, or VAX D_float format. IEEE T_float format real and imaginary parts each range from 2.2250738585072013D-308 to 1.7976931348623158D308. Values between 2.2250738585072008D--308 and 4.94065645841246544D--324 are denormalized 3.
VAX G_float format real and imaginary parts each range from 0.5562684646268004D--308 to 0.89884656743115785407D308.
VAX D_float format real and imaginary parts each range from 0.2938735877055719D--38 to 1.70141183460469229D38.
COMPLEX (KIND=16)
COMPLEX*32
32 (256 bits)
Extended-precision complex floating-point values in a pair of IEEE X_float format parts: real and imaginary. The real and imaginary parts each range from
6.475175119438025110924 4389582276465524996Q-4966
to
1.189731495357231765085 759326628007016196477Q4932.
CHARACTER
1 byte (8 bits) per character
Character data represented by character code convention. Character declarations can be in the form CHARACTER(LEN= n), CHARACTER( n), or CHARACTER* n, where n is the number of bytes or n can be (*) to indicate passed-length format.
HOLLERITH
1 byte (8 bits) per Hollerith character
Hollerith constants.

1This range is allowed for assignment to variables of this type, but the data type is treated as signed in arithmetic operations.
2Logical data type ranges correspond to their comparable integer data type ranges. For example, in LOGICAL (KIND=2) L, the range for L is the same as the range for INTEGER (KIND=2) integers.
3You cannot write a constant for a denormalized number. For more information on floating-point underflow, see Section 2.3.24.

Fortran Format Statements

The following text is copied from http://www.cs.mtu.edu/~shene/COURSES/cs201/NOTES/chap05/format.html

Format Edit Descriptors

The tedious part of using Fortran format is to master many format edit descriptors. Each edit descriptor tells the system how to handle certain type of values or activity. Each value requires some positions. For example, an integer of four digits requires at least four positions to print. Therefore, the number of positions to be used is the most important information in an edit descriptor. We shall use the following convention of symbols:
  • w: the number of positions to be used
  • m: the minimum number of positions to be used
  • d: the number of digits to the right of the decimal point
  • e: the number of digits in the exponent part
Although we may print a number using as many positions as you want, this is only for input/output. This number of positions is not the precision (i.e., the number of significant digits) of that number. To be more precisely, computers normally can store real numbers up to seven significant digits. This is the precision of real numbers. However, we can print a real number using 50 positions in which 25 positions are for the fraction part. This is only a way of describing the appearance and does not change the precision of real numbers. The following are the editor descriptors to be discussed. Details will be given on subsequent pages.

Purpose
Edit Descriptors
Reading/writing INTEGERs
Iw
Iw.m
Reading/writing REALs
Decimal form
Fw.d
Exponential form
Ew.d
Ew.dEe
Scientific form
ESw.d
ESw.dEe
Engineering form
ENw.d
ENw.dEe
Reading/writing LOGICALs
Lw
Reading/writing CHARACTERs
A
Aw
Positioning
Horizontal
nX
Tabbing
Tc
TLc and TRc
Vertical
/
Others
Grouping
r(....)
Format Scanning Control
:
Sign Control
S, SP and SS
Blank Control
BN and BZ

Fortran Line Layout

I program in Fortran from time to time, but not frequently enough that I always remember the odd syntax requirements.  So I'm listing the required statement layout here for future reference.
 
Fortran Statement Layout
Columns 1-5 Label
Column 6 Continuation
Columns 7-72 FORTRAN statements
Columns 73-80 Programmer use
Comment statement - C in column 1 comment in columns 2-72


FORTRAN routines for computation of Special Functions

Occasionally I have to evaluate some obscure (at least to me) mathematical functions in Fortran.  Attempting to code these functions is no trivial task to get it right.  In many cases, these functions are series solutions requiring an unknown number of terms for computational accuracy.  A while back I found this site which has an extensive list of subroutines for evaluating mathematical functions in Fortran.  The subroutines are also optimized for to ensure the efficient calculation of an accurate answer, making their functions much better than anything I could have created.  So thanks to Jianming Jin and the Department of Electrical and Computer Engineering at University of Illinois at Urbana-Champaign.

Getting Started

I really enjoy programming and have learned a little about a lot of different languages but because each is slightly different and I can go months or years between using each one, I often forget what I have learned. So this blog is intended to be a repository to help me remember the little things I've learned about each language.