forums.silverfrost.com
Welcome to the Silverfrost forums

Author Message
Jim

Joined: 21 Jul 2006
Posts: 24
Location: USA

 Posted: Fri Apr 15, 2016 8:39 pm    Post subject: Simple Interpolation 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?
mecej4

Joined: 31 Oct 2006
Posts: 1743

Posted: Fri Apr 15, 2016 8:46 pm    Post subject:

Replace the line
 Code: IF(MD(K).EQ.MD(I))MD(K)=MD(I)

by
 Code: 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)).
JohnCampbell

Joined: 16 Feb 2006
Posts: 2434
Location: Sydney

Posted: Sat Apr 16, 2016 2:06 am    Post subject:

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:

 Code: 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 ?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1