📄 ,mlplot.c
字号:
if (alow == ahigh) alow = -ahigh; if (alow != -DBL_MAX) alo_flag++; if (ahigh != DBL_MAX) ahi_flag++; if (debug_level > 1) { Fprintf(stderr, "%s: alow = %e, ahigh = %e.\n", ProgName, alow, ahigh); (void) fflush(stderr); } } for (i = 0; i < num_of_files; i++) { if (debug_level > 1) { Fprintf(stderr, "%s: skipping %ld records in %s\n", ProgName, firstrec - start[i], sdfilename[i]); (void) fflush(stderr); } if (firstrec > start[i]) skiprec(sdfile[i], firstrec - start[i], size_rec(hd[i])); } if (debug_level > 1) { Fprintf(stderr, "%s: allocating memory for data, u, v, ylow, yhigh, yscale, yticint.\n", argv[0]); (void) fflush(stderr); } /* * Allocate memory for data, u, and v. * We need to allocate: * * (number of files to plot) [num_of_files] * by * (number of data points in one "window") [xinc] * * memory space. * * Note: data will be xinc by num_of_files, whereas * u and v are num_of_files by xinc * * Allocate memory for ylow, yhigh, yscale, yticint also. * These arrays should have num_of_files elements. * */ (void) allo_d_matrix(num_of_files, (int) nrec); (void) allo_d_array(num_of_files); /* read data from the ESPS generic file and store in data array */ if (debug_level > 3) { Fprintf(stderr, "%s: reading %ld data records from ESPS Sampled Data file...\n", ProgName, nrec); (void) fflush(stderr); } for ( i_file = 0; i_file < num_of_files; i_file++ ) { if (get_sd_recd(data[i_file], (int) nrec, hd[i_file], sdfile[i_file]) == EOF) { Fprintf(stderr, "\n\n%s: appending zeros; not enough data in %s.\n\n", ProgName, sdfilename[i_file]); } if (alo_flag && ahi_flag) { yhigh[i_file] = ahigh; ylow[i_file] = alow; } else { /* * Compute the maximum and minumum elements in the * Sampled Data file and then determine how many bits * we need to get the required resolution using an * Analog-to-Digital converter. * */ for (i = 0; i < nrec; i++) { if (i == 0) { yhigh[i_file] = data[i_file][i]; ylow[i_file] = data[i_file][i]; } else { if (data[i_file][i] > yhigh[i_file]) yhigh[i_file] = data[i_file][i]; if (data[i_file][i] < ylow[i_file]) ylow[i_file] = data[i_file][i]; } } if (debug_level > 3) { Fprintf(stderr, "%s: actual: ylow[%d] = %g, yhigh[%d] = %g\n", ProgName, i_file, ylow[i_file], i_file, yhigh[i_file]); (void) fflush(stderr); } if (yhigh[i_file] <= 0.0) yhigh[i_file] = 0.0; else { for (sample_range = 1.0; sample_range < yhigh[i_file]; sample_range *= 2.0) {} yhigh[i_file] = sample_range; } if (ylow[i_file] >= 0.0) ylow[i_file] = 0.0; else { for (sample_range = -1.0; sample_range > ylow[i_file]; sample_range *= 2.0) {} ylow[i_file] = sample_range; } if (alo_flag) ylow[i_file] = alow; else if (ahi_flag) yhigh[i_file] = ahigh; else if (yhigh[i_file] > 0 && ylow[i_file] < 0) { if (yhigh[i_file] > -ylow[i_file]) ylow[i_file] = -yhigh[i_file]; else yhigh[i_file] = -ylow[i_file]; } if (debug_level > 3) { Fprintf(stderr, "%s: using: ylow[%d] = %g, yhigh[%d] = %g\n", ProgName, i_file, ylow[i_file], i_file, yhigh[i_file]); (void) fflush(stderr); } } /* end if (alo_flag && ahi_flag) ... else */ if (ylow[i_file] >= yhigh[i_file]) ERROR("zero amplitude range.") } /* end outer for (i_file = 0; i_file < num_of_files; i_file++) loop */ if (debug_level > 0) Fprintf(stderr, "%s: data has been read, max & min computed.\n", ProgName); xinc = deltau / xscale; /* * Now compute yscale from yhigh and ylow arrays. */ for (i_file = 0; i_file < num_of_files; i_file++) { delta_y = yhigh[i_file] - ylow[i_file]; yscale[i_file] = deltav / delta_y; yticint[i_file] = delta_y / DEF_Y_SUBDIV; if (debug_level > 3) { Fprintf(stderr, "%s: yscale[%d] = %g, yticint[%d] = %g\n", ProgName, i_file, yscale[i_file], i_file, yticint[i_file]); (void) fflush(stderr); } } if (tagfilename != NULL) { tag_rec = allo_gen_recd(th); do tag_eof = get_gen_recd(tag_rec, &tag, th, tagfile) == EOF; while (!tag_eof && tag < firstrec); if ((debug_level > 0) && Pflag) Fprintf(stderr, "%s: %sreached end of tagged file.\n", ProgName, (tag_eof == 0) ? "have not " : "you have "); } page_num = 0; ulow = u0; vlow = v0; index = 0; if (debug_level > 0) Fprintf(stderr, "%s: beginning main loop:\n", ProgName);/* * M A I N * * L O O P: * * Now begin the main loop which intializes the graph (i.e printheader, * drawaxes and labels), reads data and plots points. * */ if (lflag) { xlow = firstrec - 1; xmin = firstrec; } else { xlow = firstrec - 1 - (firstrec - 1) % xinc; xmin = firstrec; } if (gps && !nflag) gps_null_comment(stdout); while (continue_plotting) { xmax = MIN(xlow + xinc, lastrec); if (debug_level > 4) Fprintf(stderr, "\n\n MAIN LOOP\n%s: xmax = %d\n", ProgName, xmax); /* * R E A D * S T O R E D * D A T A: * * Read in data from data and scale each plot accordingly. * */ /* * save the value of vlow (the vertical border) * you need it to go back to the starting place to begin plotting. * */ old_vlow = vlow; for ( x = xmin, i = 0; x <= xmax; ++x, ++index, ++i ) { /* ^ * | * * Notice: index is initialized outside MAIN LOOP, * it is used to index data * matrix across records. */ vlow = old_vlow; /* get back to the * original vertical starting position */ for ( i_file = 0; i_file < num_of_files; ++i_file ) { u[i_file][i] = ulow + (x - xlow) * xscale; v[i_file][i] = vlow + ROUND_OFF((data[i_file][index] - ylow[i_file]) * yscale[i_file]); /* * Keep track of which line we are plotting * and shift vlow accordingly. */ if (i_file == 0) line_num = nlines; if (++line_num < maxlines) vlow -= vshift; else { vlow = v0; line_num = 0; } } } vlow = old_vlow; /* get the old vertical postion */ /* * B E G I N * * P L O T T I N G: * */ for ( i_file = 0; i_file < num_of_files; ++i_file ) { if (nlines == 0) /* it's the beginning of a new page */ { ++page_num; if ((page_num > MAX_PAGES) && gps) { if ( !nflag ) { Fprintf(stderr, "%s: Warning, only 25 regions can be displayed on MC tube!\n", ProgName); Fprintf(stderr, " stopping output to stdout.\n"); nflag = 1; } } if (debug_level > 0) Fprintf(stderr, "\n"); if ( gps && (outdir != NULL) ) { if (debug_level > 3) Fprintf(stderr, "%s: initializing page (region) number %d\n", ProgName, page_num); (void) fflush(stderr); init_gps_page(); } if (debug_level > 3) { Fprintf(stderr, "%s: printing command line...\n", ProgName); (void) fflush(stderr); } /* * Print out the command line on top of output page. * */ if (strlen(command_line) > COM_CHARS) { (void) strncpy(comtxt, command_line, COM_CHARS); comtxt[COM_CHARS] = '\0'; text( hdrleft, hdrbase + 90, x_com_charsp, 0, comtxt, plotting_func); tmptxt = &command_line[COM_CHARS]; if (strlen(tmptxt) > COM_CHARS) Fprintf(stderr, "%s: command line too long: truncating string.\n"); /* * Here is what I tried to compensate the problem mentioned * above. * * if (strlen(tmptxt) > COM_CHARS){ (void) strncpy(comtxt, tmptxt, COM_CHARS); comtxt[COM_CHARS] = '\0'; text( hdrleft, hdrbase + 50, x_com_charsp, 0, comtxt, plotting_func); tmptxt = &tmptxt[COM_CHARS]; text( hdrleft, hdrbase + 20, x_com_charsp, 0, tmptxt, plotting_func); } else * * */ text( hdrleft, hdrbase + 60, x_com_charsp, 0, tmptxt, plotting_func); } else text( hdrleft, hdrbase + 90, x_com_charsp, 0, command_line, plotting_func); DRAW(hdrleft, hdrbase + 47, hdrright, hdrbase + 47, plotting_func) if (debug_level > 3) { Fprintf(stderr, "%s: printing header...\n", ProgName); (void) fflush(stderr); } /* * Now, print out the header. * */ printheader(hdrleft, hdrright, hdrbase, hdr_charsp, sdname, tagfilename, xscale, plotting_func); text( x_ttl_center - (x_ttl_charsp * strlen(x_ttl_text))/2, x_ttl_base, x_ttl_charsp, 0, x_ttl_text, plotting_func); text( y_ttl_base, y_ttl_center - (y_ttl_charsp * strlen(y_ttl_text))/2, y_ttl_charsp, 90, y_ttl_text, plotting_func); } /* end if (nlines == 0) */ /* * We should draw axes here: */ if (debug_level > 3) { Fprintf(stderr, "%s: drawing axes...\n", ProgName); (void) fflush(stderr); } delta_y = yhigh[i_file] - ylow[i_file]; drawaxes(ulow, vlow, xlow, ylow[i_file], xinc + 1, delta_y, xscale, yscale[i_file], xticint, yticint[i_file], lbl_charsp, axflag, plotting_func); if (tagfilename != NULL) while (!tag_eof && (x = tag) <= xmax) { long u = ulow + (x - xlow) * xscale; char label[LBL_MAX]; if (debug_level > 3) { Fprintf(stderr, "%s: tagged file, labeling tags...\n", argv[0]); (void) fflush(stderr); } DRAW(u, vlow + deltav, u, vlow + deltav + lbl_charsp, plotting_func) Sprintf(label, "%ld", x); text( u, vlow + deltav + lbl_charsp, tag_charsp, 90, label, plotting_func); tag_eof = get_gen_recd(tag_rec, &tag, th, tagfile) == EOF; } /* * label the current file we're plotting */ /* * use strrchr(sdfilename[], '/') to get the name of the * ESPS Sampled Data file without the full path name. */ if ( (file_text = strrchr(sdfilename[i_file], '/')) == NULL ) file_text = sdfilename[i_file]; else file_text = ++file_text; text( y_ttl_base + deltau + 400,/* 75 + vlow + ROUND_OFF(delta_y * yscale) */ vlow + deltav/2 + (y_ttl_charsp * strlen(file_text))/2, y_ttl_charsp, -90, file_text, plotting_func); if (debug_level > 3) { Fprintf(stderr, "%s: plotting data...\n", ProgName); (void) fflush(stderr); } switch (mode) { case M_POINT: if ( imagen ) tek_plotpoints(xmax - xmin + 1, u[i_file], v[i_file]); else /* gps */ for (x = xmin, i = 0; x <= xmax; ++x, ++i) DRAW(u[i_file][i], v[i_file][i], u[i_file][i], v[i_file][i], plotting_func) break; case M_CONN: if ( imagen ) tek_plotline(xmax - xmin + 1, u[i_file], v[i_file]); else /* gps */ gps_plotline(xmax - xmin + 1, u[i_file], v[i_file]); break; case M_VERT: for (x = xmin, i = 0; x <= xmax; ++x, ++i) DRAW(u[i_file][i], v[i_file][i], u[i_file][i], vlow - ylow[i_file] * yscale[i_file], plotting_func) break; } /* end switch (mode) */ if (++nlines < maxlines) { if (debug_level > 3) Fprintf(stderr, "%s: shifting frame down by vshift (%ld) to ", ProgName, vshift); vlow -= vshift; /* move next drawing frame down */ if (debug_level > 3) Fprintf(stderr, "vlow (%ld)\n", vlow); (void) fflush(stderr); } else { /* you're on the next page */ /* (nlines >= maxlines) */ if ( gps ) { if ( (page_num % 5) == 0 ) { /* move to left region after every five pages */ Q0 += MC_REGION; P0 = MC_U0; if (debug_level > 3) { Fprintf(stderr, "%s: moving drawing frame origin to (P0 = %ld, Q0 = %ld)\n", ProgName, P0, Q0); (void) fflush(stderr); } } else { /* otherwise increment along x-axis */ P0 += MC_REGION; if (debug_level > 3) { Fprintf(stderr, "%s: moving drawing frame origin to (u0+P0 = %ld, v0+Q0 = %ld)\n", ProgName, u0 + P0, v0 + Q0); (void) fflush(stderr); } } } /* end if (gps) */ vlow = v0; /* reset y-coordinates */ nlines = 0; /* reset frame number */ if (debug_level > 3) { Fprintf(stderr, "%s: moving origin to (ulow = %ld, vlow = %ld), starting new page\n\n", ProgName, ulow, vlow); (void) fflush(stderr); } if ( imagen ) tek_termpage(); if ( gps && (outdir != NULL) ) (void) fclose(outfp); } /* end if (nlines < maxlines) */ } /* end plotting loop */ xlow += xinc; xmin = xlow + 1; if (xmin > lastrec) continue_plotting = NO; } /* Main for loop */ if (nlines > 0) if ( imagen ) tek_termpage();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -