AEROSPAC ENG PROBLM
AEROSPAC ENG PROBLM AER E 160
Popular in Course
Popular in Aerospace Engineering
This 9 page Class Notes was uploaded by Noel Koelpin on Sunday September 27, 2015. The Class Notes belongs to AER E 160 at Iowa State University taught by Staff in Fall. Since its upload, it has received 17 views. For similar materials see /class/214531/aer-e-160-iowa-state-university in Aerospace Engineering at Iowa State University.
Reviews for AEROSPAC ENG PROBLM
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/27/15
Conditions amp Logical Operators Conditional constructs provide a method for comparing values and performing different operations depending on those values For example the mathematical statement 4 S x S 6 represents two different conditions 4 S x and x S 6 FORTRAN can evaluate these conditions when they are placed in a conditional construct See the accompanying document quotForms of IF Statementsquot for more information on conditional constructs The following table lists relational operators the FORTRAN 77 operators also work in FORTRAN 90 Do not use REAL numbers due to round off use types use use May use types May use types often used with LOGICAL variables Separate conditions may be combined with the logical Boolean operators AND OR and NOT For example the range of numbers above could be programmed as IF 4 lt x AND x lt 6 THEN A number between 4 and 6 would satisfy both conditions Note that these conditions must be combined with AND and not OR why The choice of AND or OR is very specific to the conditions being evaluated You may evaluate several conditions at one time For example the condition IF a lt b AND b lt C OR d gt a THEN would be met if either d gt a or a S b S c Parentheses could be used for clarity but are not required IF a lt b AND b lt C OR d gt a THEN The operator is reserved for use with CHARACTER INTEGER kind4 or kind8 and LOGICAL data types This symbol differs from an assignment symbol An assignment symbol is used to assign known values on the right side of an expression to an unknown variable on the left side of an expression The quotexactly equalsquot symbol is used to compare two values Since REAL and COMPLEX numbers will generally have roundoff error associated with them two numbers may be close but will most likely not be exactly equal If you accidentally try to compare two real numbers with the symbol most compilers will warn you that you are attempting to make a quot oatingpoint comparisonquot To compare two REAL or COMPLEX numbers use a difference and a tolerance such as IF a b lt 0000001 THEN which for most practical purposes would mean a is equal to b Assume a and b are of type REAL kind4 or REAL kind8 in this example This example suggests another point comparisons can be made between expressions For example n 42 IF n2 lt x AND x lt n21 THEN is the same as IF 21 lt x AND x lt 20 THEN The radical b2 4610 in the quadratic equation biwlb2 4ac 2a x must be positive to evaluate the radical and obtain a real root Assuming a b and c are of type REAL kind4 or kind8 a condition to evaluate the radical would be IF b2 4ac gt 0e0 THEN where the parentheses are optional around b2 4 ac Logical Comparisons Next consider LOGICAL data types Assume that the variable answer has been declared as LOGICAL The following condition is the same as asking quotis the value of answertruequot IF answer THEN Any operations inside the IF statement would be executed if the value of answer was true whereas IF NOT answer THEN is the same as asking quotis the value of answer falsequot Any operations inside the IF statement would be executed if answer was false Example 1 The following example programs test logical conditions the rst tests for true and the second tests for false This program tests for a true logical condition PROGRAM logicaltest IMPLICIT NONE LOGICAL answer This loop will run until the user enters t or true for answer WRITE quotDo you want to continue this loop tfquot READ answer t will be read as true f as false IF answer EXIT If answer true then exit the loop END DO STOP END PROGRAM logicaltest This program tests for a false logical condition PROGRAM logicaltest IMPLICIT NONE LOGICAL answer I This loop will run until the user enters f or false for answer DO WRITE quotDo you want to continue this loop tfquot READ answer t will be read as true f as false IF NOT answer EXIT If answer false then exit the loop END DO STOP END PROGRAM logicaltest Formatted Output Consider the variables step velocity units and direction Assume step is an integer velocity is real units is a character string and direction is logical and that the values of each are units quotftsquot step 14 direction true velocity 14 422 Listdirected write statements of the form WRITE quotAt step quot step quot the velocity is quot velocity unitsquotquot WRITE quotUpward quot direction quotquot would create output to the screen that might look something like this At step 14 the velocity is 1442200 fts Upward T The output while in the correct order contains extra spaces and extra digits on velocity How could the format be improved ie controlled Through the use of FORMAT statements WRITE 10 step velocity units 10 FORMAT 1XquotAt step quotI2quot the velocity is quotF631XA4quotquot WRITE l2 direction 12 FORMAT 1X quotUpward quot Ll quot quot These statements would produce the output At step 14 the velocity is 14422 fts Upward T This output is free from extra spaces and has the correct number of digits for velocity Statement Numbers FORMAT statements are preceded by a number sometimes called a label and that number is used in WRITE statements to refer to the FORMAT statement A single FORMAT statement may be referenced multiple times ie with more than one WRITE statement The number can be anywhere from 1 to 99999 and is at the discretion of the programmer Suggestions 0 When possible put FORMAT statements next to the WRITE statements that reference them for clarity and readability 0 Keep statement numbers in order from lowest to highest for example to make finding the statement number a matter of looking downward through the file 0 Skip a few numbers between each statement number to leave room for future additions ie adding a new FORMAT statement in the middle of an existing code while still keeping the statement numbers in order Format Descriptors The FORMAT statement uses descriptors to control the format of the output Descriptors that might be common for aerospace engineering students to use include A E F I L Xand The X Descriptor This descriptor inserts spaces into the output and has the form X where is the number of spaces to include in the output For example 1X would insert one space while 10X would insert 10 spaces Notes 0 Placing 1X at the beginning of a FORMAT statement ie lO FORMAT 1X causes normal spacing placing a quotOquot in this position creates doublespaced output quot1quot with no X descriptor advances the output to a new page and quotquot overwrites an existing line An alternate method of inserting spaces would be to use quot quot 7 for example 1 quot quot would insert one space and 10 quot quot would insert ten spaces The A Descriptor This descriptor controls the format of CHARACTER strings and has the form A where is the number of characters to print out Examples Code Segment CHARACTER 20 2 first last first quotJanequot last quotDoequot WRITE 5 first last 5 FORMAT 1XA41XA3 Output Jane Doe Notes 0 The CHARACTER variable may have a greater length than the format descriptor which means the rightmost characters of the variable would not be printed The format descriptor may exceed the length of the CHARACTER variable as well which has the effect of adding blank spaces to the end of the variable on output The I Descriptor This descriptor controls the format of INTEGER strings and has the form I where is the number of digits to print out Examples Code Segment INTEGER i j k i 1000 j 12 k 519 WRITE 7 i j k 7 FORMAT 31XI3 Output 12 519 Notes 0 The first variable i did not print correctly because I 3 allows for too few digits indicates the integer is too large to fit in the allocated number of digits The second integer j is preceded by one extra space since it has only two digits where as I3 specifies three Making the descriptor larger than the actual integer is akin to adding spaces to the left of the integer CoMng3lXI3 thesmneasco ng1XI31XI31XI3L The F Descriptor This descriptor controls the format of REAL strings and has the form F where left is the number of digits to print out including the decimal point and the right is the number of decimal places Examples Code Segment REAL a b c d e a 975 b 00001 c 519000 d 7131330 e 1555 WRITE 9 a b C d 9 FORMAT 1XF411XF6421XF711XF41 Output 975 00001 519000 156 Notes 0 The variable d did not print correctly because F7 1 allows for too few digits indicates the real number is too large to fit in the allocated number of digits The variable e was truncated since F4 1 has one fewer decimal places than would be required Coding 2 1X F7 1 is the same as coding 1X F7 1 1X F7 1 The E Descriptor This descriptor causes REAL strings to be printed in exponential form and has the form E where left is the number of digits to print out including the decimal point and power of ten and the right is the number of decimal places Examples Code Segment REAL a b c d e a 975 b 00001 c 519000 d 713133 0 e 1555 WRITE 11 a b c d 11 FORMAT 1XE931XE7121XE1151XE41 Output O975E02 01E03 O519OOE05 071313EO6 Notes 0 The variable e did not print correctly because E4 1 allows for too few digits indicates the real number is too large to fit in the allocated number of digits and include the power often The variable d was truncated since E11 5 has one fewer decimal places than would be required so E1 1 6 would work Coding 2 1XE11 5 is the same as coding 1XE11 51XE11 5 The L and Descriptors This descriptor controls the format of LOGICAL strings and has the form L where is the number of spaces to output with the values quotTquot or quotFquot The descriptor causes output to be written to a new line Examples Code Segment LOGICAL answer switch answer true switch false WRITE 13 answer switch 13 FORMAT 1XquotThe answer is quotL1quotquot1XquotThe switch is on quotL5quotquot Output The answer is T The switch is on F Notes 0 The variable switch is output with several spaces before the value quotFquot since the field width is five The sentences containing answer and switch appear on different lines because of In this example no comma was necessary before or after but could have been included with no change in output 13 FORMAT 1XquotThe answer is quotL1quotquot1XquotThe switch is on quotL5quotquot Introoluction to OneDimensional Arrays General Purpose Aerospae engineers often work with lists of numbers Examples inlude saving many veloities atdifferentpoints in a flowing uid or saving heightatdifferentpoints along the traietory of a roket An array uses a ommon variable name with an index to save eah number in the list Example Consider the listofnunhers 52 32 47 99 These numbers mighthe saved in an array x as xl x2 52 x3 32 x4 4 7 x5 9 9 Arrays are used in a variety ofonputations For example arrays an be used to add up numbers in a ounter D0 loop sum O DOil5l sum sum Xl END DO where i is an index used to look up a speifi value ofx ln ontemporary versions of FORTRAN i an be either INTEGER or REAL Sine REAL nunhers involve roundoff errors inexperiened programmers should be wary ofusing REAL indies for the purposes of Aer E loll use only INTEGER indies An array with one index is alled a onedimensional arrayquot A one dimensional array an store one olunn or one row of data Example 2 reate a programto read up to n nunhers from an inputfile alled inputdatquot Assume n is the first line of the input le and that n numhers follow Whatis the differene between the following two exanples Notusing an array lOpen the input file and read in the list of numbers lNote that every number is replaced by the previous number lThe code cannot save more than one number at a time OPEN unit 12 file inputdat READ 12 n DO i l n READ 12 number END DO Using an array lOpen the input file and read in the list of numbers lEvery number is being saved based on the index i OPEN unit 12 file inputdat READ 12 n DO i l n READ 12 numberi END DO D Haugli Senior Lecturer Aer E 160 Aerospace Engineering II T 072008 OneDimensional Arrays Iowa State University
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'