home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk373.lzh / Multiplot / source / mplot_src / src.zoo / savedat.c < prev    next >
C/C++ Source or Header  |  1990-08-02  |  5KB  |  205 lines

  1. #include <graphics/display.h>
  2. #include <libraries/dosextens.h>
  3. #include <libraries/diskfont.h>
  4. #include <exec/exec.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <graphics/regions.h>
  7. #include <devices/keymap.h>
  8. #include <stdio.h>
  9. #include <workbench/startup.h>
  10. #include <intuition/intuition.h>
  11. #include <workbench/workbench.h>
  12. #include <graphics/gfxmacros.h>
  13. #include <graphics/gfxbase.h>
  14. #include <math.h>
  15.  
  16. #include "struct.h"
  17. #include "ffp.h"
  18.  
  19. USHORT DatIconImageData[] = {
  20.   0x0,   0x0,   0x0,
  21.   0x0,   0x0,   0x0,
  22.   0x1fff,   0xffff,   0xffe0,
  23.   0x1fff,   0xffff,   0xffe0,
  24.   0x1fff,   0xffff,   0xffe0,
  25.   0x1fff,   0xffff,   0xffe0,
  26.   0x1fff,   0xffff,   0xffe0,
  27.   0x1fff,   0xffff,   0xffe0,
  28.   0x1fff,   0xffff,   0xffe0,
  29.   0x1fff,   0xffff,   0xffe0,
  30.   0x1fff,   0xffff,   0xffe0,
  31.   0x1fff,   0xffff,   0xffe0,
  32.   0x1fff,   0xffff,   0xffe0,
  33.   0x1fff,   0xffff,   0xffe0,
  34.   0x1fff,   0xffff,   0xffe0,
  35.   0x1fff,   0xffff,   0xffe0,
  36.   0x1fff,   0xffff,   0xffe0,
  37.   0x1fff,   0xffff,   0xffe0,
  38.   0x1fff,   0xffff,   0xffe0,
  39.   0x1fff,   0xffff,   0xffe0,
  40.   0x1fff,   0xffff,   0xe000,
  41.   0x1fff,   0xfffc,   0xfe0,
  42.   0x1fff,   0xfffd,   0xffc0,
  43.   0x1fff,   0xfffe,   0xff80,
  44.   0x1fff,   0xffff,   0x3e00,
  45.   0x1fff,   0xffff,   0xbc00,
  46.   0x1fff,   0xffff,   0x9000,
  47.   0x1fff,   0xffff,   0xc000,
  48.   0x0,   0x0,   0x0,
  49.   0x0,   0x0,   0x0,
  50.  /*------ plane # 1: --------*/
  51.  
  52.   0x0,   0x0,   0x0,
  53.   0x7fff,   0xffff,   0xfff8,
  54.   0x6000,   0x0,   0x18,
  55.   0x6000,   0x0,   0x18,
  56.   0x6000,   0x0,   0x18,
  57.   0x63f6,   0xf1ce,   0x3f18,
  58.   0x6200,   0x81,   0xc118,
  59.   0x6007,   0x90,   0x8118,
  60.   0x6202,   0x1fef,   0x8118,
  61.   0x6202,   0x2080,   0x8118,
  62.   0x6002,   0x41c1,   0xc118,
  63.   0x6207,   0x8000,   0x118,
  64.   0x623a,   0x0,   0x118,
  65.   0x6042,   0x0,   0x118,
  66.   0x62c7,   0x0,   0x118,
  67.   0x6200,   0x0,   0x118,
  68.   0x63f7,   0xfdfd,   0xff18,
  69.   0x6000,   0x0,   0x18,
  70.   0x6000,   0x0,   0x18,
  71.   0x6000,   0x0,   0x18,
  72.   0x6000,   0x0,   0x1ff8,
  73.   0x6000,   0x3,   0xf018,
  74.   0x6000,   0x2,   0x38,
  75.   0x6000,   0x1,   0x60,
  76.   0x6000,   0x0,   0xc1c0,
  77.   0x6000,   0x0,   0x4300,
  78.   0x6000,   0x0,   0x6e00,
  79.   0x6000,   0x0,   0x3800,
  80.   0x7fff,   0xffff,   0xe000,
  81.   0x0,   0x0,   0x0
  82. };
  83.  
  84. #define ICONHEI 30
  85. #define ICONWID 46
  86. struct Image DatIconImage = {
  87. 0,
  88. 0,
  89. ICONWID,
  90. ICONHEI, 2,
  91. DatIconImageData,
  92. 3, 0,
  93. NULL
  94. };
  95.  
  96.  
  97. struct DiskObject DatIconDiskObject = {
  98. WB_DISKMAGIC,
  99. WB_DISKVERSION,
  100.  
  101. NULL,
  102. 0, 0,
  103. ICONWID, ICONHEI+1,
  104. GADGIMAGE|GADGBACKFILL,
  105. RELVERIFY|GADGIMMEDIATE,
  106. BOOLGADGET,
  107. (APTR) &DatIconImage,
  108. NULL,
  109. NULL,
  110. 0,
  111. NULL,
  112. 0,
  113. NULL,
  114. WBPROJECT,
  115. "Multiplot:Multiplot",
  116. NULL,
  117. NO_ICON_POSITION,
  118. NO_ICON_POSITION,
  119. NULL,
  120. NULL,
  121. 10000
  122. };
  123.  
  124. extern struct Window *window;
  125. extern char filename[150];
  126. extern struct Screen *screen;
  127. extern struct TextBox *ExtraText;
  128. extern int MAXHORIZ;
  129. extern int MAXVERT;
  130.  
  131.  
  132. SaveDat(Pict,saveas)
  133. struct Pict *Pict;
  134. short saveas;
  135. {
  136.    struct Process  *OurTask;
  137.    struct Window   *old_pr_WindowPtr;
  138.    int i;
  139.    FFP *xarray, *yarray, *earray;
  140.    FILE *fp;
  141.    struct Plot *Plot;
  142.    struct TextBox *TempText;
  143.    char plotname[150], def_drive[150], def_path[100], def_node[30],def_extn[20];
  144.    static char mPlotNum = 0;
  145.  
  146.    strcpy(plotname,filename);
  147.    if (saveas)
  148.      {
  149.         strsfn(plotname,def_drive,def_path,def_node,def_extn);
  150.         strcat(def_drive,def_path);
  151.         strcat(def_node,".dat");
  152.         strcat(def_node,mPlotNum);
  153.  
  154.         OurTask = (struct Process *)FindTask(0L);
  155.         old_pr_WindowPtr = (struct Window *)OurTask->pr_WindowPtr;
  156.         OurTask->pr_WindowPtr = (APTR)window;
  157.         if (get_fname(window,screen,"Save Data As...",def_node,def_drive)==NULL)
  158.             { OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr; return(TRUE); }
  159.         OurTask->pr_WindowPtr = (APTR)old_pr_WindowPtr;
  160.         strmfp(plotname,def_drive,def_node);
  161.      }
  162.    if (!(fp = fopen(plotname,"w") ))
  163.       {Message("    Can't write data file  "); return(FALSE);}
  164.  
  165.    fprintf(fp,"*TITLE* %s\n*XLABEL* %s\n*YLABEL* %s\n", Pict->Title,Pict->XLabel->String,Pict->YLabel->String);
  166.    fprintf(fp,"*AUTOSCRIPT* %d %d %d %d %d %d %.5g %.5g %.5g %.5g\n\n",
  167.       Pict->ErrBar,Pict->ShowErr,Pict->Grid,Pict->Tics->NX,Pict->Tics->NY,Pict->RMargin,
  168.       Pict->CurrReg->XMin,Pict->CurrReg->XMax,Pict->CurrReg->YMin, Pict->CurrReg->YMax);
  169.    Plot = Pict->Plot;
  170.    while (Plot)
  171.      {
  172.        fprintf(fp,"*LEGEND* %s\n",Plot->Legend->String);
  173.        fprintf(fp,"*AUTOSCRIPT* %d %d %d %d %d %d %d %d\n",
  174.             Plot->Color,Plot->PlotType,Plot->Lines,Plot->PointSize,Plot->PointType,Plot->Enabled,MAXHORIZ-Plot->Legend->x,Plot->Legend->y);
  175.        do {
  176.              xarray=Plot->x; yarray=Plot->y; earray=Plot->e;
  177.              for (i=0;i<Plot->NPts;i++,xarray++,yarray++,earray++)
  178.                {
  179.                   if (Pict->ErrBar) {fprintf(fp,"%.5g  %.5g  %.5g\n", *xarray,*yarray,*earray);}
  180.                   else {fprintf(fp,"%.5g  %.5g\n", *xarray,*yarray);}
  181.                }
  182.           } while ((Plot->Continued)&&(Plot=Plot->NextPlot));
  183.        fprintf(fp,"\n\n");
  184.        Plot=Plot->NextPlot;
  185.      }
  186.    if (ExtraText)
  187.      {
  188.        fprintf(fp,"*EXTRATEXT*\n");
  189.        TempText=ExtraText;
  190.        while (TempText)
  191.          {
  192.             fprintf(fp,"%d %d %s\n",MAXHORIZ-TempText->x,MAXVERT-TempText->y,TempText->String);
  193.             TempText=TempText->NextText;
  194.          }
  195.      }
  196.    (void) fclose(fp);
  197.    if (!PutDiskObject(plotname,&DatIconDiskObject))
  198.       {Message("    Can't write icon file  "); return(FALSE);}
  199.  
  200.    return(TRUE);
  201. }
  202.  
  203.  
  204.  
  205.