From 26798499f6e724a1dfce58d7c2cc6ef6b81356a8 Mon Sep 17 00:00:00 2001
From: Gildas Cambon <gildas.cambon@ird.fr>
Date: Tue, 19 Mar 2024 17:53:18 +0100
Subject: [PATCH] Squashed commit of the following:

commit a861c34ba628960b28e3a1abf6b85de0490a0348
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Tue Mar 19 17:11:51 2024 +0100

    Refactorisation : use of write_mercator_multi.m
    instead of write_mercator_frcst.m

commit 747149f7e7d7b5e4bd915131ea68befede046f0d
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Tue Mar 19 15:18:50 2024 +0100

    Cleaning

commit 0dc67715d969213a2de3e622a58bdc896bf51337
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Tue Mar 19 14:29:18 2024 +0100

    Update in download_mercator_frcst_python

commit f5c9aaddbe16247974cfb86e6e77f6b157da8e6f
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Mon Mar 18 14:33:52 2024 +0100

    Cleaning in make_OGCM_frcst
        - Rename make_OGCM_frcst.m  in make_OGCM_mercator_frcst.m
        - some simplifications

commit 90a6ebc1eed360a8bfc2a6c113d5cf7b875d0c75
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Mon Mar 18 14:20:30 2024 +0100

    Remove ECCO product from Forecast_tools

commit 5040ce6c0d8704afbd0121f9efd8e56cf234dee2
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Mon Mar 18 14:17:33 2024 +0100

    Remove original file "raw_mercator_name" after download

commit a1fae6b97390dcb8d50e16748e6e7a5e69313eed
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Mon Mar 18 14:11:52 2024 +0100

    Remove downloading of taux/tauy in extract_SODA

commit 76fc422ba040321ff42400ddcfe12fc58197f9eb
Author: Gildas Cambon <gildas.cambon@ird.fr>
Date:   Mon Mar 18 14:04:31 2024 +0100

    In Preprocessing_tools, during geostrophic calculation,
    add the Ekman transport only of forcing file (containing wind strss) exists
---
 Forecast_tools/download_ECCO_frcst.m          | 173 ------------------
 .../download_mercator_frcst_python.m          |  19 +-
 Forecast_tools/extract_ECCO_frcst.m           | 115 ------------
 ...GCM_frcst.m => make_OGCM_mercator_frcst.m} | 146 +++++++--------
 Forecast_tools/write_mercator_frcst.m         | 139 --------------
 Oforc_OGCM/download_mercator_python.m         |   4 +-
 Oforc_OGCM/extract_SODA.m                     |  58 +++---
 Oforc_OGCM/write_mercator.m                   |   6 +-
 Oforc_OGCM/write_mercator_multi.m             |  27 ++-
 Preprocessing_tools/geost_currents.m          |   4 +-
 Preprocessing_tools/geost_currents_bry.m      |   4 +-
 11 files changed, 143 insertions(+), 552 deletions(-)
 delete mode 100644 Forecast_tools/download_ECCO_frcst.m
 delete mode 100644 Forecast_tools/extract_ECCO_frcst.m
 rename Forecast_tools/{make_OGCM_frcst.m => make_OGCM_mercator_frcst.m} (66%)
 delete mode 100644 Forecast_tools/write_mercator_frcst.m

diff --git a/Forecast_tools/download_ECCO_frcst.m b/Forecast_tools/download_ECCO_frcst.m
deleted file mode 100644
index c0f3703c..00000000
--- a/Forecast_tools/download_ECCO_frcst.m
+++ /dev/null
@@ -1,173 +0,0 @@
-function ecco_name=download_ECCO_frcst(lonmin,lonmax,latmin,latmax,...
-                                         FRCST_dir,FRCST_prefix,url,Yorig)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  Extract a subgrid from ECCO to get a CROCO forcing
-%   Store that into monthly files.
-%   Take care of the Greenwitch Meridian.
-% 
-% 
-%  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) 2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
-%
-%  Updated    8-Sep-2006 by Pierrick Penven
-%  Updated    20-Aug-2008 by Matthieu Caillaud & P. Marchesiello
-%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-%
-% Get the date
-%
-rundate_str=date;
-rundate=datenum(rundate_str)-datenum(Yorig,1,1);
-[y,m,d,h,mi,s]=datevec(rundate_str);
-%
-% start
-%
-disp([' '])
-disp(['Get data for ',rundate_str])
-disp(['Minimum Longitude: ',num2str(lonmin)])
-disp(['Maximum Longitude: ',num2str(lonmax)])
-disp(['Minimum Latitude: ',num2str(latmin)])
-disp(['Maximum Latitude: ',num2str(latmax)])
-disp([' '])
-%
-% Create the directory
-%
-disp(['Making output data directory ',FRCST_dir])
-eval(['!mkdir ',FRCST_dir])
-%
-% Start 
-%
-disp(['Process the dataset: ',url])
-%
-% Get the latest ECCO time
-%
-%
-% first ecco time: 06-Jan-2006 (315696)
-% first ecco time: 07-Jan-2006 (324456) !!! should be reset every year !!!
-ecco_time_start_year=359520;
-
-%
-ecco_time_start=ecco_time_start_year/24+datenum(1970,1,1)-datenum(Yorig,1,1);
-ecco_times=[ecco_time_start:10:ecco_time_start+10000];
-%htime_ecco=24*(ecco_times+datenum(Yorig,1,1)-datenum(1970,1,1));
-%
-% Get the closest ecco time
-%
-ecco_indx=max(find(ecco_times<=rundate));
-foundfile=0;
-%
-while foundfile==0
-  ecco_time=ecco_times(ecco_indx);
-  disp([' Testing date: ' datestr(ecco_time+datenum(Yorig,1,1))])
-  [ecco_y,ecco_m,ecco_d,ecco_h,ecco_mi,ecco_s]=...
-  datevec(ecco_time+datenum(Yorig,1,1));
-  daysinyear=ecco_time+datenum(Yorig,1,1)-datenum(ecco_y,1,1);
-  necco=round(daysinyear/10);
-  nhours=necco*240;
-  if nhours < 1000
-    endname=['_00',num2str(nhours),'_240.cdf'];
-  elseif nhours < 10000
-    endname=['_0',num2str(nhours),'_240.cdf'];
-  else nhours < 10000
-    endname=['_',num2str(nhours),'_240.cdf'];
-  end
-%  
-  if necco <= 9
-    prefix=[url,num2str(ecco_y),'/n10day_01_0',num2str(necco),'/'];
-    suffix=['_08_08.00001',endname];
-  elseif necco <= 18
-    prefix=[url,num2str(ecco_y),'/n10day_10_',num2str(necco),'/'];
-    suffix=['_08_08.02160',endname];
-  elseif necco <= 27
-    prefix=[url,num2str(ecco_y),'/n10day_19_',num2str(necco),'/'];
-    suffix=['_08_08.04320',endname];
-  elseif necco <= 37
-    prefix=[url,num2str(ecco_y),'/n10day_28_',num2str(necco),'/'];
-    suffix=['_08_08.06480',endname];
-  end
-%
-%  test if the file exist
-%
-  vname='Have';
-  fname=[prefix,vname,suffix];
-  warning off
-  try
-    x=loaddap('-A -e +v ',fname);
-    foundfile=1;
-  catch
-    foundfile=0;
-  end
-  if foundfile==1 & ~isempty(x)
-    disp('  File found')
-  else
-    foundfile=0;
-    disp('  File does not exist')
-    ecco_indx=ecco_indx-1;
-    if ecco_indx==0
-     error('DOWNLOAD_ECCO_FRCST: No file found...')
-    end
-  end
-  warning on
-end
-%
-tindex=x.time.DODS_ML_Size;
-missval=x.Have.missing_value;
-%
-% Get the time
-%
-vname='Have';
-fname=[prefix,'Have',suffix];
-trange=['[',num2str(tindex-1),':',num2str(tindex-1),']'];
-time=readdap(fname,'time',trange);
-time=floor(time/24+datenum(1970,1,1));
-disp(['    Date: ',datestr(time)])
-time=time-datenum(Yorig,1,1);
-ecco_name=[FRCST_dir,FRCST_prefix,num2str(time),'.cdf'];
-%
-%if isempty(dir(ecco_name))
-if ~exist(ecco_name)
-%
-%
-% Get a subset of the ECCO grid
-%
-  vname='Have';
-  fname=[prefix,vname,suffix];
-  [i1min,i1max,i2min,i2max,i3min,i3max,...
-   i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u,...
-   jrange,jrange_v,krange,lon,lon_u,lat,lat_v,depth]=...
-   get_ECCO_subgrid(fname,lonmin,lonmax,latmin,latmax);
-%
-% Extract ECCO
-%
-  extract_ECCO_frcst(FRCST_dir,FRCST_prefix,prefix,suffix,tindex,missval,...
-                      lon,lon_u,lat,lat_v,depth,...
-                      krange,jrange,jrange_v,...
-                      i1min,i1max,i2min,i2max,i3min,i3max,...
-                      i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u,...
-                      time,Yorig)
-else
-  disp('  ECCO file already exists')
-end
-return
diff --git a/Forecast_tools/download_mercator_frcst_python.m b/Forecast_tools/download_mercator_frcst_python.m
index aa11005d..0b0257a8 100644
--- a/Forecast_tools/download_mercator_frcst_python.m
+++ b/Forecast_tools/download_mercator_frcst_python.m
@@ -2,7 +2,7 @@ function download_mercator_frcst_python(pathCMC,user,password,mercator_type, ...
                                         raw_mercator_name,product_id, ...
                                         lh,lf, ...
                                         lonmin,lonmax,latmin,latmax,zmax, ...
-                                        FRCST_dir,FRCST_prefix,mercator_name,Yorig)
+                                        FRCST_dir,FRCST_prefix,date_frcst,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % Extract a subgrid from mercator to get a CROCO forcing
 % Store that into monthly files.
@@ -148,12 +148,17 @@ if convert_raw2crocotools
     % Convert data format and write in a more CROCOTOOLS 
     % compatible input file 
     %
-    if exist(mercator_name)  
-        disp('Mercator file already exist => overwrite it')
-    end
-    write_mercator_frcst(FRCST_dir,FRCST_prefix,raw_mercator_name, ...
-                         mercator_type,mercator_name,vars,time,Yorig); % write data
- %   eval(['! rm -f ',[raw_mercator_name(1:end-3),'*nc '] ]);
+%     if exist(mercator_name)  
+%         disp('Mercator file already exist => overwrite it')
+%     end
+%     write_mercator_frcst(FRCST_dir,FRCST_prefix,raw_mercator_name, ...
+%                          mercator_type,mercator_name,vars,time,Yorig); % write data
+%  %   eval(['! rm -f ',[raw_mercator_name(1:end-3),'*nc '] ]);
+
+    write_mercator_multi(FRCST_dir,FRCST_prefix,raw_mercator_name,...
+                        mercator_type,vars,time,date_frcst,Yorig)
+     %   eval(['! rm -f ',[raw_mercator_name(1:end-3),'*nc '] ]);                    
+
 end
 
 end
diff --git a/Forecast_tools/extract_ECCO_frcst.m b/Forecast_tools/extract_ECCO_frcst.m
deleted file mode 100644
index 10ad8ffb..00000000
--- a/Forecast_tools/extract_ECCO_frcst.m
+++ /dev/null
@@ -1,115 +0,0 @@
-function extract_ECCO_frcst(FRCST_dir,FRCST_prefix,prefix,suffix,tindex,missval,...
-                      lon,lon_u,lat,lat_v,depth,...
-                      krange,jrange,jrange_v,...
-                      i1min,i1max,i2min,i2max,i3min,i3max,...
-                      i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u,...
-                      time,Yorig)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% Extract a subset from ECCO using DODS
-% Write it in a local file (keeping the classic
-% SODA netcdf format)
-% 
-% 
-%  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) 2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
-%
-%  Updated    9-Sep-2006 by Pierrick Penven
-%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-disp(['    Download ECCO'])
-trange=['[',num2str(tindex-1),':',num2str(tindex-1),']'];
-%
-% Get the time
-%
-%vname='Have';
-%fname=[prefix,vname,suffix];
-%time=readdap(fname,'time',trange)
-%time=floor(time/24+datenum(1970,1,1));
-%disp(['    Date: ',datestr(time)])
-%time=time-datenum(Yorig,1,1)
-%
-% Get SSH
-%
-disp('    ...SSH')
-vname='Have';
-fname=[vname,suffix];
-ssh=getdap(prefix,fname,vname,...
-            trange,'',jrange,...
-            i1min,i1max,i2min,i2max,i3min,i3max);
-ssh=shiftdim(ssh,2);
-ssh(ssh<=missval)=NaN;
-%
-% Get U
-%
-disp('    ...U')
-vname='Uave';
-fname=[vname,suffix];
-u=getdap(prefix,fname,vname,...
-          trange,krange,jrange,...
-          i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u);
-u=permute(u,[4 3 1 2]);
-u(u<=missval)=NaN;
-%
-% Get V
-%
-disp('    ...V')
-vname='Vave';
-fname=[vname,suffix];
-v=getdap(prefix,fname,vname,...
-          trange,krange,jrange_v,...
-          i1min,i1max,i2min,i2max,i3min,i3max);
-v=permute(v,[4 3 1 2]);
-v(v<=missval)=NaN;
-%
-% Get TEMP
-%
-disp('    ...TEMP')
-vname='Tave';
-fname=[vname,suffix];
-temp=getdap(prefix,fname,vname,...
-             trange,krange,jrange,...
-             i1min,i1max,i2min,i2max,i3min,i3max);
-temp=permute(temp,[4 3 1 2]);
-temp(temp<=missval)=NaN;
-%
-% Get SALT
-%
-disp('    ...SALT')
-vname='Save';
-fname=[vname,suffix];
-salt=getdap(prefix,fname,vname,...
-             trange,krange,jrange,...
-             i1min,i1max,i2min,i2max,i3min,i3max);
-salt=permute(salt,[4 3 1 2]);
-salt(salt<=missval)=NaN;
-%
-% Create the ECCO file
-%
-create_OGCM([FRCST_dir,FRCST_prefix,num2str(time),'.cdf'],...
-             lon,lat,lon_u,lat,lon,lat_v,depth,time,...
-             squeeze(temp),squeeze(salt),squeeze(u),...
-             squeeze(v),squeeze(ssh),Yorig)
-%
-return
diff --git a/Forecast_tools/make_OGCM_frcst.m b/Forecast_tools/make_OGCM_mercator_frcst.m
similarity index 66%
rename from Forecast_tools/make_OGCM_frcst.m
rename to Forecast_tools/make_OGCM_mercator_frcst.m
index e6400335..bf2d2ec0 100644
--- a/Forecast_tools/make_OGCM_frcst.m
+++ b/Forecast_tools/make_OGCM_mercator_frcst.m
@@ -1,7 +1,7 @@
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-% Create and fill CROCO clim and bry files with OGCM data.
-% for a forecast run
+% Create and fill CROCO clim and bry files with OGCM data 
+% from mercator for a forecast run
 %
 %
 %  Further Information:
@@ -31,7 +31,7 @@
 %  Updated   20-Aug-2008 by Matthieu Caillaud & P. Marchesiello
 %  Updated   12-Feb-2016 by P. Marchesiello
 %  Updated   14-Oct-2020 by P. Marchesiello
-%
+%  Updated   18-Mar-2024 by G. Cambon
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 clear all
 close all
@@ -52,32 +52,33 @@ rundate_str=date;
 date_run=datenum(rundate_str);
 rundate=date_run-datenum(Yorig,1,1);
 rundate0=rundate;
-if strcmp(OGCM,'mercator')
-  for i=1:hdays+1
-    time1(i)=date_run-(hdays+1-i);
-  end
-  date_deb=datestr(time1(1+hdays),'yyyy-mm-ddT00:00:00Z');
-  if hdays ~= 0
-   % date_deb = rundate - hindcast days : example 2024-02-28T00:00:00Z-PT1D
-   % for a validity date 1 day before run 20240228 00hUTC ...
-   date_deb=strcat(datestr(time1(1+hdays),'yyyy-mm-ddT00:00:00') ,['-PT',num2str(hdays),'D']);
-  end
+%OGCM=mercator
+for i=1:hdays+1
+  time1(i)=date_run-(hdays+1-i);
+end
+rundate=datestr(time1(1+hdays),'yyyy-mm-ddT00:00:00Z');
+if hdays ~= 0
+  % date_deb = rundate - hindcast days : example 2024-02-28T00:00:00Z-PT2D
+  % for a validity date 2 days before run 20240228 00hUTC ...
+  date_deb=strcat(datestr(time1(1+hdays),'yyyy-mm-ddT00:00:00') ,['-PT',num2str(hdays),'D']);
+else
+  date_deb=rundate;
 end
 %
 % Set generic OGCM file name
 %
-FRCST_prefix=[OGCM,'_'];
-OGCM_name=[FRCST_dir,FRCST_prefix,num2str(date_deb),'.cdf'];
+%OGCM='mercator';
+FRCST_prefix=['mercator_'];
+OGCM_name=[FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'];
 %
-if strcmp(OGCM,'mercator')
-  %
-  %  MERCATOR : see get_file_python_mercator.m
-  %
-  raw_mercator_name=[FRCST_dir,'raw_mercator_',num2str(date_deb),'.nc'];
-  mercator_name=[FRCST_dir,FRCST_prefix,num2str(date_deb),'.cdf'];
-else
-  error(['Unknown OGCM for forecast: ',OGCM])
-end
+%
+%  MERCATOR : see get_file_python_mercator.m
+%
+raw_mercator_name=[FRCST_dir,'raw_mercator_',num2str(rundate),'.nc'];
+%mercator_name=[FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'];
+%mercator_name;
+date_frcst=rundate;
+
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 % end of user input  parameters
@@ -105,33 +106,28 @@ close(nc)
 % Extract data from the Internet
 %---------------------------------------------------------------
 if Download_data
- %
- % Get model limits
- %
- lonmin=min(min(lon)); 
- lonmax=max(max(lon));
- latmin=min(min(lat));
- latmax=max(max(lat));
- %
- % Download data (matlab routine for download depends on OGCM)
- %
- if strcmp(OGCM,'mercator')
+  %
+  % Get model limits
+  %
+  lonmin=min(min(lon)); 
+  lonmax=max(max(lon));
+  latmin=min(min(lat));
+  latmax=max(max(lat));
+  %
+  % Download data (matlab routine for download depends on OGCM)
+  %
   %
   % Use of Copernicusmarine client (python)
   %  -> script download_mercator_frcst_python.m
   %
   disp('Download data...')
-  eval(['download_', ...
-          OGCM,'_frcst_python(pathCMC,user,password,mercator_type,', ...
-                              'raw_mercator_name,product_id,', ...
-                              'hdays,fdays,', ...
-                              'lonmin,lonmax,latmin,latmax,hmax,', ...
-                              'FRCST_dir,FRCST_prefix,mercator_name,Yorig);'])
-
-  else
-    error(['Unknown OGCM for forecast: ',OGCM])
-  end
+  download_mercator_frcst_python(pathCMC,user,password,mercator_type, ...
+                                 raw_mercator_name,product_id, ...
+                                 hdays,fdays, ...
+                                 lonmin,lonmax,latmin,latmax,hmax, ...
+                                 FRCST_dir,FRCST_prefix,date_frcst,Yorig);
 end
+
 %---------------------------------------------------------------
 % Get OGCM grid 
 %---------------------------------------------------------------
@@ -149,17 +145,13 @@ Z=Z(1:NZ);
 %---------------------------------------------------------------
 % Get time array 
 %---------------------------------------------------------------
-if strcmp(OGCM,'mercator')
-  OGCM_time=nc{'time'}(:);
-  time_cycle=0;
-  delta=1; % >1 if subsampling
-  trange=[1:delta:length(OGCM_time)];
-  time=zeros(length(trange),1);
-  for i=1:length(trange)
-    time(i)=OGCM_time(trange(i));
-  end
-else
-  error(['Unknown OGCM for forecast: ',OGCM])
+OGCM_time=nc{'time'}(:);
+time_cycle=0;
+delta=1; % >1 if subsampling
+trange=[1:delta:length(OGCM_time)];
+time=zeros(length(trange),1);
+for i=1:length(trange)
+  time(i)=OGCM_time(trange(i));
 end
 close(nc)
 %---------------------------------------------------------------
@@ -167,7 +159,7 @@ close(nc)
 %---------------------------------------------------------------
 if makeini==1
   %
-  ininame=[ini_prefix,num2str(rundate),nc_suffix];
+  ininame=[ini_prefix,num2str(date_deb),nc_suffix];
   disp(['-> Create an initial file for date ',num2str(date_deb);])
   create_inifile(ininame,grdname,CROCO_title,...
                  theta_s,theta_b,hc,N,...
@@ -180,11 +172,11 @@ if makeini==1
               1,vtransform,obc)
   close(nc_ini)
   if hdays ~= 0
-   if (isoctave == 0)
-      eval(['!cp ',ininame,' ',ini_prefix,'hct_',num2str(rundate),nc_suffix])
-   else
-      eval(['cp ',ininame,' ',ini_prefix,'hct_',num2str(rundate),nc_suffix])
-   end
+    if (isoctave == 0)
+      eval(['!cp ',ininame,' ',ini_prefix,'hct_',num2str(date_deb),nc_suffix])
+    else
+      eval(['cp ',ininame,' ',ini_prefix,'hct_',num2str(date_deb),nc_suffix])
+    end
   end 
 end
 %---------------------------------------------------------------
@@ -192,10 +184,10 @@ end
 %---------------------------------------------------------------
 if makeclim==1 | makebry==1
   if makebry==1
-    bryname=[bry_prefix,num2str(rundate),nc_suffix];
-	disp([' '])
+    bryname=[bry_prefix,num2str(date_deb),nc_suffix];
+    disp([' '])
     disp(['-> Create bry files from ',num2str(date_deb);])
-	create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
+    create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
                    theta_s,theta_b,hc,N,...
                    time,time_cycle,'clobber',vtransform);
     nc_bry=netcdf(bryname,'write');
@@ -203,9 +195,9 @@ if makeclim==1 | makebry==1
     nc_bry=[];
   end
   if makeclim==1
-    clmname=[clm_prefix,num2str(rundate),nc_suffix];
+    clmname=[clm_prefix,num2str(date_deb),nc_suffix];
     disp(['-> Create clim files from ',num2str(date_deb);])
-	create_climfile(clmname,grdname,CROCO_title,...
+    create_climfile(clmname,grdname,CROCO_title,...
                     theta_s,theta_b,hc,N,...
                     time,time_cycle,'clobber',vtransform);
     nc_clm=netcdf(clmname,'write');
@@ -215,13 +207,13 @@ if makeclim==1 | makebry==1
 %---------------------------------------------------------------
 % Perform interpolations for all selected records
 %---------------------------------------------------------------
-for tndx=1:length(time)
-  disp([' Time step : ',num2str(tndx),' of ',num2str(length(time)),' :'])
-  interp_OGCM_frcst(OGCM_name,Roa,interp_method,...
-                    lonU,latU,lonV,latV,lonT,latT,Z,trange(tndx),...
-		            nc_clm,nc_bry,lon,lat,angle,h,pm,pn,rmask, ...
-                    tndx,vtransform,obc)
-end
+  for tndx=1:length(time)
+    disp([' Time step : ',num2str(tndx),' of ',num2str(length(time)),' :'])
+    interp_OGCM_frcst(OGCM_name,Roa,interp_method,...
+                      lonU,latU,lonV,latV,lonT,latT,Z,trange(tndx),...
+                      nc_clm,nc_bry,lon,lat,angle,h,pm,pn,rmask, ...
+                      tndx,vtransform,obc)
+  end
 %
 % Close CROCO files
 %
@@ -240,21 +232,21 @@ if makeplot==1
   disp(' ')
   disp(' Make a few plots...')
   if makeini==1
-    ininame=[ini_prefix,num2str(rundate),nc_suffix];
+    ininame=[ini_prefix,num2str(date_deb),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,num2str(rundate),nc_suffix];
+    clmname=[clm_prefix,num2str(date_deb),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,num2str(rundate),nc_suffix];
+    bryname=[bry_prefix,num2str(date_deb),nc_suffix];
     figure
     test_bry(bryname,grdname,'temp',1,obc)
     figure
diff --git a/Forecast_tools/write_mercator_frcst.m b/Forecast_tools/write_mercator_frcst.m
deleted file mode 100644
index 4dc455dd..00000000
--- a/Forecast_tools/write_mercator_frcst.m
+++ /dev/null
@@ -1,139 +0,0 @@
-function write_mercator_frcst(FRCST_dir,FRCST_prefix,raw_mercator_name,...
-                              mercator_type, mercator_name,vars,time,Yorig)
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% Extract a subset from Mercator using python  copernicusmarine client
-% Write it in a local file (keeping the classic SODA netcdf format)
-% 
-%  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) 2006 by Pierrick Penven 
-%  e-mail:Pierrick.Penven@ird.fr  
-%
-%  Updated    9-Sep-2006 by Pierrick Penven
-%  Updated    19-May-2011 by Andres Sepulveda & Gildas Cambon
-%  Updated    12-Feb-2016 by P. Marchesiello
-%  Updated    06-May-2023 by Efrain Rodriguez-Rubio & P. Marchesiello
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-disp([' '])
-disp(['    Writing MERCATOR file'])
-%
-fname_z=[raw_mercator_name(1:end-3),'_z.nc'];
-fname_u=[raw_mercator_name(1:end-3),'_u.nc'];
-fname_t=[raw_mercator_name(1:end-3),'_t.nc'];
-fname_s=[raw_mercator_name(1:end-3),'_s.nc'];
-%
-% Get grid and time frame
-%
-nc = netcdf(fname_t,'r');
-lon = nc{'longitude'}(:);
-lat = nc{'latitude'}(:);
-time = nc{'time'}(:);
-depth = nc{'depth'}(:);
-if mercator_type ~= 5
-  time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
-else
-  time = time / 24 + datenum(1900,1,1) - datenum(Yorig,1,1);
-end
-close(nc)
-%
-% Get SSH
-%
-disp('    ...SSH')
-nc = netcdf(fname_z,'r');
-vname=sprintf('%s',vars{1});
-ncc=nc{vname};
-ssh=ncc(:);
-missval=ncc.FillValue_(:);
-scale_factor=1; %ncc.scale_factor(:);
-add_offset=0.;  %ncc.add_offset(:);
-ssh(ssh>=missval)=NaN;
-ssh = ssh.*scale_factor + add_offset;
-close(nc)
-%
-% Get U
-%
-disp('    ...U')
-nc = netcdf(fname_u,'r');
-vname=sprintf('%s',vars{2});
-ncc=nc{vname};
-u=ncc(:);
-missval=ncc.FillValue_(:);
-scale_factor=1; %ncc.scale_factor(:);
-add_offset=0.;  %ncc.add_offset(:);
-u(u>=missval)=NaN;
-u = u.*scale_factor + add_offset;
-close(nc)
-%
-% Get V
-%
-disp('    ...V')
-nc = netcdf(fname_u,'r');
-vname=sprintf('%s',vars{3});
-ncc=nc{vname};
-v=ncc(:);
-missval=ncc.FillValue_(:);
-scale_factor=1; %ncc.scale_factor(:);
-add_offset=0.;  %ncc.add_offset(:);
-v(v>=missval)=NaN;
-v = v.*scale_factor + add_offset;
-close(nc)
-%
-% Get TEMP
-%
-disp('    ...TEMP')
-nc = netcdf(fname_t,'r');
-vname=sprintf('%s',vars{4});
-ncc=nc{vname};
-temp=ncc(:);
-missval=ncc.FillValue_(:);
-scale_factor=1; %ncc.scale_factor(:);
-add_offset=0.;  %ncc.add_offset(:);
-temp(temp>=missval)=NaN;
-temp = temp.*scale_factor + add_offset;
-close(nc)
-%
-% Get SALT
-%
-disp('    ...SALT')
-nc = netcdf(fname_s,'r');
-vname=sprintf('%s',vars{5});
-ncc=nc{vname};
-salt=ncc(:);
-missval=ncc.FillValue_(:);
-scale_factor=1; %ncc.scale_factor(:);
-add_offset=0.;  %ncc.add_offset(:);
-salt(salt>=missval)=NaN;
-salt = salt.*scale_factor + add_offset;
-close(nc)
-%
-% Create the Mercator file
-%
-create_OGCM( mercator_name,...
-             lon,lat,lon,lat,lon,lat,depth,time,...
-             squeeze(temp),squeeze(salt),squeeze(u),...
-             squeeze(v),squeeze(ssh),Yorig)
-%
-return
-
-end
-
diff --git a/Oforc_OGCM/download_mercator_python.m b/Oforc_OGCM/download_mercator_python.m
index 1e5769a0..275ffa1b 100644
--- a/Oforc_OGCM/download_mercator_python.m
+++ b/Oforc_OGCM/download_mercator_python.m
@@ -148,11 +148,11 @@ if convert_raw2crocotools
     if mercator_type==1
       write_mercator(OGCM_dir,OGCM_prefix,raw_mercator_name, ...
                      mercator_type,vars,time,thedatemonth,Yorig); % write data
-%	  eval(['! rm -f ',raw_mercator_name]);
+	  eval(['! rm -f ',raw_mercator_name]);
     elseif mercator_type==2
 	  write_mercator_multi(OGCM_dir,OGCM_prefix,raw_mercator_name, ...
                            mercator_type,vars,time,thedatemonth,Yorig); % write data
-%      eval(['! rm -f ',raw_mercator_name(1:end-3),'*.nc']);
+      eval(['! rm -f ',raw_mercator_name(1:end-3),'*.nc']);
 	end
 
 
diff --git a/Oforc_OGCM/extract_SODA.m b/Oforc_OGCM/extract_SODA.m
index 1790f396..77c7936b 100644
--- a/Oforc_OGCM/extract_SODA.m
+++ b/Oforc_OGCM/extract_SODA.m
@@ -32,8 +32,10 @@ function extract_SODA(SODA_dir,SODA_prefix,url,year,month,...
 %  e-mail:Pierrick.Penven@ird.fr  
 %
 %  Updated   6-Sep-2006 by Pierrick Penven
-%  Updated : 23-Oct-2009 by Gildas Cambon Adaptation for the special tratment 
+%  Updated : 23-Oct-2009 by Gildas Cambon Adaptation for the special treatement 
 %            for the bry file
+%  Updated 18-March-2024 by Gildas Cambon
+%                        - remove download of taux and tauy
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 disp(['    Download SODA for ',num2str(year),...
@@ -62,33 +64,33 @@ if missval<0
 else
   ssh(ssh>=(0.9*missval))=NaN;
 end
-%
-% Get TAUX
-%
-disp('    ...TAUX')
-taux=getdap(url,'',...
-		'taux',trange,'',jrange,...
-		i1min,i1max,i2min,i2max,i3min,i3max);
-eval(['missval=double(x.taux.',missname,');'])
-if missval<0
-  taux(taux<=(0.9*missval))=NaN;
-else
-  taux(taux>=(0.9*missval))=NaN;
-end
-%
-% Get TAUY
-%
-disp('    ...TAUY')
-tauy=getdap(url,'',...
-		'tauy',trange,'',jrange,...
-		i1min,i1max,i2min,i2max,i3min,i3max);
-eval(['missval=double(x.tauy.',missname,');'])
-if missval<0
-  tauy(tauy<=(0.9*missval))=NaN;
-else
-  tauy(tauy>=(0.9*missval))=NaN;
-end
-%
+% %
+% % Get TAUX
+% %
+% disp('    ...TAUX')
+% taux=getdap(url,'',...
+% 		'taux',trange,'',jrange,...
+% 		i1min,i1max,i2min,i2max,i3min,i3max);
+% eval(['missval=double(x.taux.',missname,');'])
+% if missval<0
+%   taux(taux<=(0.9*missval))=NaN;
+% else
+%   taux(taux>=(0.9*missval))=NaN;
+% end
+% %
+% % Get TAUY
+% %
+% disp('    ...TAUY')
+% tauy=getdap(url,'',...
+% 		'tauy',trange,'',jrange,...
+% 		i1min,i1max,i2min,i2max,i3min,i3max);
+% eval(['missval=double(x.tauy.',missname,');'])
+% if missval<0
+%   tauy(tauy<=(0.9*missval))=NaN;
+% else
+%   tauy(tauy>=(0.9*missval))=NaN;
+% end
+% %
 % Get U
 %
 disp('    ...U')
diff --git a/Oforc_OGCM/write_mercator.m b/Oforc_OGCM/write_mercator.m
index ceab42ab..353f1e9f 100644
--- a/Oforc_OGCM/write_mercator.m
+++ b/Oforc_OGCM/write_mercator.m
@@ -2,8 +2,8 @@ function write_mercator(OGCM_dir,OGCM_prefix,raw_mercator_name,...
                          mercator_type,vars,time,thedatemonth,Yorig)
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-% Extract a subset from Mercator in the case of hindcast
-% using python motu client (cls)
+% Extract a subset from Mercator  in the case of hindcast 
+% using python  copernicusmarine client
 % Write it in a local file (keeping the classic SODA netcdf format)
 % 
 %  Further Information:  
@@ -35,7 +35,7 @@ function write_mercator(OGCM_dir,OGCM_prefix,raw_mercator_name,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-disp(['    writing MERCATOR file'])
+disp(['    Writing MERCATOR file'])
 %
 % Get grid and time frame
 %
diff --git a/Oforc_OGCM/write_mercator_multi.m b/Oforc_OGCM/write_mercator_multi.m
index 3f4878da..23f9234b 100644
--- a/Oforc_OGCM/write_mercator_multi.m
+++ b/Oforc_OGCM/write_mercator_multi.m
@@ -35,7 +35,21 @@ function write_mercator_multi(OGCM_dir,OGCM_prefix,raw_mercator_name,...
 %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-disp(['    writing MERCATOR multifiles '])
+if nargin <1
+    OGCM_dir='/local/tmp/3/gcambon/CONFIGS/RUN_V2.0_LR_DEV/DATA/Forecast/';
+    OGCM_prefix='mercator_';
+    raw_mercator_name='/local/tmp/3/gcambon/CONFIGS/RUN_V2.0_LR_DEV/DATA/Forecast/raw_mercator_2024-03-19T00:00:00Z.nc'
+    mercator_type=3;
+    vars={'zos' ...
+          'uo' ...
+          'vo' ...
+          'thetao' ...
+          'so'};
+    time=[739328 739329 739330 739331 739332 739333 739334];
+    thedatemonth='2024-03-19T00:00:00Z';
+    Yorig=2000;
+end
+disp(['    Writing MERCATOR multifiles '])
 
 fname_z=[raw_mercator_name(1:end-3),'_z.nc'];
 fname_u=[raw_mercator_name(1:end-3),'_u.nc'];
@@ -45,12 +59,17 @@ fname_s=[raw_mercator_name(1:end-3),'_s.nc'];
 %
 % Get grid and time frame
 %
-nc = netcdf(fname_u);
+nc = netcdf(fname_t);
 lon = nc{'longitude'}(:);
 lat = nc{'latitude'}(:);
 depth = nc{'depth'}(:);
 time = nc{'time'}(:);
-time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
+if mercator_type ~= 5
+  time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
+else
+  time = time / 24 + datenum(1900,1,1) - datenum(Yorig,1,1);
+end
+close(nc)
 %
 % Get SSH
 %
@@ -117,7 +136,7 @@ temp(temp>=missval)=NaN;
 %add_offset=ncc.add_offset(:);
 %temp(temp<=missval)=NaN;
 temp = temp.*scale_factor + add_offset;
-close(nc) % close raw_mercator_name
+close(nc) % close raw_mercator_nam
 %
 % Get SALT
 %
diff --git a/Preprocessing_tools/geost_currents.m b/Preprocessing_tools/geost_currents.m
index 73026f9b..2363074b 100644
--- a/Preprocessing_tools/geost_currents.m
+++ b/Preprocessing_tools/geost_currents.m
@@ -162,8 +162,8 @@ for l=1:tlen
 %
 % Ekman transport
 %
-  if ~isempty(frcname)
-%    disp('Add the Ekman transport')
+  if exist(frcname)
+    disp('Add the Ekman transport')
     sustr(:,:)=nfrc{'sustr'}(l,:,:);
     svstr(:,:)=nfrc{'svstr'}(l,:,:);
 %    rhoA=1.3; Cd=1.4e-3;
diff --git a/Preprocessing_tools/geost_currents_bry.m b/Preprocessing_tools/geost_currents_bry.m
index cc0f2e0a..eaad7517 100644
--- a/Preprocessing_tools/geost_currents_bry.m
+++ b/Preprocessing_tools/geost_currents_bry.m
@@ -193,8 +193,8 @@ for l=1:tlen
 %
 % Ekman transport
 %
-  if ~isempty(frcname)
-%    disp('Add the Ekman transport')
+   if exist(frcname)
+      disp('Add the Ekman transport')
     if obcndx==1
       tmp=squeeze(nfrc{'sustr'}(l,1,:));
       sustr=0*h; 
-- 
GitLab