class26 - PHYS 5900 Class 26 11am-12:15pm Zi-Wei Lin...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: PHYS 5900 Class 26 (10/28/2009 11am-12:15pm) Zi-Wei Lin FORTRAN program for efield: download the following files from blackboard electric-field.f & efield.input Some basics of Fortran programming: REAL array_name(n_dimension) declares an array of type REAL with n_dimension elements CHARACTER*9 string_name declares string_name as a 9-character string READ(unit#, format) list reads list from a file associated with unit# using a format; unit# =5 or * represents the standard input; format =* means unformatted, =label means to use the statement label as the format. SUBROUTINE subr_name(variable1,variable2,...) starts the definition of a subroutine CALL subr_name(value1,value2,...) calls a subroutine subr_name FUNCTION func_name(variable1,variable2,...) or type FUNCTION func_name(variable1,variable2,...) starts the definition of a function and its type variable=func_name(value1,value2,...) calls a function func_name & assigns the values to variables RETURN returns from the subroutine or function. A subroutine or function needs variable declarations, as the main program; variables in the call statement (value1, value2, ...) could be changed by the subroutine or function; variables in the call statement must match CALL subr_name(value1,value2,...) calls a subroutine subr_name 2 class26-f.nb FUNCTION func_name(variable1,variable2,...) or type FUNCTION func_name(variable1,variable2,...) starts the definition of a function and its type variable=func_name(value1,value2,...) calls a function func_name & assigns the values to variables RETURN returns from the subroutine or function. A subroutine or function needs variable declarations, as the main program; variables in the call statement (value1, value2, ...) could be changed by the subroutine or function; variables in the call statement must match (in number, type, and dimension) the variables inside the subroutine or function; names need not to be matched. FORMAT(string1,format1,string2,format2) means to write string1 first, then uses format1 for the format of the 1st variable in WRITE, then writes string2, then uses format2 for the format of the 2nd variable in WRITE; a7 means 7 characters are available for a string; e12.6 means a numerical value in exponential notation with a total width of 12, where (on gfortran on my PC) 1 for the negative sign or the starting zero 1 for the decimal point 6 digits are used for decimals (after the decimal point) 1 for the symbol E 1 for the sign of the exponent 2 digits for the exponent acos() sqrt() Exercises: represents the ArcCos function represents the Square Root function Use SI units to calculate: A charge of 1.66782 10 7 Coulomb located at (-10 cm, 30 cm) & another charge of 6.67127 10 8 Coulomb at (30 cm, 20 cm); use the default evaluation point (0,0). Modify the input to use Gaussian units to calculate the same: A charge of 500 statcoulomb located at (-10 cm, 30 cm) & another charge of - 200 statcoulomb at (30 cm, 20 cm); use the default evaluation point (0,0). class26-f.nb 3 Modify the input to use Gaussian units to calculate the same: A charge of 500 statcoulomb located at (-10 cm, 30 cm) & another charge of - 200 statcoulomb at (30 cm, 20 cm); use the default evaluation point (0,0). Modify the .f program to change the theta-range to between -Pi and Pi. Modify the input to include one more charge (using Gaussian units): a charge of 300 statcoulomb located at (0 cm, -20 cm); still use the default evaluation point (0, 0) ...
View Full Document

This note was uploaded on 04/25/2010 for the course PHYS 5900 taught by Professor Lin during the Fall '09 term at East Carolina University .

Ask a homework question - tutors are online