Silverfrost Forums

Welcome to our forums

Simple Interpolation

15 Apr 2016 7:39 #17429

I want to do a simple linear interpolation between points. I read in the following data using

  DO 50 I = 1,NUMBR,1
  READ(25,*)MD(I),INC(I),AZM(I)

50 CONTINUE

Data

MD(I) INC(I) AZM(I) 0 0 0 100 0.21 24.234 200 0.255 22.873 300 0.347 37.584 400 0.459 39.115 500 0.419 28.605 600 0.586 344.075 700 0.623 341.053 800 0.59 338.811 900 0.47 354.067 1000 0.36 351.009

I use the next routine to read in points that may may or or may not equal to main point set.

DO 51 K = 1,POINTS,1 READ(25,*)MD(K) 51 CONTINUE

Data

MD(K) 150 250 350

I then use the following loop to find do a linear interpolation to find INC(K) and AZM(K). This is the routine I am using:

399 DO 400 I = 1,NUMBR,1 IF(MD(K).EQ.MD(I))MD(K)=MD(I) INC(K)=INC(I) AZM(K)=AZM(I) ELSEIF(MD(K).GE.MD(I).AND.MD(K).LT.MD(I+1))THEN DMD(K)=DMD(K)-MD(I) INC(K)=INC(I)+((INC(I+I)-INC(I))((MD(K)-MD(I))/DMD(I+1))) AZM(K)=AZM(I)+((AZM(I+I)-AZM(I))((MD(K)-MD(I))/DMD(I+1))) ENDIF 400 CONTINUE

I get the error 'Found ELSE IF without a corresponding IF statement'.

Anyone have an idea of what is wrong and how do I fix the error?

15 Apr 2016 7:46 #17430

Replace the line

IF(MD(K).EQ.MD(I))MD(K)=MD(I) 

by

IF(MD(K).EQ.MD(I)) THEN
   MD(K)=MD(I) 

You meant to use a block IF construct, but what you wrote is a single-line IF statement. As a result, the compiler does not find an IF(clause)THEN to match the ELSE IF (clause) THEN... and the ENDIF statements, and detects a syntax error.

Next, consider the semantics. The assignment MD(K) = MD(I) is superfluous, coming immediately after IF(MD(K).EQ.MD(I)).

16 Apr 2016 1:06 #17431

Do you mean to use MD in loop 51, as it overwrites the reference table you are wanting to use? A useful change to something like:

      DO 51 K = 1,POINTS,1 
        READ(25,*) MDnew(K) 
 51   CONTINUE 

399   DO 400 I = 1,NUMBR-1,1 
        IF (MDnew(K).EQ.MD(I)) THEN
          INCnew(K) = INC(I) 
          AZMnew(K) = AZM(I) 
          exit
        ELSE IF (MDnew(K).GE.MD(I) .AND.   &
                 MDnew(K).LT.MD(I+1)) THEN
          f = (MDnew(K)-MD(I)) / (MD(I+1)-MD(I))
          INCnew(K) = INC(I) + ((INC(I+I)-INC(I)) * f
          AZMnew(K) = AZM(I) + ((AZM(I+I)-AZM(I)) * f
          exit
        END IF 
 400  CONTINUE 
!    now test I to confirm interpolation

Will you be trying to interpolate for MDnew = 550 ?

Please login to reply.