DATA FITTING DEMONSTRATION

DATA FITTING DEMONSTRATION

Demonstration: Data Fitting Multiple Sets of Data.
In experiments, it is routine to replicate a test multiple times. In this example, four sets of data for a rotor blade over one revolution are fit to generate one curve.
PROGRAM datafit
IMPLICIT NONE
INTEGER :: ierr1, nl, order, check
CHARACTER(LEN=50) :: myfile
REAL, DIMENSION(:,:), ALLOCATABLE :: points
myfile = ’blade.dat’ !Flight test data file
​
!!!!!! FILE FORMAT !!!!!!
! blade.dat is the file for flight test data
! It should be in the form:
! Azimuthal Location, Exp. 1, Exp. 2, Exp. 3, Exp. 4
!!!!!! END !!!!!!
​
CALL readFile
DO order = 1,10
	CALL datafit(order,nl,points,check)
	IF (check == 1) THEN
		EXIT
	ENDIF
ENDDO
WRITE(*,*) !Extra line for aesthetics
​
CONTAINS
SUBROUTINE readFile
	IMPLICIT NONE
	INTEGER :: i, j, ios
	REAL :: z
​
	WRITE(*,*) !Extra line for aesthetics
	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 1000 lines’
		ELSE
			nl = nl + 1
		ENDIF
	ENDDO
	WRITE(*,*) ’End of file found:’, nl, ’pieces of data total.’
	nl = nl*4
	WRITE(*,*) ’Hence, ’, nl, ’ data points found.’
	WRITE(*,*) ’’
	CLOSE(1)
​
	!Use this number to allocate size to x and Cp
	ALLOCATE(points(nl,2), STAT=ierr1)
	IF (ierr1 .NE. 0) THEN
		WRITE(*,*) ’Allocation denied.  Program terminated.’
		STOP
	ENDIF
​
	OPEN(UNIT=1, FILE=myfile)
	!Read from file
	DO i=1,nl,4
		READ(1,*,IOSTAT=ios) z, (points(j,2), j=i,i+3)
		points(i:i+3,1) = z
	ENDDO
	CLOSE(1)
END SUBROUTINE readFile
!!!!!!!!!!
Next Page →
Next Page →