Appendix C.2 



SUBROUTINE COSFIT(A,B,PHI,X,Y,N,AMIN,BMIN,PHIMIN, ILIST) 

 C 



C THIS ROUTINE PERFORMS A BEST FIT TO DATA WITH A TRIGONOMETRIC 

 C FUNCTION OF THE FORM Y=A+B*(C0S(4*PI*(X-PHI ) ) ) USING AN ITERATIVE 

 C METHOD AS DESCRIBED IN SCARBOROUGH (1930), ART. 115. 

 C INPUTS ARE 

 C A=C0NSTANT 



C B=AMPLITUDE OF SINUSOIDAL COMPONENT 

 C PHI= ANGLE OF MAXIMUM AMPLITUDE 

 C X= ARRAY OF DEPENDENT VARIABLE VALUES 

 C Y= ARRAY OF DEPENDENT VARIABLE VALUES 

 C N= NUMBER OF DATA PAIRS OF X AND Y 



C AMIN= MINIMUM VALUE FOR A CORRECTION TO STOP ITERATION 

 C BMIN= MINIMUM VALUE FOR B CORRECTION TO STOP ITERATION 

 C PHIMIN= MINIMUM VALUE FOR PHI CORRECTION TO STOP ITERATION 

 C ILIST= 1 FOR SUMMARY OF ITERATION PROCESS, = , NO LISTING 

 C PROGRAMMED BY C.G. FOX-ADVANCED TECHNOLOGY STAFF, NAVOCEANO, 8/30/83 

 C 



DIMENSION X(1024),Y(1024) 



REAL I9,J9,K9,L9 

 C 



C COMPUTE INITIAL ESTIMATE OF A AND B BY PERFORMING A SIMPLE 

 C LINEAR FIT ON LOG TRANSFORMED DATA 

 C 



XN=FLOAT(N) 



XPRCD=0.0 



XSUM=0.0 



YSUM=0.0 



XSQR=0.0 

 C WRITE(6,'(2F10.4)') (X(I),Y( I),I=1,N) 

 C FIND MEAN LEVEL AND CONVERT X TO RADIANS 



DO 50 1=1, N 



X(I)=X(I)/57. 2957795 

 50 A0=A0+(Y(I)/XN) 

 C LOCATE LARGEST POSITIVE DIFFERENCE FROM THE MEAN AND ITS PHI 



DO 60 1=1, N 



IF((Y(I)-AO).LT.BO) GO TO 60 



B0=Y(I)-A0 



PHIO=X(I) 

 60 CONTINUE 

 C 



C COMPUTE SUM OF SQUARES OF THE RESIDUALS 

 C 



POLD=0.0 



DO 100 1=1, N 

 100 P0LD=P0LD+((Y(I)-F3(X(I),A0,B0,PHI0))**2) 



ITERAT=0 



NBIS=0 



IF(ILIST.EQ.1)WRITE(6,110) 

 110 FORMATC ITERATION # OF BISECTIONS A B 



181 



