-1
F90 = gfortran
FFLAGS = #-O3, this is an optimizer which makes loops more efficient
EXECUTABLE = quad

# Object Files for build
OBJS = \
Constants.o \
functions.o \
quadratureRules.o \

$(EXECUTABLE) : $(OBJS)
    $(F90) $(FFLAGS) -o $(EXECUTABLE) ./QuadExample.f90 $(OBJS)


# Object dependencies and compilation

Constants.o : ./Constants.f90
    $(F90) $(FFLAGS) -c ./Constants.f90

functions.o : ./functions.f90 \
Constants.o
    $(F90) $(FFLAGS) -c ./functions.f90

quadratureRules.o : ./quadratureRules.f90 \
Constants.o
    $(F90) $(FFLAGS) -c ./quadratureRules.f90

# Utility targets
.PHONY: clean
clean:
    rm *.o *.mod
    rm quad

I was trying to compile the Fortran code as listed in Fortran Andrew R. Winters notes. I am listing the version here in case these notes disappear from the web.

But when running make to build these files, I got the following error

Makefile:12: *** missing separator. Stop.

After seeing the other make file questions, I sort of felt that the problem was due to Sublime Text transforming my tabs to spaces as I had initially set it up to do. (For python). I did not want to disturb that.

I tried to detect where the tabs were supposed to be but it sort of gave mixed results  where the tabs were supposed Like I could not figure out what the ^M meant.

Then I tried .editorconfig file approach to tell Sublime Text to not fix tabs automagically. Also to no avail.

I also tried an answer that said use the u09 Unicode character, I can't find it now.

I am reproducing the files Constants.f90 functions.f90 QuadExample.f90 quadratureRules.f90 below for better idea

Constants.f90

MODULE Constants
    IMPLICIT NONE
    INTEGER ,PARAMETER          :: RP = SELECTED_REAL_KIND(15)
    REAL(KIND=RP),PARAMETER     :: pi = 4.0_RP*ATAN(1.0_RP)
END MODULE Constants

functions.f90

FUNCTION f(x)
IMPLICIT NONE
INTEGER,PARAMETER           :: RP = SELECTED_REAL_KIND(15)
REAL(KIND=RP),INTENT(IN)    :: x
REAL(KIND=RP)               :: f
!
f = EXP(x) - x**2 ! Alternatively could use x*x, faster than the "power" command
!
END FUNCTION f
!
FUNCTION g(x)
IMPLICIT NONE
INTEGER,PARAMETER           :: RP = SELECTED_REAL_KIND(15)
REAL(KIND=RP),INTENT(IN)    :: x
REAL(KIND=RP)               :: g
!
g = SIN(x) - COS(x)
!
END FUNCTION g

QuadExample.f90

PROGRAM Quadrature
    IMPLICIT NONE
    INTEGER ,PARAMETER          :: RP = SELECTED_REAL_KIND(15)
    INTEGER ,PARAMETER          :: N = 150
    REAL(KIND=RP),PARAMETER     :: a = -1.0_RP, b = 2.0_RP
    REAL(KIND=RP)               :: Integral
    REAL(KIND=RP),EXTERNAL      :: leftHandRule,f,g
!
    WRITE(*,*)
    Integral = lefthandRule(a,b,N,f)
    WRITE(*,*) 'Approximation for f(x) integral: ',Integral
    WRITE(*,*)
    Integral = leftHandRule(a,b,N,g)
    WRITE(*,*)'Approximation for g(x) integral: ',Integral
!
END PROGRAM Quadrature

quadratureRules.f90

FUNCTION leftHandRule(a,b,N,func)
    IMPLICIT NONE
    INTEGER ,PARAMETER          :: RP = SELECTED_REAL_KIND(15)
    INTEGER ,INTENT(IN)         :: N
    REAL(KIND=RP),INTENT(IN)    :: a,b
    REAL(KIND=RP),EXTERNAL      :: func
    REAL(KIND=RP)               :: leftHandRule
! Local Variables
    INTEGER                     :: i
    REAL(KIND=RP)               :: dx,x
!
    dx = (b-a)/N
    leftHandRule = 0.0_RP
    DO i = 0,N-1
    x = a + i*dx
    leftHandRule = leftHandRule + func(x)*dx
    END DO! i
!
END FUNCTION leftHandRule
francescalus
  • 30,576
  • 16
  • 61
  • 96
Tejas Shetty
  • 685
  • 6
  • 30

1 Answers1

0

Inspired by an answer relating to gedit

I opened Sublime Text> Preferences > Settings and added "Makefile" to "file_exclude_patterns":

After that, I opened it I gedit and actually converted spaces to tabs. Voila things worked.

Tejas Shetty
  • 685
  • 6
  • 30
  • 2
    You converted tabs to spaces in your Makefile and things worked??? Are you sure? In Makefiles the recipe lines **must** start with a tab. If they don't you get the error message you saw (and this has absolutely nothing to do with your Fortran code which is not relevant here). So the right solution is to configure your editor to recognize Makefiles and to not touch tabs in Makefiles. And, of course, to start all your recipe lines with a tab when editing a Makefile. – Renaud Pacalet Nov 04 '21 at 11:05