diff --git a/@dynaload/display.m b/@dynaload/display.m
index 2dbd0e765b3ee901dcb849c6cdb485a22930892e..6ced587904aee50cd3e9f9ca856739f56e7475ad 100644
--- a/@dynaload/display.m
+++ b/@dynaload/display.m
@@ -13,7 +13,7 @@ result = elements(self);
 %       % -----------------------
 %       wks = whos('global');
 %       for i=1:length(wks)
-%         if strcmp(wks(i).class, 'us191.dynaload')
+%         if strcmp(wks(i).class, 'dynaload')
 %           var = wks(i).name;
 %         end
 %       end
diff --git a/@dynaload/dynaload.m b/@dynaload/dynaload.m
index 5c480c4e2cdf1504e2d7a1a5693d28562dcdd591..c8279487a2e8b17f41165251c68ec1c4dbf70dfb 100644
--- a/@dynaload/dynaload.m
+++ b/@dynaload/dynaload.m
@@ -104,23 +104,23 @@ function self = dynaload(varargin)
 % test constructor argument
 % -------------------------
 switch nargin
-  
+
   case 0  % can't create default object
     [file, path, filterIndex] = uigetfile(...
       {'*.csv','Ascii-file (*.csv)';...
       '*.xls','Excel-file (*.xls)'}, 'Select file');
     if ~any(file)
       self.file = 'memory';
-      return
+      filterIndex = -1;
+    else
+      self.file = fullfile(path, file);
     end
-    self.file = fullfile(path, file);
-    
+
   case 1
     if strcmp(varargin{1}, 'memory')
       self.file = 'memory';
-      return
-    end
-    if( isa(varargin{1}, 'char'))
+      filterIndex = -1;
+    elseif( isa(varargin{1}, 'char'))
       file = which(varargin{1});
       if isempty( file)
         file = varargin{1};
@@ -138,10 +138,10 @@ switch nargin
     else
       error('Wrong input argument');
     end
-    
+
   otherwise
     error('Wrong number of input arguments');
-    
+
 end
 
 % init class properties
diff --git a/@dynaload/save.m b/@dynaload/save.m
index 518e55fc3840a92f818de8c8c57dba2a56135325..dfa35c80d5659c3905452021847ce5c5d17a29da 100644
--- a/@dynaload/save.m
+++ b/@dynaload/save.m
@@ -1,6 +1,6 @@
 function save(self, varargin)
-% us191.dynaload.save
-% it's a wrapper on us191.dynaload.write method
+% dynaload save
+% it's a wrapper on dynaload.write method
 %
 % $Id$
 
diff --git a/@dynaload/write.m b/@dynaload/write.m
index 194580c0c345287745caa1d14541104e521d07e3..d6ecfcfc9dbdc9c2d5fa006e4a8e52e95aba5fe5 100644
--- a/@dynaload/write.m
+++ b/@dynaload/write.m
@@ -1,15 +1,15 @@
    function write(self, varargin)
    % write dynaload memory structure to ASCII CSV file (Comma Separated Value)
 % nc is a dynaload objet in memory load from xls file. for example:
-% >> nc = us191.dynaload('test.xls');
+% >> nc = dynaload('test.xls');
 % >> nc
-% us191.dynaload
+% dynaload
 % 
 % 	file:	test.xls
 % 
-% 	DIMENSIONS               	us191.hashtable
-% 	VARIABLES                	us191.hashtable
-% 	ATTRIBUTES               	us191.hashtable
+% 	DIMENSIONS               	hashtable
+% 	VARIABLES                	hashtable
+% 	ATTRIBUTES               	hashtable
 % 
 % >> s = nc.VARIABLES.SSTP
 % 
diff --git a/@hashtable/elements.m b/@hashtable/elements.m
index d610e8b78b7a5ad448e3e6e45047c34540421a39..f9bed61950a539ae4e88b36f5069bb9fcaea592d 100644
--- a/@hashtable/elements.m
+++ b/@hashtable/elements.m
@@ -8,6 +8,10 @@ function data = elements(hash)
 
 % Copyright (c) 2004 Matthew Krauski (mkrauski@uci.edu), CNLM, UC Irvine
 
-data(:,1) = hash.keys;
-data(:,2) = hash.data;
+if isempty( hash )
+  data = {};
+else
+  data(:,1) = hash.keys;
+  data(:,2) = hash.data;
+end
 
diff --git a/@hashtable/size.m b/@hashtable/size.m
new file mode 100644
index 0000000000000000000000000000000000000000..642e516cd911e7977e13a5f9fcc9ec662b4aea6a
--- /dev/null
+++ b/@hashtable/size.m
@@ -0,0 +1,6 @@
+function out = size(self)
+% get hashtable size
+
+% Return the number of keys in hashtable
+% --------------------------------------
+out = numel(self.keys);
diff --git a/@netcdf_native/display.m b/@netcdf_native/display.m
new file mode 100644
index 0000000000000000000000000000000000000000..d6086abd78182e0306479c8f057fc6d377d93692
--- /dev/null
+++ b/@netcdf_native/display.m
@@ -0,0 +1,53 @@
+function display(self)
+% display netcdf object
+
+
+% diplay help in hypertext link
+% -----------------------------
+fprintf('<a href="matlab:help netcdf">netcdf</a>\n\n');
+if self.mode ~= -1
+  fprintf('\tfile:      ''%s''\n', self.file);
+end
+%fprintf('\tdynaload:  ''%s''\n', self.dynaload);
+fprintf('\tmode:      ''%s''\n', self.mode);
+if self.autonan
+  theAutonan = 'true';
+else
+  theAutonan = 'false';
+end
+fprintf('\tautonan:    %s\n', theAutonan);
+if self.autoscale
+  theAutoscale = 'true';
+else
+  theAutoscale = 'false';
+end
+fprintf('\tautoscale:  %s\n\n', theAutoscale);
+
+% call protected function hashtable.elements that return
+% <nx2> cell array of key/value
+% ------------------------------------------------------
+result = elements(self);
+
+%       % get workspace variables
+%       % -----------------------
+%       wks = whos('global');
+%       for i=1:length(wks)
+%         if strcmp(wks(i).class, '.netcdf')
+%           var = wks(i).name;
+%         end
+%       end
+
+% loop over key
+% -------------
+%nb = size(result);
+
+for key = result'
+  fprintf('\t%-25s\t%2d [%-10s]\n', ...
+    key{1}, size(key{2}), class(key{2}));
+end
+fprintf('\n');
+
+% diplay methods list in hypertext link
+% -------------------------------------
+disp('list of <a href="matlab:methods(''.netcdf'')">methods</a>');
+end
\ No newline at end of file
diff --git a/@netcdf_native/file.m b/@netcdf_native/file.m
new file mode 100644
index 0000000000000000000000000000000000000000..77be74093396513c23bf97ce073f950597dc93b0
--- /dev/null
+++ b/@netcdf_native/file.m
@@ -0,0 +1,5 @@
+function file = file(self)
+
+file = self.file;
+
+end
\ No newline at end of file
diff --git a/@netcdf_native/get.m b/@netcdf_native/get.m
new file mode 100644
index 0000000000000000000000000000000000000000..d1a2666ba780d8ba15f10e7a895ca167786e52f9
--- /dev/null
+++ b/@netcdf_native/get.m
@@ -0,0 +1,28 @@
+function value = get( self, prop )
+% GET: Get profil properties from specified object
+
+% $Id: get.m 121 2007-02-05 17:16:33Z jgrelet $
+
+if nargin==1  % list properties if only object is given
+  disp('profil properties:')
+  fprintf(' file, mode, nc_id, autonan, autoscale');
+  return
+end
+
+if ~ischar(prop), error('GET: prop must be string.'), end
+
+switch prop
+  
+  case 'file'
+    value = self.file;
+  case 'mode'
+    value = self.mode;
+  case 'nc_id'
+    value = self.nc_id;
+  case 'autonan'
+    value = self.autonan;
+  case 'autoscale'
+    value = self.autoscale;
+  otherwise
+   error(['GET: ', prop,' is not a valid netcdf property.']);
+end
\ No newline at end of file
diff --git a/@netcdf_native/getConstantNames.m b/@netcdf_native/getConstantNames.m
new file mode 100644
index 0000000000000000000000000000000000000000..042bbdce11ff175ab0bbe30f7673bb012b6355b2
--- /dev/null
+++ b/@netcdf_native/getConstantNames.m
@@ -0,0 +1,17 @@
+function name = getConstantNames(self, xtype)
+switch xtype
+  case  1   % NC_BYTE 1
+    name = 'byte';
+  case  2   % NC_CHAR 2
+    name = 'char';
+  case  3   % NC_SHORT 3
+    name = 'short';
+  case  4   % NC_INT, NC_LONG 4
+    name = 'int';
+  case  5   %NC_FLOAT 5
+    name = 'float';
+  case  6   % NC_DOUBLE 6
+    name = 'double';
+  otherwise
+    error( 'unhandled data type %d\n', xtype );
+end
diff --git a/@netcdf_native/mode.m b/@netcdf_native/mode.m
new file mode 100644
index 0000000000000000000000000000000000000000..231ef162443532ea67a807965d11bb220a4496b2
--- /dev/null
+++ b/@netcdf_native/mode.m
@@ -0,0 +1,5 @@
+function mode = mode(self)
+
+mode = self.mode;
+
+end
\ No newline at end of file
diff --git a/@netcdf_native/netcdf_native.m b/@netcdf_native/netcdf_native.m
new file mode 100644
index 0000000000000000000000000000000000000000..4578eba13056d9bb055e408105a021957ab7feaf
--- /dev/null
+++ b/@netcdf_native/netcdf_native.m
@@ -0,0 +1,217 @@
+function self = netcdf_native(varargin)
+%
+% file @netcdf_native/netcdf_native
+
+arg = nargin;
+
+if arg == 1 && isempty(varargin{1})
+  arg = 0;
+end
+
+theFile = ''; theDynaload = 'memory'; theMode = 'MEMORY';
+
+switch arg
+  
+  % with not arg, read netcdf file with uigetfile
+  % ---------------------------------------------
+  case 0
+    [theFileName, thePathName] = uigetfile(...
+      {'*.nc;*.cdf','NetCDF (*.nc,*.cdf)'}, 'Select file');
+    if any(theFileName)
+      theFile = fullfile(thePathName, theFileName);
+      theMode = 'NC_NOWRITE';
+      theDynaload = 'memory';
+    else
+      theFile = '';
+    end
+    
+    % with one arg, read given netcdf filename
+    % ----------------------------------------
+  case 1
+    if( strcmp(varargin{1}, 'memory'))
+      theDynaload = 'memory';
+      theFile = 'memory';
+      theMode = 'MEMORY';
+      
+    elseif( isa(varargin{1}, 'char'))
+      theFile = varargin{1};
+      if isempty(exist(theFile, 'file'))
+        error('netcdf: %s file don''t exist.\n', theFile );
+      end
+      [thePathName, theFileName, theFileExt] = fileparts(varargin{1});
+      
+      switch theFileExt
+        case {'.nc', 'cdf'}
+          theMode = 'NC_NOWRITE';
+          % a revoir ...
+          theDynaload = 'memory';
+        case {'.csv', '.xls'}
+          theDynaload = varargin{1};
+          theMode = 'DYNALOAD';
+        otherwise
+          error('Wrong file type');
+      end
+      
+    else
+      error('Wrong input argument');
+    end
+    
+    % work on given netcdf filename with mode and dynaload dexcriptor
+    % file
+    % ---------------------------------------------------------------
+  case 2
+    
+    % is the mode numeric.
+    if ischar(varargin{2})
+      %  convert it in numeric value
+      switch (varargin{2})
+        case { 'NC_WRITE', 'NC_CLOBBER', 'NC_NOCLOBBER', 'NC_SHARE' };
+          theMode = varargin{2};
+        otherwise
+          error('Wrong mode to create netcdf file: %s', varargin{2});
+      end
+    else
+      % a modifier sur mode est numeric
+      theMode = varargin{2};
+    end
+    
+  otherwise
+    error('Wrong number of input arguments');
+end
+
+d = dynaload( theDynaload );
+
+self.file      = theFile;
+%self.dynaload = theDynaload;
+self.mode      = theMode;
+self.nc_id     = 0;
+self.autonan   = logical(1);
+self.autoscale = logical(0);
+
+% constants for netcdf data types
+% -------------------------------
+self.NC_BYTE             = netcdf.getConstant('NC_BYTE');    % 1
+self.NC_CHAR             = netcdf.getConstant('NC_CHAR');    % 2
+self.NC_SHORT            = netcdf.getConstant('NC_SHORT');   % 3
+self.NC_INT              = netcdf.getConstant('NC_INT');     % 4
+self.NC_LONG             = netcdf.getConstant('NC_LONG');    % 4
+self.NC_FLOAT            = netcdf.getConstant('NC_FLOAT');   % 5
+self.NC_DOUBLE           = netcdf.getConstant('NC_DOUBLE');  % 6
+
+self.NC_MEMORY           = -1;
+
+% constants for netcdf.open()
+% ---------------------------
+%self.NC_NOWRITE:	Read-only access
+self.NC_NOWRITE          = netcdf.getConstant('NC_NOWRITE');   % 0
+
+%self.NC_WRITE:      	Read-write access
+self.NC_WRITE            = netcdf.getConstant('NC_WRITE');     % 1
+
+% constants for netcdf.create()
+% -----------------------------
+self.NC_CLOBBER          = netcdf.getConstant('NC_CLOBBER');   % 0
+
+%self.NC_NOCLOBBER:    Prevent overwriting of existing file with the same name.
+self.NC_NOCLOBBER        = netcdf.getConstant('NC_NOCLOBBER'); % 4
+
+%self.NC_SHARE:	       Allow synchronous file updates.
+self.NC_SHARE            = netcdf.getConstant('NC_SHARE');     % 2048
+
+%self.NC_64BIT_OFFSET: Allow easier creation of files and variables which
+%                  are larger than two gigabytes.
+self.NC_64BIT_OFFSET     = netcdf.getConstant('NC_64BIT_OFFSET');  % 512
+
+self.NC_ERR             = netcdf.getConstant('NC2_ERR');      % -1
+self.NC_EBADDIM          = netcdf.getConstant('NC_EBADDIM');
+self.NC_EBADID           = netcdf.getConstant('NC_EBADID');
+self.NC_EBADNAME         = netcdf.getConstant('NC_EBADNAME');
+self.NC_EBADTYPE         = netcdf.getConstant('NC_EBADTYPE');
+self.NC_ECHAR            = netcdf.getConstant('NC_ECHAR');
+self.NC_EDIMSIZE         = netcdf.getConstant('NC_EDIMSIZE');
+self.NC_EEDGE            = netcdf.getConstant('NC_EEDGE');
+self.NC_EEXIST           = netcdf.getConstant('NC_EEXIST');
+self.NC_EGLOBAL          = netcdf.getConstant('NC_EGLOBAL');
+self.NC_EINDEFINE        = netcdf.getConstant('NC_EINDEFINE');
+self.NC_EINVAL           = netcdf.getConstant('NC_EINVAL');
+self.NC_EINVALCOORDS     = netcdf.getConstant('NC_EINVALCOORDS');
+self.NC_EMAXATTS         = netcdf.getConstant('NC_EMAXATTS');
+self.NC_EMAXDIMS         = netcdf.getConstant('NC_EMAXDIMS');
+self.NC_EMAXNAME         = netcdf.getConstant('NC_EMAXNAME');
+self.NC_EMAXVARS         = netcdf.getConstant('NC_EMAXVARS');
+self.NC_ENAMEINUSE       = netcdf.getConstant('NC_ENAMEINUSE');
+self.NC_ENFILE           = netcdf.getConstant('NC_ENFILE');
+self.NC_ENOMEM           = netcdf.getConstant('NC_ENOMEM');
+self.NC_ENORECVARS       = netcdf.getConstant('NC_ENORECVARS');
+self.NC_ENOTATT          = netcdf.getConstant('NC_ENOTATT');
+self.NC_ENOTINDEFINE     = netcdf.getConstant('NC_ENOTINDEFINE');
+self.NC_ENOTNC           = netcdf.getConstant('NC_ENOTNC');
+self.NC_ENOTVAR          = netcdf.getConstant('NC_ENOTVAR');
+self.NC_EPERM            = netcdf.getConstant('NC_EPERM');
+self.NC_ERANGE           = netcdf.getConstant('NC_ERANGE');
+self.NC_ESTRIDE          = netcdf.getConstant('NC_ESTRIDE');
+self.NC_ESTS             = netcdf.getConstant('NC_ESTS');
+self.NC_ETRUNC           = netcdf.getConstant('NC_ETRUNC');
+self.NC_EUNLIMIT         = netcdf.getConstant('NC_EUNLIMIT');
+self.NC_EUNLIMPOS        = netcdf.getConstant('NC_EUNLIMPOS');
+self.NC_EVARSIZE         = netcdf.getConstant('NC_EVARSIZE');
+self.NC_FATAL            = netcdf.getConstant('NC_FATAL');       % 1
+self.NC_FILL             = netcdf.getConstant('NC_FILL');        % 0
+self.NC_FILL_BYTE        = netcdf.getConstant('NC_FILL_BYTE');   % -127
+self.NC_FILL_CHAR        = netcdf.getConstant('NC_FILL_CHAR');   % 0
+self.NC_FILL_DOUBLE      = netcdf.getConstant('NC_FILL_DOUBLE'); % 9.9692e+036
+self.NC_FILL_FLOAT       = netcdf.getConstant('NC_FILL_FLOAT');  % 9.9692e+036
+self.NC_FILL_INT         = netcdf.getConstant('NC_FILL_INT');    % -2.1475e+009
+self.NC_FILL_SHORT       = netcdf.getConstant('NC_FILL_SHORT');  % -32767
+self.NC_FORMAT_64BIT     = netcdf.getConstant('NC_FORMAT_64BIT');   % 2
+self.NC_FORMAT_CLASSIC   = netcdf.getConstant('NC_FORMAT_CLASSIC'); % 1
+self.NC_GLOBAL           = netcdf.getConstant('NC_GLOBAL');       % -1
+self.NC_LOCK             = netcdf.getConstant('NC_LOCK');         % 1024
+self.NC_MAX_ATTRS        = netcdf.getConstant('NC_MAX_ATTRS');    % 8192
+self.NC_MAX_DIMS         = netcdf.getConstant('NC_MAX_DIMS');     % 1024
+self.NC_MAX_NAME         = netcdf.getConstant('NC_MAX_NAME');     % 256
+self.NC_MAX_VARS         = netcdf.getConstant('NC_MAX_VARS');     % 8192
+self.NC_MAX_VAR_DIMS     = netcdf.getConstant('NC_MAX_VAR_DIMS'); % 1024
+self.NC_NAT              = netcdf.getConstant('NC_NAT');          % 0
+self.NC_NOERR            = netcdf.getConstant('NC_NOERR');        % 0
+self.NC_NOFILL           = netcdf.getConstant('NC_NOFILL');       % 256
+self.NC_SIZEHINT_DEFAULT = netcdf.getConstant('NC_SIZEHINT_DEFAULT');  % 0
+self.NC_UNLIMITED        = netcdf.getConstant('NC_UNLIMITED');    % 0
+self.NC_VERBOSE          = netcdf.getConstant('NC_VERBOSE');      % 2
+
+% bless class
+% -----------
+self = class(self, 'netcdf_native', d);
+
+% call private function following mode state
+% a revoir !!!!!!!!!!!!!!!
+% ------------------------------------------
+switch self.mode
+  case 'NC_NOWRITE'     % NOWRITE mode
+    [self] = read(self, true);
+  case 'NC_WRITE'     % READ/WRITE mode
+    self = put(self,'DIMENSIONS', hashtable);
+    self = put(self,'VARIABLES',  hashtable);
+    self = put(self,'ATTRIBUTES', hashtable);
+  case 'NC_NOCLOBBER'     % NOCLOBBER mode
+  case 'NC_CLOBBER'     % NOCLOBBER mode
+    self = put(self,'DIMENSIONS', hashtable);
+    self = put(self,'VARIABLES',  hashtable);
+    self = put(self,'ATTRIBUTES', hashtable);
+    %         case self.NC_SHARE  % SHARE mode
+    %           % not implemeted
+  case 'NC_64BIT_OFFSET'
+    %           %
+  case 'DYNALOAD'
+    %           %
+  case 'MEMORY'
+    self = put(self,'DIMENSIONS', hashtable);
+    self = put(self,'VARIABLES',  hashtable);
+    self = put(self,'ATTRIBUTES', hashtable);
+  otherwise
+    error('Wrong mode argument');
+end
+
+
+
+
diff --git a/@netcdf_native/private/read.m b/@netcdf_native/private/read.m
new file mode 100644
index 0000000000000000000000000000000000000000..81e0990d42d4f42beb223a9376c1dc836a486475
--- /dev/null
+++ b/@netcdf_native/private/read.m
@@ -0,0 +1,263 @@
+function self = read(self, varargin)
+%
+%varargin{1} ........... waitbar (boolean)
+%
+% $Id$
+
+% no waitbar per default
+% ----------------------
+wbool = false;
+
+% check varargin
+% --------------
+if nargin > 1
+  if varargin{1}
+    wbool = true;
+  end
+end
+
+% check file validity
+% -------------------
+self.nc_id = netcdf.open(self.file, self.mode);
+if self.nc_id == -1
+  error(['netcdf:netcdf', ...
+    'The specified data file ''%s'' does not exist\n' ...
+    'or is not in the directory which is on the MATLAB path'],...
+    self.file);
+end
+
+% update waitbar title with Tex mode disable
+% ------------------------------------------
+if wbool
+  %set(0,'DefaulttextInterpreter','none')
+  wb = waitbar(0, ['Loading file.  Please  wait...']);
+  hchild = get(wb,'children');
+  htitle = get(hchild,'title');
+  set(htitle,'Interpreter','None');
+end
+
+% create a temporary hashtable use to store data read in file
+% -----------------------------------------------------------
+hash = hashtable;
+
+% returns the number of dimensions, variables, global attributes and
+% eventually unlimited dimension in a netCDF file.
+% ------------------------------------------------------------------
+[n_dims, nvars, ngatts, unlimdimid] = netcdf.inq(self.nc_id);
+
+% get dimensions and store to netcdf hashtable
+% --------------------------------------------
+for dimid = 0:n_dims-1
+  
+  % initialize empty structure
+  % --------------------------
+  s = [];
+  
+  % Get name and length of id dimension
+  % -------------------------------------
+  [dimname, dimlen] = netcdf.inqDim(self.nc_id, dimid);
+  
+  % Get dimid (dimension id) from name
+  % normalement pas besoin, a verifier....
+  % ----------------------------------
+  %dimid = netcdf.inqDimId(self.nc_id, dimname);
+  
+  % fill dimension structure with name and boolean for unlimdimid
+  % -------------------------------------------------------------
+  s.dimlen = dimlen;
+  if(dimid == unlimdimid)
+    s.unlimited = true;
+  else
+    s.unlimited = false;
+  end
+  
+  % put dimension name and length to temporary hashtable
+  % ----------------------------------------------------
+  hash = put(hash, dimname, s);
+end
+
+% put dimensions hashtable to netcdf hashtable
+% --------------------------------------------
+self = put(self, 'DIMENSIONS', hash);
+
+% clear temporary hashtable for next use
+% --------------------------------------
+hash = clear(hash);
+% bug (TODO), on ne peut pas utiliser hash = hash.clear !!!!
+% 09/03/2009: ce n'est pas un bug, voir subsref de hashtable
+
+% get variables and store to netcdf hashtable
+% -------------------------------------------
+for id = 0:nvars-1
+  
+  % moves the waitbar cursor
+  % ------------------------
+  if wbool
+    waitbar( id/nvars, wb);
+  end
+  
+  % initialize empty structure
+  % --------------------------
+  s = [];
+  
+  % return information about variable
+  % ---------------------------------
+  [varName, xtype, dimids, natts] = netcdf.inqVar(self.nc_id, id);
+  
+  % fill structure s with variable attribute names and values
+  % ---------------------------------------------------------
+  for attid = 0:natts-1
+    
+    % get attribute name
+    % ------------------
+    attName = netcdf.inqAttName(self.nc_id, id, attid);
+    
+    % if attribute name is '_FillValue', transforme to 'FillValue,
+    % because Matlab dosn't handle member name begining with '_'
+    % ------------------------------------------------------------
+    if strcmp(attName, '_FillValue')
+      s.('FillValue_') = netcdf.getAtt(self.nc_id, id, attName);
+      
+    else
+      
+      % otherwise, dynamically fill attribute member of structure s
+      % with it's value
+      % -----------------------------------------------------------
+      s.(attName) = netcdf.getAtt(self.nc_id, id, attName);
+    end
+    
+  end  % end for loop over variable attributes
+  
+  % add internal type__ member from xtype 2->char, 6->double
+  % --------------------------------------------------------
+  s.type__ = getConstantNames(self, xtype);
+  
+  % fill temporary structure s with value
+  % -------------------------------------
+  s.data__ = netcdf.getVar(self.nc_id, id);
+  
+  % If a NetCDF variable has valid scale_factor and add_offset
+  % attributes, then the data is scaled accordingly.
+  % ----------------------------------------------------------
+  if self.autoscale
+    if isfield(s, 'scale_factor') && isfield(s, 'add_offset')
+      s.data__ = s.data__ * s.scale_factor + s.add_offset;
+    end
+  end
+  
+  % replace FillValue_ by NaN only for numeric variable
+  % autonan mode is set to true by default
+  % ---------------------------------------------------
+  if self.autonan && isfield(s, 'FillValue_')
+    switch(xtype)
+      case self.NC_CHAR
+        % For now, do nothing.
+        
+      case { self.NC_DOUBLE, self.NC_FLOAT, self.NC_LONG,...
+          self.NC_SHORT, self.NC_BYTE }
+        
+        % sometimes, FillValue could be a char a badformed netcdf
+        % files
+        % --------------------------------------------------------
+        if isnumeric(s.('FillValue_'))
+          s.data__(s.data__ == s.('FillValue_')) = NaN;
+        else
+          s.data__(s.data__ == str2double(s.('FillValue_'))) = NaN;
+          
+          % verrue, pour les fichiers Roscop netcdf mal formés
+          % --------------------------------------------------
+          if str2double(s.('FillValue_')) > 1e35
+            s.data__(s.data__ >= 1e35) = NaN;
+          end
+        end
+        
+      otherwise
+        error( 'unhandled datatype %d\n', xtype );
+    end
+  end
+  
+  % if var is char and as vertical alignment, transpose it
+  % ------------------------------------------------------
+  %         if xtype == self.NC_CHAR && (size(s.data__, 1) ~= 1)
+  %           s.data__ = s.data__';
+  %         end
+  
+  % add internal dimension__ member
+  % Because MATLAB uses FORTRAN-style ordering, however, the order of
+  % the dimension IDs is reversed relative to what would be obtained
+  % from the C API
+  % ----------------------------
+  if length(dimids) > 1
+    s.data__ = permute(s.data__, fliplr(1:length(dimids)));
+    dimids = fliplr(dimids);
+  end
+  
+  
+  for dimid = 1:numel(dimids)
+    dimname = netcdf.inqDim(self.nc_id, dimids(dimid));
+    
+    % we need to reverse dimid
+    % a verifier imperativement avec plusieurs dimensions
+    % ---------------------------------------
+    s.dimension__{dimid} = dimname;
+  end
+  
+  % put variable name and value to temporary hashtable
+  % --------------------------------------------------
+  hash = put(hash, varName, s);
+  
+end
+
+
+% put variable temporary hash to netcdf hashtable
+% -----------------------------------------------
+self = put(self, 'VARIABLES', hash);
+
+% clear temporary hashtable for next use
+% --------------------------------------
+hash = clear(hash);
+
+% get gloabal attributes and store to netcdf hashtable
+% -----------------------------------------------------
+for id = 0:ngatts-1
+  
+  % initialize empty structure
+  % --------------------------
+  s = [];
+  
+  % Get the name of the global attribute associated with the
+  % variable.
+  % --------------------------------------------------------
+  gattName = netcdf.inqAttName(self.nc_id, ...
+    self.NC_GLOBAL, id);
+  
+  % Get value of global attribute.
+  % ------------------------------
+  attVal = netcdf.getAtt(self.nc_id, ...
+    self.NC_GLOBAL, gattName);
+  
+  % fill global attribute structure
+  % -------------------------------
+  s.key__  = gattName;
+  s.data__ = attVal;
+  
+  % put attribute name and value to temporary hashtable
+  % ---------------------------------------------------
+  hash = put(hash, gattName, s);
+end
+
+% put attribute temporary hash to netcdf hashtable
+% ------------------------------------------------
+self = put(self, 'ATTRIBUTES', hash);
+
+% Close waitbar
+% -------------
+if wbool
+  close(wb)
+end
+
+% close netcdf file
+% -----------------
+netcdf.close(self.nc_id)
+
+end % end of read function
\ No newline at end of file
diff --git a/@netcdf_native/save.m b/@netcdf_native/save.m
new file mode 100644
index 0000000000000000000000000000000000000000..d37b0c41ce516b8d320b1cde7c7acbbb8dcb7bb4
--- /dev/null
+++ b/@netcdf_native/save.m
@@ -0,0 +1,7 @@
+function save(self, varargin)
+% netcdf.save
+% it's a wrapper on netcdf write method
+%
+% $Id$
+
+write(self, varargin);
diff --git a/@netcdf_native/set.m b/@netcdf_native/set.m
new file mode 100644
index 0000000000000000000000000000000000000000..2152847232096ab31a6f5797de60e2384ff687b2
--- /dev/null
+++ b/@netcdf_native/set.m
@@ -0,0 +1,26 @@
+function self = set( self, varargin )
+
+% modifier set pour modifier plusieurs propriete
+% (voir doc Programing Matlab, page 8-41)
+
+if nargin == 3
+  prop  = varargin{1};
+  value = varargin{2};
+  
+  switch prop
+    
+    case 'file'
+      self.file = value;
+    case 'mode'
+      self.mode = value;
+    case 'nc_id'
+      self.nc_id = value;
+    case 'autonan'
+      self.autonan = value;
+    case 'autoscale'
+      self.autoscale = value;
+   otherwise
+      error('Unrecognized property name ''%s''.', prop); 
+  end
+  
+end
\ No newline at end of file
diff --git a/@netcdf_native/subsasgn.m b/@netcdf_native/subsasgn.m
new file mode 100644
index 0000000000000000000000000000000000000000..3e14aa67fb301173f645b88e33a4776795b4d336
--- /dev/null
+++ b/@netcdf_native/subsasgn.m
@@ -0,0 +1,49 @@
+function self = subsasgn(self, s, val)
+% Subscripted assignment for object Hashtable
+% -------------------------------------------
+
+% see help for subsasgn
+% ---------------------
+switch (length(s))
+  case 3
+    switch s(3).type
+      case '.'
+        h = get(self.dynaload, s(1).subs);
+        t = get(h, s(2).subs);
+        t.(s(3).subs) = val;
+        h = put(h, s(2).subs, t);
+        self = put(self, s(1).subs, h);
+      otherwise
+        error('Invalid type.')
+    end
+  case 2
+    switch s(1).type
+      case '.'
+        if isstruct(val)
+          h = get(self.dynaload, s(1).subs);
+          h = put(h, s(2).subs, val);
+          self = put(self, s(1).subs, h);
+        else
+          error('value must be a structure');
+        end
+      otherwise
+        error('Invalid type.')
+    end
+  case 1
+    switch s.type
+      case '()'
+        if (length(s.subs) ~= 1)
+          error('Only single indexing is supported.');
+        end
+        self = put(self, s.subs{1}, val);
+      case '.'
+        switch s.subs
+          case {'autonan', 'autoscale'  }       
+            builtin('subsasgn', self, s, val);
+          otherwise
+            self = put(self, s.subs, val);
+        end
+      otherwise
+        error('Invalid type.')
+    end
+end
diff --git a/@netcdf_native/subsref.m b/@netcdf_native/subsref.m
new file mode 100644
index 0000000000000000000000000000000000000000..cab086abcc1f7951840c5c403f06a13abdfae2c8
--- /dev/null
+++ b/@netcdf_native/subsref.m
@@ -0,0 +1,41 @@
+function val = subsref(self, s)
+% overloading subscripted reference for objects
+% Dot Notation vs. Function Notation
+%
+% MATLAB classes support both function and dot notation syntax for calling methods. 
+% For example, if write is a method of the class of object nc, then calling 
+% write with function notation would be:
+%
+% nc = write(nc, 'mode');
+%
+% The equivalent method call using dot notation is:
+%
+% nc = nc.write('mode')
+%
+% However, in certain cases, the results for dot notation can differ with respect 
+% to how MATLAB dispatching works:
+%
+%   If there is an overloaded subsref, it is invoked whenever using dot-notation. 
+%   That is, the statement is first tested to see if it is subscripted assignment.
+%
+%   If there is no overloaded subsref, then setColor must be a method of X.
+%   An ordinary function or a class constructor is never called using this notation.
+%
+% $Id: subsref.m 411 2009-07-23 16:26:40Z jgrelet $
+
+% see help from substruct and subsref
+% -----------------------------------
+switch s(1).type
+  case '.'
+    switch s(1).subs
+      case {'write', 'save'}
+        builtin('subsref', self, s);
+      case {'autonan','autoscale'}
+        val = builtin('subsref', self, s);   
+      otherwise
+        
+        % call dynaload subsref
+        % ---------------------
+        val = subsref(self.dynaload, s);
+    end
+end
diff --git a/@netcdf/tsgqc_netcdf.csv b/@netcdf_native/tsgqc_netcdf.csv
similarity index 92%
rename from @netcdf/tsgqc_netcdf.csv
rename to @netcdf_native/tsgqc_netcdf.csv
index 9651b0902ae2da4939e20e428ad2aa90b72b8ea0..4f6a7a52b6b189554d7277e08ce165a6b2ef2079 100644
--- a/@netcdf/tsgqc_netcdf.csv
+++ b/@netcdf_native/tsgqc_netcdf.csv
@@ -3,7 +3,7 @@
 %
 %
 $DIMENSIONS$
-#;key__;value;unlimited;#
+#;key__;dimlen;unlimited;#
 #;char;integer;logical;#
 #;DAYD;;0;#
 #;DAYD_EXT;;0;#
@@ -36,18 +36,18 @@ $VARIABLES$
 #;CNDC_CAL;'DAYD';float;CONDUCTIVITY CALIBRATED;sea_water_electrical_conductivity;S/meter;;0;7;%6.3f;99999;;;0.001;Conductivity calibrated using linearization coefficient;;DAYD;#
 #;CNDC_FREQ;'DAYD';float;SENSOR CONDUCTIVITY FREQUENCY;;hz;;0;20000;%9.3f;99999;;;0.001;Sensor conductivity frequency measured by TSG;;DAYD;#
 #;CNDC_CALCOEF;'NCOEF_CAL';double;CONDUCTIVITY CALIBRATION COEFFICIENTS;;;;;;;99999;;;;Calibration coefficients are real value, date is in julian day from REFERENCE_DATE_TIME;;;#
-#;CNDC_CALCOEF_CONV;'NCOEF_CAL','STRING8';char;CONDUCTIVITY CALIBRATION COEFFICIENTS CONVENTION;;;;;;;NaN;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','a','b','c','d','f0';;;#
+#;CNDC_CALCOEF_CONV;'NCOEF_CAL','STRING8';char;CONDUCTIVITY CALIBRATION COEFFICIENTS CONVENTION;;;;;;;;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','a','b','c','d','f0';;;#
 #;CNDC_LINCOEF;'NCOEF_LIN';double;CONDUCTIVITY LINEAR DRIFT CORRECTION COEFFICIENTS;;;;;;;99999;;;;Calibration coefficients are real value, date is in julian day from REFERENCE_DATE_TIME;;;#
-#;CNDC_LINCOEF_CONV;'NCOEF_LIN','STRING8';char;CONDUCTIVITY LINEAR DRIFT CORRECTION COEFFICIENTS CONVENTION;;;;;;;NaN;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','offset','slope';;;#
+#;CNDC_LINCOEF_CONV;'NCOEF_LIN','STRING8';char;CONDUCTIVITY LINEAR DRIFT CORRECTION COEFFICIENTS CONVENTION;;;;;;;;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','offset','slope';;;#
 #;SSJT;'DAYD';float;WATER JACKET TEMPERATURE;;degree_Celsius;;-1.5;38;%6.3f;99999;;;0.001;Temperature within TSG or (Water Jacket Temperature). Warning, this is not ocean SST temperature. Is is used for salinity computation. The reduction applied is the same as for conductivity. Temperature is ITS-90;;DAYD;#
 #;SSJT_QC;'DAYD';byte;WATER JACKET TEMPERATURE QUALITY FLAG;;;;0;9;%1d;;;;;Quality flag applied on water jacket temperature values;0;DAYD;#
 #;SSJT_STD;'DAYD';float;WATER JACKET TEMPERATURE STANDARD DEVIATION;;degree_Celsius;;-1.5;38;%6.3f;99999;;;0.001;Water jacket temperature standard deviation for data wich have been reduced (with a mean or median);;DAYD;#
 #;SSJT_CAL;'DAYD';float;WATER JACKET TEMPERATURE CALIBRATED;;degree_Celsius;;-1.5;38;%6.3f;99999;;;0.001;Water jacket temperature calibrated using linearization coefficients;;DAYD;#
 #;SSJT_FREQ;'DAYD';float;WATER JACKET SENSOR TEMPERATURE FREQUENCY;;hz;;0;20000;%9.3f;99999;;;0.001;Frequency of water jacket temperature sensor ;;DAYD;#
 #;SSJT_CALCOEF;'NCOEF_CAL';double;TEMPERATURE CALIBRATION COEFFICIENTS;;;;;;;99999;;;;Calibration coefficients are real value, date is in julian day from REFERENCE_DATE_TIME;;;#
-#;SSJT_CALCOEF_CONV;'NCOEF_CAL','STRING8';char;TEMPERATURE CALIBRATION COEFFICIENTS CONVENTION;;;;;;;NaN;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','a','b','c','d','f0';;;#
+#;SSJT_CALCOEF_CONV;'NCOEF_CAL','STRING8';char;TEMPERATURE CALIBRATION COEFFICIENTS CONVENTION;;;;;;;;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','a','b','c','d','f0';;;#
 #;SSJT_LINCOEF;'NCOEF_LIN';double;TEMPERATURE LINEAR DRIFT CORRECTION COEFFICIENTS;;;;;;;99999;;;;Calibration coefficients are real value, date is in julian day from REFERENCE_DATE_TIME;;;#
-#;SSJT_LINCOEF_CONV;'NCOEF_LIN','STRING8';char;TEMPERATURE LINEAR DRIFT CORRECTION COEFFICIENTS CONVENTION;;;;;;;NaN;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','offset','slope';;;#
+#;SSJT_LINCOEF_CONV;'NCOEF_LIN','STRING8';char;TEMPERATURE LINEAR DRIFT CORRECTION COEFFICIENTS CONVENTION;;;;;;;;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','offset','slope';;;#
 #;SSJT_ADJUSTED;'DAYD';float;WATER JACKET TEMPERATURE ADJUSTED;;degree_Celsius;;-1.5;38;%6.3f;99999;;;0.001;Adjusted water jacket temperature with external data (ARGO,CTD,XBT,...);;DAYD;#
 #;SSJT_ADJUSTED_ERROR;'DAYD';float;ERROR ON ADJUSTED WATER JACKET TEMPERATURE;;degree_Celsius;;-1.5;38;%6.3f;99999;;;0.001;Error on adjusted water jacket temperature with external data (ARGO,CTD, XBT,…);;DAYD;#
 #;SSJT_ADJUSTED_QC;'DAYD';byte;WATER JACKET TEMPERATURE QUALITY FLAG;;;;0;9;%1d;;;;;Quality flag applied on adjusted water jacket temperature values;0;DAYD;#
@@ -74,9 +74,9 @@ $VARIABLES$
 #;SSTP_DEPH_MIN;'N1';float;MINIMUM DEPTH OF WATER INTAKE FOR TEMPERATURE MEASUREMENT;;meter;;0;100;%6.3f;99999;;;;;;;#
 #;SSTP_DEPH_MAX;'N1';float;MAXIMUM DEPTH OF WATER INTAKE FOR TEMPERATURE MEASUREMENT;;meter;;0;100;%6.3f;99999;;;;;;;#
 #;SSTP_CALCOEF;'NCOEF_CAL';double;TEMPERATURE CALIBRATION COEFFICIENTS;;;;;;;99999;;;;Calibration coefficients are real value, date is in julian day from REFERENCE_DATE_TIME;;;#
-#;SSTP_CALCOEF_CONV;'NCOEF_CAL','STRING8';char;TEMPERATURE CALIBRATION COEFFICIENTS CONVENTION;;;;;;;NaN;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','a','b','c','d','f0';;;#
+#;SSTP_CALCOEF_CONV;'NCOEF_CAL','STRING8';char;TEMPERATURE CALIBRATION COEFFICIENTS CONVENTION;;;;;;;;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','a','b','c','d','f0';;;#
 #;SSTP_LINCOEF;'NCOEF_LIN';double;TEMPERATURE LINEAR DRIFT CORRECTION COEFFICIENTS;;;;;;;99999;;;;Calibration coefficients are real value, date is in julian day from REFERENCE_DATE_TIME;;;#
-#;SSTP_LINCOEF_CONV;'NCOEF_LIN','STRING8';char;TEMPERATURE LINEAR DRIFT CORRECTION COEFFICIENTS CONVENTION;;;;;;;NaN;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','offset','slope';;;#
+#;SSTP_LINCOEF_CONV;'NCOEF_LIN','STRING8';char;TEMPERATURE LINEAR DRIFT CORRECTION COEFFICIENTS CONVENTION;;;;;;;;;;;Calibration coefficient convention is an enumeration of coefficients name, ex: 'date','offset','slope';;;#
 #;SSTP_EXT;'DAYD_EXT';float;SEA SURFACE TEMPERATURE FROM EXTERNAL DATA;sea_surface_temperature;degree_Celsius;;-1.5;38;%6.3f;99999;;;0.001;Sea Surface Temperature (SST) from external data instrument (ARGO,CTD, XBT);;DAYD_EXT;#
 #;SSTP_EXT_QC;'DAYD_EXT';byte;SEA SURFACE TEMPERATURE FROM EXTERNAL DATA QUALITY FLAG;;;;0;9;%1d;;;;;Quality flag applied on external sea surface temperature data values;0;DAYD_EXT;#
 #;SSTP_EXT_TYPE;'DAYD_EXT','STRING4';char;TYPE OF EXTERNAL SEA SURFACE TEMPERATURE  DATA ORIGIN;;;;;;;;;;;ARGO,CTD,XBT,...;;DAYD_EXT;#
@@ -84,7 +84,7 @@ $VARIABLES$
 #;SSPS_EXT_QC;'DAYD_EXT';byte;SEA SURFACE SALINITY FROM EXTERNAL DATA QUALITY FLAG;;;;0;9;%1d;;;;;Quality flag applied on external sea surface salinity data values;0;DAYD_EXT;#
 #;SSPS_EXT_TYPE;'DAYD_EXT','STRING4';char;TYPE OF EXTERNAL SEA SURFACE SALINITY DATA ORIGIN;;;;;;;;;;;WS (Water Sample),ARGO,CTD,XBT,...;;DAYD_EXT;#
 #;SSPS_EXT_ANALDATE;'DAYD_EXT','STRING14';char;DATE OF WATER SAMPLE SURFACE SALINITY ANALYSIS;;;yyyymmddhhmmss;;;;;;;;Date of sea surface salinity water sample analysis;;DAYD_EXT;#
-#;SSPS_EXT_BOTTLE;'DAYD_EXT','STRING4';char;SEA SURFACE SALINITY BOTTLE NUMBER;;;;;;;NaN;;;;Number of sea surface salinity water sample;;DAYD_EXT;#
+#;SSPS_EXT_BOTTLE;'DAYD_EXT','STRING4';char;SEA SURFACE SALINITY BOTTLE NUMBER;;;;;;;;;;;Number of sea surface salinity water sample;;DAYD_EXT;#
 %
 $ATTRIBUTES$
 #;key__;name;conventions;uicontrolType;string;value;length;height;horizontalAlignment;comment;#
diff --git a/@netcdf_native/tsgqc_netcdf.m b/@netcdf_native/tsgqc_netcdf.m
new file mode 100644
index 0000000000000000000000000000000000000000..f71cae63b17e64d1c3891ad45c09eb44e94ba053
--- /dev/null
+++ b/@netcdf_native/tsgqc_netcdf.m
@@ -0,0 +1,5 @@
+% tsgqc_netcdf.m
+% convert Excel file to csv
+
+d = dynaload('tsgqc_netcdf.xls')
+write( d, 'tsgqc_netcdf.csv')
\ No newline at end of file
diff --git a/@netcdf/tsgqc_netcdf.xls b/@netcdf_native/tsgqc_netcdf.xls
similarity index 81%
rename from @netcdf/tsgqc_netcdf.xls
rename to @netcdf_native/tsgqc_netcdf.xls
index 1a347919a7d50ddd48ea36de9e6f20732be4eadb..6cfc733e1124ed974522220c71252f848f3541d7 100644
Binary files a/@netcdf/tsgqc_netcdf.xls and b/@netcdf_native/tsgqc_netcdf.xls differ
diff --git a/@netcdf_native/write.m b/@netcdf_native/write.m
new file mode 100644
index 0000000000000000000000000000000000000000..e723d8cc17e5b378ede94a0dd150e389dda83ceb
--- /dev/null
+++ b/@netcdf_native/write.m
@@ -0,0 +1,421 @@
+function write(self, varargin)
+% self = write(self, varargin)
+%  write method from netcdf class, create and write data to netcdf file
+%  also call by save method
+%
+% % Input
+% -----
+% self        ........... netcdf object
+% varargin{1} ........... netcdf file
+% varargin{2} ........... file mode
+% varargin{3} ........... waitbar (boolean)
+%
+% Output
+% ------
+% self        ........... netcd object
+%
+% $Id: write.m 411 2009-07-23 16:26:40Z jgrelet $
+
+%% check arguments
+% TODOS: modify and test
+% ----------------------
+wbool = false;
+self.file = char(varargin{1});
+if nargin > 2
+  self.mode = char(varargin{2});
+end
+if nargin > 3
+  if varargin{3}
+    wbool = true;
+  end
+end
+
+% get keys list of dimensions, variables and attributes from netcdf instance
+% --------------------------------------------------------------------------
+ncd_keys = keys( get(self.dynaload, 'DIMENSIONS'));
+ncv_keys = keys( get(self.dynaload, 'VARIABLES'));
+nca_keys = keys( get(self.dynaload, 'ATTRIBUTES'));
+
+% display more info about write file on console
+% ---------------------------------------------
+fprintf('\nWRITE_NETCDF_FILE\n'); tic;
+fprintf('...writing %s : ', self.file);
+
+% Initialize loading NetCDF file waitbar
+% --------------------------------------
+if wbool
+  wb = waitbar(0, 'Initializing NetCDF file. Please  wait...');
+  
+  % We cannot change title property to 'none' (default set as 'tex') inside
+  % waitbar function (line 81), see
+  % http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
+  % -----------------------------------------------------------------------
+  hchild = get(wb,'children');
+  htitle = get(hchild,'title');
+  set(htitle,'Interpreter','None');
+end
+
+%% Open or create netcdf file
+% -------------------------
+switch(self.mode)
+  case {'NC_CLOBBER'}
+    self.nc_id = netcdf.create(self.file, self.mode);
+  case 'NC_WRITE'
+    self.nc_id = netcdf.open(self.file, self.mode);
+  otherwise
+end
+
+
+%% Create NetCDF DIMENSIONS
+% -------------------------
+for i=1:numel(ncd_keys)
+  key__ = ncd_keys{i};
+  s = get(get(self.dynaload, 'DIMENSIONS'), key__);
+  %value = s.value;
+  dimlen = s.dimlen;
+  
+  % % create unlimited dimension. Any unlimited dimension is therefore last
+  % % in the list of dimension IDs in defVar function, todo below...
+  % % ---------------------------------------------------------------------
+  %   if s.unlimited
+  %     unlimDimId = netcdf.defDim(self.nc_id, key__, ...
+  %                                netcdf.getConstant('NC_UNLIMITED'));
+  %   end
+  
+  % if dimension is not set, get size from variable
+  % a faire evoluer car peu sur, et a voir pour tableaux
+  % -----------------------------------------------
+  if isempty(dimlen)
+    t = get(get(self.dynaload, 'VARIABLES'), key__);
+    if isfield(t, 'data__')
+      netcdf.defDim(self.nc_id, key__, numel(t.data__));
+    end
+  else
+    try
+      netcdf.defDim(self.nc_id, key__, dimlen);
+    catch ME
+      error('\nError: netcdf.%s (line %d), nc_id: %d, key__: %s dimlen: %d\n\tin function call: %s (%s)',...
+        ME.stack(2).name, ME.stack(2).line, self.nc_id, key__, dimlen, ME.stack(1).name, ME.message);
+    end
+  end
+  
+end
+
+% display filename after 'Interpreter','None' initialization to prevent
+% display console warning
+% ---------------------------------------------------------------------
+if wbool
+  waitbar(1/50,wb, ['Writing file: ' self.file ' Please  wait...']);
+end
+
+%% Create and write NetCDF GLOBAL ATTRIBUTES
+% -----------------------------------
+
+% get netcdf global attribute constant
+% ------------------------------------
+nga = self.NC_GLOBAL;
+%nga = netcdf.getConstant('NC_GLOBAL');
+
+for i=1:numel(nca_keys)
+  key = nca_keys{i};
+  s = get(get(self.dynaload, 'ATTRIBUTES'), key);
+  %value = s.data__;
+  if isfield(s, 'data__')
+    
+    % Create an attribute associated with the variable.
+    % -------------------------------------------------
+    try
+      netcdf.putAtt(self.nc_id, nga, key, s.data__);
+    catch ME
+      fprintf('\nError: netcdf.%s (line %d)\n\tin function call: %s (%s)',...
+        ME.stack(2).name, ME.stack(2).line, ME.stack(1).name, ME.message);
+    end
+  end
+end
+
+% Leave define mode.
+% ------------------
+netcdf.endDef(self.nc_id)
+
+
+
+%% Adds NetCDF VARIABLES
+% ----------------------
+for i=1:numel(ncv_keys)
+  
+  % Re-enter define mode.
+  % ---------------------
+  netcdf.reDef(self.nc_id);
+  
+  % initialise varstruct
+  % nc_addvar use a structure with four fields:
+  % Name
+  % Nctype
+  % Dimension
+  % Attribute is also a structure array
+  % see help nc_addvar
+  % -----------------------------------
+  %varstruct = [];
+  
+  
+  % get variable name
+  % -----------------
+  key  = ncv_keys{i};
+  
+  % display waitbar
+  % ---------------
+  if wbool
+    waitbar( i/numel(ncv_keys), wb, ['writing ' key ' variable']);
+  end
+  
+  % uncomment for debug only, display variable
+  % ------------------------------------------
+  % key
+  
+  % get structure
+  % -------------
+  s = get(get(self.dynaload, 'VARIABLES'), key);
+  
+  % get dimension(s) dimids from ncetcdf file, s.dimension is cell
+  % --------------------------------------------------------------
+  %dimids = [];
+  
+  % utiliser numel(s.dimension__) et dimids(i) pour creer le tableau des
+  % dimids
+  if ~isfield(s, 'dimension__')
+    s %#ok<NOPRT>
+    error('field dimension__ not defined in variables structure ...');
+  end
+  
+  try
+    % preallocate dimids
+    % ------------------
+    dimids = zeros(size(s.dimension__));
+    
+    % fill dimids array from dim name
+    % -------------------------------
+    for ind=1:length(dimids)
+      dimid = netcdf.inqDimID(self.nc_id, s.dimension__{ind});
+      dimids(ind) = dimid;
+    end
+    
+    % find index of unlimited dimension
+    % ---------------------------------
+    %ind = find(dimids == unlimDimId);
+    
+    % reshape dimids array with unlimited  value at the start
+    % -------------------------------------------------------
+    %     if ~isempty(ind)
+    %       dimids = [ dimids(1:ind-1), circshift(dimids(ind+1:end),[0 -1])];
+    %       dimids = [circshift(dimids(1:ind),[0 1]), dimids(ind+1:end)];
+    %     end
+    
+  catch ME
+    fprintf('\nNotice: netcdf.%s, dimension %s don''t exist or is empty',...
+      ME.stack(2).name, s.dimension__{ind});
+    
+    % Leave define mode and go to next variable (key__)
+    % -------------------------------------------------
+    netcdf.endDef(self.nc_id);
+    continue;
+  end
+  
+  % We need to flip the dimensions
+  % ------------------------------
+  dimids = fliplr(dimids);
+  %netcdf.reDef(self.nc_id);
+  
+  % create variable and get it's varid
+  % ----------------------------------
+  varid = netcdf.defVar(self.nc_id, key, s.type__, dimids);
+  
+  % dynamically reate variable attributes
+  % get structure fieldnames from hashtable
+  % ---------------------------------------
+  ncv_fieldNames  = fieldnames(s);
+  
+  % loop over fieldname (variable attributes), first is key (code)
+  % --------------------------------------------------------------
+  for j=1:numel(ncv_fieldNames)
+    
+    % get fielname and value
+    % ----------------------
+    fieldName = ncv_fieldNames{j};
+    value = s.(fieldName);
+    
+    % jump each internal fieldname (eg key__, data__, type__, dimension__)
+    % or empty fieldname
+    % -------------------------------------------------------------
+    if ~isempty(regexp(fieldName, '__$','ONCE')) || isempty(value)
+      continue;
+    end
+    
+    % change struct fieldname FillValue_ to attribute _FillValue
+    % ----------------------------------------------------------
+    if strcmp( fieldName, 'FillValue_')
+      fieldName = '_FillValue';
+    end
+    
+    % BE CARREFULL: it's an very important notice
+    % value assign to attribute _FillValue should have same type
+    % as variable, true for all numeric atribute variable
+    % ------------------------------------------------------
+    if isnumeric(value)
+      switch s.type__
+        case {'double', 'real'}
+          value = double(value);
+        case {'float', 'single'}
+          value = single(value);
+        case {'int', 'integer', 'int32'}
+          value = int32(value);
+        case {'short', 'int16'}
+          value = int16(value);
+        case {'int8'}
+          value = int8(value);
+        case {'byte', 'uint8'}
+          value = uint8(value);
+        case 'char'
+          value = char(value);
+      end
+    end
+    
+    % Write variable netCDF attribute
+    % -------------------------------
+    netcdf.putAtt(self.nc_id, varid, fieldName, value);
+    
+  end
+  
+  % Leave define mode and enter data mode to write data.
+  % -----------------------------------------------------
+  netcdf.endDef(self.nc_id);
+  
+  % if there is not data for variable or data__ empty
+  % ------------------------------------------------
+  if ~isfield(s, 'data__') || isempty(s.data__)
+    
+    % and it's missing_value attribute is set, fill data with missing_value
+    % -------------------------------------------------------------------
+    if isfield(s, 'missing_value') && ~isempty(s.missing_value)
+      
+      % get dimension id from name
+      % --------------------------
+      dimsize = numel(s.dimension__);
+      
+      % rajouter un test iscell
+      
+      % set dimids size array
+      % ----------------------
+      dimids = zeros(dimsize, 1);
+      
+      % fill dimids array with dimension(s) Id
+      % --------------------------------------
+      try
+        for dim = 1: dimsize
+          dimids(dim) = netcdf.inqDimID(self.nc_id, s.dimension__{dim});
+        end
+      catch ME
+        msg = sprintf('dimension: %s don''t exist', s.dimension__{dim});
+        fprintf('\nWarning: netcdf.%s (line %d)\n\tin function call: %s',...
+          ME.stack(2).name, ME.stack(2).line, msg);
+        continue;
+      end
+      
+      % get size of pre-allocate dimsize
+      % -------------------------------
+      dimlen = zeros(dimsize, 1);
+      
+      % get dimension name and length from it's dimid
+      % ---------------------------------------------
+      for dim = 1: dimsize
+        [dimname, dimlen(dim)] = netcdf.inqDim(self.nc_id, dimids(dim));
+      end
+      
+      % fill data with missing_value
+      % could use repmat to do that: s.data__ = repmat(1, dimlen, 1));
+      % --------------------------------------------------------------
+      if dimsize == 1
+        s.data__ = ones(dimlen,1) * s.missing_value;
+      else
+        s.data__ = ones(dimlen) * s.missing_value;
+      end
+    else
+      
+      % if variable don't have attribute missing_value, exit loop and go to
+      % next variable
+      % -------------------------------------------------------------------
+      continue;
+    end
+    
+  end
+  
+  % BE CAREFULL:
+  % cast variable with the right netcdf nctype
+  % ------------------------------------------
+  switch s.type__
+    case {'double', 'real'}
+      value = double(s.data__);
+    case {'float', 'single'}
+      value = single(s.data__);
+    case {'int', 'integer', 'int32'}
+      value = int32(s.data__);
+    case {'short', 'int16'}
+      value = int16(s.data__);
+    case {'byte', 'int8'}
+      value = int8(s.data__);
+    case 'char'
+      value = char(s.data__);
+  end
+  
+  % matlab use FORTRAN indexing (k,j,i) and lib netcdf come from C  style
+  % indexing (i,j,k)
+  % Matlab documentation is not very clear about this very important tips
+  % see:
+  % http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/matlab_prog/brrbr9v-1.html&http://www.mathworks.fr/cgi-bin/texis/webinator/search/
+  % -------------------------------------------
+  value = permute(value, fliplr(1:ndims(value)));
+  
+  % If a NetCDF variable has valid scale_factor and add_offset
+  % attributes, then the data is scaled accordingly.
+  % ----------------------------------------------------------
+  if self.autoscale
+    if isfield(s, 'scale_factor') && isfield(s, 'add_offset')
+      value = (value - s.add_offset) / s.scale_factor;
+    end
+  end
+  
+  % If a NetCDF variable has valid _FillValue attributes, then
+  % the data is filled accordingly.
+  % ----------------------------------------------------------
+  if self.autonan && isfield(s, 'FillValue_')
+    value(isnan(value)) = s.FillValue_;
+  end
+  
+  % Write data to variable.
+  % -----------------------
+  try
+    netcdf.putVar(self.nc_id, varid, value);
+  catch exception
+    fprintf('write variable error: %s', s.key__');
+    s %#ok<NOPRT>
+    fprintf('check your dynaload csv or xls file !!!\n');
+    error('Matla:netcdf.write:netcdf.putVar',...
+      'Cannot write netcdf file\n%s.', exception.message);  %#ok<CTPCT>
+    
+  end
+end % end for ncv variables loop
+
+% Close waitbar
+% -------------
+if wbool
+  close(wb)
+end
+
+% Display time to write file on console
+% -------------------------------------
+t = toc; fprintf('...done (%6.2f sec).\n\n',t);
+
+% close netcdf file
+% -----------------
+netcdf.close(self.nc_id)
+
+end % end of write function
\ No newline at end of file
diff --git a/INSTALL b/INSTALL
index e555cd5c29917cb9c54b4664d3423d5d2763b9f1..2da0be5867932bffb8cdeb92e4e1ccb4f6f3b5f4 100644
--- a/INSTALL
+++ b/INSTALL
@@ -16,16 +16,18 @@ Installation:
     http://mexcdf.sourceforge.net/downloads/
     voir lien egalement sous http://www.ird.fr/us191/spip.php?article18
  
- - Installer la toolbox NetCDF sous Matlab depuis:
+  - Pour les versions Matlab R2006b a R2008a, il faut installer la toolbox 
+    MEXNC/NetCDF depuis:
     http://mexcdf.sourceforge.net/downloads/
     voir lien egalement sous http://www.ird.fr/us191/spip.php?article18#
+
+    Pour les versions de Matlab >= R2008b, le programme utilise le support
+    natif des fichiers NetCDF disponible a partir de cette version. Il faut 
+    supprimer du path Matlab tout lien vers la toolbox mexnc
 	
-Etapes d'installation MEXNC
-	Sous Windows
-	Sous Linux
-	Installation toolbox NETCDF
 
-  - Depuis la version 1.0RC5, le format netcdf des fichiers de climato
+  - Installation des fichiers de climatologie:
+    Depuis la version 1.0RC5, le format netcdf des fichiers de climato
     a change, et une version WOA05 a ete generee. Le logiciel fonctionne
     indefferement avec les fichiers WOA01 ou WOA04 (a choisir dans le menu
     options/preference 
diff --git a/tsg_doc/CORTSG_format_gosud.doc b/tsg_doc/CORTSG_format_gosud.doc
index f75e35ed1721d5193a8f2dd67421ec55f71a4738..d50d2c21856a5fb22dbc667941129158a11aa8ee 100644
Binary files a/tsg_doc/CORTSG_format_gosud.doc and b/tsg_doc/CORTSG_format_gosud.doc differ
diff --git a/tsg_io/readTsgDataNetCDF.m b/tsg_io/readTsgDataNetCDF.m
index 324417eafe55fbd1b757d2ba98185a43b21b774b..eaf2f11d185bb3e8750b9550404bab06ad0770b8 100644
--- a/tsg_io/readTsgDataNetCDF.m
+++ b/tsg_io/readTsgDataNetCDF.m
@@ -15,119 +15,189 @@ function [error] = readTsgDataNetCDF( hMainFig, filename)
 %
 % $Id$
 
-% clear all variables in base workspace
-% -------------------------------------
-%clear all;
-
-% Get the data from the application GUI
-% -------------------------------------
-tsg = getappdata( hMainFig, 'tsg_data');
-
-% Display read file info on console
-% ---------------------------------
-fprintf('\nREAD_NETCDF_FILE\n'); tic;
-
-% Open netCDF file
-% ----------------
-nc = netcdf(filename,'read');
-if isempty(nc)
-  msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
-  warndlg( msg_error, 'NetCDF error dialog');
-  sprintf('...cannot locate %s\n', filename);
-  error = -1;
-  return;
-end
-
-% Display more info about read file on console
-% --------------------------------------------
-fprintf('...reading %s : ', filename);
-
-% populate tsg.file structure
-% ---------------------------
-[tsg.file.pathstr, tsg.file.name, tsg.file.ext, tsg.file.versn] = ...
-  fileparts(filename);
-tsg.file.type = 'NETCDF';
-
-
-% get global attributes: meta data
-% --------------------------------
-global_att = att(nc);
-
-for i=1:length(global_att)
-  
-  % extract name and value from netcdf globals attributes
-  % -----------------------------------------------------
-  attribute = name(global_att{i});
-  value     = global_att{i}(:);
-  
-  % assign globals attributes in base workspace
-  % -------------------------------------------
-  assignin('base', attribute, value);
-  
-  % populate tsg structure with globals attributes
-  % ----------------------------------------------
-  tsg.(attribute) = value;
-end
-
-% get variables describing TSG installation
-% -----------------------------------------
-variables = var(nc);
-
-for i=1:length(variables)
-
-  % extract name and value from netcdf variables
-  % --------------------------------------------
-  variable = name(variables{i});
-  %value    = variables{i}(:);
-  nv       = nc{i};
-
-  % use autonan mode, remplace fillValue with NaN
-  % ---------------------------------------------
-  nv = autonan(nv, true);
-
-  % finally replace fillvalue with NaN when only fillvalue exist
-  % ------------------------------------------------------------
-%   if ~isempty(fillval(nc{i}))
-%     value(value == fillval(nc{i})) = NaN;
-%   end
-
-  % assign netcdf variables in base workspace
-  % -----------------------------------------
-  assignin('base', variable, nv(:));
-
-  % populate tsg structure with netcdf variables
-  % --------------------------------------------
-  tsg.(variable) = nv(:);
-
-  % transforme julian days variables to Matlab datenum
-  % --------------------------------------------------
-  if strmatch('DAYD', variable)
-    tsg.(variable) = julianToDatenum(tsg.(variable));
-  end
+%% Check Netcdf library version
+% -----------------------------
+switch ( version('-release') )
+  case { '11', '12', '13', '14', '2006a', '2006b', '2007a', '2007b', '2008a' }
+    read_netcdf_toolbox;
+  otherwise
+    read_netcdf_native;
 end
 
-% Keep somme information for the log file
-% ---------------------------------------
-tsg.report.tsgfile = filename;
-
-% Save the data in the application GUI
-% ------------------------------------
-setappdata( hMainFig, 'tsg_data', tsg );
-
 % Perform somme automatic tests
 % -----------------------------
 automaticQC( hMainFig )
 
-% Close the file
-% --------------
-close(nc);
-
-% Display time to read file on console
-% ------------------------------------
-t = toc; fprintf('...done (%5.2f sec).\n\n',t);
 
-% Everything OK
-% -------------
-error = 1;
-
-end
+%% Nested functions
+% -----------------
+
+% use Charles Dunham toolbox
+% --------------------------
+  function read_netcdf_toolbox
+    
+    % Get the data from the application GUI
+    % -------------------------------------
+    tsg = getappdata( hMainFig, 'tsg_data');
+    
+    % Display read file info on console
+    % ---------------------------------
+    fprintf('\nREAD_NETCDF_FILE\n'); tic;
+    
+    % Open netCDF file
+    % ----------------
+    nc = netcdf(filename,'read');
+    if isempty(nc)
+      msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
+      warndlg( msg_error, 'NetCDF error dialog');
+      sprintf('...cannot locate %s\n', filename);
+      error = -1;
+      return;
+    end
+    
+    % Display more info about read file on console
+    % --------------------------------------------
+    fprintf('...reading %s : ', filename);
+    
+    % populate tsg.file structure
+    % ---------------------------
+    [tsg.file.pathstr, tsg.file.name, tsg.file.ext, tsg.file.versn] = ...
+      fileparts(filename);
+    tsg.file.type = 'NETCDF';
+    
+    % get global attributes: meta data
+    % --------------------------------
+    global_att = att(nc);
+    
+    for i=1:length(global_att)
+      
+      % extract name and value from netcdf globals attributes
+      % -----------------------------------------------------
+      attribute = name(global_att{i});
+      value     = global_att{i}(:);
+      
+      % assign globals attributes in base workspace
+      % -------------------------------------------
+      assignin('base', attribute, value);
+      
+      % populate tsg structure with globals attributes
+      % ----------------------------------------------
+      tsg.(attribute) = value;
+    end
+    
+    % get variables describing TSG installation
+    % -----------------------------------------
+    variables = var(nc);
+    
+    for i=1:length(variables)
+      
+      % extract name and value from netcdf variables
+      % --------------------------------------------
+      variable = name(variables{i});
+      %value    = variables{i}(:);
+      nv       = nc{i};
+      
+      % use autonan mode, remplace fillValue with NaN
+      % ---------------------------------------------
+      nv = autonan(nv, true);
+      
+      % finally replace fillvalue with NaN when only fillvalue exist
+      % ------------------------------------------------------------
+      %   if ~isempty(fillval(nc{i}))
+      %     value(value == fillval(nc{i})) = NaN;
+      %   end
+      
+      % assign netcdf variables in base workspace
+      % -----------------------------------------
+      assignin('base', variable, nv(:));
+      
+      % populate tsg structure with netcdf variables
+      % --------------------------------------------
+      tsg.(variable) = nv(:);
+      
+      % transforme julian days variables to Matlab datenum
+      % --------------------------------------------------
+      if strmatch('DAYD', variable)
+        tsg.(variable) = julianToDatenum(tsg.(variable));
+      end
+    end
+    
+    % Keep somme information for the log file
+    % ---------------------------------------
+    tsg.report.tsgfile = filename;
+    
+    % Save the data in the application GUI
+    % ------------------------------------
+    setappdata( hMainFig, 'tsg_data', tsg );
+    
+    % Close the file
+    % --------------
+    close(nc);
+    
+    % Display time to read file on console
+    % ------------------------------------
+    t = toc; fprintf('...done (%5.2f sec).\n\n',t);
+    
+    % Everything OK
+    % -------------
+    error = 1;
+    
+  end % end of read_netcdf_toolbox
+
+% use native toolbox +netcdf since R2008b
+% ---------------------------------------
+  function read_netcdf_native
+    
+    % Get the data from the application GUI
+    % -------------------------------------
+    tsg = getappdata( hMainFig, 'tsg_data');
+    
+    % Display read file info on console
+    % ---------------------------------
+    fprintf('\nREAD_NETCDF_FILE\n'); tic;
+    
+    % populate tsg.file structure
+    % ---------------------------
+    [tsg.file.pathstr, tsg.file.name, tsg.file.ext, tsg.file.versn] = ...
+      fileparts(filename);
+    tsg.file.type = 'NETCDF';
+    
+    % Open netCDF file
+    % ----------------
+    nc = netcdf_native(filename);
+    
+    % loop over all variables and get associated value in tsg structure
+    % -----------------------------------------------------------------
+    for key = keys(nc.VARIABLES)
+      var = char(key);
+      tsg.(var) = nc.VARIABLES.(var).data__;
+    end
+    
+    % loop over all gloabal attributes and get associated value in
+    % tsg structure
+    % -----------------------------------------------------------------
+    for key = keys(nc.ATTRIBUTES)
+      att = char(key);
+      tsg.(att) = nc.ATTRIBUTES.(att).data__;
+    end
+    
+    % Save the data in the application GUI
+    % ------------------------------------
+    setappdata( hMainFig, 'tsg_data', tsg );
+    
+    
+    % Close the file
+    % --------------
+    %close(nc);
+    
+    % Display time to read file on console
+    % ------------------------------------
+    t = toc; fprintf('...done (%5.2f sec).\n\n',t);
+    
+    % Everything OK
+    % -------------
+    error = 1;
+    
+  end % end of read_netcdf_native
+
+end % end of readTsgDataNetCDF
diff --git a/tsg_io/read_file_woa.m b/tsg_io/read_file_woa.m
index 569af21060908c752e6281f4d11a8f17ea8ba5cc..b8ce62cd56cf873d579f28ddbb0f96022e50acd1 100644
--- a/tsg_io/read_file_woa.m
+++ b/tsg_io/read_file_woa.m
@@ -7,98 +7,135 @@ function levitus = read_file_woa(file)
 % check for file existence
 % ------------------------
 filesfound = checkforfiles( file );
-if filesfound == 0; 
-   warning(['Couldn''t find ', file]);
-   levitus = -1;
-   return;
+if filesfound == 0;
+  warning(['Couldn''t find ', file]);
+  levitus = -1;
+  return;
 end
 
-% il existe un "bug" dans netcdf ligne 409, ncitem retourne une
-% erreur dans la variable result
-
-% open file in read mode
-% ----------------------
-nc = netcdf(which(file), 'nowrite');
-
-% Initialise la waitbar de chargement du fichier netCDF
-% -----------------------------------------------------
-%wb = waitbar(0,'');
-
-% We cannot change title property to 'none' (default set as 'tex') inside
-% waitbar function (line 81), see
-% http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
-% -----------------------------------------------------------------------
-% hchild = get(wb,'children');
-% htitle = get(hchild,'title');
-% set(htitle,'Interpreter','None');
-% ('none' as opposed to 'latex') to leave underscores as underscores
-set(0,'DefaulttextInterpreter','none')
-
-
-% update waitbar title with Tex mode disable
-% ------------------------------------------
-wb = waitbar(0, ['Loading file: ' file ' Please  wait...']);
-
-% loop for every variable
-% -----------------------
-for i = 1:length(var(nc))
-  
-  % first initialize the dimensions of the data array, this is due to a bug
-  % (?) in netcdf toolbox, with an array [1,1,n,m], netcdf operator (:)
-  % return only [n,m]. This is true for surface climatology file !!!!!
-  % -------------------------------------------------------------------
-  data = zeros(size(nc{i}));
-  
-  % return current variable (object)
-  % --------------------------------
-  nv = nc{i};
-  
-  % use autonan mode on this variable (object), remplace fillValue with NaN
-  % -----------------------------------------------------------------------
-  nv = autonan(nv, true);
-  
-  % then fill with values, we use a temporary object data, because nv
-  % is an netcdf object, see line 75
-  % -----------------------------------------------------------------
-  data(:) = nv(:);
-  
-  % other Matlab way to replace fillValue by NaN
-  % --------------------------------------------
-  %   if ~isempty(fillval(nc{i}))
-  %     data(data == fillval(nc{i})) = NaN;
-  %   end
-  
-  % assign dynamically variable in structure levitus
-  % ------------------------------------------------
-  % be carreful !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-  % don't use data(:) ... 
-  % whem data dimensions are [1,1,m,n]
-  % [m,n]     = data(:) 
-  % [1,1,m,n] = data
-  % ------------------------------------------------
-  levitus.(name(nv)) = data;
-  
-  % moves the waitbar cursor 
-  % ------------------------
-  waitbar( i/length(nv), wb);
-  
+%% Check Netcdf library version
+% -----------------------------
+switch ( version('-release') )
+  case { '11', '12', '13', '14', '2006a', '2006b', '2007a', '2007b', '2008a' }
+    read_netcdf_toolbox;
+  otherwise
+    read_netcdf_native;
 end
 
-% close waitbar
-% -------------
-close(wb);
 
-% close netcdf file
+%% Nested functions
 % -----------------
-close(nc);
 
+% use Charles Dunham toolbox
+% --------------------------
+  function read_netcdf_toolbox
+    % il existe un "bug" dans netcdf ligne 409, ncitem retourne une
+    % erreur dans la variable result
+    
+    % open file in read mode
+    % ----------------------
+    nc = netcdf(which(file), 'nowrite');
+    
+    % Initialise la waitbar de chargement du fichier netCDF
+    % -----------------------------------------------------
+    %wb = waitbar(0,'');
+    
+    % We cannot change title property to 'none' (default set as 'tex') inside
+    % waitbar function (line 81), see
+    % http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
+    % -----------------------------------------------------------------------
+    % hchild = get(wb,'children');
+    % htitle = get(hchild,'title');
+    % set(htitle,'Interpreter','None');
+    % ('none' as opposed to 'latex') to leave underscores as underscores
+    set(0,'DefaulttextInterpreter','none')
+    
+    
+    % update waitbar title with Tex mode disable
+    % ------------------------------------------
+    wb = waitbar(0, ['Loading file: ' file ' Please  wait...']);
+    
+    % loop for every variable
+    % -----------------------
+    for i = 1:length(var(nc))
+      
+      % first initialize the dimensions of the data array, this is due to a bug
+      % (?) in netcdf toolbox, with an array [1,1,n,m], netcdf operator (:)
+      % return only [n,m]. This is true for surface climatology file !!!!!
+      % -------------------------------------------------------------------
+      data = zeros(size(nc{i}));
+      
+      % return current variable (object)
+      % --------------------------------
+      nv = nc{i};
+      
+      % use autonan mode on this variable (object), remplace fillValue with NaN
+      % -----------------------------------------------------------------------
+      nv = autonan(nv, true);
+      
+      % then fill with values, we use a temporary object data, because nv
+      % is an netcdf object, see line 75
+      % -----------------------------------------------------------------
+      data(:) = nv(:);
+      
+      % other Matlab way to replace fillValue by NaN
+      % --------------------------------------------
+      %   if ~isempty(fillval(nc{i}))
+      %     data(data == fillval(nc{i})) = NaN;
+      %   end
+      
+      % assign dynamically variable in structure levitus
+      % ------------------------------------------------
+      % be carreful !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+      % don't use data(:) ...
+      % whem data dimensions are [1,1,m,n]
+      % [m,n]     = data(:)
+      % [1,1,m,n] = data
+      % ------------------------------------------------
+      levitus.(name(nv)) = data;
+      
+      % moves the waitbar cursor
+      % ------------------------
+      waitbar( i/length(nv), wb);
+      
+    end
+    
+    % close waitbar
+    % -------------
+    close(wb);
+    
+    % close netcdf file
+    % -----------------
+    close(nc);
+  end
+
+% use native toolbox +netcdf since R2008b
+% ---------------------------------------
+  function read_netcdf_native
+    
+    % Open netCDF file
+    % ----------------
+    nc = netcdf_native(file);
+    
+    for key = keys(nc.VARIABLES)
+      var = char(key);
+      data = zeros( size( nc.VARIABLES.(var).data__ ) );
+      data(:) = nc.VARIABLES.(var).data__;
+      levitus.(var) = data;
+    end
+    
+  end
 
-%----------------------------------------------------------------------
-%----------------------------------------------------------------------
-function filesfound = checkforfiles( file )
+% check if file exist
+%--------------------
+  function filesfound = checkforfiles( file )
+    
+    if exist(file,'file');
+      filesfound = 1;
+    else
+      filesfound = 0;
+    end
+    
+  end
 
-if exist(file,'file');
-   filesfound = 1;
-else 
-   filesfound = 0;
 end
diff --git a/tsg_io/writeTSGDataNetCDF.m b/tsg_io/writeTSGDataNetCDF.m
index f2ce6ea5e223ec88b308d842d1e3cb301d8abd1c..3617c42afdc276d49a47ea814709e10453c6e3a3 100644
--- a/tsg_io/writeTSGDataNetCDF.m
+++ b/tsg_io/writeTSGDataNetCDF.m
@@ -20,307 +20,371 @@ function [error] = writeTSGDataNetCDF( hTsgGUI, filename)
 %
 % $Id$
 
-%% Open the file
-% -------------
-nc = netcdf(filename, 'clobber');
-if isempty(nc)
-  msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
-  warndlg( msg_error, 'NetCDF write dialog');
-  error = -1;
-  return;
+%% Check Netcdf library version
+% -----------------------------
+switch ( version('-release') )
+  case { '11', '12', '13', '14', '2006a', '2006b', '2007a', '2007b', '2008a' }
+    write_netcdf_toolbox;
+  otherwise
+    write_netcdf_native;
 end
 
-% Display read file info on console
-% ---------------------------------
-fprintf('\nWRITE_NETCDF_FILE\n'); tic;
-
-% Initialize loading NetCDF file waitbar
-% --------------------------------------
-wb = waitbar(0, 'Initializing NetCDF file. Please  wait...');
-
-% We cannot change title property to 'none' (default set as 'tex') inside
-% waitbar function (line 81), see
-% http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
-% -----------------------------------------------------------------------
-hchild = get(wb,'children');
-htitle = get(hchild,'title');
-set(htitle,'Interpreter','None');
-
-% Get the data from the application GUI
-% -------------------------------------
-tsg = getappdata( hTsgGUI, 'tsg_data');
-
-% Get an instance of dynaload objetc from file 'tsgqc_netcdf.csv'
-% -----------------------------------------------------------------
-dyna = dynaload('tsgqc_netcdf.csv');
-
-% Get attributes & variables list from dynaload instance
-% ------------------------------------------------------
-ncd_keys = keys(dyna.DIMENSIONS);
-ncv_keys = keys(dyna.VARIABLES);
-nca_keys = keys(dyna.ATTRIBUTES);
-
-%ncv_fieldNames  = get_fieldnames(ncv);
-
-% Display more info about write file on console
-% ---------------------------------------------
-fprintf('...writing %s : ', filename);
-
-%% Create NetCDF file:
-% -------------------
-% for key = ncd_keys
-%   k = char(key);
-%   value = dyna.DIMENSIONS.(key).value;
-%   if ~isempty(value) 
-%     nc(k) = value;
-%   elseif ~isempty(tsg.(k))
-%     nc(k) = numel(tsg.(k));
-%   end
-% end
-
-% Variable dimensions
-% -------------------
-nc('DAYD')      = numel(tsg.DAYD);
-
-% if dimension is empty (no data), don't create, because create empty
-% dimension quive it unlimited dimension, but you can only have one
-% unlimited dimension in a file
-% --------------------------------------------------------------------
-
-% number of external SSPS or SSTP comparison
-% ------------------------------------------
-if ~isempty(tsg.DAYD_EXT)
-  nc('DAYD_EXT')  = numel(tsg.DAYD_EXT);
-end
-
-% number of calibration coefficients
-% ----------------------------------
-nc('NCOEF_CAL') = tsg.dim.CALCOEF;   % 7
-
-% number of linearisation coefficients
-% ------------------------------------
-nc('NCOEF_LIN') = tsg.dim.LINCOEF;   % 2
-
-% Fixed dimensions
-% ----------------
-nc('STRING256') = tsg.dim.STRING256;
-nc('STRING14')  = tsg.dim.STRING14;
-nc('STRING8')   = tsg.dim.STRING8;
-nc('STRING4')   = tsg.dim.STRING4;
-nc('N1')        = tsg.dim.N1;
-
-% display filename after 'Interpreter','None' initialization to prevent
-% display console warning
-% ---------------------------------------------------------------------
-waitbar(1/50,wb,['Writing file: ' filename ' Please  wait...']);
-
-%% Create NetCDF global attributes
-% -------------------------------
-for key = nca_keys
-  global_att = char(key);
-  nc.(global_att) = tsg.(global_att);
-end
-
-% Create NetCDF variables and attributes
-% --------------------------------------
-for key = ncv_keys
-
-  variable = char(key);
-
-  % get structure
-  % -------------
-  s = dyna.VARIABLES.(variable);
-  
-  ncv_fieldNames  = fieldnames(s); 
-  
-   % get variable dimension declare in file
-  % --------------------------------------
-  %dimension = get(ncv, variable, ncv_fieldNames{1});
-  dimension = s.dimension__;
-
-  % get variable type declare in file
-  % --------------------------------------
-  %nctype    = get(ncv, variable, ncv_fieldNames{2});
-  nctype = s.type__;
-
-  % create netcdf variable with dimension, dimension must be a cell
-  % ---------------------------------------------------------------
-  switch nctype
-    case 'double'
-      nc{variable} = ncdouble(dimension);
-    case 'float'
-      nc{variable} = ncfloat(dimension);
-    case 'int'
-      nc{variable} = ncint(dimension);
-    case 'short'
-      nc{variable} = ncshort(dimension);
-    case 'byte'
-      nc{variable} = ncbyte(dimension);
-    case 'char'
-      nc{variable} = ncchar(dimension);
-    otherwise
-      % by default, display a warning and cast to char
-      % ----------------------------------------------
-      warning('tsgqc_GUI:writeTSGDataNetCDF', ...
-        'unknow type ''%s'' for  dimension ''%s'' of  ''%s'' variable.\nCheck your %s file', ...
-        nctype, dimension{1}, variable, file(ncv));
-
-      nc{variable} = ncchar(dimension);
-  end
-
-  % create variable attribute, jump dimension and nctype fields
-  % -----------------------------------------------------------
-  for j=1:numel(ncv_fieldNames)
-
-    % see new us191.netcdf toolbox, we'll not use index to get type
-    % but structure with special variable, eg: s.type__
-    % -------------------------------------------------
-    fieldName = ncv_fieldNames{j};
-    value     = s.(fieldName);
-    %nctype    = get(ncv, variable, ncv_fieldNames{2});
+%% Nested functions
+% -----------------
 
-    % jump each internal fieldname (eg key__, data__, type__, dimension__)
-    % or empty fieldname
-    % -------------------------------------------------------------
-    if ~isempty(regexp(fieldName, '__$','ONCE')) || isempty(value)
-      continue;
+% use Charles Dunham toolbox
+% --------------------------
+  function write_netcdf_toolbox
+    
+    
+    %% Open the file
+    % --------------
+    nc = netcdf(filename, 'clobber');
+    if isempty(nc)
+      msg_error = ['TSG_GOSUD file_lecture : Open file error : ' filename];
+      warndlg( msg_error, 'NetCDF write dialog');
+      error = -1;
+      return;
     end
     
-    % if field is empy, it's not a attribute for this netcdf variable
-    % ---------------------------------------------------------------
-    if ~isempty(value)
-
-      % ncatt(theAttname, theAttvalue, theParent) uses the class of
-      % theAttvalue as theAtttype ('char' or 'double').
-      % need to be cast before assignment
+    % Display read file info on console
+    % ---------------------------------
+    fprintf('\nWRITE_NETCDF_FILE\n'); tic;
+    
+    % Initialize loading NetCDF file waitbar
+    % --------------------------------------
+    wb = waitbar(0, 'Initializing NetCDF file. Please  wait...');
+    
+    % We cannot change title property to 'none' (default set as 'tex') inside
+    % waitbar function (line 81), see
+    % http://www.mathworks.co.uk/matlabcentral/newsreader/view_thread/115725
+    % -----------------------------------------------------------------------
+    hchild = get(wb,'children');
+    htitle = get(hchild,'title');
+    set(htitle,'Interpreter','None');
+    
+    % Get the data from the application GUI
+    % -------------------------------------
+    tsg = getappdata( hTsgGUI, 'tsg_data');
+    
+    % Get an instance of dynaload objetc from file 'tsgqc_netcdf.csv'
+    % -----------------------------------------------------------------
+    dyna = dynaload('tsgqc_netcdf.csv');
+    
+    % Get attributes & variables list from dynaload instance
+    % ------------------------------------------------------
+    ncd_keys = keys(dyna.DIMENSIONS);
+    ncv_keys = keys(dyna.VARIABLES);
+    nca_keys = keys(dyna.ATTRIBUTES);
+    
+    %ncv_fieldNames  = get_fieldnames(ncv);
+    
+    % Display more info about write file on console
+    % ---------------------------------------------
+    fprintf('...writing %s : ', filename);
+    
+    %% Create NetCDF file:
+    % -------------------
+    % for key = ncd_keys
+    %   k = char(key);
+    %   value = dyna.DIMENSIONS.(key).value;
+    %   if ~isempty(value)
+    %     nc(k) = value;
+    %   elseif ~isempty(tsg.(k))
+    %     nc(k) = numel(tsg.(k));
+    %   end
+    % end
+    
+    % Variable dimensions
+    % !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    % pour l'instant, code en dur, a revoir !!!!!!!!!!!!!!!!
+    % -------------------
+    nc('DAYD')      = numel(tsg.DAYD);
+    
+    % if dimension is empty (no data), don't create, because create empty
+    % dimension quive it unlimited dimension, but you can only have one
+    % unlimited dimension in a file
+    % --------------------------------------------------------------------
+    
+    % number of external SSPS or SSTP comparison
+    % ------------------------------------------
+    if ~isempty(tsg.DAYD_EXT)
+      nc('DAYD_EXT')  = numel(tsg.DAYD_EXT);
+    end
+    
+    % number of calibration coefficients
+    % ----------------------------------
+    nc('NCOEF_CAL') = tsg.dim.CALCOEF;   % 7
+    
+    % number of linearisation coefficients
+    % ------------------------------------
+    nc('NCOEF_LIN') = tsg.dim.LINCOEF;   % 2
+    
+    % Fixed dimensions
+    % ----------------
+    nc('STRING256') = tsg.dim.STRING256;
+    nc('STRING14')  = tsg.dim.STRING14;
+    nc('STRING8')   = tsg.dim.STRING8;
+    nc('STRING4')   = tsg.dim.STRING4;
+    nc('N1')        = tsg.dim.N1;
+    
+    % display filename after 'Interpreter','None' initialization to prevent
+    % display console warning
+    % ---------------------------------------------------------------------
+    waitbar(1/50,wb,['Writing file: ' filename ' Please  wait...']);
+    
+    %% Create NetCDF global attributes
+    % -------------------------------
+    for key = nca_keys
+      global_att = char(key);
+      nc.(global_att) = tsg.(global_att);
+    end
+    
+    % Create NetCDF variables and attributes
+    % --------------------------------------
+    for key = ncv_keys
+      
+      variable = char(key);
+      
+      % get structure
+      % -------------
+      s = dyna.VARIABLES.(variable);
+      
+      ncv_fieldNames  = fieldnames(s);
+      
+      % get variable dimension declare in file
+      % --------------------------------------
+      %dimension = get(ncv, variable, ncv_fieldNames{1});
+      dimension = s.dimension__;
+      
+      % get variable type declare in file
+      % --------------------------------------
+      %nctype    = get(ncv, variable, ncv_fieldNames{2});
+      nctype = s.type__;
+      
+      % create netcdf variable with dimension, dimension must be a cell
+      % ---------------------------------------------------------------
+      switch nctype
+        case 'double'
+          nc{variable} = ncdouble(dimension);
+        case 'float'
+          nc{variable} = ncfloat(dimension);
+        case 'int'
+          nc{variable} = ncint(dimension);
+        case 'short'
+          nc{variable} = ncshort(dimension);
+        case 'byte'
+          nc{variable} = ncbyte(dimension);
+        case 'char'
+          nc{variable} = ncchar(dimension);
+        otherwise
+          % by default, display a warning and cast to char
+          % ----------------------------------------------
+          warning('tsgqc_GUI:writeTSGDataNetCDF', ...
+            'unknow type ''%s'' for  dimension ''%s'' of  ''%s'' variable.\nCheck your %s file', ...
+            nctype, dimension{1}, variable, file(ncv));
+          
+          nc{variable} = ncchar(dimension);
+      end
+      
+      % create variable attribute, jump dimension and nctype fields
       % -----------------------------------------------------------
-      if isnumeric(value)
-
-        % BE CAREFUL 
-        % bug dans la toolbox, le cast autre que double met l'attribut a 0
-        % keep these lines comment !!!!!!!!!!!!
+      for j=1:numel(ncv_fieldNames)
         
-%          switch nctype
-%              case {'double', 'real', 'float', 'single'}
-%                value = double(value);
-%              case {'float', 'single'}
-%                value = single(value);               
-%             case {'int', 'integer', 'int32'}
-%               value = int32(value);
-%             case {'short', 'int16'}
-%               value = int16(value);
-%             case 'int8'
-%               value = int8(value);
-%             % bug dans la toolbox, le type uint ne marche pas
-%             % on met int8
-%             case {'byte', 'uint8'}
-%               value = int8(value);  
-%           end
-          nc{variable}.(fieldName) = value;
-
-      else
-        nc{variable}.(fieldName) = char(value);
+        % see new us191.netcdf toolbox, we'll not use index to get type
+        % but structure with special variable, eg: s.type__
+        % -------------------------------------------------
+        fieldName = ncv_fieldNames{j};
+        value     = s.(fieldName);
+        %nctype    = get(ncv, variable, ncv_fieldNames{2});
+        
+        % jump each internal fieldname (eg key__, data__, type__, dimension__)
+        % or empty fieldname
+        % -------------------------------------------------------------
+        if ~isempty(regexp(fieldName, '__$','ONCE')) || isempty(value)
+          continue;
+        end
+        
+        % if field is empy, it's not a attribute for this netcdf variable
+        % ---------------------------------------------------------------
+        if ~isempty(value)
+          
+          % ncatt(theAttname, theAttvalue, theParent) uses the class of
+          % theAttvalue as theAtttype ('char' or 'double').
+          % need to be cast before assignment
+          % -----------------------------------------------------------
+          if isnumeric(value)
+            
+            % BE CAREFUL
+            % bug dans la toolbox, le cast autre que double met l'attribut a 0
+            % keep these lines comment !!!!!!!!!!!!
+            
+            %          switch nctype
+            %              case {'double', 'real', 'float', 'single'}
+            %                value = double(value);
+            %              case {'float', 'single'}
+            %                value = single(value);
+            %             case {'int', 'integer', 'int32'}
+            %               value = int32(value);
+            %             case {'short', 'int16'}
+            %               value = int16(value);
+            %             case 'int8'
+            %               value = int8(value);
+            %             % bug dans la toolbox, le type uint ne marche pas
+            %             % on met int8
+            %             case {'byte', 'uint8'}
+            %               value = int8(value);
+            %           end
+            nc{variable}.(fieldName) = value;
+            
+          else
+            nc{variable}.(fieldName) = char(value);
+          end
+          
+        end
       end
-
     end
-  end
-end
-
-%% Create data to NetCDF file:
-% ---------------------------
-
-% Write global attributes
-% -----------------------
-for i=1:numel(nca_keys)
-
-  % get netcdf global attribute name
-  % --------------------------------
-  global_attr = nca_keys{i};
-
-  nc.(global_attr) = tsg.(global_attr);
-end
-
-% Convert Matlab julian days (datenum) to 1950 reference
-% ------------------------------------------------------
-d = strmatch('DAYD',ncv_keys);
-for i=1:numel(d)
-  tsg.(ncv_keys{d(i)}) = datenumToJulian(tsg.(ncv_keys{d(i)}));
-end
-
-% shift to [-180 180] longitude range if needed
-% ---------------------------------------------
-if ~isempty(tsg.indcross)
-  tsg.LONX = mod(tsg.LONX+180,360)-180;
-end
-
-% Write measurements (tsg.variables)
-% ----------------------------------
-for i=1:numel(ncv_keys)
-
-  % get netcdf variable name
-  % ------------------------
-  variable = ncv_keys{i};
-
-  % display waitbar
-  % ---------------
-  waitbar( i/numel(ncv_keys), wb, ['writing ' variable ' variable']);
-
-  % get ncvar type object nv
-  % ------------------------
-  nv = nc{variable};
-
-  % be careful, if dimension DAYD_EXT not defined (no sample data),
-  % nv is empty
-  % ---------------------------------------------------------
-  if ~isempty(nv)
-
-    % set autonan mode (FillValue_)
-    % -----------------------------
-    nv = autonan(nv,1);
-
-    % tsg variable is not empty, fill nv with it
-    % ------------------------------------------
-    if ~isempty(tsg.(variable))
-
-      % fill netcdf variables nv with corresponding tsg variable
-      % --------------------------------------------------------
-      nv(:) = tsg.(variable);
-
-      % In case of unlimited dimension, for example only, use:
-      % nc{variable}(1:length(tsg.(variable))) = tsg.(variable)
-      % -------------------------------------------------------
-
-    else
-
-      % if default_value defined, fill nv with it
-      % -----------------------------------------
-      if ~isempty(nv.default_value(:))
-        % a verifier, doit marcher pour tout les type de variable
-        %nv(:) = int8(nv.default_value(:));
-        nv(:) = nv.default_value(:);
+    
+    %% Create data to NetCDF file:
+    % ---------------------------
+    
+    % Write global attributes
+    % -----------------------
+    for i=1:numel(nca_keys)
+      
+      % get netcdf global attribute name
+      % --------------------------------
+      global_attr = nca_keys{i};
+      
+      nc.(global_attr) = tsg.(global_attr);
+    end
+    
+    % Convert Matlab julian days (datenum) to 1950 reference
+    % ------------------------------------------------------
+    d = strmatch('DAYD',ncv_keys);
+    for i=1:numel(d)
+      tsg.(ncv_keys{d(i)}) = datenumToJulian(tsg.(ncv_keys{d(i)}));
+    end
+    
+    % shift to [-180 180] longitude range if needed
+    % ---------------------------------------------
+    if ~isempty(tsg.indcross)
+      tsg.LONX = mod(tsg.LONX+180,360)-180;
+    end
+    
+    % Write measurements (tsg.variables)
+    % ----------------------------------
+    for i=1:numel(ncv_keys)
+      
+      % get netcdf variable name
+      % ------------------------
+      variable = ncv_keys{i};
+      
+      % display waitbar
+      % ---------------
+      waitbar( i/numel(ncv_keys), wb, ['writing ' variable ' variable']);
+      
+      % get ncvar type object nv
+      % ------------------------
+      nv = nc{variable};
+      
+      % be careful, if dimension DAYD_EXT not defined (no sample data),
+      % nv is empty
+      % ---------------------------------------------------------
+      if ~isempty(nv)
+        
+        % set autonan mode (FillValue_)
+        % -----------------------------
+        nv = autonan(nv,1);
+        
+        % tsg variable is not empty, fill nv with it
+        % ------------------------------------------
+        if ~isempty(tsg.(variable))
+          
+          % fill netcdf variables nv with corresponding tsg variable
+          % --------------------------------------------------------
+          nv(:) = tsg.(variable);
+          
+          % In case of unlimited dimension, for example only, use:
+          % nc{variable}(1:length(tsg.(variable))) = tsg.(variable)
+          % -------------------------------------------------------
+          
+        else
+          
+          % if default_value defined, fill nv with it
+          % -----------------------------------------
+          if ~isempty(nv.default_value(:))
+            % a verifier, doit marcher pour tout les type de variable
+            %nv(:) = int8(nv.default_value(:));
+            nv(:) = nv.default_value(:);
+          end
+          
+        end
+        
       end
-
+      
     end
+    
+    % Close waitbar
+    % -------------
+    close(wb)
+    
+    % Close NetCDF file
+    % -----------------
+    endef(nc)
+    close(nc)
+    
+    % Display time to write file on console
+    % -------------------------------------
+    t = toc; fprintf('...done (%6.2f sec).\n\n',t);
+    
+    % Everything OK
+    % -------------
+    error = 1;
+    
+  end % end of nested function nc_write_old
 
+% use native toolbox +netcdf since R2008b
+% ---------------------------------------
+  function write_netcdf_native
+    
+    % Get the data from the application GUI
+    % -------------------------------------
+    tsg = getappdata( hTsgGUI, 'tsg_data');
+    
+    % Get an instance of dynaload object from file 'tsgqc_netcdf.csv'
+    % -----------------------------------------------------------------
+    nc = netcdf_native('tsgqc_netcdf.csv');
+    
+    % loop over all variables and get associated value in tsg structure
+    % -----------------------------------------------------------------
+    for key = keys(nc.VARIABLES)
+      var = char(key);
+      nc.VARIABLES.(var).data__ = tsg.(var);
+    end
+    
+    % loop over all global attributes and get associated value in tsg 
+    % structure
+    % -----------------------------------------------------------------
+    for key = keys(nc.ATTRIBUTES)
+      att = char(key);
+      nc.ATTRIBUTES.(att).data__ = tsg.(att);
+    end
+    
+ % try
+    
+    % write netcdf file with and display waibar (boolean)
+    % ---------------------------------------------------
+    write( nc, filename, 'NC_CLOBBER', true );
+    
+    % Everything OK
+    % -------------
+    error = 1;
+ % catch
+ %   error = -1;
+ % end
+    
   end
 
-end
-
-% Close waitbar
-% -------------
-close(wb)
-
-% Close NetCDF file
-% -----------------
-endef(nc)
-close(nc)
+end % end od writeTSGDataNetCDF
 
-% Display time to write file on console
-% -------------------------------------
-t = toc; fprintf('...done (%6.2f sec).\n\n',t);
-
-% Everything OK
-% -------------
-error = 1;
-
-end