function strutcall(action)

global x y tmax
% Remove
global P

switch(action)
case 'load'
  
   % Read Input Data
   [fname,pname] = uigetfile('*.dat','File containing airfoil co-ordinates');
   if fname == 0 
      return;
   end
   
   dot=find(fname=='.');
     
   oldpath = pwd;
   eval(['cd ' pname]);
   data = load(fname);
   eval(['cd ' pwd]);
   
   x = data(:,1);
   y = data(:,2);
   
   txtHndl=findobj(gcbf,'Tag','airfoilname');
   set(txtHndl,'String',fname(1:dot-1));
   
   plot(x,y); axis([0 1 -.5 .5]);
   
   % Load default strut size
   fid=fopen('default.dat','r');
   fgetl(fid);
   lstrut=eval(fgetl(fid));
   fgetl(fid);
   wstrut=eval(fgetl(fid));
   fclose(fid);
   
   txtHndl=findobj(gcbf,'Tag','length');
   set(txtHndl,'String',num2str(lstrut));
   
   txtHndl=findobj(gcbf,'Tag','width');
   set(txtHndl,'String',num2str(wstrut)); 
   
case 'calculate'

        global x y
        delt=1e-7;                                              % Used for calculating dF/dt
        TOL=1e-6; % Tolerance for N-R iteration

        N = length(x);
        c = max(x)-min(x);
        x1 = x-c/2;
        r = sqrt(x1.^2+y.^2);
        theta = acos(x1./r);
        % Use a continues theta
        theta((N+1)/2:N)=2*pi-theta((N+1)/2:N);
        P = spline(theta,r); % Fit cubic spline in polar coords

        txtHndl=findobj(gcbf,'Tag','length');
        lstrut=eval(get(txtHndl,'String'));
   
        txtHndl=findobj(gcbf,'Tag','width');
        tstrut=eval(get(txtHndl,'String')); 

        ARrqd=lstrut/tstrut; % AR of strut

        [tmax,I]=max(y); % Approx. max thickness
        tmax=tmax*2;

        t0=tmax/2; % Start with tmax/2

        F='ARfit(P,x)-y'; % For sol. F=AR(t)-ARrqd=0
        FP=['(ARfit(P,x+' num2str(delt) ')-(ARfit(P,x)))/' num2str(delt)];
                                                                                % Derivative: F'=(F(t+dt)-F(t))/dt
                              
   tnew=Newton(F,FP,t0,ARrqd,P,TOL);
                                                                                % Find size of strut that will fit in norm. airfoil                           
                                   
        [AR,xLEnew]=ARfit(P,tnew);

        % Scale
        scale = tstrut/tnew;
   chord=scale*c;
   xLEnewnorm = xLEnew+c/2;
        xLEnew = xLEnewnorm*scale;

        x1=x*scale;
        y1=y*scale;

        % Plotit
        c1x=xLEnew; cy=tstrut/2;
        c2x=xLEnew+lstrut; 
        strx=[c1x c2x c2x c1x c1x];
        stry=[cy cy -cy -cy cy];
        plot(x1,y1,'b',strx,stry,'r');
        axis([0 chord -chord/2 chord/2]);
   
   txtHndl=findobj(gcbf,'Tag','scale');
   set(txtHndl,'String',num2str(scale));
   
   txtHndl=findobj(gcbf,'Tag','xlepers');
   set(txtHndl,'String',num2str(xLEnewnorm*100));
   
   txtHndl=findobj(gcbf,'Tag','xle');
   set(txtHndl,'String',num2str(xLEnew));
   
   
   
end;