Fortran_Lecture_5

Fortran_Lecture_5 - Fortran Class Notes Lecture 5...

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

View Full Document Right Arrow Icon
Fortran Class Notes Lecture 5 – Subroutines and Double Precision Long, complex programs are often divided up into pieces. Being able to look at the program in smaller chunks can make the code and structure easier to understand. There are other reasons to divide the program…it can help to shorten the length of the file by using a set of code multiple times. In Fortran, there are three types of modules: program, subroutine, and function. For now, we’ll concentrate on subroutines; we may return to the subject of functions later in the semester. Normal programs are what we’ve worked with so far. They begin with the “program” command and a name, and they end with “stop” and “end”. Subroutines are slightly different. They start with the “subroutine” command and a name, and they end with “return” and “end”. Everything in the middle, including declarations, is done exactly the same way in programs and subroutines. Here’s a quick example: program subexample ! This program shows how a subroutine works. 50 j=0 write(*,*) ‘Enter a positive integer.’ read(*,*) i call checkinput(i,j) if (j.eq.1) goto 50 if (i.le.5) write(*,*) 'AUBURN' if (i.gt.5) write(*,*) 'TIGERS' stop end subroutine checkinput(i,j) ! This subroutine checks for invalid input. if (i.lt.0) then write(*,*) 'No negatives, please!' j=1 end if return end In Force 2.0, the program and all subroutines must be saved in the same .f file, but the order does not matter. Subroutines are activated by the “call” command, which is
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
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 / 3

Fortran_Lecture_5 - Fortran Class Notes Lecture 5...

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

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