1 / 12

صياغة البرنامج Coding the Program

صياغة البرنامج Coding the Program. خرائط التدفق Flowchart ويطلق عليها أيضاً خرائط سير العمليات وهي مجموعة من الرموز المتعارف عليها تستخدم لتوضيح الخطوات المنطقية اللازمة لحل مشكلة ما. عناصر البرنامج. Program name Type declarations Assignment and Input/Output Statements Comments

Download Presentation

صياغة البرنامج Coding the Program

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. صياغة البرنامجCoding the Program

  2. خرائط التدفقFlowchart ويطلق عليها أيضاً خرائط سير العمليات وهي مجموعة من الرموز المتعارف عليها تستخدم لتوضيح الخطوات المنطقية اللازمة لحل مشكلة ما.

  3. عناصر البرنامج • Program name • Type declarations • Assignment and • Input/OutputStatements • Comments • Subprograms

  4. Hello1 بداية program Hello ! ! talk to the computer ! write (*,*) 'Hello, world' stop end نهاية الازرق = شفرة (code) الاخضر = ملاحظات (comments) المكونات الاساسيةلاي برنامج

  5. Fortran 90: Data types and constants CHARACTER constant: a string of one or more characters between single or double quotes. e.g. "Fred", ' ' (a blank) Numerical constants may be positive, negative or zero. If positive the sign is optional. Embedded commas (e.g. 1,000,000) or spaces (1 000 000) are not permitted. INTEGER constant: any number not containing a decimal point and/or exponent. e.g. 2153 -36 0 123456 999 Range is machine dependent. On SUN, PC and many others to > |2 000 000 000| Complete accuracy. (32 bits = 4 bytes)

  6. REAL constant: any number containing a decimal point and/or exponent (“scientific” notation) e.g. 21.362 -9.6405 0.0 -25. .00125 The exponent is the letter E followed by an integer constant representing a power of 10 e.g. -3.5E4 ( 3 5 .( 104 )0.263E-6 0 263 10 6 . ) 5E+12 ( 5 1012)1E-8 ( 10 8 ) decimal point not required if exponent present. Precision depends on computer and compiler. SUN, PC: 6 to 7 decimal digits Exponent range is ±38~ ± ± 10 38 REAL numbers: Beware of rounding errors and truncation. DOUBLE PRECISION: for greater range and precision (64 bits total). 15-17 digits, range . Constants must be in exponent form using D. ~ ± ± 10 308 e.g. 5D12, 3.141592653589793D0, 1D0 STRONGLY RECOMMENDED FOR SCIENTIFIC WORK

  7. Fortran 90: Standard character set A to Z (upper case), digits 0 to 9, underscore _ special characters: space = + - * ( ) , . ' : " ! % & ; < > ? $ For portability it is advisable to stick to these characters even in character constants, but most computers now use the ASCII character set to represent characters as 8 bit numbers (0-255). additional characters: a to z (lower case), # @ [ \ ] ^ ` { | } Any character acceptable to the computer may be used in CHARACTER constants. WARNING: Fortran compilers do not distinguish between upper and lower case except in character constants. i.e. ABCDE abcdeAbCdEaBcDe, etc.

  8. Other data types: LOGICAL, COMPLEX • Variable names: (and most other names, e.g. for PROGRAM) • First character must be a letter. • Remaining characters may be any combination of • letters, digits or underscore ( _ ) characters. • Maximum length is 31 characters. • e.g. A A12 Alpha_3 Next_Month width • Variables are names of ‘boxes’ in computer memory where • numerical or other data values are stored. • We must tell the compiler what type of data they will hold by • declaring all variables in Type statements. • e.g. old style new style • REAL a, b, c or REAL :: a, b, c • INTEGER count, year INTEGER :: count, year Use IMPLICIT NONE at the start of each program unit. Use comments to create a variable dictionary.

  9. Hello 2 program Hello ! implicit none real first, second, average ! ! talk to the computer ! write (*,*) 'Hello, world' read (*,*) first read (*,*) second average = (first+second)*0.5 write (*,*) average stop end

  10. Hello 3 program Hello ! implicit none real first, second, average ! ! talk to the computer ! write (6,*) 'Hello, world' read (5,*) first read (5,*) second average = (first+second)*0.5 write (6,*) average stop end

  11. Hello 4 program Hello ! ! with good programming habits ! implicit none real first, second, average integer kread, kwrite data kread/5/, kwrite/6/ ! ! talk to the computer ! write (kwrite,*) 'Hello, world' read (kread,*) first write (kwrite,*) 'first variable:', first read (kread,*) second write (kwrite,*) 'second variable:', second average = (first+second)*0.5 write (kwrite,*) 'average of first and second variable is:', average stop end

  12. program mprecision ! ! check out machine precision ! implicit none real epssp, onesp double precision epsdp,onedp integer n,i integer kread, kwrite Data kread/5/, kwrite/6/ ! epssp=1. epsdp=1.d0 !single precision: do n=1,20 do i=1,10 epssp=epssp/2. onesp= 1. +epssp end do write (kwrite,*) 'loop number',n*10,' onesp =',onesp,' epssp =', & & epssp end do write (kwrite,*) write (kwrite,*) ! double precision: do n=1,40 i=1,10 epsdp=epsdp/2.d0 onedp= 1. +epsdp end do write (kwrite,*) 'loop number',n*10,' onedp =',onedp,' epsdp =', & & epsdp end do stop end precision

More Related