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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran Document not compiling

Status
Not open for further replies.

Fairfield33

Programmer
Feb 19, 2005
4
US
This document on Integer FFT's is not compiling for me. I am a beginner in Fortran and am having some problems. I would greatly appreciate any Help with this document.


SUBROUTINE FASTI (IRE,IMG,ISIZE)
C PROVIDE INTEGER WORD LENGTH AND PIE TO AVAILABLE PRECISION
DATA NBITTS/16/,PIE/3.14159/
DIMENSION IRE (1) ,IMG(1)
IBIG=2**(NBITS-2)
IBG2=IBIG/2
XBIG=FLOAT(IBIG)
N=IABS(ISIZE)
C SET UP INITIAL TRIG FUNCTIONS
Z=PIE/FLOAT(N)
IAS=SIN(Z)*XBIG+0.5
IAS=COS(Z)*XBIG+0.5
C SET UP INTIAL VALUES OF TRANSORM SPLIT
IFA = N/2
C IF AN INVERSE TRANSFORM, CONJUGATE THE DATA
IF(ISIZE)1,3,3
1 DO 2 K=1,N
2 IMG(K)=-IMG(K)
3 I TIME=0
4 IFAB=IFA*2
ITIME=ITIME+1
C DOUBLE THE BASIC ANGLE
IBSIN = 2*MPY(IAS,IAC)
IBCOS=MPY(IAS,IAS)
IAS=IBSIN
IAC=(IBG2-IBCOS)*2
CALL COMP(IAS,IAC)
C MAIN CALCLATION OF RADIX 2 TRANSFORMS
ISW=0
ICW=IBIG
DO 11 LA = 1,IFA
DO 9 IP=LA,N,IFAB
IQ=IP+IFA
C EXTRACT DATA AND SCALE
K1=IRE(IP)
K2=TRE(IQ)
L1=IMG(IP)
L2=IMG(IQ)
IF(ISIZE)6,18,5
5 K1=K1/2
K2=K2/2
L1=L1/2
L2=L2/2
C FLUTTER BY
6 IRE(IP)=K1+K2
K1=K1-K2
IMG(IP)=L1+L2
L1=L1-L2
IF(LA-1)18,7,8
7 IRE(IQ)=K1
IMG(IQ)=L1
GO TO 9
C MULTIPLY BY TWIDDLE FACTORS IF REQUIRED
8 IRE(IQ)=MPY(K1,ICW)+MPY(L1,ISW)
IMG(IQ)=MPY(L1,ICW)+MPY(K1,ISW)
9 CONTINUE
IF(LA-IFA)10,11,18
C CALCULATE A NEW SET OF TWIDDLE FACTORS
10 IT=ICW-MPY(IBSIN,ISW)-2*MPY(IBCOS,ICW)
ISW=ISW+MPY(IBSIN,ICW)-2*MPY(IBCOS,ISW)
ICW=IT
CALL COMP(ISW,ICW)
11 CONTINUE
IFA=IFA/2
IF(IFA)12,12,4
C TRANSFORM COMPLETE - CONJUGATE RESULT IF INVERSE
12 IF(ISIZE)13,18,15
13 DO 14 K=1,N
14 IMG(K)=-IMG(K)
15 DO 17 J20=1,N
IZ=J20-1
CALL BITRV(IZ,II,ITIME)
IF(II-J20)17,17,16
16 II=II+1
IT=IRE(II)
IRE(II)=IRE(J20)
IRE(J20)=IT
IT=IMG(II)
IMG(II)=IMG(J20)
IMG(J20)=IT
17 CONTINUE
18 RETURN
END
FUNCTION MPY(I,J)
C FUNCTION TO MULTIPLY FIXED POINT FRACTIONS
C THIS VERSION INCORPORATES ROUNDING
C
C PROVIDE CONSTANTS FOR DECOMPOSISTION FO PRODUCT
DATA IMAD,IMID/64,128/
ILEF=I/IMID
IRIT=I-ILEF*IMID
JLEF=J/IMID
JRIT=J-JLEF*IMID
C DO NOT REARRANGE THE FOLLOWING MULTIPLICATION
II=(IRIT*JRIT)/IMID+IRIT*JLEF+JRIT*ILEF
MPY= (II+ISIGN(IMAD,II))/IMID+ILEF*JLEF
RETURN
END

FUNCTION MPY(I,J)
C
C FUNCTION TO MULITPLY FIXED POINT FRACTIONS
C THIS VERSION DOES NOT ROUND
C
C PROVED CONSTANTS FOR DECOMPOSITION OF PRODUCT
DATA IMID/128/
ILEF=I/IMID
IRIT=I-ILEF*IMID
JLEF=J/IMID
JRIT=J-JLEF*IMID
C DO NOT REARRANGE THE FOLLOWING MULTIPLICATION
MPY=((IRIT*JRIT)/IMID+IRIT*JLEF+JRIT*ILEF)/IMID+ILEF*JLEF
RETURN
END

SUBROUTINE BITRV(I,J,NBITS)
C
C SUBROUTINE WHICH RETURNS NBITS BITS OF I REVERSED IN J.
C
IZ=I
IJ=0
DO 1 K=1,NBITS
C DO NOT REARRANGE THE FOLLOWING STATEMENT
IJ=IJ+IJ+IZ/2*2
1 IZ=IZ/2
J=IJ
RETURN
END
 
If you are pasting code, enclose it withing [ CODE] and [/CODE]. Looks like F77 so you have to follow the F77 rules.

1) Labels from cols 1-5
2) Continuation in col 6
3) Code begins in col 7 - there are a few errors in this area. If you can do not use tabs. Some compilers take a tab as 8 characters, others take it as one. eg
Code:
      DO 1 K=1,NBITS
C DO NOT REARRANGE THE FOLLOWING STATEMENT
         IJ=IJ+IJ+IZ/2*2
   1     IZ=IZ/2
The IZ=IZ/2 was in the wrong column.

By default, integers begin with letters from I to N, everything else is real. If IAS is meant to be real, it has to be declared as such. Try that for starters: see how you get on.
 
Which version of Fortran are you using. Just realized that the program has 3 way jumps which aren't supported in Fortran 90/95.
 
I only know it is F77. The errors are pretty much fixed other than --->In function `main':
: undefined reference to `MAIN__'

Any ideas?
 
Have you got something like
Code:
program main
   call fasti (1, 2, 3)
   stop
end program
It is probably telling you that you are missing a program module.
 
Code:
        SUBROUTINE FASTI (IRE,IMG,ISIZE)
C PROVIDE INTEGER WORD LENGTH AND PIE TO AVAILABLE         C PRECISION
       DATA NBITS/16/,PIE/3.14159/
       DIMENSION IRE (1) ,IMG(1)
       IBIG=2**(NBITS-2)
       IBG2=IBIG/2
       XBIG=FLOAT(IBIG)
       N=IABS(ISIZE)
C SET UP INITIAL TRIG FUNCTIONS
       Z=PIE/FLOAT(N)
       IAS=SIN(Z)*XBIG+0.5
       IAS=COS(Z)*XBIG+0.5
C SET UP INTIAL VALUES OF TRANSORM SPLIT
       IFA = N/2
C IF AN INVERSE TRANSFORM, CONJUGATE THE DATA
       IF(ISIZE)1,3,3
  1    DO 2 K=1,N
  2    IMG(K)=-IMG(K)
  3    ITIME=0
  4    IFAB=IFA*2
       ITIME=ITIME+1
C DOUBLE THE BASIC ANGLE
       IBSIN = 2*MPY(IAS,IAC)
       IBCOS=MPY(IAS,IAS)
       IAS=IBSIN
       IAC=(IBG2-IBCOS)*2
       CALL COMP(IAS,IAC)
C  CALCLATION OF RADIX 2 TRANSFORMS      
       ISW=0
       ICW=IBIG
       DO 11 LA = 1,IFA
       DO 9 IP=LA,N,IFAB
       IQ=IP+IFA
C EXTRACT DATA AND SCALE
       K1=IRE(IP)
C CHANGED TO IRE FROM TRE
       K2=IRE(IQ)
       L1=IMG(IP)
       L2=IMG(IQ)
       IF(ISIZE)6,18,5
 5     K1=K1/2
       K2=K2/2
       L1=L1/2
       L2=L2/2
C FLUTTER BY
 6     IRE(IP)=K1+K2
       K1=K1-K2
       IMG(IP)=L1+L2
       L1=L1-L2
       IF(LA-1)18,7,8
 7     IRE(IQ)=K1
       IMG(IQ)=L1
       GO TO 9
C MULTIPLY BY TWIDDLE FACTORS IF REQUIRED
 8     IRE(IQ)=MPY(K1,ICW)+MPY(L1,ISW)
       IMG(IQ)=MPY(L1,ICW)+MPY(K1,ISW)
 9     CONTINUE
       IF(LA-IFA)10,11,18
C CALCULATE A NEW SET OF TWIDDLE FACTORS
 10    IT=ICW-MPY(IBSIN,ISW)-2*MPY(IBCOS,ICW)
       ISW=ISW+MPY(IBSIN,ICW)-2*MPY(IBCOS,ISW)
       ICW=IT
       CALL COMP(ISW,ICW)
 11    CONTINUE
       IFA=IFA/2
       IF(IFA)12,12,4
C TRANSFORM COMPLETE - CONJUGATE RESULT IF INVERSE
 12    IF(ISIZE)13,18,15
 13    DO 14 K=1,N
 14    IMG(K)=-IMG(K)
 15    DO 17 J20=1,N
       IZ=J20-1
       CALL BITRV(IZ,II,ITIME)
       IF(II-J20)17,17,16
 16    II=II+1
       IT=IRE(II)
       IRE(II)=IRE(J20)
       IRE(J20)=IT
       IT=IMG(II)
       IMG(II)=IMG(J20)
       IMG(J20)=IT
 17    CONTINUE
 18    RETURN
       END
C       FUNCTION MPY(I,J)
C FUNCTION TO MULTIPLY FIXED POINT FRACTIONS
C THIS VERSION INCORPORATES ROUNDING
C
C PROVIDE CONSTANTS FOR DECOMPOSISTION FO PRODUCT
C       DATA IMAD,IMID/64,128/
C       ILEF=I/IMID
C       IRIT=I-ILEF*IMID
C       JLEF=J/IMID
C       JRIT=J-JLEF*IMID
C DO NOT REARRANGE THE FOLLOWING MULTIPLICATION
C     II=(IRIT*JRIT)/IMID+IRIT*JLEF+JRIT*ILEF
C       MPY= (II+ISIGN(IMAD,II))/IMID+ILEF*JLEF
C       RETURN
C       END

       FUNCTION MPY(I,J)
C
C FUNCTION TO MULITPLY FIXED POINT FRACTIONS
C THIS VERSION DOES NOT ROUND
C
C PROVED CONSTANTS FOR DECOMPOSITION OF PRODUCT
        DATA IMID/128/
        ILEF=I/IMID
        IRIT=I-ILEF*IMID
        JLEF=J/IMID
        JRIT=J-JLEF*IMID
C DO NOT REARRANGE THE FOLLOWING MULTIPLICATION
        MPY=((IRIT*JRIT)/IMID+IRIT*JLEF+JRIT*ILEF)/IMID+ILEF*JLEF
        RETURN
        END

        SUBROUTINE BITRV(I,J,NBITS)
C
C SUBROUTINE WHICH RETURNS NBITS BITS OF I REVERSED IN J.
C
        IZ=I
        IJ=0
        DO 1 K=1,NBITS
C DO NOT REARRANGE THE FOLLOWING STATEMENT
        IJ=IJ+IJ+IZ/2*2
 1      IZ=IZ/2
        J=IJ
        RETURN
        END
       SUBROUTINE COMP (IS,IC)
C
C SUBROUTINE TO COMPENSATE SIN AND COS FOR MODULUS ERRORS
C
       IT=MPY(IS,IS)/2+MPY(IC,IC)/2
       IS=(IS-MPY(IS,IT))+IS/2
       IC=(IC-MPY(IC,IT))+IC/2
       RETURN
       END
C
C MAIN METHOD
C
       PROGRAM MAIN
       DIMENSION IRE(1),IMG(1)
       CALL FASTI(IRE,IMG,2)
       STOP
       END PROGRAM

Thanks to your help I have this code compiling correctly. However I am not certain of how exactly to print out results I need. I believe I need the results of IRE and IMG. I am actually using a converter for this specific program f2j and if anyone knows anything about an error that states "Ok... compiling 'original.f' to JAVA
original.f:
fasti:
DIMENSION is not implemented."

I believe it has something to do with my declaration of the one dimensional arrays in the main method but i am not certain.
 
1. You MUST define real extents for arrays in PROGRAM (not IMG(1) etc).
2. Try declare INTEGER IMG(set_real_extent),... instead of DIMENSION...

 
But dont you need to declare one dimensional arrays that need to be passed into the FASTI subroutine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top