Im new to using fortran and im having some problems with an if statement. Im trying to write something along the lines of if element in array 1 is larger than element in array 2 then let h = some expression, else h = 0. I have coppied my code below
DO I=1,NPOIN
IF ((X(I)*COS(0.0)+0.0*Y(I)*COS(0.0)+0.1)*0.15 .GT. ZF(I)) THEN
H%R(I) =0.15*((X(I)*COS(0.0))+(0.0*Y(I)*COS(0.0))+0.1)
ELSE
H%R(I) = 1
ENDIF
ENDDO
The error im getting is:
IF ((X(I)*COS(0.0)+0.0*Y(I)*COS(0.0)+0.1)*0.15 .GT. ZF(I)) THEN
Error: Syntax error in IF-expression at (1)
Apologies if this is somethign really obvious but ive tried all sorts to fix it with no joy so far. Any help would be appreciated.
There may be a better way to compare the two arrays but yeah essentially im trying have ZF as my main array, but where H is larger than ZF i want the ZF value to be replaced with the H value. SO essentially i have a new array with the maximum value possible between the two arrays.
Thanks in advance
real :: X(NPOIN), Y(NPOIN), ZF(NPOIN), R(NPOIN)and exchanged 'H%R' -> 'R'. Maybe there is something else going wrong. Could you post something compilable?(X(I)*COS(0.0)+0.0*Y(I)*COS(0.0)+0.1)-- occurs twice in your code and can be reduced toX(I)+0.1. I can't see the extra terms as the source of the problem you report but they get in your way, and ours, in trying to understand what is going on. Get rid of them.