Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to rewrite a program

Status
Not open for further replies.
Jul 8, 2015
1
BR
Hi
I am tring to rewrite the program as this link: Exemplo I and II (page from 1 to 8)
but i dont know why it is not working.

this is the program I wrote:

thanks !!!!!

PROGRAM EXERCICIO2
DIMENSION A(2,2), B(2,2), C(2,2)
C
C VAI DEFINIR OS PONTOS A
C
A(1,1)=0.0
A(1,2)=0.0 ! CONSIDERE, POR EXEMPLO, OS
A(2,1)=10.0 !PONTOS EXTREMOS DE UM SEGMENTO DE RETA
A(2,2)=0.0
C
C VAI LER O ANGULO DE ROTAÇÃO

WRITE(*,'(A\)')' ANGULO:'
READ(*,*)TETA
PI=4*ATAN(1.0) !DEFINE A CTE PI
TETA=TETA*PI/180 !CONVERTE GRAUS EM RADIANOS
C
C DEFINE MATRIZ DE ROTAÇAO EM TORNO DA ORIGEM
C
B(1,1)=COS(TETA)
B(2,1)=SIN(TETA)
B(2,1)=-SIN(TETA)
B(2,2)=COS(TETA)
C
CALL MULTMAT(A,B,C) !CHAMA A SUB ROTINA MULTMAT
C
C ESCREVE A MATRIZ RESULTANTE DO PRODUTO C(...)
C
DO 20 I=1,2
WRITE(*,*)(C(I,J),J=1,2) !CICLO DO INTERNO EM J
20 CONTINUE
STOP
END
C
C SUB ROTINA PARA O PRODUTO DE DUAS MATRIZES 2X2
C
SUBROUTINE MULTMAT (A,B,C)
DIMENSION A(2,2), B(2,2), C(2,2)
C
C FAZ CICLO SOB O NUMERO DE LINHAS I
C
DO 1 I=1,2
C
C FAZ PRODUTO COM A MATRIZ QUADRADA B
C
DO 2 J=1,2
AB=0.0 !INICIA VALOR DA POSIÇÃO DA MATRIZ
DO 3 K=1,2
AB=AB+A(I,K)*B(K,J) !ADICIONA CONTRIBUIÇOES
3 CONTINUE
C(I,J)=AB !GUARDA VALOR NA POSIÇÃO DA MATRIZ
2 CONTINUE
1 CONTINUE
C
RETURN
END
 
As you know, this is computer and programming stuff...you can't just hand wave (american idiom)...you need to tell exactly what you are doing, exactly what you are getting and why/how is different from what you were expecting.

What is the extension of the source file? This matters! ...*.F, *.FOR, *.F77, *.F90?
What compiler are you using and what exactly is the compilation command?
What do you get?

Please copy and paste as much as you can...trying to explain things when you don't know what you are doing does not come across well.

Finally...if I could convince you, please do not bother to learn Fortran 77...the presentation you are reading is from 2001, yet, we have had modern Fortran since 1995...please, please, please drop that tutorial and look for literature and tutorials for Fortran90 or Fortran95...it is sooooo much nicer.

Tutorials.
Wikipedia.

 
What is not working about it - does it not compile or does it not run as expected. If the latter, then what are you expecting and what are you getting?
 
It worked for me when I replaced '\' with '$' line 13.
I compile with g77.

This doesn't work for me: write(*,'(A)',advance='no')

WRITE (*, '(A$)') ' ANGULO : ' !! TRY $ TO REPLACE
Code:
      PROGRAM exercicio2
      DIMENSION A(2, 2), B(2, 2), C(2, 2)
C
C VAI DEFINIR PONTOS A(...)
C
      A(1, 1) = 0.0
      A(1, 2) = 0.0  ! Considere, por exemplo, os
      A(2, 1) = 10.0 ! pontos extremos dum segmento de recta
      A(2, 2) = 0.0
C
C VAI LER O ÂNGULO DE ROTAÇÃO
C
      !WRITE (*, '(A\)') '  ANGULO : ' !! TRY $ TO REPLACE       WRITE (*, '(A$)') '  ANGULO : ' !! TRY $ TO REPLACE       READ (*, *) TETA
      PI = 4*ATAN(1.0)     ! Define a constante p (pi)
      TETA = TETA*PI/180   ! Converte graus em radianos
C
C DEFINE MATRIZ DE ROTAÇÃO em torno da origem
C
      B(1, 1) = COS(TETA)
      B(1, 2) = SIN(TETA)
      B(2, 1) = -SIN(TETA)
      B(2, 2) = COS(TETA)
C
      CALL MULTMAT(A, B, C)! Chamada da subrotina MULTMAT
C
C ESCREVE A MATRIZ RESULTANTE DO PRODUTO C(...)
C
      DO 20 I = 1, 2
      WRITE (*,*) (C(I, J), J = 1, 2)   ! Ciclo DO interno em J
   20 CONTINUE
      STOP
      END
C
C Subrotina para o produto de duas matrizes de 2x2
C
      SUBROUTINE MULTMAT(A, B, C)
      DIMENSION A(2, 2), B(2, 2), C(2, 2)
C
C    faz ciclo sobre o número de linhas I
C
      DO 1 I = 1, 2
C
C    faz produto com a matriz quadrada  B
C
        DO 2 J = 1, 2
          AB = 0.0       ! Inicia valor da posição da matriz
          DO 3 K = 1, 2
            AB = AB+A(I, K)*B(K, J) !Adiciona contribuições
    3     CONTINUE
          C(I, J) = AB    ! Guarda valor na posição da matriz
    2   CONTINUE
    1 CONTINUE
C
      RETURN
      END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top