INTERPOLATION DEMONSTRATION
!Print out final data WRITE(*,*) ’Lower Airfoil Data’ WRITE(*,*) ’ X-Values Linear Cp Newton-Raphson Cp’ DO i = 1,SIZE(lower,1),1 WRITE(*,*) lower(i, 1:3) ENDDO WRITE(*,*) ’Upper Airfoil Data’ WRITE(*,*) ’ X-Values Linear Cp Newton-Raphson Cp’ DO i = 1,SIZE(upper,1),1 WRITE(*,*) upper(i, 1:3) ENDDO !Deallocate x and Cp arrays IF (ALLOCATED(x)) THEN DEALLOCATE(x, STAT=ierr1) ENDIF IF (ALLOCATED(Cp)) THEN DEALLOCATE(Cp, STAT=ierr2) ENDIF IF ((ierr1 .EQ. 0) .AND. (ierr2 .EQ. 0)) THEN WRITE(*,*) ’Memory successfully deallocated.’ ELSE WRITE(*,*) ’Memory not successfully deallocated.’ ENDIF CONTAINS !———————————————————————-- SUBROUTINE readFile IMPLICIT NONE INTEGER :: i, ios, nl !REAL :: z WRITE(*,*) ’Reading from file: ’, myfile !Open file to read from it OPEN(UNIT=1, FILE=myfile) !Determine the number of lines in the file nl = 0 !Initialize DO i = 1,1000,1 READ (1, *, IOSTAT=ios) !Dummy variable !If it’s the end of the file, then exit IF (ios /= 0) THEN EXIT ELSEIF (i == 1000) THEN WRITE (*,*) ’Maximum allowable data input reached. (1000 lines)’ ELSE nl = nl + 1 ENDIF ENDDO WRITE(*,*) ’End of file found:’, nl, ’pieces of data total.’ WRITE(*,*) ’’ CLOSE(1) !Use this number to allocate size to x and Cp ALLOCATE(x(nl), STAT=ierr1) ALLOCATE(Cp(nl), STAT=ierr2) IF ((ierr1 .NE. 0) .OR. (ierr2 .NE. 0)) THEN WRITE(*,*) ’Allocation denied. Program terminated.’ STOP ENDIF OPEN(UNIT=1, FILE=myfile) !Read from file DO i=1,nl,1 READ(1, *, IOSTAT=ios) x(i), Cp(i) END DO CLOSE(1) END SUBROUTINE readFile !———————————————————————-- !———————————————————————-- SUBROUTINE linearForm(arr, row, str) IMPLICIT NONE REAL, DIMENSION(2,2) :: arr INTEGER :: row CHARACTER(5) :: str !Use linear 1st order Taylor series !f(x) = f(x_0) + [(x - x_0)/(x_1 - x_0)] * [f(x_1) - f(x_0)] IF (str == ’lower’) THEN lower(row, 2) = arr(1,2) + ((lower(row,1) - arr(1,1)) / (arr(2,1) - arr(1,1))) * (arr(2,2) - arr(1,2)) ELSEIF (str == ’upper’) THEN upper(row, 2) = arr(1,2) + ((upper(row,1) - arr(1,1)) / (arr(2,1) - arr(1,1))) * (arr(2,2) - arr(1,2)) ENDIF END SUBROUTINE linearForm
Next Page →
Next Page →
← Previous Page
← Previous Page