Пример #1
0
func pvd_write(buf *bytes.Buffer, label string) {
	if buf == nil {
		return
	}
	io.Ff(buf, "</Collection>\n</VTKFile>")
	io.WriteFileV(io.Sf("%s/%s_%s.pvd", dirout, fnkey, label), buf)
}
Пример #2
0
func main() {

	// catch errors
	defer func() {
		if err := recover(); err != nil {
			io.PfRed("ERROR: %v\n", err)
		}
	}()

	// input data
	matfn, fnk := io.ArgToFilename(0, "materials", ".mat", true)
	io.Pf("\n%s\n", io.ArgsTable(
		"material filename", "matfn", matfn,
	))

	// skip variables
	skip := "gref nowet α"

	// skip parameters
	skipp := make(map[string]bool)
	for _, key := range io.SplitKeys(skip) {
		skipp[key] = true
	}

	// Read
	mdb := inp.ReadMat("", matfn)

	// Get max number of parameters
	nmaxprms := 0
	for _, mdat := range mdb.Materials {
		n := len(mdat.Prms)
		if n > nmaxprms {
			nmaxprms = n
		}
	}

	// header
	b := new(bytes.Buffer)
	io.Ff(b, "\\documentclass[12pt,a4paper]{article}\n")
	io.Ff(b, "\\usepackage[margin=2.0cm,footskip=0.5cm]{geometry}\n")
	io.Ff(b, "\\usepackage[labelfont=bf,tableposition=top,aboveskip=4pt]{caption}\n")
	io.Ff(b, "\\usepackage{tabularx}\n")
	io.Ff(b, "\\usepackage{booktabs}\n")
	io.Ff(b, "\n")
	io.Ff(b, "\\title{Materials Table}\n")
	io.Ff(b, "\\author{GoFem MatTable tool}\n")
	io.Ff(b, "\n")
	io.Ff(b, "\\begin{document}\n")
	io.Ff(b, "\\maketitle\n")

	// table with parameters
	io.Ff(b, "\n")
	io.Ff(b, "\\begin{table} \\centering\n")
	io.Ff(b, "\\caption{Parameters from %s}\n", matfn)
	io.Ff(b, "\\begin{tabularx}{\\linewidth}[c]{l %s} \\toprule\n", strings.Repeat("c", nmaxprms))

	for i, mdat := range mdb.Materials {
		necols := nmaxprms - len(mdat.Prms) // number of empty cols

		// mat name
		io.Ff(b, "  %-20s", mdat.Name)

		// parameters names
		for _, param := range mdat.Prms {
			io.Ff(b, " &%12s", ToTex(param.N))
		}

		io.Ff(b, " %s", strings.Repeat(" &", necols))
		io.Ff(b, " \\\\\n")

		// values
		io.Ff(b, "  %-20s", "")
		for _, param := range mdat.Prms {
			io.Ff(b, " &%12s", NumFormat(param.V))
		}

		io.Ff(b, " %s", strings.Repeat(" &", necols))
		io.Ff(b, " \\\\\n")

		// units
		io.Ff(b, "  %-20s", "")
		for _, param := range mdat.Prms {
			if param.U == "" {
				io.Ff(b, " &%12v", "-")
			} else {
				io.Ff(b, " &%12v", UnitFormat(param.U))
			}
		}

		io.Ff(b, " %s", strings.Repeat(" &", necols))
		io.Ff(b, " \\\\\n")

		if i < len(mdb.Materials)-1 {
			io.Ff(b, "  \\\\\n")
		}
	}

	// footer
	io.Ff(b, "  \\bottomrule\n\\end{tabularx}\n\\label{tab:prms}\n\\end{table}\n")
	io.Ff(b, "\\end{document}\n")
	io.WriteFileV(fnk+".tex", b)

}