From 29c406b639238c201227d4c256098c16c5e59aed Mon Sep 17 00:00:00 2001
From: Gildas Cambon <gildas.cambon@ird.fr>
Date: Thu, 11 Apr 2024 20:13:33 +0200
Subject: [PATCH] Fix to have clean plot in Forecast_tools/

- Remove the get_missingval call to handle m_contour + m_usercoast patch when saving figures in batch mode
- Save (using export_fig) in jpg format to speed-up
- Still some adaptation for wind stress plot (case 1)
---
 Forecast_tools/plot_forecast_croco.m | 71 +++++++++++++++-------------
 1 file changed, 39 insertions(+), 32 deletions(-)

diff --git a/Forecast_tools/plot_forecast_croco.m b/Forecast_tools/plot_forecast_croco.m
index 3fa454a0..48bd8fde 100644
--- a/Forecast_tools/plot_forecast_croco.m
+++ b/Forecast_tools/plot_forecast_croco.m
@@ -35,7 +35,7 @@ plot_fig_1 = 0; % wind
 plot_fig_2 = 1; % surface currents
 plot_fig_3 = 1; % SST + surface currents
 plot_fig_4 = 1; % SSH
-plot_fig_5 = 0; % HBL
+plot_fig_5 = 1; % HBL
 
 % offset to convert UTC model time 
 % into local matlab time [days]
@@ -135,9 +135,10 @@ if plot_fig_1,
   %m_streamslice(lonr,latr,ur,vr,1); hold on;
   set(h,'color','b');
   if ~isempty(coastfile)  
-   m_usercoast(coastfile,'patch',[.0 .0 .0]);
+    m_usercoast(coastfile,'patch',[.0 .0 .0]);
+    %m_usercoast(coastfile,'line', 'color', 'black', 'linewidth', 2);
   else
-   m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k')
+     m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k')
   end
   hold off
   m_grid('box','fancy','tickdir','in','FontSize',fsize);
@@ -160,9 +161,9 @@ if plot_fig_1,
   xlabel('Wind [knots]','FontSize',fsize)
   set(gcf, 'PaperPositionMode', 'auto');
 
-  % export_fig -transparent file.pdf
-  % eval(['! mv -f file.pdf ',dirout,outname,'.pdf']);
-  eval(['print -bestfit -dpdf',dirout,outname,'.pdf']);
+  export_fig -transparent file.jpg
+  eval(['! mv -f file.jpg ',dirout,outname,'.jpg']);
+  %eval(['print -bestfit -dpdf',dirout,outname,'.pdf']);
  end
 close(nc)
 end % plot_fig_1
@@ -213,7 +214,7 @@ for tndx=hdays+1:nx+hdays
     close(nc)
 
     spd=1.94384*mask.*sqrt((u2rho_2d(u)).^2+(v2rho_2d(v)).^2);
-    spd=get_missing_val(lon,lat,spd);
+    %spd=get_missing_val(lon,lat,spd); % in batch mode, do not render properly with m_contour + m_usercoast
     [ur,vr,lonr,latr,maskr]=uv_vec2rho(u,v,lon,lat,angle,mask,skip_cur,[0 0 0 0]);
 
     m_proj('mercator',...
@@ -224,9 +225,9 @@ for tndx=hdays+1:nx+hdays
     caxis([cmin cmax])
     hold on
     m_quiver(lonr,latr,cff_cur*ur,cff_cur*vr,0,'k');
-    m_usercoast(coastfile,'patch',[.0 .0 .0]);
     if ~isempty(coastfile)  
-     m_usercoast(coastfile,'patch',[.0 .0 .0]);
+        m_usercoast(coastfile,'patch',[.0 .0 .0]);
+        %m_usercoast(coastfile,'line', 'color', 'black', 'linewidth', 2);
     else
      m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k')
     end
@@ -254,9 +255,9 @@ for tndx=hdays+1:nx+hdays
     end
     set(gcf, 'PaperPositionMode', 'auto');
 
-    % export_fig -transparent file.pdf
-    % eval(['! mv -f file.pdf ',dirout,outname,'.pdf']);
-    eval(['print -bestfit -dpdf ',dirout,outname,'.pdf']);
+    export_fig -transparent file.jpg
+    eval(['! mv -f file.jpg ',dirout,outname,'.jpg']);
+    %eval(['print -bestfit -dpdf ',dirout,outname,'.pdf
   end
 end
 end % plot_fig_2
@@ -293,9 +294,9 @@ for tndx=hdays+1:nx+hdays
     close(nc)
     [ur,vr,lonr,latr,maskr]=uv_vec2rho(u,v,lon,lat,angle,mask,skip_cur,[0 0 0 0]);
     spdr=sqrt(ur.^2+vr.^2);
-    sst=get_missing_val(lon,lat,sst);
-    ur=get_missing_val(lonr,latr,ur);
-    vr=get_missing_val(lonr,latr,vr);
+    %sst=get_missing_val(lon,lat,sst); % in batch mode, do not render properly with m_contour + m_usercoast
+    %ur=get_missing_val(lonr,latr,ur); 
+    %vr=get_missing_val(lonr,latr,vr);
 
     %plot_res=1/3;
     %[LON,LAT]=meshgrid([lonmin:plot_res:lonmax],[latmin:plot_res:latmax]);
@@ -306,14 +307,15 @@ for tndx=hdays+1:nx+hdays
          'lon',[lonmin lonmax],...
          'lat',[latmin latmax]);
     [C0,h0]=m_contourf(lon,lat,sst,[cmin:cint:cmax],'k');
+    %m_pcolor(lon,lat,sst);
     shading flat
     caxis([cmin cmax])
     hold on
     m_quiver(lonr,latr,cff_cur*ur,cff_cur*vr,0,'k');
     %m_streamslice(LON,LAT,U,V,2);
-    m_usercoast(coastfile,'patch',[.0 .0 .0]);
     if ~isempty(coastfile)  
-     m_usercoast(coastfile,'patch',[.0 .0 .0]);
+        m_usercoast(coastfile,'patch',[.0 .0 .0]);
+        %m_usercoast(coastfile,'line', 'color', 'black', 'linewidth', 2);
     else
      m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k')
     end
@@ -337,9 +339,11 @@ for tndx=hdays+1:nx+hdays
     xlabel('SST [^{o}C]','FontSize',fsize)
     set(gcf, 'PaperPositionMode', 'auto');
 
-    % export_fig -transparent file.pdf
-    % eval(['! mv -f file.pdf ',dirout,outname,'.pdf']);
-    eval(['print -bestfit -dpdf ',dirout,outname,'.pdf']);
+    export_fig -transparent file.jpg
+    eval(['! mv -f file.jpg ',dirout,outname,'.jpg']);
+    %export_fig -transparent file.pdf
+    %eval(['! mv -f file.pdf ',dirout,outname,'.pdf']);
+    %eval(['print -bestfit -dpdf ',dirout,outname,'.pdf']);
   end
 end
 end % plot_fig_3
@@ -367,14 +371,15 @@ for tndx=hdays+1:nx+hdays
     ssh=100*squeeze(nc{'zeta'}(tndx,:,:));
     ssh=(ssh-mean(mean(ssh))).*mask;
     close(nc)
-    ssh=get_missing_val(lon,lat,ssh);
+    %ssh=get_missing_val(lon,lat,ssh); % in batch mode, do not render properly with m_contour + m_usercoast
 
     m_proj('mercator','lon',[lonmin lonmax],'lat',[latmin latmax]);
     [C0,h0]=m_contourf(lon,lat,ssh,[cmin:cint:cmax]);
-%    shading flat
+    shading flat
     caxis([cmin cmax])
     if ~isempty(coastfile)  
      m_usercoast(coastfile,'patch',[.0 .0 .0]);
+     %m_usercoast(coastfile,'line', 'color', 'black', 'linewidth', 2);
     else
      m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k')
     end
@@ -397,9 +402,9 @@ for tndx=hdays+1:nx+hdays
     xlabel('SSH [cm]','FontSize',fsize)
     set(gcf, 'PaperPositionMode', 'auto');
 
-    % export_fig -transparent file.pdf
-    % eval(['! mv -f file.pdf ',dirout,outname,'.pdf']);
-    eval(['print -bestfit -dpdf ',dirout,outname,'.pdf']);
+    export_fig -transparent file.jpg
+    eval(['! mv -f file.jpg ',dirout,outname,'.jpg']);
+    %eval(['print -bestfit -dpdf ',dirout,outname,'.pdf']);
   end
 end
 end % plot_fig_4
@@ -425,16 +430,18 @@ for tndx=hdays+1:nx+hdays
   if ~isempty(scrumtime)
     hbl=mask.*squeeze(nc{'hbl'}(tndx,:,:));
     close(nc)
-%    hbl=get_missing_val(lon,lat,hbl);
+    %hbl=get_missing_val(lon,lat,hbl); % in batch mode, do not render properly with m_contour + m_usercoast
 
     m_proj('mercator','lon',[lonmin lonmax],'lat',[latmin latmax]);
-    m_pcolor(lon,lat,hbl);
-    shading flat
+    %[C0,h0]=m_contourf(lon,lat,ssh,[cmin:cint:cmax]);
+    %shading flat
+    m_pcolor(lon,lat,hbl);shading flat;
     caxis([cmin cmax])
     if ~isempty(coastfile)  
      m_usercoast(coastfile,'patch',[.0 .0 .0]);
+     %m_usercoast(coastfile,'line', 'color', 'black', 'linewidth', 2);
     else
-     m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k')
+     m_gshhs_f('patch',[.7 .7 .7],'edgecolor','k');
     end
     m_grid('box','fancy','tickdir','in','FontSize',fsize-2);
     set(findobj('tag','m_grid_color'),'facecolor','white')
@@ -455,9 +462,9 @@ for tndx=hdays+1:nx+hdays
     xlabel('HBL [m]','FontSize',fsize)
     set(gcf, 'PaperPositionMode', 'auto');
 
-    % export_fig -transparent file.pdf
-    % eval(['! mv -f file.pdf ',dirout,outname,'.pdf']);
-    eval(['print  -bestfit -dpdf ',dirout,outname,'.pdf']);
+    export_fig -transparent file.jpg
+    eval(['! mv -f file.jpg ',dirout,outname,'.jpg']);
+    %eval(['print  -bestfit -dpdf ',dirout,outname,'.pdf']);
   end
 end
 end % plot_fig_5
-- 
GitLab