Example #1
0
void
print_table(struct curve_points *current_plot, int plot_num)
{
    int i, curve;
    char *buffer = gp_alloc(BUFFERSIZE, "print_table: output buffer");
    outfile = (table_outfile) ? table_outfile : gpoutfile;

    for (curve = 0; curve < plot_num;
	 curve++, current_plot = current_plot->next) {
	struct coordinate GPHUGE *point = NULL;

	/* two blank lines between tabulated plots by prepending \n here */
	fprintf(outfile, "\n# Curve %d of %d, %d points",
		curve, plot_num, current_plot->p_count);

	if ((current_plot->title) && (*current_plot->title)) {
	    char *title = expand_newline(current_plot->title);
    	    fprintf(outfile, "\n# Curve title: \"%s\"", title);
	    free(title);
	}

	fprintf(outfile, "\n# x y");
	switch (current_plot->plot_style) {
	case BOXES:
	case XERRORBARS:
	    fputs(" xlow xhigh", outfile);
	    break;
	case BOXERROR:
	case YERRORBARS:
	    fputs(" ylow yhigh", outfile);
	    break;
	case BOXXYERROR:
	case XYERRORBARS:
	    fputs(" xlow xhigh ylow yhigh", outfile);
	    break;
	case FILLEDCURVES:
	    fputs("1 y2", outfile);
	    break;
	case FINANCEBARS:
	    fputs(" open ylow yhigh yclose", outfile);
	    break;
	case CANDLESTICKS:
	    fputs(" open ylow yhigh yclose width", outfile);
	    break;
	case LABELPOINTS:
	    fputs(" label",outfile);
	    break;
	case VECTOR:
	    fputs(" delta_x delta_y",outfile);
	    break;
	case LINES:
	case POINTSTYLE:
	case LINESPOINTS:
	case DOTS:
	case IMPULSES:
	case STEPS:
	case FSTEPS:
	case HISTEPS:
	    break;
	case IMAGE:
	    fputs("  pixel", outfile);
	    break;
	case RGBIMAGE:
	case RGBA_IMAGE:
	    fputs("  red green blue alpha", outfile);
	    break;

	default:
	    if (interactive)
		fprintf(stderr, "Tabular output of %s plot style not fully implemented\n",
		    current_plot->plot_style == HISTOGRAMS ? "histograms" :
		    "this");
	    break;
	}

	fputs(" type\n", outfile);

	if (current_plot->plot_style == LABELPOINTS) {
	    struct text_label *this_label;
	    for (this_label = current_plot->labels->next; this_label != NULL;
		 this_label = this_label->next) {
		 char *label = expand_newline(this_label->text);
		 OUTPUT_NUMBER(this_label->place.x, current_plot->x_axis);
		 OUTPUT_NUMBER(this_label->place.y, current_plot->y_axis);
		fprintf(outfile, " \"%s\"\n", label);
		free(label);
	    }

	} else {
	    int plotstyle = current_plot->plot_style;
	    if (plotstyle == HISTOGRAMS && current_plot->histogram->type == HT_ERRORBARS)
		plotstyle = YERRORBARS;

	    for (i = 0, point = current_plot->points; i < current_plot->p_count;
		i++, point++) {

		/* FIXME HBB 20020405: had better use the real x/x2 axes of this plot */
		OUTPUT_NUMBER(point->x, current_plot->x_axis);
		OUTPUT_NUMBER(point->y, current_plot->y_axis);

		switch (plotstyle) {
		    case BOXES:
		    case XERRORBARS:
			OUTPUT_NUMBER(point->xlow, current_plot->x_axis);
			OUTPUT_NUMBER(point->xhigh, current_plot->x_axis);
			/* Hmmm... shouldn't this write out width field of box
			 * plots, too, if stored? */
			break;
		    case BOXXYERROR:
		    case XYERRORBARS:
			OUTPUT_NUMBER(point->xlow, current_plot->x_axis);
			OUTPUT_NUMBER(point->xhigh, current_plot->x_axis);
			/* FALLTHROUGH */
		    case BOXERROR:
		    case YERRORBARS:
			OUTPUT_NUMBER(point->ylow, current_plot->y_axis);
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			break;
		    case IMAGE:
			fprintf(outfile,"%g ",point->z);
			break;
		    case RGBIMAGE:
		    case RGBA_IMAGE:
			fprintf(outfile,"%4d ",(int)point->CRD_R);
			fprintf(outfile,"%4d ",(int)point->CRD_G);
			fprintf(outfile,"%4d ",(int)point->CRD_B);
			fprintf(outfile,"%4d ",(int)point->CRD_A);
			break;
		    case FILLEDCURVES:
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			break;
		    case FINANCEBARS:
			OUTPUT_NUMBER(point->ylow, current_plot->y_axis);
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			OUTPUT_NUMBER(point->z, current_plot->y_axis);
			break;
		    case CANDLESTICKS:
			OUTPUT_NUMBER(point->ylow, current_plot->y_axis);
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			OUTPUT_NUMBER(point->z, current_plot->y_axis);
			OUTPUT_NUMBER(2. * (point->x - point->xlow), current_plot->x_axis);
			break;
		    case VECTOR:
			OUTPUT_NUMBER((point->xhigh - point->x), current_plot->x_axis);
			OUTPUT_NUMBER((point->yhigh - point->y), current_plot->y_axis);
			break;
		    case LINES:
		    case POINTSTYLE:
		    case LINESPOINTS:
		    case DOTS:
		    case IMPULSES:
		    case STEPS:
		    case FSTEPS:
		    case HISTEPS:
			break;
		    default:
			/* ? */
			break;
		} /* switch(plot type) */
		fprintf(outfile, " %c\n",
		    current_plot->points[i].type == INRANGE
		    ? 'i' : current_plot->points[i].type == OUTRANGE
		    ? 'o' : 'u');
	    } /* for(point i) */
	}

	putc('\n', outfile);
    } /* for(curve) */

    fflush(outfile);
    free(buffer);
}
Example #2
0
void
print_table(struct curve_points *current_plot, int plot_num)
{
    int i, curve;
    char *buffer = (char *) gp_alloc(BUFFERSIZE, "print_table: output buffer");
    size_t size = 2*BUFFERSIZE;
    char *line = (char *) gp_alloc(size, "print_table: line buffer");
    size_t len = 0;

    outfile = (table_outfile) ? table_outfile : gpoutfile;

    for (curve = 0; curve < plot_num;
	 curve++, current_plot = current_plot->next) {
	struct coordinate *point = NULL;

	/* "with table" already wrote the output */
	if (current_plot->plot_style == TABLESTYLE)
	    continue;

	/* two blank lines between tabulated plots by prepending an empty line here */
	print_line("");
	snprintf(line, size, "# Curve %d of %d, %d points",
		curve, plot_num, current_plot->p_count);
	print_line(line);

	if ((current_plot->title) && (*current_plot->title)) {
	    char *title = expand_newline(current_plot->title);
	    snprintf(line, size, "# Curve title: \"%s\"", title);
	    print_line(line);
	    free(title);
	}

	len = snprintf(line, size, "# x y");
	switch (current_plot->plot_style) {
	case BOXES:
	case XERRORBARS:
	    len = strappend(&line, &size, len, " xlow xhigh");
	    break;
	case BOXERROR:
	case YERRORBARS:
	    len = strappend(&line, &size, len, " ylow yhigh");
	    break;
	case BOXXYERROR:
	case XYERRORBARS:
	    len = strappend(&line, &size, len, " xlow xhigh ylow yhigh");
	    break;
	case FILLEDCURVES:
	    len = strappend(&line, &size, len, "1 y2");
	    break;
	case FINANCEBARS:
	    len = strappend(&line, &size, len, " open ylow yhigh yclose");
	    break;
	case CANDLESTICKS:
	    len = strappend(&line, &size, len, " open ylow yhigh yclose width");
	    break;
	case LABELPOINTS:
	    len = strappend(&line, &size, len, " label");
	    break;
	case VECTOR:
	    len = strappend(&line, &size, len, " delta_x delta_y");
	    break;
	case LINES:
	case POINTSTYLE:
	case LINESPOINTS:
	case DOTS:
	case IMPULSES:
	case STEPS:
	case FSTEPS:
	case HISTEPS:
	    break;
	case IMAGE:
	    len = strappend(&line, &size, len, "  pixel");
	    break;
	case RGBIMAGE:
	case RGBA_IMAGE:
	    len = strappend(&line, &size, len, "  red green blue alpha");
	    break;

	default:
	    if (interactive)
		fprintf(stderr, "Tabular output of %s plot style not fully implemented\n",
		    current_plot->plot_style == HISTOGRAMS ? "histograms" :
		    "this");
	    break;
	}

	if (current_plot->varcolor)
	    len = strappend(&line, &size, len, "  color");

	strappend(&line, &size, len, " type");
	print_line(line);

	if (current_plot->plot_style == LABELPOINTS) {
	    struct text_label *this_label;
	    for (this_label = current_plot->labels->next;
		 this_label != NULL;
		 this_label = this_label->next) {
		char *label = expand_newline(this_label->text);
		line[0] = NUL;
		len = 0;
		OUTPUT_NUMBER(this_label->place.x, current_plot->x_axis);
		OUTPUT_NUMBER(this_label->place.y, current_plot->y_axis);
		len = strappend(&line, &size, len, "\"");
		len = strappend(&line, &size, len, label);
		len = strappend(&line, &size, len, "\"");
		print_line(line);
		free(label);
	    }

	} else {
	    int plotstyle = current_plot->plot_style;
	    if (plotstyle == HISTOGRAMS && current_plot->histogram->type == HT_ERRORBARS)
		plotstyle = YERRORBARS;

	    for (i = 0, point = current_plot->points; i < current_plot->p_count;
		i++, point++) {

		/* Reproduce blank lines read from original input file, if any */
		if (!memcmp(point, &blank_data_line, sizeof(struct coordinate))) {
		    print_line("");
		    continue;
		}

		/* FIXME HBB 20020405: had better use the real x/x2 axes of this plot */
		line[0] = NUL;
		len = 0;
		OUTPUT_NUMBER(point->x, current_plot->x_axis);
		OUTPUT_NUMBER(point->y, current_plot->y_axis);

		switch (plotstyle) {
		    case BOXES:
		    case XERRORBARS:
			OUTPUT_NUMBER(point->xlow, current_plot->x_axis);
			OUTPUT_NUMBER(point->xhigh, current_plot->x_axis);
			/* Hmmm... shouldn't this write out width field of box
			 * plots, too, if stored? */
			break;
		    case BOXXYERROR:
		    case XYERRORBARS:
			OUTPUT_NUMBER(point->xlow, current_plot->x_axis);
			OUTPUT_NUMBER(point->xhigh, current_plot->x_axis);
			/* FALLTHROUGH */
		    case BOXERROR:
		    case YERRORBARS:
			OUTPUT_NUMBER(point->ylow, current_plot->y_axis);
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			break;
		    case IMAGE:
			snprintf(buffer, BUFFERSIZE, "%g ", point->z);
			len = strappend(&line, &size, len, buffer);
			break;
		    case RGBIMAGE:
		    case RGBA_IMAGE:
			snprintf(buffer, BUFFERSIZE, "%4d %4d %4d %4d ", 
			        (int)point->CRD_R, (int)point->CRD_G,
			        (int)point->CRD_B, (int)point->CRD_A);
			len = strappend(&line, &size, len, buffer);
			break;
		    case FILLEDCURVES:
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			break;
		    case FINANCEBARS:
			OUTPUT_NUMBER(point->ylow, current_plot->y_axis);
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			OUTPUT_NUMBER(point->z, current_plot->y_axis);
			break;
		    case CANDLESTICKS:
			OUTPUT_NUMBER(point->ylow, current_plot->y_axis);
			OUTPUT_NUMBER(point->yhigh, current_plot->y_axis);
			OUTPUT_NUMBER(point->z, current_plot->y_axis);
			OUTPUT_NUMBER(2. * (point->x - point->xlow), current_plot->x_axis);
			break;
		    case VECTOR:
			OUTPUT_NUMBER((point->xhigh - point->x), current_plot->x_axis);
			OUTPUT_NUMBER((point->yhigh - point->y), current_plot->y_axis);
			break;
		    case LINES:
		    case POINTSTYLE:
		    case LINESPOINTS:
		    case DOTS:
		    case IMPULSES:
		    case STEPS:
		    case FSTEPS:
		    case HISTEPS:
			break;
		    default:
			/* ? */
			break;
		} /* switch(plot type) */

		if (current_plot->varcolor) {
		    double colorval = current_plot->varcolor[i];
		    if ((current_plot->lp_properties.pm3d_color.value < 0.0)
		    &&  (current_plot->lp_properties.pm3d_color.type == TC_RGB)) {
			snprintf(buffer, BUFFERSIZE, "0x%06x", (unsigned int)(colorval));
			len = strappend(&line, &size, len, buffer);
		    } else if (current_plot->lp_properties.pm3d_color.type == TC_Z) {
			OUTPUT_NUMBER(colorval, COLOR_AXIS);
		    } else if (current_plot->lp_properties.l_type == LT_COLORFROMCOLUMN) {
			OUTPUT_NUMBER(colorval, COLOR_AXIS);
		    }
		}

		snprintf(buffer, BUFFERSIZE, " %c",
		    current_plot->points[i].type == INRANGE
		    ? 'i' : current_plot->points[i].type == OUTRANGE
		    ? 'o' : 'u');
		strappend(&line, &size, len, buffer);
		print_line(line);
	    } /* for(point i) */
	}

	print_line("");
    } /* for(curve) */

    if (outfile)
	fflush(outfile);
    free(buffer);
    free(line);
}
Example #3
0
void
print_3dtable(int pcount)
{
    struct surface_points *this_plot;
    int i, surface;
    struct coordinate GPHUGE *point;
    struct coordinate GPHUGE *tail;
    char *buffer = gp_alloc(BUFFERSIZE, "print_3dtable output buffer");
    outfile = (table_outfile) ? table_outfile : gpoutfile;

    for (surface = 0, this_plot = first_3dplot;
	 surface < pcount;
	 this_plot = this_plot->next_sp, surface++) {
	fprintf(outfile, "\n# Surface %d of %d surfaces\n", surface, pcount);

	if ((this_plot->title) && (*this_plot->title)) {
	    char *title = expand_newline(this_plot->title);
    	    fprintf(outfile, "\n# Curve title: \"%s\"", title);
	    free(title);
	}

	switch (this_plot->plot_style) {
	case LABELPOINTS:
	    {
	    struct text_label *this_label;
	    for (this_label = this_plot->labels->next; this_label != NULL;
		 this_label = this_label->next) {
		 char *label = expand_newline(this_label->text);
		 OUTPUT_NUMBER(this_label->place.x, FIRST_X_AXIS);
		 OUTPUT_NUMBER(this_label->place.y, FIRST_Y_AXIS);
		 OUTPUT_NUMBER(this_label->place.z, FIRST_Z_AXIS);
		fprintf(outfile, " \"%s\"\n", label);
		free(label);
	    }
	    }
	    continue;
	case LINES:
	case POINTSTYLE:
	case IMPULSES:
	case DOTS:
	case VECTOR:
	case IMAGE:
	    break;
	default:
	    fprintf(stderr, "Tabular output of this 3D plot style not implemented\n");
	    continue;
	}

	if (draw_surface) {
	    struct iso_curve *icrvs;
	    int curve;

	    /* only the curves in one direction */
	    for (curve = 0, icrvs = this_plot->iso_crvs;
		 icrvs && curve < this_plot->num_iso_read;
		 icrvs = icrvs->next, curve++) {

		fprintf(outfile, "\n# IsoCurve %d, %d points\n# x y z",
			curve, icrvs->p_count);
		if (this_plot->plot_style == VECTOR) {
		    tail = icrvs->next->points;
		    fprintf(outfile, " delta_x delta_y delta_z");
		} else tail = NULL;  /* Just to shut up a compiler warning */

		fprintf(outfile, " type\n");

		for (i = 0, point = icrvs->points;
		     i < icrvs->p_count;
		     i++, point++) {
		    OUTPUT_NUMBER(point->x, FIRST_X_AXIS);
		    OUTPUT_NUMBER(point->y, FIRST_Y_AXIS);
		    OUTPUT_NUMBER(point->z, FIRST_Z_AXIS);
		    if (this_plot->plot_style == VECTOR) {
			OUTPUT_NUMBER((tail->x - point->x), FIRST_X_AXIS);
			OUTPUT_NUMBER((tail->y - point->y), FIRST_Y_AXIS);
			OUTPUT_NUMBER((tail->z - point->z), FIRST_Z_AXIS);
			tail++;
		    } else if (this_plot->plot_style == IMAGE) {
			fprintf(outfile,"%g ",point->CRD_COLOR);
		    }
		    fprintf(outfile, "%c\n",
			    point->type == INRANGE
			    ? 'i' : point->type == OUTRANGE
			    ? 'o' : 'u');
		} /* for(point) */
	    } /* for(icrvs) */
	    putc('\n', outfile);
	} /* if(draw_surface) */

	if (draw_contour) {
	    int number = 0;
	    struct gnuplot_contours *c = this_plot->contours;

	    while (c) {
		int count = c->num_pts;
		struct coordinate GPHUGE *point = c->coords;

		if (c->isNewLevel)
		    /* don't display count - contour split across chunks */
		    /* put # in case user wants to use it for a plot */
		    /* double blank line to allow plot ... index ... */
		    fprintf(outfile, "\n# Contour %d, label: %s\n",
			    number++, c->label);

		for (; --count >= 0; ++point) {
		    OUTPUT_NUMBER(point->x, FIRST_X_AXIS);
		    OUTPUT_NUMBER(point->y, FIRST_Y_AXIS);
		    OUTPUT_NUMBER(point->z, FIRST_Z_AXIS);
		    putc('\n', outfile);
		}

		/* blank line between segments of same contour */
		putc('\n', outfile);
		c = c->next;

	    } /* while (contour) */
	} /* if (draw_contour) */
    } /* for(surface) */
    fflush(outfile);

    free(buffer);
}
Example #4
0
boolean_t dse_fdmp(sm_uc_ptr_t data, int len)
{
	unsigned char	*key_char_ptr, *work_char_ptr;
	int 		dest_len;
	unsigned char	*ret_addr;
	boolean_t	is_snblk=FALSE;
	span_subs	*ss_ptr;		/*spanning node key pointer */
	unsigned int	snbid, offset, trail_zero, rev_num, num;
	unsigned short	blk_sz;

	if (work_buff_length < ZWR_EXP_RATIO(gv_cur_region->max_rec_size))
	{
		work_buff_length = ZWR_EXP_RATIO(gv_cur_region->max_rec_size);
		if (work_buff)
			free (work_buff);
		work_buff = (unsigned char *)malloc(work_buff_length);
	}
	work_char_ptr = work_buff;
	*work_char_ptr++ = '^';
	for (key_char_ptr = (uchar_ptr_t)patch_comp_key; *key_char_ptr ; key_char_ptr++)
	{
		if (PRINTABLE(*key_char_ptr))
			*work_char_ptr++ = *key_char_ptr;
		else
			return FALSE;
	}
	key_char_ptr++;
	if (SPAN_START_BYTE != *key_char_ptr) /*Global has subscript*/
	{
		*work_char_ptr++ = '(';
		for (;;)
		{
			work_char_ptr = gvsub2str(key_char_ptr, work_char_ptr, TRUE);
			/* Removed unnecessary checks for printable characters (PRINTABLE()) here
			 * since the data being written into files (OPENed files) would have been
			 * passed through ZWR translation which would have taken care of converting
			 * to $CHAR() or $ZCHAR() */

			for (; *key_char_ptr ; key_char_ptr++)
				;
			key_char_ptr++;
			/* Check if this is spanning node if yes break out of the loop */
			if (SPAN_START_BYTE == *key_char_ptr
			    && (int)*(key_char_ptr + 1) >= SPAN_BYTE_MIN
			    && (int)*(key_char_ptr + 2) >= SPAN_BYTE_MIN)
			{
				is_snblk = TRUE;
				break;
			}
			if (*key_char_ptr)
				*work_char_ptr++ = ',';
			else
				break;
		}
		*work_char_ptr++ = ')';
	} else	/*Spanning node without subscript*/
		is_snblk = TRUE;
	if (is_snblk)
	{
		ss_ptr = (span_subs *)key_char_ptr;
		snbid = SPAN_GVSUBS2INT(ss_ptr);
		key_char_ptr = key_char_ptr + SPAN_SUBS_LEN + 1; /* Move out of special subscript of spanning node */
		blk_sz = gv_cur_region->dyn.addr->blk_size;
		/* Decide the offset of the content of a block inside the value of spanning node*/
		offset = (snbid) ? (blk_sz - (SIZEOF(blk_hdr) + SIZEOF(rec_hdr) + gv_cur_region->dyn.addr->reserved_bytes
				    + (key_char_ptr - (uchar_ptr_t)patch_comp_key + 1))) * (snbid - 1) : 0 ;
		ret_addr =(unsigned char *)memmove((void *)(work_buff+4), (void *)work_buff, (work_char_ptr - work_buff));
		assert(*ret_addr == '^');
		*work_buff = '$';
		*(work_buff + 1) = 'z';
		*(work_buff + 2) = 'e';
		*(work_buff + 3) = '(';
		/* length of "$ze(" is 4, so move the work_char_ptr by 4*/
		work_char_ptr = work_char_ptr + 4;
		*work_char_ptr++ = ',';

		/* Dump the offset of the content of a block inside the value of spanning node */
		num = snbid ? offset : 0;
		COUNT_TRAILING_ZERO(num, work_char_ptr, trail_zero);
		num = offset;
		OUTPUT_NUMBER(num, work_char_ptr, trail_zero);
		*work_char_ptr++ = ',';

		/* Dump the length of the content of a block */
		num = snbid ? len : 0;
		COUNT_TRAILING_ZERO(num, work_char_ptr, trail_zero);
		num = snbid ? len : 0;
		OUTPUT_NUMBER(num, work_char_ptr, trail_zero);
		*work_char_ptr++ = ')';
	}
	assert(MAX_ZWR_KEY_SZ >= work_char_ptr - work_buff);
	if (GLO_FMT == dse_dmp_format)
	{
		if (!dse_fdmp_output(work_buff, (int4)(work_char_ptr - work_buff)))
			return FALSE;
		if (!dse_fdmp_output(data, len))
			return FALSE;
	} else
	{
		assert(ZWR_FMT == dse_dmp_format);
		*work_char_ptr++ = '=';
		if(is_snblk && !snbid)
		{
			*work_char_ptr++ = '"';
			*work_char_ptr++ = '"';
			dest_len = 0;
		} else
			format2zwr(data, len, work_char_ptr, &dest_len);
		if (!dse_fdmp_output(work_buff, (int4)(work_char_ptr + dest_len - work_buff)))
			return FALSE;
	}
	return TRUE;
}