#!/usr/bin/env python3




#===============================================================================
#   Options
#===============================================================================
period='19920101_19920131'
period_title='(year 1992 month 1)'

file_type='avg'
freq='5d'

# ASAP2 : 34.0052  South
idxlat0 = 127    # transect parent grid
idxlat1 = 167   # transect child grid

##### A CORRIGER
#####  plot_map reclame le zoom1 et zoom2 pour tracer l'emprunte. 
####    conditionner le plot des empruntes en général a leur définition et non au fait qu'on veuille faire un plot du zoom
# map0 
lonmin_grid0, lonmax_grid0, latmin_grid0, latmax_grid0, lon_interv0, lat_interv0 = -29, 74, -58, 10, 11, 11
# map1 
lonmin_grid1, lonmax_grid1, latmin_grid1, latmax_grid1, lon_interv1, lat_interv1 = 2, 42, -47, -24, 11, 11
# map2 
lonmin_grid2, lonmax_grid2, latmin_grid2, latmax_grid2, lon_interv2, lat_interv2 = 2, 42, -47, -24, 11, 11

# transect 1 
lonmin_transect0, lonmax_transect0, depthmin_transect0, depthmax_transect0 = 11, 31, -500, 0


#===============================================================================
#   Var choice
#===============================================================================
### physic 2D
#var_list=['SST','zeta','hbl','sustr','svstr','shflux','swflux','swrad']

### physic 3D
#var_list=['temp','usurf','vsurf']

### bio 3D
#var_list=['FER','NO3','DCHL','NCHL','CHL','MESO','ZOO','CACO3','O2','PO4','Si','NH4']

F_map0=True
F_map1=False
F_map2=True
var_list_map_phy=['SST','zeta','hbl','usurf','vsurf']
#var_list_map_phy=['SST']
var_list_map_bio=['FER','NO3','DCHL','NCHL','CHL','MESO','ZOO','O2']
#var_list_map_bio=['FER']

F_transect1=True
var_list_transect_phy=['temp','usurf','vsurf']
#var_list_transect_phy=['temp']
var_list_transect_bio=['FER','NO3','DCHL','NCHL','CHL','MESO','ZOO','O2']
#var_list_transect_bio=['FER']

#var_list_map=['usurf']
#var_list_transect=['usurf']

#===============================================================================
#   Exp choice
#===============================================================================
asap2_00_Steph_KPP_orig={
#'root_path':'/ccc/scratch/cont005/gen1140/chabertp/can11sen2_croco/outputs',
'root_path':'/ccc/scratch/cont005/gen1140/hourdinc/ASAP2/outputs',
'exp_name':'asap2_00_Steph_KPP_orig',
'test_name':''
}

asap2_01_Steph_KPP_rmk={
'root_path':'/ccc/scratch/cont005/gen1140/hourdinc/ASAP2/outputs',
'exp_name':'asap2_01_Steph_KPP_rmk',
'test_name':''
}

#  all
#exp_list=[c11cp_climatoruns_021020, c11s2cp_climatoruns_051120, c11s2cp_climatoruns_151020, c11s2cp_climatoruns_sync_ASAP2020, c11s2_climatoruns]

#exp_list=[c11cp_climatoruns_021020]
#exp_list=[c11s2cp_climatoruns_051120]
#exp_list=[c11s2cp_climatoruns_151020]
#exp_list=[c11s2cp_climatoruns_sync_ASAP2020]

#exp_list=[asap2_00_Steph_KPP_orig]
exp_list=[asap2_01_Steph_KPP_rmk]
#exp_list=[asap2_00_Steph_KPP_orig, asap2_01_Steph_KPP_rmk]



#===============================================================================
#   Import
#===============================================================================
#  pour netcdf pour eviter pb opal
import mpi4py
mpi4py.rc.initialize=False
mpi4py.rc.finalize=False

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
##from netCDF4 import Dataset
import cmocean
import xarray
#import scipy
import xcroco
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import matplotlib.ticker as mticker
from matplotlib.patches import Rectangle
##import cartopy.feature as cfeature
#from matplotlib.font_manager import FontProperties
import datetime

#  fonts
#plt.rc('font',size=10)
#mpl.rc('text', usetex=True)    #  False pour desactiver latex.
#mpl.rc('font', family='serif')


#===============================================================================
#   Functions
#===============================================================================
def var_choice(ds, var_str):
    if var_str=='SST':
        var = ds.temp[0, -1, :, :].values
#       cm = cmocean.cm.solar
        cm = 'jet'
        cbartitle = 'SST [C]'
        vmin, vmax = 19, 27
    if var_str=='zeta':
        var = ds.zeta[0, :, :].values
        cm = cmocean.cm.balance
        cbartitle = 'zeta [m]'
        vmin, vmax = -0.3, 0
    if var_str=='hbl':
        var = ds.hbl[0, :, :].values
        cm = cmocean.cm.deep
        cbartitle = 'hbl [m]'
        vmin, vmax = 10, 80
    if var_str=='usurf':
        var = ds.u[0, -1, :, :]
        var = xcroco.var2rho(ds, var).values
        cm = cmocean.cm.balance
#       cbartitle = 'u_{surf} [m/s]'
        cbartitle = 'usurf [m/s]'
        vmin, vmax = -0.1, 0.1
    if var_str=='vsurf':
        var = ds.v[0, -1, :, :]
        var = xcroco.var2rho(ds, var).values
        cm = cmocean.cm.balance
#       cbartitle = 'v_{surf} [m/s]'
        cbartitle = 'vsurf [m/s]'
        vmin, vmax = -0.1, 0.1
    if var_str=='sustr':
        var = xcroco.var2rho(ds, ds.sustr).values
        cm = cmocean.cm.algae
        cbartitle = 'sustr [N m-2]'
        vmin, vmax = 0, 2
    if var_str=='svstr':
        var = xcroco.var2rho(ds, ds.svstr).values
        cm = cmocean.cm.algae
        cbartitle = 'svstr [N m-2]'
        vmin, vmax = 0, 2
    if var_str=='shflux':
        var = ds.shflux[0, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'shflux [W m-2]'
        vmin, vmax = 0, 2
    if var_str=='swflux':
        var = ds.swflux[0, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'swflux [cm d-1]'
        vmin, vmax = 0, 2
    if var_str=='swrad':
        var = ds.swrad[0, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'swrad [W m-2]'
        vmin, vmax = 0, 2
    if var_str=='FER':
        var = ds.FER[0, -1, :, :].values
        cm = cmocean.cm.matter
        cbartitle = 'FER [umol Fe L-1]'
        vmin, vmax = 1e-4, 0.003
    if var_str=='NO3':
        var = ds.NO3[0, -1, :, :].values
        cm = cmocean.cm.matter
        cbartitle = 'NO3 [umol N L-1]'
        vmin, vmax = 0, 10
    if var_str=='DCHL':
        var = ds.DCHL[0, -1, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'DCHL [$mg.m^{-3}$]'
        vmin, vmax = 1e-2, 1
    if var_str=='NCHL':
        var = ds.NCHL[0, -1, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'NCHL [$mg.m^{-3}$]'
        vmin, vmax = 1e-2, 1e1
    if var_str=='CHL':
        varA = ds.DCHL[0, -1, :, :].values
        varB = ds.NCHL[0, -1, :, :].values
        var = varA + varB
        cm = cmocean.cm.algae
        cbartitle = 'DCHL+NCHL [$mg.m^{-3}$]'
        vmin, vmax = 1e-1, 1e1
    if var_str=='MESO':
        var = ds.MESO[0, -1, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'MESO [umol C L-1]'
        vmin, vmax = 0, 2
    if var_str=='ZOO':
        var = ds.ZOO[0, -1, :, :].values
        cm = cmocean.cm.algae
        cbartitle = 'ZOO [umol C L-1]'
        vmin, vmax = 1e-2, 5
    if var_str=='CACO3':
        var = ds.CACO3[0, -1, :, :].values
        cm = cmocean.cm.matter
        cbartitle = 'CACO3 [umol C L-1]'
        vmin, vmax = 0, 0.1
    if var_str=='O2':
        var = ds.O2[0, -1, :, :].values
        cm = cmocean.cm.oxy
        cbartitle = 'O2 [umol L-1]'
        vmin, vmax = 0, 220
    if var_str=='PO4':
        var = ds.PO4[0, -1, :, :].values
        cm = cmocean.cm.matter
        cbartitle = 'PO4 [umol P L-1]'
        vmin, vmax = 0, 1
    if var_str=='Si':
        var = ds.Si[0, -1, :, :].values
        cm = cmocean.cm.matter
        cbartitle = 'Si [umol Si L-1]'
        vmin, vmax = 0, 10
    if var_str=='NH4':
        var = ds.NH4[0, -1, :, :].values
        cm = cmocean.cm.matter
        cbartitle = 'NH4 [umol N L-1]'
        vmin, vmax = 0, 2

    return(var, cm, cbartitle, vmin, vmax)


def var_choice2(ds, var_str, idxlat):
    if var_str=='temp':
        var = ds.temp[0, :, idxlat, :].values
#       cm = cmocean.cm.solar
        cm = 'jet'
        cbartitle = 'Temp [°C]'
        vmin, vmax = 5, 25
    if var_str=='usurf':
        var = ds.u[0, :, idxlat, :].values
        cm = cmocean.cm.balance
#       cbartitle = 'u_{surf} [m/s]'
        cbartitle = 'usurf [m/s]'
        vmin, vmax = -0.1, 0.1
    if var_str=='vsurf':
        var = ds.v[0, :, idxlat, :].values
        cm = cmocean.cm.balance
#       cbartitle = 'v_{surf} [m/s]'
        cbartitle = 'vsurf [m/s]'
        vmin, vmax = -0.1, 0.1
    if var_str=='FER':
        var = ds.FER[0, :, idxlat, :].values
        cm = cmocean.cm.matter
        cbartitle = 'FER [umol Fe L-1]'
        vmin, vmax = 1e-4, 0.003
    if var_str=='NO3':
        var = ds.NO3[0, :, idxlat, :].values
        cm = cmocean.cm.matter
        cbartitle = 'NO3 [umol N L-1]'
        vmin, vmax = 0, 35
    if var_str=='DCHL':
        var = ds.DCHL[0, :, idxlat, :].values
        cm = cmocean.cm.algae
        cbartitle = 'DCHL [$mg.m^{-3}$]'
        vmin, vmax = 1e-2, 1
    if var_str=='NCHL':
        var = ds.NCHL[0, :, idxlat, :].values
        cm = cmocean.cm.algae
        cbartitle = 'NCHL [$mg.m^{-3}$]'
        vmin, vmax = 1e-2, 1
    if var_str=='CHL':
        varA = ds.DCHL[0, :, idxlat, :].values
        varB = ds.NCHL[0, :, idxlat, :].values
        var = varA + varB
        cm = cmocean.cm.algae
        cbartitle = 'DCHL+NCHL [$mg.m^{-3}$]'
        vmin, vmax = 1e-1, 1e1
    if var_str=='MESO':
        var = ds.MESO[0, :, idxlat, :].values
        cm = cmocean.cm.algae
        cbartitle = 'MESO [umol C L-1]'
        vmin, vmax = 0, 2
    if var_str=='ZOO':
        var = ds.ZOO[0, :, idxlat, :].values
        cm = cmocean.cm.algae
        cbartitle = 'ZOO [umol C L-1]'
        vmin, vmax = 1e-2, 2
    if var_str=='CACO3':
        var = ds.CACO3[0, :, idxlat, :].values
        cm = cmocean.cm.matter
        cbartitle = 'CACO3 [umol C L-1]'
        vmin, vmax = 0, 0.3
    if var_str=='O2':
        var = ds.O2[0, :, idxlat, :].values
        cm = cmocean.cm.oxy
        cbartitle = 'O2 [umol L-1]'
        vmin, vmax = 0, 250
    if var_str=='PO4':
        var = ds.PO4[0, :, idxlat, :].values
        cm = cmocean.cm.matter
        cbartitle = 'PO4 [umol P L-1]'
        vmin, vmax = 0, 2
    if var_str=='Si':
        var = ds.Si[0, :, idxlat, :].values
        cm = cmocean.cm.matter
        cbartitle = 'Si [umol Si L-1]'
        vmin, vmax = 0, 40
    if var_str=='NH4':
        var = ds.NH4[0, :, idxlat, :].values
        cm = cmocean.cm.matter
        cbartitle = 'NH4 [umol N L-1]'
        vmin, vmax = 0, 2

    return(var, cm, cbartitle, vmin, vmax)

local_time1=datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d')    #  '2018-09-26'
local_time2=datetime.datetime.strftime(datetime.datetime.now(), '%d-%b-%Y')    #  '2018-09-26'
local_time3=datetime.datetime.strftime(datetime.datetime.now(), '%Y_%m_%d-%H-%M-%S') # '2018_09_26-16-38-04'
local_time4=datetime.datetime.strftime(datetime.datetime.now(), '%d-%b-%Y')    #  '19-Sep-2018'

def plot_map(ii, agrif, idxlat, exp_name, ds, var_str, lonmin, lonmax, latmin, latmax, lon_interv, lat_interv, lon_zoom, lat_zoom):
   if agrif == 0 : ext1='PARENT grid'; ext2=''
   elif agrif == 1 : ext1='CHILD grid'; ext2='_CHILD'

   print ('\n   ',var_str,' plot map '+ext1+'  (lon : '+str(lonmin)+' '+str(lonmax)+'    lat : '+str(latmin)+' '+str(latmax)+')')
#  lons = np.linspace(lonmin-1, lonmax+1, lonmax - lonmin + 3)
#  lats = np.linspace(latmin-1, latmax+1, latmax - latmin + 3)
   lons = np.linspace(lonmin, lonmax, lon_interv)
   lats = np.linspace(latmin, latmax, lat_interv)
   lon, lat = ds.lon_rho.values, ds.lat_rho.values

   landmask = ds.mask_rho.values[:,:]

   var, cm, cbartitle, vmin, vmax = var_choice(ds, var_str)
#  mmvar="\\Large (min:%.1e  max:%.1e)" %(var.min(),var.max())
   if var.max() < 0.1 : 
      mmvar="(min:%.1e  max:%.1e)" %(var.min(),var.max())
   else :
      mmvar="(min:%.2f  max:%.2f)" %(var.min(),var.max())
   var[landmask==0] = np.nan

   plt.figure(ii,figsize=(16,9));
   plt.subplot(1,1,1, projection=ccrs.PlateCarree()) 
   ax = plt.gca()
   pcm = ax.pcolormesh(lon, lat, var, cmap=cm, vmin=vmin, vmax=vmax)
   if var_str=='DCHL' or var_str=='NCHL' or var_str=='CHL' or var_str=='FER':
      pcm = ax.pcolormesh(lon, lat, var, cmap=cm, vmin=vmin, vmax=vmax, norm=mpl.colors.LogNorm())
   plt.colorbar(pcm, label=cbartitle)
   plt.suptitle(exp_name+' '+ext1+'  '+period_title)
   plt.text(lonmin+0.2,latmin+0.2,mmvar,verticalalignment='bottom',horizontalalignment='left',bbox=dict(facecolor='white', edgecolor='white',alpha=0.5))
   plt.text(lonmax-0.2,latmin+0.2,local_time4,verticalalignment='bottom',horizontalalignment='right',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
#  plt.text(lonmax-0.2,latmin+0.2,'\\large \\textbf{\\it{'+local_time4+'}}',verticalalignment='bottom',horizontalalignment='right',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
   gl = ax.gridlines(draw_labels=True, linestyle='--', alpha=.5, color='gray', linewidth=1)
   gl.xlocator = mticker.FixedLocator(lons)
   gl.ylocator = mticker.FixedLocator(lats)
   gl.xformatter = LONGITUDE_FORMATTER
   gl.xformatter = LONGITUDE_FORMATTER
   gl.yformatter = LATITUDE_FORMATTER
   gl.ylabels_right = False
   gl.xlabels_top = False
   gl.ylabels_left = False
   gl.ylabels_left = True
   plt.xlim(lonmin, lonmax);plt.ylim(latmin,latmax)
   plt.xlabel('Longitude (°)'); plt.ylabel('Latitude (°)')
# if agrif : plot zoom boundaries 
#  A GENERALISER POUR TOUTES LES CONFIGS!!!
#  Faire un test AGRIF independant du nom de la config:
#  if 'c11s2' in exp_name1 : 
   plt.plot(lon_zoom,lat_zoom,'m-')
   plt.text(lon_zoom[3],lat_zoom[3],'AGRIF',verticalalignment='bottom',horizontalalignment='left',color='magenta',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
# plot zoom map0, map1...
   ax.add_patch(Rectangle((lonmin_grid1, latmin_grid1), lonmax_grid1-lonmin_grid1, latmax_grid1-latmin_grid1,alpha=1,edgecolor='black',facecolor='none',linestyle='-.',lw=1,hatch=' ')) 
   plt.text(lonmax_grid1, latmax_grid1 ,'zoom1',verticalalignment='bottom',horizontalalignment='left',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
   ax.add_patch(Rectangle((lonmin_grid2, latmin_grid2), lonmax_grid2-lonmin_grid2, latmax_grid2-latmin_grid2,alpha=1,edgecolor='black',facecolor='none',linestyle='-.',lw=1,hatch=' ')) 
   plt.text(lonmax_grid2, latmax_grid2 ,'zoom2',verticalalignment='bottom',horizontalalignment='left',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
# plot transect line
   iimin=0; iimax=0
   while (ds.lon_rho[idxlat,iimin].values < lonmin_transect0) : iimin=iimin+1
   while (ds.lon_rho[idxlat,iimax].values < lonmax_transect0) : iimax=iimax+1
   plt.plot (ds.lon_rho[idxlat,iimin:iimax].values,ds.lat_rho[idxlat,iimin:iimax].values, color='black', linestyle='-.')
   plt.text(ds.lon_rho[idxlat,iimax].values, ds.lat_rho[idxlat,iimax].values ,'transect',verticalalignment='bottom',horizontalalignment='left',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
#  plt.show()
   sav_name=exp_name+'_'+var_str+'_'+period+'_lon_'+str(lonmin)+'_'+str(lonmax)+'_lat_'+str(latmin)+'_'+str(latmax)+ext2+'.png'
   plt.savefig(sav_name)
   plt.close()
   return()


def plot_transect(ii, agrif, idxlat, exp_name, ds, var_str, lonmin, lonmax, depthmin, depthmax):
   if agrif == 0 : ext1='PARENT grid'; ext2=''
   elif agrif == 1 : ext1='CHILD grid'; ext2='_CHILD'

   print ('\n   ',var_str,' plot transect '+ext1+'  (lon : '+str(lonmin)+' '+str(lonmax)+'    depth : '+str(depthmin)+' '+str(depthmax)+')')
   var, cm, cbartitle, vmin, vmax = var_choice2(ds, var_str, idxlat)
#  mmvar="\\Large (min:%.1e  max:%.1e)" %(var.min(),var.max())
   if var.max() < 0.1 : 
      mmvar="(min:%.1e  max:%.1e)" %(var.min(),var.max())
   else :
      mmvar="(min:%.2f  max:%.2f)" %(var.min(),var.max())
   z_rho = ds.z_rho[0].values
   z_rho = z_rho[:,idxlat,:]
   lon = ds.lon_rho[idxlat, :].values
   x = np.empty(z_rho.shape)
   for i in range(x.shape[0]):
       x[i,:] = lon

   plt.figure(ii, figsize=(14,8))
   plt.suptitle(exp_name+' '+ext1+'  '+period_title)
   plt.text(lonmin+0.2,depthmin+10,mmvar,verticalalignment='bottom',horizontalalignment='left',bbox=dict(facecolor='white', edgecolor='white',alpha=0.5))
   plt.text(lonmax-0.2,depthmin+10,local_time4,verticalalignment='bottom',horizontalalignment='right',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
#  plt.text(lonmax-0.2,latmin+0.2,'\\large \\textbf{\\it{'+local_time4+'}}',verticalalignment='bottom',horizontalalignment='right',color='black',bbox=dict(facecolor='white', edgecolor='white', alpha=0.5))
   plt.subplot(1,1,1)
   ax = plt.gca()
   pcm = ax.pcolormesh(x, z_rho, var, cmap=cm, vmin=vmin, vmax=vmax)
   if var_str=='DCHL' or var_str=='NCHL' or var_str=='CHL' or var_str=='FER':
       pcm = ax.pcolormesh(x, z_rho, var, cmap=cm, vmin=vmin, vmax=vmax, norm=mpl.colors.LogNorm())
   plt.colorbar(pcm, label=cbartitle)
   plt.xlim(lonmin, lonmax);plt.ylim(depthmin,depthmax)
   plt.xlabel('Longitude (°)'); plt.ylabel('Depth (m)')
#  plt.show()
   sav_name=exp_name+'_'+var_str+'_'+period+'_lon_'+str(lonmin)+'_'+str(lonmax)+'_depth_'+str(depthmin)+'_'+str(depthmax)+ext2+'.png'
   plt.savefig(sav_name)
   plt.close()
   return()


#===============================================================================
#   Execute
#===============================================================================

# pour plotter la grille zoom dans la grille mere
file_zoom='/ccc/work/cont005/gen1140/hourdinc/ASAP/inputs/grd/asap_grd.nc.1'
ds_zoom=xarray.open_dataset(file_zoom)
lon_zoom=[ds_zoom.lon_rho.values[0,0], ds_zoom.lon_rho.values[-1,0], ds_zoom.lon_rho.values[-1,-1], ds_zoom.lon_rho.values[0,-1], ds_zoom.lon_rho.values[0,0]]
lat_zoom=[ds_zoom.lat_rho.values[0,0], ds_zoom.lat_rho.values[-1,0], ds_zoom.lat_rho.values[-1,-1], ds_zoom.lat_rho.values[0,-1], ds_zoom.lat_rho.values[0,0]]

ii1=1

#-------------------------------------------------------------------------------
for exp1 in exp_list :
#-------------------------------------------------------------------------------
### exp1
   root_path1=exp1['root_path']
   exp_name1=exp1['exp_name']
   test_name1=exp1['test_name']

   exp_path1=root_path1+'/'+exp_name1+'/'+period

   if test_name1 != '' :
      exp_path1=exp_path1+'_'+test_name1

   file1=exp_path1+'/'+exp_name1+'_'+file_type+'_'+freq+'_'+period+'_mean.nc'

#  ds1=xarray.open_dataset(file1)
# ouverture via xcroco pour pouvoir passer de la grille u ou v a la grille rho
# necessite d'interpoller les grilles au préalable avec xgcm appele par xcroco.croco_dataset
#  globals()['exp1']=xcroco.croco_dataset(file1)
#  ds1 =  xarray.concat([globals()['exp1']],'time')
   ds1=xcroco.croco_dataset(file1)

#  A GENERALISER POUR TOUTES LES CONFIGS!!!
#  Faire un test AGRIF independant du nom de la config:
#  if 'c11s2' in exp_name1 : 
#     file1z=file1+'.1'
#     ds1z=xcroco.croco_dataset(file1z)
   file1z=file1+'.1'
   ds1z=xcroco.croco_dataset(file1z)

### transect :
#  climato_v1 = '/ccc/work/cont005/gen1140/chabertp/CONFIGS/CAN11_NEW/RESTARTS_pisces/creation_rst/can11_avg.mean.2000-2006.can11bio1.nc'
#  ds_climv1 = xcroco.croco_dataset(climato_v1)
#  z_rho = ds_climv1.z_rho[0].values
#  z_rho = z_rho[:,idxlat,:]

   print ('\n\n',80*'=','\n   ',exp_name1,' \n',80*'=')
   print (exp_path1)
   print (file1)

   #-------------------------------------------------------------------------------
   
#  A GENERALISER POUR TOUTES LES CONFIGS!!!
#  if 'cp' in exp_name1 :
#     var_list_map=var_list_map_phy + var_list_map_bio
#     var_list_transect=var_list_transect_phy + var_list_transect_bio
#  else : 
#     var_list_map=var_list_map_phy
#     var_list_transect=var_list_transect_phy
   var_list_map=var_list_map_phy + var_list_map_bio
   var_list_transect=var_list_transect_phy + var_list_transect_bio
   


   for var1_str in var_list_map :
      if F_map0 : plot_map(ii1, 0, idxlat0,  exp_name1, ds1, var1_str, lonmin_grid0, lonmax_grid0, latmin_grid0, latmax_grid0, lon_interv0, lat_interv0, lon_zoom, lat_zoom); ii1=ii1+1
      if F_map1 : plot_map(ii1, 0, idxlat0,  exp_name1, ds1, var1_str, lonmin_grid1, lonmax_grid1, latmin_grid1, latmax_grid1, lon_interv1, lat_interv1, lon_zoom, lat_zoom); ii1=ii1+1
      if F_map2 :
         plot_map(ii1, 0, idxlat0,  exp_name1, ds1, var1_str, lonmin_grid2, lonmax_grid2, latmin_grid2, latmax_grid2, lon_interv2, lat_interv2, lon_zoom, lat_zoom); ii1=ii1+1
#  A GENERALISER POUR TOUTES LES CONFIGS!!!
#  Faire un test AGRIF independant du nom de la config:
#        if 'c11s2' in exp_name1 : plot_map(ii1, 1, idxlat1,  exp_name1, ds1z, var1_str, lonmin_grid2, lonmax_grid2, latmin_grid2, latmax_grid2, lon_interv2, lat_interv2, lon_zoom, lat_zoom); ii1=ii1+1
# plot de la grille fille
         plot_map(ii1, 1, idxlat1,  exp_name1, ds1z, var1_str, lonmin_grid2, lonmax_grid2, latmin_grid2, latmax_grid2, lon_interv2, lat_interv2, lon_zoom, lat_zoom); ii1=ii1+1


   #-------------------------------------------------------------------------------
   for var1_str in var_list_transect :
      if F_transect1 :
         plot_transect(ii1, 0, idxlat0, exp_name1, ds1, var1_str, lonmin_transect0, lonmax_transect0, depthmin_transect0, depthmax_transect0); ii1=ii1+1
#  A GENERALISER POUR TOUTES LES CONFIGS!!!
#  Faire un test AGRIF independant du nom de la config:
#        if 'c11s2' in exp_name1 : plot_transect(ii1, 1, idxlat1, exp_name1, ds1z, var1_str, lonmin_transect0, lonmax_transect0, depthmin_transect0, depthmax_transect0); ii1=ii1+1
         plot_transect(ii1, 1, idxlat1, exp_name1, ds1z, var1_str, lonmin_transect0, lonmax_transect0, depthmin_transect0, depthmax_transect0); ii1=ii1+1

#  ds1.close()




plt.show()







