#!/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_by_season.html" comment="Supermodel seasonal hindcast initialised using supermodel reanalysis: SST RMSD 1990-2020" title="TITLE" column=( 'SST Corr' tr 'NI_reana' tr 'MODELS_MEAN' 'NorESM' 'CESM' 'MPIESM' 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 '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 'SM_reana - NI_reana' tr SM_DIFF_SST_glb_corr_map_MODELS_MEAN SM_DIFF_SST_glb_corr_map_NorESM SM_DIFF_SST_glb_corr_map_CESM SM_DIFF_SST_glb_corr_map_MPIESM ) ## 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 comment on top text+=$'
\n' text+=$'

\n' text+=$'

\n' text+="$comment" text+=$'

\n' #text+=$'

\n' 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+=""$'\n' fi icol=$(( $icol + 1)) done wait ## show figures with table text+=""$'\n' text+="
"$(fig2png "${dst}")"
"$'\n' # html footer text+=$'\n' text+=$' \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} ${nl}" entryhtml="${entryhtml} ${nl}" entryhtml="${entryhtml}

${title}

${nl}" entryhtml="${entryhtml} ${nl}" entryhtml="${entryhtml}
${nl}" entryhtml="${entryhtml}
${comment}
${nl}" entryhtml="${entryhtml} ${nl}" entryhtml="${entryhtml}
${nl}" entryhtml="${entryhtml} ${nl}" entryhtml="${entryhtml}
${nl}" fi