function [zout]=my_fun(Z0);
%function [zout]=my_fun(Z0);

lonref=69;
latref=30;
lat0 = 29.95;

% load float data
%load dr_82586.txt
%load dr_6.txt
load Drogue_52486_smoothed.txt
% time lon lat
% assign columns
%t = dr_82586(:,1);
%lon=-dr_82586(:,2);
%lat=dr_82586(:,3);
t = dr_6(:,1);
lon=-dr_6(:,2);
lat=dr_6(:,3);

% convert to m
%phi=mean(lat)*pi.180;
phi = lat0*pi/180;
x=111000/cos(phi)*(lonref-lon);
y=111000*(lat-latref);
% make a single value
z=x+i*y;

% reference time
t0 = t(1)-.001;
% convert to seconds
tsec_ref = (t-t0)*3600*24;

% extract info from input vector
z00   = Z0(1);
r     = Z0(2);
th0   = Z0(3);
omega = Z0(4);
w     = Z0(5);

zfun = ( z00 + r * exp(i*(th0+omega*tsec_ref)) + w*tsec_ref ); 
zout = sum( (z - zfun).^2 ); 
keyboard
% x,y,t - input data  (as z0)
% t0 - reference time (before all data)
% t-t0 is in seconds
% unknowns:
% u,v (w)- componants of velocity of center
% w - u + (i * v);
% r - radius of orbit around center
% omega - angular velocity of orbit around center
% th0 - initial angle at t0
% x00, y00 - position at t0 (z00 - complex value of x00 + (i * y00))
