Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran Forum

  1. Jan 18, 2007 #1
    Mentor's note (May 2012):

    This thread is closed to new posts. It is over five years old and has been resuscitated many many times by people finding it in Google searches or something. If you want to post a question about Fortran programming, please go to the parent forum

    https://www.physicsforums.com/forumdisplay.php?f=165

    and start a new thread (topic) by clicking the "New Topic" button. Give your new thread a suitably descriptive title.

    ------------------------------------------------------


    hey guys,
    I was reading the sticky threads and did not find much help for fortran so I thought I might list a a website that has a bunch of helpful people on it. It has an awesome forum for Fortran 90-95 aswell as other languages:

    www.tek-tips.com

    Its a no bull**** site for those who need it.

    Plus another 5c :

    I have been using FORTRAN 90/95 explained by Metcalf and Reid, not very helpful :grumpy:

    Regards
     
    Last edited by a moderator: May 24, 2012
  2. jcsd
  3. Aug 25, 2008 #2
    Hi guys
    As I m anew user for Fortran 77, so I am still struggling how to do the declaration, i mean what is the common block?I have written a code but gaveme error message about the declaration............
    any one could help
     
  4. Aug 25, 2008 #3

    Astronuc

    User Avatar

    Staff: Mentor

    Can you post the error message.

    A COMMON block is a way of storing data in memory. One can store arrays, vectors and scalar data.

    One can also label COMMON blocks.

    They are placed in the main routine and subroutines as necessary. If one does this, then it's not necessary to put the variables in the argument of the subroutine or function subroutine.

    http://labmon.io.usp.br/cursos/iof0227/fortran/common.htm
     
  5. Aug 25, 2008 #4
    implicit none
    c * LOCAL SCALARS
    integer i,N
    real*8 X,Y,sum1,sum2,arc
    c * COMMON BLOCKS
    integer dim(X),dim(Y)
    real*8 area,arc
    common/matpara/ area,arc,dim(X),dim(Y)
    1 read(*,*) dim(X),dim(Y)
    if (dim(X).ne.dim(Y)) then
    print *, 'The dim of X must be equal to dim of Y'
    go to 1
    else
    if (dim(X).le.3)
    print *, 'This is not a case'
    end if
    end if
    N=5
    Many thanks for ur help this is the code, but I do not know if the declaration is enough, also cos I need to call subroutine to do a job, so do I need to redefine varible again, is the way I have entered the array X Y correct,
    do 10 i=0, N-1
    read(*,*) X(i), Y(i)
    10 continue
    when I compiled I have got this error message

    Area.f: In program `MAIN__':
    Area.f:6:
    real*8 X,Y,sum1,sum2,arc
    1
    Area.f:8: (continued):
    integer dim(X),dim(Y)
    2
    Invalid declaration of or reference to symbol `x' at (2)
    Area.f:6:
    real*8 X,Y,sum1,sum2,arc
    1
    Area.f:8: (continued):
    integer dim(X),dim(Y)
    2
    Invalid declaration of or reference to symbol `y' at (2)
    Area.f:8:
    integer dim(X),dim(Y)
    1 2
    Invalid declaration of or reference to symbol `dim' at (2)]
    Area.f:6:
    real*8 X,Y,sum1,sum2,arc
    1
    Area.f:9: (continued):
    real*8 area,arc
    2
    Invalid declaration of or reference to symbol `arc' at (2)]
    Area.f:6:
    real*8 X,Y,sum1,sum2,arc
    1
    Area.f:10: (continued):
    common/matpara/ area,arc,dim(X),dim(Y)
    2
    Invalid declaration of or reference to symbol `arc' at (2)]
    Area.f:8:
    integer dim(X),dim(Y)
    1
    Area.f:10: (continued):
    common/matpara/ area,arc,dim(X),dim(Y)
    2
    Invalid declaration of or reference to symbol `dim' at (2)]
    Area.f:11:
    1 read(*,*) dim(X),dim(Y)
    ^
    Non-numeric character at (^) in label field [info -f g77
    Area.f:12:
    if (dim(X).ne.dim(Y)) then
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area.f:13:
    print *, 'The dim of X must be equal to dim of Y'
    ^
    Non-numeric character at (^) in label field [info -f g77
    Area.f:14:
    go to 1
    ^
    Non-numeric character at (^) in label field [info -f g77
    Area.f:15:
    else
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area.f:16:
    if (dim(X).le.3)
    ^
    Non-numeric character at (^) in label field [info -f g77
    Area.f:17:
    print *, 'This is not a Polygon'
    ^
    Non-numeric character at (^) in label field [info -f g77
    Area.f:18:
    end if
    ^
    Non-numeric character at (^) in label field [info -f g77
    Area.f:19:
    end if
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area.f:20:
    N=5
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area.f:22:
    read(*,*) X(i), Y(i)
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area.f:23:
    10 continue
     
  6. Aug 25, 2008 #5

    Borek

    User Avatar

    Staff: Mentor

    If they are identical, why do you read both of them, instead of reading one and use it twice?
     
  7. Aug 25, 2008 #6

    Astronuc

    User Avatar

    Staff: Mentor

    The statement:
    integer dim(X),dim(Y)

    requires the X and Y be integers. In F77, the subscripted variables are integers. Later versions for Fortran may be more flexible, but I'm not familiar with these.

    By convention, variable names starting with I, J, K, L, M, N are integers in FORTRAN (F77), and A-H,O-Z are real unless otherwise declared.

    Also, I'm not by the listing if the FORTRAN statements start in the 7th column, or 1st, but the 1st column is reserved for C (comment statements) and cols 2-6 for STATEMENT numbers.

    Here is another tutorial - http://web.utk.edu/~prdaves/Computerhelp/Unix_Fortran_Overview.htm

    We do have another Fortran thread around here since F77 a legacy language, which is still used by us dinosaurs from the pre-internet age.
     
  8. Sep 28, 2008 #7
    Hi guyes
    I would be highly grateful if you could help me in these questions as I need to build code in Fotran 77 for the first time
    In fortran 77 what is the difference between write(*, 'ghghfy') and write(9, 'ghghf)
    Why we do this declaration
    Parameter (zero=0.0d0, one=1.0d0, two=2.0d0, thr=3.0d0)
    what is the meaing of
    pi=two*dacos(zero)
    I mean what is the job of dcos function
     
  9. Sep 28, 2008 #8

    jtbell

    User Avatar

    Staff: Mentor

    It looks like you want to use two arrays named X and Y, but you don't know (before you run the program) how big you want those arrays to be. Instead, you want the program to read the array size, before reading the data for the arrays. Is this correct?

    I don't want to proceed further until I know for sure what you are trying to do.
     
  10. Oct 6, 2008 #9
    thanks, actually I need dim of the arrays to be 5, in the case which I am dealing with now, but I want to write a general code.
     
  11. Oct 8, 2008 #10

    jtbell

    User Avatar

    Staff: Mentor

    Then you can declare the arrays either using

    Code (Text):

          real*8 x(5), y(5)
     
    or as

    Code (Text):

          parameter (n=5)
          real*8 x(n), y(n)
     
    The "parameter" statement declares a named constant with the name "n". "n" is not a variable and does not even have any memory allocated for it. The compiler substitutes "5" whenever it sees "n" in the code. So you cannot change its value while the program is running (i.e. after the program is compiled). Its advantage is that you can easily change 5 to, say, 100, in the "parameter" statement, and re-compile your code, without having to search for all the places where you use 5 as the array size.
     
  12. Oct 14, 2008 #11
    Hey there, please anyone could give me a hand
    your help is greatly appreciated, actually I have written that code, but still giving me an errors, so still struggling as a begginer in Fortran 77, here the code and the errors
    c * This program reads the five vertices of an irregular Polygon then c* calculate its area and periemeter
    c * The area of an irrigular Polygon with n vertices is(x0*y1+x1*y2+....+x_n-1*y0)-(y0*x1+y1*x2+....+y_n-1*x0)
    c *
    c *
    c *
    implicit none
    c * LOCAL SCALARS
    integer i,n
    c * PARAMETER
    parameter (n=5.0d0)
    real*8 X(1,n),Y(1,n),sum1,sum2
    c * COMMON BLOCKS
    real*8 area,arc
    common/matpara/ area,arc
    c * 1 read(*,*) dim(X),dim(Y)
    c *if (dim(X).ne.dim(Y)) then
    c * print *, 'The dim of X must be equal to dim of Y'
    c * go to 1
    c *else
    c * if (dim(X).le.3)
    c * print *, 'This is not a Polygon'
    c * end if
    c *end if
    do 10 i=1, n
    read(*,*) X(1,i), Y(1,i)
    10 continue
    call calarea(X,Y,sum1)
    call calarea(Y,X,sum2)
    c * area=(calarea(X,Y)-calarea(Y,X))/2.0
    area=(sum1-sum2)/2.0
    c * THis subroutine to calculate the area
    subroutine calarea(A,B,sum)
    implicit none
    c * LOCAL VARIABLES
    integer i, n
    c * PARAMETER
    parameter (n=5.0d0)
    c * ARGUMENTS
    real*8 A(1,n),B(1,n),sum
    sum=0.0
    do 10 i=1,n-1
    sum=sum+(A(i)*B(i+1))
    end do
    sum=sum+(A(n)*B(1))
    end
    c * The following step to calculate the arc lenght of the Polygon by summing over the distance between its vertices
    arc=0.0
    do 10 i=1, n-1
    arc=arc+dsqrt((X(i)-X(i+1))**2 + (Y(i)-Y(i+1))**2)
    end do
    arc=arc+dsqrt((X(n-1)-X(1))**2 + (Y(n)-Y(1))**2)
    print*,area,arc
    **********
    Area-PoLygon.f: In program `MAIN__':
    Area-PoLygon.f:25:
    read(*,*) X(1,i), Y(1,i)
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area-PoLygon.f:26:
    10 continue
    ^
    Non-numeric character at (^) in label field [info -f g77 M LEX]
    Area-PoLygon.f:30:
    area=(sum1-sum2)/2.0
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area-PoLygon.f:32:
    subroutine calarea(A,B,sum)
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area-PoLygon.f:33:
    implicit none
    ^
    Invalid first character at (^) [info -f g77 M LEX]
    Area-PoLygon.f:8:
    integer i,n
    1
    Area-PoLygon.f:35: (continued):
    integer i, n
    2
    Invalid declaration of or reference to symbol `i' at (2) [initially seen at (1)]
    Area-PoLygon.f:8:
    integer i,n
    1
    Area-PoLygon.f:35: (continued):
    integer i, n
     
  13. Oct 15, 2008 #12
    Have you tried putting 7 or 8 leading spaces before your code lines yet?

    Columns 1 to 6 are reserved for labels and the continuation character.

    Obviously something like
    Code (Text):

    123      continue
     
    Wouldn't need leading spaces in front of the 123, but does need the spaces between the 3 of 123 and the c of continue.
     
  14. Oct 15, 2008 #13
    yes you right, but Is the way I define the array X &Y which contains real numbers correct or no?
     
  15. Oct 15, 2008 #14

    jtbell

    User Avatar

    Staff: Mentor

    No, it is not correct. Array indexes (inside the parentheses) must be integers.
     
  16. Oct 16, 2008 #15
    Hi there yes they are integers cos I have already changed n to 5 not 5.0d, I mean X(1,n)is correct declaration for an array of n elements?????????
     
  17. Oct 16, 2008 #16
    Code (Text):

           parameter (n=5.0d0)
           real*8 X(1,n),Y(1,n),sum1,sum2
     
    This doesn't look right to me...

    You appear to be defining n as a real number (floating point), then using it to define an array.

    Also, why are you defining X and as two dimensional arrays?

    Surely X(n) and Y(n) would be simpler?

    So I reckon that
    Code (Text):

           Parameter( n=5)
           real*8 X(n), Y(n)
     
    would be a step forward.
     
  18. Oct 16, 2008 #17
    thanks, yeah I have n=5 not 5.0d0, if I define the array as real*8 X(n) , then how can I refer to the nth term in the array which is X(n) isnit??
     
  19. Oct 16, 2008 #18
    if I define the array like this then how can I refer to the nth term of it which is X(n)?????????
     
  20. Oct 17, 2008 #19
    If you want to access the 5th element of X (FORTRAN arrays start at 1, by the way, or at least they used to when I was programming), then it's simply X(5).

    for instance:

    Code (Text):

           do 100 i = 1,5
           print ( *,1000 ) X(i)
    100  continue

          stop
    1000 format ( 1x, f6.2 )
            end
     
    should print out all five elements of X.
     
  21. Nov 16, 2008 #20
    I have written this bit of code in Fortran 77 but it gives me an errors message about n
    integer n
    real u(n), v(n)
    c
    c
    print*, "Enter the number n="
    read *, n

    It gives me invaild declaration of n,u,v??????????/should be something easy, hope anyone could point it out:confused:
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Fortran Forum
  1. Fortran 90 (Replies: 1)

  2. FORTRAN Help (Replies: 1)

  3. Fortran Help (Replies: 2)

  4. Infinity in fortran (Replies: 5)

  5. Linking Fortran (Replies: 5)

Loading...