# PHYS303

75 %
25 %
Education

Published on March 6, 2014

Author: fyjordan9

Source: slideshare.net

## Description

PHYS303

C OMPUTATIONAL P HYSICS Instructor Dr. Fawaz Hrahsheh Department of Physics Jordan University of Science and Technology Second Semester 2013/2014 1/7

SUBPROGRAMS • Fortran codes that solve real problems often have tens of thousands of lines. • The only way to handle such big codes is to split them into many smaller subprograms. • Subprogram is a small piece of code that solves a speciﬁc well deﬁned subproblem. • subprogram can be invoked several times for different inputs during the calculations. • Fortran has two different types of subprograms: Functions and subroutines. • we start the subprograms by typing contains. 2/7

F UNCTIONS • Similar to mathematical functions, Fortran functions takes a set of input variables or parameters and return a output values. • In general, Fortran function always has a type, .i.e, real, integer etc. • The returns values has to be stored in a variable has the same name of the function. • Functions are terminated by return statement instead of stop. • Variables deﬁned inside Function are invisible by the main body • A function can call another function • Only one function for each function subprogram • General structure of a function is: type function name (variables) declarations statements return 3/7

E XAMPLES ON F UNCTIONS program myfunction implicit none real q,r read*,q,r print*,f(q),g(q,r) !---------------------contains real function f(x) real:: x f=2.0-x-x**2 return end function !---------------------real function g(x,y) real:: x,y,t t=f(x) g=x*y-y**2+f(x) !or g=x**2+xy**3+t-t**2/(1-t)+t**4/(1-t)**3 return end function end program myfunction !---------------------- 4/7

S UBROUTINE • The subroutine has no type. • The body of subroutine is actually a small program and could return more than one value • General structure of a subroutine is: subroutine name (input variables,output variables) declarations statements return end 5/7

E XAMPLES ON SUBROUTINE program summations implicit none real q,r,w read*,q call summ(q,r,w) print*,r,w !---------------------contains subroutine summ(x,y,z) implicit none real, intent(in)::x real,intent(out)::y,z integer i; real phi phi=0 do i=1,10 phi=phi+x*(i) enddo y=sqrt(phi) z=sin(y) end subroutine summ end program 6/7

C ONT.. program swaping implicit none real i,j read*,i,j print’(1x,a,I2,5x,a,I2)’,"i=",i,"j=",j call swap(i,j) print’(1x,a,I2,5x,a,I2)’,"i=",i,"j=",j !---------------------contains subroutine swap(m,n) implicit none real, intent(inout)::m,n real phi phi=m m=n n=phi end subroutine swap end program 7/7

 User name: Comment:

## Related presentations

#### Top 3 Knife Fighting Styles From Around the World

September 26, 2020

#### 5 Important Thermal Engineering Topics You Should ...

September 26, 2020

#### Assignment Help Melbourne by My Assignment Service...

September 26, 2020

#### How to Prepare for EC-Council 312-76 Exam

September 26, 2020

#### Ace Oracle 1z0-809 Certification with Actual Quest...

September 26, 2020

#### [PDF] Oracle 1Z0-338 Exam Questions and Syllabus

September 26, 2020

## Related pages

### PHYS303 - hleiqawi - Google Sites

Course description: ( عربي ) PHYS303 is the first semester of an undergraduate two-semester sequence of electromagnetic theory which covers the basic ...

### Atomic and Solid-State Physics - PHYS303 - 2016 Course ...

Atomic and Solid-State Physics - PHYS303. ... Macquarie University, Sydney | Last Updated: Thursday, 15th October, 2015 . ABN 90 952 ...

### PHYS 303: Classical Mechanics (Fall 2015)

PHYS 303: Classical Mechanics (Fall 2015) Syllabus. Course Materials

### people.physics.tamu.edu

Contents AdvancedMechanicsII.Phys303 1 Lecture1.ReviewofPhys302. Newtonianformulation. 1 1.1. Conservationlaws. 1 Lecture2.ReviewofPhys302 ...

### Classical Mechanics Physics 303 - William & Mary - Physics

Classical Mechanics — Physics 303 Fall Semester 2013 Also available at http://physics.wm.edu/~carlson/phys303.pdf For 2012 ﬁnal exam, go to http ...

### Physics 303 Information - William & Mary Physics Department

Professor: Keith Griffioen Office: Small 215 Phone: 1-3537 Office Hours: by appointment Lectures: MWF 10am; Small 102 Problem Session: F 2pm; Small 102

### Physics 303 homepage

classical mechnics fall 2013 ... schedule (including lecture notes, HW assignments and HW solutions) grading: The grades will be an average of homework ...

### Syllabus - Fall 2012 Physics 303 Classical Mechanics

Syllabus - Fall 2012 Physics 303 – Classical Mechanics Robert N. Oerter (roerter@gmu.edu) Office Hours: MWF 9:30-10:20 AM Room 301B, Science & Tech I ...