#! /bin/bash
# Last edited on 2017-10-03 12:26:15 by jstolfi
# To be sourced into other ".sh" report files.

function monoplot() {
  # Shows plot of a run without its spectrum.
  run="$1"; shift     # Name of the run file, minus the ".txt"
  pwidth="$1"; shift  # Width as percentage of widow width.
  printf "  <br/>\n"
  printf "  <center>\n"
  printf "    <small><b>${run##*/}</b></small><br/>\n"
  printf "    <a href=\"${run}.png\"><img src=\"${run}.png\" width=\"${pwidth}%%\"></a><br/>\n"
  printf "  </center>\n"
  printf "  <br/>\n"
  figs[${#figs[@]}]="${run}.png"
}

function biplot() {
  # Shows plots of a run and its spectrum.
  run="$1"; shift     # Name of the run file, minus the ".txt"
  pwidth="$1"; shift  # Width as percentage of widow width.
  printf "  <br/>\n"
  printf "  <center>\n"
  printf "    <small><b>${run##*/}</b></small><br/>\n"
  printf "    <a href=\"${run}.png\"><img src=\"${run}.png\" width=\"${pwidth}%%\"></a>\n"
  printf "    <a href=\"${run}_pwr.png\"><img src=\"${run}_pwr.png\" width=\"${pwidth}%%\"></a><br/>\n"
  printf "  </center>\n"
  printf "  <br/>\n"
  figs[${#figs[@]}]="${run}.png"
  figs[${#figs[@]}]="${run}_pwr.png"
}

function twoplots() {
  # Shows two figures side by side.
  filea="$1"; shift     # Name of the first file, minus the ".png"
  fileb="$1"; shift     # Name of the first file, minus the ".png"
  pwidth="$1"; shift  # Width as percentage of widow width.
  printf "  <br/>\n"
  printf "  <center>\n"
  printf "    <table cellpadding=\"2px\" border=\"0px\" cellborder=\"0px\">\n"
  printf "      <tr>\n"
  printf "        <td align=center><small><b>${filea##*/}</b></small></td>\n"
  printf "        <td>&nbsp;</td>\n"
  printf "        <td align=center><small><b>${fileb##*/}</b></small></td>\n"
  printf "      </tr>\n"
  printf "      <tr>\n"
  printf "        <td width=\"${pwidth}%%\" align=center><a href=\"${filea}.png\"><img src=\"${filea}.png\" width=\"95%%\"></a></td>\n"
  printf "        <td width=\"10px\">&nbsp;</td>\n"
  printf "        <td width=\"${pwidth}%%\" align=center><a href=\"${fileb}.png\"><img src=\"${fileb}.png\" width=\"95%%\"></a></td>\n"
  printf "      </tr>\n"
  printf "    </table>\n"
  printf "  </center>\n"
  printf "  <br/>\n"
  figs[${#figs[@]}]="${filea}.png"
  figs[${#figs[@]}]="${fileb}.png"
}

function compplots() {
  # Shows a component pattern and its trace side by side.
  filea="$1"; shift     # Name of the first file, minus the ".png"
  widtha="$1"; shift  # Width as percentage of widow width.
  fileb="$1"; shift     # Name of the first file, minus the ".png"
  widthb="$1"; shift  # Width as percentage of widow width.
  printf "  <br/>\n"
  printf "  <center>\n"
  printf "    <table cellpadding=\"2px\" border=\"0px\" cellborder=\"0px\">\n"
  printf "      <tr>\n"
  printf "        <td align=center><small><b>${filea##*/}</b></small></td>\n"
  printf "        <td>&nbsp;</td>\n"
  printf "        <td>&nbsp;</td>\n"
  printf "      </tr>\n"
  printf "      <tr>\n"
  if [[ "${filea}" != "NONE" ]]; then
    printf "        <td width=\"${widtha}%%\" align=center><a href=\"${filea}.png\"><img src=\"${filea}.png\" width=\"95%%\"></a></td>\n"
  else
    printf "        <td width=\"${widtha}%%\">&nbsp;</td>\n"
  fi
  printf "        <td width=\"10px\">&nbsp;</td>\n"
  if [[ "${fileb}" != "NONE" ]]; then
    printf "        <td width=\"${widthb}%%\" align=center><a href=\"${fileb}.png\"><img src=\"${fileb}.png\" width=\"95%%\"></a></td>\n"
  else
    printf "        <td width=\"${widthb}%%\">&nbsp;</td>\n"
  fi
  printf "      </tr>\n"
  printf "    </table>\n"
  printf "  </center>\n"
  printf "  <br/>\n"
  figs[${#figs[@]}]="${filea}.png"
  figs[${#figs[@]}]="${fileb}.png"
}

