Fortran_Lecture_3

Fortran_Lecture_3 - Lecture 3 Variable Types and...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 3 – Variable Types and Declarations, Program Structure Today’s first topic is variable types and declarations. Fortran has a very unusual way of handling declarations, but it’s easy to deal with as long as you’re aware of the quirk. Here’s an example: program declare1 write(*,*) bag write(*,*) hobby write(*,*) ink write(*,*) mom write(*,*) time write(*,*) zip stop end The output looks something like this (though the numbers will differ on each PC): 5.62364616E-039 1.40129846E-045 4199283 2293600 1.12103877E-044 5.88544794E-039 This program intentionally uses variables without setting them first, so ignore the warnings in Force. The point here is to see the general form of the random values that are displayed. When you run this program, the first two and last two numbers will always be real values, with several decimal places included. The middle two numbers will always be integer values. The reason this happens is that Fortran uses a standard implicit declaration of variable types. Unless you tell the program otherwise, all variables that start with the letters a-h and o-z will be real numbers, and all variables that start with the letters i-n will be integers. (Fortran variable names cannot begin with numbers.) This probably seemed like a good idea when Fortran was originally created, but it has caused a lot of confusion over the years. Luckily, you can easily overwrite these rules with manual variable declarations or your own implicit declarations. The next program shows how to do that: program declare2 implicit character*10 (a-h) implicit double precision (o-z) integer c real mass write(*,*) also write(*,*) c write(*,*) curb write(*,*) house
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
write(*,*) juke write(*,*) mass write(*,*) nick write(*,*) roll write(*,*) wing stop end The output looks something like this: ` " ¶@ ╠▬ 4013168 )N wBN 0 " α " ö\ 2293484 1.40129846E-045 4200140 1.62631115E-307
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/21/2011 for the course AERO 3970 taught by Professor Doucette during the Spring '11 term at Auburn University.

Page1 / 4

Fortran_Lecture_3 - Lecture 3 Variable Types and...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online