diff --git a/Aforc_ECMWF/make_bry_wkb_ECMWF.m b/Aforc_ECMWF/make_bry_wkb_ECMWF.m
index 6793a878276ae7458387da6113f222e2759dc492..ddae7b73e4b12fc27584fe9e6d90d26bb0c31cea 100644
--- a/Aforc_ECMWF/make_bry_wkb_ECMWF.m
+++ b/Aforc_ECMWF/make_bry_wkb_ECMWF.m
@@ -75,6 +75,10 @@ result=close(nc);
 grid_angle=mean(mean(angle(mask==1)));
 [M L]=size(h);
 %
+wkb_prefix=[wkb_prefix,'_ECMWF_'];
+frc_prefix=[frc_prefix,'_ECMWF_'];
+%
+%
 % Loop over monthly files
 %
 for Y=Ymin:Ymax
@@ -92,20 +96,18 @@ for Y=Ymin:Ymax
 %
 % Forcing file name
 %
-  frc_prefix=[frc_prefix,'_ECMWF_'];
   if level==0
    nc_suffix='.nc';
   else
    nc_suffix=['.nc.',num2str(level)];
   end
   frcname=[frc_prefix,'Y',num2str(Y),...
-                      'M',num2str(M),nc_suffix];
+                      'M',num2str(sprintf(Mth_format,M)),nc_suffix];
 %
 % WKB file name
 %
-  wkb_prefix=[wkb_prefix,'_ECMWF_'];
   brywkbname=[wkb_prefix,'Y',num2str(Y),...
-                     'M',num2str(M),nc_suffix];
+                     'M',num2str(sprintf(Mth_format,M)),nc_suffix];
   disp(' ')
   disp([' Making file: ',brywkbname])
   disp(['        from: ',frcname])
@@ -125,7 +127,7 @@ for Y=Ymin:Ymax
 % Create the boundary file
 %
   create_bryfile_wkb(brywkbname,grdname,CROCO_title,wkb_obc,...
-                     wkb_time,wkb_cycle,'clobber');
+                     wkb_time,wkb_cycle,'clobber',Yorig);
   disp(' ')
 %
 % 
diff --git a/Aforc_ERA5/ERA5_convert.py b/Aforc_ERA5/ERA5_convert.py
index 76def899b8f5cb0cf1a44506676f0c860e3e70f6..d3a7ff72c7aa8d934017fc02a39badfe0d1f6ef2 100755
--- a/Aforc_ERA5/ERA5_convert.py
+++ b/Aforc_ERA5/ERA5_convert.py
@@ -95,7 +95,7 @@ for iyear in range(year_start,year_end+1):
         data[np.where(data==mvalue)]=9999.
 
 #
-# Convert time from seconds since 1970-1-1 0:0:0 into days since Yorig-1-1 0:0:0
+# Convert time from seconds since 1970-1-1 0:0:0 into days since Yorig-01-01 00:00:00
 #
 
         time = time / 86400.
@@ -115,7 +115,7 @@ for iyear in range(year_start,year_end+1):
 # Create and write output netcdf file
 #
 
-        fname_out = era5_dir_processed + '/' + vname.upper() + '_Y' + str(iyear) + 'M' + str(imonth) + '.nc'
+        fname_out = era5_dir_processed + '/' + vname.upper() + '_Y' + str(iyear) + 'M' + str(imonth).zfill(2) + '.nc'
 
         nw = netcdf(fname_out,mode='w',format='NETCDF4')
 
@@ -132,7 +132,8 @@ for iyear in range(year_start,year_end+1):
         vartime.long_name = 'Time'
         varlon.units = 'degree_east'
         varlat.units = 'degree_north'
-        vartime.units = 'days since '+str(Yorig)+'-1-1'
+        vartime.units = 'days since '+str(Yorig)+'-01-01 00:00:00'
+        vartime.calendar = 'proleptic_gregorian'
         vardata.missing_value = 9999.
         vardata.units = units[k]
         vardata.long_name = vlong
diff --git a/Aforc_ERA5/era5_crocotools_param.py b/Aforc_ERA5/era5_crocotools_param.py
index fd3630ea0b6b8ec8467fba1565aee1f29ba3d4aa..a68727128776826bd496d6d026827721f6b1eb6f 100644
--- a/Aforc_ERA5/era5_crocotools_param.py
+++ b/Aforc_ERA5/era5_crocotools_param.py
@@ -21,14 +21,15 @@ era5_dir_processed = config_dir + 'DATA/ERA5_' + config_name
 #
 # extraction wave variables
 #
-wave_extract=False # True to extract wave variables
+#wave_extract=False # True to extract wave variables
+wave_extract=True # True to extract wave variables
 #
 # Dates limits
 #
 year_start = 2005
 month_start = 1
 year_end = 2005
-month_end = 3
+month_end = 4
 #
 # Year origin of time
 #
@@ -40,7 +41,8 @@ n_overlap = 0
 #
 # Request time (daily hours '00/01/.../23')
 #
-time = '00/01/02/03/04/05/06/07/08/09/10/11/12/13/14/15/16/17/18/19/20/21/22/23'
+time = '00/06/12/18'
+#time = '00/01/02/03/04/05/06/07/08/09/10/11/12/13/14/15/16/17/18/19/20/21/22/23'
 #
 # Request variables (see available at ERA5_variables.json)
 variables = ['lsm','tp','strd','ssr','t2m','q','u10','v10'] #note lsm is land_sea_mask
diff --git a/Aforc_ERA5/interp_ERA5.m b/Aforc_ERA5/interp_ERA5.m
index 0c1364e5e103c774e1f1a2c1e90c3fe7c92b7836..568175a1e03dd0e9cc0981275a77581621c3749f 100644
--- a/Aforc_ERA5/interp_ERA5.m
+++ b/Aforc_ERA5/interp_ERA5.m
@@ -1,6 +1,6 @@
 function interp_ERA5(ATMO_dir,Y,M,Roa,interp_method,...
                      lon1,lat1,lonwave1,latwave1,mask1,maskwave1,maskwave2,tin,...
-		     nc_frc, nc_blk,lon,lat,angle,tout, add_waves)
+		                  nc_frc, nc_blk,lon,lat,angle,tout, add_waves)
 %
 % Read the local ERA5 files and perform the space interpolations
 %
@@ -12,7 +12,7 @@ function interp_ERA5(ATMO_dir,Y,M,Roa,interp_method,...
 % 1: Air temperature: Convert from Kelvin to Celsius
 %
 vname='T2M';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 tair=squeeze(nc{vname}(tin,:,:));
 close(nc);
 tair=get_missing_val(lon1,lat1,mask1.*tair,nan,Roa,nan);
@@ -25,7 +25,7 @@ tair=interp2(lon1,lat1,tair,lon,lat,interp_method);
 % Get Specific Humidity [Kg/Kg]
 %
 vname='Q';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 shum=squeeze(nc{vname}(tin,:,:));
 close(nc);
 shum=get_missing_val(lon1,lat1,mask1.*shum,nan,Roa,nan);
@@ -40,7 +40,7 @@ rhum=shum./qsat(tair);
 % 3: Precipitation rate: Convert from [kg/m^2/s] to cm/day
 %
 vname='TP';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 prate=squeeze(nc{vname}(tin,:,:));
 close(nc);
 prate=get_missing_val(lon1,lat1,mask1.*prate,nan,Roa,nan);
@@ -54,7 +54,7 @@ prate(prate<1.e-4)=0;
 %  Solar shortwave
 %
 vname='SSR';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 dswrf=squeeze(nc{vname}(tin,:,:));
 close(nc);
 radsw=get_missing_val(lon1,lat1,mask1.*dswrf,nan,Roa,nan);
@@ -77,7 +77,7 @@ radsw(radsw<1.e-10)=0;
 %  5.2 get the downward longwave flux [W/m^2]
 %
 vname='STRD';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 dlwrf_in=squeeze(nc{vname}(tin,:,:));
 close(nc);
 radlw_in=get_missing_val(lon1,lat1,mask1.*dlwrf_in,nan,Roa,nan);
@@ -87,7 +87,7 @@ radlw_in=interp2(lon1,lat1,radlw_in,lon,lat,interp_method);
 % 6: Wind  [m/s]
 %
 vname='U10M';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 uwnd=squeeze(nc{vname}(tin,:,:));
 close(nc)
 uwnd=get_missing_val(lon1,lat1,mask1.*uwnd,nan,Roa,nan);
@@ -95,7 +95,7 @@ uwnd=interp2(lon1,lat1,uwnd,lon,lat,interp_method);
 %
 %
 vname='V10M';
-nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
 vwnd=squeeze(nc{vname}(tin,:,:));
 close(nc)
 vwnd=get_missing_val(lon1,lat1,mask1.*vwnd,nan,Roa,nan);
@@ -149,7 +149,7 @@ if add_waves == 1
  % 8: Surface wave amplitude: convert from SWH to Amp
  %
  vname='SWH';
- nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+ nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
  awave=1/(2*sqrt(2))*squeeze(nc{vname}(tin,:,:));
  close(nc);
  %[ATMO_DIR,vname,'_Y',num2str(Y),'M',num2str(M),'.nc']
@@ -159,7 +159,7 @@ if add_waves == 1
  % 9: Surface wave direction
  %
  vname='MWD';
- nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+ nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
  dwave=squeeze(nc{vname}(tin,:,:));
  close(nc);
  dwave=get_missing_val(lonwave1,latwave1,maskwave1.*dwave,nan,Roa,nan);
@@ -168,7 +168,7 @@ if add_waves == 1
  % 10: Surface wave peak period
  %
  vname='PP1D';
- nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+ nc=netcdf([ATMO_dir,vname,'_Y',num2str(Y),'M',num2str(sprintf('%02d',M)),'.nc'],'r');
  pwave=squeeze(nc{vname}(tin,:,:));
  close(nc);
  pwave=get_missing_val(lonwave1,latwave1,maskwave2.*pwave,nan,Roa,nan);
diff --git a/Aforc_ERA5/make_ERA5.m b/Aforc_ERA5/make_ERA5.m
index faee3873cdd7c78bddaba3582cb571fb604c01e7..b5d4c25bc76fd723a792969df73dc2dcec664517 100644
--- a/Aforc_ERA5/make_ERA5.m
+++ b/Aforc_ERA5/make_ERA5.m
@@ -1,13 +1,13 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  make_ERA5.m
-% 
+%
 %  Create and fill frc and bulk files with ERA5 data.
 %  (ERA-5 Reanalysis)
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -25,7 +25,7 @@
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Updated    D. Donoso, G. Cambon. P. Penven (Oct 2021) 
+%  Updated    D. Donoso, G. Cambon. P. Penven (Oct 2021)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 clear all
 close all
@@ -33,8 +33,8 @@ close all
 %
 % Common parameters
 %
-crocotools_param 
-isoctave=exist('octave_config_info');       
+crocotools_param
+isoctave=exist('octave_config_info');
 frc_prefix=[frc_prefix,'_ERA5_'];
 blk_prefix=[blk_prefix,'_ERA5_'];
 %
@@ -68,8 +68,8 @@ close(nc);
 %
 % Get the ERA5 horizontal grids (it should be the same for every month)
 %
-nc=netcdf([ERA5_dir,'LSM_Y',num2str(Ymin),'M',num2str(Mmin),'.nc'],'r');
-disp(['Use this land file :',char([ERA5_dir,'LSM_Y',num2str(Ymin),'M',num2str(Mmin),'.nc'])])
+nc=netcdf([ERA5_dir,'LSM_Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),'.nc'],'r');
+disp(['Use this land file :',char([ERA5_dir,'LSM_Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),'.nc'])])
 
 lon1=nc{'lon'}(:);
 lat1=nc{'lat'}(:);
@@ -85,10 +85,10 @@ close(nc);
 if add_waves == 1
     %
     % get horizontal grid for ocean waves
-    % for ERA5 wave variables, resolution change to 0.5° instead of 0.25° 
+    % for ERA5 wave variables, resolution change to 0.5° instead of 0.25°
     % for the atmo variable (0.25° x 0.25° (atmosphere)  vs  0.5° x 0.5° (ocean waves))
     %
-    filein=[ERA5_dir,'SWH_Y',num2str(Ymin),'M',num2str(Mmin),'.nc'];
+    filein=[ERA5_dir,'SWH_Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),'.nc'];
     nc=netcdf(filein,'r');
     lonwave=nc{'lon'}(:);
     latwave=nc{'lat'}(:);
@@ -100,7 +100,7 @@ if add_waves == 1
     close(nc);
 
     % fix: PP1D doesn t have the same mask than SWH
-    filein2=[ERA5_dir,'PP1D_Y',num2str(Ymin),'M',num2str(Mmin),'.nc'];
+    filein2=[ERA5_dir,'PP1D_Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),'.nc'];
     nc=netcdf(filein2);
     maskwave2=squeeze(nc{'PP1D'}(1,:,:));
     missvalue_wave2 = ncreadatt(filein2,'PP1D','missing_value');
@@ -126,7 +126,7 @@ disp(['Loop on the years and the months'])
 
 %
 for Y=Ymin:Ymax
-    if Y==Ymin 
+    if Y==Ymin
         mo_min=Mmin;
     else
         mo_min=1;
@@ -139,14 +139,14 @@ for Y=Ymin:Ymax
     for M=mo_min:mo_max
         disp(' ')
         disp(['Processing  year ',num2str(Y),...
-              ' - month ',num2str(M)])
+            ' - month ',num2str(sprintf(Mth_format,M))])
         disp(' ')
         %-------------------------------------------------------------------%
         %
         % Process time (here in days), with SST file (minimum time step)
         %
         %-------------------------------------------------------------------%
-        nc=netcdf([ERA5_dir,'T2M_Y',num2str(Y),'M',num2str(M),'.nc'],'r');
+        nc=netcdf([ERA5_dir,'T2M_Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),'.nc'],'r');
         ERA5_time=nc{'time'}(:);
         close(nc);
         dt=mean(gradient(ERA5_time));
@@ -160,9 +160,9 @@ for Y=Ymin:Ymax
         itolap=freq*itolap_era5;
         tlen=tlen0+2*itolap;
         disp(['tlen=',num2str(tlen)])
-        disp(['Overlap is ',num2str(itolap_era5),' records before and after'])     
+        disp(['Overlap is ',num2str(itolap_era5),' records before and after'])
         time=0*(1:tlen);
-        time(itolap+1:tlen0+itolap)=ERA5_time;   
+        time(itolap+1:tlen0+itolap)=ERA5_time;
         disp(['====================='])
         disp('Compute time for croco file')
         disp(['====================='])
@@ -178,59 +178,61 @@ for Y=Ymin:Ymax
         %
         % ------------------------------------------------------------------%
         %
-	disp(['====================='])
+        disp(['====================='])
         disp('Create the frc/blk netcdf file')
         disp(['====================='])
         blkname=[blk_prefix,'Y',num2str(Y),...
-                 'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+            'M',num2str(sprintf(Mth_format,M)),nc_suffix];
         frcname=[frc_prefix,'Y',num2str(Y),...
-                 'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+            'M',num2str(sprintf(Mth_format,M)),nc_suffix];
         if makeblk==1
-          disp(['Create a new bulk file: ' blkname])
-          create_bulk(blkname,grdname,CROCO_title,time,0);
-          nc_add_globatt(blkname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,'ERA5');
-          disp([' '])
+            disp(['Create a new bulk file: ' blkname])
+            create_bulk(blkname,grdname,CROCO_title,time,0,Yorig);
+            nc_add_globatt(blkname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,'ERA5');
+            disp([' '])
         end
         if makefrc==1
-          disp(['Create a new forcing file: ' frcname])
-          disp([' '])
-          create_forcing(frcname,grdname,CROCO_title,...
-                          time,0,0,...
-                          0,0,0,...
-                          0,0,0,0,0,0)
+            disp(['Create a new forcing file: ' frcname])
+            disp([' '])
+            create_forcing(frcname,grdname,CROCO_title,...
+                            time,0,0,...
+                            0,0,0,...
+                            0,0,0,0,0,0,Yorig)
         end
         % %
         % % Add the waves
         % %
-	if makefrc==1 && add_waves==1
-          disp(['Add waves data'])
-          disp(['=============='])
+        if makefrc==1 && add_waves==1 
+            disp(['-> Add waves data previously downloaded'])
+            disp(['   using Aforc_ERA5/ERA5_request.py'])
         end
-	% % 
+        % %
         % %
         % % Add the tides
         % %
         if makefrc==1 && add_tides==1
-	     pot_tides=1;
-             add_tidal_data(tidename,grdname,frcname,Ntides,tidalrank,...
+            disp([' '])
+            disp(['-> Add tidal data'])
+            pot_tides=1;
+            add_tidal_data(tidename,grdname,frcname,Ntides,tidalrank,...
                             Yorig,Y,M,coastfileplot,makeplot,pot_tides)
         end
         %
         %
         % Open the CROCO forcing files
         if makefrc==1
-          nc_frc=netcdf(frcname,'write');
+            nc_frc=netcdf(frcname,'write');
         else
-          nc_frc=[];
+            nc_frc=[];
         end
 
-	% Open the CROCO bulk files
+        % Open the CROCO bulk files
         if makeblk==1
-	  nc_blk=netcdf(blkname,'write');
+            nc_blk=netcdf(blkname,'write');
         else
-          nc_blk=[];
+            nc_blk=[];
         end
-	%
+        %
         % Check if there are ERA5 files for the previous Month
         Mm=M-1;
         Ym=Y;
@@ -239,12 +241,12 @@ for Y=Ymin:Ymax
             Ym=Y-1;
         end
         %
-        fname = [ERA5_dir,'TP_Y',num2str(Ym),'M',num2str(Mm),'.nc'];
+        fname = [ERA5_dir,'TP_Y',num2str(Ym),'M',num2str(sprintf(Mth_format,Mm)),'.nc'];
         %nc=netcdf([ERA5_dir,'TP_Y',num2str(Ym),'M',num2str(Mm),'.nc']);
         %
         disp(' ')
         disp('======================================================')
-        disp('Perform interpolations for the previous month')      
+        disp('Perform interpolations for the previous month')
         disp('======================================================')
         disp(' ')
         if exist(fname)==0
@@ -256,16 +258,16 @@ for Y=Ymin:Ymax
             nc=netcdf(fname,'r');
             tndx=length(nc('time'));
             if makefrc==1
-               for aa=1:itolap
-                 nc_frc{'sms_time'}(aa)=nc{'time'}(tndx-(itolap-aa));
-               end
+                for aa=1:itolap
+                    nc_frc{'sms_time'}(aa)=nc{'time'}(tndx-(itolap-aa));
+                end
             end
             %
-	    if makeblk==1
-               for aa=1:itolap
-                 nc_blk{'bulk_time'}(aa)=nc{'time'}(tndx-(itolap-aa));
-               end
-	    end
+            if makeblk==1
+                for aa=1:itolap
+                    nc_blk{'bulk_time'}(aa)=nc{'time'}(tndx-(itolap-aa));
+                end
+            end
             close(nc)
         end
         %
@@ -279,29 +281,29 @@ for Y=Ymin:Ymax
             end
             interp_ERA5(ERA5_dir,Ym,Mm,Roa,interp_method,lon1,lat1,lon1wave,lat1wave, ...
                         mask,maskwave,maskwave2,aa0,nc_frc,nc_blk,lon,lat,angle,aa,add_waves)
-        end  
-        %######################################################################      
-        %   
+        end
+        %######################################################################
+        %
         disp(' ')
         disp('======================================================')
         disp('Perform interpolations for the current month')
         disp('======================================================')
         disp(' ')
-        
+
         % Perform interpolations for the current month
         %
-        
+
         for tndx=1:tlen0
             if mod(tndx,6)==0
                 disp(['Step: ',num2str(tndx),' of ',num2str(tlen0)])
             end
             interp_ERA5(ERA5_dir,Y,M,Roa,interp_method,lon1,lat1,lon1wave,lat1wave,...
-                        mask,maskwave,maskwave2,tndx,nc_frc,nc_blk,lon,lat,angle,tndx+itolap,add_waves)	
+                        mask,maskwave,maskwave2,tndx,nc_frc,nc_blk,lon,lat,angle,tndx+itolap,add_waves)
         end
-        
-        disp(' ')      
+
+        disp(' ')
         disp('======================================================')
-        disp('Perform interpolations for next month')    
+        disp('Perform interpolations for next month')
         disp('======================================================')
         disp(' ')
         %######################################################################
@@ -313,9 +315,9 @@ for Y=Ymin:Ymax
             Mp=1;
             Yp=Y+1;
         end
-        
+
         fname=[ERA5_dir,'TP_Y',num2str(Yp),'M',num2str(Mp),'.nc'];
-        
+
         if exist(fname)==0
             disp(['No data for the next month: using current month'])
             tndx=tlen0;
@@ -325,18 +327,18 @@ for Y=Ymin:Ymax
             nc=netcdf(fname,'r');
 
             if makefrc==1
-              disp('sms_time')
-              for tndx=tlen0+itolap+1:tlen;
-                nc_frc{'sms_time'}(tndx)=nc{'time'}(tndx-tlen0-(itolap));
-              end;
+                disp('sms_time')
+                for tndx=tlen0+itolap+1:tlen;
+                    nc_frc{'sms_time'}(tndx)=nc{'time'}(tndx-tlen0-(itolap));
+                end;
             end
 
-	    if makeblk==1
-              disp('bulk_time')
-              for tndx=tlen0+itolap+1:tlen;
-                nc_blk{'bulk_time'}(tndx)=nc{'time'}(tndx-tlen0-(itolap));
-              end
-	    end
+            if makeblk==1
+                disp('bulk_time')
+                for tndx=tlen0+itolap+1:tlen;
+                    nc_blk{'bulk_time'}(tndx)=nc{'time'}(tndx-tlen0-(itolap));
+                end
+            end
             close(nc)
         end
         %
@@ -349,23 +351,23 @@ for Y=Ymin:Ymax
             disp(['tout=tndx ',num2str(tndx)])
             if Mp==M
                 %tin=tlen0;       % persistency if current month is used
-                tin=tndx-2*itolap
+                tin=tndx-2*itolap;
                 disp(['tin=',num2str(tin)])
             else
                 tin=tndx-tlen0-itolap;
                 disp(['tin=',num2str(tin)])
             end
             interp_ERA5(ERA5_dir,Yp,Mp,Roa,interp_method,lon1,lat1,lon1wave,lat1wave,...
-                        mask,maskwave,maskwave2,tin,nc_frc,nc_blk,lon,lat,angle,tout,add_waves)           
+                        mask,maskwave,maskwave2,tin,nc_frc,nc_blk,lon,lat,angle,tout,add_waves)
         end;
         %
         % Close the CROCO forcing files
         %
         if ~isempty(nc_frc)
-           close(nc_frc);
+            close(nc_frc);
         end
         if ~isempty(nc_blk)
-           close(nc_blk);
+            close(nc_blk);
         end
     end
 end
@@ -375,13 +377,13 @@ end
 %
 disp('======================================================')
 if SPIN_Long>0
-disp('Add spin up phase')
+    disp('Add spin up phase')
     M=Mmin-1;
     Y=Ymin-SPIN_Long;
     for month=1:12*SPIN_Long
         M=M+1;
         if M==13
-            M=1; 
+            M=1;
             Y=Y+1;
         end
         %
@@ -392,22 +394,22 @@ disp('Add spin up phase')
         %
         blkname=[blk_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
         blkname2=[blk_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-        disp(['Create ',blkname2]) 
+        disp(['Create ',blkname2])
 
         if (isoctave == 0)
             eval(['!cp ',blkname,' ',blkname2])
         else
             system(['cp ',blkname,' ',blkname2])
-        end          
+        end
         %
         % Change the time
         %
         nc=netcdf(blkname2,'write');
         time=nc{'bulk_time'}(:)-365.*(Ymin-Y);%+datenum(Yorig,1,1);
-                                              %[y,m,d,h,mi,s]=datevec(time);
-                                              %dy=Ymin-Y;
-                                              %y=y-dy;
-                                              %time=datenum(y,m,d,h,mi,s)-datenum(Yorig,1,1);
+        %[y,m,d,h,mi,s]=datevec(time);
+        %dy=Ymin-Y;
+        %y=y-dy;
+        %time=datenum(y,m,d,h,mi,s)-datenum(Yorig,1,1);
         nc{'bulk_time'}(:)=time;
         close(nc)
     end
@@ -420,7 +422,7 @@ if makeplot==1
     disp('======================================================')
     disp(' Make a few plots...')
     slides=[1 12 24 36];
-    
+
     test_forcing(blkname,grdname,'tair',slides,3,coastfileplot)
     figure
     test_forcing(blkname,grdname,'rhum',slides,3,coastfileplot)
diff --git a/Aforc_ERA5/make_bry_wkb_ERA5.m b/Aforc_ERA5/make_bry_wkb_ERA5.m
index b9c163c899e4dd9d93833f5b656b65e5be4b51d6..7d4097fee4c31ae251426c87ff448e2e7aa75f15 100644
--- a/Aforc_ERA5/make_bry_wkb_ERA5.m
+++ b/Aforc_ERA5/make_bry_wkb_ERA5.m
@@ -75,6 +75,10 @@ result=close(nc);
 grid_angle=mean(mean(angle(mask==1)));
 [M L]=size(h);
 %
+wkb_prefix=[wkb_prefix,'_ERA5_'];
+frc_prefix=[frc_prefix,'_ERA5_'];
+%
+%
 % Loop over monthly files
 %
 for Y=Ymin:Ymax
@@ -92,20 +96,18 @@ for Y=Ymin:Ymax
 %
 % Forcing file name
 %
-  frc_prefix=[frc_prefix,'_ERA5_'];
   if level==0
    nc_suffix='.nc';
   else
    nc_suffix=['.nc.',num2str(level)];
   end
   frcname=[frc_prefix,'Y',num2str(Y),...
-                      'M',num2str(M),nc_suffix];
+                      'M',num2str(sprintf(Mth_format,M)),nc_suffix];
 %
 % WKB file name
 %
-  wkb_prefix=[wkb_prefix,'_ERA5_'];
   brywkbname=[wkb_prefix,'Y',num2str(Y),...
-                     'M',num2str(M),nc_suffix];
+                     'M',num2str(sprintf(Mth_format,M)),nc_suffix];
   disp(' ')
   disp([' Making file: ',brywkbname])
   disp(['        from: ',frcname])
@@ -120,12 +122,12 @@ for Y=Ymin:Ymax
   close(nc)
 
   wkb_time=time;
-  wkb_cycle=wkb_time(end);
+  wkb_cycle=0;
 %
 % Create the boundary file
 %
   create_bryfile_wkb(brywkbname,grdname,CROCO_title,wkb_obc,...
-                     wkb_time,wkb_cycle,'clobber');
+                     wkb_time,wkb_cycle,'clobber',Yorig);
   disp(' ')
 %
 % 
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e62c6b3a7a7c1556ba65f58449bd48069206f56e..74e9ee833fa64894f224768ab53da3e42fc4da5a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,8 +6,21 @@ Release changelog are available here : https://gitlab.inria.fr/croco-ocean/croco
 
 ### Added
 
+- Issue 57 : update croco_frcbio creation with make_dust.m and make_ndepo.m (Thanks to C. Ethee and R. Person)
+
+
 ## Fixed
 
+- Issue 60 : fix overlaps problems with mercator daily and monthly forcing starting the first days of the month at 00:00h
+- Issue 59 : 
+  - propagate time unit, cycle_length and calendar attribute updates
+  - updates and fixes for bio into nestgui (interp_ini, interp_frcbio, interp_clim) 
+
+- Issue 51 :
+  - various fixes, cleaning and indentation in croco_tools
+  - add time unit, cycle_length and calendar attribute update
+  - refactorization for time unit, cycle_length and calendar attributea
+
 - Issue 50 : fix in mexcdf functionality for matlab 20xx versions (in particular matlab 2024)
 - Issue 49, 43 : add GSHHS coastline dataset in m_map private directory
 - Issue 44 : fix problem in editmask with longitude in 0-360° convention
@@ -15,6 +28,8 @@ Release changelog are available here : https://gitlab.inria.fr/croco-ocean/croco
 
 ## Changed
 
+- Issue 58 : cleaning and update in Preprocessing_tools/Bio
+ 
 ## Removed
 
 ### Deprecated
diff --git a/Nesting_tools/create_nestedbulk.m b/Nesting_tools/create_nestedbulk.m
index bb5b8ed6adbc7078e9d5942e2ec72d76b1d1808e..cfb377fdfa554d935596d387318bf4e33e2c3ca6 100644
--- a/Nesting_tools/create_nestedbulk.m
+++ b/Nesting_tools/create_nestedbulk.m
@@ -1,4 +1,4 @@
-function  create_bulk(blkname,parentname,grdname,title,bulkt,bulkc)
+function  create_bulk(blkname,parentname,grdname,title,bulkt,bulkc,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % 	Create an empty netcdf heat flux bulk bulk file
@@ -38,7 +38,18 @@ M=length(nc('eta_psi'));
 result=close(nc);
 Lp=L+1;
 Mp=M+1;
-
+%
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                            get_time_attributes(Yorig);
+%
 nw = netcdf(blkname, 'clobber');
 %result = redef(nw);
 
@@ -60,9 +71,8 @@ nw('bulk_time') = length(bulkt);
 nw{'bulk_time'}              = ncdouble('bulk_time');
 nw{'bulk_time'}.long_name    = ncchar('bulk formulation execution time');
 nw{'bulk_time'}.long_name    = 'bulk formulation execution time';
-nw{'bulk_time'}.units        = ncchar('days');
-nw{'bulk_time'}.units        = 'days';
-nw{'bulk_time'}.cycle_length = bulkc;
+write_time_attributes(nc,'bulk_time',bulkc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'tair'}             = ncdouble('bulk_time', 'eta_rho', 'xi_rho');
 nw{'tair'}.long_name   = ncchar('surface air temperature');
diff --git a/Nesting_tools/create_nestedclim.m b/Nesting_tools/create_nestedclim.m
index 9f38043d26bcf39cfe4bb7c32a5fb0d33e3a24e2..bdea5542ccde6c63a9ab484547ddd7b3b7c6ccfd 100644
--- a/Nesting_tools/create_nestedclim.m
+++ b/Nesting_tools/create_nestedclim.m
@@ -4,8 +4,8 @@ function ncclim=create_nestedclim(climfile,gridfile,parentfile,title,...
 				  tcycle,scycle,ucycle,vcycle,sshcycle,...
                   tbiol, cbiol,tpisces,cpisces,...
                   clobber,...    
-				  biol,pisces,timebiol,cyclebiol,timepisces,cyclepisce, ...
-                  namebiol,namepisces,unitbiol,unitpisces,hc,vtransform)
+				  biol,pisces,timebiol,cyclebiol,timepisces,cyclepisces, ...
+                  namebiol,namepisces,unitbiol,unitpisces,hc,vtransform,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function ncclim=create_climfile(climfile,gridfile,theta_s,...
@@ -62,6 +62,18 @@ function ncclim=create_nestedclim(climfile,gridfile,parentfile,title,...
 %  e-mail:Pierrick.Penven@ird.fr  
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 disp(' ')
 disp(' ')
 disp(['Creating the file : ',climfile])
@@ -95,11 +107,11 @@ ncclim('eta_rho') = Mp;
 ncclim('s_rho') = N;
 ncclim('s_w') = Np;
 ncclim('tracer') = 2;
-ncclim('tclm_time') = size(ttime);
-ncclim('sclm_time') = size(stime);
-ncclim('uclm_time') = size(utime);
-ncclim('vclm_time') = size(vtime);
-ncclim('ssh_time') = size(sshtime);
+ncclim('tclm_time') = length(ttime);
+ncclim('sclm_time') = length(stime);
+ncclim('uclm_time') = length(utime);
+ncclim('vclm_time') = length(vtime);
+ncclim('ssh_time') = length(sshtime);
 
 if biol
     for k=1:length(timebiol)
@@ -152,13 +164,13 @@ ncclim{'Vstretching'}.long_name = 'vertical terrain-following stretching functio
 %
 ncclim{'tstart'}.long_name = ncchar('start processing day');
 ncclim{'tstart'}.long_name = 'start processing day';
-ncclim{'tstart'}.units = ncchar('day');
-ncclim{'tstart'}.units = 'day';
+write_time_attributes(nc,'tstart',tcycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 ncclim{'tend'}.long_name = ncchar('end processing day');
 ncclim{'tend'}.long_name = 'end processing day';
-ncclim{'tend'}.units = ncchar('day');
-ncclim{'tend'}.units = 'day';
+write_time_attributes(nc,'tend',tcycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 ncclim{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
 ncclim{'theta_s'}.long_name = 'S-coordinate surface control parameter';
@@ -200,43 +212,39 @@ ncclim{'Cs_rho'}.field = 'Cs_rho, scalar';
 %
 ncclim{'tclm_time'}.long_name = ncchar('time for temperature climatology');
 ncclim{'tclm_time'}.long_name = 'time for temperature climatology';
-ncclim{'tclm_time'}.units = ncchar('day');
-ncclim{'tclm_time'}.units = 'day';
-ncclim{'tclm_time'}.cycle_length = tcycle;
 ncclim{'tclm_time'}.field = ncchar('tclm_time, scalar, series');
 ncclim{'tclm_time'}.field = 'tclm_time, scalar, series'  ;
+write_time_attributes(nc,'tclm_time',tcycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 ncclim{'sclm_time'}.long_name = ncchar('time for salinity climatology');
 ncclim{'sclm_time'}.long_name = 'time for salinity climatology';
-ncclim{'sclm_time'}.units = ncchar('day');
-ncclim{'sclm_time'}.units = 'day';
-ncclim{'sclm_time'}.cycle_length = scycle;
 ncclim{'sclm_time'}.field = ncchar('sclm_time, scalar, serie');
 ncclim{'sclm_time'}.field = 'sclm_time, scalar, serie';
+write_time_attributes(nc,'sclm_time',scycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 ncclim{'uclm_time'}.long_name = ncchar('time climatological u');
 ncclim{'uclm_time'}.long_name = 'time climatological u';
-ncclim{'uclm_time'}.units = ncchar('day');
-ncclim{'uclm_time'}.units = 'day';
-ncclim{'uclm_time'}.cycle_length = ucycle;
 ncclim{'uclm_time'}.field = ncchar('uclm_time, scalar, serie');
 ncclim{'uclm_time'}.field = 'uclm_time, scalar, serie';
+write_time_attributes(nc,'uclm_time',ucycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 ncclim{'vclm_time'}.long_name = ncchar('time climatological v');
 ncclim{'vclm_time'}.long_name = 'time climatological v';
-ncclim{'vclm_time'}.units = ncchar('day');
-ncclim{'vclm_time'}.units = 'day';
-ncclim{'vclm_time'}.cycle_length = vcycle;
 ncclim{'vclm_time'}.field = ncchar('vclm_time, scalar, serie');
 ncclim{'vclm_time'}.field = 'vclm_time, scalar, serie';
+write_time_attributes(nc,'vclm_time',vcycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
+
 %
 ncclim{'ssh_time'}.long_name = ncchar('time for sea surface height');
 ncclim{'ssh_time'}.long_name = 'time for sea surface height';
-ncclim{'ssh_time'}.units = ncchar('day');
-ncclim{'ssh_time'}.units = 'day';
-ncclim{'ssh_time'}.cycle_length = sshcycle;
 ncclim{'ssh_time'}.field = ncchar('ssh_time, scalar, serie');
 ncclim{'ssh_time'}.field = 'ssh_time, scalar, serie';
+write_time_attributes(nc,'ssh_time',sshcycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 if biol
     for k=1:length(timebiol)
@@ -244,12 +252,12 @@ if biol
         ncclim{char(timebiol(k))} = ncdouble(char(timebiol(k,:)));
         ncclim{char(timebiol(k))}.long_name = ncchar(char(timebiol(k)));
         ncclim{char(timebiol(k))}.long_name = char(timebiol(k));
-        ncclim{char(timebiol(k))}.units = ncchar('day');
-        ncclim{char(timebiol(k))}.units = 'day';
-        ncclim{char(timebiol(k))}.cycle_length = char(timebiol(k));
         ncclim{char(timebiol(k))}.field = ncchar([char(timebiol(k)),', scalar, series']);
         ncclim{char(timebiol(k))}.field = [char(timebiol(k)),', scalar, series']  ;
-%     
+        write_time_attributes(nc,char(timebiol(k)),cbiol,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
+
+        %     
        % disp(char(namebiol(k)))
         ncclim{char(namebiol(k))} = ncdouble(char(timebiol(k,:)),'s_rho','eta_rho','xi_rho');
         ncclim{char(namebiol(k))}.long_name = ncchar(char(namebiol(k)));
@@ -269,11 +277,10 @@ if pisces
         ncclim{char(timepisces(k))} = ncdouble(char(timepisces(k,:)));
         ncclim{char(timepisces(k))}.long_name = ncchar(char(timepisces(k)));
         ncclim{char(timepisces(k))}.long_name = char(timepisces(k));
-        ncclim{char(timepisces(k))}.units = ncchar('day');
-        ncclim{char(timepisces(k))}.units = 'day';
-        ncclim{char(timepisces(k))}.cycle_length = ncchar([char(namepisces(k)),', scalar, series']);
         ncclim{char(timepisces(k))}.field = ncchar([char(timepisces(k)), ',scalar, series']);
         ncclim{char(timepisces(k))}.field = [char(timepisces(k)), ',scalar, series']  ;
+        write_time_attributes(nc,char(timepisces(k)),cpisces,time_unit_att,time_second_unit_att,...
+                                calendar_att,insecond,add_cycle);
         %
         %disp(char(namepisces(k)))
         ncclim{char(namepisces(k))} = ncdouble(char(timepisces(k,:)),'s_rho','eta_rho','xi_rho');
diff --git a/Nesting_tools/create_nesteddust.m b/Nesting_tools/create_nesteddust.m
index ffb0ac733a7b001744d34f61932b524b11032a3f..e8ee205a45a6b2d30ec1a5854b85ff771a1416db 100644
--- a/Nesting_tools/create_nesteddust.m
+++ b/Nesting_tools/create_nesteddust.m
@@ -30,6 +30,17 @@ function  create_nesteddust(dustname,parentname,grdname,title,dustt,dustc)
 %  e-mail:Pierrick.Penven@ird.fr  
 %  Update : Gildas Cambon 13 Oct 2009
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 nc=netcdf(grdname);
 L=length(nc('xi_psi'));
 M=length(nc('eta_psi'));
@@ -56,11 +67,10 @@ nw('dust_time') = length(dustt);
 nw{'dust_time'} = ncdouble('dust_time');
 nw{'dust_time'}.long_name = ncchar('dust time');
 nw{'dust_time'}.long_name = 'dust time';
-nw{'dust_time'}.units = ncchar('days');
-nw{'dust_time'}.units = 'days';
-nw{'dust_time'}.cycle_length = dustc;
 nw{'dust_time'}.field = ncchar('time, scalar, series');
 nw{'dust_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'dust_time',dustc,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 
 nw{'dust'} = ncdouble('dust_time', 'eta_rho', 'xi_rho');
 nw{'dust'}.long_name = ncchar('Fe Dust Deposition');
@@ -70,7 +80,39 @@ nw{'dust'}.units = 'nmol Fe m-3';
 nw{'dust'}.field = ncchar('Fe Dust Deposition, scalar, series');
 nw{'dust'}.field = 'Fe Dust Deposition, scalar, series';
 
-%endef(nw);
+nw{'dustfer'} = ncdouble('dust_time', 'eta_rho', 'xi_rho');
+nw{'dustfer'}.long_name = ncchar('Fe Dust Deposition');
+nw{'dustfer'}.long_name = 'Fe Dust Deposition';
+nw{'dustfer'}.units = ncchar('Kg m-2 s-1');
+nw{'dustfer'}.units = 'Kg m-2 s-1';
+nw{'dustfer'}.field = ncchar('dustfer, scalar, series');
+nw{'dustfer'}.field = 'dustfer, scalar, series';
+%
+nw{'dustpo4'} = ncdouble('dust_time', 'eta_rho', 'xi_rho');
+nw{'dustpo4'}.long_name = ncchar('PO4 Dust Deposition');
+nw{'dustpo4'}.long_name = 'PO4 Dust Deposition';
+nw{'dustpo4'}.units = ncchar('Kg m-2 s-1');
+nw{'dustpo4'}.units = 'Kg m-2 s-1';
+nw{'dustpo4'}.field = ncchar('dustpo4, scalar, series');
+nw{'dustpo4'}.field = 'dustpo4, scalar, series';
+%
+nw{'dustsi'} = ncdouble('dust_time', 'eta_rho', 'xi_rho');
+nw{'dustsi'}.long_name = ncchar('Si Dust Deposition');
+nw{'dustsi'}.long_name = 'Si Dust Deposition';
+nw{'dustsi'}.units = ncchar('Kg m-2 s-1');
+nw{'dustsi'}.units = 'Kg m-2 s-1';
+nw{'dustsi'}.field = ncchar('dustsi, scalar, series');
+nw{'dustsi'}.field = 'dustsi, scalar, series';
+%
+nw{'solubility2'} = ncdouble('dust_time', 'eta_rho', 'xi_rho');
+nw{'solubility2'}.long_name = ncchar('Fe solubility from Mahowald');
+nw{'solubility2'}.long_name = 'Fe solubility from Mahowald';
+nw{'solubility2'}.units = ncchar('%');
+nw{'solubility2'}.units = '%';
+nw{'solubility2'}.field = ncchar('solubility2, scalar, series');
+nw{'solubility2'}.field = 'solubility2, scalar, series';
+
+endef(nw);
 
 %
 % Create global attributes
diff --git a/Nesting_tools/create_nestedforcing.m b/Nesting_tools/create_nestedforcing.m
index 2a7c37ce43b9be1b5e189d2aa8724a1678401a8e..dfc2d432990fffe421ee05e9b871c0206ce28485 100644
--- a/Nesting_tools/create_nestedforcing.m
+++ b/Nesting_tools/create_nestedforcing.m
@@ -1,6 +1,6 @@
 function  create_nestedforcing(frcname,parentname,grdname,title,smst,...
                          shft,swft,srft,sstt,ssst,smsc,...
-                         shfc,swfc,srfc,sstc,sssc)
+                         shfc,swfc,srfc,sstc,sssc,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % 	Create an empty netcdf forcing file
@@ -38,6 +38,18 @@ M=length(nc('eta_psi'));
 close(nc);
 Lp=L+1;
 Mp=M+1;
+%
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+      get_time_attributes(Yorig);
+%
 nw = netcdf(frcname, 'clobber');
 %redef(nw);
 %
@@ -63,57 +75,52 @@ nw('sss_time') = length(ssst);
 nw{'sms_time'} = ncdouble('sms_time');
 nw{'sms_time'}.long_name = ncchar('surface momentum stress time');
 nw{'sms_time'}.long_name = 'surface momentum stress time';
-nw{'sms_time'}.units = ncchar('days');
-nw{'sms_time'}.units = 'days';
-nw{'sms_time'}.cycle_length = smsc;
 nw{'sms_time'}.field = ncchar('time, scalar, series');
 nw{'sms_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'sms_time',smsc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'shf_time'} = ncdouble('shf_time');
 nw{'shf_time'}.long_name = ncchar('surface heat flux time');
 nw{'shf_time'}.long_name = 'surface heat flux time';
-nw{'shf_time'}.units = ncchar('days');
-nw{'shf_time'}.units = 'days';
-nw{'shf_time'}.cycle_length =shfc ;
 nw{'shf_time'}.field = ncchar('time, scalar, series');
 nw{'shf_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'shf_time',shfc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'swf_time'} = ncdouble('swf_time');
 nw{'swf_time'}.long_name = ncchar('surface freshwater flux time');
 nw{'swf_time'}.long_name = 'surface freshwater flux time';
-nw{'swf_time'}.units = ncchar('days');
-nw{'swf_time'}.units = 'days';
-nw{'swf_time'}.cycle_length = swfc;
 nw{'swf_time'}.field = ncchar('time, scalar, series');
 nw{'swf_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'swf_time',swfc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 
 nw{'sst_time'} = ncdouble('sst_time');
 nw{'sst_time'}.long_name = ncchar('sea surface temperature time');
 nw{'sst_time'}.long_name = 'sea surface temperature time';
-nw{'sst_time'}.units = ncchar('days');
-nw{'sst_time'}.units = 'days';
-nw{'sst_time'}.cycle_length = sstc;
 nw{'sst_time'}.field = ncchar('time, scalar, series');
 nw{'sst_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'sst_time',sstc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
+
 
 nw{'sss_time'} = ncdouble('sss_time');
 nw{'sss_time'}.long_name = ncchar('sea surface salinity time');
 nw{'sss_time'}.long_name = 'sea surface salinity time';
-nw{'sss_time'}.units = ncchar('days');
-nw{'sss_time'}.units = 'days';
-nw{'sss_time'}.cycle_length = sssc;
 nw{'sss_time'}.field = ncchar('time, scalar, series');
 nw{'sss_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'sss_time',sssc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'srf_time'} = ncdouble('srf_time');
 nw{'srf_time'}.long_name = ncchar('solar shortwave radiation time');
 nw{'srf_time'}.long_name = 'solar shortwave radiation time';
-nw{'srf_time'}.units = ncchar('days');
-nw{'srf_time'}.units = 'days';
-nw{'srf_time'}.cycle_length = srfc;
 nw{'srf_time'}.field = ncchar('time, scalar, series');
 nw{'srf_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'srf_time',srfc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'sustr'} = ncdouble('sms_time', 'eta_u', 'xi_u');
 nw{'sustr'}.long_name = ncchar('surface u-momentum stress');
diff --git a/Nesting_tools/create_nestedinitial.m b/Nesting_tools/create_nestedinitial.m
index 7bb1e37ec0b8e055d06d9e02787e24d651d95d08..6fb41bfbd817dea4140bfd3ecd1e9468651a44a4 100644
--- a/Nesting_tools/create_nestedinitial.m
+++ b/Nesting_tools/create_nestedinitial.m
@@ -1,7 +1,7 @@
 function ncini=create_nestedinitial(inifile,gridfile,parentfile,title,...
 				    theta_s,theta_b,Tcline,N,time,clobber,...
 				    biol,pisces,namebiol,namepisces,...
-				    unitbiol,unitpisces,hc,vtransform)
+				    unitbiol,unitpisces,hc,vtransform,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function ncini=create_inifile(inifile,gridfile,theta_s,... 
@@ -68,6 +68,17 @@ elseif nargin <18
     vtransform = 1; 
 end
 %
+% options for write_time_attributes
+insecond = 1  ;
+add_cycle = 0 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 %  Read the grid file
 %
 nc=netcdf(gridfile, 'nowrite');
@@ -143,11 +154,13 @@ ncini{'tstart'}.long_name = ncchar('start processing day');
 ncini{'tstart'}.long_name = 'start processing day';
 ncini{'tstart'}.units = ncchar('day');
 ncini{'tstart'}.units = 'day';
+write_time_attributes(nc,'tstart','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 ncini{'tend'}.long_name = ncchar('end processing day');
 ncini{'tend'}.long_name = 'end processing day';
-ncini{'tend'}.units = ncchar('day');
-ncini{'tend'}.units = 'day';
+write_time_attributes(nc,'tend','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 ncini{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
 ncini{'theta_s'}.long_name = 'S-coordinate surface control parameter';
@@ -189,10 +202,10 @@ ncini{'Cs_rho'}.field = 'Cs_rho, scalar';
 %
 ncini{'scrum_time'}.long_name = ncchar('time since initialization');
 ncini{'scrum_time'}.long_name = 'time since initialization';
-ncini{'scrum_time'}.units = ncchar('second');
-ncini{'scrum_time'}.units = 'second';
 ncini{'scrum_time'}.field = ncchar('time, scalar, series');
 ncini{'scrum_time'}.field = 'time, scalar, series';
+write_time_attributes(nc,'scrum_time','',time_unit_att,time_second_unit_att,...
+                      calendar_att,1,0);
 %
 ncini{'u'}.long_name = ncchar('u-momentum component');
 ncini{'u'}.long_name = 'u-momentum component';
diff --git a/Nesting_tools/create_nestedndepo.m b/Nesting_tools/create_nestedndepo.m
new file mode 100644
index 0000000000000000000000000000000000000000..b1b0128ea9e711e6aa78372860387ea048c10094
--- /dev/null
+++ b/Nesting_tools/create_nestedndepo.m
@@ -0,0 +1,113 @@
+function  create_nestedndepo(ndeponame,parentname,grdname,title,ndepot,ndepoc)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% 	Create an empty netcdf ndepo forcing file (for PISCES)
+%       ndeponame: name of the ndepo file
+%       grdname: name of the grid file
+%       title: title in the netcdf file  
+%
+%  Further Information:  
+%  http://www.croco-ocean.org
+%  
+%  This file is part of CROCOTOOLS
+%
+%  CROCOTOOLS is free software; you can redistribute it and/or modify
+%  it under the terms of the GNU General Public License as published
+%  by the Free Software Foundation; either version 2 of the License,
+%  or (at your option) any later version.
+%
+%  CROCOTOOLS is distributed in the hope that it will be useful, but
+%  WITHOUT ANY WARRANTY; without even the implied warranty of
+%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%  GNU General Public License for more details.
+%
+%  You should have received a copy of the GNU General Public License
+%  along with this program; if not, write to the Free Software
+%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+%  MA  02111-1307  USA
+%
+%  Copyright (c) 2004-2006 by Pierrick Penven 
+%  e-mail:Pierrick.Penven@ird.fr  
+%  Update : Gildas Cambon 13 Oct 2009
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+nc=netcdf(grdname);
+L=length(nc('xi_psi'));
+M=length(nc('eta_psi'));
+close(nc);
+Lp=L+1;
+Mp=M+1;
+nw = netcdf(ndeponame, 'write');
+%redef(nw);
+%
+%  Create dimensions
+%
+nw('xi_u') = L;
+nw('eta_u') = Mp;
+nw('xi_v') = Lp;
+nw('eta_v') = M;
+nw('xi_rho') = Lp;
+nw('eta_rho') = Mp;
+nw('xi_psi') = L;
+nw('eta_psi') = M;
+nw('ndepo_time') = length(ndepot);
+%
+%  Create variables and attributes
+%
+nw{'ndepo_time'} = ncdouble('ndepo_time');
+nw{'ndepo_time'}.long_name = ncchar('ndepo time');
+nw{'ndepo_time'}.long_name = 'ndepo time';
+nw{'ndepo_time'}.units = ncchar('days');
+nw{'ndepo_time'}.units = 'days';
+nw{'ndepo_time'}.cycle_length = ndepoc;
+nw{'ndepo_time'}.field = ncchar('time, scalar, series');
+nw{'ndepo_time'}.field = 'time, scalar, series';
+
+%
+nw{'ndepo'} = ncdouble('ndepo_time', 'eta_rho', 'xi_rho');
+nw{'ndepo'}.long_name = ncchar('Nitrogen Deposition');
+nw{'ndepo'}.long_name = 'Nitrogen Deposition';
+nw{'ndepo'}.units = ncchar('KgN m-2 s-1');
+nw{'ndepo'}.units = 'KgN m-2 s-1';
+nw{'ndepo'}.field = ncchar('ndepo, scalar, series');
+nw{'ndepo'}.field = 'ndepo, scalar, series';
+%
+nw{'noyndepo'} = ncdouble('ndepo_time', 'eta_rho', 'xi_rho');
+nw{'noyndepo'}.long_name = ncchar('NOy Deposition');
+nw{'noyndepo'}.long_name = 'NOy Deposition';
+nw{'noyndepo'}.units = ncchar('KgN m-2 s-1');
+nw{'noyndepo'}.units = 'KgN m-2 s-1';
+nw{'noyndepo'}.field = ncchar('noyndepo, scalar, series');
+nw{'noyndepo'}.field = 'noyndepo, scalar, series';
+%
+nw{'nhxndepo'} = ncdouble('ndepo_time', 'eta_rho', 'xi_rho');
+nw{'nhxndepo'}.long_name = ncchar('NHx Deposition');
+nw{'nhxndepo'}.long_name = 'NHx Deposition';
+nw{'nhxndepo'}.units = ncchar('KgN m-2 s-1');
+nw{'nhxndepo'}.units = 'KgN m-2 s-1';
+nw{'nhxndepo'}.field = ncchar('nhxndepo, scalar, series');
+nw{'nhxndepo'}.field = 'nhxndepo, scalar, series';
+%
+%endef(nw);
+
+%
+% Create global attributes
+%
+
+nw.title = ncchar(title);
+nw.title = title;
+nw.date = ncchar(date);
+nw.date = date;
+nw.grd_file = ncchar(grdname);
+nw.grd_file = grdname;
+nw.parent_file = ncchar(parentname);
+nw.parent_file = parentname;
+
+%
+% Write time variables
+%
+
+nw{'ndepo_time'}(:) = ndepot;
+
+
+close(nw);
+return
diff --git a/Nesting_tools/interp_dust.m b/Nesting_tools/interp_dust.m
index cf9305e852bd12bb43cb7bbdb4d966b8bc87dec6..31cdf89b32e29982538ab2bed74ee32da39924dc 100644
--- a/Nesting_tools/interp_dust.m
+++ b/Nesting_tools/interp_dust.m
@@ -50,4 +50,5 @@ switch Answer
   handles.childdust=childname;
 end
 nested_dust(handles.childgrid,handles.parentdust,handles.childdust)
+nested_ndepo(handles.childgrid,handles.parentdust,handles.childdust)
 return
diff --git a/Nesting_tools/nested_clim.m b/Nesting_tools/nested_clim.m
index b38472855724693a3834e1bcb6a00048c98051ed..96bdf80a906917fc068ce04a3675e4c733618186 100644
--- a/Nesting_tools/nested_clim.m
+++ b/Nesting_tools/nested_clim.m
@@ -1,12 +1,12 @@
 function nested_clim(child_grd,parent_clim,child_clim,...
-                     vertical_correc,extrapmask,biol,bioebus,pisces)
+  vertical_correc,extrapmask,biol,bioebus,pisces)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  compute the climatology of the embedded grid
 %
-%  Further Information:  
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -24,8 +24,8 @@ function nested_clim(child_grd,parent_clim,child_clim,...
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2004-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2004-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
@@ -46,9 +46,8 @@ tpisces=[];cpisces=[];
 
 
 % Check type of clim file
-%
-if nvar <= 31
-elseif (nvar <=  41 & biol)
+if biol
+  if (bioebus~=1) %% for biol + npzd
     timebiol={'no3_time';'o2_time';'chla_time';'phyto_time';'zoo_time'};
     cyclebiol={'no3_cyle';'o2_cycle';'chla_cycle';'phyto_cycle';'zoo_cycle'};
     namebiol={'NO3';'O2';'CHLA';'PHYTO';'ZOO'};
@@ -57,30 +56,27 @@ elseif (nvar <=  41 & biol)
     disp(['Compute Biogeochemical variables type NPZD : '])
     disp(['NChlPZD or N2ChlPZD2                     '])
     disp('==========================')
-elseif (46 <= nvar <=47 & biobus)
+  else % for biol + bioebus)
     timebiol={'no3_time';'o2_time';'chla_time';'sphyto_time';'lphyto_time';'szoo_time';'lzoo_time';'n2o_time'};
     cyclebiol={'no3_cyle';'o2_cycle';'chla_cycle';'sphyto_cycle';'lphyto_cycle';'szoo_cycle';'lzoo_cycle';'n2o_cycle'};
     namebiol={'NO3';'O2';'CHLA';'SPHYTO';'LPHYTO';'SZOO';'LZOO';'N2O'};
     unitbiol={'mMol N m-3';'mMol O m-3';'mg C l-1';'mMol N m-3';'mMol N m-3';'mMol N m-3';'mMol N m-3';'mMol N m-3'};
     disp(['Compute Biological variables for BIOEBUS : '])
     disp('==========================')
-elseif (pisces & nvar>=47)
-    timepisces={'no3_time';'po4_time';'si_time';'o2_time';'dic_time';'talk_time';'doc_time';'fer_time'};
-    cyclepisces={'no3_cycle';'po4_cycle';'si_cycle';'o2_cycle';'dic_cycle';'talk_cycle';'doc_cycle';'fer_cycle'};
-    namepisces={'NO3';'PO4';'Si';'O2';'DIC';'TALK';'DOC';'FER'};
-    unitpisces={'mMol N m-3';'mMol P m-3';'mMol Si m-3';'mMol O m-3';'mMol C m-3';'mMol C m-3';'mMol C m-3';'uMol Fe m-3'};
-    disp('Compute Biogeochemical variables for PISCES')
-    disp('=========================')
-else
-    error(sprintf(['You don''t have the neccesary variables in the clim file. \n',...
-        'or you didn''t choose the right bio. model. \n',...
-        'Check croco_ini.nc parent file and make_clim.m']))
+  end
+elseif (pisces)
+  timepisces={'no3_time';'po4_time';'si_time';'o2_time';'dic_time';'talk_time';'doc_time';'fer_time'};
+  cyclepisces={'no3_cycle';'po4_cycle';'si_cycle';'o2_cycle';'dic_cycle';'talk_cycle';'doc_cycle';'fer_cycle'};
+  namepisces={'NO3';'PO4';'Si';'O2';'DIC';'TALK';'DOC';'FER'};
+  unitpisces={'mMol N m-3';'mMol P m-3';'mMol Si m-3';'mMol O m-3';'mMol C m-3';'mMol C m-3';'mMol C m-3';'uMol Fe m-3'};
+  disp('Compute Biogeochemical variables for PISCES')
+  disp('=========================')
 end
-%
+
 % Title
 %
 title=['Climatology file for the embedded grid :',child_clim,...
-       ' using parent forcing file: ',parent_clim];
+  ' using parent forcing file: ',parent_clim];
 disp(' ')
 disp(title)
 if extrapmask==1
@@ -93,7 +89,7 @@ if vertical_correc==1
   disp('===============')
 end
 %
-if pisces & biol 
+if pisces & biol
   error(['Both Biol NPZD and Pisces are ON, no possible yet...!'])
 end
 %
@@ -132,9 +128,9 @@ vtransform=nc{'Vtransform'}(:);
 hc = nc{'hc'}(:);
 disp([' Use parent VTRANSFORM = ',num2str(vtransform)])
 if ~exist('vtransform') | isempty(vtransform)
-    disp([' No VTRANSFORM parameter found'])
-    disp([' Use the default one VTRANSFORM = 1'])
-    vtransform=1;
+  disp([' No VTRANSFORM parameter found'])
+  disp([' Use the default one VTRANSFORM = 1'])
+  vtransform=1;
 end
 ttime = nc{'tclm_time'}(:);
 tcycle = nc{'tclm_time'}.cycle_length(:);
@@ -148,23 +144,30 @@ sshtime = nc{'ssh_time'}(:);
 sshcycle = nc{'ssh_time'}.cycle_length(:);
 %
 if biol==1
-    for k=1:length(namebiol)
-        eval([char(timebiol(k)),'=nc{''',char(timebiol(k)),'''}(:);']);
-        eval([char(cyclebiol(k)),'=nc{''',char(timebiol(k)),'''}.cycle_length(:);']);
-        %
-        eval(['tbiol(k,:)=',char(timebiol(k)),';']);
-        eval(['cbiol(k,:)=',char(cyclebiol(k)),';']);
-end
+  for k=1:length(namebiol)
+    if strcmp(char(namebiol{k}), 'NO3') || strcmp(char(namebiol{k}), 'O2') || strcmp(char(namebiol{k}), 'N2O')
+      skip = 3;  % for no3_time + o2_time + n2o_time % a bit sloppy
+                % wa tale value every 3 month to have kinf of seasonal ...
+    else
+      skip = 1;
+    end
+
+    eval([char(timebiol(k)),'=nc{''',char(timebiol(k)),'''}(1:skip:end,:);']);
+    eval([char(cyclebiol(k)),'=nc{''',char(timebiol(k)),'''}.cycle_length(:);']);
+
+    eval(['tbiol(k,:)=',char(timebiol(k)),';']);
+    eval(['cbiol(k,:)=',char(cyclebiol(k)),';']);
+  end
 end
 %
 if pisces==1
-    for k=1:length(namepisces)
-        eval([char(timepisces(k)),'=nc{''',char(timepisces(k)),'''}(:);']);
-        eval([char(cyclepisces(k)),'=nc{''',char(timepisces(k)),'''}.cycle_length(:);']);
-        %
-        eval(['tpisces(k,:)=',char(timepisces(k)),';']);
-        eval(['cpisces(k,:)=',char(cyclepisces(k)),';']);
-    end
+  for k=1:length(namepisces)
+    eval([char(timepisces(k)),'=nc{''',char(timepisces(k)),'''}(:);']);
+    eval([char(cyclepisces(k)),'=nc{''',char(timepisces(k)),'''}.cycle_length(:);']);
+    %
+    eval(['tpisces(k,:)=',char(timepisces(k)),';']);
+    eval(['cpisces(k,:)=',char(cyclepisces(k)),';']);
+  end
 end
 %
 result=close(nc);
@@ -178,15 +181,16 @@ end
 %
 disp(' ')
 disp(' Create the climatology file...')
+%
 ncclim=create_nestedclim(child_clim,child_grd,parent_clim,title,...
-			 theta_s,theta_b,Tcline,N,...
-			 ttime,stime,utime,vtime,sshtime,...
-			 tcycle,scycle,ucycle,vcycle,sshcycle,...
-             tbiol,cbiol,tpisces, cpisces, ...
-             'clobber',...
-			 biol,pisces,...
-             timebiol, cyclebiol,timepisces,cyclepisces,...
-             namebiol,namepisces,unitbiol,unitpisces,hc,vtransform);
+  theta_s,theta_b,Tcline,N,...
+  ttime,stime,utime,vtime,sshtime,...
+  tcycle,scycle,ucycle,vcycle,sshcycle,...
+  tbiol,cbiol,tpisces, cpisces, ...
+  'clobber',...
+  biol,pisces,...
+  timebiol, cyclebiol,timepisces,cyclepisces,...
+  namebiol,namepisces,unitbiol,unitpisces,hc,vtransform);
 %
 % parent indices
 %
@@ -207,66 +211,66 @@ jrchild=(jmin+0.5-0.5/refinecoeff:1/refinecoeff:jmax+0.5+0.5/refinecoeff);
 [ichildgrd_v,jchildgrd_v]=meshgrid(irchild,jpchild);
 %
 % interpolations
-% 
+%
 disp(' ')
-disp(' Do the interpolations...')                     
+disp(' Do the interpolations...')
 np=netcdf(parent_clim);
 disp('u...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar4d(np,ncclim,igrd_u,jgrd_u,ichildgrd_u,jchildgrd_u,'u',mask,tindex,N)
 end
 disp('v...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar4d(np,ncclim,igrd_v,jgrd_v,ichildgrd_v,jchildgrd_v,'v',mask,tindex,N)
 end
 disp('zeta...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar3d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'SSH',mask,tindex)
 end
 disp('ubar...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar3d(np,ncclim,igrd_u,jgrd_u,ichildgrd_u,jchildgrd_u,'ubar',mask,tindex)
 end
 disp('vbar...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar3d(np,ncclim,igrd_v,jgrd_v,ichildgrd_v,jchildgrd_v,'vbar',mask,tindex)
 end
 disp('temp...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar4d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'temp',mask,tindex,N)
 end
 disp('salt...')
 for tindex=1:length(climtime)
-  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))]) 
+  disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
   interpvar4d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'salt',mask,tindex,N)
 end
 %
 %%
 %
 if biol
-    for k=1:length(namebiol)
-        disp(char(namebiol(k)))
-        for tindex=1:length(tbiol(k,:))
-            disp([' Time index : ',num2str(tindex),' of ',num2str(length(tbiol(k,:)))])
-            interpvar4d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,char(namebiol(k)),mask,tindex,N)
-        end
+  for k=1:length(namebiol)
+    disp(char(namebiol(k)))
+    for tindex=1:length(tbiol(k,:))
+      disp([' Time index : ',num2str(tindex),' of ',num2str(length(tbiol(k,:)))])
+      interpvar4d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,char(namebiol(k)),mask,tindex,N)
     end
+  end
 end
 %
 if pisces
-    for k=1:length(namepisces)
-        disp(char(namepisces(k)))
-        for tindex=1:length(tpisces(k,:))
-            disp([' Time index : ',num2str(tindex),' of ',num2str(length(tpisces(k,:)))])
-            interpvar4d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,char(namepisces(k)),mask,tindex,N)
-        end
+  for k=1:length(namepisces)
+    disp(char(namepisces(k)))
+    for tindex=1:length(tpisces(k,:))
+      disp([' Time index : ',num2str(tindex),' of ',num2str(length(tpisces(k,:)))])
+      interpvar4d(np,ncclim,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,char(namepisces(k)),mask,tindex,N)
     end
+  end
 end
 close(np);
 close(ncclim);
@@ -274,33 +278,33 @@ close(ncclim);
 %  Vertical corrections
 %
 if (vertical_correc==1)
-    disp('Process variable physical variables')
-    for tindex=1:length(climtime)
-        disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
-        vert_correc(child_clim,tindex,0,0,namebiol,namepisces)
-    end
-    %%
-    if biol
-        disp('Process variable NPZD')
-        for k=1:length(namebiol)
-            disp(char(namebiol(k)))
-            for tindex=1:length(tbiol(k,:))
-                disp([' Time index : ',num2str(tindex),' of ',num2str(length(tbiol(k,:)))])
-                vert_correc_onefield(child_clim,tindex,char(namebiol(k)))
-            end
-        end
+  disp('Process variable physical variables')
+  for tindex=1:length(climtime)
+    disp([' Time index : ',num2str(tindex),' of ',num2str(length(climtime))])
+    vert_correc(child_clim,tindex,0,0,namebiol,namepisces)
+  end
+  %%
+  if biol
+    disp('Process variable NPZD')
+    for k=1:length(namebiol)
+      disp(char(namebiol(k)))
+      for tindex=1:length(tbiol(k,:))
+        disp([' Time index : ',num2str(tindex),' of ',num2str(length(tbiol(k,:)))])
+        vert_correc_onefield(child_clim,tindex,char(namebiol(k)))
+      end
     end
-    %%
-    if pisces
-        disp('Process variable PISCES')
-        for k=1:length(namepisces)
-            disp(char(namepisces(k)))
-            for tindex=1:length(tpisces(k,:))
-                disp([' Time index : ',num2str(tindex),' of ',num2str(length(tpisces(k,:)))])
-                vert_correc_onefield(child_clim,tindex,char(namepisces(k)))
-            end
-        end
+  end
+  %%
+  if pisces
+    disp('Process variable PISCES')
+    for k=1:length(namepisces)
+      disp(char(namepisces(k)))
+      for tindex=1:length(tpisces(k,:))
+        disp([' Time index : ',num2str(tindex),' of ',num2str(length(tpisces(k,:)))])
+        vert_correc_onefield(child_clim,tindex,char(namepisces(k)))
+      end
     end
+  end
 end
 %
 % Make a plot
diff --git a/Nesting_tools/nested_dust.m b/Nesting_tools/nested_dust.m
index 98a94db76135ef88054de83b2056e324062db237..10d34370bd24cac9d7476cbd2b2c0d01e9d79b69 100644
--- a/Nesting_tools/nested_dust.m
+++ b/Nesting_tools/nested_dust.m
@@ -102,6 +102,10 @@ nc=netcdf(child_dust,'write');
 disp('dust...')
 for tindex=1:length(dustt)
   interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'dust',mask,tindex)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'dustfer',mask,tindex)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'dustpo4',mask,tindex)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'dustsi',mask,tindex)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'solubility2',mask,tindex)
 end
 result=close(np);
 result=close(nc);
diff --git a/Nesting_tools/nested_ndepo.m b/Nesting_tools/nested_ndepo.m
new file mode 100644
index 0000000000000000000000000000000000000000..63d6f102cb65fa6216f1d960070744d8d9147850
--- /dev/null
+++ b/Nesting_tools/nested_ndepo.m
@@ -0,0 +1,118 @@
+function nested_ndepo(child_grd,parent_ndepo,child_ndepo)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  compute the ndepo file (PISCES biogeochemical model) 
+%  of the embedded grid
+%
+%  Further Information:  
+%  http://www.croco-ocean.org
+%  
+%  This file is part of CROCOTOOLS
+%
+%  CROCOTOOLS is free software; you can redistribute it and/or modify
+%  it under the terms of the GNU General Public License as published
+%  by the Free Software Foundation; either version 2 of the License,
+%  or (at your option) any later version.
+%
+%  CROCOTOOLS is distributed in the hope that it will be useful, but
+%  WITHOUT ANY WARRANTY; without even the implied warranty of
+%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%  GNU General Public License for more details.
+%
+%  You should have received a copy of the GNU General Public License
+%  along with this program; if not, write to the Free Software
+%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+%  MA  02111-1307  USA
+%
+%  Copyright (c) 2004-2006 by Pierrick Penven 
+%  e-mail:Pierrick.Penven@ird.fr  
+%  Update : Gildas Cambon: 13 Nov 2009
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+extrapmask=0;
+%
+% Title
+%
+title=['ndepo file for the embedded grid :',child_ndepo,...
+       ' using parent ndepo file: ',parent_ndepo];
+disp(' ')
+disp(title)
+%
+% Read in the embedded grid
+%
+disp(' ')
+disp(' Read in the embedded grid...')
+nc=netcdf(child_grd);
+parent_grd=nc.parent_grid(:);
+imin=nc{'grd_pos'}(1);
+imax=nc{'grd_pos'}(2);
+jmin=nc{'grd_pos'}(3);
+jmax=nc{'grd_pos'}(4);
+refinecoeff=nc{'refine_coef'}(:);
+result=close(nc);
+nc=netcdf(parent_grd);
+Lp=length(nc('xi_rho'));
+Mp=length(nc('eta_rho'));
+if extrapmask==1
+  mask=nc{'mask_rho'}(:);
+else
+  mask=[];
+end
+result=close(nc);
+%
+% Read in the parent ndepo file
+%
+disp(' ')
+disp(' Read in the parent ndepo file...')
+nc = netcdf(parent_ndepo);
+ndepot = nc{'ndepo_time'}(:);
+ndepoc = nc{'ndepo_time'}.cycle_length(:);
+result=close(nc);
+%
+% Create the ndepo file
+%
+disp(' ')
+disp(' Create the ndepo file...')
+create_nestedndepo(child_ndepo,parent_ndepo,child_grd,title,...
+		  ndepot,ndepoc)
+%
+% parent indices
+%
+[igrd_r,jgrd_r]=meshgrid((1:1:Lp),(1:1:Mp));
+[igrd_p,jgrd_p]=meshgrid((1:1:Lp-1),(1:1:Mp-1));
+[igrd_u,jgrd_u]=meshgrid((1:1:Lp-1),(1:1:Mp));
+[igrd_v,jgrd_v]=meshgrid((1:1:Lp),(1:1:Mp-1));
+%
+% the children indices
+%
+ipchild=(imin:1/refinecoeff:imax);
+jpchild=(jmin:1/refinecoeff:jmax);
+irchild=(imin+0.5-0.5/refinecoeff:1/refinecoeff:imax+0.5+0.5/refinecoeff);
+jrchild=(jmin+0.5-0.5/refinecoeff:1/refinecoeff:jmax+0.5+0.5/refinecoeff);
+[ichildgrd_p,jchildgrd_p]=meshgrid(ipchild,jpchild);
+[ichildgrd_r,jchildgrd_r]=meshgrid(irchild,jrchild);
+[ichildgrd_u,jchildgrd_u]=meshgrid(ipchild,jrchild);
+[ichildgrd_v,jchildgrd_v]=meshgrid(irchild,jpchild);
+%
+% interpolations
+% 
+disp(' ')
+disp(' Do the interpolations...')                 
+np=netcdf(parent_ndepo);
+nc=netcdf(child_ndepo,'write');
+disp('ndepo...')
+for tindex=1:length(ndepot)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'ndepo',mask,tindex)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'noyndepo',mask,tindex)
+  interpvar3d(np,nc,igrd_r,jgrd_r,ichildgrd_r,jchildgrd_r,'nhxndepo',mask,tindex)
+end
+result=close(np);
+result=close(nc);
+disp(' ')
+disp(' Done ')
+%
+% Make a plot
+%
+disp(' ')
+disp(' Make a plot...')
+figure(1)
+plot_nestndepo(child_ndepo,'ndepo',[1 6],1)
diff --git a/Nesting_tools/nestgui.fig b/Nesting_tools/nestgui.fig
index b6a22c1684e145f76caa30e670a28dcfc8018a03..4f5c4b92d7fd0473e92ea098b8dde0bf487acec2 100644
Binary files a/Nesting_tools/nestgui.fig and b/Nesting_tools/nestgui.fig differ
diff --git a/Nesting_tools/plot_nestndepo.m b/Nesting_tools/plot_nestndepo.m
new file mode 100644
index 0000000000000000000000000000000000000000..111a655afc136cdd8d547045639ae7c07a26522d
--- /dev/null
+++ b/Nesting_tools/plot_nestndepo.m
@@ -0,0 +1,83 @@
+function plot_nestndepo(child_ndepo,thefield,thetime,skip)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% Test the embedded ndepo forcing file.
+%
+%  Further Information:  
+%  http://www.croco-ocean.org
+%  
+%  This file is part of CROCOTOOLS
+%
+%  CROCOTOOLS is free software; you can redistribute it and/or modify
+%  it under the terms of the GNU General Public License as published
+%  by the Free Software Foundation; either version 2 of the License,
+%  or (at your option) any later version.
+%
+%  CROCOTOOLS is distributed in the hope that it will be useful, but
+%  WITHOUT ANY WARRANTY; without even the implied warranty of
+%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+%  GNU General Public License for more details.
+%
+%  You should have received a copy of the GNU General Public License
+%  along with this program; if not, write to the Free Software
+%  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+%  MA  02111-1307  USA
+%
+%  Copyright (c) 2004-2006 by Pierrick Penven 
+%  e-mail:Pierrick.Penven@ird.fr  
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+npts=[0 0 0 0];
+i=0;
+for time=thetime
+  i=i+1;
+  
+  subplot(2,length(thetime),i)
+
+
+  nc=netcdf(child_ndepo);
+  parent_ndepo=nc.parent_file(:);
+  child_grd=nc.grd_file(:);
+  fieldc=nc{thefield}(time,:,:);
+  fieldname=nc{thefield}.long_name(:);
+  result=close(nc);
+
+  nc=netcdf(child_grd);
+  parent_grd=nc.parent_grid(:);
+  refinecoeff=nc{'refine_coef'}(:);
+  lonc=nc{'lon_rho'}(:);
+  latc=nc{'lat_rho'}(:);
+  mask=nc{'mask_rho'}(:);
+  result=close(nc);
+  mask(mask==0)=NaN;
+  pcolor(lonc,latc,mask.*fieldc)
+  shading flat
+  axis image
+  caxis([min(min(fieldc)) max(max(fieldc))])
+  colorbar
+  axis([min(min(lonc)) max(max(lonc)) min(min(latc)) max(max(latc))])
+  title(['\bf ',fieldname,' CHILD'])
+
+  subplot(2,length(thetime),i+length(thetime))
+  nc=netcdf(parent_ndepo);
+  field=nc{thefield}(time,:,:);
+  fieldname=nc{thefield}.long_name(:);
+  result=close(nc);
+  
+  nc=netcdf(parent_grd);
+  lon=nc{'lon_rho'}(:);
+  lat=nc{'lat_rho'}(:);
+  mask=nc{'mask_rho'}(:);
+  result=close(nc);
+  mask(mask==0)=NaN;
+  pcolor(lon,lat,mask.*field)
+  shading flat
+  axis image
+  caxis([min(min(fieldc)) max(max(fieldc))])
+  colorbar
+  axis([min(min(lonc)) max(max(lonc)) min(min(latc)) max(max(latc))])
+  title(['\bf ',fieldname,' PARENT'])
+end
+
+
+return
diff --git a/Oforc_OGCM/create_OGCM.m b/Oforc_OGCM/create_OGCM.m
index 88f0469002ac1d2a37c6e9b7521ee2bb1d33b7b0..c4428922ee0e3b3522769a12a9fc499e65c35725 100644
--- a/Oforc_OGCM/create_OGCM.m
+++ b/Oforc_OGCM/create_OGCM.m
@@ -1,12 +1,12 @@
 function create_OGCM(fname,lonT,latT,lonU,latU,lonV,latV,depth,time,...
-                     temp,salt,u,v,ssh,Yorig)
+                      temp,salt,u,v,ssh,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % Create the OGCM file
 %
-%  Further Information:  
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -24,8 +24,8 @@ function create_OGCM(fname,lonT,latT,lonU,latU,lonV,latV,depth,time,...
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2005-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2005-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %  Updated    6-Sep-2006 by Pierrick Penven
 %  Updated    7-Oct-2013 by Gildas Cambon
@@ -120,8 +120,10 @@ nc{'depth'}=ncdouble('depth') ;
 nc{'depth'}.units=ncchar('meters');
 nc{'depth'}.units='meters';
 nc{'time'}=ncdouble('time') ;
-eval(['nc{''time''}.units = ncchar(''days since 1-Jan-',num2str(Yorig),' 00:00:0.0'');'])
-eval(['nc{''time''}.units = ''days since 1-Jan-',num2str(Yorig),' 00:00:0.0'';'])
+eval(['nc{''time''}.units = ncchar(''days since ',sprintf('%04d', Yorig),'-01-01 00:00:00'');'])
+eval(['nc{''time''}.units = ''days since ',sprintf('%04d', Yorig),'-01-01 00:00:00'';'])
+nc{'time'}.calendar = ncchar('proleptic_gregorian');
+nc{'time'}.calendar = 'proleptic_gregorian';
 endef(nc);
 %
 % File the file
@@ -136,13 +138,13 @@ nc{'latV'}(:)=latV;
 nc{'lonV'}(:)=lonV;
 %
 for tndx=1:length(time)
-%
-nc{'time'}(tndx)=time(tndx);
-%
+  %
+  nc{'time'}(tndx)=time(tndx);
+  %
   if length(time)==1
     nc{'ssh'}(tndx,:,:)=ssh;
-%    nc{'taux'}(tndx,:,:)=taux;
-%    nc{'tauy'}(tndx,:,:)=tauy;
+    %    nc{'taux'}(tndx,:,:)=taux;
+    %    nc{'tauy'}(tndx,:,:)=tauy;
     u1=u;
     v1=v;
     nc{'u'}(tndx,:,:,:)=u1;
@@ -151,8 +153,8 @@ nc{'time'}(tndx)=time(tndx);
     nc{'salt'}(tndx,:,:,:)=salt;
   else
     nc{'ssh'}(tndx,:,:)=squeeze(ssh(tndx,:,:));
-%    nc{'taux'}(tndx,:,:)=squeeze(taux(tndx,:,:));
-%    nc{'tauy'}(tndx,:,:)=squeeze(tauy(tndx,:,:));
+    %    nc{'taux'}(tndx,:,:)=squeeze(taux(tndx,:,:));
+    %    nc{'tauy'}(tndx,:,:)=squeeze(tauy(tndx,:,:));
     u1=squeeze(u(tndx,:,:,:));
     v1=squeeze(v(tndx,:,:,:));
     nc{'u'}(tndx,:,:,:)=u1;
@@ -160,35 +162,35 @@ nc{'time'}(tndx)=time(tndx);
     nc{'temp'}(tndx,:,:,:)=squeeze(temp(tndx,:,:,:));
     nc{'salt'}(tndx,:,:,:)=squeeze(salt(tndx,:,:,:));
   end
-%
-% Compute the barotropic velocities
-%
-masku=isfinite(u1);
-maskv=isfinite(v1);
-u1(isnan(u1))=0;
-v1(isnan(v1))=0;
-dz=gradient(depth);
-NZ=length(depth);
-du=0*squeeze(u1(1,:,:));
-zu=du;
-dv=0*squeeze(v1(1,:,:));
-zv=dv;
-for k=1:NZ
-  du=du+dz(k)*squeeze(u1(k,:,:));
-  zu=zu+dz(k)*squeeze(masku(k,:,:));
-  dv=dv+dz(k)*squeeze(v1(k,:,:));
-  zv=zv+dz(k)*squeeze(maskv(k,:,:));
-end
-du(zu==0)=NaN;
-dv(zv==0)=NaN;
-zu(zu==0)=NaN;
-zv(zv==0)=NaN;
-ubar=du./zu;
-vbar=dv./zv;
-%
-nc{'ubar'}(tndx,:,:)=ubar;
-nc{'vbar'}(tndx,:,:)=vbar;
-%
+  %
+  % Compute the barotropic velocities
+  %
+  masku=isfinite(u1);
+  maskv=isfinite(v1);
+  u1(isnan(u1))=0;
+  v1(isnan(v1))=0;
+  dz=gradient(depth);
+  NZ=length(depth);
+  du=0*squeeze(u1(1,:,:));
+  zu=du;
+  dv=0*squeeze(v1(1,:,:));
+  zv=dv;
+  for k=1:NZ
+    du=du+dz(k)*squeeze(u1(k,:,:));
+    zu=zu+dz(k)*squeeze(masku(k,:,:));
+    dv=dv+dz(k)*squeeze(v1(k,:,:));
+    zv=zv+dz(k)*squeeze(maskv(k,:,:));
+  end
+  du(zu==0)=NaN;
+  dv(zv==0)=NaN;
+  zu(zu==0)=NaN;
+  zv(zv==0)=NaN;
+  ubar=du./zu;
+  vbar=dv./zv;
+  %
+  nc{'ubar'}(tndx,:,:)=ubar;
+  nc{'vbar'}(tndx,:,:)=vbar;
+  %
 end
 %
 close(nc)
diff --git a/Oforc_OGCM/make_OGCM_SODA.m b/Oforc_OGCM/make_OGCM_SODA.m
index f59e5e54c0f8ec650b2a2044832c2bf95b552635..31a2f33eb041f2ed42fa47240e8b233f7137e5a4 100644
--- a/Oforc_OGCM/make_OGCM_SODA.m
+++ b/Oforc_OGCM/make_OGCM_SODA.m
@@ -6,10 +6,10 @@
 % http://iridl.ldeo.columbia.edu./SOURCES/.CARTON-GIESE/.SODA/
 % The on-line reference to ECCO is at
 % http://ecco.jpl.nasa.gov/cgi-bin/nph-dods/datasets/
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -27,8 +27,8 @@
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2005-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2005-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %  Contributions of P. Marchesiello (IRD), J. Lefevre (IRD),
 %                   and F. Colberg (UCT)
@@ -46,18 +46,18 @@ close all
 %
 crocotools_param
 
-  %
-  %  SODA DODS URL
-  %
-  % SODA_2.2.4/ [ C20R-2 1871-2008 / POP2.1 ]
-  %%url='http://iridl.ldeo.columbia.edu/SOURCES/.CARTON-GIESE/.SODA/.v2p2p4' ;
-  url='http://apdrc.soest.hawaii.edu:80/dods/public_data/SODA/soda_pop2.2.4' ;
+%
+%  SODA DODS URL
+%
+% SODA_2.2.4/ [ C20R-2 1871-2008 / POP2.1 ]
+%%url='http://iridl.ldeo.columbia.edu/SOURCES/.CARTON-GIESE/.SODA/.v2p2p4' ;
+url='http://apdrc.soest.hawaii.edu:80/dods/public_data/SODA/soda_pop2.2.4' ;
 %
 itolap_tot=itolap_a + itolap_p;
 disp(['Overlap before =',num2str(itolap_a)])
 disp(['Overlap after =',num2str(itolap_p)])
 disp(['Total overlap =',num2str(itolap_tot)])
-disp(['...'])   
+disp(['...'])
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % end of user input  parameters
@@ -81,6 +81,10 @@ lat=nc{'lat_rho'}(:);
 angle=nc{'angle'}(:);
 h=nc{'h'}(:);
 close(nc)
+
+if ~strcmp(OGCM, 'SODA')
+  error('Error: OGCM must be "SODA" in crocotools_param.m. Exiting script.');
+end
 %
 % Extract data over the internet
 %
@@ -94,16 +98,16 @@ if Download_data==1
   latmax=max(max(lat));
   %
   % Download data with DODS (the download matlab routine depends on the OGCM)
-  % 
+  %
   disp('Download data...')
- download_SODA(Ymin,Ymax,Mmin,Mmax,lonmin,lonmax,latmin,latmax,...
-               OGCM_dir,OGCM_prefix,url,Yorig)
+  download_SODA(Ymin,Ymax,Mmin,Mmax,lonmin,lonmax,latmin,latmax,...
+                OGCM_dir,OGCM_prefix,url,Yorig)
 end
 %
 %------------------------------------------------------------------------------------
 %
-% Get the OGCM grid 
-% 
+% Get the OGCM grid
+%
 nc=netcdf([OGCM_dir,OGCM_prefix,'Y',num2str(Ymin),'M',num2str(Mmin),'.cdf'],'r');
 lonT=nc{'lonT'}(:);
 latT=nc{'latT'}(:);
@@ -117,18 +121,18 @@ NZ=NZ-rmdepth;
 Z=Z(1:NZ);
 close(nc)
 %
-% Initial file 
+% Initial file
 % (the strategy is to start at the begining of a month)
-% it is possible to do some temporal interpolation... 
+% it is possible to do some temporal interpolation...
 % but I am too lazy. lets start the first day of
 % month Mmin of year Ymin... with the first data available.
 %
 if makeini==1
-    if  ~exist('vtransform')
-        vtransform=1; %Old Vtransform
-        disp([' NO VTRANSFORM parameter found'])
-        disp([' USE vtransform default value  Vtransfor = 1'])
-    end
+  if  ~exist('vtransform')
+    vtransform=1; %Old Vtransform
+    disp([' NO VTRANSFORM parameter found'])
+    disp([' USE vtransform default value  Vtransfor = 1'])
+  end
   ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
   %
   % Process the time in Yorig time (i.e days since Yorig-01-01)
@@ -136,29 +140,29 @@ if makeini==1
   tini=datenum(Ymin,Mmin,1)-datenum(Yorig,1,1);
   disp(['Create an initial file for ',datestr(tini+datenum(Yorig,1,1));])
   create_inifile(ininame,grdname,CROCO_title,...
-		 theta_s,theta_b,hc,N,...
-		 tini,'clobber', vtransform);
-  nc_add_globatt(ininame,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);  
+                theta_s,theta_b,hc,N,...
+                tini,'clobber', vtransform,Yorig);
+  nc_add_globatt(ininame,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);
   nc_ini=netcdf(ininame,'write');
   interp_OGCM(OGCM_dir,OGCM_prefix,Ymin,Mmin,Roa,interp_method,...
-	      lonU,latU,lonV,latV,lonT,latT,Z,1,...
-	      nc_ini,[],lon,lat,angle,h,1,obc,vtransform)
+    lonU,latU,lonV,latV,lonT,latT,Z,1,...
+    nc_ini,[],lon,lat,angle,h,1,obc,vtransform)
   close(nc_ini)
 end
 %
-% Clim and Bry files 
+% Clim and Bry files
 %
 if makeclim==1 | makebry==1
-    if  ~exist('vtransform')
-        vtransform=1; %Old Vtransform
-        disp([' NO VTRANSFORM parameter found'])
-        disp([' USE vtransform default value  Vtransfor = 1'])
-    end
+  if  ~exist('vtransform')
+    vtransform=1; %Old Vtransform
+    disp([' NO VTRANSFORM parameter found'])
+    disp([' USE vtransform default value  Vtransfor = 1'])
+  end
   %
   % Loop on the years and the months
   %
   for Y=Ymin:Ymax
-    if Y==Ymin 
+    if Y==Ymin
       mo_min=Mmin;
     else
       mo_min=1;
@@ -171,100 +175,100 @@ if makeclim==1 | makebry==1
     for M=mo_min:mo_max
       disp(' ')
       disp(['Processing  year ',num2str(Y),...
-	    ' - month ',num2str(sprintf(Mth_format,M))])
+        ' - month ',num2str(sprintf(Mth_format,M))])
       disp(' ')
       %
       Mm=M-1;Ym=Y;
       if Mm==0
-	Mm=12;
-	Ym=Y-1;
+        Mm=12;
+        Ym=Y-1;
       end
       Mp=M+1;Yp=Y;
       if Mp==13
-	Mp=1;
-	Yp=Y+1;
+        Mp=1;
+        Yp=Y+1;
       end
       %
-      % Add 2 times step in the CROCO files: 1 at the beginning and 1 at the end 
+      % Add 2 times step in the CROCO files: 1 at the beginning and 1 at the end
       %
       nc=netcdf([OGCM_dir,OGCM_prefix,'Y',num2str(Y),'M',num2str(M),'.cdf'],'r');
       OGCM_time=nc{'time'}(:);
       ntimes=length(OGCM_time);
       if ntimes==1
-	dt=30; % monthly files (SODA..)
+        dt=30; % monthly files (SODA..)
         itolap_a=1; itolap_p=1;
         itolap_tot=itolap_a + itolap_p;
         disp(['Reduced overlap for monthly SODA files'])
         disp(['...'])
       else
-	dt=max(gradient(OGCM_time));
+        dt=max(gradient(OGCM_time));
       end
       %
       %% Fill the time axis
       %
       croco_time=0*(1:ntimes+itolap_tot);
-      %Current month	
+      %Current month
       croco_time(itolap_a+1:end-itolap_p)=OGCM_time;
       %
       %Previous  month
       %
       disp(['==================================='])
       for aa= 1:itolap_a
-	      disp(['Compute beginning overlap, time index:',num2str(aa)])	
-	      disp(['Add ',num2str(-(itolap_a + 1 - aa)), ' timestep dt'])
-	      disp(['--------'])
-	      croco_time(aa) = croco_time(itolap_a+1) - ((itolap_a + 1 - aa).* dt);
+        disp(['Compute beginning overlap, time index:',num2str(aa)])
+        disp(['Add ',num2str(-(itolap_a + 1 - aa)), ' timestep dt'])
+        disp(['--------'])
+        croco_time(aa) = croco_time(itolap_a+1) - ((itolap_a + 1 - aa).* dt);
       end
       %
-      %Next month	
+      %Next month
       %
-      disp(['==================================='])	
+      disp(['==================================='])
       for aa= 1:itolap_p
-	      disp(['Compute end overlap, time index:',num2str(ntimes+itolap_tot - itolap_p + aa)])
-	      disp(['Add ',num2str(aa), ' timestep dt'])
-	      disp(['--------'])
-	      croco_time(end - itolap_p +  aa   ) = croco_time(end - itolap_p) +  aa.* dt;
+        disp(['Compute end overlap, time index:',num2str(ntimes+itolap_tot - itolap_p + aa)])
+        disp(['Add ',num2str(aa), ' timestep dt'])
+        disp(['--------'])
+        croco_time(end - itolap_p +  aa   ) = croco_time(end - itolap_p) +  aa.* dt;
       end
       disp(['==================================='])
       close(nc)
-      %-----------------------------------------------------	
+      %-----------------------------------------------------
       %
       % Create and open the CROCO files
       %
       if makebry==1
-	      bryname=[bry_prefix,'Y',num2str(Y),...
-		            'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-	      create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
-		       theta_s,theta_b,hc,N,...
-		       croco_time,0,'clobber',vtransform);
-        nc_add_globatt(bryname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM); 
-	      nc_bry=netcdf(bryname,'write');
+        bryname=[bry_prefix,'Y',num2str(Y),...
+                'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+        create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
+                      theta_s,theta_b,hc,N,...
+                      croco_time,0,'clobber',vtransform,Yorig);
+        nc_add_globatt(bryname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);
+        nc_bry=netcdf(bryname,'write');
       else
-	      nc_bry=[];
+        nc_bry=[];
       end
       if makeclim==1
-	      clmname=[clm_prefix,'Y',num2str(Y),...
-		             'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-	      create_climfile(clmname,grdname,CROCO_title,...
-                        theta_s,theta_b,hc,N,croco_time,0,'clobber',vtransform);
-        nc_add_globatt(clmname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM); 
-	      nc_clm=netcdf(clmname,'write');
+        clmname=[clm_prefix,'Y',num2str(Y),...
+                'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+        create_climfile(clmname,grdname,CROCO_title,...
+                        theta_s,theta_b,hc,N,croco_time,0,'clobber',vtransform,Yorig);
+        nc_add_globatt(clmname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);
+        nc_clm=netcdf(clmname,'write');
       else
-	      nc_clm=[];
+        nc_clm=[];
       end
       %
       % Check if there are OGCM files for the previous Month
       %
       fname=[OGCM_dir,OGCM_prefix,'Y',num2str(Ym),'M',num2str(Mm),'.cdf'];
       if exist(fname)==0
-	      disp(['   No data for the previous month: using current month'])
-	      Mm=M;
-	      Ym=Y;
-	      tndx_OGCM=ones(itolap_a,1);
+        disp(['   No data for the previous month: using current month'])
+        Mm=M;
+        Ym=Y;
+        tndx_OGCM=ones(itolap_a,1);
       else
-	      nc=netcdf(fname,'r');
-	      tndx_OGCM=[(length(nc('time'))- (itolap_a -1) ):1: (length(nc('time')))];
-	      close(nc)
+        nc=netcdf(fname,'r');
+        tndx_OGCM=[(length(nc('time'))- (itolap_a -1) ):1: (length(nc('time')))];
+        close(nc)
       end
       %
       % Perform the interpolations for the previous month
@@ -272,11 +276,11 @@ if makeclim==1 | makebry==1
       disp(' Previous month :')
       disp('=================')
       for aa=1:itolap_a
-	      disp(['Beg overlap # ', num2str(aa),' -> tindex ',num2str(aa)])
-	      disp(['It. of prev month used for it= ',num2str(tndx_OGCM(aa))])
-	      interp_OGCM(OGCM_dir,OGCM_prefix,Ym,Mm,Roa,interp_method,...
-		                lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
-		    nc_clm,nc_bry,lon,lat,angle,h,aa,obc,vtransform)
+        disp(['Beg overlap # ', num2str(aa),' -> tindex ',num2str(aa)])
+        disp(['It. of prev month used for it= ',num2str(tndx_OGCM(aa))])
+        interp_OGCM(OGCM_dir,OGCM_prefix,Ym,Mm,Roa,interp_method,...
+                    lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
+                    nc_clm,nc_bry,lon,lat,angle,h,aa,obc,vtransform)
       end
       %
       % Perform the interpolations for the current month
@@ -285,26 +289,26 @@ if makeclim==1 | makebry==1
       disp(' Current month :')
       disp('================')
       for tndx_OGCM=1:ntimes
-	      disp([' Time step : ',num2str(tndx_OGCM),' of ',num2str(ntimes),' :'])
-	      interp_OGCM(OGCM_dir,OGCM_prefix,Y,M,Roa,interp_method,...
-		                lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM,...
-		    nc_clm,nc_bry,lon,lat,angle,h,tndx_OGCM+itolap_a,obc,vtransform)
+        disp([' Time step : ',num2str(tndx_OGCM),' of ',num2str(ntimes),' :'])
+        interp_OGCM(OGCM_dir,OGCM_prefix,Y,M,Roa,interp_method,...
+                    lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM,...
+                    nc_clm,nc_bry,lon,lat,angle,h,tndx_OGCM+itolap_a,obc,vtransform)
       end
       %
       % Read the OGCM file for the next month
       %
       fname=[OGCM_dir,OGCM_prefix,'Y',num2str(Yp),'M',num2str(Mp),'.cdf'];
       if exist(fname)==0
-	      disp(['   No data for the next month: using current month'])
-	      Mp=M;
-	      Yp=Y;
-	      for aa=1:itolap_p    
-	         tndx_OGCM(aa)=ntimes;
-              end
+        disp(['   No data for the next month: using current month'])
+        Mp=M;
+        Yp=Y;
+        for aa=1:itolap_p
+          tndx_OGCM(aa)=ntimes;
+        end
       else
-	      for aa=1:itolap_p  
-                tndx_OGCM(aa)=aa;
-	      end;
+        for aa=1:itolap_p
+          tndx_OGCM(aa)=aa;
+        end;
       end
       %
       % Perform the interpolations for the next month
@@ -312,20 +316,20 @@ if makeclim==1 | makebry==1
       disp(' Next month :')
       disp('=============')
       for aa=1:itolap_p
-	      disp(['End Overlap #',num2str(aa),' -> tindex ',num2str(ntimes+itolap_a+aa)])
-	      disp(['It. of next month used for it= ',num2str(tndx_OGCM(aa))])
-	      interp_OGCM(OGCM_dir,OGCM_prefix,Yp,Mp,Roa,interp_method,...
-		    lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
-		    nc_clm,nc_bry,lon,lat,angle,h,ntimes+itolap_a+aa,obc,vtransform)
+        disp(['End Overlap #',num2str(aa),' -> tindex ',num2str(ntimes+itolap_a+aa)])
+        disp(['It. of next month used for it= ',num2str(tndx_OGCM(aa))])
+        interp_OGCM(OGCM_dir,OGCM_prefix,Yp,Mp,Roa,interp_method,...
+                    lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
+                    nc_clm,nc_bry,lon,lat,angle,h,ntimes+itolap_a+aa,obc,vtransform)
       end
       %
       % Close the CROCO files
       %
       if ~isempty(nc_clm)
-	      close(nc_clm);
+        close(nc_clm);
       end
       if ~isempty(nc_bry)
-	      close(nc_bry);
+        close(nc_bry);
       end
       %
     end
@@ -345,7 +349,7 @@ if SPIN_Long>0
     %
     ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
     ininame2=[ini_prefix,'Y',num2str(Ymin-SPIN_Long),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-    disp(['Create ',ininame2]) 
+    disp(['Create ',ininame2])
     eval(['!cp ',ininame,' ',ininame2])
     %
     % Change the time
@@ -361,7 +365,7 @@ if SPIN_Long>0
   for month=1:12*SPIN_Long
     M=M+1;
     if M==13
-      M=1; 
+      M=1;
       Y=Y+1;
     end
     %
@@ -373,8 +377,8 @@ if SPIN_Long>0
       %
       clmname=[clm_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
       clmname2=[clm_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-      disp(['Create ',clmname2]) 
-      eval(['!cp ',clmname,' ',clmname2]) 
+      disp(['Create ',clmname2])
+      eval(['!cp ',clmname,' ',clmname2])
       %
       % Change the time
       %
@@ -401,8 +405,8 @@ if SPIN_Long>0
       %
       bryname=[bry_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
       bryname2=[bry_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-      disp(['Create ',bryname2]) 
-      eval(['!cp ',bryname,' ',bryname2]) 
+      disp(['Create ',bryname2])
+      eval(['!cp ',bryname,' ',bryname2])
       %
       % Change the time
       %
diff --git a/Oforc_OGCM/make_OGCM_mercator.m b/Oforc_OGCM/make_OGCM_mercator.m
index 687dcdbfe728dbced0e32f479ee6578a557ae62c..f72433683b0b37c6e66d7adf012ff27fe1f87267 100644
--- a/Oforc_OGCM/make_OGCM_mercator.m
+++ b/Oforc_OGCM/make_OGCM_mercator.m
@@ -1,6 +1,6 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  Create and fill CROCO clim and bry files with OGCM 
+%  Create and fill CROCO clim and bry files with OGCM
 %  MERCATOR data.
 %
 %  On crocotools_param.m, available datasets:
@@ -17,10 +17,10 @@
 %                    (more than 15days from now  : Best analysis)
 %
 %  Online reference to MERCATOR is at http://marine.copernicus.eu
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -38,8 +38,8 @@
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2005-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2005-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %  Contributions of P. Marchesiello (IRD), J. Lefevre (IRD),
 %                   and F. Colberg (UCT)
@@ -68,7 +68,7 @@ itolap_tot=itolap_a + itolap_p;
 disp(['Overlap before =',num2str(itolap_a)])
 disp(['Overlap after =',num2str(itolap_p)])
 disp(['Total overlap =',num2str(itolap_tot)])
-disp(['...'])   
+disp(['...'])
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % end of user input  parameters
@@ -78,10 +78,10 @@ disp(['==================='])
 disp([' Compute time axis '])
 disp(['==================='])
 if level==0
-  nc_suffix='.nc';
+    nc_suffix='.nc';
 else
-  nc_suffix=['.nc.',num2str(level)];
-  grdname=[grdname,'.',num2str(level)];
+    nc_suffix=['.nc.',num2str(level)];
+    grdname=[grdname,'.',num2str(level)];
 end
 %
 % Get the model grid
@@ -93,6 +93,10 @@ angle=nc{'angle'}(:);
 h=nc{'h'}(:);
 close(nc)
 %
+if ~strcmp(OGCM, 'mercator')
+    error('Error: OGCM must be "mercator" in crocotools_param.m. Exiting script.');
+  end
+%
 % Extract data over the internet
 %
 if Download_data==1
@@ -105,7 +109,7 @@ if Download_data==1
     latmax=max(max(lat));
     %
     % Download data with DODS (the download matlab routine depends on the OGCM)
-    % 
+    %
     disp('Download data...')
     % Loop on the years
     %
@@ -122,20 +126,20 @@ if Download_data==1
             mo_max=12;
         end
         for M=mo_min:mo_max
-            thedatemonth=['Y',num2str(Y),'M',num2str(M)];          
+            thedatemonth=['Y',num2str(Y),'M',num2str(M)];
             download_mercator_python(pathCMC,user,password,mercator_type,...
-                                     product_id, ...
-                                     Y,M, ...
-                                     lonmin,lonmax,latmin,latmax,hmax, ...
-                                     OGCM_dir,OGCM_prefix,thedatemonth,Yorig)           
+                                    product_id, ...
+                                    Y,M, ...
+                                    lonmin,lonmax,latmin,latmax,hmax, ...
+                                    OGCM_dir,OGCM_prefix,thedatemonth,Yorig)
         end
-    end  %End loop over month and years for the downloading with python/motu client 
+    end  %End loop over month and years for the downloading with python/motu client
 end %End loop for Download_data
 %
 %------------------------------------------------------------------------------------
 %
-% Get the OGCM grid 
-% 
+% Get the OGCM grid
+%
 nc=netcdf([OGCM_dir,OGCM_prefix,'Y',num2str(Ymin),'M',num2str(Mmin),'.cdf']);
 lonT=nc{'lonT'}(:);
 latT=nc{'latT'}(:);
@@ -149,9 +153,9 @@ NZ=NZ-rmdepth;
 Z=Z(1:NZ);
 close(nc)
 %
-% Initial file 
+% Initial file
 % (the strategy is to start at the begining of a month)
-% it is possible to do some temporal interpolation... 
+% it is possible to do some temporal interpolation...
 % but I am too lazy. lets start the first day of
 % month Mmin of year Ymin... with the first data available.
 %
@@ -161,25 +165,25 @@ if makeini==1
         disp([' NO VTRANSFORM parameter found'])
         disp([' USE vtransform default value  Vtransfor = 1'])
     end
-  ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
-  %
-  % Process the time in Yorig time (i.e days since Yorig-01-01)
-  %
-  tini=datenum(Ymin,Mmin,1)-datenum(Yorig,1,1);
-  disp([' '])
-  disp(['=> Create an initial file for ',datestr(tini+datenum(Yorig,1,1));])
-  create_inifile(ininame,grdname,CROCO_title,...
-		 theta_s,theta_b,hc,N,...
-		 tini,'clobber', vtransform);
-  nc_ini=netcdf(ininame,'write');
-  interp_OGCM(OGCM_dir,OGCM_prefix,Ymin,Mmin,Roa,interp_method,...
-	            lonU,latU,lonV,latV,lonT,latT,Z,1,...
-	            nc_ini,[],lon,lat,angle,h,1,obc,vtransform)
-  nc_add_globatt(ininame,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM); 
-  close(nc_ini)
+    ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
+    %
+    % Process the time in Yorig time (i.e days since Yorig-01-01)
+    %
+    tini=datenum(Ymin,Mmin,1)-datenum(Yorig,1,1);
+    disp([' '])
+    disp(['=> Create an initial file for ',datestr(tini+datenum(Yorig,1,1));])
+    create_inifile(ininame,grdname,CROCO_title,...
+                    theta_s,theta_b,hc,N,...
+                    tini,'clobber', vtransform,Yorig);
+    nc_ini=netcdf(ininame,'write');
+    interp_OGCM(OGCM_dir,OGCM_prefix,Ymin,Mmin,Roa,interp_method,...
+                lonU,latU,lonV,latV,lonT,latT,Z,1,...
+                nc_ini,[],lon,lat,angle,h,1,obc,vtransform)
+    nc_add_globatt(ininame,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);
+    close(nc_ini)
 end
 %
-% Clim and Bry files 
+% Clim and Bry files
 %
 if makeclim==1 | makebry==1
     if  ~exist('vtransform')
@@ -187,297 +191,302 @@ if makeclim==1 | makebry==1
         disp([' NO VTRANSFORM parameter found'])
         disp([' USE vtransform default value  Vtransfor = 1'])
     end
-  %
-  % Loop on the years and the months
-  %
-  for Y=Ymin:Ymax
-    if Y==Ymin 
-      mo_min=Mmin;
-    else
-      mo_min=1;
-    end
-    if Y==Ymax
-      mo_max=Mmax;
-    else
-      mo_max=12;
-    end
-    for M=mo_min:mo_max
-      disp(' ')
-      disp(['Processing  year ',num2str(Y),...
-	    ' - month ',num2str(M)])
-      disp(' ')
-      %
-      Mm=M-1;Ym=Y;
-      if Mm==0
-	      Mm=12;
-	      Ym=Y-1;
-      end
-      Mp=M+1;Yp=Y;
-      if Mp==13
-	      Mp=1;
-	      Yp=Y+1;
-      end
-      %
-      % Add 2 times step in the CROCO files: 1 at the beginning and 1 at the end 
-      %
-      nc=netcdf([OGCM_dir,OGCM_prefix,'Y',num2str(Y),'M',num2str(M),'.cdf']);
-      OGCM_time=nc{'time'}(:);
-      ntimes=length(OGCM_time);
-      if ntimes==1
-	dt=30; % monthly files
-        itolap_a=1; itolap_p=1;
-        itolap_tot=itolap_a + itolap_p;
-        disp(['Reduced overlap for monthly files'])
-        disp(['...'])
-      else
-	      dt=max(gradient(OGCM_time));
-      end
-      %
-      %% Fill the time axis
-      %
-      croco_time=0*(1:ntimes+itolap_tot);
-      %Current month	
-      croco_time(itolap_a+1:end-itolap_p)=OGCM_time;
-      %
-      %Previous  month
-      %
-      disp(['==================================='])
-      for aa= 1:itolap_a
-	      disp(['Compute beginning overlap, time index:',num2str(aa)])	
-	      disp(['Add ',num2str(-(itolap_a + 1 - aa)), ' timestep dt'])
-	      disp(['--------'])
-	      croco_time(aa) = croco_time(itolap_a+1) - ((itolap_a + 1 - aa).* dt);
-      end
-      %
-      %Next month	
-      %
-      disp(['==================================='])	
-      for aa= 1:itolap_p
-	      disp(['Compute end overlap, time index:',num2str(ntimes+itolap_tot - itolap_p + aa)])
-	      disp(['Add ',num2str(aa), ' timestep dt'])
-        disp(['--------'])
-	      croco_time(end - itolap_p +  aa   ) = croco_time(end - itolap_p) +  aa.* dt;
-      end
-      disp(['==================================='])
-      close(nc)
-      %-----------------------------------------------------	
-      %
-      % Create and open the CROCO files
-      %
-      if makebry==1
-	      bryname=[bry_prefix,'Y',num2str(Y),...
-		            'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-	      disp([' '])
-              disp(['=> Create bry file : ',  bryname ])
-	      create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
-		       theta_s,theta_b,hc,N,...
-		       croco_time,0,'clobber',vtransform);
-        nc_add_globatt(bryname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM); 
-	      nc_bry=netcdf(bryname,'write');
-      else
-	      nc_bry=[];
-      end
-      if makeclim==1
-	      clmname=[clm_prefix,'Y',num2str(Y),...
-	            	 'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-	      create_climfile(clmname,grdname,CROCO_title,...
-	                  		theta_s,theta_b,hc,N,...
-			croco_time,0,'clobber',vtransform);
-      nc_add_globatt(clmname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM); 
-	    nc_clm=netcdf(clmname,'write');
-      else
-	      nc_clm=[];
-      end
-      %
-      % Check if there are OGCM files for the previous Month
-      %
-      fname=[OGCM_dir,OGCM_prefix,'Y',num2str(Ym),'M',num2str(Mm),'.cdf'];
-      if exist(fname)==0
-	      disp(['   No data for the previous month: using current month'])
-        Mm=M;
-	      Ym=Y;
-	      tndx_OGCM=ones(itolap_a,1);
-      else
-	      nc=netcdf(fname);
-	      tndx_OGCM=[(length(nc('time'))- (itolap_a -1) ):1: (length(nc('time')))];
-	      close(nc)
-      end
-      %
-      % Perform the interpolations for the previous month
-      %
-      disp(' Previous month :')
-      disp('=================')
-      for aa=1:itolap_a
-	      disp(['Beg overlap # ', num2str(aa),' -> tindex ',num2str(aa)])
-	      disp(['It. of prev month used for it= ',num2str(tndx_OGCM(aa))])
-	      interp_OGCM(OGCM_dir,OGCM_prefix,Ym,Mm,Roa,interp_method,...
-	            	    lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
-		    nc_clm,nc_bry,lon,lat,angle,h,aa,obc,vtransform)
-      end
-      %
-      % Perform the interpolations for the current month
-      %
+    %
+    % Loop on the years and the months
+    %
+    for Y=Ymin:Ymax
+        if Y==Ymin
+            mo_min=Mmin;
+        else
+            mo_min=1;
+        end
+        if Y==Ymax
+            mo_max=Mmax;
+        else
+            mo_max=12;
+        end
+        for M=mo_min:mo_max
+            disp(' ')
+            disp(['Processing  year ',num2str(Y),...
+                ' - month ',num2str(M)])
+            disp(' ')
+            %
+            Mm=M-1;Ym=Y;
+            if Mm==0
+                Mm=12;
+                Ym=Y-1;
+            end
+            Mp=M+1;Yp=Y;
+            if Mp==13
+                Mp=1;
+                Yp=Y+1;
+            end
+            %
+            % Add 2 times step in the CROCO files: 1 at the beginning and 1 at the end
+            %
+            nc=netcdf([OGCM_dir,OGCM_prefix,'Y',num2str(Y),'M',num2str(M),'.cdf']);
+            OGCM_time=nc{'time'}(:);
+            ntimes=length(OGCM_time);
+            if ntimes==1
+                dt = eomday(Y, M); % monthly files
+                %disp(['Number of days of the given month: ',num2str(dt)]);
+                if strcmp(OGCM, 'mercator')
+                    dt = eomday(Y, M) + 1 ;  % add +1 days to avoid problems 
+                                             % with mercator starting at first days month   
+                end
+                itolap_a=1; itolap_p=1;
+                itolap_tot=itolap_a + itolap_p;
+                disp(['Reduced overlap for monthly files'])
+                disp(['...'])
+            else
+                dt=max(gradient(OGCM_time));
+            end
+            %
+            %Fill the time axis
+            %
+            croco_time=0*(1:ntimes+itolap_tot);
+            %Current month
+            croco_time(itolap_a+1:end-itolap_p)=OGCM_time;
+            %
+            %Previous  month
+            %
+            disp(['==================================='])
+            for aa= 1:itolap_a
+                disp(['Compute beginning overlap, time index:',num2str(aa)])
+                disp(['Add ',num2str(-(itolap_a + 1 - aa)), ' timestep dt'])
+                disp(['--------'])
+                croco_time(aa) = croco_time(itolap_a+1) - ((itolap_a + 1 - aa).* dt);
+            end
+            %
+            %Next month
+            %
+            disp(['==================================='])
+            for aa= 1:itolap_p
+                disp(['Compute end overlap, time index:',num2str(ntimes+itolap_tot - itolap_p + aa)])
+                disp(['Add ',num2str(aa), ' timestep dt'])
+                disp(['--------'])
+                croco_time(end - itolap_p +  aa   ) = croco_time(end - itolap_p) +  aa.* dt;
+            end
+            disp(['==================================='])
+            close(nc)
+            %-----------------------------------------------------
+            %
+            % Create and open the CROCO files
+            %
+            if makebry==1
+                bryname=[bry_prefix,'Y',num2str(Y),...
+                    'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+                disp([' '])
+                disp(['=> Create bry file : ',  bryname ])
+                create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
+                                theta_s,theta_b,hc,N,...
+                                croco_time,0,'clobber',vtransform,Yorig);
+                nc_add_globatt(bryname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);
+                nc_bry=netcdf(bryname,'write');
+            else
+                nc_bry=[];
+            end
+            if makeclim==1
+                clmname=[clm_prefix,'Y',num2str(Y),...
+                        'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+                create_climfile(clmname,grdname,CROCO_title,...
+                                theta_s,theta_b,hc,N,...
+                                croco_time,0,'clobber',vtransform,Yorig);
+                nc_add_globatt(clmname,Yorig,Mmin,Dmin,Hmin,Min_min,Smin,OGCM);
+                nc_clm=netcdf(clmname,'write');
+            else
+                nc_clm=[];
+            end
+            %
+            % Check if there are OGCM files for the previous Month
+            %
+            fname=[OGCM_dir,OGCM_prefix,'Y',num2str(Ym),'M',num2str(Mm),'.cdf'];
+            if exist(fname)==0
+                disp(['   No data for the previous month: using current month'])
+                Mm=M;
+                Ym=Y;
+                tndx_OGCM=ones(itolap_a,1);
+            else
+                nc=netcdf(fname);
+                tndx_OGCM=[(length(nc('time'))- (itolap_a -1) ):1: (length(nc('time')))];
+                close(nc)
+            end
+            %
+            % Perform the interpolations for the previous month
+            %
+            disp(' Previous month :')
+            disp('=================')
+            for aa=1:itolap_a
+                disp(['Beg overlap # ', num2str(aa),' -> tindex ',num2str(aa)])
+                disp(['It. of prev month used for it= ',num2str(tndx_OGCM(aa))])
+                interp_OGCM(OGCM_dir,OGCM_prefix,Ym,Mm,Roa,interp_method,...
+                            lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
+                            nc_clm,nc_bry,lon,lat,angle,h,aa,obc,vtransform)
+            end
+            %
+            % Perform the interpolations for the current month
+            %
 
-      disp(' Current month :')
-      disp('================')
-      for tndx_OGCM=1:ntimes
-	      disp([' Time step : ',num2str(tndx_OGCM),' of ',num2str(ntimes),' :'])
-	      interp_OGCM(OGCM_dir,OGCM_prefix,Y,M,Roa,interp_method,...
-		                lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM,...
-		    nc_clm,nc_bry,lon,lat,angle,h,tndx_OGCM+itolap_a,obc,vtransform)
-      end
-      %
-      % Read the OGCM file for the next month
-      %
-      fname=[OGCM_dir,OGCM_prefix,'Y',num2str(Yp),'M',num2str(Mp),'.cdf'];
-      if exist(fname)==0
-	      disp(['   No data for the next month: using current month'])
-	      Mp=M;
-	      Yp=Y;
-	      for aa=1:itolap_p    
-	        tndx_OGCM(aa)=ntimes;
-	      end
-      else
-	    for aa=1:itolap_p  
-	      tndx_OGCM(aa)=aa;
-	    end;
-    end
-      %
-      % Perform the interpolations for the next month
-      %
-      disp(' Next month :')
-      disp('=============')
-      for aa=1:itolap_p
-	      disp(['End Overlap #',num2str(aa),' -> tindex ',num2str(ntimes+itolap_a+aa)])
-	      disp(['It. of next month used for it= ',num2str(tndx_OGCM(aa))])
-	      interp_OGCM(OGCM_dir,OGCM_prefix,Yp,Mp,Roa,interp_method,...
-	            	    lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
-		    nc_clm,nc_bry,lon,lat,angle,h,ntimes+itolap_a+aa,obc,vtransform)
-      end
-      %
-      % Close the CROCO files
-      %
-      if ~isempty(nc_clm)
-	      close(nc_clm);
-      end
-      if ~isempty(nc_bry)
-	      close(nc_bry);
-      end
-      %
+            disp(' Current month :')
+            disp('================')
+            for tndx_OGCM=1:ntimes
+                disp([' Time step : ',num2str(tndx_OGCM),' of ',num2str(ntimes),' :'])
+                interp_OGCM(OGCM_dir,OGCM_prefix,Y,M,Roa,interp_method,...
+                            lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM,...
+                            nc_clm,nc_bry,lon,lat,angle,h,tndx_OGCM+itolap_a,obc,vtransform)
+            end
+            %
+            % Read the OGCM file for the next month
+            %
+            fname=[OGCM_dir,OGCM_prefix,'Y',num2str(Yp),'M',num2str(Mp),'.cdf'];
+            if exist(fname)==0
+                disp(['   No data for the next month: using current month'])
+                Mp=M;
+                Yp=Y;
+                for aa=1:itolap_p
+                    tndx_OGCM(aa)=ntimes;
+                end
+            else
+                for aa=1:itolap_p
+                    tndx_OGCM(aa)=aa;
+                end;
+            end
+            %
+            % Perform the interpolations for the next month
+            %
+            disp(' Next month :')
+            disp('=============')
+            for aa=1:itolap_p
+                disp(['End Overlap #',num2str(aa),' -> tindex ',num2str(ntimes+itolap_a+aa)])
+                disp(['It. of next month used for it= ',num2str(tndx_OGCM(aa))])
+                interp_OGCM(OGCM_dir,OGCM_prefix,Yp,Mp,Roa,interp_method,...
+                            lonU,latU,lonV,latV,lonT,latT,Z,tndx_OGCM(aa),...
+                            nc_clm,nc_bry,lon,lat,angle,h,ntimes+itolap_a+aa,obc,vtransform)
+            end
+            %
+            % Close the CROCO files
+            %
+            if ~isempty(nc_clm)
+                close(nc_clm);
+            end
+            if ~isempty(nc_bry)
+                close(nc_bry);
+            end
+            %
+        end
     end
-  end
 end
 %
 % Spin-up: (reproduce the first year 'SPIN_Long' times)
 % just copy the files for the first year and change the time
 %
 if SPIN_Long>0
-  %
-  % Initial file
-  %
-  if makeini==1
     %
-    % Copy the file
-    %
-    ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
-    ininame2=[ini_prefix,'Y',num2str(Ymin-SPIN_Long),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
-    disp(['Create ',ininame2]) 
-    eval(['!cp ',ininame,' ',ininame2])
+    % Initial file
     %
-    % Change the time
-    %
-    nc=netcdf(ininame2,'write');
-    time=nc{'scrum_time'}(:)-365.*SPIN_Long*(24*3600);
-    nc{'scrum_time'}(:)=time;
-    close(nc)
-  end
-  %
-  M=Mmin-1;
-  Y=Ymin-SPIN_Long;
-  for month=1:12*SPIN_Long
-    M=M+1;
-    if M==13
-      M=1; 
-      Y=Y+1;
+    if makeini==1
+        %
+        % Copy the file
+        %
+        ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
+        ininame2=[ini_prefix,'Y',num2str(Ymin-SPIN_Long),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
+        disp(['Create ',ininame2])
+        eval(['!cp ',ininame,' ',ininame2])
+        %
+        % Change the time
+        %
+        nc=netcdf(ininame2,'write');
+        time=nc{'scrum_time'}(:)-365.*SPIN_Long*(24*3600);
+        nc{'scrum_time'}(:)=time;
+        close(nc)
     end
     %
-    % Climatology files
-    %
-    if makeclim==1
-      %
-      % Copy the file
-      %
-      clmname=[clm_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-      clmname2=[clm_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-      disp(['Create ',clmname2]) 
-      eval(['!cp ',clmname,' ',clmname2]) 
-      %
-      % Change the time
-      %
-      nc=netcdf(clmname2,'write');
-      time=nc{'tclm_time'}(:)-365.*(Ymin-Y);
-      nc{'tclm_time'}(:)=time;
-      nc{'temp_time'}(:)=time;
-      nc{'sclm_time'}(:)=time;
-      nc{'salt_time'}(:)=time;
-      nc{'uclm_time'}(:)=time;
-      nc{'vclm_time'}(:)=time;
-      nc{'v2d_time'}(:)=time;
-      nc{'v3d_time'}(:)=time;
-      nc{'ssh_time'}(:)=time;
-      nc{'zeta_time'}(:)=time;
-      close(nc)
-    end
-    %
-    % Boundary files
-    %
-    if makebry==1
-      %
-      % Copy the file
-      %
-      bryname=[bry_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-      bryname2=[bry_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-      disp(['Create ',bryname2]) 
-      eval(['!cp ',bryname,' ',bryname2]) 
-      %
-      % Change the time
-      %
-      nc=netcdf(bryname2,'write');
-      time=nc{'bry_time'}(:)-365.*(Ymin-Y);
-      nc{'bry_time'}(:)=time;
-      close(nc)
+    M=Mmin-1;
+    Y=Ymin-SPIN_Long;
+    for month=1:12*SPIN_Long
+        M=M+1;
+        if M==13
+            M=1;
+            Y=Y+1;
+        end
+        %
+        % Climatology files
+        %
+        if makeclim==1
+            %
+            % Copy the file
+            %
+            clmname=[clm_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+            clmname2=[clm_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+            disp(['Create ',clmname2])
+            eval(['!cp ',clmname,' ',clmname2])
+            %
+            % Change the time
+            %
+            nc=netcdf(clmname2,'write');
+            time=nc{'tclm_time'}(:)-365.*(Ymin-Y);
+            nc{'tclm_time'}(:)=time;
+            nc{'temp_time'}(:)=time;
+            nc{'sclm_time'}(:)=time;
+            nc{'salt_time'}(:)=time;
+            nc{'uclm_time'}(:)=time;
+            nc{'vclm_time'}(:)=time;
+            nc{'v2d_time'}(:)=time;
+            nc{'v3d_time'}(:)=time;
+            nc{'ssh_time'}(:)=time;
+            nc{'zeta_time'}(:)=time;
+            close(nc)
+        end
+        %
+        % Boundary files
+        %
+        if makebry==1
+            %
+            % Copy the file
+            %
+            bryname=[bry_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+            bryname2=[bry_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+            disp(['Create ',bryname2])
+            eval(['!cp ',bryname,' ',bryname2])
+            %
+            % Change the time
+            %
+            nc=netcdf(bryname2,'write');
+            time=nc{'bry_time'}(:)-365.*(Ymin-Y);
+            nc{'bry_time'}(:)=time;
+            close(nc)
+        end
     end
-  end
 end
 %---------------------------------------------------------------
 % Make a few plots
 %---------------------------------------------------------------
 if makeplot==1
-  disp(' ')
-  disp(' Make a few plots...')
-  if makeini==1
-    ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
-    figure
-    test_clim(ininame,grdname,'temp',1,coastfileplot)
-    figure
-    test_clim(ininame,grdname,'salt',1,coastfileplot)
-  end
-  if makeclim==1
-    clmname=[clm_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-    figure
-    test_clim(clmname,grdname,'temp',1,coastfileplot)
-    figure
-    test_clim(clmname,grdname,'salt',1,coastfileplot)
-  end
-  if makebry==1
-    bryname=[bry_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
-    figure
-    test_bry(bryname,grdname,'temp',1,obc)
-    figure
-    test_bry(bryname,grdname,'salt',1,obc)
-    figure
-    test_bry(bryname,grdname,'u',1,obc)
-    figure
-    test_bry(bryname,grdname,'v',1,obc)
-  end
+    disp(' ')
+    disp(' Make a few plots...')
+    if makeini==1
+        ininame=[ini_prefix,'Y',num2str(Ymin),'M',num2str(sprintf(Mth_format,Mmin)),nc_suffix];
+        figure
+        test_clim(ininame,grdname,'temp',1,coastfileplot)
+        figure
+        test_clim(ininame,grdname,'salt',1,coastfileplot)
+    end
+    if makeclim==1
+        clmname=[clm_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+        figure
+        test_clim(clmname,grdname,'temp',1,coastfileplot)
+        figure
+        test_clim(clmname,grdname,'salt',1,coastfileplot)
+    end
+    if makebry==1
+        bryname=[bry_prefix,'Y',num2str(Y),'M',num2str(sprintf(Mth_format,M)),nc_suffix];
+        figure
+        test_bry(bryname,grdname,'temp',1,obc)
+        figure
+        test_bry(bryname,grdname,'salt',1,obc)
+        figure
+        test_bry(bryname,grdname,'u',1,obc)
+        figure
+        test_bry(bryname,grdname,'v',1,obc)
+    end
 end
diff --git a/Preprocessing_tools/Bio/add_bry_pisces.m b/Preprocessing_tools/Bio/add_bry_pisces.m
index 966f75274ee33c4eb9ad9981b26ab728a74dc387..96550928c134f6057946dc26964a74d098880541 100644
--- a/Preprocessing_tools/Bio/add_bry_pisces.m
+++ b/Preprocessing_tools/Bio/add_bry_pisces.m
@@ -1,25 +1,26 @@
-function add_bry_pisces(bryname,obc,time,cycle,makequota,clobber);
+function add_bry_pisces(bryname,obc,time,cycle,...
+  makequota,clobber,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                 
-% function add_bry_pisces(bryname,grdname,title,obc...            
-%                         theta_s,theta_b,hc,N,...                
-%                         time,cycle,clobber);                    
-%                                                                 
-%   This function create the header of a Netcdf climatology       
-%   file.                                                         
-%                                                                 
-%   Input:                                                        
-%                                                                 
-%   bryname      Netcdf climatology file name (character string). 
-%   obc          open boundaries flag (1=open , [S E N W]).       
-%   time         time.(vector)                                    
-%   cycle        Length (days) for cycling the climatology.(Real) 
-%   clobber      Switch to allow or not writing over an existing  
-%                file.(character string)                          
-%
-%  Further Information:  
+%
+% function add_bry_pisces(bryname,grdname,title,obc...
+%                         theta_s,theta_b,hc,N,...
+%                         time,cycle,clobber);
+%
+%   This function create the header of a Netcdf climatology
+%   file.
+%
+%   Input:
+%
+%   bryname      Netcdf climatology file name (character string).
+%   obc          open boundaries flag (1=open , [S E N W]).
+%   time         time.(vector)
+%   cycle        Length (days) for cycling the climatology.(Real)
+%   clobber      Switch to allow or not writing over an existing
+%                file.(character string)
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -37,14 +38,26 @@ function add_bry_pisces(bryname,obc,time,cycle,makequota,clobber);
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2001-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2001-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %  Pierrick Penven, IRD, 2005.                                    %
 %  Olivier Aumont the master, IRD, 2006.                          %
 %  Patricio Marchesiello, chief, IRD, 2007.                       %
 %  Christophe Eugene Raoul Menkes, the slave, IRD, 2007.          %
 %                                                                 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 disp(' ')
 disp([' Adding PISCES data into file : ',bryname])
 disp(' ')
@@ -65,8 +78,8 @@ nc('si_time')   = length(time);
 nc('fer_time')  = length(time);
 nc('o2_time')   = length(time);
 if makequota
-   nc('dop_time')  = length(time);
-   nc('don_time')  = length(time);
+  nc('dop_time')  = length(time);
+  nc('don_time')  = length(time);
 end
 nc('one') = 1;
 %
@@ -75,346 +88,344 @@ nc('one') = 1;
 nc{'dic_time'} = ncdouble('dic_time') ;
 nc{'dic_time'}.long_name = ncchar('time for DIC climatology');
 nc{'dic_time'}.long_name = 'time for DIC climatology';
-nc{'dic_time'}.units = ncchar('day');
-nc{'dic_time'}.units = 'day';
-nc{'dic_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'dic_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'talk_time'} = ncdouble('talk_time') ;
 nc{'talk_time'}.long_name = ncchar('time for TALK climatology');
 nc{'talk_time'}.long_name = 'time for TALK climatology';
-nc{'talk_time'}.units = ncchar('day');
-nc{'talk_time'}.units = 'day';
-nc{'talk_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'talk_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'no3_time'} = ncdouble('no3_time') ;
 nc{'no3_time'}.long_name = ncchar('time for NO3 climatology');
 nc{'no3_time'}.long_name = 'time for NO3 climatology';
-nc{'no3_time'}.units = ncchar('day');
-nc{'no3_time'}.units = 'day';
-nc{'no3_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'po4_time'} = ncdouble('po4_time') ;
 nc{'po4_time'}.long_name = ncchar('time for PO4 climatology');
 nc{'po4_time'}.long_name = 'time for PO4 climatology';
-nc{'po4_time'}.units = ncchar('day');
-nc{'po4_time'}.units = 'day';
-nc{'po4_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'po4_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'si_time'} = ncdouble('si_time') ;
 nc{'si_time'}.long_name = ncchar('time for Si climatology');
 nc{'si_time'}.long_name = 'time for Si climatology';
-nc{'si_time'}.units = ncchar('day');
-nc{'si_time'}.units = 'day';
-nc{'si_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'si_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'o2_time'} = ncdouble('o2_time') ;
 nc{'o2_time'}.long_name = ncchar('time for O2 climatology');
 nc{'o2_time'}.long_name = 'time for O2 climatology';
-nc{'o2_time'}.units = ncchar('day');
-nc{'o2_time'}.units = 'day';
-nc{'o2_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'doc_time'} = ncdouble('doc_time') ;
 nc{'doc_time'}.long_name = ncchar('time for DOC climatology');
 nc{'doc_time'}.long_name = 'time for DOC climatology';
-nc{'doc_time'}.units = ncchar('day');
-nc{'doc_time'}.units = 'day';
-nc{'doc_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'doc_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'fer_time'} = ncdouble('fer_time') ;
 nc{'fer_time'}.long_name = ncchar('time for FER climatology');
 nc{'fer_time'}.long_name = 'time for FER climatology';
-nc{'fer_time'}.units = ncchar('day');
-nc{'fer_time'}.units = 'day';
-nc{'fer_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'fer_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 if makequota
-   nc{'dop_time'} = ncdouble('dop_time') ;
-   nc{'dop_time'}.long_name = ncchar('time for DOP climatology');
-   nc{'dop_time'}.long_name = 'time for DOP climatology';
-   nc{'dop_time'}.units = ncchar('day');
-   nc{'dop_time'}.units = 'day';
-   nc{'dop_time'}.cycle_length = cycle;%
-%
-   nc{'don_time'} = ncdouble('don_time') ;
-   nc{'don_time'}.long_name = ncchar('time for DON climatology');
-   nc{'don_time'}.long_name = 'time for DON climatology';
-   nc{'don_time'}.units = ncchar('day');
-   nc{'don_time'}.units = 'day';
-   nc{'don_time'}.cycle_length = cycle;%
+  nc{'dop_time'} = ncdouble('dop_time') ;
+  nc{'dop_time'}.long_name = ncchar('time for DOP climatology');
+  nc{'dop_time'}.long_name = 'time for DOP climatology';
+  write_time_attributes(nc,'dop_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+ 
+  %
+  nc{'don_time'} = ncdouble('don_time') ;
+  nc{'don_time'}.long_name = ncchar('time for DON climatology');
+  nc{'don_time'}.long_name = 'time for DON climatology';
+  write_time_attributes(nc,'don_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+  
 end
 %
 %
 if obc(1)==1
-%
-%   Southern boundary
-%
+  %
+  %   Southern boundary
+  %
   nc{'NO3_south'} = ncdouble('no3_time','s_rho','xi_rho') ;
   nc{'NO3_south'}.long_name = ncchar('southern boundary NO3');
   nc{'NO3_south'}.long_name = 'southern boundary NO3';
   nc{'NO3_south'}.units = ncchar('mMol N m-3');
   nc{'NO3_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_south'} = ncdouble('po4_time','s_rho','xi_rho') ;
   nc{'PO4_south'}.long_name = ncchar('southern boundary PO4');
   nc{'PO4_south'}.long_name = 'southern boundary PO4';
   nc{'PO4_south'}.units = ncchar('mMol N m-3');
   nc{'PO4_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_south'} = ncdouble('si_time','s_rho','xi_rho') ;
   nc{'Si_south'}.long_name = ncchar('southern boundary Si');
   nc{'Si_south'}.long_name = 'southern boundary Si';
   nc{'Si_south'}.units = ncchar('mMol N m-3');
   nc{'Si_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_south'} = ncdouble('o2_time','s_rho','xi_rho') ;
   nc{'O2_south'}.long_name = ncchar('southern boundary O2');
   nc{'O2_south'}.long_name = 'southern boundary O2';
   nc{'O2_south'}.units = ncchar('mMol N m-3');
   nc{'O2_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_south'} = ncdouble('dic_time','s_rho','xi_rho') ;
   nc{'DIC_south'}.long_name = ncchar('southern boundary DIC');
   nc{'DIC_south'}.long_name = 'southern boundary DIC';
   nc{'DIC_south'}.units = ncchar('mMol N m-3');
   nc{'DIC_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_south'} = ncdouble('talk_time','s_rho','xi_rho') ;
   nc{'TALK_south'}.long_name = ncchar('southern boundary TALK');
   nc{'TALK_south'}.long_name = 'southern boundary TALK';
   nc{'TALK_south'}.units = ncchar('mMol N m-3');
   nc{'TALK_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_south'} = ncdouble('doc_time','s_rho','xi_rho') ;
   nc{'DOC_south'}.long_name = ncchar('southern boundary DOC');
   nc{'DOC_south'}.long_name = 'southern boundary DOC';
   nc{'DOC_south'}.units = ncchar('mMol N m-3');
   nc{'DOC_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_south'} = ncdouble('fer_time','s_rho','xi_rho') ;
   nc{'FER_south'}.long_name = ncchar('southern boundary Iron');
   nc{'FER_south'}.long_name = 'southern boundary Iron';
   nc{'FER_south'}.units = ncchar('mMol N m-3');
   nc{'FER_south'}.units = 'mMol N m-3';
-%
+  %
   if makequota
-     nc{'DOP_south'} = ncdouble('dop_time','s_rho','xi_rho') ;
-     nc{'DOP_south'}.long_name = ncchar('southern boundary DOP');
-     nc{'DOP_south'}.long_name = 'southern boundary DOP';
-     nc{'DOP_south'}.units = ncchar('mMol N m-3');
-     nc{'DOP_south'}.units = 'mMol N m-3';
-%
-     nc{'DON_south'} = ncdouble('don_time','s_rho','xi_rho') ;
-     nc{'DON_south'}.long_name = ncchar('southern boundary DON');
-     nc{'DON_south'}.long_name = 'southern boundary DON';
-     nc{'DON_south'}.units = ncchar('mMol N m-3');
-     nc{'DON_south'}.units = 'mMol N m-3';
- end
-%
+    nc{'DOP_south'} = ncdouble('dop_time','s_rho','xi_rho') ;
+    nc{'DOP_south'}.long_name = ncchar('southern boundary DOP');
+    nc{'DOP_south'}.long_name = 'southern boundary DOP';
+    nc{'DOP_south'}.units = ncchar('mMol N m-3');
+    nc{'DOP_south'}.units = 'mMol N m-3';
+    %
+    nc{'DON_south'} = ncdouble('don_time','s_rho','xi_rho') ;
+    nc{'DON_south'}.long_name = ncchar('southern boundary DON');
+    nc{'DON_south'}.long_name = 'southern boundary DON';
+    nc{'DON_south'}.units = ncchar('mMol N m-3');
+    nc{'DON_south'}.units = 'mMol N m-3';
+  end
+  %
 end
 %
 if obc(2)==1
-%
-%   Eastern boundary
-%
+  %
+  %   Eastern boundary
+  %
   nc{'NO3_east'} = ncdouble('no3_time','s_rho','eta_rho') ;
   nc{'NO3_east'}.long_name = ncchar('eastern boundary NO3');
   nc{'NO3_east'}.long_name = 'eastern boundary NO3';
   nc{'NO3_east'}.units = ncchar('mMol N m-3');
   nc{'NO3_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_east'} = ncdouble('po4_time','s_rho','eta_rho') ;
   nc{'PO4_east'}.long_name = ncchar('eastern boundary PO4');
   nc{'PO4_east'}.long_name = 'eastern boundary PO4';
   nc{'PO4_east'}.units = ncchar('mMol N m-3');
   nc{'PO4_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_east'} = ncdouble('si_time','s_rho','eta_rho') ;
   nc{'Si_east'}.long_name = ncchar('eastern boundary Si');
   nc{'Si_east'}.long_name = 'eastern boundary Si';
   nc{'Si_east'}.units = ncchar('mMol N m-3');
   nc{'Si_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_east'} = ncdouble('o2_time','s_rho','eta_rho') ;
   nc{'O2_east'}.long_name = ncchar('eastern boundary O2');
   nc{'O2_east'}.long_name = 'eastern boundary O2';
   nc{'O2_east'}.units = ncchar('mMol N m-3');
   nc{'O2_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_east'} = ncdouble('dic_time','s_rho','eta_rho') ;
   nc{'DIC_east'}.long_name = ncchar('eastern boundary DIC');
   nc{'DIC_east'}.long_name = 'eastern boundary DIC';
   nc{'DIC_east'}.units = ncchar('mMol N m-3');
   nc{'DIC_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_east'} = ncdouble('talk_time','s_rho','eta_rho') ;
   nc{'TALK_east'}.long_name = ncchar('eastern boundary TALK');
   nc{'TALK_east'}.long_name = 'eastern boundary TALK';
   nc{'TALK_east'}.units = ncchar('mMol N m-3');
   nc{'TALK_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_east'} = ncdouble('doc_time','s_rho','eta_rho') ;
   nc{'DOC_east'}.long_name = ncchar('eastern boundary DOC');
   nc{'DOC_east'}.long_name = 'eastern boundary DOC';
   nc{'DOC_east'}.units = ncchar('mMol N m-3');
   nc{'DOC_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_east'} = ncdouble('fer_time','s_rho','eta_rho') ;
   nc{'FER_east'}.long_name = ncchar('eastern boundary Iron');
   nc{'FER_east'}.long_name = 'eastern boundary Iron';
   nc{'FER_east'}.units = ncchar('mMol N m-3');
   nc{'FER_east'}.units = 'mMol N m-3';
-%
+  %
   if makequota
-     nc{'DOP_east'} = ncdouble('dop_time','s_rho','eta_rho') ;
-     nc{'DOP_east'}.long_name = ncchar('eastern boundary DOP');
-     nc{'DOP_east'}.long_name = 'eastern boundary DOP';
-     nc{'DOP_east'}.units = ncchar('mMol N m-3');
-     nc{'DOP_east'}.units = 'mMol N m-3';
-%
-     nc{'DON_east'} = ncdouble('don_time','s_rho','eta_rho') ;
-     nc{'DON_east'}.long_name = ncchar('eastern boundary DON');
-     nc{'DON_east'}.long_name = 'eastern boundary DON';
-     nc{'DON_east'}.units = ncchar('mMol N m-3');
-     nc{'DON_east'}.units = 'mMol N m-3';
+    nc{'DOP_east'} = ncdouble('dop_time','s_rho','eta_rho') ;
+    nc{'DOP_east'}.long_name = ncchar('eastern boundary DOP');
+    nc{'DOP_east'}.long_name = 'eastern boundary DOP';
+    nc{'DOP_east'}.units = ncchar('mMol N m-3');
+    nc{'DOP_east'}.units = 'mMol N m-3';
+    %
+    nc{'DON_east'} = ncdouble('don_time','s_rho','eta_rho') ;
+    nc{'DON_east'}.long_name = ncchar('eastern boundary DON');
+    nc{'DON_east'}.long_name = 'eastern boundary DON';
+    nc{'DON_east'}.units = ncchar('mMol N m-3');
+    nc{'DON_east'}.units = 'mMol N m-3';
   end
-%
+  %
 end
 %
 if obc(3)==1
-%
-%   Northern boundary
-%
+  %
+  %   Northern boundary
+  %
   nc{'NO3_north'} = ncdouble('no3_time','s_rho','xi_rho') ;
   nc{'NO3_north'}.long_name = ncchar('northern boundary NO3');
   nc{'NO3_north'}.long_name = 'northern boundary NO3';
   nc{'NO3_north'}.units = ncchar('mMol N m-3');
   nc{'NO3_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_north'} = ncdouble('po4_time','s_rho','xi_rho') ;
   nc{'PO4_north'}.long_name = ncchar('northern boundary PO4');
   nc{'PO4_north'}.long_name = 'northern boundary PO4';
   nc{'PO4_north'}.units = ncchar('mMol N m-3');
   nc{'PO4_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_north'} = ncdouble('si_time','s_rho','xi_rho') ;
   nc{'Si_north'}.long_name = ncchar('northern boundary Si');
   nc{'Si_north'}.long_name = 'northern boundary Si';
   nc{'Si_north'}.units = ncchar('mMol N m-3');
   nc{'Si_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_north'} = ncdouble('o2_time','s_rho','xi_rho') ;
   nc{'O2_north'}.long_name = ncchar('northern boundary O2');
   nc{'O2_north'}.long_name = 'northern boundary O2';
   nc{'O2_north'}.units = ncchar('mMol N m-3');
   nc{'O2_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_north'} = ncdouble('dic_time','s_rho','xi_rho') ;
   nc{'DIC_north'}.long_name = ncchar('northern boundary DIC');
   nc{'DIC_north'}.long_name = 'northern boundary DIC';
   nc{'DIC_north'}.units = ncchar('mMol N m-3');
   nc{'DIC_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_north'} = ncdouble('talk_time','s_rho','xi_rho') ;
   nc{'TALK_north'}.long_name = ncchar('northern boundary TALK');
   nc{'TALK_north'}.long_name = 'northern boundary TALK';
   nc{'TALK_north'}.units = ncchar('mMol N m-3');
   nc{'TALK_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_north'} = ncdouble('doc_time','s_rho','xi_rho') ;
   nc{'DOC_north'}.long_name = ncchar('northern boundary DOC');
   nc{'DOC_north'}.long_name = 'northern boundary DOC';
   nc{'DOC_north'}.units = ncchar('mMol N m-3');
   nc{'DOC_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_north'} = ncdouble('fer_time','s_rho','xi_rho') ;
   nc{'FER_north'}.long_name = ncchar('northern boundary Iron');
   nc{'FER_north'}.long_name = 'northern boundary Iron';
   nc{'FER_north'}.units = ncchar('mMol N m-3');
   nc{'FER_north'}.units = 'mMol N m-3';
-%
+  %
   if makequota
-     nc{'DOP_north'} = ncdouble('dop_time','s_rho','xi_rho') ;
-     nc{'DOP_north'}.long_name = ncchar('northern boundary DOP');
-     nc{'DOP_north'}.long_name = 'northern boundary DOP';
-     nc{'DOP_north'}.units = ncchar('mMol N m-3');
-     nc{'DOP_north'}.units = 'mMol N m-3';
-%
-     nc{'DON_north'} = ncdouble('don_time','s_rho','xi_rho') ;
-     nc{'DON_north'}.long_name = ncchar('northern boundary DON');
-     nc{'DON_north'}.long_name = 'northern boundary DON';
-     nc{'DON_north'}.units = ncchar('mMol N m-3');
-     nc{'DON_north'}.units = 'mMol N m-3';
+    nc{'DOP_north'} = ncdouble('dop_time','s_rho','xi_rho') ;
+    nc{'DOP_north'}.long_name = ncchar('northern boundary DOP');
+    nc{'DOP_north'}.long_name = 'northern boundary DOP';
+    nc{'DOP_north'}.units = ncchar('mMol N m-3');
+    nc{'DOP_north'}.units = 'mMol N m-3';
+    %
+    nc{'DON_north'} = ncdouble('don_time','s_rho','xi_rho') ;
+    nc{'DON_north'}.long_name = ncchar('northern boundary DON');
+    nc{'DON_north'}.long_name = 'northern boundary DON';
+    nc{'DON_north'}.units = ncchar('mMol N m-3');
+    nc{'DON_north'}.units = 'mMol N m-3';
   end
-%
+  %
 end
 %
 if obc(4)==1
-%
-%   Western boundary
-%
+  %
+  %   Western boundary
+  %
   nc{'NO3_west'} = ncdouble('no3_time','s_rho','eta_rho') ;
   nc{'NO3_west'}.long_name = ncchar('western boundary NO3');
   nc{'NO3_west'}.long_name = 'western boundary NO3';
   nc{'NO3_west'}.units = ncchar('mMol N m-3');
   nc{'NO3_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_west'} = ncdouble('po4_time','s_rho','eta_rho') ;
   nc{'PO4_west'}.long_name = ncchar('western boundary PO4');
   nc{'PO4_west'}.long_name = 'western boundary PO4';
   nc{'PO4_west'}.units = ncchar('mMol N m-3');
   nc{'PO4_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_west'} = ncdouble('si_time','s_rho','eta_rho') ;
   nc{'Si_west'}.long_name = ncchar('western boundary Si');
   nc{'Si_west'}.long_name = 'western boundary Si';
   nc{'Si_west'}.units = ncchar('mMol N m-3');
   nc{'Si_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_west'} = ncdouble('o2_time','s_rho','eta_rho') ;
   nc{'O2_west'}.long_name = ncchar('western boundary O2');
   nc{'O2_west'}.long_name = 'western boundary O2';
   nc{'O2_west'}.units = ncchar('mMol N m-3');
   nc{'O2_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_west'} = ncdouble('dic_time','s_rho','eta_rho') ;
   nc{'DIC_west'}.long_name = ncchar('western boundary DIC');
   nc{'DIC_west'}.long_name = 'western boundary DIC';
   nc{'DIC_west'}.units = ncchar('mMol N m-3');
   nc{'DIC_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_west'} = ncdouble('talk_time','s_rho','eta_rho') ;
   nc{'TALK_west'}.long_name = ncchar('western boundary TALK');
   nc{'TALK_west'}.long_name = 'western boundary TALK';
   nc{'TALK_west'}.units = ncchar('mMol N m-3');
   nc{'TALK_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_west'} = ncdouble('doc_time','s_rho','eta_rho') ;
   nc{'DOC_west'}.long_name = ncchar('western boundary DOC');
   nc{'DOC_west'}.long_name = 'western boundary DOC';
   nc{'DOC_west'}.units = ncchar('mMol N m-3');
   nc{'DOC_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_west'} = ncdouble('fer_time','s_rho','eta_rho') ;
   nc{'FER_west'}.long_name = ncchar('western boundary Iron');
   nc{'FER_west'}.long_name = 'western boundary Iron';
   nc{'FER_west'}.units = ncchar('mMol N m-3');
   nc{'FER_west'}.units = 'mMol N m-3';
-%
+  %
   if makequota
-     nc{'DOP_west'} = ncdouble('dop_time','s_rho','eta_rho') ;
-     nc{'DOP_west'}.long_name = ncchar('western boundary DOP');
-     nc{'DOP_west'}.long_name = 'western boundary DOP';
-     nc{'DOP_west'}.units = ncchar('mMol N m-3');
-     nc{'DOP_west'}.units = 'mMol N m-3';
-%
-     nc{'DON_west'} = ncdouble('don_time','s_rho','eta_rho') ;
-     nc{'DON_west'}.long_name = ncchar('western boundary DON');
-     nc{'DON_west'}.long_name = 'western boundary DON';
-     nc{'DON_west'}.units = ncchar('mMol N m-3');
-     nc{'DON_west'}.units = 'mMol N m-3';
+    nc{'DOP_west'} = ncdouble('dop_time','s_rho','eta_rho') ;
+    nc{'DOP_west'}.long_name = ncchar('western boundary DOP');
+    nc{'DOP_west'}.long_name = 'western boundary DOP';
+    nc{'DOP_west'}.units = ncchar('mMol N m-3');
+    nc{'DOP_west'}.units = 'mMol N m-3';
+    %
+    nc{'DON_west'} = ncdouble('don_time','s_rho','eta_rho') ;
+    nc{'DON_west'}.long_name = ncchar('western boundary DON');
+    nc{'DON_west'}.long_name = 'western boundary DON';
+    nc{'DON_west'}.units = ncchar('mMol N m-3');
+    nc{'DON_west'}.units = 'mMol N m-3';
   end
-%
+  %
 end
 %
 % Leave define mode
@@ -432,8 +443,8 @@ nc{'si_time'}(:) = time;
 nc{'fer_time'}(:) = time;
 nc{'o2_time'}(:) = time;
 if makequota
-   nc{'dop_time'}(:) = time;
-   nc{'don_time'}(:) = time;
+  nc{'dop_time'}(:) = time;
+  nc{'don_time'}(:) = time;
 end
 if obc(1)==1
   nc{'NO3_south'}(:)  =  0;
@@ -445,10 +456,10 @@ if obc(1)==1
   nc{'DOC_south'}(:)  =  0;
   nc{'FER_south'}(:)  =  0;
   if makequota
-     nc{'DOP_south'}(:)  =  0;
-     nc{'DON_south'}(:)  =  0;
+    nc{'DOP_south'}(:)  =  0;
+    nc{'DON_south'}(:)  =  0;
   end
-end 
+end
 if obc(2)==1
   nc{'NO3_east'}(:)  =  0;
   nc{'PO4_east'}(:)  =  0;
@@ -459,10 +470,10 @@ if obc(2)==1
   nc{'DOC_east'}(:)  =  0;
   nc{'FER_east'}(:)  =  0;
   if makequota
-     nc{'DOP_east'}(:)  =  0;
-     nc{'DON_east'}(:)  =  0;
+    nc{'DOP_east'}(:)  =  0;
+    nc{'DON_east'}(:)  =  0;
   end
-end 
+end
 if obc(3)==1
   nc{'NO3_north'}(:)  =  0;
   nc{'PO4_north'}(:)  =  0;
@@ -473,10 +484,10 @@ if obc(3)==1
   nc{'DOC_north'}(:)  =  0;
   nc{'FER_north'}(:)  =  0;
   if makequota
-     nc{'DOP_north'}(:)  =  0;
-     nc{'DON_north'}(:)  =  0;
+    nc{'DOP_north'}(:)  =  0;
+    nc{'DON_north'}(:)  =  0;
   end
-end 
+end
 if obc(4)==1
   nc{'NO3_west'}(:)  =  0;
   nc{'PO4_west'}(:)  =  0;
@@ -487,10 +498,10 @@ if obc(4)==1
   nc{'DOC_west'}(:)  =  0;
   nc{'FER_west'}(:)  =  0;
   if makequota
-     nc{'DOP_west'}(:)  =  0;
-     nc{'DON_west'}(:)  =  0
+    nc{'DOP_west'}(:)  =  0;
+    nc{'DON_west'}(:)  =  0
   end
-end 
+end
 close(nc)
 return
 
diff --git a/Preprocessing_tools/Bio/add_bry_pisces_Z.m b/Preprocessing_tools/Bio/add_bry_pisces_Z.m
index 69bde9cd1fab7f65d4f4d5e1991c91ccc0b22394..97667243beef738a64ba34693bb1ccec8e383ffb 100644
--- a/Preprocessing_tools/Bio/add_bry_pisces_Z.m
+++ b/Preprocessing_tools/Bio/add_bry_pisces_Z.m
@@ -1,4 +1,5 @@
-function add_bry_pisces_Z(zbryname,obc,Z,time,cycle,makequota,clobber);
+function add_bry_pisces_Z(zbryname,obc,Z,time,cycle,makequota,...
+  clobber,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                 %
 %   function add_bry_pisces_Z(zbryname,obc,...                    %
@@ -23,6 +24,19 @@ function add_bry_pisces_Z(zbryname,obc,Z,time,cycle,makequota,clobber);
 %  Christophe Eugene Raoul Menkes, the slave, IRD, 2007.          %
 %                                                                 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+
 disp(' ')
 disp([' Adding PISCES data into file : ',zbryname])
 disp(' ')
@@ -35,59 +49,118 @@ nc = netcdf(zbryname,clobber);
 %  Create dimensions
 %
 nc('dic_time') = length(time);
+nc{'dic_time'} = ncdouble('dic_time') ;
+nc{'dic_time'}.long_name = 'time for DIC';
+write_time_attributes(nc,'dic_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+%
 nc('doc_time') = length(time);
+nc{'doc_time'} = ncdouble('doc_time') ;
+nc{'doc_time'}.long_name = 'time for DOC';
+write_time_attributes(nc,'doc_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+%
 nc('no3_time') = length(time);
+nc{'no3_time'} = ncdouble('no3_time') ;
+nc{'no3_time'}.long_name = 'time for NO3';
+write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+%
 nc('po4_time') = length(time);
+nc{'po4_time'} = ncdouble('po4_time') ;
+nc{'po4_time'}.long_name = 'time for PO4';
+write_time_attributes(nc,'po4_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+%
 nc('talk_time') = length(time);
+nc{'talk_time'} = ncdouble('talk_time') ;
+nc{'talk_time'}.long_name = 'time for TALK';
+write_time_attributes(nc,'talk_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+%
 nc('si_time') = length(time);
+nc{'si_time'} = ncdouble('si_time') ;
+nc{'si_time'}.long_name = 'time for silicate';
+write_time_attributes(nc,'si_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+%
 nc('fer_time') = length(time);
+nc{'fer_time'} = ncdouble('fer_time') ;
+nc{'fer_time'}.long_name = 'time for iron';
+write_time_attributes(nc,'fer_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+% %
 nc('o2_time') = length(time);
+nc{'o2_time'} = ncdouble('o2_time') ;
+nc{'o2_time'}.long_name = 'time for oxygen';
+write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
+
 if makequota
-   nc('dop_time') = length(time);
-   nc('don_time') = length(time);
+  nc('dop_time') = length(time);
+  nc{'dop_time'} = ncdouble('dop_time') ;
+  nc{'dop_time'}.long_name = 'time for dop';
+  write_time_attributes(nc,'dop_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+
+  %
+  nc('don_time') = length(time);
+  nc{'don_time'} = ncdouble('don_time') ;
+  nc{'don_time'}.long_name = 'time for don';
+  write_time_attributes(nc,'don_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+ 
 end
 nc('one') = 1;
 %
 if obc(1)==1
-%
-%   Southern boundary
-%
+  %
+  %   Southern boundary
+  %
   nc{'NO3_south'} = ncdouble('no3_time','Z','xi_rho') ;
   nc{'NO3_south'}.long_name = ncchar('southern boundary NO3');
   nc{'NO3_south'}.long_name = 'southern boundary NO3';
   nc{'NO3_south'}.units = ncchar('mMol N m-3');
   nc{'NO3_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_south'} = ncdouble('po4_time','Z','xi_rho') ;
   nc{'PO4_south'}.long_name = ncchar('southern boundary PO4');
   nc{'PO4_south'}.long_name = 'southern boundary PO4';
   nc{'PO4_south'}.units = ncchar('mMol N m-3');
   nc{'PO4_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_south'} = ncdouble('si_time','Z','xi_rho') ;
   nc{'Si_south'}.long_name = ncchar('southern boundary Si');
   nc{'Si_south'}.long_name = 'southern boundary Si';
   nc{'Si_south'}.units = ncchar('mMol N m-3');
   nc{'Si_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_south'} = ncdouble('o2_time','Z','xi_rho') ;
   nc{'O2_south'}.long_name = ncchar('southern boundary O2');
   nc{'O2_south'}.long_name = 'southern boundary O2';
   nc{'O2_south'}.units = ncchar('mMol N m-3');
   nc{'O2_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_south'} = ncdouble('dic_time','Z','xi_rho') ;
   nc{'DIC_south'}.long_name = ncchar('southern boundary DIC');
   nc{'DIC_south'}.long_name = 'southern boundary DIC';
   nc{'DIC_south'}.units = ncchar('mMol N m-3');
   nc{'DIC_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_south'} = ncdouble('talk_time','Z','xi_rho') ;
   nc{'TALK_south'}.long_name = ncchar('southern boundary TALK');
   nc{'TALK_south'}.long_name = 'southern boundary TALK';
   nc{'TALK_south'}.units = ncchar('mMol N m-3');
   nc{'TALK_south'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_south'} = ncdouble('doc_time','Z','xi_rho') ;
   nc{'DOC_south'}.long_name = ncchar('southern boundary DOC');
   nc{'DOC_south'}.long_name = 'southern boundary DOC';
@@ -99,225 +172,225 @@ if obc(1)==1
   nc{'FER_south'}.long_name = 'southern boundary Iron';
   nc{'FER_south'}.units = ncchar('mMol N m-3');
   nc{'FER_south'}.units = 'mMol N m-3';
-%
-   if makequota
-      nc{'DOP_south'} = ncdouble('dop_time','Z','xi_rho') ;
-      nc{'DOP_south'}.long_name = ncchar('southern boundary DOP');
-      nc{'DOP_south'}.long_name = 'southern boundary DOP';
-      nc{'DOP_south'}.units = ncchar('mMol N m-3');
-      nc{'DOP_south'}.units = 'mMol N m-3';
-%
-      nc{'DON_south'} = ncdouble('don_time','Z','xi_rho') ;
-      nc{'DON_south'}.long_name = ncchar('southern boundary DON');
-      nc{'DON_south'}.long_name = 'southern boundary DON';
-      nc{'DON_south'}.units = ncchar('mMol N m-3');
-      nc{'DON_south'}.units = 'mMol N m-3';
-   end
-%
+  %
+  if makequota
+    nc{'DOP_south'} = ncdouble('dop_time','Z','xi_rho') ;
+    nc{'DOP_south'}.long_name = ncchar('southern boundary DOP');
+    nc{'DOP_south'}.long_name = 'southern boundary DOP';
+    nc{'DOP_south'}.units = ncchar('mMol N m-3');
+    nc{'DOP_south'}.units = 'mMol N m-3';
+    %
+    nc{'DON_south'} = ncdouble('don_time','Z','xi_rho') ;
+    nc{'DON_south'}.long_name = ncchar('southern boundary DON');
+    nc{'DON_south'}.long_name = 'southern boundary DON';
+    nc{'DON_south'}.units = ncchar('mMol N m-3');
+    nc{'DON_south'}.units = 'mMol N m-3';
+  end
+  %
 end
 %
 if obc(2)==1
-%
-%   Eastern boundary
-%
+  %
+  %   Eastern boundary
+  %
   nc{'NO3_east'} = ncdouble('no3_time','Z','eta_rho') ;
   nc{'NO3_east'}.long_name = ncchar('eastern boundary NO3');
   nc{'NO3_east'}.long_name = 'eastern boundary NO3';
   nc{'NO3_east'}.units = ncchar('mMol N m-3');
   nc{'NO3_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_east'} = ncdouble('po4_time','Z','eta_rho') ;
   nc{'PO4_east'}.long_name = ncchar('eastern boundary PO4');
   nc{'PO4_east'}.long_name = 'eastern boundary PO4';
   nc{'PO4_east'}.units = ncchar('mMol N m-3');
   nc{'PO4_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_east'} = ncdouble('si_time','Z','eta_rho') ;
   nc{'Si_east'}.long_name = ncchar('eastern boundary Si');
   nc{'Si_east'}.long_name = 'eastern boundary Si';
   nc{'Si_east'}.units = ncchar('mMol N m-3');
   nc{'Si_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_east'} = ncdouble('o2_time','Z','eta_rho') ;
   nc{'O2_east'}.long_name = ncchar('eastern boundary O2');
   nc{'O2_east'}.long_name = 'eastern boundary O2';
   nc{'O2_east'}.units = ncchar('mMol N m-3');
   nc{'O2_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_east'} = ncdouble('dic_time','Z','eta_rho') ;
   nc{'DIC_east'}.long_name = ncchar('eastern boundary DIC');
   nc{'DIC_east'}.long_name = 'eastern boundary DIC';
   nc{'DIC_east'}.units = ncchar('mMol N m-3');
   nc{'DIC_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_east'} = ncdouble('talk_time','Z','eta_rho') ;
   nc{'TALK_east'}.long_name = ncchar('eastern boundary TALK');
   nc{'TALK_east'}.long_name = 'eastern boundary TALK';
   nc{'TALK_east'}.units = ncchar('mMol N m-3');
   nc{'TALK_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_east'} = ncdouble('doc_time','Z','eta_rho') ;
   nc{'DOC_east'}.long_name = ncchar('eastern boundary DOC');
   nc{'DOC_east'}.long_name = 'eastern boundary DOC';
   nc{'DOC_east'}.units = ncchar('mMol N m-3');
   nc{'DOC_east'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_east'} = ncdouble('fer_time','Z','eta_rho') ;
   nc{'FER_east'}.long_name = ncchar('eastern boundary Iron');
   nc{'FER_east'}.long_name = 'eastern boundary Iron';
   nc{'FER_east'}.units = ncchar('mMol N m-3');
   nc{'FER_east'}.units = 'mMol N m-3';
-%
-   if makequota
-      nc{'DOP_east'} = ncdouble('dop_time','Z','eta_rho') ;
-      nc{'DOP_east'}.long_name = ncchar('eastern boundary DOP');
-      nc{'DOP_east'}.long_name = 'eastern boundary DOP';
-      nc{'DOP_east'}.units = ncchar('mMol N m-3');
-      nc{'DOP_east'}.units = 'mMol N m-3';
-%
-      nc{'DON_east'} = ncdouble('don_time','Z','eta_rho') ;
-      nc{'DON_east'}.long_name = ncchar('eastern boundary DON');
-      nc{'DON_east'}.long_name = 'eastern boundary DON';
-      nc{'DON_east'}.units = ncchar('mMol N m-3');
-      nc{'DON_east'}.units = 'mMol N m-3';
-   end
-%
+  %
+  if makequota
+    nc{'DOP_east'} = ncdouble('dop_time','Z','eta_rho') ;
+    nc{'DOP_east'}.long_name = ncchar('eastern boundary DOP');
+    nc{'DOP_east'}.long_name = 'eastern boundary DOP';
+    nc{'DOP_east'}.units = ncchar('mMol N m-3');
+    nc{'DOP_east'}.units = 'mMol N m-3';
+    %
+    nc{'DON_east'} = ncdouble('don_time','Z','eta_rho') ;
+    nc{'DON_east'}.long_name = ncchar('eastern boundary DON');
+    nc{'DON_east'}.long_name = 'eastern boundary DON';
+    nc{'DON_east'}.units = ncchar('mMol N m-3');
+    nc{'DON_east'}.units = 'mMol N m-3';
+  end
+  %
 end
 %
 if obc(3)==1
-%
-%   Northern boundary
-%
+  %
+  %   Northern boundary
+  %
   nc{'NO3_north'} = ncdouble('no3_time','Z','xi_rho') ;
   nc{'NO3_north'}.long_name = ncchar('northern boundary NO3');
   nc{'NO3_north'}.long_name = 'northern boundary NO3';
   nc{'NO3_north'}.units = ncchar('mMol N m-3');
   nc{'NO3_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_north'} = ncdouble('po4_time','Z','xi_rho') ;
   nc{'PO4_north'}.long_name = ncchar('northern boundary PO4');
   nc{'PO4_north'}.long_name = 'northern boundary PO4';
   nc{'PO4_north'}.units = ncchar('mMol N m-3');
   nc{'PO4_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_north'} = ncdouble('si_time','Z','xi_rho') ;
   nc{'Si_north'}.long_name = ncchar('northern boundary Si');
   nc{'Si_north'}.long_name = 'northern boundary Si';
   nc{'Si_north'}.units = ncchar('mMol N m-3');
   nc{'Si_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_north'} = ncdouble('o2_time','Z','xi_rho') ;
   nc{'O2_north'}.long_name = ncchar('northern boundary O2');
   nc{'O2_north'}.long_name = 'northern boundary O2';
   nc{'O2_north'}.units = ncchar('mMol N m-3');
   nc{'O2_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_north'} = ncdouble('dic_time','Z','xi_rho') ;
   nc{'DIC_north'}.long_name = ncchar('northern boundary DIC');
   nc{'DIC_north'}.long_name = 'northern boundary DIC';
   nc{'DIC_north'}.units = ncchar('mMol N m-3');
   nc{'DIC_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_north'} = ncdouble('talk_time','Z','xi_rho') ;
   nc{'TALK_north'}.long_name = ncchar('northern boundary TALK');
   nc{'TALK_north'}.long_name = 'northern boundary TALK';
   nc{'TALK_north'}.units = ncchar('mMol N m-3');
   nc{'TALK_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_north'} = ncdouble('doc_time','Z','xi_rho') ;
   nc{'DOC_north'}.long_name = ncchar('northern boundary DOC');
   nc{'DOC_north'}.long_name = 'northern boundary DOC';
   nc{'DOC_north'}.units = ncchar('mMol N m-3');
   nc{'DOC_north'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_north'} = ncdouble('fer_time','Z','xi_rho') ;
   nc{'FER_north'}.long_name = ncchar('northern boundary Iron');
   nc{'FER_north'}.long_name = 'northern boundary Iron';
   nc{'FER_north'}.units = ncchar('mMol N m-3');
   nc{'FER_north'}.units = 'mMol N m-3';
-%
-   if makequota
-      nc{'DOP_north'} = ncdouble('dop_time','Z','xi_rho') ;
-      nc{'DOP_north'}.long_name = ncchar('northern boundary DOP');
-      nc{'DOP_north'}.long_name = 'northern boundary DOP';
-      nc{'DOP_north'}.units = ncchar('mMol N m-3');
-      nc{'DOP_north'}.units = 'mMol N m-3';
-%
-      nc{'DON_north'} = ncdouble('don_time','Z','xi_rho') ;
-      nc{'DON_north'}.long_name = ncchar('northern boundary DON');
-      nc{'DON_north'}.long_name = 'northern boundary DON';
-      nc{'DON_north'}.units = ncchar('mMol N m-3');
-      nc{'DON_north'}.units = 'mMol N m-3';
-   end
-%
+  %
+  if makequota
+    nc{'DOP_north'} = ncdouble('dop_time','Z','xi_rho') ;
+    nc{'DOP_north'}.long_name = ncchar('northern boundary DOP');
+    nc{'DOP_north'}.long_name = 'northern boundary DOP';
+    nc{'DOP_north'}.units = ncchar('mMol N m-3');
+    nc{'DOP_north'}.units = 'mMol N m-3';
+    %
+    nc{'DON_north'} = ncdouble('don_time','Z','xi_rho') ;
+    nc{'DON_north'}.long_name = ncchar('northern boundary DON');
+    nc{'DON_north'}.long_name = 'northern boundary DON';
+    nc{'DON_north'}.units = ncchar('mMol N m-3');
+    nc{'DON_north'}.units = 'mMol N m-3';
+  end
+  %
 end
 %
 if obc(4)==1
-%
-%   Western boundary
-%
+  %
+  %   Western boundary
+  %
   nc{'NO3_west'} = ncdouble('no3_time','Z','eta_rho') ;
   nc{'NO3_west'}.long_name = ncchar('western boundary NO3');
   nc{'NO3_west'}.long_name = 'western boundary NO3';
   nc{'NO3_west'}.units = ncchar('mMol N m-3');
   nc{'NO3_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'PO4_west'} = ncdouble('po4_time','Z','eta_rho') ;
   nc{'PO4_west'}.long_name = ncchar('western boundary PO4');
   nc{'PO4_west'}.long_name = 'western boundary PO4';
   nc{'PO4_west'}.units = ncchar('mMol N m-3');
   nc{'PO4_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'Si_west'} = ncdouble('si_time','Z','eta_rho') ;
   nc{'Si_west'}.long_name = ncchar('western boundary Si');
   nc{'Si_west'}.long_name = 'western boundary Si';
   nc{'Si_west'}.units = ncchar('mMol N m-3');
   nc{'Si_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'O2_west'} = ncdouble('o2_time','Z','eta_rho') ;
   nc{'O2_west'}.long_name = ncchar('western boundary O2');
   nc{'O2_west'}.long_name = 'western boundary O2';
   nc{'O2_west'}.units = ncchar('mMol N m-3');
   nc{'O2_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'DIC_west'} = ncdouble('dic_time','Z','eta_rho') ;
   nc{'DIC_west'}.long_name = ncchar('western boundary DIC');
   nc{'DIC_west'}.long_name = 'western boundary DIC';
   nc{'DIC_west'}.units = ncchar('mMol N m-3');
   nc{'DIC_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'TALK_west'} = ncdouble('talk_time','Z','eta_rho') ;
   nc{'TALK_west'}.long_name = ncchar('western boundary TALK');
   nc{'TALK_west'}.long_name = 'western boundary TALK';
   nc{'TALK_west'}.units = ncchar('mMol N m-3');
   nc{'TALK_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'DOC_west'} = ncdouble('doc_time','Z','eta_rho') ;
   nc{'DOC_west'}.long_name = ncchar('western boundary DOC');
   nc{'DOC_west'}.long_name = 'western boundary DOC';
   nc{'DOC_west'}.units = ncchar('mMol N m-3');
   nc{'DOC_west'}.units = 'mMol N m-3';
-%
+  %
   nc{'FER_west'} = ncdouble('fer_time','Z','eta_rho') ;
   nc{'FER_west'}.long_name = ncchar('western boundary Iron');
   nc{'FER_west'}.long_name = 'western boundary Iron';
   nc{'FER_west'}.units = ncchar('mMol N m-3');
   nc{'FER_west'}.units = 'mMol N m-3';
-%
-   if makequota
-      nc{'DOP_west'} = ncdouble('dop_time','Z','eta_rho') ;
-      nc{'DOP_west'}.long_name = ncchar('western boundary DOP');
-      nc{'DOP_west'}.long_name = 'western boundary DOP';
-      nc{'DOP_west'}.units = ncchar('mMol N m-3');
-      nc{'DOP_west'}.units = 'mMol N m-3';
-%
-      nc{'DON_west'} = ncdouble('don_time','Z','eta_rho') ;
-      nc{'DON_west'}.long_name = ncchar('western boundary DON');
-      nc{'DON_west'}.long_name = 'western boundary DON';
-      nc{'DON_west'}.units = ncchar('mMol N m-3');
-      nc{'DON_west'}.units = 'mMol N m-3';
-   end
-%
+  %
+  if makequota
+    nc{'DOP_west'} = ncdouble('dop_time','Z','eta_rho') ;
+    nc{'DOP_west'}.long_name = ncchar('western boundary DOP');
+    nc{'DOP_west'}.long_name = 'western boundary DOP';
+    nc{'DOP_west'}.units = ncchar('mMol N m-3');
+    nc{'DOP_west'}.units = 'mMol N m-3';
+    %
+    nc{'DON_west'} = ncdouble('don_time','Z','eta_rho') ;
+    nc{'DON_west'}.long_name = ncchar('western boundary DON');
+    nc{'DON_west'}.long_name = 'western boundary DON';
+    nc{'DON_west'}.units = ncchar('mMol N m-3');
+    nc{'DON_west'}.units = 'mMol N m-3';
+  end
+  %
 end
 %
 % Leave define mode
@@ -326,18 +399,18 @@ end
 %
 % Write variables
 %
-nc('dic_time') = time;
-nc('doc_time') = time;
-nc('no3_time') = time;
-nc('po4_time') = time;
-nc('talk_time') = time;
-nc('si_time') = time;
-nc('fer_time') = time;
-nc('o2_time') = time;
-   if makequota
-      nc('dop_time') = time;
-      nc('don_time') = time;
-   end
+nc{'dic_time'}(:) = time;
+nc{'doc_time'}(:) = time;
+nc{'no3_time'}(:) = time;
+nc{'po4_time'}(:) = time;
+nc{'talk_time'}(:) = time;
+nc{'si_time'}(:) = time;
+nc{'fer_time'}(:) = time;
+nc{'o2_time'}(:) = time;
+if makequota
+  nc{'dop_time'}(:) = time;
+  nc{'don_time'}(:) = time;
+end
 if obc(1)==1
   nc{'NO3_south'}(:)  =  0;
   nc{'PO4_south'}(:)  =  0;
@@ -347,12 +420,12 @@ if obc(1)==1
   nc{'TALK_south'}(:) =  0;
   nc{'DOC_south'}(:)  =  0;
   nc{'FER_south'}(:)  =  0;
-     if makequota
-        nc{'DOP_south'}(:)  =  0;
-        nc{'DON_south'}(:)  =  0;
-     end
-end 
-if obc(2)==1 
+  if makequota
+    nc{'DOP_south'}(:)  =  0;
+    nc{'DON_south'}(:)  =  0;
+  end
+end
+if obc(2)==1
   nc{'NO3_east'}(:)  =  0;
   nc{'PO4_east'}(:)  =  0;
   nc{'Si_east'}(:) =  0;
@@ -361,12 +434,12 @@ if obc(2)==1
   nc{'TALK_east'}(:) =  0;
   nc{'DOC_east'}(:)  =  0;
   nc{'FER_east'}(:)  =  0;
-     if makequota
-        nc{'DOP_east'}(:)  =  0;
-        nc{'DON_east'}(:)  =  0;
-     end
-end 
-if obc(3)==1 
+  if makequota
+    nc{'DOP_east'}(:)  =  0;
+    nc{'DON_east'}(:)  =  0;
+  end
+end
+if obc(3)==1
   nc{'NO3_north'}(:)  =  0;
   nc{'PO4_north'}(:)  =  0;
   nc{'Si_north'}(:) =  0;
@@ -375,12 +448,12 @@ if obc(3)==1
   nc{'TALK_north'}(:) =  0;
   nc{'DOC_north'}(:)  =  0;
   nc{'FER_north'}(:)  =  0;
-     if makequota
-        nc{'DOP_north'}(:)  =  0;
-        nc{'DON_north'}(:)  =  0;
-     end
-end 
-if obc(4)==1 
+  if makequota
+    nc{'DOP_north'}(:)  =  0;
+    nc{'DON_north'}(:)  =  0;
+  end
+end
+if obc(4)==1
   nc{'NO3_west'}(:)  =  0;
   nc{'PO4_west'}(:)  =  0;
   nc{'Si_west'}(:) =  0;
@@ -389,11 +462,11 @@ if obc(4)==1
   nc{'TALK_west'}(:) =  0;
   nc{'DOC_west'}(:)  =  0;
   nc{'FER_west'}(:)  =  0;
-     if makequota
-        nc{'DOP_west'}(:)  =  0;
-        nc{'DON_west'}(:)  =  0;
-    end
-end 
+  if makequota
+    nc{'DOP_west'}(:)  =  0;
+    nc{'DON_west'}(:)  =  0;
+  end
+end
 close(nc)
 return
 
diff --git a/Preprocessing_tools/Bio/add_dic.m b/Preprocessing_tools/Bio/add_dic.m
index 7796c218a157c6c7ce7870eba5db7ae256c56877..fd3edaac37d81d1760d83fc1878acaf114641717 100644
--- a/Preprocessing_tools/Bio/add_dic.m
+++ b/Preprocessing_tools/Bio/add_dic.m
@@ -1,5 +1,5 @@
 function add_dic(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,dic]=add_dic(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_dic(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -29,13 +29,25 @@ function add_dic(oafile,climfile,inifile,gridfile,seas_datafile,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0 ;
+add_cycle = 1 ; 
+%
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                    get_time_attributes(Yorig);
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +58,37 @@ kmax=max(find(zdic<hmax))-1;
 zdic=zdic(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_dic: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('dic_time') = length(t);
   nc{'dic_time'} = ncdouble('dic_time') ;
   nc('Zdic') = length(zdic);
   nc{'Zdic'} = ncdouble('Zdic') ;
   nc{'DIC'} = ncdouble('dic_time','Zdic','eta_rho','xi_rho') ;
-%
-  nc{'dic_time'}.long_name = ncchar('time for DIC');
-  nc{'dic_time'}.long_name = 'time for DIC';
-  nc{'dic_time'}.units = ncchar('day');
-  nc{'dic_time'}.units = 'day';
-  if cycle~=0
-    nc{'dic_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'dic_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  
+  %
   nc{'Zdic'}.long_name = ncchar('Depth for DIC');
   nc{'Zdic'}.long_name = 'Depth for DIC';
   nc{'Zdic'}.units = ncchar('m');
   nc{'Zdic'}.units = 'm';
-%
+  %
   nc{'DIC'}.long_name = ncchar('DIC');
   nc{'DIC'}.long_name = 'DIC';
   nc{'DIC'}.units = ncchar('mMol C m-3');
   nc{'DIC'}.units = 'mMol C m-3';
   nc{'DIC'}.fields = ncchar('DIC, scalar, series');
   nc{'DIC'}.fields = 'DIC, scalar, series';
-%
-%%  endef(nc);
-%
-% record deth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record deth and time and close
+  %
   nc{'dic_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Zdic'}(:)=zdic;
   close(nc)
@@ -91,56 +98,55 @@ end
 %
 if (makeclim)
   disp('Add_dic: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('dic_time') = length(t);;
   nc{'dic_time'} = ncdouble('dic_time') ;
   nc{'DIC'} = ncdouble('dic_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'dic_time'}.long_name = ncchar('time for DIC');
   nc{'dic_time'}.long_name = 'time for DIC';
-  nc{'dic_time'}.units = ncchar('day');
-  nc{'dic_time'}.units = 'day';
-  if cycle~=0
-    nc{'dic_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'dic_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'DIC'}.long_name = ncchar('DIC');
   nc{'DIC'}.long_name = 'DIC';
   nc{'DIC'}.units = ncchar('mMol C m-3');
   nc{'DIC'}.units = 'mMol C m-3';
   nc{'DIC'}.fields = ncchar('DIC, scalar, series');
   nc{'DIC'}.fields = 'DIC, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'dic_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-%
-% Same thing for the Initial file
-if (makeini)
-%
-disp('Add_dic: creating variables and attributes for the Initial file')
-%
-% open the clim file  
-% 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'DIC'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-%
-nc{'DIC'}.long_name = ncchar('DIC');
-nc{'DIC'}.long_name = 'DIC';
-nc{'DIC'}.units = ncchar('mMol C m-3');
-nc{'DIC'}.units = 'mMol C m-3';
-end
+% %
+% % Same thing for the Initial file
+% if (makeini)
+% %
+% disp('Add_dic: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
+% %
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'DIC'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% nc{'DIC'}.long_name = ncchar('DIC');
+% nc{'DIC'}.long_name = 'DIC';
+% nc{'DIC'}.units = ncchar('mMol C m-3');
+% nc{'DIC'}.units = 'mMol C m-3';
+% endef(nc);
+% close(nc)
+% end
+
+
 
-endef(nc);
-close(nc)
 
 return
diff --git a/Preprocessing_tools/Bio/add_doc.m b/Preprocessing_tools/Bio/add_doc.m
index 2a101b7aeb28c0b5dca4f9b0f2af18f1892b568f..5362a137db46644941401e973039ec0bff096228 100644
--- a/Preprocessing_tools/Bio/add_doc.m
+++ b/Preprocessing_tools/Bio/add_doc.m
@@ -1,5 +1,5 @@
 function add_doc(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,doc]=add_doc(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_doc(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -29,13 +29,24 @@ function add_doc(oafile,climfile,inifile,gridfile,seas_datafile,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +57,40 @@ kmax=max(find(zdoc<hmax))-1;
 zdoc=zdoc(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_doc: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('doc_time') = length(t);
   nc{'doc_time'} = ncdouble('doc_time') ;
   nc('Zdoc') = length(zdoc);
   nc{'Zdoc'} = ncdouble('Zdoc') ;
   nc{'DOC'} = ncdouble('doc_time','Zdoc','eta_rho','xi_rho') ;
-%
+  %
   nc{'doc_time'}.long_name = ncchar('time for doc');
   nc{'doc_time'}.long_name = 'time for doc';
-  nc{'doc_time'}.units = ncchar('day');
-  nc{'doc_time'}.units = 'day';
-  if cycle~=0
-    nc{'doc_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'doc_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+
+  %
   nc{'Zdoc'}.long_name = ncchar('Depth for DOC');
   nc{'Zdoc'}.long_name = 'Depth for DOC';
   nc{'Zdoc'}.units = ncchar('m');
   nc{'Zdoc'}.units = 'm';
-%
+  %
   nc{'DOC'}.long_name = ncchar('DOC');
   nc{'DOC'}.long_name = 'DOC';
   nc{'DOC'}.units = ncchar('mMol C m-3');
   nc{'DOC'}.units = 'mMol C m-3';
   nc{'DOC'}.fields = ncchar('DOC, scalar, series');
   nc{'DOC'}.fields = 'DOC, scalar, series';
-%
-%%  endef(nc);
-%
-% record deth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record deth and time and close
+  %
   nc{'doc_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Zdoc'}(:)=zdoc;
   close(nc)
@@ -91,56 +100,53 @@ end
 %
 if (makeclim)
   disp('Add_doc: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('doc_time') = length(t);;
   nc{'doc_time'} = ncdouble('doc_time') ;
   nc{'DOC'} = ncdouble('doc_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'doc_time'}.long_name = ncchar('time for doc');
   nc{'doc_time'}.long_name = 'time for doc';
-  nc{'doc_time'}.units = ncchar('day');
-  nc{'doc_time'}.units = 'day';
-  if cycle~=0
-    nc{'doc_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'doc_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'DOC'}.long_name = ncchar('DOC');
   nc{'DOC'}.long_name = 'DOC';
   nc{'DOC'}.units = ncchar('mMol C m-3');
   nc{'DOC'}.units = 'mMol C m-3';
   nc{'DOC'}.fields = ncchar('DOC, scalar, series');
   nc{'DOC'}.fields = 'DOC, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'doc_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-%
-% Same thing for the Initial file
-%
-if (makeini)
-disp('Add_doc: creating variables and attributes for the Initial file')
-%
-% open the clim file  
-% 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'DOC'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-%
-nc{'DOC'}.long_name = ncchar('DOC');
-nc{'DOC'}.long_name = 'DOC';
-nc{'DOC'}.units = ncchar('mMol C m-3');
-nc{'DOC'}.units = 'mMol C m-3';
-%
-endef(nc);
-close(nc)
-end
+% %
+% % Same thing for the Initial file
+% %
+% if (makeini)
+% disp('Add_doc: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
+% %
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'DOC'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% nc{'DOC'}.long_name = ncchar('DOC');
+% nc{'DOC'}.long_name = 'DOC';
+% nc{'DOC'}.units = ncchar('mMol C m-3');
+% nc{'DOC'}.units = 'mMol C m-3';
+% %
+% endef(nc);
+% close(nc)
+% end
 
 return
diff --git a/Preprocessing_tools/Bio/add_don.m b/Preprocessing_tools/Bio/add_don.m
index 4d76919366b5a422ea9b65063569a5f010706a2d..005b6f03781fa4ea0e65cf044325b0a0b66a5bdb 100644
--- a/Preprocessing_tools/Bio/add_don.m
+++ b/Preprocessing_tools/Bio/add_don.m
@@ -1,5 +1,5 @@
 function add_don(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makequota,makeini);
+                 ann_datafile,cycle,makeoa,makeclim,makequota,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,doc]=add_doc(climfile,gridfile,...
@@ -50,6 +50,18 @@ function add_don(oafile,climfile,inifile,gridfile,seas_datafile,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
@@ -100,11 +112,9 @@ if (makeoa)
 
   nc{'don_time'}.long_name = ncchar('time for don');
   nc{'don_time'}.long_name = 'time for don';
-  nc{'don_time'}.units = ncchar('day');
-  nc{'don_time'}.units = 'day';
-  if cycle~=0
-    nc{'don_time'}.cycle_length = cycle;
-  end
+  write_time_attributes(nc,'don_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+
 %%
   nc{'Zdon'}.long_name = ncchar('Depth for DON');
   nc{'Zdon'}.long_name = 'Depth for DON';
@@ -143,11 +153,8 @@ if (makeclim)
 %
   nc{'don_time'}.long_name = ncchar('time for don');
   nc{'don_time'}.long_name = 'time for don';
-  nc{'don_time'}.units = ncchar('day');
-  nc{'don_time'}.units = 'day';
-  if cycle~=0
-    nc{'don_time'}.cycle_length = cycle;
-  end
+  write_time_attributes(nc,'don_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
 %
   nc{'DON'}.long_name = ncchar('DON');
   nc{'DON'}.long_name = 'DON';
@@ -163,25 +170,25 @@ if (makeclim)
   nc{'don_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-%
-% Same thing for the Initial file
-%
-if (makeini)
-disp('Add_don: creating variables and attributes for the Initial file')
-%
-% open the clim file  
-% 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'DON'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-%
-nc{'DON'}.long_name = ncchar('DON');
-nc{'DON'}.long_name = 'DON';
-nc{'DON'}.units = ncchar('mMol C m-3');
-nc{'DON'}.units = 'mMol C m-3';
-%
-endef(nc);
-close(nc)
-end
+% %
+% % Same thing for the Initial file
+% %
+% if (makeini)
+% disp('Add_don: creating variables and attributes for the Initial file')
+% %
+% % open the clim file  
+% % 
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'DON'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% nc{'DON'}.long_name = ncchar('DON');
+% nc{'DON'}.long_name = 'DON';
+% nc{'DON'}.units = ncchar('mMol C m-3');
+% nc{'DON'}.units = 'mMol C m-3';
+% %
+% endef(nc);
+% close(nc)
+% end
 
 return
diff --git a/Preprocessing_tools/Bio/add_dop.m b/Preprocessing_tools/Bio/add_dop.m
index 8c9900870ca84146078f9aaa332efc8e0970b2f1..5010f40dd93eb371423c53892722db2cddb6fc6b 100644
--- a/Preprocessing_tools/Bio/add_dop.m
+++ b/Preprocessing_tools/Bio/add_dop.m
@@ -1,5 +1,5 @@
 function add_dop(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makequota,makeini);
+                 ann_datafile,cycle,makeoa,makeclim,makequota,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,dop]=add_dop(climfile,gridfile,...
@@ -49,6 +49,18 @@ function add_dop(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  e-mail:Pierrick.Penven@ird.fr
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 %
 % Read in the grid
 %
@@ -100,11 +112,8 @@ if (makeoa)
 
   nc{'dop_time'}.long_name = ncchar('time for dop');
   nc{'dop_time'}.long_name = 'time for dop';
-  nc{'dop_time'}.units = ncchar('day');
-  nc{'dop_time'}.units = 'day';
-  if cycle~=0
-    nc{'dop_time'}.cycle_length = cycle;
-  end
+  write_time_attributes(nc,'dop_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
 %
   nc{'Zdop'}.long_name = ncchar('Depth for DOP');
   nc{'Zdop'}.long_name = 'Depth for DOP';
@@ -143,11 +152,8 @@ if (makeclim)
 %
   nc{'dop_time'}.long_name = ncchar('time for dop');
   nc{'dop_time'}.long_name = 'time for dop';
-  nc{'dop_time'}.units = ncchar('day');
-  nc{'dop_time'}.units = 'day';
-  if cycle~=0
-    nc{'dop_time'}.cycle_length = cycle;
-  end
+  write_time_attributes(nc,'dop_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
 %
   nc{'DOP'}.long_name = ncchar('DOP');
   nc{'DOP'}.long_name = 'DOP';
@@ -163,22 +169,23 @@ if (makeclim)
   nc{'dop_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-if (makeini)
-disp('Add_dop: creating variables and attributes for the Initial file')
-%
-% open the clim file
-%
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'DOP'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-%
-nc{'DOP'}.long_name = ncchar('DOP');
-nc{'DOP'}.long_name = 'DOP';
-nc{'DOP'}.units = ncchar('mMol C m-3');
-nc{'DOP'}.units = 'mMol C m-3';
-%
-endef(nc);
-close(nc)
-end
+% %
+% if (makeini)
+% disp('Add_dop: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
+% %
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'DOP'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% nc{'DOP'}.long_name = ncchar('DOP');
+% nc{'DOP'}.long_name = 'DOP';
+% nc{'DOP'}.units = ncchar('mMol C m-3');
+% nc{'DOP'}.units = 'mMol C m-3';
+% %
+% endef(nc);
+% close(nc)
+% end
 
 return
diff --git a/Preprocessing_tools/Bio/add_fer.m b/Preprocessing_tools/Bio/add_fer.m
index 086a18798aebfbf060134c5429012d6a6e898ade..6ae7633c3771a303711e63a901e006e32b9a146b 100644
--- a/Preprocessing_tools/Bio/add_fer.m
+++ b/Preprocessing_tools/Bio/add_fer.m
@@ -1,5 +1,5 @@
 function add_fer(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,fer]=add_fer(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_fer(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -29,13 +29,25 @@ function add_fer(oafile,climfile,inifile,gridfile,seas_datafile,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +58,40 @@ kmax=max(find(zfer<hmax))-1;
 zfer=zfer(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_fer: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('fer_time') = length(t);
   nc{'fer_time'} = ncdouble('fer_time') ;
   nc('Zfer') = length(zfer);
   nc{'Zfer'} = ncdouble('Zfer') ;
   nc{'FER'} = ncdouble('fer_time','Zfer','eta_rho','xi_rho') ;
-%
+  %
   nc{'fer_time'}.long_name = ncchar('time for iron');
   nc{'fer_time'}.long_name = 'time for iron';
-  nc{'fer_time'}.units = ncchar('day');
-  nc{'fer_time'}.units = 'day';
-  if cycle~=0
-    nc{'fer_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'fer_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+
+  %
   nc{'Zfer'}.long_name = ncchar('Depth for FER');
   nc{'Zfer'}.long_name = 'Depth for FER';
   nc{'Zfer'}.units = ncchar('m');
   nc{'Zfer'}.units = 'm';
-%
+  %
   nc{'FER'}.long_name = ncchar('Iron');
   nc{'FER'}.long_name = 'Iron';
   nc{'FER'}.units = ncchar('uMol Fe m-3');
   nc{'FER'}.units = 'uMol Fe m-3';
   nc{'FER'}.fields = ncchar('FER, scalar, series');
   nc{'FER'}.fields = 'FER, scalar, series';
-%
-%%  endef(nc);
-%
-% record deth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record deth and time and close
+  %
   nc{'fer_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Zfer'}(:)=zfer;
   close(nc)
@@ -91,52 +101,49 @@ end
 %
 if (makeclim)
   disp('Add_fer: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
-%%  redef(nc);
-  nc('fer_time') = length(t);;
+  %%  redef(nc);
+  nc('fer_time') = length(t);
   nc{'fer_time'} = ncdouble('fer_time') ;
   nc{'FER'} = ncdouble('fer_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'fer_time'}.long_name = ncchar('time for iron');
   nc{'fer_time'}.long_name = 'time for iron';
-  nc{'fer_time'}.units = ncchar('day');
-  nc{'fer_time'}.units = 'day';
-  if cycle~=0
-    nc{'fer_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'fer_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'FER'}.long_name = ncchar('Iron');
   nc{'FER'}.long_name = 'Iron';
   nc{'FER'}.units = ncchar('uMol Fe m-3');
   nc{'FER'}.units = 'uMol Fe m-3';
   nc{'FER'}.fields = ncchar('FER, scalar, series');
   nc{'FER'}.fields = 'FER, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'fer_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-if (makeini)
-disp('Add_fer: creating variables and attributes for the Initial file')
-%
-% open the clim file
-%
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'FER'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-%
-nc{'FER'}.long_name = ncchar('FER');
-nc{'FER'}.long_name = 'FER';
-nc{'FER'}.units = ncchar('uMol Fe m-3');
-nc{'FER'}.units = 'uMol Fe m-3';
-%
-endef(nc);
-close(nc)
-end
+% if (makeini)
+% disp('Add_fer: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
+% %
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'FER'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% nc{'FER'}.long_name = ncchar('FER');
+% nc{'FER'}.long_name = 'FER';
+% nc{'FER'}.units = ncchar('uMol Fe m-3');
+% nc{'FER'}.units = 'uMol Fe m-3';
+% %
+% endef(nc);
+% close(nc)
+% end
 return
diff --git a/Preprocessing_tools/Bio/add_no3.m b/Preprocessing_tools/Bio/add_no3.m
index ac708dae042bee5fd8874e34ffcf8324ad56593d..8a528bde733843a47fccf4f5107f897e5c7b3521 100644
--- a/Preprocessing_tools/Bio/add_no3.m
+++ b/Preprocessing_tools/Bio/add_no3.m
@@ -1,5 +1,5 @@
 function add_no3(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,no3]=add_no3(climfile,gridfile,...
@@ -11,12 +11,12 @@ function add_no3(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -24,10 +24,10 @@ function add_no3(oafile,climfile,inifile,gridfile,seas_datafile,...
 %   output:
 %
 %    [longrd,latgrd,no3] : surface field to plot (as an illustration)
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -45,18 +45,30 @@ function add_no3(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2001-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2001-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -70,59 +82,56 @@ zno3=zno3(1:kmax);
 size(zno3);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_no3: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
- % redef(nc);
-  
+  % redef(nc);
+
   %Create Dimensions
   nc('no3_time') = length(t);
   %Create Variable
   nc{'no3_time'} = ncdouble('no3_time') ;
-%
-%%
-%
+  %
+  %%
+  %
   %Create Dimensions
-  nc('Zno3') = length(zno3);  
+  nc('Zno3') = length(zno3);
   %Create Variable
   nc{'Zno3'} = ncdouble('Zno3') ;
-%
-%%
-%    
+  %
+  %%
+  %
   %Create Variable
   nc{'NO3'} = ncdouble('no3_time','Zno3','eta_rho','xi_rho') ;
-%
-%%
-%    
+  %
+  %%
+  %
   %Create Attribute
-  
+
   nc{'no3_time'}.long_name = ncchar('time for nitrate');
   nc{'no3_time'}.long_name = 'time for nitrate';
-  nc{'no3_time'}.units = ncchar('day');
-  nc{'no3_time'}.units = 'day';
-  if cycle~=0
-    nc{'no3_time'}.cycle_length = cycle;
-  end
-%%%
+  write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %%%
   nc{'Zno3'}.long_name = ncchar('Depth for NO3');
   nc{'Zno3'}.long_name = 'Depth for NO3';
   nc{'Zno3'}.units = ncchar('m');
   nc{'Zno3'}.units = 'm';
-%%%
+  %%%
   nc{'NO3'}.long_name = ncchar('Nitrate');
   nc{'NO3'}.long_name = 'Nitrate';
   nc{'NO3'}.units = ncchar('mMol N m-3');
   nc{'NO3'}.units = 'mMol N m-3';
   nc{'NO3'}.fields = ncchar('NO3, scalar, series');
   nc{'NO3'}.fields = 'NO3, scalar, series';
-%%%
-%%  endef(nc);
-%
-%% Write variables
-%% record depth and time and close
-%
+  %%%
+  %%  endef(nc);
+  %
+  %% Write variables
+  %% record depth and time and close
+  %
   nc{'no3_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Zno3'}(:)=zno3;
   close(nc)
@@ -132,56 +141,59 @@ end
 %
 if (makeclim)
   disp('Add_no3: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
- % redef(nc);
+  % redef(nc);
   nc('no3_time') = length(t);;
   nc{'no3_time'} = ncdouble('no3_time') ;
   nc{'NO3'} = ncdouble('no3_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'no3_time'}.long_name = ncchar('time for nitrate');
   nc{'no3_time'}.long_name = 'time for nitrate';
-  nc{'no3_time'}.units = ncchar('day');
-  nc{'no3_time'}.units = 'day';
+  nc{'no3_time'}.units = ncchar(time_unit_att);
+  nc{'no3_time'}.units = time_unit_att;
+  nc{'no3_time'}.calendar = calendar_att;
   if cycle~=0
     nc{'no3_time'}.cycle_length = cycle;
   end
-%
+  write_time_attributes(nc,'tclm_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'NO3'}.long_name = ncchar('Nitrate');
   nc{'NO3'}.long_name = 'Nitrate';
   nc{'NO3'}.units = ncchar('mMol N m-3');
   nc{'NO3'}.units = 'mMol N m-3';
   nc{'NO3'}.fields = ncchar('NO3, scalar, series');
   nc{'NO3'}.fields = 'NO3, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'no3_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-%
-if (makeini)
-% Same thing for the Initial file
-%
-disp('Add_no3: creating variables and attributes for the Initial file')
-%
-% open the clim file  
- 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'NO3'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% if (makeini)
+% % Same thing for the Initial file
+% %
+% disp('Add_no3: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
 
-nc{'NO3'}.long_name = ncchar('Nitrate');
-nc{'NO3'}.long_name = 'Nitrate';
-nc{'NO3'}.units = ncchar('mMol N m-3');
-nc{'NO3'}.units = 'mMol N m-3';
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'NO3'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
 
-endef(nc);
-close(nc)
-end
+% nc{'NO3'}.long_name = ncchar('Nitrate');
+% nc{'NO3'}.long_name = 'Nitrate';
+% nc{'NO3'}.units = ncchar('mMol N m-3');
+% nc{'NO3'}.units = 'mMol N m-3';
+
+% endef(nc);
+% close(nc)
+% end
 
 return
diff --git a/Preprocessing_tools/Bio/add_o2.m b/Preprocessing_tools/Bio/add_o2.m
index 7a2665258244aeab23b18c5d70acdcdacdd98714..febe5c29d71df7c9a1e52c0912d2469ecdf3fae2 100644
--- a/Preprocessing_tools/Bio/add_o2.m
+++ b/Preprocessing_tools/Bio/add_o2.m
@@ -1,5 +1,5 @@
 function add_o2(oafile,climfile,inifile,gridfile,month_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,o2]=add_o2(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_o2(oafile,climfile,inifile,gridfile,month_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    month_datafile : regular longitude - latitude - z monthly data 
+%    month_datafile : regular longitude - latitude - z monthly data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -29,13 +29,25 @@ function add_o2(oafile,climfile,inifile,gridfile,month_datafile,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(month_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +58,40 @@ kmax=max(find(zo2<hmax))-1;
 zo2=zo2(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_o2: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('o2_time') = length(t);
   nc{'o2_time'} = ncdouble('o2_time') ;
   nc('Zo2') = length(zo2);
   nc{'Zo2'} = ncdouble('Zo2') ;
   nc{'O2'} = ncdouble('o2_time','Zo2','eta_rho','xi_rho') ;
-%
+  %
   nc{'o2_time'}.long_name = ncchar('time for oxygen');
   nc{'o2_time'}.long_name = 'time for oxygen';
-  nc{'o2_time'}.units = ncchar('day');
-  nc{'o2_time'}.units = 'day';
-  if cycle~=0
-    nc{'o2_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+
+  %
   nc{'Zo2'}.long_name = ncchar('Depth for O2');
   nc{'Zo2'}.long_name = 'Depth for O2';
   nc{'Zo2'}.units = ncchar('m');
   nc{'Zo2'}.units = 'm';
-%
+  %
   nc{'O2'}.long_name = ncchar('Oxygen');
   nc{'O2'}.long_name = 'Oxygen';
   nc{'O2'}.units = ncchar('mMol O m-3');
   nc{'O2'}.units = 'mMol O m-3';
   nc{'O2'}.fields = ncchar('O2, scalar, series');
   nc{'O2'}.fields = 'O2, scalar, series';
-%
-%%  endef(nc);
-%
-% record depth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record depth and time and close
+  %
   nc{'o2_time'}(:)=t*30;  % ojo aqui quite *30 % if time in month in the dataset !!!
   nc{'Zo2'}(:)=squeeze(zo2);
   close(nc)
@@ -91,55 +101,53 @@ end
 %
 if (makeclim)
   disp('Add_o2: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
- %% redef(nc);
+  %% redef(nc);
   nc('o2_time') = length(t);
   nc{'o2_time'} = ncdouble('o2_time') ;
   nc{'O2'} = ncdouble('o2_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'o2_time'}.long_name = ncchar('time for oxygen');
   nc{'o2_time'}.long_name = 'time for oxygen';
-  nc{'o2_time'}.units = ncchar('day');
-  nc{'o2_time'}.units = 'day';
-  if cycle~=0
-    nc{'o2_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
+  %
   nc{'O2'}.long_name = ncchar('Oxygen');
   nc{'O2'}.long_name = 'Oxygen';
   nc{'O2'}.units = ncchar('mMol O m-3');
   nc{'O2'}.units = 'mMol O m-3';
   nc{'O2'}.fields = ncchar('O2, scalar, series');
   nc{'O2'}.fields = 'O2, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'o2_time'}(:,:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-if (makeini)
-% Same thing for the Initial file
-%
-disp('Add_o2: creating variables and attributes for the Initial file')
-%
-% open the clim file
+% %
+% if (makeini)
+% % Same thing for the Initial file
+% %
+% disp('Add_o2: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'O2'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'O2'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
 
-nc{'O2'}.long_name = ncchar('Oxygen');
-nc{'O2'}.long_name = 'Oxygen';
-nc{'O2'}.units = ncchar('mMol O m-3');
-nc{'O2'}.units = 'mMol O m-3';
+% nc{'O2'}.long_name = ncchar('Oxygen');
+% nc{'O2'}.long_name = 'Oxygen';
+% nc{'O2'}.units = ncchar('mMol O m-3');
+% nc{'O2'}.units = 'mMol O m-3';
 
-endef(nc);
-close(nc)
-end
+% endef(nc);
+% close(nc)
+% end
 
 return
diff --git a/Preprocessing_tools/Bio/add_po4.m b/Preprocessing_tools/Bio/add_po4.m
index b495f53fcd9a275660b05c93577d37a29ec2d30c..16f4c6ec6f1f7e65ef23ad46d8cbc1481527b5ab 100644
--- a/Preprocessing_tools/Bio/add_po4.m
+++ b/Preprocessing_tools/Bio/add_po4.m
@@ -1,5 +1,5 @@
 function add_po4(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,po4]=add_po4(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_po4(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -28,6 +28,17 @@ function add_po4(oafile,climfile,inifile,gridfile,seas_datafile,...
 %    [longrd,latgrd,po4] : surface field to plot (as an illustration)
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 %
 % Read in the grid
 %
@@ -35,7 +46,7 @@ nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +57,39 @@ kmax=max(find(zpo4<hmax))-1;
 zpo4=zpo4(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_po4: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('po4_time') = length(t);
   nc{'po4_time'} = ncdouble('po4_time') ;
   nc('Zpo4') = length(zpo4);
   nc{'Zpo4'} = ncdouble('Zpo4') ;
   nc{'PO4'} = ncdouble('po4_time','Zpo4','eta_rho','xi_rho') ;
-%
+  %
   nc{'po4_time'}.long_name = ncchar('time for phosphate');
   nc{'po4_time'}.long_name = 'time for phosphate';
-  nc{'po4_time'}.units = ncchar('day');
-  nc{'po4_time'}.units = 'day';
-  if cycle~=0
-    nc{'po4_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'po4_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
+  %
   nc{'Zpo4'}.long_name = ncchar('Depth for PO4');
   nc{'Zpo4'}.long_name = 'Depth for PO4';
   nc{'Zpo4'}.units = ncchar('m');
   nc{'Zpo4'}.units = 'm';
-%
+  %
   nc{'PO4'}.long_name = ncchar('Phosphate');
   nc{'PO4'}.long_name = 'Phosphate';
   nc{'PO4'}.units = ncchar('mMol P m-3');
   nc{'PO4'}.units = 'mMol P m-3';
   nc{'PO4'}.fields = ncchar('PO4, scalar, series');
   nc{'PO4'}.fields = 'PO4, scalar, series';
-%
-%%  endef(nc);
-%
-% record deth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record deth and time and close
+  %
   nc{'po4_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Zpo4'}(:)=zpo4;
   close(nc)
@@ -91,54 +99,51 @@ end
 %
 if (makeclim)
   disp('Add_po4: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('po4_time') = length(t);;
   nc{'po4_time'} = ncdouble('po4_time') ;
   nc{'PO4'} = ncdouble('po4_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'po4_time'}.long_name = ncchar('time for phosphate');
   nc{'po4_time'}.long_name = 'time for phosphate';
-  nc{'po4_time'}.units = ncchar('day');
-  nc{'po4_time'}.units = 'day';
-  if cycle~=0
-    nc{'po4_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'po4_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'PO4'}.long_name = ncchar('Phosphate');
   nc{'PO4'}.long_name = 'Phosphate';
   nc{'PO4'}.units = ncchar('mMol P m-3');
   nc{'PO4'}.units = 'mMol P m-3';
   nc{'PO4'}.fields = ncchar('PO4, scalar, series');
   nc{'PO4'}.fields = 'PO4, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'po4_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-if (makeini)
-% Same thing for the Initial file
-%
-disp('Add_po4: creating variables and attributes for the Initial file')
-%
-% open the clim file
+% if (makeini)
+% % Same thing for the Initial file
+% %
+% disp('Add_po4: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'PO4'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'PO4'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
 
-nc{'PO4'}.long_name = ncchar('Phosphate');
-nc{'PO4'}.long_name = 'Phosphate';
-nc{'PO4'}.units = ncchar('mMol P m-3');
-nc{'PO4'}.units = 'mMol P m-3';
+% nc{'PO4'}.long_name = ncchar('Phosphate');
+% nc{'PO4'}.long_name = 'Phosphate';
+% nc{'PO4'}.units = ncchar('mMol P m-3');
+% nc{'PO4'}.units = 'mMol P m-3';
 
-endef(nc);
-close(nc)
-end
+% endef(nc);
+% close(nc)
+% end
 return
diff --git a/Preprocessing_tools/Bio/add_sio3.m b/Preprocessing_tools/Bio/add_sio3.m
index b7ad50531ac2479e3017c256398903aeb1be4dba..9708ce01dc448677f659b38fbb15cd4ca9a8fd84 100644
--- a/Preprocessing_tools/Bio/add_sio3.m
+++ b/Preprocessing_tools/Bio/add_sio3.m
@@ -1,5 +1,5 @@
 function add_sio3(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,sio3]=add_sio3(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_sio3(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -29,13 +29,25 @@ function add_sio3(oafile,climfile,inifile,gridfile,seas_datafile,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
 % Read in the grid
 %
 nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +58,39 @@ kmax=max(find(zsi<hmax))-1;
 zsi=zsi(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_sio3: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('si_time') = length(t);
   nc{'si_time'} = ncdouble('si_time') ;
   nc('Zsi') = length(zsi);
   nc{'Zsi'} = ncdouble('Zsi') ;
   nc{'Si'} = ncdouble('si_time','Zsi','eta_rho','xi_rho') ;
-%
+  %
   nc{'si_time'}.long_name = ncchar('time for silicate');
   nc{'si_time'}.long_name = 'time for silicate';
-  nc{'si_time'}.units = ncchar('day');
-  nc{'si_time'}.units = 'day';
-  if cycle~=0
-    nc{'si_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'si_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'Zsi'}.long_name = ncchar('Depth for Si');
   nc{'Zsi'}.long_name = 'Depth for Si';
   nc{'Zsi'}.units = ncchar('m');
   nc{'Zsi'}.units = 'm';
-%
+  %
   nc{'Si'}.long_name = ncchar('Silicate');
   nc{'Si'}.long_name = 'Silicate';
   nc{'Si'}.units = ncchar('mMol Si m-3');
   nc{'Si'}.units = 'mMol Si m-3';
   nc{'Si'}.fields = ncchar('Si, scalar, series');
   nc{'Si'}.fields = 'Si, scalar, series';
-%
-%%  endef(nc);
-%
-% record deth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record deth and time and close
+  %
   nc{'si_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Zsi'}(:)=zsi;
   close(nc)
@@ -91,54 +100,51 @@ end
 %
 if (makeclim)
   disp('Add_sio3: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('si_time') = length(t);;
   nc{'si_time'} = ncdouble('si_time') ;
   nc{'Si'} = ncdouble('si_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'si_time'}.long_name = ncchar('time for silicate');
   nc{'si_time'}.long_name = 'time for silicate';
-  nc{'si_time'}.units = ncchar('day');
-  nc{'si_time'}.units = 'day';
-  if cycle~=0
-    nc{'si_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'si_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+  %
   nc{'Si'}.long_name = ncchar('Silicate');
   nc{'Si'}.long_name = 'Silicate';
   nc{'Si'}.units = ncchar('mMol Si m-3');
   nc{'Si'}.units = 'mMol Si m-3';
   nc{'Si'}.fields = ncchar('Si, scalar, series');
   nc{'Si'}.fields = 'Si, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'si_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-if (makeini)
-% Same thing for the Initial file
-%
-disp('Add_si: creating variables and attributes for the Initial file')
-%
-% open the clim file
+% if (makeini)
+% % Same thing for the Initial file
+% %
+% disp('Add_si: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'Si'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'Si'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
 
-nc{'Si'}.long_name = ncchar('Silicate');
-nc{'Si'}.long_name = 'Silicate';
-nc{'Si'}.units = ncchar('mMol Si m-3');
-nc{'Si'}.units = 'mMol Si m-3';
+% nc{'Si'}.long_name = ncchar('Silicate');
+% nc{'Si'}.long_name = 'Silicate';
+% nc{'Si'}.units = ncchar('mMol Si m-3');
+% nc{'Si'}.units = 'mMol Si m-3';
 
-endef(nc);
-close(nc)
-end
+% endef(nc);
+% close(nc)
+% end
 return
diff --git a/Preprocessing_tools/Bio/add_talk.m b/Preprocessing_tools/Bio/add_talk.m
index 41f56e0c8fdce67244599f039d4ae836b4f0493c..5a4757c4a81dbd93ac55a39863d050327d1e2563 100644
--- a/Preprocessing_tools/Bio/add_talk.m
+++ b/Preprocessing_tools/Bio/add_talk.m
@@ -1,5 +1,5 @@
 function add_talk(oafile,climfile,inifile,gridfile,seas_datafile,...
-                 ann_datafile,cycle,makeoa,makeclim,makeini);
+  ann_datafile,cycle,makeoa,makeclim,makeini,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function [longrd,latgrd,talk]=add_talk(climfile,gridfile,...
@@ -13,12 +13,12 @@ function add_talk(oafile,climfile,inifile,gridfile,seas_datafile,...
 %  lower levels
 %
 %  input:
-%    
+%
 %    climfile      : croco climatology file to process (netcdf)
 %    gridfile      : croco grid file (netcdf)
-%    seas_datafile : regular longitude - latitude - z seasonal data 
+%    seas_datafile : regular longitude - latitude - z seasonal data
 %                    file used for the upper levels  (netcdf)
-%    ann_datafile  : regular longitude - latitude - z annual data 
+%    ann_datafile  : regular longitude - latitude - z annual data
 %                    file used for the lower levels  (netcdf)
 %    cycle         : time length (days) of climatology cycle (ex:360 for
 %                    annual cycle) - 0 if no cycle.
@@ -28,6 +28,16 @@ function add_talk(oafile,climfile,inifile,gridfile,seas_datafile,...
 %    [longrd,latgrd,talk] : surface field to plot (as an illustration)
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
 %
 % Read in the grid
 %
@@ -35,7 +45,7 @@ nc=netcdf(gridfile,'r');
 hmax=max(max(nc{'h'}(:)));
 close(nc);
 %
-% read in the datafiles 
+% read in the datafiles
 %
 nc=netcdf(seas_datafile,'r');
 t=nc{'T'}(:);
@@ -46,42 +56,40 @@ kmax=max(find(ztalk<hmax))-1;
 ztalk=ztalk(1:kmax);
 close(nc)
 %
-% open the OA file  
-% 
+% open the OA file
+%
 if (makeoa)
   disp('Add_talk: creating variables and attributes for the OA file')
   nc=netcdf(oafile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('talk_time') = length(t);
   nc{'talk_time'} = ncdouble('talk_time') ;
   nc('Ztalk') = length(ztalk);
   nc{'Ztalk'} = ncdouble('Ztalk') ;
   nc{'TALK'} = ncdouble('talk_time','Ztalk','eta_rho','xi_rho') ;
-%
+  %
   nc{'talk_time'}.long_name = ncchar('time for TALK');
   nc{'talk_time'}.long_name = 'time for TALK';
-  nc{'talk_time'}.units = ncchar('day');
-  nc{'talk_time'}.units = 'day';
-  if cycle~=0
-    nc{'talk_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'talk_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+ 
+  %
   nc{'Ztalk'}.long_name = ncchar('Depth for TALK');
   nc{'Ztalk'}.long_name = 'Depth for TALK';
   nc{'Ztalk'}.units = ncchar('m');
   nc{'Ztalk'}.units = 'm';
-%
+  %
   nc{'TALK'}.long_name = ncchar('TALK');
   nc{'TALK'}.long_name = 'TALK';
   nc{'TALK'}.units = ncchar('mMol C m-3');
   nc{'TALK'}.units = 'mMol C m-3';
   nc{'TALK'}.fields = ncchar('TALK, scalar, series');
   nc{'TALK'}.fields = 'TALK, scalar, series';
-%
-%%  endef(nc);
-%
-% record deth and time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record deth and time and close
+  %
   nc{'talk_time'}(:)=t*30; % if time in month in the dataset !!!
   nc{'Ztalk'}(:)=ztalk;
   close(nc)
@@ -91,56 +99,53 @@ end
 %
 if (makeclim)
   disp('Add_talk: creating variables and attributes for the Climatology file')
-%
-% open the clim file  
-% 
+  %
+  % open the clim file
+  %
   nc=netcdf(climfile,'write');
-%%  redef(nc);
+  %%  redef(nc);
   nc('talk_time') = length(t);;
   nc{'talk_time'} = ncdouble('talk_time') ;
   nc{'TALK'} = ncdouble('talk_time','s_rho','eta_rho','xi_rho') ;
-%
+  %
   nc{'talk_time'}.long_name = ncchar('time for TALK');
   nc{'talk_time'}.long_name = 'time for TALK';
-  nc{'talk_time'}.units = ncchar('day');
-  nc{'talk_time'}.units = 'day';
-  if cycle~=0
-    nc{'talk_time'}.cycle_length = cycle;
-  end
-%
+  write_time_attributes(nc,'talk_time',cycle,time_unit_att,time_second_unit_att,...
+    calendar_att,insecond,add_cycle);
+  %
   nc{'TALK'}.long_name = ncchar('TALK');
   nc{'TALK'}.long_name = 'TALK';
   nc{'TALK'}.units = ncchar('mMol C m-3');
   nc{'TALK'}.units = 'mMol C m-3';
   nc{'TALK'}.fields = ncchar('TALK, scalar, series');
   nc{'TALK'}.fields = 'TALK, scalar, series';
-%
-%%  endef(nc);
-%
-% record the time and close
-%
+  %
+  %%  endef(nc);
+  %
+  % record the time and close
+  %
   nc{'talk_time'}(:)=t*30; % if time in month in the dataset !!!
   close(nc)
 end
-%
-% Same thing for the Initial file
-%
-if (makeini)
-disp('Add_talk: creating variables and attributes for the Initial file')
-%
-% open the clim file  
-% 
-nc=netcdf(inifile,'write');
-redef(nc);
-nc{'TALK'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-%
-nc{'TALK'}.long_name = ncchar('TALK');
-nc{'TALK'}.long_name = 'TALK';
-nc{'TALK'}.units = ncchar('mMol C m-3');
-nc{'TALK'}.units = 'mMol C m-3';
-%
-endef(nc);
-close(nc)
-end
+% %
+% % Same thing for the Initial file
+% %
+% if (makeini)
+% disp('Add_talk: creating variables and attributes for the Initial file')
+% %
+% % open the clim file
+% %
+% nc=netcdf(inifile,'write');
+% redef(nc);
+% nc{'TALK'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+% %
+% nc{'TALK'}.long_name = ncchar('TALK');
+% nc{'TALK'}.long_name = 'TALK';
+% nc{'TALK'}.units = ncchar('mMol C m-3');
+% nc{'TALK'}.units = 'mMol C m-3';
+% %
+% endef(nc);
+% close(nc)
+% end
 
 return
diff --git a/Preprocessing_tools/Bio/make_biol.m b/Preprocessing_tools/Bio/make_biol.m
index 32968ef015261ab73ae2a49af45f1e2040f711ed..a226e7dd9bbfd5ec1a99a74f2ea16ccffd2a2afc 100644
--- a/Preprocessing_tools/Bio/make_biol.m
+++ b/Preprocessing_tools/Bio/make_biol.m
@@ -4,9 +4,9 @@ close all
 %
 %  Add biological parameters to CROCO input files
 %
-%  Further Information:  
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -24,8 +24,8 @@ close all
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2003-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2003-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %  Contributions of P. Marchesiello (IRD)
 %
@@ -50,54 +50,60 @@ crocotools_param
 % Climatological file
 %----------------------------------------------------------------------
 if (makeclim)
-  disp('===========================================================')
-  disp('Climatology for the biogeochemical model')
-  if (makenpzd)
-     disp('========================')
-     disp('Climatology for NPZD variables')
-     %     disp('already done in make_ini_npzd')
-     make_clim_npzd
-  end
-  if (makepisces)
-     disp('========================')
-     disp('Climatology for PISCES variables')
-     make_clim_pisces
-     disp('------------------------')
-     disp('Iron deposition file')
-     make_dust
-     disp('------------------------')
-     disp('Nitrogen deposition')
-     make_ndepo
-  end
-  if (makebioebus)
-     disp('========================')
-     disp('Climatology for BioEBUS variables')
-     %disp('already done in make_ini_bioebus')
-     make_clim_bioebus
-  end
+   disp('===========================================================')
+   disp('Climatology for the biogeochemical model')
+   if (makenpzd)
+      disp('========================')
+      disp('Climatology for NPZD variables')
+      make_clim_npzd
+   end
+   if (makebioebus)
+      disp('========================')
+      disp('Climatology for BioEBUS variables')
+      make_clim_bioebus
+   end
+   if (makepisces)
+      disp('========================')
+      disp('Climatology for PISCES variables')
+      make_clim_pisces
+      disp('------------------------')
+      disp('Iron deposition file')
+      make_dust
+      disp('------------------------')
+      disp('Nitrogen deposition')
+      make_ndepo
+   end
+
 end
 
 %----------------------------------------------------------------------
 % Bry file
 %----------------------------------------------------------------------
 if (makebry)
-  disp('===========================================================')
-  disp('Bry for the biogeochemical model')
-  if (makenpzd)
-     disp('========================')
-     disp('Bry for NPZD variables')
-     make_bry_npzd
-  end
-  if (makepisces)
-     disp('========================')
-     disp('Bry for PISCES variables')
-     make_bry_pisces
-  end
-  if (makebioebus)
-     disp('========================')
-     disp('Bry for BioEBUS variables')
-     make_bry_bioebus
-  end
+   disp('===========================================================')
+   disp('Bry for the biogeochemical model')
+   if (makenpzd)
+      disp('========================')
+      disp('Bry for NPZD variables')
+      make_bry_npzd
+   end
+   if (makebioebus)
+      disp('========================')
+      disp('Bry for BioEBUS variables')
+      make_bry_bioebus
+   end
+   if (makepisces)
+      disp('========================')
+      disp('Bry for PISCES variables')
+      make_bry_pisces
+      disp('------------------------')
+      disp('Iron deposition file')
+      make_dust
+      disp('------------------------')
+      disp('Nitrogen deposition')
+      make_ndepo
+   end
+
 end
 
 %----------------------------------------------------------------------
@@ -105,29 +111,34 @@ end
 %----------------------------------------------------------------------
 
 if (makeini)
-  disp('===========================================================')
-  disp('Initial variables for the biogeochemical model')
-  if (makenpzd)
-     disp('========================')
-     disp('Initial NPZD variables')
-     make_ini_npzd
-  end
-  if (makebioebus)
-     disp('========================')
-     disp('Initial BioEBUS variables')
-     make_ini_bioebus
-  end
+   disp('===========================================================')
+   disp('Initial variables for the biogeochemical model')
+   if (makenpzd)
+      disp('========================')
+      disp('Initial NPZD variables')
+      make_ini_npzd
+   end
+   if (makebioebus)
+      disp('========================')
+      disp('Initial BioEBUS variables')
+      make_ini_bioebus
+   end
+   if (makepisces)
+      disp('========================')
+      disp('Initial PISCES variables')
+      make_ini_pisces
+   end
 end
 
 %----------------------------------------------------------------------
 % N2O in BioEBUS
 %----------------------------------------------------------------------
 
-  if (makebioebus)
-     disp('========================')
-     disp('Input values for N2O in BioEBUS')
-     make_n2o_bioebus
-  end
+if (makebioebus)
+   disp('========================')
+   disp('Input values for N2O in BioEBUS')
+   make_n2o_bioebus
+end
 
 
 
diff --git a/Preprocessing_tools/Bio/make_bry_pisces.m b/Preprocessing_tools/Bio/make_bry_pisces.m
index bb9d5406f8dc38148086fb67a29577bb7448fe8d..406a8be935c0c5a98f7819933f3f45d4108b4f52 100644
--- a/Preprocessing_tools/Bio/make_bry_pisces.m
+++ b/Preprocessing_tools/Bio/make_bry_pisces.m
@@ -5,7 +5,7 @@
 %  Extrapole and interpole temperature and salinity from a
 %  climatology to get boundary conditions for
 %  CROCO (boundary netcdf file) .
-%  Get the velocities and sea surface elevation via a 
+%  Get the velocities and sea surface elevation via a
 %  geostrophic computation.
 %
 %  Data input format (netcdf):
@@ -18,10 +18,10 @@
 %  Data source : IRI/LDEO climate Data Library (World Ocean Atlas 1998)
 %    http://ingrid.ldgo.columbia.edu/
 %    http://iridl.ldeo.columbia.edu/SOURCES/.NOAA/.NODC/.WOA98/
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -39,8 +39,8 @@
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2005-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2005-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %  Updated    1-Sep-2006 by Pierrick Penven
 %  Pierrick Penven, IRD, 2005.                                    %
@@ -64,8 +64,8 @@ Roa;
 %
 % Set times and cycles: monthly climatology for all data
 %
-time=woa_time;             % time 
-cycle=woa_cycle;           % cycle 
+time=woa_time;             % time
+cycle=woa_cycle;           % cycle
 %
 %  Data climatologies file names:
 %
@@ -89,9 +89,9 @@ fer_ann_data   = [woapisces_dir,'fer_ann.cdf'];
 dust_seas_data = [woapisces_dir,'dust_seas.cdf'];
 dust_ann_data  = [woapisces_dir,'dust_ann.cdf'];
 if strcmp(climato_dir,cars2009_dir);
-    err_msg=sprintf(['Error : you need to use woadir when creating the croco_oa.nc (Z) \n'...
-                     'file to be compatible with PISCES'])
-    error(err_msg)
+  err_msg=sprintf(['Error : you need to use woadir when creating the croco_oa.nc (Z) \n'...
+    'file to be compatible with PISCES'])
+  error(err_msg)
 end
 %
 %
@@ -109,7 +109,7 @@ disp([' Title: ',CROCO_title])
 %
 disp(' ')
 disp(' Read in the grid...')
-      nc=netcdf(grdname,'r');
+nc=netcdf(grdname,'r');
 lon=nc{'lon_rho'}(:);
 lat=nc{'lat_rho'}(:);
 Lp=length(nc('xi_rho'));
@@ -134,10 +134,10 @@ end
 if (makeZbry)
   disp(' ')
   disp(' Redefine the boundary Z-file...')
-%
-% get Z
-%
-    nc=netcdf(no3_ann_data,'r');
+  %
+  % get Z
+  %
+  nc=netcdf(no3_ann_data,'r');
   Z=nc{'Z'}(:);
   kmax=max(find(Z<hmax))-1;
   Z=Z(1:kmax);
@@ -145,82 +145,82 @@ if (makeZbry)
   add_bry_pisces_Z(Zbryname,obc,Z,time,cycle,makequota,'write');
   disp(' ')
   disp(' Horizontal extrapolations')
-%
-% Loop on the lateral boundaries 
-%
+  %
+  % Loop on the lateral boundaries
+  %
   for obcndx=1:4
     if obc(obcndx)==1
       if obcndx==1
         disp(' Processing southern boundary...')
-	suffix='_south';
+        suffix='_south';
       elseif obcndx==2
         disp(' Processing eastern boundary...')
-	suffix='_east';
+        suffix='_east';
       elseif obcndx==3
         disp(' Processing northern boundary...')
-	suffix='_north';
+        suffix='_north';
       elseif obcndx==4
         disp(' Processing western boundary...')
-	suffix='_west';
+        suffix='_west';
       end
       disp('  Nitrate...')
       bry_interp_pisces(Zbryname,lon,lat,no3_seas_data,no3_ann_data,...
-               'nitrate',['NO3',suffix],obcndx,Roa);        
+        'nitrate',['NO3',suffix],obcndx,Roa);
       disp('  Phosphate...')
       bry_interp_pisces(Zbryname,lon,lat,po4_seas_data,po4_ann_data,...
-               'phosphate',['PO4',suffix],obcndx,Roa);        
+        'phosphate',['PO4',suffix],obcndx,Roa);
       disp('  Silicate...')
       bry_interp_pisces(Zbryname,lon,lat,sio3_seas_data,sio3_ann_data,...
-               'silicate',['Si',suffix],obcndx,Roa);        
+        'silicate',['Si',suffix],obcndx,Roa);
       disp('  Oxygen...')
       bry_interp_pisces(Zbryname,lon,lat,o2_seas_data,o2_ann_data,...
-               'oxygen',['O2',suffix],obcndx,Roa);        
+        'oxygen',['O2',suffix],obcndx,Roa);
       disp('  Dissolved Inorganic Carbon...')
       bry_interp_pisces(Zbryname,lon,lat,dic_seas_data,dic_ann_data,...
-               'dic',['DIC',suffix],obcndx,Roa);        
+        'dic',['DIC',suffix],obcndx,Roa);
       disp('  Total Alkalinity...')
       bry_interp_pisces(Zbryname,lon,lat,talk_seas_data,talk_ann_data,...
-               'talk',['TALK',suffix],obcndx,Roa);        
+        'talk',['TALK',suffix],obcndx,Roa);
       disp('  Dissolved Organic Carbon...')
       bry_interp_pisces(Zbryname,lon,lat,doc_seas_data,doc_ann_data,...
-               'doc',['DOC',suffix],obcndx,Roa);        
-       if makequota
-         disp('  Dissolved Organic Nitrogen...')
-         bry_interp_pisces(Zbryname,lon,lat,doc_seas_data,doc_ann_data,...
-               'doc',['DON',suffix],obcndx,Roa);
-         disp('  Dissolved Organic Phosphorus...')
-         bry_interp_pisces(Zbryname,lon,lat,doc_seas_data,doc_ann_data,...
-               'doc',['DOP',suffix],obcndx,Roa);
+        'doc',['DOC',suffix],obcndx,Roa);
+      if makequota
+        disp('  Dissolved Organic Nitrogen...')
+        bry_interp_pisces(Zbryname,lon,lat,doc_seas_data,doc_ann_data,...
+          'doc',['DON',suffix],obcndx,Roa);
+        disp('  Dissolved Organic Phosphorus...')
+        bry_interp_pisces(Zbryname,lon,lat,doc_seas_data,doc_ann_data,...
+          'doc',['DOP',suffix],obcndx,Roa);
       end
       disp('  Iron...')
       bry_interp_pisces(Zbryname,lon,lat,fer_seas_data,fer_ann_data,...
-               'fer',['FER',suffix],obcndx,Roa);        
+        'fer',['FER',suffix],obcndx,Roa);
     end
   end
 end
 %
-% Vertical interpolations 
+% Vertical interpolations
 %
 if (makebry)
   disp(' ')
   disp(' Vertical interpolations')
-%
-% Loop on the lateral boundaries 
-%
+  %
+  % Loop on the lateral boundaries
+  %
   for obcndx=1:4
     if obc(obcndx)==1
       if obcndx==1
         disp(' Processing southern boundary...')
-	suffix='_south';
+        suffix='_south';
       elseif obcndx==2
         disp(' Processing eastern boundary...')
-	suffix='_east';
+        suffix='_east';
       elseif obcndx==3
         disp(' Processing northern boundary...')
-	suffix='_north';
+        suffix='_north';
       elseif obcndx==4
         disp(' Processing western boundary...')
-	suffix='_west';
+        suffix='_west';
       end
       disp(' ')
       disp('  Nitrate...')
@@ -244,12 +244,12 @@ if (makebry)
       disp('  Dissolved Organic Carbon...')
       vinterp_bry(bryname,grdname,Zbryname,['DOC',suffix],obcndx);
       if makequota
-         disp(' ')
-         disp('  Dissolved Organic Nitrogen...')
-         vinterp_bry(bryname,grdname,Zbryname,['DON',suffix],obcndx);
-         disp(' ')
-         disp('  Dissolved Organic Phosphorus...')
-         vinterp_bry(bryname,grdname,Zbryname,['DOP',suffix],obcndx);
+        disp(' ')
+        disp('  Dissolved Organic Nitrogen...')
+        vinterp_bry(bryname,grdname,Zbryname,['DON',suffix],obcndx);
+        disp(' ')
+        disp('  Dissolved Organic Phosphorus...')
+        vinterp_bry(bryname,grdname,Zbryname,['DOP',suffix],obcndx);
       end
       disp(' ')
       disp('  Iron...')
@@ -261,30 +261,30 @@ end
 % Make a few plots
 %
 if makeplot==1
-disp(' ')
-disp(' Make a few plots...')
-test_bry(bryname,grdname,'NO3',1,obc)
-figure
-test_bry(bryname,grdname,'PO4',1,obc)
-figure
-test_bry(bryname,grdname,'Si',1,obc)
-figure
-test_bry(bryname,grdname,'O2',1,obc)
-figure
-test_bry(bryname,grdname,'DIC',6,obc)
-figure
-test_bry(bryname,grdname,'TALK',6,obc)
-figure
-test_bry(bryname,grdname,'DOC',6,obc)
-figure
-test_bry(bryname,grdname,'FER',6,obc)
-figure
-   if makequota
-   test_bry(bryname,grdname,'DON',6,obc)
-   figure
-   test_bry(bryname,grdname,'DOP',6,obc)
-   figure
-   end
+  disp(' ')
+  disp(' Make a few plots...')
+  test_bry(bryname,grdname,'NO3',1,obc)
+  figure
+  test_bry(bryname,grdname,'PO4',1,obc)
+  figure
+  test_bry(bryname,grdname,'Si',1,obc)
+  figure
+  test_bry(bryname,grdname,'O2',1,obc)
+  figure
+  test_bry(bryname,grdname,'DIC',6,obc)
+  figure
+  test_bry(bryname,grdname,'TALK',6,obc)
+  figure
+  test_bry(bryname,grdname,'DOC',6,obc)
+  figure
+  test_bry(bryname,grdname,'FER',6,obc)
+  figure
+  if makequota
+    test_bry(bryname,grdname,'DON',6,obc)
+    figure
+    test_bry(bryname,grdname,'DOP',6,obc)
+    figure
+  end
 end
 %
 % End
diff --git a/Preprocessing_tools/Bio/make_clim_pisces.m b/Preprocessing_tools/Bio/make_clim_pisces.m
index 51342d1a064762eb52ee8ef1805954fd4014255b..0198dcb30c748c74be4c1bbbacea59649178e8a9 100644
--- a/Preprocessing_tools/Bio/make_clim_pisces.m
+++ b/Preprocessing_tools/Bio/make_clim_pisces.m
@@ -218,95 +218,95 @@ end
   vinterp_clm(clmname,grdname,oaname,'FER','fer_time','Zfer',0,'r');
 end
 
-%----------------------------------------------------------------------------
-% Initial file
-%----------------------------------------------------------------------------
-if (makeini)
-%
-%  NO3
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' NO3...')
-  vinterp_clm(ininame,grdname,oaname,'NO3','no3_time','Zno3',tini,'r',1);
-%
-% DIC
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' DIC...')
-  vinterp_clm(ininame,grdname,oaname,'DIC','dic_time','Zdic',tini,'r',1);
-%
-%  PO4
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' PO4...')
-  vinterp_clm(ininame,grdname,oaname,'PO4','po4_time','Zpo4',tini,'r',1);
- %
- %  Si
- %
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' Si...')
-  vinterp_clm(ininame,grdname,oaname,'Si','si_time','Zsi',tini,'r',1);
-%
-%  O2
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' O2...')
-  vinterp_clm(ininame,grdname,oaname,'O2','o2_time','Zo2',tini,'r',1);
-%
-% TALK
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' TALK...')
-  vinterp_clm(ininame,grdname,oaname,'TALK','talk_time','Ztalk',tini,'r',1);
-%
-% DOC
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' DOC...')
-  vinterp_clm(ininame,grdname,oaname,'DOC','doc_time','Zdoc',tini,'r',1);
-
-if makequota
-%
-% DON
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' DON...')
-  vinterp_clm(ininame,grdname,oaname,'DON','don_time','Zdon',tini,'r',1);
-%
-% DOP
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' DOP...')
-  vinterp_clm(ininame,grdname,oaname,'DOP','dop_time','Zdop',tini,'r',1);
-end
-
-%
-% FER
-%
-  disp(' ')
-  disp(' Vertical interpolations')
-  disp(' ')
-  disp(' FER...')
-  vinterp_clm(ininame,grdname,oaname,'FER','fer_time','Zfer',tini,'r',1);
-end
+% %----------------------------------------------------------------------------
+% % Initial file
+% %----------------------------------------------------------------------------
+% if (makeini)
+% %
+% %  NO3
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' NO3...')
+%   vinterp_clm(ininame,grdname,oaname,'NO3','no3_time','Zno3',tini,'r',1);
+% %
+% % DIC
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' DIC...')
+%   vinterp_clm(ininame,grdname,oaname,'DIC','dic_time','Zdic',tini,'r',1);
+% %
+% %  PO4
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' PO4...')
+%   vinterp_clm(ininame,grdname,oaname,'PO4','po4_time','Zpo4',tini,'r',1);
+%  %
+%  %  Si
+%  %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' Si...')
+%   vinterp_clm(ininame,grdname,oaname,'Si','si_time','Zsi',tini,'r',1);
+% %
+% %  O2
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' O2...')
+%   vinterp_clm(ininame,grdname,oaname,'O2','o2_time','Zo2',tini,'r',1);
+% %
+% % TALK
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' TALK...')
+%   vinterp_clm(ininame,grdname,oaname,'TALK','talk_time','Ztalk',tini,'r',1);
+% %
+% % DOC
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' DOC...')
+%   vinterp_clm(ininame,grdname,oaname,'DOC','doc_time','Zdoc',tini,'r',1);
+
+% if makequota
+% %
+% % DON
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' DON...')
+%   vinterp_clm(ininame,grdname,oaname,'DON','don_time','Zdon',tini,'r',1);
+% %
+% % DOP
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' DOP...')
+%   vinterp_clm(ininame,grdname,oaname,'DOP','dop_time','Zdop',tini,'r',1);
+% end
+
+% %
+% % FER
+% %
+%   disp(' ')
+%   disp(' Vertical interpolations')
+%   disp(' ')
+%   disp(' FER...')
+%   vinterp_clm(ininame,grdname,oaname,'FER','fer_time','Zfer',tini,'r',1);
+% end
 
 if (makeplot)
 disp(' ')
diff --git a/Preprocessing_tools/Bio/make_dust.m b/Preprocessing_tools/Bio/make_dust.m
index bfcf43b89ad129a1bd47c5d64d4dfcda4561777b..6ba5f98cf20113b745406581ea25d0c2017d4838 100644
--- a/Preprocessing_tools/Bio/make_dust.m
+++ b/Preprocessing_tools/Bio/make_dust.m
@@ -26,6 +26,18 @@
 clear all
 close all
 %%%%%%%%%%%%%%%%%%%%% USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 disp(' ')
 disp('Creating biology forcing file')
 %
@@ -86,13 +98,9 @@ nc{'dustpo4'}   = ncdouble('dust_time','eta_rho','xi_rho') ;
 nc{'dustsi'}    = ncdouble('dust_time','eta_rho','xi_rho') ;
 nc{'solubility2'}    = ncdouble('dust_time','eta_rho','xi_rho') ;
 %
-nc{'dust_time'}.long_name = ncchar('time for dust');
-nc{'dust_time'}.long_name = 'time for dust';
-nc{'dust_time'}.units = ncchar('day');
-nc{'dust_time'}.units = 'day';
-if cycle~=0
-  nc{'dust_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'dust_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'dust'}.long_name = ncchar('Dust Deposition');
 nc{'dust'}.long_name = 'Dust Deposition';
diff --git a/Preprocessing_tools/Bio/make_ini_pisces.m b/Preprocessing_tools/Bio/make_ini_pisces.m
index 80a3afa418a8d90b02292a208b71b01926da6f7d..291992444f275fb4575b0023ad01f065ab0a7161 100644
--- a/Preprocessing_tools/Bio/make_ini_pisces.m
+++ b/Preprocessing_tools/Bio/make_ini_pisces.m
@@ -115,7 +115,8 @@ disp(' ')
 disp('Iron ...')
 ext_tracers_ini(ininame,grdname,fer_month_data,fer_ann_data,...
              'fer','FER','r',tini);
-if (makeplot == 1)disp(' ')
+if (makeplot == 1)
+   disp(' ')
 %
 % Make a few plots
 %
diff --git a/Preprocessing_tools/Bio/make_n2o_bioebus.m b/Preprocessing_tools/Bio/make_n2o_bioebus.m
deleted file mode 100644
index c8805312ca66c4482541c5bd14b78bc4896f9f23..0000000000000000000000000000000000000000
--- a/Preprocessing_tools/Bio/make_n2o_bioebus.m
+++ /dev/null
@@ -1,317 +0,0 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  Add N2O data in input CROCO files from Global Atlas (WOA or CARS)
-%
-%  N2O distribution from Nevison et al. (2003) formulation
-%
-%  Data input format (netcdf):
-%     variable(T, Z, Y, X)
-%     T : time [Months]
-%     Z : Depth [m]
-%     Y : Latitude [degree north]
-%     X : Longitude [degree east]
-%
-%
-%  Elodie Gutknecht, 2013
-%  Gildas Cambon, 2013
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-clear all
-close all
-%
-%  Title 
-%
-crocotools_param
-%%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
-
-%
-%=========
-
-if makeini
-   nc=netcdf(grdname,'r');
-h = nc{'h'}(:);
-close(nc)
-% O2 initial conditions
-nc=netcdf(ininame,'r');
-theta_s = nc{'theta_s'}(:);
-theta_b = nc{'theta_b'}(:);
-Tcline = nc{'Tcline'}(:);
-N =  length(nc('s_rho'));
-vtransform=nc{'Vtransform'}(:);
-if  ~exist('vtransform')
-    vtransform=1; %Old Vtransform
-    disp([' NO VTRANSFORM parameter found'])
-    disp([' USE TRANSFORM default value vtransform = 1'])
-end
-O2_ini   = nc{'O2'}(:);
-close(nc)   
-type = 'initial conditions file' ; 
-history = 'CROCO' ;
-[KK,LL,MM]=size(O2_ini);
-%
-zw_ini=zlevs(h,0.,theta_s,theta_b,Tcline,N,'w',vtransform); 
-N2O_ini=zeros(KK,LL,MM);N2O_ini=NaN;
-for k=1:KK
-    for j=1:LL
-        for i=1:MM
-            N2O_ini(k,j,i)=nevis_2003(squeeze(zw_ini(k,j,i)),squeeze(O2_ini(k,j,i)));
-        end
-    end
-end
-% Find NaN
-find(isnan(N2O_ini)==1);%
-%
-% open the ini file  
-nc = netcdf(ininame,'write');
-% new variable
-%%redef(nc);
-nc('n2o_time') = 1;
-nc{'n2o_time'} = ncdouble('time') ;
-nc{'N2O'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
-nc{'N2O'}.long_name = ncchar('Nitrous oxide');
-nc{'N2O'}.long_name = 'Nitrous oxide';
-nc{'N2O'}.units = ncchar('mMol N2O m-3'); 
-nc{'N2O'}.units = 'mMol N2O m-3';
-nc{'N2O'}.fields = ncchar('NO2, scalar, series');
-nc{'N2O'}.fields = 'NO2, scalar, series';
-%%endef(nc);
-% write new variable
-nc{'N2O'}(:,:,:) =  N2O_ini; 
-% Synchronize on disk
-close(nc);
-end
-
-%==========
-if makeclim
-  nc=netcdf(grdname,'r');
-h = nc{'h'}(:);
-close(nc)
-% O2 climatological conditions
-nc=netcdf(clmname,'r');
-theta_s = nc{'theta_s'}(:);
-theta_b = nc{'theta_b'}(:);
-Tcline = nc{'Tcline'}(:);
-N =  length(nc('s_rho'));
-vtransform=nc{'Vtransform'}(:);
-if  ~exist('vtransform')
-    vtransform=1; %Old Vtransform
-    disp([' NO VTRANSFORM parameter found'])
-    disp([' USE TRANSFORM default value vtransform = 1'])
-end
-O2_clm  = nc{'O2'}(:);
-O2_time = nc{'o2_time'}(:);
-O2_cycle = nc{'o2_time'}.cycle_length(:);
-zeta = nc{'zeta'}(:);
-close(nc)
-[TT,KK,LL,MM]=size(O2_clm);
-for itps=1:length(O2_time)
-    zw_clm(itps,:,:,:)=zlevs(h,squeeze(zeta(itps,:,:)),theta_s,theta_b,Tcline,N,'w',vtransform); 
-end 
-N2O_clm=zeros(TT,KK,LL,MM); N2O_clm(:)=NaN;
-for t=1:TT
-    for k=1:KK
-        for j=1:LL
-            for i=1:MM
-                zw= squeeze(zw_clm(t,k,j,i));
-                O2=squeeze(O2_clm(t,k,j,i));
-                N2O_clm(t,k,j,i)=nevis_2003(zw,02);
-            end
-        end
-    end
-end
-% Find NaN
-find(isnan(N2O_clm)==1);
-%
-% add N20 in climatological file
-type = 'climatological conditions file' ; 
-history = 'CROCO' ;
-%
-% open the clm file  
-% 
-nc = netcdf(clmname,'write');
-%
-% new variable
-%
-%%redef(nc);
-nc('n2o_time') = TT;
-nc{'n2o_time'} = ncdouble('n2o_time') ;
-nc{'n2o_time'}.long_name = ncchar('time climatological N2O');
-nc{'n2o_time'}.long_name = 'time climatological N2O';
-nc{'n2o_time'}.units = ncchar('day');
-nc{'n2o_time'}.units = 'day';
-nc{'n2o_time'}.cycle_length = O2_cycle;
-
-nc{'N2O'} = ncdouble('n2o_time','s_rho','eta_rho','xi_rho') ;
-nc{'N2O'}.long_name = ncchar('Nitrous oxide');
-nc{'N2O'}.long_name = 'Nitrous oxide';
-nc{'N2O'}.units = ncchar('mMol N2O m-3'); 
-nc{'N2O'}.units = 'mMol N2O m-3';
-nc{'N2O'}.fields = ncchar('NO2, scalar, series');
-nc{'N2O'}.fields = 'NO2, scalar, series';
-%%endef(nc);
-%
-% write new variable
-%
-nc{'n2o_time'}(:) =  O2_time(:); 
-nc{'N2O'}(:,:,:,:) = N2O_clm(:); 
-%
-% Synchronize on disk
-%
-close(nc);
-end 
-
-%==========
-if makebry
-% O2 boundary conditions
-  nc=netcdf(grdname,'r');
-h = nc{'h'}(:);
-close(nc)       
-
-nc=netcdf(bryname,'r');
-theta_s = nc{'theta_s'}(:);
-theta_b = nc{'theta_b'}(:);
-Tcline = nc{'Tcline'}(:);
-N =  length(nc('s_rho'));
-vtransform=nc{'Vtransform'}(:);
-if  ~exist('vtransform')
-    vtransform=1; %Old Vtransform
-    disp([' NO VTRANSFORM parameter found'])
-    disp([' USE TRANSFORM default value vtransform = 1'])
-end
-O2_bry_west = nc{'O2_west'}(:);
-O2_bry_east = nc{'O2_east'}(:);
-O2_bry_south = nc{'O2_south'}(:);
-O2_bry_north = nc{'O2_north'}(:);
-O2_time = nc{'o2_time'}(:);
-O2_cycle = nc{'o2_time'}.cycle_length(:);
-zeta_west  = nc{'zeta_west'}(:);
-zeta_east  = nc{'zeta_east'}(:);
-zeta_south = nc{'zeta_south'}(:);
-zeta_north = nc{'zeta_north'}(:);
-close(nc)
-
-% BRY
-[TT,KK,MM]=size(O2_bry_south); [TT,KK,LL]=size(O2_bry_west);
-type='w'; 
-zw_bry_west  = zeros(TT,KK+1);
-zw_bry_east  = zeros(TT,KK+1);
-zw_bry_south = zeros(TT,KK+1);
-zw_bry_north = zeros(TT,KK+1);
-
-N2O_bry_east  = zeros(TT,KK,LL); N2O_bry_east(:)=NaN  ;
-N2O_bry_west  = zeros(TT,KK,LL); N2O_bry_west(:)=NaN  ;
-N2O_bry_south = zeros(TT,KK,MM); N2O_bry_south(:)=NaN ;
-N2O_bry_north = zeros(TT,KK,MM); N2O_bry_north(:)=NaN ;
-for t=1:TT
-    for j=1:LL
-        h_west  = squeeze(h(j,1));
-        h_east  = squeeze(h(j,end));
-        zw_bry_west(t,:,j) = zlevs_1d(h_west , squeeze(zeta_west(t,j)) , theta_s, theta_b, hc, N, type, vtransform);
-        zw_bry_east(t,:,j)= zlevs_1d(h_east , squeeze(zeta_east(t,j)) , theta_s, theta_b, hc, N, type, vtransform);
-    end
-end
-for t=1:TT
-    for i=1:MM
-        h_south  = squeeze(h(1,i));
-        h_north  = squeeze(h(end,i));
-        zw_bry_south(t,:,i)= zlevs_1d(h_south , squeeze(zeta_south(t,i)) , theta_s, theta_b, hc, N, type, vtransform);
-        zw_bry_north(t,:,i)= zlevs_1d(h_north , squeeze(zeta_north(t,i)) , theta_s, theta_b, hc, N, type, vtransform);
-    end
-end
-for t=1:TT
-    for k=1:KK
-        for j=1:LL
-            zw_east=zw_bry_east(t,k,j);
-            zw_west=zw_bry_west(t,k,j);
-            O2_east=O2_bry_east(t,k,j);
-            O2_west=O2_bry_west(t,k,j);      
-            N2O_bry_east(t,k,j)= nevis_2003(zw_east,O2_east);
-            N2O_bry_west(t,k,j)= nevis_2003(zw_west,O2_west);
-        end
-    end
-end
-for t=1:TT
-    for k=1:KK
-        for i=1:MM
-            zw_north=zw_bry_north(t,k,i);
-            zw_south=zw_bry_south(t,k,i);
-            O2_north=O2_bry_north(t,k,i);
-            O2_south=O2_bry_south(t,k,i);     
-            N2O_bry_north(t,k,i)=nevis_2003(zw_north,O2_north);
-            N2O_bry_south(t,k,i)=nevis_2003(zw_south,O2_south);
-        end
-    end
-end
-T= O2_time ;% time in days
-cycle=O2_cycle;
-
-%
-% add N20 in bryfile file
-%
-type = 'boundary conditions file' ; 
-history = 'CROCO' ;
-%
-% open the bry file  
-% 
-nc = netcdf(bryname,'write');
-% new variable
-%
-%%redef(nc);
-nc('n2o_time') = length(T);
-nc{'n2o_time'} = ncdouble('n2o_time') ;
-nc{'n2o_time'}.long_name = ncchar('time climatological N2O');
-nc{'n2o_time'}.long_name = 'time climatological N2O';
-nc{'n2o_time'}.units = ncchar('day');
-nc{'n2o_time'}.units = 'day';
-nc{'n2o_time'}.cycle_length = O2_cycle;
-
-nc{'N2O_east'} = ncdouble('n2o_time','s_rho','eta_rho') ;
-nc{'N2O_east'}.long_name = ncchar('Nitrous oxide');
-nc{'N2O_east'}.long_name = 'Nitrous oxide';
-nc{'N20_east'}.units = ncchar('mMol N2O m-3'); 
-nc{'N2O_east'}.units = 'mMol N2O m-3';
-nc{'N2O_east'}.fields = ncchar('NO2, scalar, series');
-nc{'N2O_east'}.fields = 'NO2, scalar, series';
-
-nc{'N2O_west'} = ncdouble('n2o_time','s_rho','eta_rho') ;
-nc{'N2O_west'}.long_name = ncchar('Nitrous oxide');
-nc{'N2O_west'}.long_name = 'Nitrous oxide';
-nc{'N2O_west'}.units = ncchar('mMol N2O m-3'); 
-nc{'N2O_west'}.units = 'mMol N2O m-3';
-nc{'N2O_west'}.fields = ncchar('NO2, scalar, series');
-nc{'N2O_west'}.fields = 'NO2, scalar, series';
-
-nc{'N2O_south'} = ncdouble('n2o_time','s_rho','xi_rho') ;
-nc{'N2O_south'}.long_name = ncchar('Nitrous oxide');
-nc{'N2O_south'}.long_name = 'Nitrous oxide';
-nc{'N20_south'}.units = ncchar('mMol N2O m-3'); 
-nc{'N2O_south'}.units = 'mMol N2O m-3';
-nc{'N2O_south'}.fields = ncchar('NO2, scalar, series');
-nc{'N2O_south'}.fields = 'NO2, scalar, series';
-
-nc{'N2O_north'} = ncdouble('n2o_time','s_rho','xi_rho') ;
-nc{'N2O_north'}.long_name = ncchar('Nitrous oxide');
-nc{'N2O_north'}.long_name = 'Nitrous oxide';
-nc{'N20_north'}.units = ncchar('mMol N2O m-3'); 
-nc{'N2O_north'}.units = 'mMol N2O m-3';
-nc{'N2O_north'}.fields = ncchar('NO2, scalar, series');
-nc{'N2O_north'}.fields = 'NO2, scalar, series';
-
-%
-% write new variable
-%
-nc{'n2o_time'}(:) =  T; 
-nc{'N2O_east'}(:,:,:,:) =  N2O_bry_east; 
-nc{'N2O_west'}(:,:,:,:) =  N2O_bry_west; 
-nc{'N2O_south'}(:,:,:,:) = N2O_bry_south; 
-nc{'N2O_north'}(:,:,:,:) = N2O_bry_north; 
-%
-% Synchronize on disk
-%
-close(nc);
-end
-
-
-
-
-
-
diff --git a/Preprocessing_tools/Bio/make_ndepo.m b/Preprocessing_tools/Bio/make_ndepo.m
index 1c2c35bb7e21264bc1c8b7c93fcdeacf8d808402..1571c79614589b67efce143ed508c2c193abdc67 100644
--- a/Preprocessing_tools/Bio/make_ndepo.m
+++ b/Preprocessing_tools/Bio/make_ndepo.m
@@ -29,6 +29,17 @@ close all
 disp(' ')
 disp('Creating biology forcing file')
 %
+% options for write_time_attributes
+insecond = 0  ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 %  Title - Grid file name - Forcing file name
 %
 crocotools_param
@@ -84,11 +95,8 @@ nc{'nhxndepo'} = ncdouble('ndepo_time','eta_rho','xi_rho') ;
 %
 nc{'ndepo_time'}.long_name = ncchar('time for nitrogen deposition');
 nc{'ndepo_time'}.long_name = 'time for nitrogen deposition';
-nc{'ndepo_time'}.units = ncchar('day');
-nc{'ndepo_time'}.units = 'day';
-if cycle~=0
-  nc{'ndepo_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'ndepo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'ndepo'}.long_name = ncchar('Nitrogen Deposition');
 nc{'ndepo'}.long_name = 'Nitrogen Deposition';
diff --git a/Preprocessing_tools/Bio/add_Sphyto_Lphyto.m b/Preprocessing_tools/Bio/npzd-bioebus/add_Sphyto_Lphyto.m
similarity index 85%
rename from Preprocessing_tools/Bio/add_Sphyto_Lphyto.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_Sphyto_Lphyto.m
index 95a2eade49fd798fdc560a5cda09a75554a5b6d0..ed04cf5e42493533b8d0527a63017c547e2e3bb7 100644
--- a/Preprocessing_tools/Bio/add_Sphyto_Lphyto.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_Sphyto_Lphyto.m
@@ -41,6 +41,18 @@ function add_Sphyto_Lphyto(climfile);
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0 ;
+add_cycle = 1 ; 
+%
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                    get_time_attributes(Yorig);
+%
 theta1=0.1;
 theta2=0.4;
 %
@@ -61,11 +73,8 @@ nc{'SPHYTO'} = ncdouble('sphyto_time','s_rho','eta_rho','xi_rho') ;
 %
 nc{'sphyto_time'}.long_name = ncchar('time for Small Phytoplankton');
 nc{'sphyto_time'}.long_name = 'time for Small Phytoplankton';
-nc{'sphyto_time'}.units = ncchar('day');
-nc{'sphyto_time'}.units = 'day';
-if cycle~=0
-  nc{'sphyto_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'sphyto_time',cycle,time_unit_att,time_second_unit_att,...
+                    calendar_att,insecond,add_cycle);
 %
 nc('lphyto_time') = tlen;
 nc{'lphyto_time'} = ncdouble('lphyto_time') ;
@@ -73,11 +82,8 @@ nc{'LPHYTO'} = ncdouble('lphyto_time','s_rho','eta_rho','xi_rho') ;
 %
 nc{'lphyto_time'}.long_name = ncchar('time for Large Phytoplankton');
 nc{'lphyto_time'}.long_name = 'time for Large Phytoplankton';
-nc{'lphyto_time'}.units = ncchar('day');
-nc{'lphyto_time'}.units = 'day';
-if cycle~=0
-  nc{'lphyto_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'lphyto_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
 %
 nc{'SPHYTO'}.long_name = ncchar('Small Phytoplankton');
 nc{'SPHYTO'}.long_name = 'Small Phytoplankton';
diff --git a/Preprocessing_tools/Bio/add_Szoo_Lzoo.m b/Preprocessing_tools/Bio/npzd-bioebus/add_Szoo_Lzoo.m
similarity index 84%
rename from Preprocessing_tools/Bio/add_Szoo_Lzoo.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_Szoo_Lzoo.m
index 96bc091cf7cdb0812e010d52fec772d581112512..1015c3a30cfffdf5c675745ee7d12d094b9a5e5b 100644
--- a/Preprocessing_tools/Bio/add_Szoo_Lzoo.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_Szoo_Lzoo.m
@@ -41,6 +41,18 @@ function add_Szoo_Lzoo(climfile);
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0 ;
+add_cycle = 1 ; 
+%
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                    get_time_attributes(Yorig);
+%
 theta1=0.2;
 theta2=0.3;
 %
@@ -61,11 +73,8 @@ nc{'SZOO'} = ncdouble('szoo_time','s_rho','eta_rho','xi_rho') ;
 %
 nc{'szoo_time'}.long_name = ncchar('time for Small Zooplankton');
 nc{'szoo_time'}.long_name = 'time for Small Zooplankton';
-nc{'szoo_time'}.units = ncchar('day');
-nc{'szoo_time'}.units = 'day';
-if cycle~=0
-  nc{'szoo_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'szoo_time',cycle,time_unit_att,time_second_unit_att,...
+                       calendar_att,insecond,add_cycle);
 %
 nc('lzoo_time') = tlen;
 nc{'lzoo_time'} = ncdouble('lzoo_time') ;
@@ -73,11 +82,8 @@ nc{'LZOO'} = ncdouble('lzoo_time','s_rho','eta_rho','xi_rho') ;
 %
 nc{'lzoo_time'}.long_name = ncchar('time for Large Zooplankton');
 nc{'lzoo_time'}.long_name = 'time for Large Zooplankton';
-nc{'lzoo_time'}.units = ncchar('day');
-nc{'lzoo_time'}.units = 'day';
-if cycle~=0
-  nc{'lzoo_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'lzoo_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
 %
 nc{'SZOO'}.long_name = ncchar('Small Zooplankton');
 nc{'SZOO'}.long_name = 'Small Zooplankton';
diff --git a/Preprocessing_tools/Bio/add_bry_bioebus.m b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_bioebus.m
similarity index 92%
rename from Preprocessing_tools/Bio/add_bry_bioebus.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_bry_bioebus.m
index 6938dafe7aef8314e6101fe8606c163e1cfc1086..ab69dbd2936ce4f753ef2a6990eb8a5ef967a2d8 100644
--- a/Preprocessing_tools/Bio/add_bry_bioebus.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_bioebus.m
@@ -46,6 +46,18 @@ function add_bry_bioebus(bryname,obc,time_no3,time_o2,time_zoo,time_phyto,time_c
 %  Gildas Cambon, IRD, 2011                                       %
 %  Gildas Cambon, IRD, 2013 : Add oxygen processing               %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 disp(' ')
 disp([' Adding BIOEBUS BGC data into file : ',bryname])
 disp(' ')
@@ -71,51 +83,44 @@ nc('one') = 1;
 nc{'no3_time'} = ncdouble('no3_time') ;
 nc{'no3_time'}.long_name = ncchar('time for NO3 climatology')
 nc{'no3_time'}.long_name = 'time for NO3 climatology';
-nc{'no3_time'}.units = ncchar('day');
-nc{'no3_time'}.units = 'day';
-nc{'no3_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'o2_time'} = ncdouble('o2_time') ;
 nc{'o2_time'}.long_name = ncchar('time for O2 climatology')
 nc{'o2_time'}.long_name = 'time for O2 climatology';
-nc{'o2_time'}.units = ncchar('day');
-nc{'o2_time'}.units = 'day';
-nc{'o2_time'}.cycle_length = cycle;
+write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'chla_time'} = ncdouble('chla_time') ;
 nc{'chla_time'}.long_name = ncchar('time for CHLA climatology');
 nc{'chla_time'}.long_name = 'time for CHLA climatology';
-nc{'chla_time'}.units = ncchar('day');
-nc{'chla_time'}.units = 'day';
-nc{'chla_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'chla_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'sphyto_time'} = ncdouble('sphyto_time') ;
 nc{'sphyto_time'}.long_name = ncchar('time for SPHYTO climatology');
 nc{'sphyto_time'}.long_name = 'time for SPHYTO climatology';
-nc{'sphyto_time'}.units = ncchar('day');
-nc{'sphyto_time'}.units = 'day';
-nc{'sphyto_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'sphyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'lphyto_time'} = ncdouble('lphyto_time') ;
 nc{'lphyto_time'}.long_name = ncchar('time for LPHYTO climatology');
 nc{'lphyto_time'}.long_name = 'time for LPHYTO climatology';
-nc{'lphyto_time'}.units = ncchar('day');
-nc{'lphyto_time'}.units = 'day';
-nc{'lphyto_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'lphyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'szoo_time'} = ncdouble('szoo_time') ;
 nc{'szoo_time'}.long_name = ncchar('time for SZOO climatology');
 nc{'szoo_time'}.long_name = 'time for SZOO climatology';
-nc{'szoo_time'}.units = ncchar('day');
-nc{'szoo_time'}.units = 'day';
-nc{'szoo_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'szoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'lzoo_time'} = ncdouble('lzoo_time') ;
 nc{'lzoo_time'}.long_name = ncchar('time for LZOO climatology');
 nc{'lzoo_time'}.long_name = 'time for LZOO climatology';
-nc{'lzoo_time'}.units = ncchar('day');
-nc{'lzoo_time'}.units = 'day';
-nc{'lzoo_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'lzoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 %
 if obc(1)==1
diff --git a/Preprocessing_tools/Bio/add_bry_bioebus_Z.m b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_bioebus_Z.m
similarity index 91%
rename from Preprocessing_tools/Bio/add_bry_bioebus_Z.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_bry_bioebus_Z.m
index 4a953a06fa12eaed48e35071c7fa2ebf60fb70a6..d643aa401ef99e94d1a8d8dd51686bb32f39b5c5 100644
--- a/Preprocessing_tools/Bio/add_bry_bioebus_Z.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_bioebus_Z.m
@@ -23,6 +23,18 @@ function add_bry_bioebus_Z(zbryname,obc,Z,time_no3,time_o2,time_zoo,time_phyto,t
 %  Christophe Eugene Raoul Menkes, the slave, IRD, 2007.          %
 %  Gildas Cambon, IRD/LEGOS, 2013 : Add O2 processing             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 disp(' ')
 disp([' Adding BioEBUS data into file : ',zbryname])
 disp(' ')
@@ -48,51 +60,45 @@ nc('one') = 1;
 nc{'no3_time'} = ncdouble('no3_time') ;
 nc{'no3_time'}.long_name = ncchar('time for NO3 climatology')
 nc{'no3_time'}.long_name = 'time for NO3 climatology';
-nc{'no3_time'}.units = ncchar('day');
-nc{'no3_time'}.units = 'day';
-nc{'no3_time'}.cycle_length = cycle;
+write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
+
 %
 nc{'o2_time'} = ncdouble('o2_time') ;
 nc{'o2_time'}.long_name = ncchar('time for O2 climatology')
 nc{'o2_time'}.long_name = 'time for O2 climatology';
-nc{'o2_time'}.units = ncchar('day');
-nc{'o2_time'}.units = 'day';
-nc{'o2_time'}.cycle_length = cycle;
+write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'chla_time'} = ncdouble('chla_time') ;
 nc{'chla_time'}.long_name = ncchar('time for CHLA climatology');
 nc{'chla_time'}.long_name = 'time for CHLA climatology';
-nc{'chla_time'}.units = ncchar('day');
-nc{'chla_time'}.units = 'day';
-nc{'chla_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'chla_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'sphyto_time'} = ncdouble('sphyto_time') ;
 nc{'sphyto_time'}.long_name = ncchar('time for SPHYTO climatology');
 nc{'sphyto_time'}.long_name = 'time for SPHYTO climatology';
-nc{'sphyto_time'}.units = ncchar('day');
-nc{'sphyto_time'}.units = 'day';
-nc{'sphyto_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'sphyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'lphyto_time'} = ncdouble('lphyto_time') ;
 nc{'lphyto_time'}.long_name = ncchar('time for LPHYTO climatology');
 nc{'lphyto_time'}.long_name = 'time for LPHYTO climatology';
-nc{'lphyto_time'}.units = ncchar('day');
-nc{'lphyto_time'}.units = 'day';
-nc{'lphyto_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'lphyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'szoo_time'} = ncdouble('szoo_time') ;
 nc{'szoo_time'}.long_name = ncchar('time for SZOO climatology');
 nc{'szoo_time'}.long_name = 'time for SZOO climatology';
-nc{'szoo_time'}.units = ncchar('day');
-nc{'szoo_time'}.units = 'day';
-nc{'szoo_time'}.cycle_length = cycle;
+write_time_attributes(nc,'szoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'lzoo_time'} = ncdouble('lzoo_time') ;
 nc{'lzoo_time'}.long_name = ncchar('time for LZOO climatology');
 nc{'lzoo_time'}.long_name = 'time for LZOO climatology';
-nc{'lzoo_time'}.units = ncchar('day');
-nc{'lzoo_time'}.units = 'day';
-nc{'lzoo_time'}.cycle_length = cycle;
+write_time_attributes(nc,'lzoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 
 if obc(1)==1
diff --git a/Preprocessing_tools/Bio/add_bry_npzd.m b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_npzd.m
similarity index 90%
rename from Preprocessing_tools/Bio/add_bry_npzd.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_bry_npzd.m
index 9cd49e6bd408693dff0f851e35392903379cb099..a46c011125dab0f982e94f8354204680ee64884b 100644
--- a/Preprocessing_tools/Bio/add_bry_npzd.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_npzd.m
@@ -46,6 +46,22 @@ function add_bry_npzd(bryname,obc,time_no3,time_o2,time_zoo,time_phyto,time_chla
 %  Gildas Cambon, IRD, 2011                                       %
 %  Gildas Cambon, IRD, 2013 : Add oxygen processing               %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+disp(' ')
+disp([' Adding PISCES data into file : ',bryname])
+disp(' ')
+%
 disp(' ')
 disp([' Adding NPZD BGC data into file : ',bryname])
 disp(' ')
@@ -67,39 +83,34 @@ nc('one') = 1;
 %  Create variables and attributes
 %
 nc{'no3_time'} = ncdouble('no3_time') ;
-nc{'no3_time'}.long_name = ncchar('time for NO3 climatology')
+nc{'no3_time'}.long_name = ncchar('time for NO3 climatology');
 nc{'no3_time'}.long_name = 'time for NO3 climatology';
-nc{'no3_time'}.units = ncchar('day');
-nc{'no3_time'}.units = 'day';
-nc{'no3_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'o2_time'} = ncdouble('o2_time') ;
-nc{'o2_time'}.long_name = ncchar('time for O2 climatology')
+nc{'o2_time'}.long_name = ncchar('time for O2 climatology');
 nc{'o2_time'}.long_name = 'time for O2 climatology';
-nc{'o2_time'}.units = ncchar('day');
-nc{'o2_time'}.units = 'day';
-nc{'o2_time'}.cycle_length = cycle;
+write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'chla_time'} = ncdouble('chla_time') ;
 nc{'chla_time'}.long_name = ncchar('time for CHLA climatology');
 nc{'chla_time'}.long_name = 'time for CHLA climatology';
-nc{'chla_time'}.units = ncchar('day');
-nc{'chla_time'}.units = 'day';
-nc{'chla_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'chla_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'phyto_time'} = ncdouble('phyto_time') ;
 nc{'phyto_time'}.long_name = ncchar('time for PHYTO climatology');
 nc{'phyto_time'}.long_name = 'time for PHYTO climatology';
-nc{'phyto_time'}.units = ncchar('day');
-nc{'phyto_time'}.units = 'day';
-nc{'phyto_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'phyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'zoo_time'} = ncdouble('zoo_time') ;
 nc{'zoo_time'}.long_name = ncchar('time for ZOO climatology');
 nc{'zoo_time'}.long_name = 'time for ZOO climatology';
-nc{'zoo_time'}.units = ncchar('day');
-nc{'zoo_time'}.units = 'day';
-nc{'zoo_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'zoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 %
 if obc(1)==1
diff --git a/Preprocessing_tools/Bio/add_bry_npzd_Z.m b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_npzd_Z.m
similarity index 91%
rename from Preprocessing_tools/Bio/add_bry_npzd_Z.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_bry_npzd_Z.m
index c1755f6a3e5cd3d51f8c448d1e8d5749ac2a59e5..29b60a6b91df2294df3c43394606269adf4c5857 100644
--- a/Preprocessing_tools/Bio/add_bry_npzd_Z.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_bry_npzd_Z.m
@@ -23,6 +23,18 @@ function add_bry_npzd_Z(zbryname,obc,Z,time_no3,time_o2,time_zoo,time_phyto,time
 %  Christophe Eugene Raoul Menkes, the slave, IRD, 2007.          %
 %  Gildas Cambon, IRD/LEGOS, 2013 : Add O2 processing             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
 disp(' ')
 disp([' Adding NPZD data into file : ',zbryname])
 disp(' ')
@@ -46,37 +58,32 @@ nc('one') = 1;
 nc{'no3_time'} = ncdouble('no3_time') ;
 nc{'no3_time'}.long_name = ncchar('time for NO3 climatology')
 nc{'no3_time'}.long_name = 'time for NO3 climatology';
-nc{'no3_time'}.units = ncchar('day');
-nc{'no3_time'}.units = 'day';
-nc{'no3_time'}.cycle_length = cycle;
+write_time_attributes(nc,'no3_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'o2_time'} = ncdouble('o2_time') ;
 nc{'o2_time'}.long_name = ncchar('time for O2 climatology')
 nc{'o2_time'}.long_name = 'time for O2 climatology';
-nc{'o2_time'}.units = ncchar('day');
-nc{'o2_time'}.units = 'day';
-nc{'o2_time'}.cycle_length = cycle;
+write_time_attributes(nc,'o2_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'chla_time'} = ncdouble('chla_time') ;
 nc{'chla_time'}.long_name = ncchar('time for CHLA climatology');
 nc{'chla_time'}.long_name = 'time for CHLA climatology';
-nc{'chla_time'}.units = ncchar('day');
-nc{'chla_time'}.units = 'day';
-nc{'chla_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'chla_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'phyto_time'} = ncdouble('phyto_time') ;
 nc{'phyto_time'}.long_name = ncchar('time for PHYTO climatology');
 nc{'phyto_time'}.long_name = 'time for PHYTO climatology';
-nc{'phyto_time'}.units = ncchar('day');
-nc{'phyto_time'}.units = 'day';
-nc{'phyto_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'phyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'zoo_time'} = ncdouble('zoo_time') ;
 nc{'zoo_time'}.long_name = ncchar('time for ZOO climatology');
 nc{'zoo_time'}.long_name = 'time for ZOO climatology';
-nc{'zoo_time'}.units = ncchar('day');
-nc{'zoo_time'}.units = 'day';
-nc{'zoo_time'}.cycle_length = cycle;
+write_time_attributes(nc,'zoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 
 if obc(1)==1
@@ -89,7 +96,7 @@ if obc(1)==1
   nc{'NO3_south'}.units = ncchar('mMol N m-3');
   nc{'NO3_south'}.units = 'mMol N m-3';
 %
-  nc{'O2_south'} = ncdouble('no3_time','Z','xi_rho') ;
+  nc{'O2_south'} = ncdouble('o2_time','Z','xi_rho') ;
   nc{'O2_south'}.long_name = ncchar('southern boundary O2');
   nc{'O2_south'}.long_name = 'southern boundary O2';
   nc{'O2_south'}.units = ncchar('mMol O m-3');
diff --git a/Preprocessing_tools/Bio/add_chla.m b/Preprocessing_tools/Bio/npzd-bioebus/add_chla.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_chla.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_chla.m
diff --git a/Preprocessing_tools/Bio/add_ini_Sphyto_Lphyto.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_Sphyto_Lphyto.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_Sphyto_Lphyto.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_Sphyto_Lphyto.m
diff --git a/Preprocessing_tools/Bio/add_ini_Szoo_Lzoo.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_Szoo_Lzoo.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_Szoo_Lzoo.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_Szoo_Lzoo.m
diff --git a/Preprocessing_tools/Bio/add_ini_bioebus.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_bioebus.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_bioebus.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_bioebus.m
diff --git a/Preprocessing_tools/Bio/add_ini_chla.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_chla.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_chla.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_chla.m
diff --git a/Preprocessing_tools/Bio/add_ini_no3.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_no3.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_no3.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_no3.m
diff --git a/Preprocessing_tools/Bio/add_ini_npzd.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_npzd.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_npzd.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_npzd.m
diff --git a/Preprocessing_tools/Bio/add_ini_o2.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_o2.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_o2.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_o2.m
diff --git a/Preprocessing_tools/Bio/add_ini_phyto.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_phyto.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_phyto.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_phyto.m
diff --git a/Preprocessing_tools/Bio/add_ini_zoo.m b/Preprocessing_tools/Bio/npzd-bioebus/add_ini_zoo.m
similarity index 100%
rename from Preprocessing_tools/Bio/add_ini_zoo.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_ini_zoo.m
diff --git a/Preprocessing_tools/Bio/add_phyto.m b/Preprocessing_tools/Bio/npzd-bioebus/add_phyto.m
similarity index 85%
rename from Preprocessing_tools/Bio/add_phyto.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_phyto.m
index c38091ca6954c01cabd58cb7c85dc149c74e7a72..cbcc07cc190a32e496e4ad24830cc8df55ac37dd 100644
--- a/Preprocessing_tools/Bio/add_phyto.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_phyto.m
@@ -39,6 +39,18 @@ function add_phyto(climfile);
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0 ;
+add_cycle = 1 ; 
+%
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                    get_time_attributes(Yorig);
+%
 theta=0.5;
 %
 disp('Add_phyto: creating variable and attribute')
@@ -56,11 +68,8 @@ nc{'PHYTO'} = ncdouble('phyto_time','s_rho','eta_rho','xi_rho') ;
 %
 nc{'phyto_time'}.long_name = ncchar('time for phytoplankton');
 nc{'phyto_time'}.long_name = 'time for phytoplankton';
-nc{'phyto_time'}.units = ncchar('day');
-nc{'phyto_time'}.units = 'day';
-if cycle~=0
-  nc{'phyto_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'phyto_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'PHYTO'}.long_name = ncchar('Phytoplankton');
 nc{'PHYTO'}.long_name = 'Phytoplankton';
diff --git a/Preprocessing_tools/Bio/add_zoo.m b/Preprocessing_tools/Bio/npzd-bioebus/add_zoo.m
similarity index 85%
rename from Preprocessing_tools/Bio/add_zoo.m
rename to Preprocessing_tools/Bio/npzd-bioebus/add_zoo.m
index 597a1c10555bcfe406512e3d9f3212d9fdd7832c..cf14cdaf080e706de67d1014668b6e3d2aee626d 100644
--- a/Preprocessing_tools/Bio/add_zoo.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/add_zoo.m
@@ -41,6 +41,19 @@ function add_zoo(climfile);
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
+% options for write_time_attributes
+insecond = 0 ;
+add_cycle = 1 ; 
+%
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                    get_time_attributes(Yorig);
+%
+%
 theta=0.2;
 %
 disp('Add_zoo: creating variable and attribute')
@@ -58,11 +71,8 @@ nc{'ZOO'} = ncdouble('zoo_time','s_rho','eta_rho','xi_rho') ;
 %
 nc{'zoo_time'}.long_name = ncchar('time for zooplankton');
 nc{'zoo_time'}.long_name = 'time for zooplankton';
-nc{'zoo_time'}.units = ncchar('day');
-nc{'zoo_time'}.units = 'day';
-if cycle~=0
-  nc{'zoo_time'}.cycle_length = cycle;
-end
+write_time_attributes(nc,'zoo_time',cycle,time_unit_att,time_second_unit_att,...
+  calendar_att,insecond,add_cycle);
 %
 nc{'ZOO'}.long_name = ncchar('Zooplankton');
 nc{'ZOO'}.long_name = 'Zooplankton';
diff --git a/Preprocessing_tools/Bio/bry_interp_bgc.m b/Preprocessing_tools/Bio/npzd-bioebus/bry_interp_bgc.m
similarity index 100%
rename from Preprocessing_tools/Bio/bry_interp_bgc.m
rename to Preprocessing_tools/Bio/npzd-bioebus/bry_interp_bgc.m
diff --git a/Preprocessing_tools/Bio/bry_interp_bgc_chloro.m b/Preprocessing_tools/Bio/npzd-bioebus/bry_interp_bgc_chloro.m
similarity index 100%
rename from Preprocessing_tools/Bio/bry_interp_bgc_chloro.m
rename to Preprocessing_tools/Bio/npzd-bioebus/bry_interp_bgc_chloro.m
diff --git a/Preprocessing_tools/Bio/make_bry_bioebus.m b/Preprocessing_tools/Bio/npzd-bioebus/make_bry_bioebus.m
similarity index 99%
rename from Preprocessing_tools/Bio/make_bry_bioebus.m
rename to Preprocessing_tools/Bio/npzd-bioebus/make_bry_bioebus.m
index 7e7ad42670068c8c2ff4c16b6bbb7f961efd4c21..9bea5debdd860cf4bb982c4da5ce0c9e912d94cc 100644
--- a/Preprocessing_tools/Bio/make_bry_bioebus.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/make_bry_bioebus.m
@@ -72,7 +72,7 @@ no3_ann_data=[climato_dir,'no3_ann.cdf'];
 o2_seas_data=[climato_dir,'o2_month.cdf'];
 o2_ann_data=[climato_dir,'o2_ann.cdf'];
 chla_seas_data=[chla_dir,'chla_seas.cdf'];
-chla_ann_data=[chla_dir,'chla_seas.cdf'];
+chla_ann_data=[chla_dir,'chla_ann.cdf'];
 %
 %
 %%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
diff --git a/Preprocessing_tools/Bio/make_bry_npzd.m b/Preprocessing_tools/Bio/npzd-bioebus/make_bry_npzd.m
similarity index 98%
rename from Preprocessing_tools/Bio/make_bry_npzd.m
rename to Preprocessing_tools/Bio/npzd-bioebus/make_bry_npzd.m
index 11b9b01a9a04e79cc5f25213ae2920ac3ab7a9e7..0dd9b10bd69b4eacaab02fc1255cacddbddec502 100644
--- a/Preprocessing_tools/Bio/make_bry_npzd.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/make_bry_npzd.m
@@ -67,9 +67,9 @@ Roa;
 %  Data climatologies file names:
 %
 %
-no3_seas_data=[climato_dir,'no3_seas.cdf'];
+no3_seas_data=[climato_dir,'no3_month.cdf'];
 no3_ann_data=[climato_dir,'no3_ann.cdf'];
-o2_seas_data=[climato_dir,'o2_seas.cdf'];
+o2_seas_data=[climato_dir,'o2_month.cdf'];
 o2_ann_data=[climato_dir,'o2_ann.cdf'];
 chla_seas_data=[chla_dir,'chla_seas.cdf'];
 chla_ann_data=[chla_dir,'chla_ann.cdf'];
diff --git a/Preprocessing_tools/Bio/make_clim_bioebus.m b/Preprocessing_tools/Bio/npzd-bioebus/make_clim_bioebus.m
similarity index 100%
rename from Preprocessing_tools/Bio/make_clim_bioebus.m
rename to Preprocessing_tools/Bio/npzd-bioebus/make_clim_bioebus.m
diff --git a/Preprocessing_tools/Bio/make_clim_npzd.m b/Preprocessing_tools/Bio/npzd-bioebus/make_clim_npzd.m
similarity index 97%
rename from Preprocessing_tools/Bio/make_clim_npzd.m
rename to Preprocessing_tools/Bio/npzd-bioebus/make_clim_npzd.m
index 0f31acb21a5d6f0cf0f5399aa73313cafb0cc0e7..65edff43589f325c62cd0b16dfd2776201f30ae1 100644
--- a/Preprocessing_tools/Bio/make_clim_npzd.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/make_clim_npzd.m
@@ -34,9 +34,9 @@ crocotools_param
 %
 %  Data climatologies file names:
 %
-no3_seas_data=[climato_dir,'no3_seas.cdf'];
+no3_seas_data=[climato_dir,'no3_month.cdf'];
 no3_ann_data=[climato_dir,'no3_ann.cdf'];
-o2_seas_data=[climato_dir,'o2_seas.cdf'];
+o2_seas_data=[climato_dir,'o2_month.cdf'];
 o2_ann_data=[climato_dir,'o2_ann.cdf'];
 chla_seas_data=[chla_dir,'chla_seas.cdf'];
 
diff --git a/Preprocessing_tools/Bio/make_ini_bioebus.m b/Preprocessing_tools/Bio/npzd-bioebus/make_ini_bioebus.m
similarity index 100%
rename from Preprocessing_tools/Bio/make_ini_bioebus.m
rename to Preprocessing_tools/Bio/npzd-bioebus/make_ini_bioebus.m
diff --git a/Preprocessing_tools/Bio/make_ini_npzd.m b/Preprocessing_tools/Bio/npzd-bioebus/make_ini_npzd.m
similarity index 100%
rename from Preprocessing_tools/Bio/make_ini_npzd.m
rename to Preprocessing_tools/Bio/npzd-bioebus/make_ini_npzd.m
diff --git a/Preprocessing_tools/Bio/npzd-bioebus/make_n2o_bioebus.m b/Preprocessing_tools/Bio/npzd-bioebus/make_n2o_bioebus.m
new file mode 100644
index 0000000000000000000000000000000000000000..ea0677a57d13bc5b0de4a499c1c6d07255534a89
--- /dev/null
+++ b/Preprocessing_tools/Bio/npzd-bioebus/make_n2o_bioebus.m
@@ -0,0 +1,322 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  Add N2O data in input CROCO files from Global Atlas (WOA or CARS)
+%
+%  N2O distribution from Nevison et al. (2003) formulation
+%
+%  Data input format (netcdf):
+%     variable(T, Z, Y, X)
+%     T : time [Months]
+%     Z : Depth [m]
+%     Y : Latitude [degree north]
+%     X : Longitude [degree east]
+%
+%
+%  Elodie Gutknecht, 2013
+%  Gildas Cambon, 2013
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+clear all
+close all
+%
+%  Title
+%
+crocotools_param
+%%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
+%
+% options for write_time_attributes
+insecond =  0 ;
+add_cycle = 1 ;
+Yorig='';
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
+%=========
+
+if makeini
+    nc=netcdf(grdname,'r');
+    h = nc{'h'}(:);
+    close(nc)
+    % O2 initial conditions
+    nc=netcdf(ininame,'r');
+    theta_s = nc{'theta_s'}(:);
+    theta_b = nc{'theta_b'}(:);
+    Tcline = nc{'Tcline'}(:);
+    N =  length(nc('s_rho'));
+    vtransform=nc{'Vtransform'}(:);
+    if  ~exist('vtransform')
+        vtransform=1; %Old Vtransform
+        disp([' NO VTRANSFORM parameter found'])
+        disp([' USE TRANSFORM default value vtransform = 1'])
+    end
+    O2_ini   = nc{'O2'}(:);
+    close(nc)
+    type = 'initial conditions file' ;
+    history = 'CROCO' ;
+    [KK,LL,MM]=size(O2_ini);
+    %
+    zw_ini=zlevs(h,0.,theta_s,theta_b,Tcline,N,'w',vtransform);
+    N2O_ini=zeros(KK,LL,MM);N2O_ini=NaN;
+    for k=1:KK
+        for j=1:LL
+            for i=1:MM
+                N2O_ini(k,j,i)=nevis_2003(squeeze(zw_ini(k,j,i)),squeeze(O2_ini(k,j,i)));
+            end
+        end
+    end
+    % Find NaN
+    find(isnan(N2O_ini)==1);%
+    %
+    % open the ini file
+    nc = netcdf(ininame,'write');
+    % new variable
+    %%redef(nc);
+    %
+    nc{'N2O'} = ncdouble('time','s_rho','eta_rho','xi_rho') ;
+    nc{'N2O'}.long_name = 'Nitrous oxide';
+    nc{'N2O'}.fields = 'NO2, scalar, series';
+    %%endef(nc);
+    % write new variable
+    nc{'N2O'}(:,:,:) =  N2O_ini;
+    % Synchronize on disk
+    close(nc);
+end
+
+%==========
+if makeclim
+    nc=netcdf(grdname,'r');
+    h = nc{'h'}(:);
+    close(nc)
+    % O2 climatological conditions
+    nc=netcdf(clmname,'r');
+    theta_s = nc{'theta_s'}(:);
+    theta_b = nc{'theta_b'}(:);
+    Tcline = nc{'Tcline'}(:);
+    N =  length(nc('s_rho'));
+    vtransform=nc{'Vtransform'}(:);
+    if  ~exist('vtransform')
+        vtransform=1; %Old Vtransform
+        disp([' NO VTRANSFORM parameter found'])
+        disp([' USE TRANSFORM default value vtransform = 1'])
+    end
+    O2_clm  = nc{'O2'}(:);
+    O2_time = nc{'o2_time'}(:);
+    O2_cycle = nc{'o2_time'}.cycle_length(:);
+    zeta = nc{'zeta'}(:);
+    close(nc)
+    [TT,KK,LL,MM]=size(O2_clm);
+    for itps=1:length(O2_time)
+        zw_clm(itps,:,:,:)=zlevs(h,squeeze(zeta(itps,:,:)),theta_s,theta_b,Tcline,N,'w',vtransform);
+    end
+    N2O_clm=zeros(TT,KK,LL,MM); N2O_clm(:)=NaN;
+    for t=1:TT
+        for k=1:KK
+            for j=1:LL
+                for i=1:MM
+                    zw= squeeze(zw_clm(t,k,j,i));
+                    O2=squeeze(O2_clm(t,k,j,i));
+                    N2O_clm(t,k,j,i)=nevis_2003(zw,02);
+                end
+            end
+        end
+    end
+    % Find NaN
+    find(isnan(N2O_clm)==1);
+    %
+    % add N20 in climatological file
+    type = 'climatological conditions file' ;
+    history = 'CROCO' ;
+    %
+    % open the clm file
+    %
+    nc = netcdf(clmname,'write');
+    %
+    % new variable
+    %
+    %%redef(nc);
+    nc('n2o_time') = TT;
+    nc{'n2o_time'} = ncdouble('n2o_time') ;
+    nc{'n2o_time'}.long_name = ncchar('time climatological N2O');
+    nc{'n2o_time'}.long_name = 'time climatological N2O';
+    write_time_attributes(nc,'n2o_time',O2_cycle,time_unit_att,time_second_unit_att,...
+        calendar_att,0,1);
+
+    nc{'N2O'} = ncdouble('n2o_time','s_rho','eta_rho','xi_rho') ;
+    nc{'N2O'}.long_name = ncchar('Nitrous oxide');
+    nc{'N2O'}.long_name = 'Nitrous oxide';
+    nc{'N2O'}.units = ncchar('mMol N2O m-3');
+    nc{'N2O'}.units = 'mMol N2O m-3';
+    nc{'N2O'}.fields = ncchar('NO2, scalar, series');
+    nc{'N2O'}.fields = 'NO2, scalar, series';
+    %%endef(nc);
+    %
+    % write new variable
+    %
+    nc{'n2o_time'}(:) =  O2_time(:);
+    nc{'N2O'}(:,:,:,:) = N2O_clm(:);
+    %
+    % Synchronize on disk
+    %
+    close(nc);
+end
+
+%==========
+if makebry
+    % O2 boundary conditions
+    nc=netcdf(grdname,'r');
+    h = nc{'h'}(:);
+    close(nc)
+
+    nc=netcdf(bryname,'r');
+    theta_s = nc{'theta_s'}(:);
+    theta_b = nc{'theta_b'}(:);
+    Tcline = nc{'Tcline'}(:);
+    N =  length(nc('s_rho'));
+    vtransform=nc{'Vtransform'}(:);
+    if  ~exist('vtransform')
+        vtransform=1; %Old Vtransform
+        disp([' NO VTRANSFORM parameter found'])
+        disp([' USE TRANSFORM default value vtransform = 1'])
+    end
+    O2_bry_west = nc{'O2_west'}(:);
+    O2_bry_east = nc{'O2_east'}(:);
+    O2_bry_south = nc{'O2_south'}(:);
+    O2_bry_north = nc{'O2_north'}(:);
+    O2_time = nc{'o2_time'}(:);
+    O2_cycle = nc{'o2_time'}.cycle_length(:);
+    zeta_west  = nc{'zeta_west'}(:);
+    zeta_east  = nc{'zeta_east'}(:);
+    zeta_south = nc{'zeta_south'}(:);
+    zeta_north = nc{'zeta_north'}(:);
+    close(nc)
+
+    % BRY
+    [TT,KK,MM]=size(O2_bry_south); [TT,KK,LL]=size(O2_bry_west);
+    type='w';
+    zw_bry_west  = zeros(TT,KK+1);
+    zw_bry_east  = zeros(TT,KK+1);
+    zw_bry_south = zeros(TT,KK+1);
+    zw_bry_north = zeros(TT,KK+1);
+
+    N2O_bry_east  = zeros(TT,KK,LL); N2O_bry_east(:)=NaN  ;
+    N2O_bry_west  = zeros(TT,KK,LL); N2O_bry_west(:)=NaN  ;
+    N2O_bry_south = zeros(TT,KK,MM); N2O_bry_south(:)=NaN ;
+    N2O_bry_north = zeros(TT,KK,MM); N2O_bry_north(:)=NaN ;
+    for t=1:TT
+        for j=1:LL
+            h_west  = squeeze(h(j,1));
+            h_east  = squeeze(h(j,end));
+            zw_bry_west(t,:,j) = zlevs_1d(h_west , squeeze(zeta_west(t,j)) , theta_s, theta_b, hc, N, type, vtransform);
+            zw_bry_east(t,:,j)= zlevs_1d(h_east , squeeze(zeta_east(t,j)) , theta_s, theta_b, hc, N, type, vtransform);
+        end
+    end
+    for t=1:TT
+        for i=1:MM
+            h_south  = squeeze(h(1,i));
+            h_north  = squeeze(h(end,i));
+            zw_bry_south(t,:,i)= zlevs_1d(h_south , squeeze(zeta_south(t,i)) , theta_s, theta_b, hc, N, type, vtransform);
+            zw_bry_north(t,:,i)= zlevs_1d(h_north , squeeze(zeta_north(t,i)) , theta_s, theta_b, hc, N, type, vtransform);
+        end
+    end
+    for t=1:TT
+        for k=1:KK
+            for j=1:LL
+                zw_east=zw_bry_east(t,k,j);
+                zw_west=zw_bry_west(t,k,j);
+                O2_east=O2_bry_east(t,k,j);
+                O2_west=O2_bry_west(t,k,j);
+                N2O_bry_east(t,k,j)= nevis_2003(zw_east,O2_east);
+                N2O_bry_west(t,k,j)= nevis_2003(zw_west,O2_west);
+            end
+        end
+    end
+    for t=1:TT
+        for k=1:KK
+            for i=1:MM
+                zw_north=zw_bry_north(t,k,i);
+                zw_south=zw_bry_south(t,k,i);
+                O2_north=O2_bry_north(t,k,i);
+                O2_south=O2_bry_south(t,k,i);
+                N2O_bry_north(t,k,i)=nevis_2003(zw_north,O2_north);
+                N2O_bry_south(t,k,i)=nevis_2003(zw_south,O2_south);
+            end
+        end
+    end
+    T= O2_time ;% time in days
+    cycle=O2_cycle;
+
+    %
+    % add N20 in bryfile file
+    %
+    type = 'boundary conditions file' ;
+    history = 'CROCO' ;
+    %
+    % open the bry file
+    %
+    nc = netcdf(bryname,'write');
+    % new variable
+    %
+    %%redef(nc);
+    nc('n2o_time') = length(T);
+    nc{'n2o_time'} = ncdouble('n2o_time') ;
+    nc{'n2o_time'}.long_name = ncchar('time climatological N2O');
+    nc{'n2o_time'}.long_name = 'time climatological N2O';
+    write_time_attributes(nc,'n2o_time',O2_cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,0,1);
+
+    nc{'N2O_east'} = ncdouble('n2o_time','s_rho','eta_rho') ;
+    nc{'N2O_east'}.long_name = ncchar('Nitrous oxide');
+    nc{'N2O_east'}.long_name = 'Nitrous oxide';
+    nc{'N20_east'}.units = ncchar('mMol N2O m-3');
+    nc{'N2O_east'}.units = 'mMol N2O m-3';
+    nc{'N2O_east'}.fields = ncchar('NO2, scalar, series');
+    nc{'N2O_east'}.fields = 'NO2, scalar, series';
+
+    nc{'N2O_west'} = ncdouble('n2o_time','s_rho','eta_rho') ;
+    nc{'N2O_west'}.long_name = ncchar('Nitrous oxide');
+    nc{'N2O_west'}.long_name = 'Nitrous oxide';
+    nc{'N2O_west'}.units = ncchar('mMol N2O m-3');
+    nc{'N2O_west'}.units = 'mMol N2O m-3';
+    nc{'N2O_west'}.fields = ncchar('NO2, scalar, series');
+    nc{'N2O_west'}.fields = 'NO2, scalar, series';
+
+    nc{'N2O_south'} = ncdouble('n2o_time','s_rho','xi_rho') ;
+    nc{'N2O_south'}.long_name = ncchar('Nitrous oxide');
+    nc{'N2O_south'}.long_name = 'Nitrous oxide';
+    nc{'N20_south'}.units = ncchar('mMol N2O m-3');
+    nc{'N2O_south'}.units = 'mMol N2O m-3';
+    nc{'N2O_south'}.fields = ncchar('NO2, scalar, series');
+    nc{'N2O_south'}.fields = 'NO2, scalar, series';
+
+    nc{'N2O_north'} = ncdouble('n2o_time','s_rho','xi_rho') ;
+    nc{'N2O_north'}.long_name = ncchar('Nitrous oxide');
+    nc{'N2O_north'}.long_name = 'Nitrous oxide';
+    nc{'N20_north'}.units = ncchar('mMol N2O m-3');
+    nc{'N2O_north'}.units = 'mMol N2O m-3';
+    nc{'N2O_north'}.fields = ncchar('NO2, scalar, series');
+    nc{'N2O_north'}.fields = 'NO2, scalar, series';
+
+    %
+    % write new variable
+    %
+    nc{'n2o_time'}(:) =  T;
+    nc{'N2O_east'}(:,:,:,:) =  N2O_bry_east;
+    nc{'N2O_west'}(:,:,:,:) =  N2O_bry_west;
+    nc{'N2O_south'}(:,:,:,:) = N2O_bry_south;
+    nc{'N2O_north'}(:,:,:,:) = N2O_bry_north;
+    %
+    % Synchronize on disk
+    %
+    close(nc);
+end
+
+
+
+
+
+
diff --git a/Preprocessing_tools/Bio/nevis_2003.m b/Preprocessing_tools/Bio/npzd-bioebus/nevis_2003.m
similarity index 100%
rename from Preprocessing_tools/Bio/nevis_2003.m
rename to Preprocessing_tools/Bio/npzd-bioebus/nevis_2003.m
diff --git a/Preprocessing_tools/Bio/vinterp_bry_bgc.m b/Preprocessing_tools/Bio/npzd-bioebus/vinterp_bry_bgc.m
similarity index 98%
rename from Preprocessing_tools/Bio/vinterp_bry_bgc.m
rename to Preprocessing_tools/Bio/npzd-bioebus/vinterp_bry_bgc.m
index 154fb011637849b3318aff1044ce088f49da3256..ea3c42dceb2f8b35ad20d7db555cab059376b68b 100644
--- a/Preprocessing_tools/Bio/vinterp_bry_bgc.m
+++ b/Preprocessing_tools/Bio/npzd-bioebus/vinterp_bry_bgc.m
@@ -93,7 +93,6 @@ for l=1:tlen
 %for l=1:1
   disp([' Time index: ',num2str(l),' of total: ',num2str(tlen)])
   var=squeeze(noa{vname}(l,:));
-%  disp(['SIZE VAR=',num2str(size(var))])
   if addsurf
     var=cat(1,var(1,:),var);
   end
diff --git a/Preprocessing_tools/create_bry_Z.m b/Preprocessing_tools/create_bry_Z.m
index ffd60b91ddaa6a82ccfddb89034dcce201201fa2..10e06c66d72e3889401531c5f1c9bcf174e1d574 100644
--- a/Preprocessing_tools/create_bry_Z.m
+++ b/Preprocessing_tools/create_bry_Z.m
@@ -1,5 +1,5 @@
 function create_bry_Z(zbryname,grdname,title,obc,...
-                      Z,time,cycle,clobber);
+                      Z,time,cycle,clobber,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %   This function create the header of a Netcdf boundary
@@ -44,6 +44,17 @@ disp(' ')
 disp([' Creating the file : ',zbryname])
 disp(' ')
 %
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+        get_time_attributes(Yorig);
+%
 %  Read the grid file and check the topography
 %
 nc = netcdf(grdname, 'nowrite');
@@ -81,9 +92,8 @@ nc{'Z'}.units = 'm';
 nc{'bry_time'} = ncdouble('bry_time') ;
 nc{'bry_time'}.long_name = ncchar('time for temperature climatology');
 nc{'bry_time'}.long_name = 'time for temperature climatology';
-nc{'bry_time'}.units = ncchar('day');
-nc{'bry_time'}.units = 'day';
-nc{'bry_time'}.cycle_length = cycle;%
+write_time_attributes(nc,'bry_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 if obc(1)==1
 %
diff --git a/Preprocessing_tools/create_bryfile.m b/Preprocessing_tools/create_bryfile.m
index e36dde8a424dba55eb23d715dc26d29afe2877d6..0c24858aad0b95c9bc5adc5bd00d1ff4a91b1790 100644
--- a/Preprocessing_tools/create_bryfile.m
+++ b/Preprocessing_tools/create_bryfile.m
@@ -1,6 +1,6 @@
 function create_bryfile(bryname,grdname,title,obc,...
                         theta_s,theta_b,hc,N,...
-                        time,cycle,clobber,vtransform);
+                        time,cycle,clobber,vtransform,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % function create_bryfile(bryname,grdname,title,obc...
@@ -60,6 +60,19 @@ if nargin < 12
 end
 disp([' VTRANSFORM = ',num2str(vtransform)])
 %
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+                    get_time_attributes(Yorig);
+%
+%
 %  Read the grid file and check the topography
 %
 nc = netcdf(grdname, 'nowrite');
@@ -130,14 +143,14 @@ nc{'Vstretching'}.long_name = 'vertical terrain-following stretching function';
 nc{'tstart'} = ncdouble('one') ;
 nc{'tstart'}.long_name = ncchar('start processing day');
 nc{'tstart'}.long_name = 'start processing day';
-nc{'tstart'}.units = ncchar('day');
-nc{'tstart'}.units = 'day';
+write_time_attributes(nc,'tstart','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'tend'} = ncdouble('one') ;
 nc{'tend'}.long_name = ncchar('end processing day');
 nc{'tend'}.long_name = 'end processing day';
-nc{'tend'}.units = ncchar('day');
-nc{'tend'}.units = 'day';
+write_time_attributes(nc,'tend','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'theta_s'} = ncdouble('one') ;
 nc{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
@@ -214,103 +227,70 @@ nc{'Cs_w'}.valid_min = -1;
 nc{'Cs_w'}.valid_max = 0;
 %
 nc{'bry_time'} = ncdouble('bry_time') ;
-nc{'bry_time'}.long_name = ncchar('time for boundary climatology');
-nc{'bry_time'}.long_name = 'time for boundary climatology';
-nc{'bry_time'}.units = ncchar('day');
-nc{'bry_time'}.units = 'day';
-nc{'bry_time'}.calendar = ncchar('360.0 days in every year');
-nc{'bry_time'}.calendar = '360.0 days in every year';
-nc{'bry_time'}.cycle_length = cycle;
+nc{'bry_time'}.long_name = ncchar('time for boundary');
+nc{'bry_time'}.long_name = 'time for boundary';
+write_time_attributes(nc,'bry_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
 %
 nc{'tclm_time'} = ncdouble('tclm_time') ;
 nc{'tclm_time'}.long_name = ncchar('time for temperature climatology');
 nc{'tclm_time'}.long_name = 'time for temperature climatology';
-nc{'tclm_time'}.units = ncchar('day');
-nc{'tclm_time'}.units = 'day';
-nc{'tclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'tclm_time'}.calendar = '360.0 days in every year';
-nc{'tclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'tclm_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
 %
 nc{'temp_time'} = ncdouble('temp_time') ;
 nc{'temp_time'}.long_name = ncchar('time for temperature climatology');
 nc{'temp_time'}.long_name = 'time for temperature climatology';
-nc{'temp_time'}.units = ncchar('day');
-nc{'temp_time'}.units = 'day';
-nc{'temp_time'}.calendar = ncchar('360.0 days in every year');
-nc{'temp_time'}.calendar = '360.0 days in every year';
-nc{'temp_time'}.cycle_length = cycle;
+write_time_attributes(nc,'temp_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'sclm_time'} = ncdouble('sclm_time') ;
 nc{'sclm_time'}.long_name = ncchar('time for salinity climatology');
 nc{'sclm_time'}.long_name = 'time for salinity climatology';
-nc{'sclm_time'}.units = ncchar('day');
-nc{'sclm_time'}.units = 'day';
-nc{'sclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'sclm_time'}.calendar = '360.0 days in every year';
-nc{'sclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'sclm_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'salt_time'} = ncdouble('salt_time') ;
 nc{'salt_time'}.long_name = ncchar('time for salinity climatology');
 nc{'salt_time'}.long_name = 'time for salinity climatology';
-nc{'salt_time'}.units = ncchar('day');
-nc{'salt_time'}.units = 'day';
-nc{'salt_time'}.calendar = ncchar('360.0 days in every year');
-nc{'salt_time'}.calendar = '360.0 days in every year';
-nc{'salt_time'}.cycle_length = cycle;
+write_time_attributes(nc,'salt_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'uclm_time'} = ncdouble('uclm_time') ;
 nc{'uclm_time'}.long_name = ncchar('time climatological u');
 nc{'uclm_time'}.long_name = 'time climatological u';
-nc{'uclm_time'}.units = ncchar('day');
-nc{'uclm_time'}.units = 'day';
-nc{'uclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'uclm_time'}.calendar = '360.0 days in every year';
-nc{'uclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'sclm_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'vclm_time'} = ncdouble('vclm_time') ;
 nc{'vclm_time'}.long_name = ncchar('time climatological v');
 nc{'vclm_time'}.long_name = 'time climatological v';
-nc{'vclm_time'}.units = ncchar('day');
-nc{'vclm_time'}.units = 'day';
-nc{'vclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'vclm_time'}.calendar = '360.0 days in every year';
-nc{'vclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'vclm_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'v2d_time'} = ncdouble('v2d_time') ;
 nc{'v2d_time'}.long_name = ncchar('time for 2D velocity climatology');
 nc{'v2d_time'}.long_name = 'time for 2D velocity climatology';
-nc{'v2d_time'}.units = ncchar('day');
-nc{'v2d_time'}.units = 'day';
-nc{'v2d_time'}.calendar = ncchar('360.0 days in every year');
-nc{'v2d_time'}.calendar = '360.0 days in every year';
-nc{'v2d_time'}.cycle_length = cycle;
+write_time_attributes(nc,'v2d_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'v3d_time'} = ncdouble('v3d_time') ;
 nc{'v3d_time'}.long_name = ncchar('time for 3D velocity climatology');
 nc{'v3d_time'}.long_name = 'time for 3D velocity climatology';
-nc{'v3d_time'}.units = ncchar('day');
-nc{'v3d_time'}.units = 'day';
-nc{'v3d_time'}.calendar = ncchar('360.0 days in every year');
-nc{'v3d_time'}.calendar = '360.0 days in every year';
-nc{'v3d_time'}.cycle_length = cycle;
+write_time_attributes(nc,'v3d_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'ssh_time'} = ncdouble('ssh_time') ;
 nc{'ssh_time'}.long_name = ncchar('time for sea surface height');
 nc{'ssh_time'}.long_name = 'time for sea surface height';
-nc{'ssh_time'}.units = ncchar('day');
-nc{'ssh_time'}.units = 'day';
-nc{'ssh_time'}.calendar = ncchar('360.0 days in every year');
-nc{'ssh_time'}.calendar = '360.0 days in every year';
-nc{'ssh_time'}.cycle_length = cycle;
+write_time_attributes(nc,'ssh_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 nc{'zeta_time'} = ncdouble('zeta_time') ;
 nc{'zeta_time'}.long_name = ncchar('time for sea surface height');
 nc{'zeta_time'}.long_name = 'time for sea surface height';
-nc{'zeta_time'}.units = ncchar('day');
-nc{'zeta_time'}.units = 'day';
-nc{'zeta_time'}.calendar = ncchar('360.0 days in every year');
-nc{'zeta_time'}.calendar = '360.0 days in every year';
-nc{'zeta_time'}.cycle_length = cycle;
+write_time_attributes(nc,'zeta_time',cycle,time_unit_att,time_second_unit_att,...
+                           calendar_att,insecond,add_cycle);
 %
 if obc(1)==1
 %
diff --git a/Preprocessing_tools/create_bryfile_wkb.m b/Preprocessing_tools/create_bryfile_wkb.m
index 1320ede33e3e32a10094e0524d446b7a56e6b818..b772955057caf6a1b0f14ad0b35a21fd321cfbac 100644
--- a/Preprocessing_tools/create_bryfile_wkb.m
+++ b/Preprocessing_tools/create_bryfile_wkb.m
@@ -1,5 +1,5 @@
 function create_bryfile(brywkbname,grdname,title,wkb_obc,...
-                        time,cycle,clobber);
+                        time,cycle,clobber,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % function create_bryfile(brywkbname,grdname,title,wkb_obc...
@@ -46,6 +46,17 @@ disp(' ')
 disp([' Creating the file : ',brywkbname])
 disp(' ')
 %
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+  %
+  % Get time attributes
+  [time_unit_att,time_second_unit_att,calendar_att]=...
+                      get_time_attributes(Yorig);
+%
 %  Read the grid file
 %
 nc = netcdf(grdname, 'nowrite');
@@ -78,25 +89,21 @@ nc('one') = 1;
 nc{'tstart'} = ncdouble('one') ;
 nc{'tstart'}.long_name = ncchar('start processing day');
 nc{'tstart'}.long_name = 'start processing day';
-nc{'tstart'}.units = ncchar('day');
-nc{'tstart'}.units = 'day';
+write_time_attributes(nc,'tstart','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'tend'} = ncdouble('one') ;
 nc{'tend'}.long_name = ncchar('end processing day');
 nc{'tend'}.long_name = 'end processing day';
-nc{'tend'}.units = ncchar('day');
-nc{'tend'}.units = 'day';
-%
+write_time_attributes(nc,'tend','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'brywkb_time'} = ncdouble('brywkb_time') ;
 nc{'brywkb_time'}.long_name = ncchar('time for boundary climatology');
 nc{'brywkb_time'}.long_name = 'time for boundary climatology';
-nc{'brywkb_time'}.units = ncchar('day');
-nc{'brywkb_time'}.units = 'day';
-nc{'brywkb_time'}.calendar = ncchar('360.0 days in every year');
-nc{'brywkb_time'}.calendar = '360.0 days in every year';
-nc{'brywkb_time'}.cycle_length = cycle;
-%
+write_time_attributes(nc,'brywkb_time',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,insecond,add_cycle);
+
 if wkb_obc(1)==1
 %
 %   Southern boundary
diff --git a/Preprocessing_tools/create_bulk.m b/Preprocessing_tools/create_bulk.m
index 1ef478163c3a02416c7442bea0eb836283ffb53b..e7783e5c41f180037f9e3216f15c9c7e50a8c85e 100644
--- a/Preprocessing_tools/create_bulk.m
+++ b/Preprocessing_tools/create_bulk.m
@@ -1,4 +1,4 @@
-function  create_bulk(frcname,grdname,title,bulkt,bulkc)
+function  create_bulk(frcname,grdname,title,bulkt,bulkc,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % 	Create an empty netcdf heat flux bulk forcing file
@@ -39,10 +39,20 @@ M=length(nc('eta_psi'));
 close(nc);
 Lp=L+1;
 Mp=M+1;
-
+%
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+      get_time_attributes(Yorig);
+%
 nw = netcdf(frcname, 'clobber');
 %result = redef(nw);
-
 %
 %  Create dimensions
 %
@@ -61,9 +71,8 @@ nw('bulk_time') = 0;
 nw{'bulk_time'}              = ncdouble('bulk_time');
 nw{'bulk_time'}.long_name    = ncchar('bulk formulation execution time');
 nw{'bulk_time'}.long_name    = 'bulk formulation execution time';
-nw{'bulk_time'}.units        = ncchar('days');
-nw{'bulk_time'}.units        = 'days';
-nw{'bulk_time'}.cycle_length = bulkc;
+write_time_attributes(nc,'bulk_time',bulkc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'tair'}             = ncdouble('bulk_time', 'eta_rho', 'xi_rho');
 nw{'tair'}.long_name   = ncchar('surface air temperature');
diff --git a/Preprocessing_tools/create_climfile.m b/Preprocessing_tools/create_climfile.m
index 7e2bee7a33a668d18c5356820ae84ec11a07c08b..617d1de9a9b8af522deefccced868cb5e9c2cf4c 100644
--- a/Preprocessing_tools/create_climfile.m
+++ b/Preprocessing_tools/create_climfile.m
@@ -1,39 +1,39 @@
 function create_climfile(clmname,grdname,title,...
-                         theta_s,theta_b,hc,N,...
-                         time,cycle,clobber,vtransform);
+                        theta_s,theta_b,hc,N,...
+                        time,cycle,clobber,vtransform, Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % function create_climfile(clmname,grdname,title,...
 %                          theta_s,theta_b,hc,N,...
 %                          time,cycle,clobber);
 %
-%   This function create the header of a Netcdf climatology 
+%   This function create the header of a Netcdf climatology
 %   file.
 %
 %   Input:
 %
 %   clmname      Netcdf climatology file name (character string).
 %   grdname      Netcdf grid file name (character string).
-%   theta_s      S-coordinate surface control parameter.(Real) 
+%   theta_s      S-coordinate surface control parameter.(Real)
 %   theta_b      S-coordinate bottom control parameter.(Real)
 %   hc           Width (m) of surface or bottom boundary layer
 %                where higher vertical resolution is required
-%                during stretching.(Real) 
-%   N            Number of vertical levels.(Integer) 
-%   time        Temperature climatology time.(vector) 
+%                during stretching.(Real)
+%   N            Number of vertical levels.(Integer)
+%   time        Temperature climatology time.(vector)
 %   time        Salinity climatology time.(vector)
 %   time        Velocity climatology time.(vector)
 %   cycle        Length (days) for cycling the climatology.(Real)
-%   clobber      Switch to allow or not writing over an existing 
+%   clobber      Switch to allow or not writing over an existing
 %                file.(character string)
 %
 %   Output
 %
 %   nc       Output netcdf object.
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -51,20 +51,32 @@ function create_climfile(clmname,grdname,title,...
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2001-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2001-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 disp(' ')
 disp([' Creating the file : ',clmname])
 disp(' ')
 if nargin < 11
-   disp([' NO VTRANSFORM parameter found'])
-   disp([' USE TRANSFORM default value vtransform = 1'])
-    vtransform = 1; 
+    disp([' NO VTRANSFORM parameter found'])
+    disp([' USE TRANSFORM default value vtransform = 1'])
+    vtransform = 1;
 end
 disp([' VTRANSFORM = ',num2str(vtransform)])
 %
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
+%
+%
 %  Read the grid file
 %
 nc = netcdf(grdname, 'nowrite');
@@ -75,9 +87,9 @@ Mp=length(nc('eta_rho'));
 close(nc);
 hmin=min(min(h(maskr==1)));
 if vtransform ==1;
-  if hc > hmin
-    error([' hc (',num2str(hc),' m) > hmin (',num2str(hmin),' m)'])
-  end
+    if hc > hmin
+        error([' hc (',num2str(hc),' m) > hmin (',num2str(hmin),' m)'])
+    end
 end
 L=Lp-1;
 M=Mp-1;
@@ -85,7 +97,7 @@ Np=N+1;
 %
 %  Create the climatology file
 %
-type = 'CLIMATOLOGY file' ; 
+type = 'CLIMATOLOGY file' ;
 history = 'CROCO' ;
 nc = netcdf(clmname,clobber);
 % result = redef(nc);
@@ -164,13 +176,13 @@ nc{'spherical'}.flag_meanings = 'spherical Cartesian';
 %
 nc{'tstart'}.long_name = ncchar('start processing day');
 nc{'tstart'}.long_name = 'start processing day';
-nc{'tstart'}.units = ncchar('day');
-nc{'tstart'}.units = 'day';
+write_time_attributes(nc,'tstart',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'tend'}.long_name = ncchar('end processing day');
 nc{'tend'}.long_name = 'end processing day';
-nc{'tend'}.units = ncchar('day');
-nc{'tend'}.units = 'day';
+write_time_attributes(nc,'tend',cycle,time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
 nc{'theta_s'}.long_name = 'S-coordinate surface control parameter';
@@ -203,7 +215,7 @@ if (vtransform ==1)
     nc{'s_rho'}.standard_name = 'ocean_s_coordinate_g1';
 elseif (vtransform ==2)
     nc{'s_rho'}.standard_name = ncchar('ocean_s_coordinate_g2');
-    nc{'s_rho'}.standard_name = 'ocean_s_coordinate_g2';     
+    nc{'s_rho'}.standard_name = 'ocean_s_coordinate_g2';
 end
 nc{'s_rho'}.formula_terms = ncchar('s: s_rho C: Cs_rho eta: zeta depth: h depth_c: hc');
 nc{'s_rho'}.formula_terms = 's: s_rho C: Cs_rho eta: zeta depth: h depth_c: hc';
@@ -240,83 +252,53 @@ nc{'Cs_w'}.valid_max = 0;
 %
 nc{'tclm_time'}.long_name = ncchar('time for temperature climatology');
 nc{'tclm_time'}.long_name = 'time for temperature climatology';
-nc{'tclm_time'}.units = ncchar('day');
-nc{'tclm_time'}.units = 'day';
-nc{'tclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'tclm_time'}.calendar = '360.0 days in every year';
-nc{'tclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'tclm_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'temp_time'}.long_name = ncchar('time for temperature climatology');
 nc{'temp_time'}.long_name = 'time for temperature climatology';
-nc{'temp_time'}.units = ncchar('day');
-nc{'temp_time'}.units = 'day';
-nc{'temp_time'}.calendar = ncchar('360.0 days in every year');
-nc{'temp_time'}.calendar = '360.0 days in every year';
-nc{'temp_time'}.cycle_length = cycle;
+write_time_attributes(nc,'temp_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'sclm_time'}.long_name = ncchar('time for salinity climatology');
 nc{'sclm_time'}.long_name = 'time for salinity climatology';
-nc{'sclm_time'}.units = ncchar('day');
-nc{'sclm_time'}.units = 'day';
-nc{'sclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'sclm_time'}.calendar = '360.0 days in every year';
-nc{'sclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'sclm_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'salt_time'}.long_name = ncchar('time for salinity climatology');
 nc{'salt_time'}.long_name = 'time for salinity climatology';
-nc{'salt_time'}.units = ncchar('day');
-nc{'salt_time'}.units = 'day';
-nc{'salt_time'}.calendar = ncchar('360.0 days in every year');
-nc{'salt_time'}.calendar = '360.0 days in every year';
-nc{'salt_time'}.cycle_length = cycle;
+write_time_attributes(nc,'salt_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'uclm_time'}.long_name = ncchar('time climatological u');
 nc{'uclm_time'}.long_name = 'time climatological u';
-nc{'uclm_time'}.units = ncchar('day');
-nc{'uclm_time'}.units = 'day';
-nc{'uclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'uclm_time'}.calendar = '360.0 days in every year';
-nc{'uclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'uclm_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'vclm_time'}.long_name = ncchar('time climatological v');
 nc{'vclm_time'}.long_name = 'time climatological v';
-nc{'vclm_time'}.units = ncchar('day');
-nc{'vclm_time'}.units = 'day';
-nc{'vclm_time'}.calendar = ncchar('360.0 days in every year');
-nc{'vclm_time'}.calendar = '360.0 days in every year';
-nc{'vclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'vclm_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'v2d_time'}.long_name = ncchar('time for 2D velocity climatology');
 nc{'v2d_time'}.long_name = 'time for 2D velocity climatology';
-nc{'v2d_time'}.units = ncchar('day');
-nc{'v2d_time'}.units = 'day';
-nc{'v2d_time'}.calendar = ncchar('360.0 days in every year');
-nc{'v2d_time'}.calendar = '360.0 days in every year';
-nc{'v2d_time'}.cycle_length = cycle;
+write_time_attributes(nc,'v2d_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'v3d_time'}.long_name = ncchar('time for 3D velocity climatology');
 nc{'v3d_time'}.long_name = 'time for 3D velocity climatology';
-nc{'v3d_time'}.units = ncchar('day');
-nc{'v3d_time'}.units = 'day';
-nc{'v3d_time'}.calendar = ncchar('360.0 days in every year');
-nc{'v3d_time'}.calendar = '360.0 days in every year';
-nc{'v3d_time'}.cycle_length = cycle;
+write_time_attributes(nc,'v3d_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'ssh_time'}.long_name = ncchar('time for sea surface height');
 nc{'ssh_time'}.long_name = 'time for sea surface height';
-nc{'ssh_time'}.units = ncchar('day');
-nc{'ssh_time'}.units = 'day';
-nc{'ssh_time'}.calendar = ncchar('360.0 days in every year');
-nc{'ssh_time'}.calendar = '360.0 days in every year';
-nc{'ssh_time'}.cycle_length = cycle;
+write_time_attributes(nc,'ssh_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'zeta_time'}.long_name = ncchar('time for sea surface height');
 nc{'zeta_time'}.long_name = 'time for sea surface height';
-nc{'zeta_time'}.units = ncchar('day');
-nc{'zeta_time'}.units = 'day';
-nc{'zeta_time'}.calendar = ncchar('360.0 days in every year');
-nc{'zeta_time'}.calendar = '360.0 days in every year';
-nc{'zeta_time'}.cycle_length = cycle;
+write_time_attributes(nc,'zeta_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'temp'}.long_name = ncchar('potential temperature');
 nc{'temp'}.long_name = 'potential temperature';
@@ -412,52 +394,40 @@ nc.history = history;
 % Set S-Curves in domain [-1 < sc < 0] at vertical W- and RHO-points.
 %
 [s_rho,Cs_rho,s_w,Cs_w] = scoordinate(theta_s,theta_b,N,hc,vtransform);
-%disp(['vtransform=',num2str(vtransform)])
-
-% cff1=1./sinh(theta_s);
-% cff2=0.5/tanh(0.5*theta_s);
-% s_rho=((1:N)-N-0.5)/N;
-% Cs_rho=(1.-theta_b)*cff1*sinh(theta_s*s_rho)...
-%     +theta_b*(cff2*tanh(theta_s*(s_rho+0.5))-0.5);
-% s_w=((0:N)-N)/N;
-% Cs_w=(1.-theta_b)*cff1*sinh(theta_s*s_w)...
-%     +theta_b*(cff2*tanh(theta_s*(s_w+0.5))-0.5);
-
-
 %
 % Write variables
 %
 nc{'spherical'}(:)='T';
 nc{'Vtransform'}(:)=vtransform;
 nc{'Vstretching'}(:)=1;
-nc{'tstart'}(:) =  min([min(time) min(time) min(time)]); 
-nc{'tend'}(:) =  max([max(time) max(time) max(time)]); 
-nc{'theta_s'}(:) =  theta_s; 
-nc{'theta_b'}(:) =  theta_b; 
-nc{'Tcline'}(:) =  hc; 
-nc{'hc'}(:) =  hc; 
+nc{'tstart'}(:) =  min([min(time) min(time) min(time)]);
+nc{'tend'}(:) =  max([max(time) max(time) max(time)]);
+nc{'theta_s'}(:) =  theta_s;
+nc{'theta_b'}(:) =  theta_b;
+nc{'Tcline'}(:) =  hc;
+nc{'hc'}(:) =  hc;
 nc{'s_rho'}(:) = s_rho;
 nc{'s_w'}(:) = s_w;
-nc{'Cs_rho'}(:) =  Cs_rho; 
+nc{'Cs_rho'}(:) =  Cs_rho;
 nc{'Cs_w'}(:) = Cs_w;
-nc{'tclm_time'}(:) =  time; 
-nc{'temp_time'}(:) =  time; 
-nc{'sclm_time'}(:) =  time; 
-nc{'salt_time'}(:) =  time; 
-nc{'uclm_time'}(:) =  time; 
-nc{'vclm_time'}(:) =  time; 
-nc{'v2d_time'}(:) =   time; 
-nc{'v3d_time'}(:) =   time; 
+nc{'tclm_time'}(:) =  time;
+nc{'temp_time'}(:) =  time;
+nc{'sclm_time'}(:) =  time;
+nc{'salt_time'}(:) =  time;
+nc{'uclm_time'}(:) =  time;
+nc{'vclm_time'}(:) =  time;
+nc{'v2d_time'}(:) =   time;
+nc{'v3d_time'}(:) =   time;
 nc{'ssh_time'}(:) =   time;
 nc{'zeta_time'}(:) =  time;
-nc{'u'}(:) =  0; 
-nc{'v'}(:) =  0; 
-nc{'ubar'}(:) =  0; 
-nc{'vbar'}(:) =  0; 
-nc{'SSH'}(:) =  0; 
-nc{'zeta'}(:) =  0; 
-nc{'temp'}(:) =  0; 
-nc{'salt'}(:) =  0; 
+nc{'u'}(:) =  0;
+nc{'v'}(:) =  0;
+nc{'ubar'}(:) =  0;
+nc{'vbar'}(:) =  0;
+nc{'SSH'}(:) =  0;
+nc{'zeta'}(:) =  0;
+nc{'temp'}(:) =  0;
+nc{'salt'}(:) =  0;
 close(nc)
 return
 
diff --git a/Preprocessing_tools/create_forcing.m b/Preprocessing_tools/create_forcing.m
index 624c2de917095f86e78023227358bc52e619b7f1..f56963d072ca96a4d983e23d727143d2a1fc2fd6 100644
--- a/Preprocessing_tools/create_forcing.m
+++ b/Preprocessing_tools/create_forcing.m
@@ -1,6 +1,6 @@
 function  create_forcing(frcname,grdname,title,smst,...
                          shft,swft,srft,sstt,ssst,smsc,...
-                         shfc,swfc,srfc,sstc,sssc)
+                         shfc,swfc,srfc,sstc,sssc, Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % 	Create an empty netcdf forcing file
@@ -38,7 +38,18 @@ M=length(nc('eta_psi'));
 close(nc);
 Lp=L+1;
 Mp=M+1;
-
+%
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+      get_time_attributes(Yorig);
+%
 nw = netcdf(frcname, 'clobber');
 %result = redef(nw);
 
@@ -67,52 +78,44 @@ nw('wwv_time') = length(smst);
 nw{'sms_time'} = ncdouble('sms_time');
 nw{'sms_time'}.long_name = ncchar('surface momentum stress time');
 nw{'sms_time'}.long_name = 'surface momentum stress time';
-nw{'sms_time'}.units = ncchar('days');
-nw{'sms_time'}.units = 'days';
-nw{'sms_time'}.cycle_length = smsc;
+write_time_attributes(nc,'sms_time',smsc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'shf_time'} = ncdouble('shf_time');
 nw{'shf_time'}.long_name = ncchar('surface heat flux time');
 nw{'shf_time'}.long_name = 'surface heat flux time';
-nw{'shf_time'}.units = ncchar('days');
-nw{'shf_time'}.units = 'days';
-nw{'shf_time'}.cycle_length =shfc ;
+write_time_attributes(nc,'shf_time',shfc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'swf_time'} = ncdouble('swf_time');
 nw{'swf_time'}.long_name = ncchar('surface freshwater flux time');
 nw{'swf_time'}.long_name = 'surface freshwater flux time';
-nw{'swf_time'}.units = ncchar('days');
-nw{'swf_time'}.units = 'days';
-nw{'swf_time'}.cycle_length = swfc;
+write_time_attributes(nc,'swf_time',swfc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'sst_time'} = ncdouble('sst_time');
 nw{'sst_time'}.long_name = ncchar('sea surface temperature time');
 nw{'sst_time'}.long_name = 'sea surface temperature time';
-nw{'sst_time'}.units = ncchar('days');
-nw{'sst_time'}.units = 'days';
-nw{'sst_time'}.cycle_length = sstc;
+write_time_attributes(nc,'sst_time',sstc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'sss_time'} = ncdouble('sss_time');
 nw{'sss_time'}.long_name = ncchar('sea surface salinity time');
 nw{'sss_time'}.long_name = 'sea surface salinity time';
-nw{'sss_time'}.units = ncchar('days');
-nw{'sss_time'}.units = 'days';
-nw{'sss_time'}.cycle_length = sssc;
+write_time_attributes(nc,'sss_time',sssc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'srf_time'} = ncdouble('srf_time');
 nw{'srf_time'}.long_name = ncchar('solar shortwave radiation time');
 nw{'srf_time'}.long_name = 'solar shortwave radiation time';
-nw{'srf_time'}.units = ncchar('days');
-nw{'srf_time'}.units = 'days';
-nw{'srf_time'}.cycle_length = srfc;
+write_time_attributes(nc,'srf_time',srfc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'wwv_time'} = ncdouble('wwv_time');
 nw{'wwv_time'}.long_name = ncchar('surface wave fields time');
 nw{'wwv_time'}.long_name = 'surface wave fields time';
-nw{'wwv_time'}.units = ncchar('days');
-nw{'wwv_time'}.units = 'days';
-nw{'wwv_time'}.cycle_length = smsc;
-
+write_time_attributes(nc,'wwv_time',smsc,time_unit_att,time_second_unit_att,...
+                          calendar_att,insecond,add_cycle);
 
 nw{'sustr'} = ncdouble('sms_time', 'eta_u', 'xi_u');
 nw{'sustr'}.long_name = ncchar('surface u-momentum stress');
diff --git a/Preprocessing_tools/create_inifile.m b/Preprocessing_tools/create_inifile.m
index acdc9abc116e2aa64d463824ebe5cf63a5fa17d2..265bb410acb5e2ec4447b2d680561c92e72c9a39 100644
--- a/Preprocessing_tools/create_inifile.m
+++ b/Preprocessing_tools/create_inifile.m
@@ -1,5 +1,6 @@
 function create_inifile(inifile,gridfile,title,...
-                         theta_s,theta_b,hc,N,time,clobber,vtransform)
+                        theta_s,theta_b,hc,N,time,clobber,vtransform,...
+                        Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function nc=create_inifile(inifile,gridfile,theta_s,...
@@ -53,12 +54,24 @@ function create_inifile(inifile,gridfile,title,...
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 disp(' ')
 disp([' Creating the file : ',inifile])
+
 if nargin < 10
    disp([' NO VTRANSFORM parameter found'])
    disp([' USE TRANSFORM default value vtransform = 1'])
    vtransform = 1; 
+   disp([' VTRANSFORM = ',num2str(vtransform)])
 end
-disp([' VTRANSFORM = ',num2str(vtransform)])
+%
+% options for write_time_attributes
+insecond = 1  ;
+add_cycle = 0 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = []; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+    get_time_attributes(Yorig);
 %
 %  Read the grid file
 %
@@ -131,13 +144,13 @@ nc{'Vstretching'}.long_name = 'vertical terrain-following stretching function';
 %
 nc{'tstart'}.long_name = ncchar('start processing day');
 nc{'tstart'}.long_name = 'start processing day';
-nc{'tstart'}.units = ncchar('day');
-nc{'tstart'}.units = 'day';
+write_time_attributes(nc,'tstart','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'tend'}.long_name = ncchar('end processing day');
 nc{'tend'}.long_name = 'end processing day';
-nc{'tend'}.units = ncchar('day');
-nc{'tend'}.units = 'day';
+write_time_attributes(nc,'tend','',time_unit_att,time_second_unit_att,...
+                      calendar_att,0,0);
 %
 nc{'theta_s'}.long_name = ncchar('S-coordinate surface control parameter');
 nc{'theta_s'}.long_name = 'S-coordinate surface control parameter';
@@ -175,13 +188,13 @@ nc{'Cs_rho'}.valid_max = 0;
 %
 nc{'ocean_time'}.long_name = ncchar('time since initialization');
 nc{'ocean_time'}.long_name = 'time since initialization';
-nc{'ocean_time'}.units = ncchar('second');
-nc{'ocean_time'}.units = 'second';
-%
+write_time_attributes(nc,'ocean_time','',time_unit_att,time_second_unit_att,...
+                      calendar_att,1,0);
+
 nc{'scrum_time'}.long_name = ncchar('time since initialization');
 nc{'scrum_time'}.long_name = 'time since initialization';
-nc{'scrum_time'}.units = ncchar('second');
-nc{'scrum_time'}.units = 'second';
+write_time_attributes(nc,'scrum_time','',time_unit_att,time_second_unit_att,...
+                      calendar_att,1,0);
 %
 nc{'u'}.long_name = ncchar('u-momentum component');
 nc{'u'}.long_name = 'u-momentum component';
diff --git a/Preprocessing_tools/create_oafile.m b/Preprocessing_tools/create_oafile.m
index 875e1cd81e445da511463dbfd8e74b13e3492122..7b765817645b17704c29fb4def8357d35ebe2415 100644
--- a/Preprocessing_tools/create_oafile.m
+++ b/Preprocessing_tools/create_oafile.m
@@ -1,5 +1,5 @@
 function create_oafile(oaname,grdname,title,Z,...
-                       time,cycle,clobber);
+                       time,cycle,clobber,Yorig);
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  function nc=create_oafile(oaname,grdname,title,Z,...
@@ -49,6 +49,18 @@ disp(' ')
 disp([' Creating the file : ',oaname])
 disp(' ')
 %
+% options for write_time_attributes
+insecond = 0;
+add_cycle = 1 ; 
+%
+% Initialize Yorig if not provided
+if ~exist('Yorig', 'var') ,  Yorig = [] ; , end
+%
+% Get time attributes
+[time_unit_att,time_second_unit_att,calendar_att]=...
+        get_time_attributes(Yorig);
+%
+%
 %  Read the grid file
 %
 nc = netcdf(grdname, 'nowrite');
@@ -153,51 +165,43 @@ nc{'Z'}.units = 'm';
 %
 nc{'tclm_time'}.long_name = ncchar('time for temperature climatology');
 nc{'tclm_time'}.long_name = 'time for temperature climatology';
-nc{'tclm_time'}.units = ncchar('day');
-nc{'tclm_time'}.units = 'day';
-nc{'tclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'tclm_time',cycle,time_unit_att,time_second_unit_att,...
+                    calendar_att,insecond,add_cycle);
 %
 nc{'sclm_time'}.long_name = ncchar('time for salinity climatology');
 nc{'sclm_time'}.long_name = 'time for salinity climatology';
-nc{'sclm_time'}.units = ncchar('day');
-nc{'sclm_time'}.units = 'day';
-nc{'sclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'sclm_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'uclm_time'}.long_name = ncchar('time for u climatology');
 nc{'uclm_time'}.long_name = 'time for u climatology';
-nc{'uclm_time'}.units = ncchar('day');
-nc{'uclm_time'}.units = 'day';
-nc{'uclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'uclm_time',cycle,time_unit_att,time_second_unit_att,...
+                    calendar_att,insecond,add_cycle);
 %
 nc{'vclm_time'}.long_name = ncchar('time for v climatology');
 nc{'vclm_time'}.long_name = 'time for v climatology';
-nc{'vclm_time'}.units = ncchar('day');
-nc{'vclm_time'}.units = 'day';
-nc{'vclm_time'}.cycle_length = cycle;
+write_time_attributes(nc,'vclm_time',cycle,time_unit_att,time_second_unit_att,...
+                    calendar_att,insecond,add_cycle);
 %
 nc{'v2d_time'}.long_name = ncchar('time for 2D velocity climatology');
 nc{'v2d_time'}.long_name = 'time for 2D velocity climatology';
-nc{'v2d_time'}.units = ncchar('day');
-nc{'v2d_time'}.units = 'day';
-nc{'v2d_time'}.cycle_length = cycle;
+write_time_attributes(nc,'v2d_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'v3d_time'}.long_name = ncchar('time for 3D velocity climatology');
 nc{'v3d_time'}.long_name = 'time for 3D velocity climatology';
-nc{'v3d_time'}.units = ncchar('day');
-nc{'v3d_time'}.units = 'day';
-nc{'v3d_time'}.cycle_length = cycle;
+write_time_attributes(nc,'v3d_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'ssh_time'}.long_name = ncchar('time for sea surface height');
 nc{'ssh_time'}.long_name = 'time for sea surface height';
-nc{'ssh_time'}.units = ncchar('day');
-nc{'ssh_time'}.units = 'day';
-nc{'ssh_time'}.cycle_length = cycle;
+write_time_attributes(nc,'ssh_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'zeta_time'}.long_name = ncchar('time for zeta climatology');
 nc{'zeta_time'}.long_name = 'time for zeta climatology';
-nc{'zeta_time'}.units = ncchar('day');
-nc{'zeta_time'}.units = 'day';
-nc{'zeta_time'}.cycle_length = cycle;
+write_time_attributes(nc,'zeta_time',cycle,time_unit_att,time_second_unit_att,...
+                        calendar_att,insecond,add_cycle);
 %
 nc{'temp'}.long_name = ncchar('potential temperature');
 nc{'temp'}.long_name = 'potential temperature';
diff --git a/Preprocessing_tools/get_time_attributes.m b/Preprocessing_tools/get_time_attributes.m
new file mode 100644
index 0000000000000000000000000000000000000000..5d1ca468855347b90a9418063ba22d8cb9018229
--- /dev/null
+++ b/Preprocessing_tools/get_time_attributes.m
@@ -0,0 +1,29 @@
+function [time_unit_att, time_second_unit_att, calendar_att] = ...
+    get_time_attributes(Yorig) ;
+
+    % GET_TIME_ATTRIBUTES Get time and calendar attributes for CROCO NetCDF files
+    %
+    % Inputs:
+    %   Yorig - Reference year (optional) for time origin
+    %
+    % Outputs:
+    %   time_unit_att - Time unit attribute string
+    %   calendar_att  - Calendar type attribute string
+
+    % Initialize default values
+    time_unit_att = 'days';
+    time_second_unit_att = 'seconds';
+    calendar_att = 'none';
+
+    % Check if valid Yorig is provided
+    % if nargin >= 1 && ~isempty(Yorig)
+    if ~isempty(Yorig)
+        disp([' Time reference is ', sprintf('%04d', Yorig), '-01-01 00:00:00'])
+        time_unit_att = ['days since ', sprintf('%04d', Yorig), '-01-01 00:00:00'];
+        time_second_unit_att = ['seconds since ',sprintf('%04d', Yorig),'-01-01 00:00:00'];
+        calendar_att = 'proleptic_gregorian';
+    else
+        disp(' No time reference')
+    end
+    
+end
\ No newline at end of file
diff --git a/Preprocessing_tools/make_bry.m b/Preprocessing_tools/make_bry.m
index 92b8dfa4c9def446b28e170a582a0fab16dbcbbe..709a88e35d4629c33eca01bd0b367b525a07e1d7 100644
--- a/Preprocessing_tools/make_bry.m
+++ b/Preprocessing_tools/make_bry.m
@@ -60,10 +60,10 @@ crocotools_param
 %    salt_month_data : monthly salinity climatology
 %    salt_ann_data   : annual salinity climatology
 %
-temp_month_data=[climato_dir,'temp_month.cdf']
-temp_ann_data=[climato_dir,'temp_ann.cdf']
-salt_month_data=[climato_dir,'salt_month.cdf']
-salt_ann_data=[climato_dir,'salt_ann.cdf']
+temp_month_data=[climato_dir,'temp_month.cdf'];
+temp_ann_data=[climato_dir,'temp_ann.cdf'];
+salt_month_data=[climato_dir,'salt_month.cdf'];
+salt_ann_data=[climato_dir,'salt_ann.cdf'];
 %
 %
 %%%%%%%%%%%%%%%%%%% END USERS DEFINED VARIABLES %%%%%%%%%%%%%%%%%%%%%%%
diff --git a/Preprocessing_tools/make_clim.m b/Preprocessing_tools/make_clim.m
index daf515f5d81f92b14fe8f1ed43b0afdb999910b7..6709dd1f15e32ea0eb3582c5396f2d734bcf6125 100644
--- a/Preprocessing_tools/make_clim.m
+++ b/Preprocessing_tools/make_clim.m
@@ -169,29 +169,29 @@ end
 
 
 
-%----------------------------------------------------------------------------
-% Initial file
-%----------------------------------------------------------------------------
-if (makeini)
-
-  disp('======================== ')
-  disp('Initial')
-  create_inifile(ininame,grdname,CROCO_title,...
-                 theta_s,theta_b,hc,N,...
-                 tini,'clobber',vtransform);
-  disp(' ')
-  disp(' Temperature...')
-  vinterp_clm(ininame,grdname,oaname,'temp','tclm_time','Z',tini,'r',1);
-  disp(' ')
-  disp(' Salinity...')
-  vinterp_clm(ininame,grdname,oaname,'salt','sclm_time','Z',tini,'r',1);
-  if (insitu2pot)
-    disp(' ')
-    disp(' Compute potential temperature from in-situ...')
-    getpot(ininame,grdname)
-  end
-
-end
+% %----------------------------------------------------------------------------
+% % Initial file
+% %----------------------------------------------------------------------------
+% if (makeini)
+
+%   disp('======================== ')
+%   disp('Initial')
+%   create_inifile(ininame,grdname,CROCO_title,...
+%                  theta_s,theta_b,hc,N,...
+%                  tini,'clobber',vtransform);
+%   disp(' ')
+%   disp(' Temperature...')
+%   vinterp_clm(ininame,grdname,oaname,'temp','tclm_time','Z',tini,'r',1);
+%   disp(' ')
+%   disp(' Salinity...')
+%   vinterp_clm(ininame,grdname,oaname,'salt','sclm_time','Z',tini,'r',1);
+%   if (insitu2pot)
+%     disp(' ')
+%     disp(' Compute potential temperature from in-situ...')
+%     getpot(ininame,grdname)
+%   end
+
+% end
 
 
 
diff --git a/Preprocessing_tools/nc_add_globatt.m b/Preprocessing_tools/nc_add_globatt.m
index 1b2447617544765a9dab321fa5785f9a745967ee..67d800c6d55ff65bdce588f58fff632d50f1df27 100644
--- a/Preprocessing_tools/nc_add_globatt.m
+++ b/Preprocessing_tools/nc_add_globatt.m
@@ -30,7 +30,9 @@ if nargin < 8
     product = 'unknown'
 end
 %
-origin_date = datestr(datenum(Yorig,Mmin,Dmin,Hmin,Min_min,Smin),0);
+%origin_date = datestr(datenum(Yorig,Mmin,Dmin,Hmin,Min_min,Smin),0);
+origin_date = char(datetime(Yorig,Mmin,Dmin,Hmin,Min_min,Smin, 'Format', 'yyyy-MM-dd HH:mm:ss'));
+
 %
 nc=netcdf(filename,'write');
 nc.origin_date = origin_date;
diff --git a/Preprocessing_tools/vinterp_bry.m b/Preprocessing_tools/vinterp_bry.m
index de614f7d770ae5c184ed772684f957debadd912b..3606af2244cc63f36f9e01d0d626d3de3056caa0 100644
--- a/Preprocessing_tools/vinterp_bry.m
+++ b/Preprocessing_tools/vinterp_bry.m
@@ -3,10 +3,10 @@ function vinterp_bry(bryname,grdname,Zbryname,vname,obcndx)
 %
 %  Vertical interpolation from a Z-grid to a sigma-grid in the
 %  case of boundary (bry) files.
-% 
-%  Further Information:  
+%
+%  Further Information:
 %  http://www.croco-ocean.org
-%  
+%
 %  This file is part of CROCOTOOLS
 %
 %  CROCOTOOLS is free software; you can redistribute it and/or modify
@@ -24,13 +24,13 @@ function vinterp_bry(bryname,grdname,Zbryname,vname,obcndx)
 %  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 %  MA  02111-1307  USA
 %
-%  Copyright (c) 2005-2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
+%  Copyright (c) 2005-2006 by Pierrick Penven
+%  e-mail:Pierrick.Penven@ird.fr
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-% open the grid file  
-% 
+% open the grid file
+%
 ng=netcdf(grdname,'r');
 L=length(ng('xi_rho'));
 M=length(ng('eta_rho'));
@@ -45,8 +45,8 @@ elseif obcndx==4
 end
 close(ng);
 %
-% open the boundary file  
-% 
+% open the boundary file
+%
 nc=netcdf(bryname,'write');
 theta_s = nc{'theta_s'}(:);
 theta_b =  nc{'theta_b'}(:);
@@ -54,14 +54,14 @@ hc  =  nc{'hc'}(:);
 N =  length(nc('s_rho'));
 vtransform = nc{'Vtransform'}(:);
 if ~exist('vtransform')
-    vtransform=1; %Old Vtransform
-    disp([' NO VTRANSFORM parameter found'])
-    disp([' USE VTRANSFORM default value vtransform = 1'])
+  vtransform=1; %Old Vtransform
+  disp([' NO VTRANSFORM parameter found'])
+  disp([' USE VTRANSFORM default value vtransform = 1'])
 end
 %
-% open the oa file  
-% 
-    noa=netcdf(Zbryname,'r');
+% open the oa file
+%
+noa=netcdf(Zbryname,'r');
 z=-noa{'Z'}(:);
 t=noa{'bry_time'}(:);
 tlen=length(t);
@@ -73,16 +73,16 @@ zcroco=squeeze(zlevs(h,0.*h,theta_s,theta_b,hc,N,'r',vtransform));
 zmin=min(min(zcroco));
 zmax=max(max(zcroco));
 %
-% Check if the min z level is below the min sigma level 
+% Check if the min z level is below the min sigma level
 %    (if not add a deep layer)
 %
 addsurf=max(z)<zmax;
 addbot=min(z)>zmin;
 if addsurf
- z=[100;z];
+  z=[100;z];
 end
 if addbot
- z=[z;-100000];
+  z=[z;-100000];
 end
 Nz=min(find(z<zmin));
 z=z(1:Nz);
@@ -90,10 +90,9 @@ z=z(1:Nz);
 % loop on time
 %
 for l=1:tlen
-%for l=1:1
-%  disp([' Time index: ',num2str(l),' of total: ',num2str(tlen)])
+  %for l=1:1
+  disp([' Time index: ',num2str(l),' of total: ',num2str(tlen)])
   var=squeeze(noa{vname}(l,:,:));
-%  disp(['SIZE VAR=',num2str(size(var))])
   if addsurf
     var=cat(1,var(1,:,:),var);
   end
@@ -105,27 +104,4 @@ for l=1:tlen
 end
 close(nc);
 close(noa);
-
-
-%DEBUG
-%
-%size(var)
-%var
-%
-%size(flipdim(var,1))
-%flipdim(var,1)
-%
-%size(z)
-%z
-%
-%size(flipud(z))
-%flipud(z)
-%
-%size(zcroco)
-%zcroco
-%
-%size(ztosigma_1d(flipdim(var,1),zcroco,flipud(z)))
-%
-%
-%%
 return
diff --git a/Preprocessing_tools/write_time_attributes.m b/Preprocessing_tools/write_time_attributes.m
new file mode 100644
index 0000000000000000000000000000000000000000..cdd646b754e65830e789a11f748178a8592ab819
--- /dev/null
+++ b/Preprocessing_tools/write_time_attributes.m
@@ -0,0 +1,29 @@
+function write_time_attributes(nc,time_name,cycle,...
+                                time_unit_att,...
+                                time_second_unit_att, ...
+                                calendar_att, ...
+                                insecond,...
+                                add_cycle) ;
+    %-----------------------------------------------------------------------
+    % Inputs:
+    %   time_unit_att : Time unit attribute string, 
+    %                   used by default for time units
+    %   time_second_unit_att : Time unit attribute string
+    %   calendar_att  : Calendar type attribute string
+    %   insecond : optional, switch to have time units in seconds
+    %-----------------------------------------------------------------------
+
+    nc{time_name}.calendar  = calendar_att;
+    %
+    if exist('insecond', 'var') && insecond == 1 
+        nc{time_name}.units        = time_second_unit_att;
+    else
+        nc{time_name}.units        = time_unit_att;
+    end
+    %
+    %Add cycle attribute
+    if exist('add_cycle', 'var') && add_cycle == 1 
+        nc{time_name}.cycle_length = cycle ;
+    end
+
+end
\ No newline at end of file
diff --git a/Rivers/create_runoff.m b/Rivers/create_runoff.m
index 4cedbe46dcf854e30c3daaeae52857f25fe029c8..878a083be710b1e3fcf3fe497311d6b15626ecae 100644
--- a/Rivers/create_runoff.m
+++ b/Rivers/create_runoff.m
@@ -1,6 +1,7 @@
 function  create_runoff(runoffname,grdname,title,...
     qbart,qbarc,rivername,rivernumber,...
-    runoffname_StrLen,dir,psource_ncfile_ts,biol,pisces,quota)
+    runoffname_StrLen,dir,psource_ncfile_ts,...
+    biol,pisces,quota, Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 % 	Create an empty netcdf runoff file
@@ -27,14 +28,25 @@ function  create_runoff(runoffname,grdname,title,...
 %  MA  02111-1307  USA
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+timeref = 1 ;
+if nargin < 14
+  disp([' Yorig parameter found'])
+  disp([' No time reference'])
+  timeref = 0 ;
+end
+if timeref == 1
+  time_unit_att = ['days since ',sprintf('%04d', Yorig),'-01-01 00:00:00'];
+  calendar_att = 'proleptic_gregorian' ;
+else
+  time_unit_att = ['days'];
+  calendar_att = 'climatological year' ;
+end
+%
 nw=netcdf(runoffname,'clobber');
 %%%result = redef(nw);
-
-
 %
 %  Create dimensions
 %
-
 nw('qbar_time') = length(qbart);
 nw('n_qbar') = rivernumber;
 nw('runoffname_StrLen') = runoffname_StrLen;
@@ -45,18 +57,21 @@ nw('two') = 2;
 %
 nw{'qbar_time'} = ncdouble('qbar_time');
 nw{'qbar_time'}.long_name = ncchar('runoff time');
-nw{'qbar_time'}.units = ncchar('days');
+nw{'qbar_time'}.units = ncchar(time_unit_att);
+nw{'qbar_time'}.calendar = calendar_att;
 nw{'qbar_time'}.cycle_length = qbarc;
 
 if psource_ncfile_ts
     nw{'temp_src_time'} = ncdouble('qbar_time');
     nw{'temp_src_time'}.long_name = ncchar('runoff time');
-    nw{'temp_src_time'}.units = ncchar('days');
+    nw{'temp_src_time'}.units = ncchar(time_unit_att);
+    nw{'temp_src_time'}.calendar = calendar_att;
     nw{'temp_src_time'}.cycle_length = qbarc;
     
     nw{'salt_src_time'} = ncdouble('qbar_time');
     nw{'salt_src_time'}.long_name = ncchar('runoff time');
-    nw{'salt_src_time'}.units = ncchar('days');
+    nw{'salt_src_time'}.units = ncchar(time_unit_att);
+    nw{'salt_src_time'}.calendar = calendar_att;
     nw{'salt_src_time'}.cycle_length = qbarc;
 end
 nw{'runoff_name'} = ncchar('n_qbar','runoffname_StrLen');
@@ -86,7 +101,8 @@ if psource_ncfile_ts
     if biol
         nw{'no3_src_time'} = ncdouble('qbar_time');
         nw{'no3_src_time'}.long_name = ncchar('runoff time');
-        nw{'no3_src_time'}.units = ncchar('days');
+        nw{'no3_src_time'}.units = ncchar(time_unit_att);
+        nw{'no3_src_time'}.calendar = calendar_att;
         nw{'no3_src_time'}.cycle_length = 360;
         
         nw{'NO3_src'} = ncdouble('n_qbar','qbar_time');
@@ -95,7 +111,8 @@ if psource_ncfile_ts
         if pisces
            nw{'po4_src_time'} = ncdouble('qbar_time');
            nw{'po4_src_time'}.long_name = ncchar('runoff time');
-           nw{'po4_src_time'}.units = ncchar('days');
+           nw{'po4_src_time'}.units = ncchar(time_unit_att);
+           nw{'po4_src_time'}.calendar = calendar_att;
            nw{'po4_src_time'}.cycle_length = 360;
 
            nw{'PO4_src'} = ncdouble('n_qbar','qbar_time');
@@ -104,7 +121,8 @@ if psource_ncfile_ts
 
            nw{'si_src_time'} = ncdouble('qbar_time');
            nw{'si_src_time'}.long_name = ncchar('runoff time');
-           nw{'si_src_time'}.units = ncchar('days');
+           nw{'si_src_time'}.units = ncchar(time_unit_att);
+           nw{'si_src_time'}.calendar = calendar_att;
            nw{'si_src_time'}.cycle_length = 360;
 
            nw{'Si_src'} = ncdouble('n_qbar','qbar_time');
@@ -113,7 +131,8 @@ if psource_ncfile_ts
 
            nw{'dic_src_time'} = ncdouble('qbar_time');
            nw{'dic_src_time'}.long_name = ncchar('runoff time');
-           nw{'dic_src_time'}.units = ncchar('days');
+           nw{'dic_src_time'}.units = ncchar(time_unit_att);
+           nw{'dic_src_time'}.calendar = calendar_att;
            nw{'dic_src_time'}.cycle_length = 360;
 
            nw{'DIC_src'} = ncdouble('n_qbar','qbar_time');
@@ -122,7 +141,8 @@ if psource_ncfile_ts
 
            nw{'doc_src_time'} = ncdouble('qbar_time');
            nw{'doc_src_time'}.long_name = ncchar('runoff time');
-           nw{'doc_src_time'}.units = ncchar('days');
+           nw{'doc_src_time'}.units = ncchar(time_unit_att);
+           nw{'doc_src_time'}.calendar = calendar_att;
            nw{'doc_src_time'}.cycle_length = 360;
 
            nw{'DOC_src'} = ncdouble('n_qbar','qbar_time');
@@ -131,7 +151,8 @@ if psource_ncfile_ts
 
            nw{'talk_src_time'} = ncdouble('qbar_time');
            nw{'talk_src_time'}.long_name = ncchar('runoff time');
-           nw{'talk_src_time'}.units = ncchar('days');
+           nw{'talk_src_time'}.units = ncchar(time_unit_att);
+           nw{'talk_src_time'}.calendar = calendar_att;
            nw{'talk_src_time'}.cycle_length = 360;
 
            nw{'TALK_src'} = ncdouble('n_qbar','qbar_time');
@@ -140,7 +161,8 @@ if psource_ncfile_ts
            if quota
               nw{'don_src_time'} = ncdouble('qbar_time');
               nw{'don_src_time'}.long_name = ncchar('runoff time');
-              nw{'don_src_time'}.units = ncchar('days');
+              nw{'don_src_time'}.units = ncchar(time_unit_att);
+              nw{'don_src_time'}.calendar = calendar_att;
               nw{'don_src_time'}.cycle_length = 360;
 
               nw{'DON_src'} = ncdouble('n_qbar','qbar_time');
@@ -149,7 +171,8 @@ if psource_ncfile_ts
             
               nw{'dop_src_time'} = ncdouble('qbar_time');
               nw{'dop_src_time'}.long_name = ncchar('runoff time');
-              nw{'dop_src_time'}.units = ncchar('days');
+              nw{'dop_src_time'}.units = ncchar(time_unit_att);
+              nw{'dop_src_time'}.calendar = calendar_att;
               nw{'dop_src_time'}.cycle_length = 360;
 
               nw{'DOP_src'} = ncdouble('n_qbar','qbar_time');
diff --git a/Rivers/make_runoff.m b/Rivers/make_runoff.m
index edef1e76f59041576962d1cb7a9186c92ded7894..226b185ecd87dd74adc4688863489404269b821b 100644
--- a/Rivers/make_runoff.m
+++ b/Rivers/make_runoff.m
@@ -104,7 +104,7 @@ plotting_zoom=0;
 %
 %=========================================================================================
 % Add biogeochemical variables 
-if (makenpzd | makepisces | makebioebus | makequota)     makebio = 1;
+if (makenpzd | makepisces | makebioebus | makequota) makebio = 1;
 else     
     makebio = 0;
 end
@@ -390,7 +390,9 @@ else
     disp(' Create the runoff file...')
     create_runoff(rivname,grdname,title_name,...
                   qbar_time,qbar_cycle, ...
-                  rivername,number_rivertoprocess,rivname_StrLen,dir,psource_ncfile_ts,makebio,makepisces,makequota)
+                  rivername,number_rivertoprocess,...
+                  rivname_StrLen,dir,psource_ncfile_ts,...
+                  makebio,makepisces,makequota)
     %%
     %% Adjust the rivers positions relative to the mask
     %%
diff --git a/crocotools_param.m b/crocotools_param.m
index 8b310ce1396cce28d18bf8d520efe0a23096ba96..e1a593e83bfa8485a3895f55127288499411dccf 100644
--- a/crocotools_param.m
+++ b/crocotools_param.m
@@ -490,6 +490,9 @@ end
 rmdepth     = 2;
 %
 % Overlap parameters : nb of records around each sequence
+% => for SODA put itolap_a = itolap_p = 1
+% => for mercator daily put itolap_a = itolap_p = 2 
+%         (due to date of the month first day of month)
 %
 itolap_a    = 1;   % before
 itolap_p    = 1;   % after
diff --git a/oct_start.m b/oct_start.m
index d16ae96dfe7fee495bde2aacc9dc14103d6d6fb7..5fb8b9ed7dba2475c9fb99327f5ab4111e332280 100644
--- a/oct_start.m
+++ b/oct_start.m
@@ -59,6 +59,7 @@ addpath([tools_path,'Forecast_tools'])
 addpath([tools_path,'Nesting_tools'])
 addpath([tools_path,'Preprocessing_tools'])
 addpath([tools_path,'Preprocessing_tools/Bio'])
+addpath([tools_path,'Preprocessing_tools/Bio/npzd-bioebus'])
 addpath([tools_path,'Oforc_OGCM'])
 addpath([tools_path,'Tides'])
 addpath([tools_path,'Tides/T_TIDE'])
diff --git a/start.m b/start.m
index 525096190278e93fb908f3a95ef5a0ed6eb57e0a..df81a16aa1e22a2190e9dab45cc8db3e218913e1 100644
--- a/start.m
+++ b/start.m
@@ -55,6 +55,7 @@ addpath([tools_path,'Forecast_tools'])
 addpath([tools_path,'Nesting_tools'])
 addpath([tools_path,'Preprocessing_tools'])
 addpath([tools_path,'Preprocessing_tools/Bio'])
+addpath([tools_path,'Preprocessing_tools/Bio/npzd-bioebus'])
 addpath([tools_path,'Oforc_OGCM'])
 addpath([tools_path,'Tides'])
 addpath([tools_path,'Tides/T_TIDE'])