From 7937a00d417bef02d69d5f145f24e3fb215b380c Mon Sep 17 00:00:00 2001
From: Jacques Grelet <jacques.grelet@ird.fr>
Date: Wed, 24 Feb 2010 09:49:31 +0000
Subject: [PATCH] ajout de commentaires et nettoyage de code

---
 tsg_io/readTsgDataNetCDF.m  | 14 +++++++++-----
 tsg_io/writeTSGDataNetCDF.m | 29 ++++++++---------------------
 2 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/tsg_io/readTsgDataNetCDF.m b/tsg_io/readTsgDataNetCDF.m
index 5da4b81..53c92ef 100644
--- a/tsg_io/readTsgDataNetCDF.m
+++ b/tsg_io/readTsgDataNetCDF.m
@@ -1,11 +1,11 @@
 function [error] = readTsgDataNetCDF( hMainFig, filename)
 % Function to read the TSG data. Should be a NetCDF file
-% GOSUD data format TSG V1.4
+% GOSUD data format TSG V1.6
 %
 % Input
 % -----
-% hMainFig ............ Handel to the main user interface
-% filename ........... Data filename
+% hMainFig ............ Handle to the main user interface
+% filename ............ Data filename
 %
 % Output
 % ------
@@ -13,6 +13,9 @@ function [error] = readTsgDataNetCDF( hMainFig, filename)
 %
 % The data are store using setappdata - Variable name : 'tsg_data'
 %
+% DAYD, DAYD_WS and DAYD_EXT in tsg structure use Matlab datenum, they 
+% should be converted from julian days using 1950 reference in NetCDF file 
+%
 % $Id$
 
 %% Check Netcdf library version
@@ -173,8 +176,9 @@ automaticQC( hMainFig )
       var = char(key);
       tsg.(var) = nc.VARIABLES.(var).data__;
       
-      % transforme julian days variables to Matlab datenum
-      % --------------------------------------------------
+      % when variable is julian days from 1950 reference, transform to
+      % Matlab datenum
+      % --------------------------------------------------------------
       if strmatch('DAYD', var)
         tsg.(var) = julianToDatenum(tsg.(var));
       end
diff --git a/tsg_io/writeTSGDataNetCDF.m b/tsg_io/writeTSGDataNetCDF.m
index 9430bc0..2b862d4 100644
--- a/tsg_io/writeTSGDataNetCDF.m
+++ b/tsg_io/writeTSGDataNetCDF.m
@@ -1,6 +1,6 @@
 function [error] = writeTSGDataNetCDF( hTsgGUI, filename)
 % [error] = writeTSGDataNetCDF( hTsgGUI, filename)
-% Function to write TSG data in NetCDF file.
+% Function to write TSG data in NetCDF file to GOSUD format 1.6.
 %
 % Input
 % -----
@@ -14,9 +14,8 @@ function [error] = writeTSGDataNetCDF( hTsgGUI, filename)
 %
 % The data are store using setappdata - Variable name : 'tsg_data'
 %
-% Actually, with DAYD, DAYD_WS and DAT_EXT dimensions defined: 61 variables
-%                DAYD, DAYD_WS dimensions defined:             57 variables
-%                DAYD only dimension defined:                  53 variables
+% DAYD, DAYD_WS and DAYD_EXT in tsg structure use Matlab datenum, they 
+% should be converted to julian days using 1950 reference in NetCDF file 
 %
 % $Id$
 
@@ -323,7 +322,7 @@ end
         
       end
       
-    end
+    end % end of loop over variables keys
     
     % Close waitbar
     % -------------
@@ -360,24 +359,17 @@ end
     % -----------------------------------------------------------------
     for key = keys(nc.VARIABLES)
       var = char(key);
+      
+      % Convert Matlab julian days (datenum) to 1950 reference
+      % ------------------------------------------------------
       if strmatch('DAYD', var)
         nc.VARIABLES.(var).data__ = datenumToJulian(tsg.(var));
       else
         nc.VARIABLES.(var).data__ = tsg.(var);
       end
     end
-      
-%     % Convert Matlab julian days (datenum) to 1950 reference
-%     % ------------------------------------------------------
-%     ncv_keys = keys(nc.VARIABLES);
-%     d = strmatch('DAYD', ncv_keys);
-%     for i=1:numel(d)
-%       tsg.(ncv_keys{d(i)}) = datenumToJulian(tsg.(ncv_keys{d(i)}));
-%     end
     
- 
-    
-    % loop over all global attributes and get associated value in tsg 
+    % loop over all global attributes and get associated value in tsg
     % structure
     % -----------------------------------------------------------------
     for key = keys(nc.ATTRIBUTES)
@@ -385,8 +377,6 @@ end
       nc.ATTRIBUTES.(att).data__ = tsg.(att);
     end
     
- % try
-    
     % write netcdf file with and display waibar (boolean)
     % ---------------------------------------------------
     write( nc, filename, 'NC_CLOBBER', true );
@@ -394,9 +384,6 @@ end
     % Everything OK
     % -------------
     error = 1;
- % catch
- %   error = -1;
- % end
     
   end
 
-- 
GitLab