Newer
Older

jacques.grelet_ird.fr
committed
hLine2 = get( hPlotAxes(2), 'UserData');

jacques.grelet_ird.fr
committed
% Delete climatology lines on axes

jacques.grelet_ird.fr
committed
% -----------------------------------
try
delete(hLine1.stdClimMinus);
delete(hLine1.stdClimPlus);
delete(hLine1.meanClim);
delete(hLine2.stdClimMinus);
delete(hLine2.stdClimPlus);
delete(hLine2.meanClim);
% if handle is missing, prevent warning message on console
% --------------------------------------------------------

jacques.grelet_ird.fr
committed
catch
end

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
%------------------------------------------------------------------------
% Callback function run when the Levitus climatology toolbar is unselected
%------------------------------------------------------------------------
function Clim_OnMenuCallback(hObject, eventdata)

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% Test if the TSG and bucket files have been read
% -----------------------------------------------
if strcmp( get(hOpenMenu, 'UserData'), 'on' )

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% Get data
% -----------------------
tsg = getappdata( hMainFig, 'tsg_data' );

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% Get line handles
% ----------------

jacques.grelet_ird.fr
committed
hLine1 = get( hPlotAxes(1), 'UserData');
hLine2 = get( hPlotAxes(2), 'UserData');

jacques.grelet_ird.fr
committed
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
% Read Climatology
% ----------------
if isempty( tsg.levitus.data)
levitus = read_file_woa01( 'woa01an.nc' );
if ~isstruct(levitus)
errordlg({'NetCDF climatology file not present in you path',...
'Check your matlab path or download it from',...
'ftp://ftp.ifremer.fr/ifremer/ird/us191/oceano/lib/matlab/woa01an.nc'},...
'NetCDF climatology file access error');
return;
else
tsg.levitus.data = levitus;
tsg.levitus.type = 'woa01an';
end
setappdata( hMainFig, 'tsg_data', tsg );
end
% round positive latitude and Longitude toward zero
% -------------------------------------------------
ind = find(tsg.LATX > 0);
lat(ind) = fix(tsg.LATX(ind)) + 0.5;
ind = find(tsg.LONX > 0);
lon(ind) = fix(tsg.LONX(ind)) + 0.5;
% rounds negative latitude and Longitudeto the nearest lowest integers
% ---------------------------------------------------------------------
ind = find(tsg.LATX <= 0);
lat(ind) = floor(tsg.LATX(ind)) + 0.5;
ind = find(tsg.LONX <= 0);
lon(ind) = floor(tsg.LONX(ind)) + 0.5;
% Calculates differences between adjacent elements of X.
% 0 if adajacent latitude or longitude are equal
% - 1 or -1 otherwise
% ------------------------------------------------------------
lat_diff = [diff( lat )'; 0];
lon_diff = [diff( lon )'; 0];
% Select latitude and longitude
% -----------------------------
ind = find(abs(lat_diff) == 1 | abs(lon_diff == 1));
lat2 = lat( ind );
lon2 = lon( ind );
time = tsg.DAYD( ind );
temp = tsg.SSJT( ind );
psal = tsg.SSPS( ind );
% Get Climatology
% LATX(80) = -0.5 et LATX(81) = 0.5
% LONX(180) = -0.5 et LONX(181) = 0.5
% ----------------
axes( hPlotAxes(1) );
mean_temp = zeros(size(ind));
mean_psal = zeros(size(ind));
std_temp = zeros(size(ind));
std_psal = zeros(size(ind));
for i=1:length(ind)
ilat = find(tsg.levitus.data.WOA01_LATX == lat2(i));
ilon = find(tsg.levitus.data.WOA01_LONX == lon2(i));
mean_temp(i) = tsg.levitus.data.WOA01_MEAN_TEMP(ilat,ilon,1);
mean_psal(i) = tsg.levitus.data.WOA01_MEAN_PSAL(ilat,ilon,1);
std_temp(i) = tsg.levitus.data.WOA01_STD_TEMP(ilat,ilon,1);
std_psal(i) = tsg.levitus.data.WOA01_STD_PSAL(ilat,ilon,1);

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
% Plot mean salinity climatology
% ------------------------------
hLine1.meanClim = line( ...
time, mean_psal,'Linestyle', '-', 'Color','k');
% Plot with 3 standard deviation
% ------------------------------
hLine1.stdClimPlus = line( ...
time, mean_psal + 3 * std_psal ,'Linestyle', '-', 'Color','r');
hLine1.stdClimMinus = line( ...
time, mean_psal - 3 * std_psal ,'Linestyle', '-', 'Color','r');
% Plot mean temperature climatology
% ---------------------------------
axes( hPlotAxes(2));
hLine2.meanClim = line( ...
time, mean_temp,'Linestyle', '-', 'Color','k');
hLine2.stdClimPlus = line( ...
time, mean_temp + 3 * std_temp ,'Linestyle', '-', 'Color','r');
hLine2.stdClimMinus = line( ...
time, mean_temp - 3 * std_temp ,'Linestyle', '-', 'Color','r');
% Store the handle of the bucketline
% ----------------------------------
set( hPlotAxes(1), 'UserData', hLine1 );
set( hPlotAxes(2), 'UserData', hLine2 );

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% -------------------------------------------------------------------
% Callback function run when the headerForm tool bar item is selected
% -------------------------------------------------------------------

jacques.grelet_ird.fr
committed
function HeaderMenuCallback(hObject, eventdata)

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% call header form function
% -------------------------
headerForm(hMainFig);

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% -------------------------------------------------------------------
% Callback function run when the Save menu item is selected
% -------------------------------------------------------------------

jacques.grelet_ird.fr
committed
function SaveMenuCallback(hObject, eventdata)

jacques.grelet_ird.fr
committed
% Retrieve named application data
% -------------------------------
tsg = getappdata( hMainFig, 'tsg_data');
% get fileName without extension in cell
% --------------------------------------
file = textscan( tsg.file.name,'%s','delimiter','.');

jacques.grelet_ird.fr
committed
% fill or append header form
% -------------------------
error = headerForm(hMainFig);
% if user press continue button, ask for netcdf file
% ------------------------------------------------
if error ~= -1
[fileName, pathName, filterIndex] = uiputfile('*.nc', ...

jacques.grelet_ird.fr
committed
'Save file name', [file{1}{1} '.nc']);

jacques.grelet_ird.fr
committed
% if user press cancel button, all var set to zero
% ------------------------------------------------
if fileName == 0
return;
end
% Pointer set to watch during reading and plotting
% ------------------------------------------------
set( hMainFig, 'Pointer', 'watch' );
% flushes the event queue and updates the closed uiputfile window
% ---------------------------------------------------------------
drawnow;
% write netcdf file
% -----------------

jacques.grelet_ird.fr
committed
error = writeTSGDataNetCDF( hMainFig, [pathName fileName] );

jacques.grelet_ird.fr
committed
% Pointer reset to arrow
% ----------------------
set( hMainFig, 'Pointer', 'arrow' );
% Check for a writing pb to NetCDF
% must to be rewriting
% --------------------------------
if error == -1

jacques.grelet_ird.fr
committed
warning(['NetCDF writing error:' [pathName fileName]]);

jacques.grelet_ird.fr
committed
return;

jacques.grelet_ird.fr
committed
% update the display
% ------------------
set( hInfoFileText, 'String', fileName);

jacques.grelet_ird.fr
committed
% enable Quality Control mode
% ---------------------------
hdl_pushtool = findobj('Tag', 'QC');
set(hdl_pushtool, 'Enable', 'on');

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% -----------------------------------------------------------------
% Callback function run when the Quit menu item is selected
% -----------------------------------------------------------------
function QuitMenuCallback(hObject, eventdata)

jacques.grelet_ird.fr
committed
% If the data have been modified and not save, the program

jacques.grelet_ird.fr
committed
% ask to save the data

jacques.grelet_ird.fr
committed
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
% --------------------------------------------------------
if strcmp( get( hSaveMenu, 'UserData' ), 'on')
selection = ...
questdlg('The file has been modified. Do you want to save it ?',...
'Save before Quit?',...
'Yes', 'No', 'Yes');
if strcmp(selection, 'Yes')
return;
else
QuitProgram;
end
else
selection = ...
questdlg(['Quit ' get(hMainFig, 'Name') '?'],...
['Quit ' get(hMainFig, 'Name') '?'],...
'Yes', 'No', 'Yes');
if strcmp(selection, 'No')
return;
else
QuitProgram;
end

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% -----------------------------------------------------------------
% call from:
% QuitMenuCallback
% callback 'CloseRequestFcn', @QuitProgram

jacques.grelet_ird.fr
committed
% -----------------------------------------------------------------

jacques.grelet_ird.fr
committed
function QuitProgram(hObject, eventdata)

jacques.grelet_ird.fr
committed
% close the main windows
% ----------------------

jacques.grelet_ird.fr
committed
delete(hMainFig);

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
% reset Matlab search path to default

jacques.grelet_ird.fr
committed
% -----------------------------------

jacques.grelet_ird.fr
committed
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_util'] );
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_data'] );
rmpath( [DEFAULT_PATH_FILE filesep 'tsg_io'] );

jacques.grelet_ird.fr
committed
% Refresh file system caches
% --------------------------

jacques.grelet_ird.fr
committed
rehash;

jacques.grelet_ird.fr
committed

jacques.grelet_ird.fr
committed
end

jacques.grelet_ird.fr
committed
% end of tsgqc_GUI
% ----------------
end