1 / 21

MET 50

MET 50. CHARACTER DATA. Character data. We have extensively used REAL and INTEGER data types. There is also: CHARACTER data COMPLEX data LOGICAL data. Character data. COMPLEX numbers take the form: Z = X + i Y where X and Y are both real numbers

kim-johns
Download Presentation

MET 50

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MET 50 CHARACTER DATA

  2. Character data We have extensively used REAL and INTEGER data types. There is also: CHARACTER data COMPLEX data LOGICAL data MET 50, FALL 2011

  3. Character data COMPLEX numbers take the form: Z = X + iY where X and Y are both real numbers and i2= -1, so that i = (-1) MET 50, FALL 2011

  4. Character data Z = X + iY X is called the real part of Z {denoted Re(Z)} REAL (X)  value Y is called the imaginary part of Z {denoted Im(Z)} AIMAG (X)  value MET 50, FALL 2011

  5. Character data Fortran stores Z as two real numbers: X and Y When you write PRINT*,Z You get: (12.0, -9.0) MET 50, FALL 2011

  6. Character data CHARACTER DATA Letters, spaces, punctuation marks Combined into something called a STRING MET 50, FALL 2011

  7. Character data Written in code as follows: “STRING” or ‘STRING’ MET 50, FALL 2011

  8. Character data Declared as follows: CHARACTER (n) :: string Where “n” is the length = number of characters in the string MET 50, FALL 2011

  9. Character data example: CHARACTER (3) :: month Then “month” is type character with 3 elements, such as janfebmar Perhaps you want to print a table of results with the month printed at the top … see later for format! MET 50, FALL 2011

  10. Character data Other ways to declare: CHARACTER (LEN=n) :: string1 CHARACTER :: string2  Length in 2nd example is assumed to be ONE!!! MET 50, FALL 2011

  11. Character data Other ways to declare: CHARACTER :: stringa*10, stringb*20, stringc*25 MET 50, FALL 2011

  12. Character data To specify the value of a string: CHARACTER (8) :: name name=“John Doe” Note that the space counts as a character!! CHARACTER (21) :: filename filename=“temperature_data_2005” MET 50, FALL 2011

  13. Character data Formatted read/write of a string: In the FORMAT statement, use the descriptor: “An” As in: format (1x, I5, A20, F10.2) Options: “I”, “F”, “E”, and now…”A” (also “D”…last slides) MET 50, FALL 2011

  14. Character data Unformatted read/write: CHARACTER (3) :: MONTH INTEGER :: NUMBER READ*,MONTH, NUMBER You might enter: “JAN” 150 MET 50, FALL 2011

  15. Character data Defects of character (hahaha!) If a string is read in that is too long, it is truncated on the right. CHARACTER (6) :: DAY DAY = “WEDNESDAY” DAY is stored as WEDNES MET 50, FALL 2011

  16. Character data If a string is read in that is too short, it is padded with blanks on the right. CHARACTER (12) :: DAY DAY = “WEDNESDAY” DAY is stored as “WEDNESDAY ” MET 50, FALL 2011

  17. Character data Character data can be “added” !!! The operation is called: concatenation “cat” for short character :: first*5, second*6, third*11 first = ‘minor’ second = ‘ thing’ third = first // second produces… third = ‘minor thing’ MET 50, FALL 2011

  18. Character data Useful??? Creation of file names inside some code… character :: first*9, second*4, third*9 character :: title*22 first = ‘data-for-’ third = ‘-smoothed’ DO YEAR = 1,10 if (year == 10) then second = ‘2010’ title = first // second // third endif ! Produces title = ‘data-for-2010-smoothed’ OPEN (15, file=‘title’) END DO MET 50, FALL 2011

  19. Character data DOUBLE PRECISION data… Suppose you declare: REAL :: TEMP and later print a value with PRINT*,TEMP  a number with certain number of digits after the decimal. MET 50, FALL 2011

  20. Character data Instead if you declare: DOUBLE PRECISION:: TEMP and later print a value with PRINT*,TEMP • a number with DOUBLE the number of digits after the decimal. • Double precision! MET 50, FALL 2011

  21. Character data This may happen if you get some code that has run on a high-end machine (e.g., 64-bit) and you now want to run it on a cheapo workstation (e.g., 16-bit) … less resolution of numbers … less accuracy See page 230 !! MET 50, FALL 2011

More Related