void gr_draw_contours(int nx, int ny, int nh, double *px, double *py, double *h, double *z, int major_h) { double mmin, mmax, *cv; int ncv, *bitmap; int i, j, k, n = 0; int precision, max_precision; char *s, buffer[80]; int eflag, error_ind = 0; int rotation, tilt, scale_options; double char_height; gks_inq_open_ws(1, &error_ind, &n, &contour_vars.wkid); /* Inquire current transformation */ contour_vars.ndc = 0; gks_inq_current_xformno(&error_ind, &contour_vars.tnr); gks_inq_xform(contour_vars.tnr, &error_ind, contour_vars.wn, contour_vars.vp); contour_vars.scale_factor = (contour_vars.vp[1] - contour_vars.vp[0]) / (contour_vars.wn[1] - contour_vars.wn[0]); contour_vars.aspect_ratio = (contour_vars.vp[3] - contour_vars.vp[2]) / (contour_vars.wn[3] - contour_vars.wn[2]) / contour_vars.scale_factor; contour_vars.xdim = nx; contour_vars.ydim = ny; contour_vars.lblmjh = major_h; contour_vars.label_map = NULL; /* Don't label any lines if a 3D-transformation */ /* or if any scale options are in effect. */ gr_inqscale(&scale_options); gr_inqspace(&contour_vars.zmin, &contour_vars.zmax, &rotation, &tilt); if ((rotation == 0) && (tilt == 90) && (contour_vars.lblmjh > 0) && (scale_options == 0)) { contour_vars.txtflg = 1; /* Compute size of 'label_map' with respect to */ /* viewport-size and character-height. */ /* 'label_map' is used to store information about */ /* previously drawn label positions to avoid */ /* overlapping */ gks_inq_text_height(&error_ind, &char_height); if (char_height < contour_min_chh) { char_height = contour_min_chh; } contour_vars.x_map_size = (int) (contour_map_rate * (contour_vars.vp[1] - contour_vars.vp[0]) / char_height) + 2; contour_vars.y_map_size = (int) (contour_map_rate * (contour_vars.vp[3] - contour_vars.vp[2]) / char_height) + 2; contour_vars.label_map = (int *) xmalloc(contour_vars.x_map_size * contour_vars.y_map_size * sizeof(int)); k = 0; for (i = 0; i < contour_vars.x_map_size; i++) for (j = 0; j < contour_vars.y_map_size; j++) { contour_vars.label_map[k] = 0; k++; } contour_vars.x_map_factor = (double) (contour_vars.x_map_size - 3) / (contour_vars.wn[1] - contour_vars.wn[0]); contour_vars.y_map_factor = (double) (contour_vars.y_map_size - 3) / (contour_vars.wn[3] - contour_vars.wn[2]); } else { contour_vars.txtflg = 0; } mmin = huge_value; mmax = -huge_value; contour_vars.z = z; k = 0; for (j = 0; j < ny; j++) { for (i = 0; i < nx; i++) { if (contour_vars.z[k] > mmax) mmax = contour_vars.z[k]; else if (contour_vars.z[k] < mmin) mmin = contour_vars.z[k]; k++; } } if (nh < 1) { ncv = contour_lines; cv = (double *) xmalloc(ncv * sizeof(double)); for (i = 0; i < ncv; i++) cv[i] = mmin + (double) (i) / (ncv - 1) * (mmax - mmin); } else { ncv = nh; cv = h; } /*-------------------------------------------------------------------------- / Find the maximum required precision for the labels and create the / appropriate format for 'sprintf' /-------------------------------------------------------------------------*/ if (contour_vars.txtflg == 1) { max_precision = 0; eflag = 0; for (i = 0; i < ncv; i++) if ((contour_vars.txtflg == 1) && ((contour_vars.lblmjh == 1) || ((i % contour_vars.lblmjh) == 1))) { sprintf(buffer, "%g", cv[i]); if ((s = (char *) strchr(buffer, '.')) != 0) { precision = strspn(s + 1, "0123456789"); if (*(s + 1 + precision) != '\0') eflag = 1; if (precision > max_precision) max_precision = precision; } } sprintf(contour_vars.lblfmt, "%%.%d%c", max_precision, eflag ? 'e' : 'f'); } bitmap = (int *) xmalloc(nx * ny * ncv * 2 * sizeof(int)); contour_vars.xmin = px[0]; contour_vars.ymin = py[0]; contour_vars.dx = px[1] - contour_vars.xmin; contour_vars.dy = py[1] - contour_vars.ymin; calc_contours(contour_vars.z, nx, nx, ny, cv, ncv, mmax, bitmap, contour_vars.xmin, contour_vars.ymin, contour_vars.dx, contour_vars.dy); free(bitmap); if (contour_vars.label_map != NULL) free(contour_vars.label_map); if (cv != h) free(cv); }
void FORTRAN(gr_inqscale)(int *options) { gr_inqscale(options); }