/* -*- c -*-
 * Time-stamp: <2005-04-17 09:57:49 rsmith>
 * 
 * lamprop/html_out.c
 * Copyright (C) 2002--2005 R.F. Smith <rsmith@xs4all.nl>. 
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

/* If you don't want debugging, #define NDEBUG */

#include <assert.h>	/* for assert() */
#include <math.h>       /* for M_PI */
#include <stdio.h>	/* for printf() */
#include "macros.h"
#include "lamprop.h"

#ifndef PACKAGE
#error You must define PACKAGE as the name of the application!
#endif

#ifndef VERSION
#error You must define VERSION as the version of the application!
#endif


/* This enables you to see which files have been used in building a
 * binary. N.B, __attribute is a GCC extension, so we test for __GNUC__. */
#ifdef __GNUC__
static char *SCMID __attribute__ ((unused)) = 
"$Id: html_out.c 36 2005-04-17 09:40:02Z rsmith $";
#endif

static const char *fstr[6] = {
	"N<sub>x</sub>",
	"N<sub>y</sub>",
	"N<sub>xy</sub>",
	"M<sub>x</sub>",
	"M<sub>y</sub>",
	"M<sub>xy</sub>"
};

static const char *dstr[6] = {
	"&epsilon;<sub>x</sub>",
	"&epsilon;<sub>y</sub>",
	"&gamma;<sub>xy</sub>",
	"&kappa;<sub>x</sub>",
	"&kappa;<sub>y</sub>",
	"&kappa;<sub>xy</sub>"
};

static void html_engprop(const struct laminate *pl)
{
 	int t = 1;
 	struct lamina *l;

	puts("        <!-- first row; tables -->");
	puts("        <tr>");
	puts("          <td>");
	puts("            <table border=\"1\" frame=\"hsides\"");
	puts("              rules=\"groups\" cellpadding=\"5%%\">");
	puts("              <caption><strong>Laminate stacking"\
	       "</strong></caption>");
	puts("              <thead align=\"right\">");
	puts("                <tr>");
	puts("                  <td>Layer</td><td>Weight</td>");
	puts("                  <td>Angle</td><td align=\"left\">"\
	       "Fiber type</td>");
	puts("                </tr>");
	puts("                <tr>");
	puts("                  <td></td><td>[gr/m&sup2;]</td>"\
	       "<td>[&deg;]</td>");
	puts("                </tr>");
	puts("              </thead>");
	puts("              <tbody align=\"right\">");
	l = (struct lamina *)list_head(pl->lamina);
	while (l != NULL) {
		puts("                <tr>");
		printf("                  <td>%d</td><td>%4.0f</td>"\
		       "<td>%5.0f</td>\n", t++, l->weight, l->angle*180/M_PI);
		printf("                  <td align=\"left\">%s</td>\n",
		       l->f->name);
		puts("                </tr>");
		l = (struct lamina *)list_next(LISTP(l));
	}
	puts("              </tbody>");
	puts("            </table>");
	puts("          </td>");
	puts("          <td>");
	puts("            <table border=\"1\" frame=\"hsides\""\
	       " rules=\"groups\" cellpadding=\"5%%\">");
	puts("              <caption><strong>Engineering properties"\
	       "</strong></caption>");
	puts("              <thead align=\"right\">");
	puts("                <tr>");
	puts("                  <td>Property</td><td>Value</td>");
	puts("                  <td align=\"left\">Dimension</td>");
	puts("                </tr>");
	puts("              </thead>");
	puts("              <tbody align=\"right\">");
	puts("                <tr>");
	printf("                  <td>v<sub>f</sub></td>"\
	       "<td>%4.2f</td><td align=\"left\">-</td>\n", pl->vf);
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>w<sub>f</sub></td>"\
	       "<td>%4.2f</td><td align=\"left\">-</td>\n", pl->wf);
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>thickness</td><td>%.3g</td>\n", pl->t);
	puts("                  <td align=\"left\">mm</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>density</td><td>%.3g</td>\n", pl->rho);
	puts("                  <td align=\"left\">gr/cm&sup3;</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>weight</td><td>%.0f</td>\n", 
	       pl->rho*pl->t/10*100*100);
	puts("                  <td align=\"left\">gr/m&sup2;</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>resin</td><td>%.0f</td>\n", pl->rc);
	puts("                  <td align=\"left\">gr/m&sup2;</td>");
	puts("                </tr>");
	puts("              </tbody>");
	puts("              <tbody align=\"right\">");
	puts("                <tr>");
	printf("                  <td>E<sub>x</sub></td><td>%8.0f</td>\n",
	       pl->Ex);
	puts("                  <td align=\"left\">MPa</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>E<sub>y</sub></td><td>%8.0f</td>\n",
	       pl->Ey);
	puts("                  <td align=\"left\">MPa</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>G<sub>xy</sub></td><td>%8.0f</td>\n",
	       pl->Gxy);
	puts("                  <td align=\"left\">MPa</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>&nu;<sub>xy</sub></td><td>%g</td>\n", 
	       pl->Vxy);
	puts("                  <td align=\"left\">-</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>&nu;<sub>yx</sub></td><td>%g</td>\n", 
	       pl->Vyx);
	puts("                  <td align=\"left\">-</td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>&alpha;<sub>x</sub></td><td>%g</td>\n", 
	       pl->cte_x);
	puts("                  <td align=\"left\">K<sup>-1</sup></td>");
	puts("                </tr>");
	puts("                <tr>");
	printf("                  <td>&alpha;<sub>y</sub></td><td>%g</td>\n", 
	       pl->cte_y);
	puts("                  <td align=\"left\">K<sup>-1</sup></td>");
	puts("                </tr>");
	puts("              </tbody>");
	puts("            </table>");
	puts("          </td>");
	puts("        </tr>");
}

static void html_mat(const struct laminate *pl)
{
 	int t = 0;

	puts("        <tr>");
	puts("          <!-- second row, stiffness matrix -->");
	puts("          <td colspan=\"2\">");
	puts("            <table border=\"1\" frame=\"vsides\" "\
	       "rules=\"groups\" cellpadding=\"5%%\">");
	puts("              <caption><strong>Stiffness matrix</strong>"\
	       "</caption>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <colgroup span=\"6\"></colgroup>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <tbody align=\"center\">");
	puts("                <tr>");
	printf("                  <td>%s</td>\n", fstr[t]);
	puts("                  <td rowspan=\"6\">=</td>");
	printf("                  <td>%6.0f</td><td>%6.0f</td>"\
	       "<td>%6.0f</td>\n", pl->ABD[t][0], pl->ABD[t][1], 
	       pl->ABD[t][2]);
	printf("                  <td>%6.0f</td><td>%6.0f</td>"\
	       "<td>%6.0f</td>\n", pl->ABD[t][3], pl->ABD[t][4], 
	       pl->ABD[t][5]);
	puts("                  <td rowspan=\"6\">&times;</td>");
	printf("                  <td>%s</td>\n", dstr[t]);
	puts("                </tr>");
	for (t=1; t<6; t++) {
		puts("                <tr>");
		printf("                  <td>%s</td>\n", fstr[t]);
		printf("                  <td>%6.0f</td><td>%6.0f</td>"\
		       "<td>%6.0f</td>\n", pl->ABD[t][0], pl->ABD[t][1], 
		       pl->ABD[t][2]);
		printf("                  <td>%6.0f</td><td>%6.0f</td>"\
		       "<td>%6.0f</td>\n", pl->ABD[t][3], pl->ABD[t][4], 
		       pl->ABD[t][5]);
		printf("                  <td>%s</td>\n", dstr[t]);
		puts("                </tr>");
	}
	puts("              </tbody>");
	puts("            </table>");
	puts("          </td>");
	puts("        </tr>");
	puts("        <tr>");
	puts("          <!-- third row, compliance matrix -->");
	puts("          <td colspan=\"2\">");
	puts("            <table border=\"1\" frame=\"vsides\" "\
	       "rules=\"groups\" cellpadding=\"5%%\">");
	puts("              <caption><strong>Compliance matrix</strong>"\
	       "</caption>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <colgroup span=\"6\"></colgroup>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <colgroup span=\"1\"></colgroup>");
	puts("              <tbody align=\"center\">");
	t=0;
	puts("                <tr>");
	printf("                  <td>%s</td>\n", dstr[t]);
	puts("                  <td rowspan=\"6\">=</td>");
	printf("                  <td>%6.3g</td><td>%6.3g</td>"\
	       "<td>%6.3g</td>\n", pl->abd[t][0]*1e6, pl->abd[t][1]*1e6, 
	       pl->abd[t][2]*1e6);
	printf("                  <td>%6.3g</td><td>%6.3g</td>"\
	       "<td>%6.3g</td>\n", pl->abd[t][3]*1e6, pl->abd[t][4]*1e6, 
	       pl->abd[t][5]*1e6);
	puts("                  <td rowspan=\"6\">&times;10"\
	       "<sup>-6</sup>&times;</td>");
	printf("                  <td>%s</td>\n", fstr[t]);
	puts("                </tr>");
	for (t=1; t<6; t++) {
		puts("                <tr>");
		printf("                  <td>%s</td>\n", dstr[t]);
		printf("                  <td>%6.3g</td><td>%6.3g</td>"\
		       "<td>%6.3g</td>\n", pl->abd[t][0]*1e6, 
		       pl->abd[t][1]*1e6, pl->abd[t][2]*1e6);
		printf("                  <td>%6.3g</td><td>%6.3g</td>"\
		       "<td>%6.3g</td>\n", pl->abd[t][3]*1e6, 
		       pl->abd[t][4]*1e6, pl->abd[t][5]*1e6);
		printf("                  <td>%s</td>\n", fstr[t]);
		puts("                </tr>");
	}
	puts("              </tbody>");
	puts("            </table>");
	puts("          </td>");
	puts("        </tr>");
}

void html_output(const struct laminate *pl, unsigned flags)
{
	assert(pl!=NULL);
	puts("    <!-- outer table -->");
	puts("    <table cellpadding=\"10%%\">");
	printf("      <caption><strong>Properties of %s</strong></caption>\n",
	       pl->name);
	puts("      <tbody align=\"center\">");
	puts("        <tr>");
	puts("          <td  align=\"center\" colspan=\"2\">"\
	       "created by "PACKAGE" "VERSION".</td>");
	puts("        </tr>");
	if ((flags & OF_ENGPROP) == OF_ENGPROP)
		html_engprop(pl);
	if ((flags & OF_MAT) == OF_MAT)
		html_mat(pl);
	puts("      </tbody>");
	puts("    </table>");
	puts("    <hr />");
}

/* EOF html_out.c */


syntax highlighted by Code2HTML, v. 0.9.1