📄 pplot1.c
字号:
/* Copyright (c) Colorado School of Mines, 1990./* All rights reserved. */#include "cwp.h"#define IFC 0#define ILC 60voidpplot1 (FILE *fp, char *title, int nx, float ax[])/*****************************************************************************printer plot of a 1-dimensional array******************************************************************************Input:fp file pointer for printed output (e.g., stdout, stderr, etc.)title title of plotnx number of x values to be plottedax array[nx] of x values******************************************************************************Author: Dave Hale, Colorado School of Mines, 12/26/89*****************************************************************************/{ int ix,ibase,icx,ic; int ifx=0; int ilx=ifx+nx-1; float xmin,xmax,xscale,xbase; /* print title */ fprintf(fp,"\n"); fprintf(fp,"%s\n",title); /* minimum and maximum x */ xmin = ax[0]; xmax = ax[0]; for (ix=1; ix<nx; ix++) { xmin = MIN(xmin,ax[ix]); xmax = MAX(xmax,ax[ix]); } fprintf(fp,"minimum = %g\n",xmin); fprintf(fp,"maximum = %g\n",xmax); /* determine scale factors and shifts for converting x values to *s */ if (xmin==xmax) xscale = 1.0; else xscale = (ILC-IFC)/(xmax-xmin); if (xmin<0.0 && xmax<0.0) { ibase = ILC; xbase = xmax; } else if (xmin<0.0 && xmax>=0.0) { ibase = IFC+(0.0-xmin)*xscale; xbase = 0.0; } else { ibase = IFC; xbase = xmin; } /* loop over x values */ for (ix=0; ix<nx; ix++) { /* determine column corresponding to x value */ icx = ibase+NINT((ax[ix]-xbase)*xscale); icx = MAX(IFC,MIN(ILC,icx)); /* print the index, x value, and row of asterixes */ fprintf(fp,"%4d %13.6e ",ifx+ix,ax[ix]); for (ic=IFC; ic<MIN(ibase,icx); ic++) fprintf(fp," "); for (ic=MIN(ibase,icx); ic<=MAX(ibase,icx); ic++) fprintf(fp,"*"); fprintf(fp,"\n"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -