How to Compile MSES Software with Unexpected Syntax in Fortran?

  • Context: Fortran 
  • Thread starter Thread starter jasonbot
  • Start date Start date
  • Tags Tags
    Software
Click For Summary

Discussion Overview

The discussion revolves around compiling the MSES software, specifically addressing issues encountered with the Fortran subroutine dplot.f. Participants explore syntax peculiarities and compiler options related to variable naming conventions in Fortran.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant expresses confusion over the use of the dollar sign in variable names, which is not standard in MATLAB and causes compilation errors in Fortran.
  • Another participant suggests using the gfortran compiler with the -fdollar-ok option to allow the use of dollar signs in variable names, providing an example of its application.
  • A participant acknowledges the fix but raises a new issue regarding the use of the XOR operator, which is not recognized by gfortran, indicating a potential limitation of the compiler compared to others like Intel's ifort.
  • There is a mention of standard Fortran alternatives for logical and bitwise operations, suggesting that some operators may not be universally supported across different compilers.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best practices for variable naming in Fortran, with some advocating against non-standard names while others focus on practical solutions for immediate compilation issues. The discussion about the XOR operator highlights differing support among compilers, indicating unresolved preferences or practices.

Contextual Notes

Limitations include the reliance on specific compiler options and the potential for confusion regarding operator support across different Fortran compilers. The discussion reflects varying levels of familiarity with Fortran among participants.

jasonbot
Messages
16
Reaction score
0
Hello,

I'm trying to compile some software called MSES, its written by Mark Drela in some fortran flavour. I've successfully compiled a number of subroutines through make files but there is one subroutine giving me grief. It's called dplot.f.

It has a strage syntax I can't seem to work around:

Code:
     SUBROUTINE DPLOT
      INCLUDE 'STATE.INC'     
      INCLUDE 'MPLOT.INC'
C-----------------------------------------------------------
C     Reads in data file or reference profiles and plots them
C     superimposed on calculated profiles.  The profiles are
C     plotted in proper location on actual airfoil.
C-----------------------------------------------------------
C
      CHARACTER*40 FNAME, LINE, uname
      PARAMETER (IPRX=40,KPRX=240)
      DIMENSION XX(KPRX), YY(KPRX)
      DIMENSION APR(IPRX), XPR(IPRX), YPR(KPRX,IPRX), UPR(KPRX,IPRX)
      DIMENSION YADD(IPRX), YPRFAC(IPRX), UPRFAC(IPRX)
      DIMENSION DSPR(IPRX), THPR(IPRX), TSPR(IPRX)
      INTEGER KK(IPRX), NXPR(IPRX)
      LOGICAL LUPR, LTPR
c
      parameter (jprx=isx*200)
      dimension nsum$(jprx)
      dimension y$(jprx), u$(jprx), uinv$(jprx), udef$(jprx)

...

the dollar sign after a variable name, as in nsum$, makes no sense to me. Coming from MATLAB this wouldn't be a valid variable name and in my fortran compiler (tried both f77 and gfortran) it tells me a number of different errors about invalid forms and type disagreements. Removing the dollar signs gives errors relating to invalid declarations.

Does anyone have any idea how to fix my code?
 
Technology news on Phys.org
Use gfortran -fdollar-ok

Use gfortran with option -fdollar-ok:

Sample
Code:
c    file foo.f
      program foo
      real pi$
      parameter (pi$ = acos(-1.0)) 
      write(*,*) pi$   
      end program foo

Reproducing the error
Code:
gfortran foo.f
foo.f:3.14:

      real pi$                                                          
              1
Error: Invalid character '$' at (1). Use -fdollar-ok to allow it as an extension
foo.f:4.20:

      parameter (pi$ = acos(-1.0))                                      
                    1
Error: Invalid character '$' at (1). Use -fdollar-ok to allow it as an extension
foo.f:5.20:

      write(*,*) pi$                                                    
                    1
Error: Invalid character '$' at (1). Use -fdollar-ok to allow it as an extension

Fixing it
Code:
gfortran -fdollar-ok foo.f
echo $?
0
But despite this fix I would strongly discourage using non-standard names in self-written code.

Cheers, Solkar
 
  • Like
Likes   Reactions: 1 person
Thank you Solkar.

What do you mean by using non standard names?

I'm new to fortran and wouldn't say I'm keen to learn it. I just need to use the programme for some work.

After using your suggestion it seemed to have compiled correctly although now I have some problems with additional modules with the error:

CHANGE = CHANGE .OR. (LMOD1(K,IP).XOR.LMOD(K,IP))
1
Error: Unknown operator 'xor' at (1)

I don't think ill bother investigating it because its a module I don't need.
 
jasonbot said:
Thank you Solkar.
What do you mean by using non standard names?
Names which require tricking the compiler into eating them, like those ending with a "$" you asked for.

jasonbot said:
CHANGE = CHANGE .OR. (LMOD1(K,IP).XOR.LMOD(K,IP))
1
Error: Unknown operator 'xor' at (1)

I think intel's ifort has .xor. defined by default, but gfortran apparently doesn't.
Standard Fortran has
Code:
A .neqv. B
for XORing of logical A,B, and it's common wisdom that most compilers support
Code:
ieor(i,j)
for bitwise XORing of integer i,j.
 
  • Like
Likes   Reactions: 1 person

Similar threads

  • · Replies 3 ·
Replies
3
Views
12K