{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Fortran_Lecture_3 - Lecture 3 Variable Types and...

Info icon This 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
Image of page 1

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

View Full Document Right 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 7.08949029E-295
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern