Newer
Older
function [error] = interpPosLinear( hMainFig, dateMin, dateMax )
%
% Function that interpolate linearly Latitude and position when they are
% set to NaN
%
% Input
% hMainFig ..... Handle to the main GUI
% dateMin ...... the correction is applied between dateMin and date Max
% dateMax ...... the correction is applied between dateMin and date Max
%
% Output
% Error ........ 1 everything OK
% ........ -1 dateMax <= date Min
%
% Get application data
% --------------------
tsg = getappdata( hMainFig, 'tsg_data');
% Get NO_CONTROL and INTERPOLATED_VALUE codes
% -------------------------------------------
%NO_CONTROL = tsg.qc.hash.NO_CONTROL.code;

jacques.grelet_ird.fr
committed
INTERPOLATED_VALUE = tsg.qc.hash.INTERPOLATED_VALUE.code;
PROBABLY_BAD = tsg.qc.hash.PROBABLY_BAD.code;
BAD = tsg.qc.hash.BAD.code;
error = 1;
if dateMax > dateMin
% set LATX and LONX to Nan when POSITION_QC is BAD or PROBABLY_BAD
% needed to interpolate bad positions
% ----------------------------------------------------------------
iPos = find(tsg.POSITION_QC == PROBABLY_BAD | tsg.POSITION_QC == BAD);
tsg.LATX(iPos) = nan;
tsg.LONX(iPos) = nan;
% Indices of the records to interpolate
% -------------------------------------
iRec = find( tsg.DAYD >= dateMin & tsg.DAYD <= dateMax );
gael.alory_legos.obs-mip.fr
committed
% Look for records with Good Latitude
% ------------------------------------
iGPLat = find( ~isnan(tsg.LATX(iRec)) );
gael.alory_legos.obs-mip.fr
committed
% Look for records with Good Longitude
% ------------------------------------
iGPLon = find( ~isnan(tsg.LONX(iRec)) );
gael.alory_legos.obs-mip.fr
committed
% Look for records with No Latitude
% ----------------------------------
iNPLat = find( isnan(tsg.LATX(iRec)) );
gael.alory_legos.obs-mip.fr
committed
% Look for records with No Longitude
% ----------------------------------
iNPLon = find( isnan(tsg.LONX(iRec)) );
gael.alory_legos.obs-mip.fr
committed
% Fill Latitudes by interpolation
% -------------------------------
if ~isempty( iNPLat ) && ~isempty( iGPLat ) && ( sum(iNPLat>min(iGPLat) & iNPLat<max(iGPLat))>0 )
gael.alory_legos.obs-mip.fr
committed
Y = interp1(tsg.DAYD(iRec(iGPLat)), tsg.LATX(iRec(iGPLat)), tsg.DAYD(iRec) );
gael.alory_legos.obs-mip.fr
committed
tsg.LATX(iRec(iNPLat)) = Y(iRec(iNPLat) - iRec(1) + 1);
gael.alory_legos.obs-mip.fr
committed
tsg.POSITION_QC(iRec(iNPLat)) = INTERPOLATED_VALUE;
end
% Fill Longitudes by interpolation
% --------------------------------
if ~isempty( iNPLon ) && ~isempty( iGPLon ) && ( sum(iNPLon>min(iGPLon) & iNPLon<max(iGPLon))>0 )
Y = interp1(tsg.DAYD(iRec(iGPLon)), tsg.LONX(iRec(iGPLon)), tsg.DAYD(iRec) );
gael.alory_legos.obs-mip.fr
committed
tsg.LONX(iRec(iNPLon)) = Y(iRec(iNPLon) - iRec(1) + 1);
gael.alory_legos.obs-mip.fr
committed
tsg.POSITION_QC(iRec(iNPLon)) = INTERPOLATED_VALUE;
gael.alory_legos.obs-mip.fr
committed
% Update tsg application data
% ---------------------------
setappdata( hMainFig, 'tsg_data', tsg);
else
error = -1;
end