but_interpolate_Callback.m 1.17 KB
function edit_interpolate_step_Callback(hObject, eventdata, handles)

global S bathy

step = str2num(handles.edit_interpolate_step.String)/(24*3600) ;

I0    = str2num(handles.edit_I0.String);
If    = str2num(handles.edit_If.String);
tq    = [S.dnum(I0):step:S.dnum(If)]' ;
iN    = numel(tq) ;

% write to logfile
newN = numel(S.dnum)-numel(I0:If)+iN ; % track size
fprintf(handles.logfid,'%s,%d,%d,%f,%d\n','interpolate',I0,If,step,newN) ;

%% get interpolated coordinate values
ilon  = interp1(S.dnum(I0:If),S.lon(I0:If),tq) ;
ilat  = interp1(S.dnum(I0:If),S.lat(I0:If),tq) ;
if isfield(S,'z') ; iz = bathy(ilon,ilat) ; end

%% Cut this data from the S raw structure
S.lon(I0:If)  = [];
S.lat(I0:If)  = [];
S.dnum(I0:If) = [];
if isfield(S,'z') ; S.z(I0:If) = [] ; end

%% Insert the interpolated values at I0
S.lon  = insertAt(S.lon ,I0,ilon) ;
S.lat  = insertAt(S.lat ,I0,ilat) ;
S.dnum = insertAt(S.dnum,I0,tq) ;
if isfield(S,'z') ; S.z = insertAt(S.z,I0,iz); end

%% Update plots
If = I0 + iN -1 ;

% Update index fields
handles.edit_If.String = num2str(If) ;

guidata(hObject, handles);
update_plots(hObject, eventdata, handles) ;

% Update handles structure
guidata(hObject, handles);

end