Tuesday, December 4, 2012

Format statement

Format Statement
             Format statement is an executable statement that used to read or write or input output statement . To read definite type of data from definite location or to write definite type of data in definite input device or to display the output in definite location is the read or write directed Format statement.

In Format statement we have definite type of field or format edit descriptor which are given below
F field : it is used to read or write the real numbers . That is the general field specification which is used to read or write the real numbers. ( F  field কে সাধারণত real number কে read অথাবা write করানোর জন্য ব্যাবহার করা হয়।)
E field: It is used to read or write the exponential form.That is the general field specification to read or write the exponential form.
( E field কে সাধারণত exponential form কে read অথবা write করার জন্য ব্যাবহার করা হয়।)
I field: The general field specification for reading or writing the integer values . That is to read or write the integer values we use I field.( Integer value কে  read অথবা write করার জন্য আমরা সধারণত I field ব্যাবহার করে থাকি)
X field: The general field specification for giving a space before or between the values or for neglecting columns .( x field ব্যাবহার করা হয় value গুলোর আগে বা পরে খালি স্থান রাখার জন্য)
Slash (/): It is used to jump to the next row .(  এক রো থেকে আর এক রোতে যাওয়ার জন্য (/) ব্যাবহার করা হয়)
কয়একটি উদাহরন এর সাহায্য আমরা format সর্ম্পকে ধারণা নেওয়ার চেষ্টা করব।
Example:  For Formatting real values
1.           Write a Fortran problem to compute the surface area and volume of a sphere whose diameter is 9.45 up to 4 decimal place
Solution :
1234567890
                          Pi = 3.1416
              Write(*,*) 'put the value of diameter of the sphere A'
              Read(*,*) A
              B = A/2
              S=4*pi*B**2
               V = (4*pi*B**3)/3
               write(*,*) ' The result of sphere and volume is ='
              Write(*,40)s, v
  40        Format(2x, 2F10.4)
              End
Description :
         Here the  result will be “The result of sphere and volume  is = “
280.5527             441.8705
Here we found that each value of the result have 4 digit after the decimal point. This why for the Format statement. In Format statement we use 2x , which means that it will keep two space before showing the result. And 2F10.4 indicate that there are two real values (sphere and volume i.e s and v). The tow real value will take 10 digit and between 10 digit there will have 4 digit after decimal point.
2.         If we want to show the above program for exponential form then it will be.
1234567890
               Pi = 3.1416
              Write(*,*) 'put the value of diameter of the sphere A'
              Read(*,*) A
              B = A/2
              S=4*pi*B**2
               V = (4*pi*B**3)/3
               write(*,*) ' The result of sphere and volume is ='
              Write(*,40)s, v
  40        Format(2x, 2E10.4)
               End 
Description :
Here the result will be “  The result of sphere and volume is =”
            0.2806E+03 0.441E+03
Because here we use E edit descriptor for showing the in exponential form.
3.  Similarly if we want to show the result in Integer form then it will be as. In this case we have to declare the integer S,V,B . Because s v and b are the real variable name. So we have declare it as it is integer.
1234567890
                integer S,B,V
                 Pi = 3.1416
              Write(*,*) 'put the value of diameter of the sphere A'
               Read(*,*) A
              B = A/2
              S=4*pi*B**2
               V = (4*pi*B**3)/3
               write(*,*) ' The result of sphere and volume is ='
              Write(*,40)s, v
  40        Format(2x, I10,'   ',I10)
              End
Description :
Here the result is “ The result of sphere and volume is =”
201                                                                268
Here does not include any real  number. Here in the Format statement we use I10 and there is no decimal point. It is why integer is always non fractional number so in format statement we do include ant decimal point. 

No comments:

Post a Comment