Exemplo n.º 1
0
func tex_results(dirout, fnkey, title, label string, dat *FemData, A, B, C, D, E *goga.Solution, document, compact bool) {
	if len(A.Flt) != 10 {
		chk.Panic("tex_results works with len(Areas)==10 only\n")
		return
	}
	buf := new(bytes.Buffer)
	if document {
		io.Ff(buf, `\documentclass[a4paper]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{booktabs}
\usepackage[margin=1.5cm,footskip=0.5cm]{geometry}

\title{GOGA Report}
\author{Dorival Pedroso}

\begin{document}

`)
	}
	io.Ff(buf, `\begin{table} \centering
\caption{%s}
`, title)
	if compact {
		io.Ff(buf, `\begin{tabular}[c]{cccccccc} \toprule
point & weight & deflection &  $A_0$ & $A_1$ & $A_2$ & $A_3$ & $A_4$   \\
      &        &            &  $A_5$ & $A_6$ & $A_7$ & $A_8$ & $A_9$   \\ \hline
`)
	} else {
		io.Ff(buf, `\begin{tabular}[c]{ccccccccccccc} \toprule
point & weight & deflection & $A_0$ & $A_1$ & $A_2$ & $A_3$ & $A_4$ & $A_5$ & $A_6$ & $A_7$ & $A_8$ & $A_9$ \\ \hline
`)
	}

	writeline := func(pt string, E []int, A []float64) {
		_, _, weight, deflection, _, _, _ := dat.RunFEM(E, A, 0, false)
		if compact {
			io.Ff(buf, "%s & $%.2f$ & $%.6f$ &  $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ \\\\\n", pt, weight, deflection, A[0], A[1], A[2], A[3], A[4])
			io.Ff(buf, "   &        &        &  $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ \\\\\n", A[5], A[6], A[7], A[8], A[9])
		} else {
			io.Ff(buf, "%s & $%.2f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ & $%.6f$ \\\\\n", pt, weight, deflection, A[0], A[1], A[2], A[3], A[4], A[5], A[6], A[7], A[8], A[9])
		}
	}

	writeline("A", A.Int, A.Flt)
	writeline("B", B.Int, B.Flt)
	writeline("C", C.Int, C.Flt)
	writeline("D", D.Int, D.Flt)
	writeline("E", E.Int, E.Flt)

	io.Ff(buf, `
\bottomrule
\end{tabular}
\label{tab:%s}
\end{table}
`, label)
	if document {
		io.Ff(buf, ` \end{document}`)
	}

	tex := fnkey + ".tex"
	if document {
		io.WriteFileD(dirout, tex, buf)
		_, err := io.RunCmd(true, "pdflatex", "-interaction=batchmode", "-halt-on-error", "-output-directory=/tmp/goga/", tex)
		if err != nil {
			chk.Panic("%v", err)
		}
		io.PfBlue("file <%s/%s.pdf> generated\n", dirout, fnkey)
	} else {
		io.WriteFileVD(dirout, tex, buf)
	}
}
Exemplo n.º 2
0
// Generate generates report
func (o *TexReport) Generate() {

	// functions
	o.col4 = "error"
	o.col5 = io.Sf("histogram ($N_{samples}=%d$)", o.nsamples)
	addHeader := o.normalTableHeader
	addRow := o.oneNormalAddRow
	switch o.Type {
	case 1:
		o.col4 = "objective"
	case 2:
		o.col5 = "spread"
		addRow = o.twoAddRow
	case 3:
		addRow = o.multiAddRow
	case 4:
		addHeader = o.compactTableHeader
		addRow = o.oneCompactAddRow
	}

	// number of rows per table
	nRowPerTab := o.NRowPerTab
	if nRowPerTab < 1 {
		nRowPerTab = len(o.Opts)
	}
	if o.RefLabel == "" {
		o.RefLabel = o.Fnkey
	}

	// input and xres tables
	o.inputHeader()
	o.xResHeader()

	// add rows
	idxtab := 0
	contd := ""
	for i, opt := range o.Opts {
		if i%nRowPerTab == 0 {
			if i > 0 {
				o.tableFooter(idxtab) // end previous table
				io.Ff(o.buf, "\n\n\n")
				contd = " (contd.)"
				idxtab++
			}
			addHeader(contd) // begin new table
		} else {
			if i > 0 {
				if o.Type != 4 {
					io.Ff(o.buf, "\\hline\n")
				}
				//io.Ff(o.bxres, "\n\\hline\n")
				io.Ff(o.buf, "\n")
			}
		}
		addRow(opt)
		o.inputRow(opt)
		o.xResRow(opt)
	}

	// close tables
	o.inputFooter()
	io.Ff(o.binp, "\n\n\n")
	o.xResFooter()
	o.tableFooter(idxtab) // end previous table
	io.Ff(o.buf, "\n\n\n")

	// write table
	tex := o.Fnkey + ".tex"
	io.WriteFileVD(o.DirOut, tex, o.buf, o.binp, o.bxres)

	// generate PDF
	if o.RunPDF {
		header := new(bytes.Buffer)
		footer := new(bytes.Buffer)
		str := ""
		if o.UseGeom {
			str = `\usepackage[margin=1.5cm,footskip=0.5cm]{geometry}`
		}
		io.Ff(header, `\documentclass[a4paper]{article}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{booktabs}
%s

\title{GOGA Report}
\author{Dorival Pedroso}

\begin{document}
`, str)
		io.Ff(footer, `
\end{document}`)

		// write temporary TeX file
		tex = "tmp_" + tex
		io.WriteFileD(o.DirOut, tex, header, o.buf, o.binp, o.bxres, footer)

		// run pdflatex
		_, err := io.RunCmd(false, "pdflatex", "-interaction=batchmode", "-halt-on-error", "-output-directory="+o.DirOut, tex)
		if err != nil {
			io.PfRed("pdflatex failed: %v\n", err)
			return
		}
		io.PfBlue("file <%s/tmp_%s.pdf> generated\n", o.DirOut, o.Fnkey)
	}
}