/* Ltas.c */
/* Paul Boersma, June 4, 2002 */

#include "Ltas.h"

class_methods (Ltas, Vector)
class_methods_end

Ltas Ltas_create (long nx, double dx) {
	Ltas me = new (Ltas);
	if (! me || ! Matrix_init (me, 0, nx * dx, nx, dx, 0.5 * dx, 1, 1, 1, 1, 1)) return NULL;
	return me;
}

void Ltas_draw (Ltas me, Graphics g, double fmin, double fmax, double minimum, double maximum, int garnish) {
	long ifreq, ifmin, ifmax;

	if (fmax <= fmin) { fmin = my xmin; fmax = my xmax; }
	if (! Matrix_getWindowSamplesX (me, fmin, fmax, & ifmin, & ifmax)) return;

	Graphics_setWindow (g, fmin, fmax, minimum, maximum);
	Graphics_setInner (g);
	for (ifreq = ifmin; ifreq <= ifmax; ifreq ++) {
		double yWC = my z [1] [ifreq];
		double f = Sampled_indexToX (me, ifreq);
		double left = f - 0.5 * my dx, right = f + 0.5 * my dx;
		if (yWC < minimum) yWC = minimum;
		if (left < fmin) left = fmin;
		if (right > fmax) right = fmax;
		Graphics_line (g, left, yWC, right, yWC);
		Graphics_line (g, left, yWC, left, minimum);
		Graphics_line (g, right, yWC, right, minimum);
	}
	Graphics_unsetInner (g);

	if (garnish) {
		Graphics_drawInnerBox (g);
		Graphics_textBottom (g, 1, "Frequency (Hz)");
		Graphics_marksBottom (g, 2, 1, 1, 0);
		Graphics_textLeft (g, 1, "Sound pressure level (dB/Hz)");
		Graphics_marksLeft (g, 2, 1, 1, 0);
	}
}

Matrix Ltas_to_Matrix (Ltas me) {
	Matrix thee = Data_copy (me);
	if (! thee) return NULL;
	Thing_overrideClass (thee, classMatrix);
	return thee;
}

Ltas Matrix_to_Ltas (Matrix me) {
	Ltas thee = Data_copy (me);
	if (! thee) return NULL;
	Thing_overrideClass (thee, classLtas);
	return thee;
}

/* End of file Ltas.c */
