From c4afc0c4efb1510078bbe94843f868702a6919d0 Mon Sep 17 00:00:00 2001
From: Jacques Grelet <jacques.grelet@ird.fr>
Date: Wed, 9 Jan 2008 13:16:10 +0000
Subject: [PATCH] propose le nom du fichier d'origine avec l'extension .nc lors
 de la sauvegarde

---
 tsg_io/readTsgDataNetCDF.m |  6 +++++-
 tsg_io/readTsgDataTxt.m    | 10 ++++------
 tsg_io/readTsgDataXML.m    |  7 ++++++-
 tsgqc_GUI.m                | 39 ++++++++++++++++++++++++--------------
 4 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/tsg_io/readTsgDataNetCDF.m b/tsg_io/readTsgDataNetCDF.m
index 475fbdc..48f56c8 100644
--- a/tsg_io/readTsgDataNetCDF.m
+++ b/tsg_io/readTsgDataNetCDF.m
@@ -38,9 +38,13 @@ end
 % --------------------------------------------
 fprintf('...reading %s : ', filename);
 
+% populate tsg.file structure
+% ---------------------------
+tsg.file.name = filename;
+tsg.file.type = 'NETCDF';
+
 % Read global attributes: meta data
 % ----------------------------------
-
 tsg.PLATFORM_NAME             = nc.PLATFORM_NAME(:);
 tsg.SHIP_CALL_SIGN            = nc.SHIP_CALL_SIGN(:);
 tsg.SHIP_MMSI                 = nc.SHIP_MMSI(:);
diff --git a/tsg_io/readTsgDataTxt.m b/tsg_io/readTsgDataTxt.m
index f57c38c..c90503a 100644
--- a/tsg_io/readTsgDataTxt.m
+++ b/tsg_io/readTsgDataTxt.m
@@ -55,12 +55,6 @@ tsg.DAYD       = datenum(tsgData(:,3), tsgData(:,2),tsgData(:,1), ...
 % save original date
 % ------------------
 tsg.DATE       = datestr(  tsg.DAYD, 'yyyymmddHHMMSS' );
-
-% convert with julian day with origin 1950
-% -----------------------------------------
-%% a supprimer !!!!!!!
-% tsg.TIME_TSG = datenumToJulian(tsg.TIME_TSG);
-
 tsg.LATX       = tsgData(:,7);
 tsg.LONX       = tsgData(:,8);
 tsg.SSJT       = tsgData(:,9);
@@ -83,6 +77,10 @@ if isempty(tsg.SPDC)
   tsg.SPDC = [tsg.SPDC';0];
 end
 
+% populate tsg.file structure
+% ---------------------------
+tsg.file.name = filename;
+tsg.file.type = 'ASCII';
 
 % Save the data in the application GUI
 % ------------------------------------
diff --git a/tsg_io/readTsgDataXML.m b/tsg_io/readTsgDataXML.m
index 8f2b79d..1fa406a 100644
--- a/tsg_io/readTsgDataXML.m
+++ b/tsg_io/readTsgDataXML.m
@@ -39,7 +39,12 @@ if fid ~= -1
 %     tsg.PSAL_QC    = tsgData(:,11);
 %     tsg.PSAL_ADJ   = tsgData(:,12);
 %     tsg.PSAL_ERR   = tsgData(:,13);
-%     
+
+%     % populate tsg.file structure
+%     % ---------------------------
+%     tsg.file.name = filename;
+%     tsg.file.type = 'XML';
+%
 %     % Save the data in the application GUI
 %     % ------------------------------------
 %     setappdata( hTsgGUI, 'tsg_data', tsg );
diff --git a/tsgqc_GUI.m b/tsgqc_GUI.m
index dcd11d3..351dacf 100644
--- a/tsgqc_GUI.m
+++ b/tsgqc_GUI.m
@@ -443,34 +443,34 @@ tsg_initialisation(hMainFig, hQcCmenu)
     % ------------------------------------------------
     set( hMainFig, 'Pointer', 'watch' );
 
-    % Make the filename
+    % Make the fileName
     % ATTENTION : function OpenMenuCallback(hObject, eventdata)
     % This has to be made general for UNIX and WINDOWS system
     % ---------------------------------------------------------
-    [filename, pathname, filterIndex] = uigetfile( ...
+    [fileName, pathname, filterIndex] = uigetfile( ...
       {'*.txt';'*.xml';'*.nc';'*.btl'}, 'Pick a file');
 
     error1 = -1;
     error2 = -1;
 
-    if ~isequal(filename, 0)
+    if ~isequal(fileName, 0)
 
       % Read the data
       % -------------
       switch filterIndex
 
         case 1
-          error1 = readTsgDataTxt( hMainFig, filename );
+          error1 = readTsgDataTxt( hMainFig, fileName );
         case 2
-          error1 = readTsgDataXML( hMainFig, filename );
+          error1 = readTsgDataXML( hMainFig, fileName );
         case 3
-          error1 = readTsgDataNetCDF( hMainFig, filename );
+          error1 = readTsgDataNetCDF( hMainFig, fileName );       
           %# a modifier
           if error1 == 1
             error2 = error1;
           end
         case 4
-          error2 = readBucketData(hMainFig, filename );
+          error2 = readBucketData(hMainFig, fileName );
         otherwise
           return;
 
@@ -488,7 +488,7 @@ tsg_initialisation(hMainFig, hQcCmenu)
 
         % update the display
         % ------------------
-        set( hInfoFileText, 'String', filename);
+        set( hInfoFileText, 'String', fileName);
 
         % The callback to detect the mouse motion can be set to on
         % --------------------------------------------------------
@@ -791,8 +791,8 @@ tsg_initialisation(hMainFig, hQcCmenu)
         % -----------------------------------------------------------
         [x, y] = gpos(hPlotAxes(1));
 
-        % Dynamically diplay data in uicontrol
-        % ------------------------------------
+        % Dynamically display data in uicontrol
+        % -------------------------------------
         if x > tsg.DAYD(1) && x < tsg.DAYD(end)
           indCursor = find( tsg.DAYD > x);
           set( hInfoDateText, 'String',...
@@ -1060,6 +1060,14 @@ tsg_initialisation(hMainFig, hQcCmenu)
 % -------------------------------------------------------------------
   function SaveMenuCallback(hObject, eventdata)
     % Callback function run when the Save menu item is selected
+    
+    % Retrieve named application data
+    % -------------------------------
+    tsg = getappdata( hMainFig, 'tsg_data');
+
+    % get fileName without extension in cell
+    % --------------------------------------
+    file = textscan( tsg.file.name,'%s','delimiter','.');
 
     % fill or append header form
     % -------------------------
@@ -1069,7 +1077,7 @@ tsg_initialisation(hMainFig, hQcCmenu)
     % ------------------------------------------------
     if error ~= -1
       [fileName, pathName, filterIndex] = uiputfile('*.nc', ...
-        'Save file name');
+        'Save file name', [file{1}{1} '.nc']);
 
       % if user press cancel button, all var set to zero
       % ------------------------------------------------
@@ -1087,8 +1095,7 @@ tsg_initialisation(hMainFig, hQcCmenu)
 
       % write netcdf file
       % -----------------
-      fileName = [pathName fileName];
-      error = writeTSGDataNetCDF( hMainFig, fileName );
+      error = writeTSGDataNetCDF( hMainFig, [pathName fileName] );
 
       % Pointer reset to arrow
       % ----------------------
@@ -1098,8 +1105,12 @@ tsg_initialisation(hMainFig, hQcCmenu)
       % must to be rewriting
       % --------------------------------
       if error == -1
-        warning(['NetCDF writing error:'  fileName]);
+        warning(['NetCDF writing error:'  [pathName fileName]]);
       end
+      
+      % update the display
+      % ------------------
+      set( hInfoFileText, 'String', fileName);
     end
   end
 
-- 
GitLab