#!/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
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="
"
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="
"
fi
test -f "$thumb" || thumb="${i%.*}_thumb.png"
echo -n "$ii"
}
cd figs/
# parameters
htmlfn="index_reana.html"
title="SM vs NI reanalysis (OLD code version)"
comment=$'\n'
comment+='
Notes
'
comment+=''
column=(
'Correlation: SST anomaly
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SST_glb_corr_map_MODELS_MEAN NI_SST_glb_corr_map_NorESM NI_SST_glb_corr_map_CESM NI_SST_glb_corr_map_MPIESM tr
'SM_reana' tr
SM_SST_glb_corr_map_MODELS_MEAN SM_SST_glb_corr_map_NorESM SM_SST_glb_corr_map_CESM SM_SST_glb_corr_map_MPIESM tr
'SM_reana - NI_reana' tr
DIFF_SST_glb_corr_diff_map_MODELS_MEAN DIFF_SST_glb_corr_diff_map_NorESM DIFF_SST_glb_corr_diff_map_CESM DIFF_SST_glb_corr_diff_map_MPIESM tr
'RMSE (with-bias): SST
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SST_glb_rmse_wBias_map_MODELS_MEAN NI_SST_glb_rmse_wBias_map_NorESM NI_SST_glb_rmse_wBias_map_CESM NI_SST_glb_rmse_wBias_map_MPIESM tr
'SM_reana' tr
SM_SST_glb_rmse_wBias_map_MODELS_MEAN SM_SST_glb_rmse_wBias_map_NorESM SM_SST_glb_rmse_wBias_map_CESM SM_SST_glb_rmse_wBias_map_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_SST_glb_rmse_wBias_diff_map_MODELS_MEAN DIFF_SST_glb_rmse_wBias_diff_map_NorESM DIFF_SST_glb_rmse_wBias_diff_map_CESM DIFF_SST_glb_rmse_wBias_diff_map_MPIESM tr
'Salinity [0-360,60S-60N]: RMSE (with-bias)
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana ' tr
NI_SAL_rmse_wBias_Depth_vs_Time_MODELS_MEAN NI_SAL_rmse_wBias_Depth_vs_Time_NorESM NI_SAL_rmse_wBias_Depth_vs_Time_CESM NI_SAL_rmse_wBias_Depth_vs_Time_MPIESM tr
'SM_reana ' tr
SM_SAL_rmse_wBias_Depth_vs_Time_MODELS_MEAN SM_SAL_rmse_wBias_Depth_vs_Time_NorESM SM_SAL_rmse_wBias_Depth_vs_Time_CESM SM_SAL_rmse_wBias_Depth_vs_Time_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_SAL_rmse_wBias_diff_Depth_vs_Time_MODELS_MEAN DIFF_SAL_rmse_wBias_diff_Depth_vs_Time_NorESM DIFF_SAL_rmse_wBias_diff_Depth_vs_Time_CESM DIFF_SAL_rmse_wBias_diff_Depth_vs_Time_MPIESM tr
'Temperature [0-360,60S-60N]: RMSE (with-bias)
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana ' tr
NI_TEM_rmse_wBias_Depth_vs_Time_MODELS_MEAN NI_TEM_rmse_wBias_Depth_vs_Time_NorESM NI_TEM_rmse_wBias_Depth_vs_Time_CESM NI_TEM_rmse_wBias_Depth_vs_Time_MPIESM tr
'SM_reana ' tr
SM_TEM_rmse_wBias_Depth_vs_Time_MODELS_MEAN SM_TEM_rmse_wBias_Depth_vs_Time_NorESM SM_TEM_rmse_wBias_Depth_vs_Time_CESM SM_TEM_rmse_wBias_Depth_vs_Time_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_TEM_rmse_wBias_diff_Depth_vs_Time_MODELS_MEAN DIFF_TEM_rmse_wBias_diff_Depth_vs_Time_NorESM DIFF_TEM_rmse_wBias_diff_Depth_vs_Time_CESM DIFF_TEM_rmse_wBias_diff_Depth_vs_Time_MPIESM tr
'Correlation: HC200 anomaly avg@[-5,5]
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana ' tr
NI_HC200_EPO_corr_map_lonVsMon_MODELS_MEAN NI_HC200_EPO_corr_map_lonVsMon_NorESM NI_HC200_EPO_corr_map_lonVsMon_CESM NI_HC200_EPO_corr_map_lonVsMon_MPIESM tr
'SM_reana ' tr
SM_HC200_EPO_corr_map_lonVsMon_MODELS_MEAN SM_HC200_EPO_corr_map_lonVsMon_NorESM SM_HC200_EPO_corr_map_lonVsMon_CESM SM_HC200_EPO_corr_map_lonVsMon_MPIESM tr
'SM_reana - NI_reana ' tr
DIFF_HC200_EPO_corr_diff_map_lonVsMon_MODELS_MEAN DIFF_HC200_EPO_corr_diff_map_lonVsMon_NorESM DIFF_HC200_EPO_corr_diff_map_lonVsMon_CESM DIFF_HC200_EPO_corr_diff_map_lonVsMon_MPIESM tr
'RMSE (with-bias): HC200 avg@[-5,5]
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_HC200_EPO_rmse_wBias_map_lonVsMon_MODELS_MEAN NI_HC200_EPO_rmse_wBias_map_lonVsMon_NorESM NI_HC200_EPO_rmse_wBias_map_lonVsMon_CESM NI_HC200_EPO_rmse_wBias_map_lonVsMon_MPIESM tr
'SM_reana' tr
SM_HC200_EPO_rmse_wBias_map_lonVsMon_MODELS_MEAN SM_HC200_EPO_rmse_wBias_map_lonVsMon_NorESM SM_HC200_EPO_rmse_wBias_map_lonVsMon_CESM SM_HC200_EPO_rmse_wBias_map_lonVsMon_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_HC200_EPO_rmse_wBias_diff_map_lonVsMon_MODELS_MEAN DIFF_HC200_EPO_rmse_wBias_diff_map_lonVsMon_NorESM DIFF_HC200_EPO_rmse_wBias_diff_map_lonVsMon_CESM DIFF_HC200_EPO_rmse_wBias_diff_map_lonVsMon_MPIESM tr
'Correlation: Z20 anomaly avg@[-5,5]
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_Z20_EPO_corr_map_lonVsMon_MODELS_MEAN NI_Z20_EPO_corr_map_lonVsMon_NorESM NI_Z20_EPO_corr_map_lonVsMon_CESM NI_Z20_EPO_corr_map_lonVsMon_MPIESM tr
'SM_reana' tr
SM_Z20_EPO_corr_map_lonVsMon_MODELS_MEAN SM_Z20_EPO_corr_map_lonVsMon_NorESM SM_Z20_EPO_corr_map_lonVsMon_CESM SM_Z20_EPO_corr_map_lonVsMon_MPIESM tr
'SM_reana - NI_reana' tr
DIFF_Z20_EPO_corr_diff_map_lonVsMon_MODELS_MEAN DIFF_Z20_EPO_corr_diff_map_lonVsMon_NorESM DIFF_Z20_EPO_corr_diff_map_lonVsMon_CESM DIFF_Z20_EPO_corr_diff_map_lonVsMon_MPIESM tr
'RMSE (with-bias): Z20 avg@[-5,5]
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'RMSE (with-bias): NI_reana' tr
NI_Z20_EPO_rmse_wBias_map_lonVsMon_MODELS_MEAN NI_Z20_EPO_rmse_wBias_map_lonVsMon_NorESM NI_Z20_EPO_rmse_wBias_map_lonVsMon_CESM NI_Z20_EPO_rmse_wBias_map_lonVsMon_MPIESM tr
'RMSE (with-bias): SM_reana' tr
SM_Z20_EPO_rmse_wBias_map_lonVsMon_MODELS_MEAN SM_Z20_EPO_rmse_wBias_map_lonVsMon_NorESM SM_Z20_EPO_rmse_wBias_map_lonVsMon_CESM SM_Z20_EPO_rmse_wBias_map_lonVsMon_MPIESM tr
'RMSE (with-bias) Diff: NI_reana - SM_reana' tr
DIFF_Z20_EPO_rmse_wBias_diff_map_lonVsMon_MODELS_MEAN DIFF_Z20_EPO_rmse_wBias_diff_map_lonVsMon_NorESM DIFF_Z20_EPO_rmse_wBias_diff_map_lonVsMon_CESM DIFF_Z20_EPO_rmse_wBias_diff_map_lonVsMon_MPIESM tr
'Correlation: SSS anomaly
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SSS_glb_corr_map_MODELS_MEAN NI_SSS_glb_corr_map_NorESM NI_SSS_glb_corr_map_CESM NI_SSS_glb_corr_map_MPIESM tr
'SM_reana' tr
SM_SSS_glb_corr_map_MODELS_MEAN SM_SSS_glb_corr_map_NorESM SM_SSS_glb_corr_map_CESM SM_SSS_glb_corr_map_MPIESM tr
'SM_reana - NI_reana' tr
DIFF_SSS_glb_corr_diff_map_MODELS_MEAN DIFF_SSS_glb_corr_diff_map_NorESM DIFF_SSS_glb_corr_diff_map_CESM DIFF_SSS_glb_corr_diff_map_MPIESM tr
'RMSE (with-bias): SSS
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SSS_glb_rmse_wBias_map_MODELS_MEAN NI_SSS_glb_rmse_wBias_map_NorESM NI_SSS_glb_rmse_wBias_map_CESM NI_SSS_glb_rmse_wBias_map_MPIESM tr
'SM_reana' tr
SM_SSS_glb_rmse_wBias_map_MODELS_MEAN SM_SSS_glb_rmse_wBias_map_NorESM SM_SSS_glb_rmse_wBias_map_CESM SM_SSS_glb_rmse_wBias_map_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_SSS_glb_rmse_wBias_diff_map_MODELS_MEAN DIFF_SSS_glb_rmse_wBias_diff_map_NorESM DIFF_SSS_glb_rmse_wBias_diff_map_CESM DIFF_SSS_glb_rmse_wBias_diff_map_MPIESM tr
'Correlation: SSH anomaly
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SSH_glb_corr_map_MODELS_MEAN NI_SSH_glb_corr_map_NorESM NI_SSH_glb_corr_map_CESM NI_SSH_glb_corr_map_MPIESM tr
'SM_reana' tr
SM_SSH_glb_corr_map_MODELS_MEAN SM_SSH_glb_corr_map_NorESM SM_SSH_glb_corr_map_CESM SM_SSH_glb_corr_map_MPIESM tr
'SM_reana - NI_reana' tr
DIFF_SSH_glb_corr_diff_map_MODELS_MEAN DIFF_SSH_glb_corr_diff_map_NorESM DIFF_SSH_glb_corr_diff_map_CESM DIFF_SSH_glb_corr_diff_map_MPIESM tr
'Correlation: HC200 anomaly
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_HC200_glb_corr_map_MODELS_MEAN NI_HC200_glb_corr_map_NorESM NI_HC200_glb_corr_map_CESM NI_HC200_glb_corr_map_MPIESM tr
'SM_reana' tr
SM_HC200_glb_corr_map_MODELS_MEAN SM_HC200_glb_corr_map_NorESM SM_HC200_glb_corr_map_CESM SM_HC200_glb_corr_map_MPIESM tr
'SM_reana - NI_reana' tr
DIFF_HC200_glb_corr_diff_map_MODELS_MEAN DIFF_HC200_glb_corr_diff_map_NorESM DIFF_HC200_glb_corr_diff_map_CESM DIFF_HC200_glb_corr_diff_map_MPIESM tr
'RMSE (with-bias): HC200
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_HC200_glb_rmse_wBias_map_MODELS_MEAN NI_HC200_glb_rmse_wBias_map_NorESM NI_HC200_glb_rmse_wBias_map_CESM NI_HC200_glb_rmse_wBias_map_MPIESM tr
'SM_reana' tr
SM_HC200_glb_rmse_wBias_map_MODELS_MEAN SM_HC200_glb_rmse_wBias_map_NorESM SM_HC200_glb_rmse_wBias_map_CESM SM_HC200_glb_rmse_wBias_map_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_HC200_glb_rmse_wBias_diff_map_MODELS_MEAN DIFF_HC200_glb_rmse_wBias_diff_map_NorESM DIFF_HC200_glb_rmse_wBias_diff_map_CESM DIFF_HC200_glb_rmse_wBias_diff_map_MPIESM tr
'Correlation: SC200 anomaly
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SC200_glb_corr_map_MODELS_MEAN NI_SC200_glb_corr_map_NorESM NI_SC200_glb_corr_map_CESM NI_SC200_glb_corr_map_MPIESM tr
'SM_reana' tr
SM_SC200_glb_corr_map_MODELS_MEAN SM_SC200_glb_corr_map_NorESM SM_SC200_glb_corr_map_CESM SM_SC200_glb_corr_map_MPIESM tr
'SM_reana - NI_reana' tr
DIFF_SC200_glb_corr_diff_map_MODELS_MEAN DIFF_SC200_glb_corr_diff_map_NorESM DIFF_SC200_glb_corr_diff_map_CESM DIFF_SC200_glb_corr_diff_map_MPIESM tr
'RMSE (with-bias): SC200
' tr
'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' tr
'NI_reana' tr
NI_SC200_glb_rmse_wBias_map_MODELS_MEAN NI_SC200_glb_rmse_wBias_map_NorESM NI_SC200_glb_rmse_wBias_map_CESM NI_SC200_glb_rmse_wBias_map_MPIESM tr
'SM_reana' tr
SM_SC200_glb_rmse_wBias_map_MODELS_MEAN SM_SC200_glb_rmse_wBias_map_NorESM SM_SC200_glb_rmse_wBias_map_CESM SM_SC200_glb_rmse_wBias_map_MPIESM tr
'NI_reana - SM_reana' tr
DIFF_SC200_glb_rmse_wBias_diff_map_MODELS_MEAN DIFF_SC200_glb_rmse_wBias_diff_map_NorESM DIFF_SC200_glb_rmse_wBias_diff_map_CESM DIFF_SC200_glb_rmse_wBias_diff_map_MPIESM tr
)
## number of figures in a row
## should be a array
ncolarr=${#column[*]}
thumb="THUMBNAIL"
#export MAGICK_THREAD_LIMIT=1 ## avoid "libgomp: Thread creation failed"
# html header
text=$'\n'
text+=$'\n'
text+=$'\n'
text+=$'\n'
# put title on top
text+=$'\n'
nl=$'\n' #newline
# convert ps to png and output entry to html
pid=$$
row=1
icol=0
text+=""$'\n'
text+=""$'\n'
# if column start with non integer
while [ ! -z "${column[$icol]}" ] ; do
dst="${column[$icol]}"
if [ "${dst}" = 'tr' ]; then
dst='
'$'\n'''
fi
if [ "${dst}" = '
' ]; then
text+="${dst}"$'\n'
else
text+="| "$(fig2png "${dst}")" | "$'\n'
fi
icol=$(( $icol + 1))
done
wait
## show figures with table
text+="
"$'\n'
text+="
"$'\n'
# html footer
text+=$'\n'
text+=$' \n'
# output to html file
echo "${text}" > "${htmlfn}"