From: ······@saruman.lb.bawue.de
Subject: Suggestions for using f2cl?
Date: 
Message-ID: <87zpeoxbdr.fsf@saruman.lb.bawue.de>
Hello Lispers,

I am trying to translate a Fortran-77 library to Lisp.
I have tried the original source and Raymond Toy's (sp?) enhanced 
version.

But I still have problems doing the translation. Things I have to
fix manually are nested (Fortran) DO-loops ans vector reference
vs. subroutine call ambiguities.  

According to the documentation F2CL has been used to translate several 
Fortran applications to CL, including a FE-program.

Has anyone had success in using f2cl for larger scale 
Fortran programs, or am I better off, using my Lisp's FFI?
Any experiences and auggestions are welcome.

Thanks in advance &
long live Lisp,

Alex

From: Raymond Toy
Subject: Re: Suggestions for using f2cl?
Date: 
Message-ID: <4nzpenxfqd.fsf@rtp.ericsson.se>
······@saruman.lb.bawue.de writes:

> 
> But I still have problems doing the translation. Things I have to
> fix manually are nested (Fortran) DO-loops ans vector reference
> vs. subroutine call ambiguities.  

Can you post an example where nested do-loops fail?

The vector reference vs subroutine call ambiguity has to be fixed by
hand.  It's hard to tell at the subroutine call if an array is wanted
or the element itself.

> Has anyone had success in using f2cl for larger scale 
> Fortran programs, or am I better off, using my Lisp's FFI?
> Any experiences and auggestions are welcome.

I, of course, have used it to translate some Fortran code, like quadpack.

If your lisp has an easy-to-use FFI, I'd go with the FFI.  If your
Fortran code has subroutines that take functions as parameters (like
quadpack), then f2cl is probably better, if you can get it to work.

Ray
From: ······@saruman.lb.bawue.de
Subject: Re: Suggestions for using f2cl?
Date: 
Message-ID: <87oguz5sph.fsf@saruman.lb.bawue.de>
Hi all, 
Raymond Toy <···@rtp.ericsson.se> writes:

> 
> ······@saruman.lb.bawue.de writes:
> 
> > 
> > But I still have problems doing the translation. Things I have to
> > fix manually are nested (Fortran) DO-loops ans vector reference
> > vs. subroutine call ambiguities.  
> 
> Can you post an example where nested do-loops fail?
> 

I have to apologize for the rash statement -- I'm not sure if 
the nested do-loops are the real  culprit anymore. However the following 
code (test.f) sends f2cl into an endless loop. This is a subroutine of
the library I want to translate, with some lines deleted and some
commented out. "g77 -Wall -pedantic" only compains about 
the mixing of character and other variables in the common block, which
is not stabdard Fortran 77, but compiles OK.

I have attempted to reproduce the endless loop with my own
F77 code, but did not have any success (see "ftest,f" 
below).

Can anyone give me a clue?

Thanks,

Alex

 ------------------- test.f ---------------------------------
      SUBROUTINE INTKL1(IDX,P,VRINT,OPTION,LEVEL,IFACE,VERTEX)
C
      IMPLICIT DOUBLE PRECISION(A-H,O-Z)
      CHARACTER OPTION*6,IOP*6
      DIMENSION IFACE(7,*), VERTEX(3,*), VRINT(6), VRTX(3,6), PDUP(3),
     *          P(3), VS(3), VT(3)
      COMMON/PFNKL1/VRTX,AREA,PDUP,IOP
      EXTERNAL FCNKL1
C
C     INITIALIZE COMMON FOR DEFINITION OF FCNKL1.
      IOP = OPTION
      DO 10 I=1,3
C 10	PDUP(I) = P(I)
        PDUP(I) = 0.0
 10   CONTINUE 
      DO 20 J=1,6
	K = 1
	DO 20 I=1,3
C20	  VRTX(I,J) = VERTEX(I,K)
          X = 0.0
 20   CONTINUE
      IF(OPTION .EQ. 'PLANAR') THEN
	  DO 30 I=1,3
            VT(I) = 1.0
30	    VS(I) = 3.0
C         CALCULATE AREA OF PLANAR TRIANGLE.
            AREA = SQRT(66.)
      END IF
C
C     PERFORM INTEGRATION.
      CALL SMPLX6(VRINT,FCNKL1,LEVEL)
      RETURN
      END

------------------------ ftest. f ---------------------------------------
      program f2cl01

      integer i,j,k, kk
      real    x, kx, arr(20)

      common /hurz/ kk, kx
      
      do 100 i=1, 10
        y = 6.0
        arr(i) = i
        do 100 j=1, 10
          y = 27.3
            do 100 k=1, 10
               write(*, *) i*j*k
 100           x = 555.0

      stop 
      end
From: Raymond Toy
Subject: Re: Suggestions for using f2cl?
Date: 
Message-ID: <4niul7xgxz.fsf@rtp.ericsson.se>
······@saruman.lb.bawue.de writes:

> 
> Can anyone give me a clue?

I ran your code.  I get syntax errors and, sometimes, an infinite
loop.  I think the problem is the embedded tabs you have in the code.
f2cl doesn't like tabs (which, I think, are forbidden in strict F77).
If you replace ALL tabs with spaces, then f2cl produces the desired
lisp code.

I always run my Fortran code through a fortran beautifier (toolpack)
before running f2cl.

Ray
From: Raymond Toy
Subject: Re: Suggestions for using f2cl?
Date: 
Message-ID: <4ng1gafxah.fsf@rtp.ericsson.se>
Raymond Toy <···@rtp.ericsson.se> writes:

> ······@saruman.lb.bawue.de writes:
> 
> > 
> > Can anyone give me a clue?
> 
> I ran your code.  I get syntax errors and, sometimes, an infinite
> loop.  I think the problem is the embedded tabs you have in the code.
> f2cl doesn't like tabs (which, I think, are forbidden in strict F77).
> If you replace ALL tabs with spaces, then f2cl produces the desired
> lisp code.
> 

Here's the fix so that f2cl handles tabs a bit better.  If a tab
starts the line, it's replaced by 6 spaces.  All other tabs are
replaced by a single space.

Just find the function preprocess in f2cl6.l and use the one below
instead.

Hope this helps you out,

Ray



(defun preprocess (file &key (outfile-name "prep.tmp"))
  (prog (inport outport line)
     (when *verbose*
       (format t "~&preprocessing begins ...~%"))
     (setq inport (infile file)
           outport (outfile outfile-name))
   loop
     (setq line (read-line inport nil 'EOF))
     (when (eq line 'EOF) 
       (close outport)
       (close inport)
       (return outfile-name))
     #+nil(setq line (string-upcase (string-right-trim '(#\Space) line)))
     (setq line (string-right-trim '(#\Space) line))
     (cond 
       ((string= line "") nil)		; we leave out blank lines
       ((or (char-equal (char line 0) #\C)
	    (char-equal (char line 0) #\*))
	(if *comments* (write-comment-line line outport)))
       (t
	(when *verbose* (princ line) (terpri))
	;; Handle tabs.  If the line begins with a tab, replace it with 6
	;; spaces.  Then replace all tabs with a single space.
	(when (char-equal (aref line 0) #\Tab)
	  (setf line (concatenate 'string "      " (subseq line 1))))
	(setf line (substitute #\Space #\Tab line))

	(write-line (adjust_nrs (replace_logl_ops line)) outport)))
     (go loop)))
From: Alexander Shendi
Subject: Re: Suggestions for using f2cl?
Date: 
Message-ID: <87btqtwnag.fsf@saruman.lb.bawue.de>
Raymond Toy <···@rtp.ericsson.se> writes:

> 
> Raymond Toy <···@rtp.ericsson.se> writes:
> 
[...]
> > 
> > I ran your code.  I get syntax errors and, sometimes, an infinite
> > loop.  I think the problem is the embedded tabs you have in the code.
> > f2cl doesn't like tabs (which, I think, are forbidden in strict F77).
> > If you replace ALL tabs with spaces, then f2cl produces the desired
> > lisp code.
> > 
> 
Yes that's it. I didn't notice, because I used an editor
thar replaced tabs with spaces in its buffer.

> Here's the fix so that f2cl handles tabs a bit better.  If a tab
> starts the line, it's replaced by 6 spaces.  All other tabs are
> replaced by a single space.

Thanks for your help,

Alex