Compiling Xfoil

@certik Thanks. --implicit-typing worked. Adding this option to Makefile is straightforward and not too painful. Now I see

 lfortran -c -O  -fdefault-real-8 --fixed-form --implicit-typing  ../src/xfoil.f
semantic error: Function 'iargc' not found (not user defined nor intrinsic)
  --> ../src/xfoil.f:54:14
   |
54 |       NARG = IARGC()
   |              ^^^^^^^

Does LFortran provide the support for IARGC through the compiler option flag?

That’s yet another extension (paired with GETARG, I suppose). The standard way is to use COMMAND_ARGUMENT_COUNT and GET_COMMAND_ARGUMENT in a loop.

Since both ifort/ifx and gfortran support the extension, maybe LFortran should as well if it’s not too difficult?

But in any case, @RonShepard is right in that the code should be updated to use as many standard-conforming features as possible.

1 Like

We don’t support iargc or getarg, but we have an open issue for that at Support legacy intrinsics iargc and getarg · Issue #10764 · lfortran/lfortran · GitHub. We should implement it.

1 Like

I predict that this is going to be a common occurrence with LFortran.

Some compilers require special options in order to enable nonstandard features, some compilers require special options in order to compile standard-conforming code. LFortran has chosen the latter approach for the implicit typing feature of standard fortran.

Yes, that’s the downside of our approach — for legacy code. For modern code the big upside is that LFortran gives a nice error about not declaring a variable. We are targeting modern code as a priority.

That being said, we of course support all legacy code and all widely-used extensions, so we just implemented iargc and getarg (feat: add legacy F77 aliases iargc and getarg by Zaneham · Pull Request #11679 · lfortran/lfortran · GitHub). CC @oroppas.

3 Likes

@certik Thanks. I can see LFortran version: 0.64.0-24-g5721168e4 support IARGC and GETARG.

Now I start seeing very cryptic error

lfortran -c -O  -fdefault-real-8 --fixed-form --implicit-typing --implicit-interface  ../src/xfoil.f
semantic error: Passing a scalar argument to an array dummy argument is not allowed. Use --legacy-array-sections to enable sequence association
 --> ../src/xfoil.f:1:1
  |
1 | C***********************************************************************
  | ^ scalar argument
  |
1 | C***********************************************************************
  | ^ array dummy argument

Let me see how much I can reduce xfoil.f for minimal example…

For that you’ll likely want the --legacy-array-sections option.

As with your other problems, it is really much better to fix the code than to depend on non-Standard compatibility options though.

Ideally, Xfoil gets fixed. That said both gfortran and flang are able to compile Xfoil as is.

Thanks. Here’s what I’ve got

lfortran -c -O  -fdefault-real-8 --fixed-form --implicit-typing --implicit-interface --legacy-array-sections  ../src/xfoil.f
make: *** [Makefile:168: xfoil.o] Segmentation fault

The minimal reproducible of xfoil.f became

      SUBROUTINE SAVE(IFTYP,FNAME1)

      CHARACTER*80 ISPARS
      COMMON/CC01/ ISPARS

      DO K=80, 1, -1
        IF(INDEX(ISPARS(K:K),' ') .NE. 1) EXIT
      ENDDO

      RETURN
      END

lfortran -c -O -fdefault-real-8 --fixed-form --implicit-typing --implicit-interface save.f

resulted in segmentation fault.

At this point it will be faster if I just fix everything in one sweep. Which version are you compiling, the xfoil6.996.tgz one?

Correct. https://web.mit.edu/drela/Public/web/xfoil/xfoil6.996.tgz

Go to Xfoil/bin then edit Makefile to set FC to lfortranat line 118.

Add --fixed-form --implicit-typing --implicit-interface to FFLAGS.

I created a repo for xfoil here: GitHub - certik/xfoil · GitHub and added build_macos.sh to build using GFortran and run tests. Had to make a few modifications. Then I added build_lfortran.sh to do the same with LFortran and I am now fixing the bugs.

Here are the LFortran options that I am using: xfoil/bin/Makefile_lfortran at aad3fc74ee93298a3ac8d64dc0036b310ac6671d · certik/xfoil · GitHub --cpp --separate-compilation --fixed-form-infer --implicit-interface --implicit-typing --legacy-array-sections --use-loop-variable-after-loop --no-style-suggestions --no-warnings. I think possibly just using --legacy might do it, but for now I use explicit options.

2 Likes

Ok, I have it: Build xfoil by certik · Pull Request #12306 · lfortran/lfortran · GitHub

With LFortran:

==> Running test case: NACA 0012 at alpha = 2 deg (inviscid) ...
    Cp distribution written OK (     241 lines). First rows:
      #      x          Cp
           1.00000    0.42134
           0.99632    0.28738
           0.99156    0.24271

With GFortran:

==> Running test case: NACA 0012 at alpha = 2 deg (inviscid) ...
    Cp distribution written OK (     241 lines). First rows:
      #      x          Cp
           1.00000    0.42121
           0.99632    0.28703
           0.99156    0.24324

There are some slight numerical differences, larger than numerical error, so probably we should track those down as well, but at least it compiles and runs pretty much correctly. In fact GFortran was called with single → double precision promotion, while LFortran was called with just a single precision, so that might completely explain the differences.

We need to first get that PR in, we usually split it into smaller ones, clean them up and get them in, so it might take a few days. But there is no blocker, just small bugs that we now have fixes for.

2 Likes