#!/bin/bash
## Generate html file to list figures with table
## Also generate descriptions for upper index.html
## column: figures filename (without suffix) or text or newrow
##    ex. 'c1' 'c2' 'c3' tr    <- text row, tr means end of row
##         fig1 fig2 fig3 tr   <- 3 figures
##         fig4 fig5 fig6 tr   <- 3 figures
##         'title2' tr         <- the row with text only
##         fig6 fig7 tr
##         fig8 fig9 fig10 tr  <- 2 and 3 figures at this and next row

#;DIAG_NORCPM; FIGFILES: 
    # figure files name "without suffix"
    # should be ps or png file
    # with suffix: make thumbnail only
#;DIAG_NORCPM; HTMLFILENAME: index.html
#;DIAG_NORCPM; TITLE: TITLE here
#;DIAG_NORCPM; COMMENT: COMMENT here
#;DIAG_NORCPM; SUMMARY: 
#;DIAG_NORCPM; COLUMN: 1
#;DIAG_NORCPM; THUMBNAIL: 
#;DIAG_NORCPM; ENTRYHTMLFN: entry.html
    ## this file will be read by diag.py, do not modified it.
#;DIAG_NORCPM; ENTRYHTMLCONTAIN: 
    ## this will be the contain of entry.html if not empyt

fig2png () { ## if text is a file, return .png name. if not, return text
    i=$1
    ii=$i
    if [ -f "${i}.ps" ] ; then ## ps2png
        convert -density 300 "${i}.ps" ${i}.png
        if [  $? != 0 ];then
            MAGICK_THREAD_LIMIT=1 convert -density 300 "${i}.ps" ${i}.png
        fi
        gzip -f "${i}.ps"
        convert ${i}.png -fuzz 1% -trim +repage tmp-${i}-${pid}.png
        mv tmp-${i}-${pid}.png ${i}.png
    fi
    if [ -f "${i}.png" ] ; then ## trim white edge and make thumbnail
        ## thumbnail
        test "${i}.png" -nt "${i}_thumb.png" && convert -thumbnail 300 "${i}.png" "${i}_thumb.png"
        ii="<a href='${i}.png'><img src='${i%.*}_thumb.png'></a>"
    fi
    if [ -f "${i}" ] ; then ## other files: make thumbnail
        #convert ${i}.png -fuzz 1% -trim +repage tmp-${i}-${pid}.png 
        #mv tmp-${i}-${pid}.png ${i}.png
        ## thumbnail
        test "${i}.png" -nt "${i}_thumb.png" && convert -thumbnail 300 "${i}" "${i%.*}_thumb.png"
        ii="<a href='${i}'><img src='${i%.*}_thumb.png'></a>"
    fi
    test -f "$thumb" || thumb="${i%.*}_thumb.png"
    echo -n "$ii"
}
summary_to_html () {
    summary=$1
    html=''
    for i in $summary; do
        h="$(fig2png $i)"
        test "$h" == "br" && h='</br>' || true
        html="$html $h"
    done
    echo -n "$html"
}

# parameters
htmlfn="index.html"
comment="Specific TBI pacemaker, super ensemble
Simulation includeds
    NorESM1/2 ; anomaly/full field nudge
    Each of them are 5 members, nudge at 10NS Altantic plus 10 deg. taper
Analysis period are 1980-2000 and 2000-2020
This correlation is between model U,V and AMIP tos(SST).
"
title="TBI pacemaker super ensemble UV"
figs=""
column=(' ' 'super ensmean U cor. to Atl3 SST'  ' ' 'super ensmean V cor. to Atl3 SST' tr
'lev' P1 P2 P1 P2 tr
200hPa cor_sens_U200-Atl3SST_P1 cor_sens_U200-Atl3SST_P2 cor_sens_V200-Atl3SST_P1 cor_sens_V200-Atl3SST_P2
tr
850hPa cor_sens_U850-Atl3SST_P1 cor_sens_U850-Atl3SST_P2 cor_sens_V850-Atl3SST_P1 cor_sens_V850-Atl3SST_P2
tr
' ' 'super ensmean U cor. to WTAtl SST'  ' ' 'super ensmean V cor. to WTAtl SST' tr
'lev' P1 P2 P1 P2 tr
200hPa cor_sens_U200-WTAtlSST_P1 cor_sens_U200-WTAtlSST_P2 cor_sens_V200-WTAtlSST_P1 cor_sens_V200-WTAtlSST_P2
tr
850hPa cor_sens_U850-WTAtlSST_P1 cor_sens_U850-WTAtlSST_P2 cor_sens_V850-WTAtlSST_P1 cor_sens_V850-WTAtlSST_P2
tr
' ' 'super ensmean U cor. to Atl3 SST JJA'  ' ' 'SON' ' ' 'DJF' ' ' 'MAM' tr
'lev' P1 P2 P1 P2 P1 P2 tr
200hPa cor_sens_U200-Atl3SST_JJA_P1 cor_sens_U200-Atl3SST_JJA_P2
       cor_sens_U200-Atl3SST_SON_P1 cor_sens_U200-Atl3SST_SON_P2
       cor_sens_U200-Atl3SST_DJF_P1 cor_sens_U200-Atl3SST_DJF_P2
       cor_sens_U200-Atl3SST_MAM_P1 cor_sens_U200-Atl3SST_MAM_P2
tr
850hPa cor_sens_U850-Atl3SST_JJA_P1 cor_sens_U850-Atl3SST_JJA_P2
       cor_sens_U850-Atl3SST_SON_P1 cor_sens_U850-Atl3SST_SON_P2
       cor_sens_U850-Atl3SST_DJF_P1 cor_sens_U850-Atl3SST_DJF_P2
       cor_sens_U850-Atl3SST_MAM_P1 cor_sens_U850-Atl3SST_MAM_P2
tr
' ' 'super ensmean U cor. to WTAtl SST JJA'  ' ' 'SON' ' ' 'DJF' ' ' 'MAM' tr
'lev' P1 P2 P1 P2 P1 P2 tr
200hPa cor_sens_U200-WTAtlSST_JJA_P1 cor_sens_U200-WTAtlSST_JJA_P2
       cor_sens_U200-WTAtlSST_SON_P1 cor_sens_U200-WTAtlSST_SON_P2
       cor_sens_U200-WTAtlSST_DJF_P1 cor_sens_U200-WTAtlSST_DJF_P2
       cor_sens_U200-WTAtlSST_MAM_P1 cor_sens_U200-WTAtlSST_MAM_P2
tr
850hPa cor_sens_U850-WTAtlSST_JJA_P1 cor_sens_U850-WTAtlSST_JJA_P2
       cor_sens_U850-WTAtlSST_SON_P1 cor_sens_U850-WTAtlSST_SON_P2
       cor_sens_U850-WTAtlSST_DJF_P1 cor_sens_U850-WTAtlSST_DJF_P2
       cor_sens_U850-WTAtlSST_MAM_P1 cor_sens_U850-WTAtlSST_MAM_P2
tr
' ' 'super ensmean U cor. to WTAtl SST' tr
'lev' 'all period JJA' SON DJF MAM tr
200hPa cor_sens_U200-WTAtlSST_JJA_allp 
       cor_sens_U200-WTAtlSST_SON_allp 
       cor_sens_U200-WTAtlSST_DJF_allp 
       cor_sens_U200-WTAtlSST_MAM_allp 
tr
850hPa cor_sens_U850-WTAtlSST_JJA_allp 
       cor_sens_U850-WTAtlSST_SON_allp 
       cor_sens_U850-WTAtlSST_DJF_allp 
       cor_sens_U850-WTAtlSST_MAM_allp 
tr
' ' 'super ensmean U cor. to WTAtl SST, but detrend' tr
'lev' 'all period JJA' SON DJF MAM tr
200hPa cor_sens_U200-WTAtlSST_JJA_allp_det
       cor_sens_U200-WTAtlSST_SON_allp_det
       cor_sens_U200-WTAtlSST_DJF_allp_det
       cor_sens_U200-WTAtlSST_MAM_allp_det
tr
850hPa cor_sens_U850-WTAtlSST_JJA_allp_det
       cor_sens_U850-WTAtlSST_SON_allp_det
       cor_sens_U850-WTAtlSST_DJF_allp_det
       cor_sens_U850-WTAtlSST_MAM_allp_det
tr
' ' 'super ensmean U cor. to NCEP2 reanalysis'  tr
'lev' P1 P2 tr
200hPa cor_sens_U200-NCEP2_P1 cor_sens_U200-NCEP2_P2
tr
850hPa cor_sens_U850-NCEP2_P1 cor_sens_U850-NCEP2_P2
tr
' ' 'NCEP2 U cor. to AMIP Atl3 SST (all OBS)'  tr
'lev' 'all mon P1' 'all mon P2' 'JJA P1' 'JJA P2' 'SON P1' 'SON P2' 'DJF P1' 'DJF P2' 'MAM P1' 'MAM P2' tr
200hPa cor_obs_U200_NCEP2-Atl3_HadISSTv1_allmon_P1 cor_obs_U200_NCEP2-Atl3_HadISSTv1_allmon_P2
       cor_obs_U200_NCEP2-Atl3_HadISSTv1_JJA_P1 cor_obs_U200_NCEP2-Atl3_HadISSTv1_JJA_P2
       cor_obs_U200_NCEP2-Atl3_HadISSTv1_SON_P1 cor_obs_U200_NCEP2-Atl3_HadISSTv1_SON_P2
       cor_obs_U200_NCEP2-Atl3_HadISSTv1_DJF_P1 cor_obs_U200_NCEP2-Atl3_HadISSTv1_DJF_P2
       cor_obs_U200_NCEP2-Atl3_HadISSTv1_MAM_P1 cor_obs_U200_NCEP2-Atl3_HadISSTv1_MAM_P2
tr
850hPa cor_obs_U850_NCEP2-Atl3_HadISSTv1_allmon_P1 cor_obs_U850_NCEP2-Atl3_HadISSTv1_allmon_P2
       cor_obs_U850_NCEP2-Atl3_HadISSTv1_JJA_P1 cor_obs_U850_NCEP2-Atl3_HadISSTv1_JJA_P2
       cor_obs_U850_NCEP2-Atl3_HadISSTv1_SON_P1 cor_obs_U850_NCEP2-Atl3_HadISSTv1_SON_P2
       cor_obs_U850_NCEP2-Atl3_HadISSTv1_DJF_P1 cor_obs_U850_NCEP2-Atl3_HadISSTv1_DJF_P2
       cor_obs_U850_NCEP2-Atl3_HadISSTv1_MAM_P1 cor_obs_U850_NCEP2-Atl3_HadISSTv1_MAM_P2
tr
' ' 'ERA5 U cor. to AMIP Atl3 SST (all OBS)'  tr
'lev' 'all mon P1' 'all mon P2' 'JJA P1' 'JJA P2' 'SON P1' 'SON P2' 'DJF P1' 'DJF P2' 'MAM P1' 'MAM P2' tr
200hPa cor_obs_U200_ERA5-Atl3_HadISSTv1_allmon_P1 cor_obs_U200_ERA5-Atl3_HadISSTv1_allmon_P2
       cor_obs_U200_ERA5-Atl3_HadISSTv1_JJA_P1 cor_obs_U200_ERA5-Atl3_HadISSTv1_JJA_P2
       cor_obs_U200_ERA5-Atl3_HadISSTv1_SON_P1 cor_obs_U200_ERA5-Atl3_HadISSTv1_SON_P2
       cor_obs_U200_ERA5-Atl3_HadISSTv1_DJF_P1 cor_obs_U200_ERA5-Atl3_HadISSTv1_DJF_P2
       cor_obs_U200_ERA5-Atl3_HadISSTv1_MAM_P1 cor_obs_U200_ERA5-Atl3_HadISSTv1_MAM_P2
tr
850hPa cor_obs_U850_ERA5-Atl3_HadISSTv1_allmon_P1 cor_obs_U850_ERA5-Atl3_HadISSTv1_allmon_P2
       cor_obs_U850_ERA5-Atl3_HadISSTv1_JJA_P1 cor_obs_U850_ERA5-Atl3_HadISSTv1_JJA_P2
       cor_obs_U850_ERA5-Atl3_HadISSTv1_SON_P1 cor_obs_U850_ERA5-Atl3_HadISSTv1_SON_P2
       cor_obs_U850_ERA5-Atl3_HadISSTv1_DJF_P1 cor_obs_U850_ERA5-Atl3_HadISSTv1_DJF_P2
       cor_obs_U850_ERA5-Atl3_HadISSTv1_MAM_P1 cor_obs_U850_ERA5-Atl3_HadISSTv1_MAM_P2
tr
' ' 'NCEP2 U cor. to AMIP WTAtl SST (all OBS)'  tr
'lev' 'all mon P1' 'all mon P2' 'JJA P1' 'JJA P2' 'SON P1' 'SON P2' 'DJF P1' 'DJF P2' 'MAM P1' 'MAM P2' tr
200hPa cor_obs_U200_NCEP2-WTAtl_HadISSTv1_allmon_P1 cor_obs_U200_NCEP2-WTAtl_HadISSTv1_allmon_P2
       cor_obs_U200_NCEP2-WTAtl_HadISSTv1_JJA_P1 cor_obs_U200_NCEP2-WTAtl_HadISSTv1_JJA_P2
       cor_obs_U200_NCEP2-WTAtl_HadISSTv1_SON_P1 cor_obs_U200_NCEP2-WTAtl_HadISSTv1_SON_P2
       cor_obs_U200_NCEP2-WTAtl_HadISSTv1_DJF_P1 cor_obs_U200_NCEP2-WTAtl_HadISSTv1_DJF_P2
       cor_obs_U200_NCEP2-WTAtl_HadISSTv1_MAM_P1 cor_obs_U200_NCEP2-WTAtl_HadISSTv1_MAM_P2
tr
850hPa cor_obs_U850_NCEP2-WTAtl_HadISSTv1_allmon_P1 cor_obs_U850_NCEP2-WTAtl_HadISSTv1_allmon_P2
       cor_obs_U850_NCEP2-WTAtl_HadISSTv1_JJA_P1 cor_obs_U850_NCEP2-WTAtl_HadISSTv1_JJA_P2
       cor_obs_U850_NCEP2-WTAtl_HadISSTv1_SON_P1 cor_obs_U850_NCEP2-WTAtl_HadISSTv1_SON_P2
       cor_obs_U850_NCEP2-WTAtl_HadISSTv1_DJF_P1 cor_obs_U850_NCEP2-WTAtl_HadISSTv1_DJF_P2
       cor_obs_U850_NCEP2-WTAtl_HadISSTv1_MAM_P1 cor_obs_U850_NCEP2-WTAtl_HadISSTv1_MAM_P2
tr
' ' 'ERA5 U cor. to AMIP WTAtl SST (all OBS)'  tr
'lev' 'all mon P1' 'all mon P2' 'JJA P1' 'JJA P2' 'SON P1' 'SON P2' 'DJF P1' 'DJF P2' 'MAM P1' 'MAM P2' tr
200hPa cor_obs_U200_ERA5-WTAtl_HadISSTv1_allmon_P1 cor_obs_U200_ERA5-WTAtl_HadISSTv1_allmon_P2
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_JJA_P1 cor_obs_U200_ERA5-WTAtl_HadISSTv1_JJA_P2
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_SON_P1 cor_obs_U200_ERA5-WTAtl_HadISSTv1_SON_P2
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_DJF_P1 cor_obs_U200_ERA5-WTAtl_HadISSTv1_DJF_P2
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_MAM_P1 cor_obs_U200_ERA5-WTAtl_HadISSTv1_MAM_P2
tr
850hPa cor_obs_U850_ERA5-WTAtl_HadISSTv1_allmon_P1 cor_obs_U850_ERA5-WTAtl_HadISSTv1_allmon_P2
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_JJA_P1 cor_obs_U850_ERA5-WTAtl_HadISSTv1_JJA_P2 cor_obs_U850_ERA5-WTAtl_HadISSTv1_JJA_allp
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_SON_P1 cor_obs_U850_ERA5-WTAtl_HadISSTv1_SON_P2 cor_obs_U850_ERA5-WTAtl_HadISSTv1_SON_allp
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_DJF_P1 cor_obs_U850_ERA5-WTAtl_HadISSTv1_DJF_P2 cor_obs_U850_ERA5-WTAtl_HadISSTv1_DJF_allp
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_MAM_P1 cor_obs_U850_ERA5-WTAtl_HadISSTv1_MAM_P2 cor_obs_U850_ERA5-WTAtl_HadISSTv1_MAM_allp
tr
'lev' 'all period' SON DJF MAM tr
200hPa 
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_JJA_allp
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_SON_allp 
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_DJF_allp 
       cor_obs_U200_ERA5-WTAtl_HadISSTv1_MAM_allp 
tr
850hPa 
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_JJA_allp 
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_SON_allp 
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_DJF_allp 
       cor_obs_U850_ERA5-WTAtl_HadISSTv1_MAM_allp 
tr
' ' 'Ensmean U cor. of each model SST'  and 'V cor.' tr
' ' 'NorESM1 full field' tr
200hPa TBI_NUG_FF_cor_ens_U200-Atl3SST_P1.png TBI_NUG_FF_cor_ens_U200-Atl3SST_P2.png 
       TBI_NUG_FF_cor_ens_V200-Atl3SST_P1.png TBI_NUG_FF_cor_ens_V200-Atl3SST_P2.png tr
850hPa TBI_NUG_FF_cor_ens_U850-Atl3SST_P1.png TBI_NUG_FF_cor_ens_U850-Atl3SST_P2.png 
       TBI_NUG_FF_cor_ens_V850-Atl3SST_P1.png TBI_NUG_FF_cor_ens_V850-Atl3SST_P2.png tr
' ' 'NorESM1 anomaly' tr
200hPa TBI_NUG_Ano_cor_ens_U200-Atl3SST_P1.png TBI_NUG_Ano_cor_ens_U200-Atl3SST_P2.png 
       TBI_NUG_Ano_cor_ens_V200-Atl3SST_P1.png TBI_NUG_Ano_cor_ens_V200-Atl3SST_P2.png tr
850hPa TBI_NUG_Ano_cor_ens_U850-Atl3SST_P1.png TBI_NUG_Ano_cor_ens_U850-Atl3SST_P2.png 
       TBI_NUG_Ano_cor_ens_V850-Atl3SST_P1.png TBI_NUG_Ano_cor_ens_V850-Atl3SST_P2.png tr
' ' 'NorESM2 full field' tr
200hPa TBI_N2_FF_w2_cor_ens_U200-Atl3SST_P1.png TBI_N2_FF_w2_cor_ens_U200-Atl3SST_P2.png 
       TBI_N2_FF_w2_cor_ens_V200-Atl3SST_P1.png TBI_N2_FF_w2_cor_ens_V200-Atl3SST_P2.png tr
850hPa TBI_N2_FF_w2_cor_ens_U850-Atl3SST_P1.png TBI_N2_FF_w2_cor_ens_U850-Atl3SST_P2.png 
       TBI_N2_FF_w2_cor_ens_V850-Atl3SST_P1.png TBI_N2_FF_w2_cor_ens_V850-Atl3SST_P2.png tr
' ' 'NorESM2 anomaly' tr
200hPa TBI_N2_Ano_w2_cor_ens_U200-Atl3SST_P1.png TBI_N2_Ano_w2_cor_ens_U200-Atl3SST_P2.png 
       TBI_N2_Ano_w2_cor_ens_V200-Atl3SST_P1.png TBI_N2_Ano_w2_cor_ens_V200-Atl3SST_P2.png tr
850hPa TBI_N2_Ano_w2_cor_ens_U850-Atl3SST_P1.png TBI_N2_Ano_w2_cor_ens_U850-Atl3SST_P2.png 
       TBI_N2_Ano_w2_cor_ens_V850-Atl3SST_P1.png TBI_N2_Ano_w2_cor_ens_V850-Atl3SST_P2.png tr
' ' 'Ensmean U cor. to NCEP2 rean.' tr
' ' 'NorESM1 full field' tr
200hPa TBI_NUG_FF_cor_ens_U200-NCEP2_P1.png TBI_NUG_FF_cor_ens_U200-NCEP2_P2.png tr
850hPa TBI_NUG_FF_cor_ens_U850-NCEP2_P1.png TBI_NUG_FF_cor_ens_U850-NCEP2_P2.png tr
' ' 'NorESM1 anomaly' tr
200hPa TBI_NUG_Ano_cor_ens_U200-NCEP2_P1.png TBI_NUG_Ano_cor_ens_U200-NCEP2_P2.png  tr
850hPa TBI_NUG_Ano_cor_ens_U850-NCEP2_P1.png TBI_NUG_Ano_cor_ens_U850-NCEP2_P2.png  tr
' ' 'NorESM2 full field' tr
200hPa TBI_N2_FF_w2_cor_ens_U200-NCEP2_P1.png TBI_N2_FF_w2_cor_ens_U200-NCEP2_P2.png tr
850hPa TBI_N2_FF_w2_cor_ens_U850-NCEP2_P1.png TBI_N2_FF_w2_cor_ens_U850-NCEP2_P2.png tr
' ' 'NorESM2 anomaly' tr
200hPa TBI_N2_Ano_w2_cor_ens_U200-NCEP2_P1.png TBI_N2_Ano_w2_cor_ens_U200-NCEP2_P2.png tr
850hPa TBI_N2_Ano_w2_cor_ens_U850-NCEP2_P1.png TBI_N2_Ano_w2_cor_ens_U850-NCEP2_P2.png tr
)
    ## number of figures in a row
    ## should be a array
ncolarr=${#column[*]}
entryfn='entry.html'
entryhtml=''

thumb="cor_vp200_superens_amip_detrend_thumb.png"
summary="For Atl3 SST to 850hPa zonal wind of 1980-2000(left) and 2000-2020(right) br
Super ensemble mean shows stong correlation JJA: br
cor_sens_U850-Atl3SST_JJA_P1 cor_sens_U850-Atl3SST_JJA_P2 br
Same correlation but in ERA5 and HadISST: br
cor_obs_U850_ERA5-Atl3_HadISSTv1_JJA_P1 cor_obs_U850_ERA5-Atl3_HadISSTv1_JJA_P2 br
Same correlation but in NCEP2 and HadISST: br
cor_obs_U850_NCEP2-Atl3_HadISSTv1_JJA_P1 cor_obs_U850_NCEP2-Atl3_HadISSTv1_JJA_P2 br
The correlation is start from MAM (1980-2000): br
cor_sens_U850-Atl3SST_MAM_P1
cor_sens_U850-Atl3SST_JJA_P1    
cor_sens_U850-Atl3SST_SON_P1
cor_sens_U850-Atl3SST_DJF_P1
br
Compare to reanalysis (ERA5-HadISST): br
cor_obs_U850_ERA5-Atl3_HadISSTv1_MAM_P1
cor_obs_U850_ERA5-Atl3_HadISSTv1_JJA_P1
cor_obs_U850_ERA5-Atl3_HadISSTv1_SON_P1
cor_obs_U850_ERA5-Atl3_HadISSTv1_DJF_P1
br br br
The path from Atl3 to tropical west-mid Pacific maybe via higher level(200hPa): br
cor_sens_U200-Atl3SST_MAM_P1
cor_sens_U200-Atl3SST_JJA_P1    
cor_sens_U200-Atl3SST_SON_P1
cor_sens_U200-Atl3SST_DJF_P1
br
cor_obs_U200_ERA5-Atl3_HadISSTv1_MAM_P1
cor_obs_U200_ERA5-Atl3_HadISSTv1_JJA_P1
cor_obs_U200_ERA5-Atl3_HadISSTv1_SON_P1
cor_obs_U200_ERA5-Atl3_HadISSTv1_DJF_P1
br
br br
This connection does not singificant at 2000-2020 850hPa: br 
cor_sens_U850-Atl3SST_MAM_P2
cor_sens_U850-Atl3SST_JJA_P2    
cor_sens_U850-Atl3SST_SON_P2
cor_sens_U850-Atl3SST_DJF_P2
br
cor_obs_U850_ERA5-Atl3_HadISSTv1_MAM_P2
cor_obs_U850_ERA5-Atl3_HadISSTv1_JJA_P2
cor_obs_U850_ERA5-Atl3_HadISSTv1_SON_P2
cor_obs_U850_ERA5-Atl3_HadISSTv1_DJF_P2
br
It does propergated vertically and southward at 2000-2020 200hPa: br 
cor_sens_U200-Atl3SST_MAM_P2
cor_sens_U200-Atl3SST_JJA_P2    
cor_sens_U200-Atl3SST_SON_P2
cor_sens_U200-Atl3SST_DJF_P2
br
cor_obs_U200_ERA5-Atl3_HadISSTv1_MAM_P2
cor_obs_U200_ERA5-Atl3_HadISSTv1_JJA_P2
cor_obs_U200_ERA5-Atl3_HadISSTv1_SON_P2
cor_obs_U200_ERA5-Atl3_HadISSTv1_DJF_P2
br
br br
"
#export MAGICK_THREAD_LIMIT=1   ## avoid "libgomp: Thread creation failed"

# html header
text=$'\n'
text+=$'<!DOCTYPE html>\n'
text+=$'<html>\n'
text+=$'<body>\n'

# put comment on top
text+=$'<div id="comment">\n'
text+=$'<p>\n'
text+=$'<pre>\n'
text+="$comment"
text+=$'</pre>\n'
#text+=$'</p>\n'
text+=$'</div>\n'

# summary section, mixed with figures and text. not done yet, HOW?
## identy in figures
## put inline figures in table?
if [ ! -z "$summary" ];then
    text+=$'<div id="summary">\n'
    text+=$'<h3>Summary: </h3>\n'
    text+="$(summary_to_html "$summary") "$'\n'
    text+=$'</div>\n'
    text+=$'</br>\n'
    text+=$'<hr>\n'
    text+=$'<h3>Figures:</h3>\n'
    
fi


nl=$'\n'  #newline
# convert ps to png and output entry to html
pid=$$
row=1
icol=0


text+="<table>"$'\n'
text+="<tr>"$'\n'

# columns
while [ ! -z "${column[$icol]}" ] ; do
    dst="${column[$icol]}"
    if [ "${dst}" = 'tr' ]; then
        dst='</tr>'$'\n''<tr>'
    fi
    if [ "${dst}" = '</tr><tr>' ]; then
        text+="${dst}"$'\n'
    else
        text+="<th>"$(fig2png "${dst}")"</th>"$'\n'
    fi
    icol=$(( $icol + 1))
done
wait

## show figures with table
text+="</tr>"$'\n'
text+="</table>"$'\n'

# html footer
text+=$'</body>\n'
text+=$'</html> \n'

# output to html file
echo "${text}" >  "${htmlfn}"


## The entry snipp html for parent index.html

nowdir=$(basename $(pwd -P))
if [ -z "$entryhtml" ]; then
    entryhtml="${entryhtml}    <span style='display:inline-block'>${nl}"
    entryhtml="${entryhtml}    <a href='${nowdir}/index.html'>${nl}"
    entryhtml="${entryhtml}    <h4>${title}</h4>${nl}"
    entryhtml="${entryhtml}    <img ALIGN='left' src='${nowdir}/${thumb}'>${nl}"
    entryhtml="${entryhtml}    </a>${nl}"
    entryhtml="${entryhtml}    <pre>${comment}</pre>${nl}"
    entryhtml="${entryhtml}    </ br>${nl}"
    entryhtml="${entryhtml}    </span>${nl}"
    entryhtml="${entryhtml}    </ br>${nl}"
    entryhtml="${entryhtml}    <hr>${nl}"
fi
echo "${entryhtml}" > "${entryfn}"

