function download_mercator_frcst_python(pathCMC,user,password,mercator_type, ...
                                        product_id, ...
                                        rundate_dnum, lh,lf, ...
                                        lonmin,lonmax,latmin,latmax,zmax, ...
                                        Yorig, raw_mercator_name)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Extract a subgrid from mercator 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) 2005-2006 by Pierrick Penven
%  e-mail:Pierrick.Penven@ird.fr
%
%  Updated    6-Sep-2006 by Pierrick Penven
%  Updated    20-Aug-2008 by Matthieu Caillaud & P. Marchesiello
%  Update     23-Oct-2020 by Gildas Cambon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

disp([' download_mercator_frcst_python() raw_mercator_name=', raw_mercator_name])

download_raw_data=1;

%
% Set variable names according to mercator type data
%
if mercator_type==1,
  vars = {'zos' ...
	  'uo' ...
	  'vo' ...
	  'thetao' ...
	  'so'};
else
  vars = {'zos_detided' ...
	  'uo' ...
	  'vo' ...
	  'thetao' ...
	  'so'};
end


%
% Get date (in Yorig time)
%
rundate=rundate_dnum-datenum(Yorig,1,1);

for i=1:lh+1
    time1(i)=rundate_dnum-(lh+1-i);
end
time2=rundate_dnum;
if lf > 0
    for j=1:lf
        time3(j)=rundate_dnum+j-2;
    end
else
    time3=[];  %(1)=rundate_dnum+1;
end
time=cat(2,time1,time2,time3);
disp('time1=')
disp(datestr(time1))
disp('time2=')
disp(datestr(time2))
disp('time3=')
disp(datestr(time3))

disp('time=')
disp(datestr(time))

tiempo_inicial = time(1);
tiempo_inicial_p0 = time(1+lh)
tiempo_final = time(end);
disp(['tiempo_inicial=', datestr(tiempo_inicial)])
disp(['tiempo_inicial_p0=', datestr(tiempo_inicial)])
disp(['tiempo_final=', datestr(tiempo_final)])
%
if (lonmin > 180)
    lonmin = lonmin - 360;
end
if (lonmax > 180)
    lonmax = lonmax - 360;
end
%
disp([' '])
disp(['  Get data for ',datestr(rundate_dnum)])
disp(['  Minimum Longitude: ',num2str(lonmin)])
disp(['  Maximum Longitude: ',num2str(lonmax)])
disp(['  Minimum Latitude:  ',num2str(latmin)])
disp(['  Maximum Latitude:  ',num2str(latmax)])
disp([' '])

if download_raw_data
    %
    % Get data
    %
    if exist([raw_mercator_name(1:end-3),'_z.nc'], 'file')
        disp(['  Raw mercator file already exists: ', raw_mercator_name(1:end-3),'_z.nc'])
    else
        disp(['--> Extraction Forecasts from operational date run  :  ', datestr(tiempo_inicial_p0,'yyyy-mm-dd')])
        for i=1:lh
          disp(['Get Hindcasts         : ',datestr(time(i),'yyyy-mm-dd')])
        end
        disp(['Get ',num2str(lf),' Forecasts      : from ',datestr(tiempo_inicial_p0,'yyyy-mm-dd'),' to ',datestr(tiempo_final,  'yyyy-mm-dd')])

        get_file_python_mercator(pathCMC,mercator_type, ...                  %SSH
                                product_id{1}, ...
                                vars(1), ...
                                [lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
                                {datestr(tiempo_inicial,'yyyy-mm-dd') ...
                                datestr(tiempo_final,  'yyyy-mm-dd')}, ...
                                {user password}, ...
                                [raw_mercator_name(1:end-3),'_z.nc']);
    end

    if exist([raw_mercator_name(1:end-3),'_u.nc'], 'file')
        disp(['  Raw mercator file already exists: ', raw_mercator_name(1:end-3),'_u.nc'])
    else
    get_file_python_mercator(pathCMC,mercator_type, ...                    %U, V
                            product_id{2}, ...
                            vars(2:3), ...
                            [lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
                            {datestr(tiempo_inicial,'yyyy-mm-dd') ...
                            datestr(tiempo_final,  'yyyy-mm-dd')}, ...
                            {user password}, ...
                            [raw_mercator_name(1:end-3),'_u.nc']);
    end
    if exist([raw_mercator_name(1:end-3),'_t.nc'], 'file')
        disp(['  Raw mercator file already exists: ', raw_mercator_name(1:end-3),'_t.nc'])
    else
    get_file_python_mercator(pathCMC,mercator_type, ...                    %T
                            product_id{3}, ...
                            vars(4), ...
                            [lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
                            {datestr(tiempo_inicial,'yyyy-mm-dd') ...
                            datestr(tiempo_final,  'yyyy-mm-dd')}, ...
                            {user password}, ...
                            [raw_mercator_name(1:end-3),'_t.nc']);
    end
    if exist([raw_mercator_name(1:end-3),'_s.nc'], 'file')
        disp(['  Raw mercator file already exists: ', raw_mercator_name(1:end-3),'_s.nc'])
    else
    get_file_python_mercator(pathCMC,mercator_type, ...                    %S
                            product_id{4}, ...
                            vars(5), ...
                            [lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
                            {datestr(tiempo_inicial,'yyyy-mm-dd') ...
                            datestr(tiempo_final,  'yyyy-mm-dd')}, ...
                            {user password}, ...
                            [raw_mercator_name(1:end-3),'_s.nc']);
    end



end


end


