home *** CD-ROM | disk | FTP | other *** search
- #include <graphics/display.h>
- #include <libraries/dosextens.h>
- #include <libraries/diskfont.h>
- #include <exec/exec.h>
- #include <intuition/intuitionbase.h>
- #include <graphics/regions.h>
- #include <devices/keymap.h>
- #include <stdio.h>
- #include <workbench/startup.h>
- #include <graphics/gfxmacros.h>
- #include <graphics/gfxbase.h>
- #include <math.h>
-
- #include "diskicon.h"
- #include "struct.h"
- #include "plotlim.h"
- #include "ffp.h"
-
- /*** PLOT TYPES ***/
- #define LINEPLOT 0
- #define POINTPLOT 1
- #define BOTHPLOT 2
- #define STEP 3
-
- extern int MAXVERT;
- extern int MAXHORIZ;
- extern int CHARWIDTH;
- extern int CHARHEIGHT;
- extern struct TextFont *xf;
- extern struct TextFont *yf;
- extern struct TextFont *tf;
- extern struct TextFont *lf;
- extern int GetDat();
- extern void plot();
- extern struct Screen *screen;
- extern struct Window *window;
- extern int XMINP; /* LMARGIN */
- extern int YMAXP; /* MAXVERT - TMARGIN */
- extern int YMINP; /* BMARGIN */
- extern int XMAXP;
-
- #define QUIT 0
- #define GO 1
- extern int QuitFlag;
- extern long IconBase;
- extern FFP xtic[MAXTICS],ytic[MAXTICS];
- extern short xticp[MAXTICS],yticp[MAXTICS];
- extern char filename[150];
- extern struct RastPort *p;
- extern struct ViewPort *vp;
- extern struct TextBox *ExtraText;
-
- #define P_X_TIC_SIZE X_TIC_SIZE*(P_YREG/MAXVERT)
- #define P_Y_TIC_SIZE Y_TIC_SIZE*(P_XREG/MAXHORIZ)
- #define P_ERR_DELIM ERR_DELIM*(P_XREG/MAXHORIZ)
-
- #define P_CH_WID 115
- #define P_CH_HEI 100
-
- int P_LMARGIN;
- int P_BMARGIN;
- int P_TMARGIN;
- int P_RMARGIN;
- int P_YREG;
- int P_XREG;
-
- #define MCAD_ERR_DELIM ERR_DELIM*(
-
- static FFP XScale, YScale, XOffset, YOffset;
- static FFP XFactor, YFactor;
-
- void fWrtFFP(fp, ffpval)
- FILE *fp;
- FFP ffpval;
- {
- fprintf(fp, "%d", (int)ffpval);
- }
-
-
- void WrtAxes(fp, Pict)
- FILE *fp;
- struct Pict *Pict;
- {
- short n, tmpx, tmpy, i;
- FFP *x, *y;
- char tmpstr[20];
- struct Plot *Plot;
- struct TextBox *TempText;
-
- /*** DRAW TICS/GRID ***/
- fprintf(fp,"SP2;");
- x=Pict->Tics->x; y=Pict->Tics->y;
- for (i=0; i < Pict->Tics->NX; i++) {
- if (Pict->Grid==2) { /* Plot Grid */
- fprintf(fp,"PU"); fWrtFFP(fp,(XScale * (XOffset + x[i])));
- fprintf(fp," %d;PD",P_BMARGIN);
- fWrtFFP(fp,(XScale * (XOffset + x[i])));
- fprintf(fp," %d;\n",P_YREG);
- }
- else {
- if ((Pict->Grid==0)||(Pict->Grid==3)) { /* Plot tics */
- fprintf(fp,"PU"); fWrtFFP(fp,(XScale * (XOffset + x[i])));
- fprintf(fp," %d;PD",P_BMARGIN);
- fWrtFFP(fp,(XScale * (XOffset + x[i])));
- fprintf(fp," %d;",P_BMARGIN + P_X_TIC_SIZE);
- }
- if (Pict->Grid==3) {
- fprintf(fp,"PU"); fWrtFFP(fp,(XScale * (XOffset + x[i])));
- fprintf(fp," %d;PD",P_YREG);
- fWrtFFP(fp,(XScale * (XOffset + x[i])));
- fprintf(fp," %d;\n",P_YREG - P_X_TIC_SIZE);
- }
- }
- }
- for (i=0; i < Pict->Tics->NY; i++) {
- if (Pict->Grid==2) {
- fprintf(fp,"PU%d ",P_LMARGIN);
- fWrtFFP(fp,(YScale * (YOffset + y[i])));
- fprintf(fp,"PD%d ",P_XREG);
- fWrtFFP(fp,(YScale * (YOffset + y[i])));
- fprintf(fp,";\n");
- }
- else {
- if ((Pict->Grid==0)||(Pict->Grid==3)) {
- fprintf(fp,"PU%d ",P_LMARGIN);
- fWrtFFP(fp,(YScale * (YOffset + y[i])));
- fprintf(fp,";PD%d ", P_LMARGIN + P_Y_TIC_SIZE);
- fWrtFFP(fp,(YScale * (YOffset + y[i])));
- fprintf(fp,";");
- }
- if (Pict->Grid==3) {
- fprintf(fp,"PU%d ",P_XREG);
- fWrtFFP(fp,(YScale * (YOffset + y[i])));
- fprintf(fp,";PD%d ", P_XREG - P_Y_TIC_SIZE);
- fWrtFFP(fp,(YScale * (YOffset + y[i])));
- fprintf(fp,";\n");
- }
- }
- }
-
- /*** DRAW BORDER ***/
- if (Pict->Grid<5) {
- fprintf(fp,"SP1;PU%d %d;",P_XREG,P_BMARGIN);
- fprintf(fp,"PD%d %d %d %d",P_LMARGIN,P_BMARGIN,P_LMARGIN,P_YREG);
- if (Pict->Grid>1) {
- fprintf(fp," %d %d %d %d",P_XREG,P_YREG,P_XREG,P_BMARGIN);
- if (Pict->RMargin) {fprintf(fp," %d %d %d %d %d %d",P_XREG+P_RMARGIN,P_BMARGIN,P_XREG+P_RMARGIN,P_YREG,P_XREG,P_YREG);}
- }
- fprintf(fp,";\n");
- }
-
- /*** PRINT TIC VALUES ***/
- if (lf) fprintf(fp,"SR%f %f;\n",(float)(lf->tf_XSize)*68.0/(float)MAXHORIZ,(float)(lf->tf_YSize)*60.0/(float)MAXVERT);
- else fprintf(fp,"SR%f %f;\n",(float)CHARWIDTH*68.0/(float)MAXHORIZ,(float)CHARHEIGHT*60/MAXVERT);
- if ((Pict->Grid==0)||(Pict->Grid==2)||(Pict->Grid==3)) {
- fprintf(fp,"SP1;");
- for (i=0; i < Pict->Tics->NX; i++) {
- n=GetString(&tmpstr,Pict->Tics->x[i]);
- tmpx = (short)((XScale * (XOffset + Pict->Tics->x[i])));
- if (lf) tmpx -= (((n+1)/2)-.5) * (short)(lf->tf_XSize)*10000/MAXHORIZ;
- else tmpx -= (((n+1)/2)-.5) * CHARWIDTH*10000/MAXHORIZ;
- if (lf) tmpy = P_BMARGIN - (2*(short)(lf->tf_YSize)*10000/MAXVERT) +1;
- else tmpy = P_BMARGIN - (2*CHARHEIGHT*10000/MAXVERT) +1;
- fprintf(fp, "PU%d %d;", tmpx,tmpy);
- fprintf(fp,"LB%s\003;\n", tmpstr);
- }
- }
- if ((Pict->Grid==0)||(Pict->Grid==2)||(Pict->Grid==3)) {
- for (i=0; i < Pict->Tics->NY; i++) {
- n=GetString(&tmpstr,Pict->Tics->y[i]);
- tmpy = (short)((YScale * (YOffset + Pict->Tics->y[i])));
- if (lf) tmpy -= (short)(lf->tf_YSize)*10000/MAXVERT/2;
- else tmpy -= CHARHEIGHT*10000/MAXVERT/2;
- if (lf) tmpx = P_LMARGIN-( (n+1) * (short)(lf->tf_XSize)*10000 / MAXHORIZ);
- else tmpx = P_LMARGIN-( (n+1) * CHARWIDTH*10000 / MAXHORIZ);
- fprintf(fp, "PU%d %d;",tmpx, tmpy);
- fprintf(fp,"LB%s\003;\n", tmpstr);
- }
- }
-
- /*** WRITE X LABEL ***/
- if (xf) fprintf(fp,"SR%f %f;\n",(float)(xf->tf_XSize)*68.0/(float)MAXHORIZ,(float)(xf->tf_YSize)*60/MAXVERT);
- else fprintf(fp,"SR%f %f;\n",(float)CHARWIDTH*68.0/(float)MAXHORIZ,(float)CHARHEIGHT*60/MAXVERT);
- if (strlen(Pict->XLabel->String)){
- tmpx = P_LMARGIN+(P_XREG-P_LMARGIN)/2;
- if (xf) tmpx = tmpx - strlen(Pict->XLabel->String)*(short)(xf->tf_XSize)*10000/MAXHORIZ/2;
- else tmpx = tmpx - strlen(Pict->XLabel->String) * CHARWIDTH*10000/MAXHORIZ/2;
- if (lf) tmpy = P_BMARGIN - (4*(short)(lf->tf_YSize)*10000/MAXVERT) +1;
- else tmpy = P_BMARGIN - (4*CHARHEIGHT*10000/MAXVERT) +1;
- fprintf(fp, "PU%d %d;", tmpx,tmpy);
- fprintf(fp,"LB%s\003;\n", Pict->XLabel->String);
- }
-
- /*** WRITE LEGEND ***/
- if (lf) fprintf(fp,"SR%f %f;\n",(float)(lf->tf_XSize)*68.0/(float)MAXHORIZ,(float)(lf->tf_YSize)*60/MAXVERT);
- else fprintf(fp,"SR%f %f;\n",(float)CHARWIDTH*68.0/(float)MAXHORIZ,(float)CHARHEIGHT*60/MAXVERT);
- Plot=Pict->Plot;
- while (Plot)
- {
- if ((Plot->Enabled)&&(strlen(Plot->Legend->String)))
- {
- fprintf(fp, "PU");
- fWrtFFP(fp, (FFP)(P_LMARGIN+(Plot->Legend->x-XMINP)*XFactor +500));
- fprintf(fp," ");
- if (lf) fWrtFFP(fp, (FFP)(P_BMARGIN+(Plot->Legend->y-YMINP)*YFactor-(short)(lf->tf_YSize)*10000/MAXVERT/2));
- else fWrtFFP(fp, (FFP)(P_BMARGIN+(Plot->Legend->y-YMINP)*YFactor-CHARHEIGHT*10000/MAXVERT/2));
- fprintf(fp,"; LB%s\003;\n", Plot->Legend->String);
- }
- while (Plot->Continued) Plot=Plot->NextPlot;
- Plot=Plot->NextPlot;
- }
-
- /*** WRITE EXTRA TEXT ***/
- TempText=ExtraText;
- while (TempText)
- {
- fprintf(fp, "PU");
- fWrtFFP(fp, (FFP)(P_LMARGIN+(TempText->x-XMINP)*XFactor +100));
- fprintf(fp," ");
- if (lf) fWrtFFP(fp, (FFP)(P_BMARGIN+(TempText->y-YMINP)*YFactor-(short)(lf->tf_YSize)*10000/MAXVERT/2));
- else fWrtFFP(fp, (FFP)(P_BMARGIN+(TempText->y-YMINP)*YFactor-CHARHEIGHT*10000/MAXVERT/2));
- fprintf(fp,"; LB%s\003", TempText->String);
- TempText=TempText->NextText;
- }
-
- /*** WRITE TITLE ***/
- if (tf) fprintf(fp,"SR%f %f;\n",(float)(tf->tf_XSize)*68.0/(float)MAXHORIZ,(float)(tf->tf_YSize)*60/MAXVERT);
- else fprintf(fp,"SR%f %f;\n",(float)CHARWIDTH*68.0/(float)MAXHORIZ,(float)CHARHEIGHT*60/MAXVERT);
- if (strlen(Pict->Title->String)) {
- tmpx = 10000/2;
- if (tf) tmpx -= strlen(Pict->Title) * (short)(tf->tf_XSize)*10000/MAXHORIZ/2;
- else tmpx -= strlen(Pict->Title) * CHARWIDTH*10000/MAXHORIZ/2;
- if (tf) tmpy= P_YREG + (short)(tf->tf_YSize)*10000/MAXVERT - 1;
- else tmpy= P_YREG + CHARHEIGHT*10000/MAXVERT - 1;
- fprintf(fp, "PU%d %d;", tmpx,tmpy);
- fprintf(fp,"LB%s\003;\n", Pict->Title->String);
- }
-
- /*** WRITE YLABEL ***/
- if (strlen(Pict->YLabel->String)) {
- if (yf) fprintf(fp,"SR%f %f;\n",(float)(yf->tf_XSize)*86/MAXHORIZ,(float)(yf->tf_YSize)*43/MAXVERT);
- else fprintf(fp,"SR%f %f;\n",(float)CHARWIDTH*86/MAXHORIZ,(float)CHARHEIGHT*43/MAXVERT);
- tmpx = 1;
- tmpy= P_BMARGIN+(P_YREG-P_BMARGIN)/2;
- if (yf) tmpy -= strlen(Pict->YLabel->String) * (short)(yf->tf_XSize)*10000/MAXVERT/2;
- else tmpy -= strlen(Pict->YLabel->String) * CHARWIDTH*10000/MAXVERT/2;
- fprintf(fp, "DR0,1; PU%d %d;", tmpx,tmpy);
- fprintf(fp,"LB%s\003", Pict->YLabel->String);
- }
-
- }
-
- extern USHORT chip WaitSprite[];
- extern char *stpchr();
-
- WrtPlt(Pict,Dest)
- USHORT Dest;
- struct Pict *Pict;
- {
- struct Process *OurTask;
- struct Window *old_pr_WindowPtr;
- FILE *fp;
- short i,n=3;
- struct Plot *Plot, *TempPlot;
- FFP *x, *y, *e, tempx1, tempx2, tempy1, tempy2;
- short xptsiz, yptsiz;
- static char plotname[150], def_drive[150]="PLT:", def_path[100], def_node[30],def_extn[20];
- static char PlotNum = 0;
- void PlotBox(), PlotTri(), PlotEggs(), PlotPlus(), PlotKite();
- struct Tics *Tics;
- char tmpstr[20];
-
- if (Dest)
- {
- strcpy(plotname,filename);
- strsfn(plotname,def_drive,def_path,def_node,def_extn);
- strcat(def_drive,def_path);
- strcat(def_node,".plt");
- strcat(def_node,PlotNum);
-
- OurTask = (struct Process *)FindTask(0L);
- old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
- OurTask->pr_WindowPtr = (APTR)window;
- if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
- {
- OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
- return(TRUE);
- }
-
- OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
- strmfp(plotname,def_drive,def_node);
- PutDiskObject(plotname,&IconDiskObject);
- }
- else
- {
- if (!(fp = fopen("l:plt-handler","r") ))
- {
- Message("Printing needs the PLT: Device"); return(FALSE);
- }
- fclose(fp);
-
- Execute("c:failat >Nil: <Nil: 20 \n c:mount >Nil: <Nil: plt:",0,0);
- strcpy(plotname,"PLT:");
- }
- if (!(fp = fopen(plotname,"w") ))
- {Message(" Can't write file to PLT:"); return(FALSE);}
- if (strlen(Pict->XLabel->String))
- {
- if (xf) P_BMARGIN=4*(short)(xf->tf_YSize)*10000/MAXVERT;
- else P_BMARGIN=4*CHARHEIGHT*10000/MAXVERT;
- }
- else
- {
- if (xf) P_BMARGIN=2*(short)(xf->tf_YSize)*10000/MAXVERT;
- else P_BMARGIN=2*CHARHEIGHT*10000/MAXVERT;
- }
- if (strlen(Pict->Title->String))
- {
- if (tf) P_TMARGIN=2*(short)(tf->tf_YSize)*10000/MAXVERT;
- else P_TMARGIN=2*CHARHEIGHT*10000/MAXVERT;
- }
- else P_TMARGIN=0;
- P_YREG = 10000-P_TMARGIN;
-
- Tics = Pict->Tics;
- for (i=0; i < Tics->NY; i++) { n=max(n,GetString(&tmpstr,Tics->y[i]));}
- if (lf) P_LMARGIN=(n+1)*(short)(lf->tf_XSize)*10000/MAXHORIZ;
- else P_LMARGIN=(n+1)* CHARWIDTH*10000/MAXHORIZ;
- if (strlen(Pict->YLabel->String))
- {
- if (yf) P_LMARGIN=P_LMARGIN+(short)(yf->tf_YSize)*10000/MAXVERT;
- else P_LMARGIN=P_LMARGIN+CHARHEIGHT*10000/MAXVERT;
- }
- P_RMARGIN = 0;
- if (Pict->RMargin) {
- Plot=Pict->Plot;
- if (lf) {
- while (Plot) {
- P_RMARGIN= max(P_RMARGIN,(strlen(Plot->Legend->String)*
- (short)(lf->tf_XSize)*10000 / MAXHORIZ));
- while (Plot->Continued) Plot=Plot->NextPlot;
- Plot=Plot->NextPlot;
- }
- }
- else {
- while (Plot) {
- P_RMARGIN= max(P_RMARGIN,(strlen(Plot->Legend->String)*
- CHARWIDTH*10000 / MAXHORIZ));
- while (Plot->Continued) Plot=Plot->NextPlot;
- Plot=Plot->NextPlot;
- }
- }
- if (P_RMARGIN>0) {P_RMARGIN=P_RMARGIN+700;}
- }
- P_XREG = 10000-P_RMARGIN;
-
- XFactor=(FFP)(P_XREG-P_LMARGIN)/(XMAXP-XMINP);
- YFactor=(FFP)(P_YREG-P_BMARGIN)/(YMAXP-YMINP);
-
- fprintf(fp,"IN;SC 0 %d 0 %d;\n", P_XREG+P_RMARGIN+100, P_YREG+100+P_TMARGIN);
- fprintf(fp,"VS 20.0;\n"); /* VELOCITY cm/s */
- fprintf(fp,"\033.N;19:\033.I81;;17:\n"); /* XON/XOFF */
-
- XScale = (FFP) (P_XREG - P_LMARGIN)/(Pict->CurrReg->XMax - Pict->CurrReg->XMin);
- YScale = (P_YREG-P_BMARGIN)/ (Pict->CurrReg->YMax - Pict->CurrReg->YMin);
- XOffset = (FFP)(P_LMARGIN) / XScale - Pict->CurrReg->XMin;
- YOffset = (FFP)(P_BMARGIN) / YScale - Pict->CurrReg->YMin;
-
- Plot = Pict->Plot;
- while (Plot) {
- if (Plot->Enabled) {
- fprintf(fp,"PU;SP%d;\n", 1+Plot->Color-PLOTCOLORBASE);
- /* PLOT LINES */
- if (Plot->Lines)
- {
- TempPlot=Plot;
- tempx1=(XScale*(XOffset+Plot->x[0]));
- tempy1=(YScale*(YOffset+Plot->y[0]));
- if (Plot->Lines>1) fprintf(fp,"LT%d,2",Plot->Lines);
-
- /*** LINE OR LINE & POINT GRAPHS ***/
- if (Plot->PlotType<STEP) {
- do {
- for (i=0; i<TempPlot->NPts; i++) {
- tempx2=(XScale*(XOffset+TempPlot->x[i]));
- tempy2=(YScale*(YOffset+TempPlot->y[i]));
- if (FFPClip(&tempx1,&tempy1,&tempx2,&tempy2,(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotLines(fp,tempx1,tempy1,tempx2,tempy2);
- }
- tempx1=(XScale*(XOffset+TempPlot->x[i]));
- tempy1=(YScale*(YOffset+TempPlot->y[i]));
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
-
- /*** STEP GRAPHS ***/
- else {
- do {
- for (i=0; i<TempPlot->NPts; i++) {
- tempx2=(XScale*(XOffset+TempPlot->x[i]));
- tempy2=(YScale*(YOffset+TempPlot->y[i]));
- if (FFPClip(&tempx1,&tempy1,&tempx2,&tempy1,(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotLines(fp,tempx1,tempy1,tempx2,tempy1);
- }
- if (FFPClip(&tempx2,&tempy1,&tempx2,&tempy1,(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotLines(fp,tempx2,tempy1,tempx2,tempy2);
- }
- tempx1=(XScale*(XOffset+TempPlot->x[i]));
- tempy1=(YScale*(YOffset+TempPlot->y[i]));
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
- fprintf(fp, ";\n");
- if (strlen(Plot->Legend->String)) {
- fprintf(fp, "PU");
- fWrtFFP(fp, (FFP)(P_LMARGIN+(Plot->Legend->x-XMINP)*XFactor));
- fprintf(fp," ");
- fWrtFFP(fp,(FFP)(P_BMARGIN+(Plot->Legend->y-YMINP)*YFactor));
- fprintf(fp,";");
- fprintf(fp, "PD");
- fWrtFFP(fp, (FFP)(P_LMARGIN+(Plot->Legend->x-XMINP)*XFactor+400));
- fprintf(fp," ");
- fWrtFFP(fp,(FFP)(P_BMARGIN+(Plot->Legend->y-YMINP)*YFactor));
- fprintf(fp,";\n");
- }
- fprintf(fp,"LT;\n");
- }
-
- /* PLOT POINTS */
- if (Plot->PointSize != 0) {
- xptsiz = abs(Plot->PointSize) * (P_XREG / 1100);
- yptsiz = abs(Plot->PointSize) * (P_YREG / 850);
- TempPlot=Plot;
- do {
- x=TempPlot->x; y=TempPlot->y;
- for (i=0; i<TempPlot->NPts; i++, x++, y++) {
- tempx1=(XScale * (XOffset + *x));
- tempy1=(YScale * (YOffset + *y));
- if (FFPClipPoint(tempx1,tempy1,(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotPoint(fp,tempx1,tempy1,Plot->PointType,xptsiz,yptsiz);
- }
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- if (strlen(Plot->Legend->String)>0)
- {
- FFPPlotPoint(fp,(FFP)(P_LMARGIN+(Plot->Legend->x-XMINP)*XFactor),(FFP)(P_BMARGIN+(Plot->Legend->y-YMINP)*YFactor),Plot->PointType,xptsiz,yptsiz);
- FFPPlotPoint(fp,(FFP)(P_LMARGIN+(Plot->Legend->x-XMINP)*XFactor+400),(FFP)(P_BMARGIN+(Plot->Legend->y-YMINP)*YFactor),Plot->PointType,xptsiz,yptsiz);
- }
- }
-
- /* PLOT ERROR BARS */
- if (Pict->ShowErr) {
- TempPlot=Plot;
- do {
- if (TempPlot->PlotType!=STEP) {
- x=TempPlot->x; y=TempPlot->y; e=TempPlot->e;
- for (i=0; i<TempPlot->NPts; i++, x++, y++, e++) {
- if ( (abs(*e)) > FFPSMALL)
- {
- tempy1=YScale * (YOffset + (*y - *e));
- tempy2=YScale * (YOffset + (*y + *e));
- tempx1=XScale * (XOffset + *x);
-
- if (FFPQuickClip(tempx1,&tempy1,&tempy2,(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotLines(fp,tempx1,tempy1,tempx1,tempy2);
- fprintf(fp,";\n");
- }
-
- /* PLOT DELIMITERS ON ERROR BARS */
- if (FFPClipPoint(tempx1,YScale*(YOffset+(*y-*e)),(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotLines(fp,(XScale*(XOffset+*x)-P_ERR_DELIM),(YScale*(YOffset+(*y-*e))),
- (XScale*(XOffset+*x)+P_ERR_DELIM),(YScale*(YOffset+(*y-*e))));
- fprintf(fp,";\n");
- }
- if (FFPClipPoint(tempx1,YScale*(YOffset+(*y+*e)),(FFP)P_LMARGIN,(FFP)P_BMARGIN,(FFP)P_XREG,(FFP)P_YREG))
- {
- FFPPlotLines(fp,(XScale*(XOffset+*x)-P_ERR_DELIM),(YScale*(YOffset+(*y+*e))),
- (XScale*(XOffset+*x)+P_ERR_DELIM),(YScale*(YOffset+(*y+*e))));
- fprintf(fp,";\n");
- }
- }
- }
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
- }
- while (Plot->Continued) Plot=Plot->NextPlot;
- Plot = Plot->NextPlot;
- }
-
- WrtAxes(fp, Pict);
-
- fprintf(fp, "SP;");
- (void) fclose(fp);
- PlotNum++;
- return(TRUE);
- }
-
- FFPPlotLines(fp,x1,y1,x2,y2)
- FILE *fp;
- FFP x1,x2,y1,y2;
- {
- static FFP tempx=0, tempy=0;
-
- if ((x1==tempx)&&(y1==tempy))
- {fprintf(fp, " %d %d",(int)x2,(int)y2);}
- else
- {fprintf(fp, "; PU%d %d; PD%d %d",(int)x1,(int)y1,(int)x2,(int)y2);}
- tempx=x2; tempy=y2;
- return(0);
- }
-
-
- FFPPlotPoint(fp,x,y,PointType,xptsiz,yptsiz)
- FILE *fp;
- FFP x,y,xptsiz,yptsiz;
- short PointType;
- {
- fprintf(fp,"PU%d %d;",(int)x,(int)y);
- switch (PointType) {
- case 1: PlotTri(fp,xptsiz/2,yptsiz/2); break;
- case 2: PlotKite(fp,xptsiz/2,yptsiz/2); break;
- case 3: PlotEggs(fp,xptsiz/2,yptsiz/2); break;
- case 4: PlotEggs(fp,xptsiz/2,yptsiz/2); /* Fall through (fancy, huh?) */
- case 5: PlotPlus(fp,xptsiz/2,yptsiz/2); break;
- case 6:
- default: PlotBox(fp,xptsiz/2,yptsiz/2); break;
- }
- return(0);
- }
-
- void PlotPlus(fp,x,y)
- FILE *fp;
- SHORT x,y;
- {
- fprintf(fp,"PR%d 0;PD%d 0;PU%d %d;PD0 %d;PA;",-x,2*x,-x,-y,2*y);
- }
-
- void PlotBox(fp,x,y)
- FILE *fp;
- SHORT x,y;
- {
- fprintf(fp,"PR%d %d;PD%d 0 0 %d %d 0 0 %d;PA;\n",-x,-y,2*x,2*y, -2*x, -2*y);
- }
-
- void PlotEggs(fp,x,y)
- FILE *fp;
- SHORT x,y;
- {
- fprintf(fp,"PR%d %d;PD%d %d;PU0 %d;PD%d %d;PU%d %d;PA\n;",-x,-y,2*x,2*y,-2*y,-2*x,2*y,x,-y);
- }
-
- void PlotKite(fp,x,y)
- FILE *fp;
- SHORT x,y;
- {
- fprintf(fp,"PR%d 0;PD%d %d %d %d %d %d %d %d;PA;\n",-x,x,y,x,-y,-x,-y,-x,y);
- }
-
-
- void PlotTri(fp,x,y)
- FILE *fp;
- SHORT x,y;
- {
- fprintf(fp,"PR%d %d;PD%d %d %d %d %d 0;PA;\n",-x,-y,x,2*y,x,-2*y,-2*x);
- }
-
-
-
-
- void header(n, c, t, fp)
- int n, c, t;
- FILE *fp;
- {
- UBYTE bdummy;
- bdummy = n;
- fwrite((char *)&bdummy, 1, 1, fp);
- bdummy = c;
- fwrite((char *)&bdummy, 1, 1, fp);
- bdummy = 0;
- fwrite((char *)&bdummy, 1, 1, fp); /* LineType */
- bdummy = t;
- fwrite((char *)&bdummy, 1, 1, fp);
- bdummy = 0;
- fwrite((char *)&bdummy, 1, 1, fp); /* padding for future use */
- fwrite((char *)&bdummy, 1, 1, fp);
- }
-
- To_mCAD(Pict,Dest)
- struct Pict *Pict;
- USHORT Dest;
- {
-
- struct Process *OurTask;
- struct Window *old_pr_WindowPtr;
-
- FILE *fp;
- short i;
- struct Plot *Plot, *TempPlot;
- FFP *x, *y, *e, xtmp, ytmp, xtmp1, ytmp1, tempx1, tempx2, tempy1, tempy2;
- FFP CADMaxX, CADMinX, CADMinY, CADMaxY, CADErrEnd;
- FFP xptsiz, yptsiz, XReg, YReg, XScale, XOffset;
- char plotname[150], def_drive[150], def_path[100], def_node[30],def_extn[20];
- static char mPlotNum = 0;
- void CADBox(), CADKite(), CADTri(), CADEggs(), CADPlus();
-
- if (Dest)
- {
- strcpy(plotname,filename);
- strsfn(plotname,def_drive,def_path,def_node,def_extn);
- strcat(def_drive,def_path);
- strcat(def_node,".txt");
- strcat(def_node,mPlotNum);
-
- OurTask = (struct Process *)FindTask(0L);
- old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
- OurTask->pr_WindowPtr = (APTR)window;
- if (get_fname(window,screen,"Save File As...",def_node,def_drive)==NULL)
- {
- OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
- return(TRUE);
- }
-
- OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
- strmfp(plotname,def_drive,def_node);
- PutDiskObject(plotname,&IconDiskObject);
- }
- else
- {
- if (!(fp = fopen("T:tempfile","w") ))
- {
- Message("Save needs the T: Device"); return(FALSE);
- }
- fclose(fp);
- strcpy(plotname,"T:tempfile");
- }
-
- if (!(fp = fopen(plotname,"w") ))
- {Message(" Can't write tempory file "); return(FALSE);}
-
- XReg = Pict->CurrReg->XMax - Pict->CurrReg->XMin;
- YReg = Pict->CurrReg->YMax - Pict->CurrReg->YMin;
- XScale = YReg/XReg * 1.4434; XOffset = Pict->CurrReg->XMin;
-
- PToU(Pict, XMINP, YMINP, &CADMinX, &CADMinY);
- CADMinX = XScale * (CADMinX - XOffset);
- PToU(Pict, XMAXP, YMAXP, &CADMaxX, &CADMaxY);
- CADMaxX = XScale * (CADMaxX - XOffset);
-
- Plot = Pict->Plot;
- while (Plot) {
- if (Plot->Enabled) {
-
- /* PLOT LINES */
- if (Plot->Lines != FALSE) {
- TempPlot=Plot;
- tempx1 = XScale * (Plot->x[0] - XOffset);
- tempy1=Plot->y[0];
-
- /*** LINE OR LINE & POINT GRAPHS ***/
- if (Plot->PlotType<STEP) {
- do {
- for (i=0; i<TempPlot->NPts; i++) {
- tempx2 = XScale * (TempPlot->x[i] - XOffset);
- tempy2 = TempPlot->y[i];
- if ((FFPClip(&tempx1,&tempy1,&tempx2,&tempy2,CADMinX,CADMinY,CADMaxX,CADMaxY))
- && ( (tempx1!=tempx2)||(tempy1!=tempy2)))
- {
- fprintf(fp, "%f %f\n", tempx1,tempy1);
- fprintf(fp, "%f %f\n*>\n", tempx2,tempy2);
- if (Plot->Lines>1) fprintf(fp,"*L %d\n", Plot->Lines);
- fprintf(fp,"*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
- tempx1 = XScale * (TempPlot->x[i] - XOffset);
- tempy1 = TempPlot->y[i];
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
-
- /*** STEP GRAPHS ***/
- else {
- do {
- for (i=0; i<TempPlot->NPts; i++) {
- tempx2 = XScale * (TempPlot->x[i] - XOffset);
- tempy2 = TempPlot->y[i];
- if ((FFPClip(&tempx1,&tempy1,&tempx2,&tempy1,CADMinX,CADMinY,CADMaxX,CADMaxY))
- && (tempx1!=tempx2))
- {
- fprintf(fp, "%f %f\n", tempx1,tempy1);
- fprintf(fp, "%f %f\n*>\n", tempx2,tempy1);
- if (Plot->Lines>1) fprintf(fp,"*L %d\n", Plot->Lines);
- fprintf(fp,"*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
- if ((FFPClip(&tempx2,&tempy1,&tempx2,&tempy2,CADMinX,CADMinY,CADMaxX,CADMaxY))
- && (tempy1!=tempy2))
- {
- fprintf(fp, "%f %f\n", tempx2,tempy1);
- fprintf(fp, "%f %f\n*>\n", tempx2,tempy2);
- if (Plot->Lines>1) fprintf(fp,"*L %d\n", Plot->Lines);
- fprintf(fp,"*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
- tempx1 = XScale * (TempPlot->x[i] - XOffset);
- tempy1 = TempPlot->y[i];
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
- }
-
- /* PLOT POINTS */
- if (Plot->PointSize != 0) {
- TempPlot=Plot;
- xptsiz = abs(Plot->PointSize) * (XReg / 582.);
- xptsiz = XScale * xptsiz;
- yptsiz = abs(Plot->PointSize) * (YReg / 360.);
- do {
- x=TempPlot->x; y=TempPlot->y;
- for (i=0; i<TempPlot->NPts; i++, x++, y++) {
- tempx1=(XScale * (*x - XOffset));
- if (FFPClipPoint(tempx1,*y,CADMinX,CADMinY,CADMaxX,CADMaxY))
- {
- switch (Plot->PointType) {
- case 1: CADTri(fp,Plot,tempx1,*y,xptsiz/2,yptsiz/2); break;
- case 2: CADKite(fp,Plot,tempx1,*y,xptsiz/2,yptsiz/2); break;
- case 3: CADEggs(fp,Plot,tempx1,*y,xptsiz/2,yptsiz/2); break;
- case 4: CADEggs(fp,Plot,tempx1,*y,xptsiz/2,yptsiz/2);
- case 5: CADPlus(fp,Plot,tempx1,*y,xptsiz/2,yptsiz/2); break;
- case 6:
- default: CADBox(fp,Plot,tempx1,*y,xptsiz/2,yptsiz/2); break;
- }
- }
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
-
- /* PLOT ERROR BARS */
- if (Pict->ShowErr) {
- TempPlot=Plot;
- CADErrEnd=XScale*(ERR_DELIM*(XReg/582)); /* SCALED ERROR DELIMITER */
- do {
- if (TempPlot->PlotType!=STEP) {
- x=TempPlot->x; y=TempPlot->y; e=TempPlot->e;
- for (i=0; i<TempPlot->NPts; i++, x++, y++, e++) {
- if ((abs(*e)) > FFPSMALL)
- {
- tempx1 = XScale * (*x - XOffset);
- tempy1 = *y - *e;
- tempy2 = *y + *e;
- if (FFPClipPoint(tempx1,tempy1,CADMinX,CADMinY,CADMaxX,CADMaxY))
- {
- fprintf(fp,"%f %f\n",tempx1-CADErrEnd,tempy1);
- fprintf(fp,"%f %f\n*>\n*C %d\n\n",tempx1+CADErrEnd,tempy1,1+Plot->Color-PLOTCOLORBASE);
- }
- if (FFPClipPoint(tempx1,tempy2,CADMinX,CADMinY,CADMaxX,CADMaxY))
- {
- fprintf(fp,"%f %f\n",tempx1-CADErrEnd,tempy2);
- fprintf(fp,"%f %f\n*>\n*C %d\n\n",tempx1+CADErrEnd,tempy2,1+Plot->Color-PLOTCOLORBASE);
- }
- if (FFPQuickClip(tempx1,&tempy1,&tempy2,CADMinX,CADMinY,CADMaxX,CADMaxY))
- {
- fprintf(fp,"%f %f\n", tempx1, tempy1);
- fprintf(fp,"%f %f\n", tempx1, tempy2);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
- }
- }
- }
- } while ((TempPlot->Continued)&&(TempPlot=TempPlot->NextPlot));
- }
- }
- while (Plot->Continued) Plot=Plot->NextPlot;
- Plot = Plot->NextPlot;
- }
-
- /*** DRAW TICS/GRID ***/
- x = Pict->Tics->x; y = Pict->Tics->y;
- for (i=0; i < Pict->Tics->NX; i++) {
- xtmp = XScale * (x[i] - XOffset);
- if (Pict->Grid==2) {
- PToU(Pict, 0, YMINP, &xtmp1, &ytmp);
- PToU(Pict, 0, YMAXP, &xtmp1, &ytmp1);
- fprintf(fp,"%f %f\n%f %f\n*>\n*C 2\n\n", xtmp, ytmp, xtmp, ytmp1);
- }
- else {
- if ((Pict->Grid==0)||(Pict->Grid==3))
- {
- PToU(Pict, 0, YMINP, &xtmp1, &ytmp);
- fprintf(fp,"%f %f\n", xtmp, ytmp);
- PToU(Pict, 0, YMINP+X_TIC_SIZE, &xtmp1, &ytmp1);
- fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp, ytmp1);
- }
- if (Pict->Grid==3)
- {
- PToU(Pict, 0, YMAXP, &xtmp1, &ytmp);
- fprintf(fp,"%f %f\n", xtmp, ytmp);
- PToU(Pict, 0, YMAXP-X_TIC_SIZE, &xtmp1, &ytmp1);
- fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp, ytmp1);
- }
- }
- }
- for (i=0; i < Pict->Tics->NY; i++) {
- if (Pict->Grid==2) {
- PToU(Pict, XMINP, YMINP, &xtmp, &ytmp);
- xtmp = XScale * (xtmp - XOffset);
- PToU(Pict, XMAXP, YMAXP, &xtmp1, &ytmp1);
- xtmp1 = XScale * (xtmp1 - XOffset);
- fprintf(fp,"%f %f\n%f %f\n*>\n*C 2\n\n", xtmp, y[i], xtmp1, y[i]);
- }
- else {
- if ((Pict->Grid==0)||(Pict->Grid==3))
- {
- PToU(Pict, XMINP, 0, &xtmp, &ytmp);
- xtmp = XScale * (xtmp - XOffset);
- fprintf(fp,"%f %f\n", xtmp, y[i]);
- PToU(Pict, XMINP+Y_TIC_SIZE, 0, &xtmp1, &ytmp1);
- xtmp1 = XScale * (xtmp1 - XOffset);
- fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp1, y[i]);
- }
- if (Pict->Grid==3)
- {
- PToU(Pict, XMAXP, 0, &xtmp, &ytmp);
- xtmp = XScale * (xtmp - XOffset);
- fprintf(fp,"%f %f\n", xtmp, y[i]);
- PToU(Pict, XMAXP-Y_TIC_SIZE, 0, &xtmp1, &ytmp1);
- xtmp1 = XScale * (xtmp1 - XOffset);
- fprintf(fp,"%f %f\n*>\n*C 3\n\n", xtmp1, y[i]);
- }
- }
- }
-
- /*** PRINT TIC VALUES ***/
- /*
- * for (i=0; i < Pict->Tics->NX; i++) {
- * n = sprintf(tmpstr, "%-.4f", Pict->Tics->x[i]);
- * n = min(n, 7);
- * while (tmpstr[n-1] == '0') n--;
- * tmpstr[n]=0;
- * }
- * for (i=0; i < Pict->Tics->NY; i++) {
- * n = sprintf(tmpstr, "%-.4f", Pict->Tics->y[i]);
- * n = min(n, 7);
- * while (tmpstr[n-1] == '0') n--;
- * tmpstr[n]=0;
- * }
- */
-
- /*** DRAW AXES ***/
- if (Pict->Grid<5)
- {
- fprintf(fp, "%f %f\n", CADMinX, CADMaxY);
- fprintf(fp, "%f %f\n", CADMinX, CADMinY);
- fprintf(fp, "%f %f\n", CADMaxX, CADMinY);
- if (Pict->Grid>1)
- {
- fprintf(fp, "%f %f\n", CADMaxX, CADMaxY);
- fprintf(fp, "%f %f\n", CADMinX, CADMaxY);
- }
- fprintf(fp,"*>\n*C 1\n\n");
- }
- (void) fclose(fp);
- mPlotNum++;
- return(TRUE);
- }
-
- void CADBox(fp,Plot,x,y,dx,dy)
- FILE *fp;
- struct Plot *Plot;
- FFP x,y,dx,dy;
- {
- x = x - dx;
- y = y - dy;
- fprintf(fp,"%f %f\n", x, y); x += 2*dx;
- fprintf(fp,"%f %f\n", x, y); y += 2*dy;
- fprintf(fp,"%f %f\n", x, y); x -= 2*dx;
- fprintf(fp,"%f %f\n", x, y); y -= 2*dy;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
-
- }
-
- void CADPlus(fp,Plot,x,y,dx,dy)
- FILE *fp;
- struct Plot *Plot;
- FFP x,y,dx,dy;
- {
- x = x - dx;
- fprintf(fp,"%f %f\n", x, y); x += 2*dx;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
-
- x -= dx; y -= dy;
- fprintf(fp,"%f %f\n", x, y); y += 2*dy;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
-
- void CADEggs(fp,Plot,x,y,dx,dy)
- FILE *fp;
- struct Plot *Plot;
- FFP x,y,dx,dy;
- {
- x = x - dx; y = y - dy;
- fprintf(fp,"%f %f\n", x, y); x += 2*dx; y += 2*dy;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
-
- y -= 2*dy;
- fprintf(fp,"%f %f\n", x, y); x -= 2*dx; y += 2*dy;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
-
-
- void CADKite(fp,Plot,x,y,dx,dy)
- FILE *fp;
- struct Plot *Plot;
- FFP x,y,dx,dy;
- {
- x = x - dx;
- fprintf(fp,"%f %f\n", x, y); x += dx; y += dy;
- fprintf(fp,"%f %f\n", x, y); x += dx; y -= dy;
- fprintf(fp,"%f %f\n", x, y); x -= dx; y -= dy;
- fprintf(fp,"%f %f\n", x, y); x -= dx; y += dy;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
-
- void CADTri(fp,Plot,x,y,dx,dy)
- FILE *fp;
- struct Plot *Plot;
- FFP x,y,dx,dy;
- {
- x = x - dx;
- y = y - dy;
- fprintf(fp,"%f %f\n", x, y); x += dx; y += 2*dy;
- fprintf(fp,"%f %f\n", x, y); x += dx; y -= 2*dy;
- fprintf(fp,"%f %f\n", x, y); x -= 2*dy;
- fprintf(fp,"%f %f\n", x, y);
- fprintf(fp,"*>\n*C %d\n\n", 1+Plot->Color-PLOTCOLORBASE);
- }
-
-