home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / Gnuplot 3.5 / source / gnubin.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-11  |  4.5 KB  |  159 lines  |  [TEXT/R*ch]

  1. #ifndef lint
  2. static char *RCSid = "$Id: gnubin.c%v 3.50 1993/07/09 05:35:24 woo Exp $";
  3. #endif
  4.  
  5.  
  6. /*
  7.  * The addition of gnu_binary_files and binary_files, along with a small patch
  8.  * to command.c, will permit gnuplot to plot binary files.
  9.  * gnu_binary_files  - contains the code that relies on gnuplot include files
  10.  *                     and other definitions
  11.  * binary_files      - contains those things that are independent of those 
  12.  *                     definitions and files
  13.  *
  14.  * With these routines, hidden line removal of your binary data is possible!
  15.  *
  16.  * Last update: 3/3/92 for Gnuplot 3.24.
  17.  * Created from code for written by RKC for gnuplot 2.0b.
  18.  *
  19.  * 19 September 1992  Lawrence Crowl  (crowl@cs.orst.edu)
  20.  * Added user-specified bases for log scaling.
  21.  *
  22.  * Copyright (c) 1991,1992 Robert K. Cunningham, MIT Lincoln Laboratory
  23.  *
  24.  */
  25. #include <stdio.h>
  26. #include <math.h>
  27. #include "plot.h"
  28. #ifdef THINK_C
  29. #include "tout_protos.h"
  30. #endif
  31.  
  32. #include "setshow.h"
  33.  
  34. /******************* SHARED INCLUDE FILE--start ***********************
  35.  *  I recommend that these be put into an include file that all
  36.  *  will share -- but I leave it up to the powers that be to do this.
  37.  */
  38. /* Copied from command.c -- this should be put in a shared macro file */
  39. #define inrange(z,min,max) ((min<max) ? ((z>=min)&&(z<=max)) : ((z>=max)&&(z<=min)) )
  40.  
  41. /* Routines for interfacing with command.c */
  42. float GPFAR *vector();
  43. float GPFAR *extend_vector();
  44. float GPFAR *retract_vector();
  45. float GPFAR * GPFAR *matrix();
  46. float GPFAR * GPFAR *extend_matrix();
  47. float GPFAR * GPFAR *retract_matrix();
  48. void free_matrix();
  49. void free_vector();
  50. /******************* SHARED INCLUDE FILE--end *************************/
  51. /*
  52.   Here we keep putting new plots onto the end of the linked list
  53.  
  54.   We assume the data's x,y values have x1<x2, x2<x3... and 
  55.                                        y1<y2, y2<y3... .
  56.   Actually, I think the assumption is less stron than that--it looks like
  57.   the direction just has to be the same.
  58.  
  59.   This routine expects the following to be properly initialized:
  60.       is_log_x, is_log_y, and is_log_z 
  61.       base_log_x, base_log_y, and base_log_z 
  62.       log_base_log_x, log_base_log_y, and log_base_log_z 
  63.       xmin,ymin, and zmin
  64.       xmax,ymax, and zmax
  65.       autoscale_lx, autoscale_ly, and autoscale_lz
  66.  
  67. */
  68. int
  69.   get_binary_data(this_plot,fp,p_ret_iso)
  70. struct surface_points *this_plot;
  71. FILE *fp;
  72. struct iso_curve **p_ret_iso;
  73. {
  74.   register int i,j;
  75.   float GPFAR * GPFAR *matrix, GPFAR *rt, GPFAR *ct;
  76.   int nr,nc;
  77.   int ndata;
  78.   struct iso_curve *this_iso;
  79.   float z;
  80.  
  81.   this_plot->plot_type = DATA3D;
  82.   this_plot->has_grid_topology = TRUE;
  83.  
  84.   if(!fread_matrix(fp,&matrix,&nr,&nc,&rt,&ct))
  85.     int_error("Binary file read error: format unknown!",NO_CARET);
  86.  
  87.   /* Now we do some error checking on the x and y axis */
  88.   if(is_log_x)
  89.     for(i=0; i<nc; i++)
  90.       if(ct[i] < 0.0)
  91.     int_error("X value must be above 0 for log scale!",NO_CARET);
  92.       else
  93.     ct[i] = log(ct[i])/log_base_log_x;
  94.  
  95.   if(is_log_y)
  96.     for(i=0; i<nr; i++)
  97.       if(rt[i] < 0.0)
  98.     int_error("Y value must be above 0 for log scale!",NO_CARET);
  99.       else
  100.     rt[i] = log(rt[i])/log_base_log_y;
  101.  
  102.   /* Count up the number of used column entries */
  103.   if (autoscale_lx) {
  104.     ndata = nc;
  105.     for(j=0; j< nc; j++){
  106.       if (ct[j] < xmin) xmin = ct[j];
  107.       if (ct[j] > xmax) xmax = ct[j];
  108.     }
  109.   }
  110.   else {
  111.     for(ndata = 0, j = 0; j< nc; j++){
  112.       if (!((ct[j] < xmin) || (ct[j] > xmax)))/*Column is in bounds*/
  113.     ndata++;
  114.     }
  115.   }
  116.  
  117.   for(i=0; i < nr; i++){
  118.       if (autoscale_ly) {
  119.     if (rt[i] < ymin) ymin = rt[i];
  120.     if (rt[i] > ymax) ymax = rt[i];
  121.       }
  122.       else if ((rt[i] < ymin) || (rt[i] > ymax))/* This row is out of bounds */
  123.     continue;
  124.  
  125.       this_iso = iso_alloc( ndata );/*Allocate the correct number of entries*/
  126.       for(ndata = 0, j = 0; j< nc; j++){/* Cycle through data */
  127.  
  128.     if ((ct[j] < xmin) || (ct[j] > xmax))/*Column is out of bounds*/
  129.       continue;       /* Only affects non-autoscale_lx cases */
  130.  
  131.     this_iso->points[ndata].x = ct[j];
  132.     this_iso->points[ndata].y = rt[i];
  133.     z = matrix[i][j];
  134.     if(is_log_z)
  135.       if (z <= 0.0)
  136.         int_error("Z value must be above 0 for log scale!",NO_CARET);
  137.       else
  138.         z = log(z)/log_base_log_z;
  139.     this_iso->points[ndata].z = z;
  140.       
  141.     if (autoscale_lz) {
  142.       if (z < zmin) zmin = z;
  143.       if (z > zmax) zmax = z;
  144.     }
  145.     ndata++;
  146.       }
  147.       this_iso->p_count = ndata;
  148.       this_iso->next = this_plot->iso_crvs;
  149.       this_plot->iso_crvs = this_iso;
  150.       this_plot->num_iso_read++;
  151.   }
  152.   
  153.   free_matrix(matrix,0,nr-1,0,nc-1);
  154.   free_vector(rt,0,nr-1);
  155.   free_vector(ct,0,nc-1);
  156.   *p_ret_iso = this_iso;
  157.   return(ndata+1);
  158. }
  159.