home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume40 / gnuplot / part16 < prev    next >
Encoding:
Text File  |  1993-10-22  |  80.5 KB  |  2,794 lines

  1. Newsgroups: comp.sources.misc
  2. From: woo@playfair.stanford.edu ("Alexander Woo")
  3. Subject: v40i028:  gnuplot - interactive function plotting utility, Part16/33
  4. Message-ID: <1993Oct22.163527.24041@sparky.sterling.com>
  5. X-Md4-Signature: 04e2fd17e40810e5d5ad2b144d4521d9
  6. Sender: kent@sparky.sterling.com (Kent Landfield)
  7. Organization: Sterling Software
  8. Date: Fri, 22 Oct 1993 16:35:27 GMT
  9. Approved: kent@sparky.sterling.com
  10.  
  11. Submitted-by: woo@playfair.stanford.edu ("Alexander Woo")
  12. Posting-number: Volume 40, Issue 28
  13. Archive-name: gnuplot/part16
  14. Environment: UNIX, MS-DOS, VMS
  15. Supersedes: gnuplot3: Volume 24, Issue 23-48
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then feed it
  19. # into a shell via "sh file" or similar.  To overwrite existing files,
  20. # type "sh file -c".
  21. # Contents:  gnuplot/binary.c gnuplot/demo/prob.dem gnuplot/graph3d.c.B
  22. # Wrapped by kent@sparky on Wed Oct 20 17:14:51 1993
  23. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 16 (of 33)."'
  26. if test -f 'gnuplot/binary.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'gnuplot/binary.c'\"
  28. else
  29.   echo shar: Extracting \"'gnuplot/binary.c'\" \(14608 characters\)
  30.   sed "s/^X//" >'gnuplot/binary.c' <<'END_OF_FILE'
  31. X#ifndef lint
  32. Xstatic char *RCSid = "$Id: binary.c%v 3.50.1.16 1993/08/27 05:04:42 woo Exp $";
  33. X#endif
  34. X
  35. X/*
  36. X * The addition of gnubin and binary, along with a small patch
  37. X * to command.c, will permit gnuplot to plot binary files.
  38. X * gnubin  - contains the code that relies on gnuplot include files
  39. X *                     and other definitions
  40. X * binary      - contains those things that are independent of those 
  41. X *                     definitions and files
  42. X *
  43. X * With these routines, hidden line removal of your binary data is possible!
  44. X *
  45. X * Last update:  3/29/92 memory allocation bugs fixed. jvdwoude@hut.nl
  46. X *               3/09/92 spelling errors, general cleanup, use alloc with no
  47. X *                       nasty fatal errors
  48. X *               3/03/92 for Gnuplot 3.24.
  49. X * Created from code for written by RKC for gnuplot 2.0b.
  50. X *
  51. X * Copyright (c) 1991,1992 Robert K. Cunningham, MIT Lincoln Laboratory
  52. X *
  53. X */
  54. X#include <stdio.h>
  55. X#if !defined(apollo) && !defined(sequent) && !defined(u3b2) && !defined(alliant) &&!defined(sun386)
  56. X#include <stdlib.h> /* realloc() */
  57. X#else
  58. X#include <sys/types.h> /* typedef long size_t; */
  59. Xextern char *realloc();
  60. X#endif
  61. X#include <math.h>
  62. X
  63. X#if defined(MSDOS) && defined(__TURBOC__) && !defined(DOSX286)
  64. X#include <alloc.h>        /* for farmalloc, farrealloc */
  65. X#define SMALLMALLOC
  66. X#endif
  67. X#if defined(_Windows) && !defined(WIN32)
  68. X#include <windows.h>
  69. X#include <windowsx.h>
  70. X#define farmalloc(s) GlobalAllocPtr(GHND,s)
  71. X#define farrealloc(p,s) GlobalReAllocPtr(p,s,GHND)
  72. X#define SMALLMALLOC
  73. X#endif
  74. X#ifdef sequent
  75. X#include <sys/types.h>      /* unsigned long size_t; */
  76. X#endif
  77. X
  78. X#include "plot.h"   /* We have to get TRUE and FALSE */
  79. X
  80. Xfloat GPFAR *vector();
  81. Xfloat GPFAR *extend_vector();
  82. Xfloat GPFAR *retract_vector();
  83. Xfloat GPFAR * GPFAR *matrix();
  84. Xfloat GPFAR * GPFAR *extend_matrix();
  85. Xfloat GPFAR * GPFAR *retract_matrix();
  86. Xvoid free_matrix();
  87. Xvoid free_vector();
  88. X
  89. X/* versions of alloc, realloc and free that work with segmented
  90. X   architectures (yuk!) */
  91. Xchar GPFAR *
  92. Xgpfaralloc(size, message)
  93. X    unsigned long size;        /* # of bytes */
  94. X    char *message;            /* description of what is being allocated */
  95. X{
  96. X#ifdef SMALLMALLOC
  97. X    char GPFAR *p;                /* the new allocation */
  98. X    char errbuf[100];        /* error message string */
  99. X    p = farmalloc(size);
  100. X    if (p == (char *)NULL) {
  101. X        /* really out of memory */
  102. X        if (message != NULL) {
  103. X            (void) sprintf(errbuf, "out of memory for %s", message);
  104. X            int_error(errbuf, NO_CARET);
  105. X            /* NOTREACHED */
  106. X        }
  107. X        /* else we return NULL */
  108. X    }
  109. X    return(p);
  110. X#else
  111. X    return alloc(size, message);
  112. X#endif
  113. X}
  114. X
  115. Xchar GPFAR *
  116. Xgpfarrealloc(p, size)
  117. X    char GPFAR *p;            /* old pointer */
  118. X    unsigned long size;        /* # of bytes */
  119. X{
  120. X#ifdef SMALLMALLOC
  121. X    return farrealloc(p, size);
  122. X#else
  123. X    return realloc(p, (size_t)size);
  124. X#endif
  125. X}
  126. X
  127. Xvoid
  128. Xgpfarfree(p)
  129. Xchar GPFAR *p;
  130. X{
  131. X#ifdef SMALLMALLOC
  132. X#ifdef _Windows
  133. XHGLOBAL hGlobal = GlobalHandle(SELECTOROF(p));
  134. X    GlobalUnlock(hGlobal);
  135. X    GlobalFree(hGlobal);
  136. X#else
  137. X    farfree(p);
  138. X#endif
  139. X#else
  140. X    free(p);
  141. X#endif
  142. X}
  143. X
  144. X
  145. X/* 
  146. X * This routine scans the first block of the file to see if the file is a 
  147. X * binary file.  A file is considered binary if 10% of the characters in it 
  148. X * are not in the ascii character set. (values < 128), or if a NUL is found.
  149. X * I hope this doesn't break when used on the bizzare PC's.
  150. X */
  151. Xint
  152. X  is_binary_file(fp)
  153. Xregister FILE *fp;
  154. X{
  155. X  register int i,len;
  156. X  register int odd;                /* Contains a count of the odd characters */
  157. X  long where;
  158. X  register unsigned char *c;
  159. X  unsigned char buffer[512];
  160. X
  161. X  if((where = ftell(fp)) == -1){ /* Find out where we start */
  162. X    fprintf(stderr,"Notice: Assuming unseekable data is not binary\n");
  163. X    return(FALSE);
  164. X  }
  165. X  else {
  166. X    rewind(fp);
  167. X
  168. X    len = fread(buffer,sizeof(char),512,fp);
  169. X    if (len <= 0)                      /* Empty file is declared ascii */
  170. X      return(FALSE);
  171. X
  172. X    c = buffer;
  173. X
  174. X    /* now scan buffer to look for odd characters */
  175. X    odd = 0;
  176. X    for (i=0; i<len; i++,c++) {
  177. X      if (!*c) {              /* NUL _never_ allowed in text */
  178. X    odd += len;
  179. X    break;
  180. X      }
  181. X      else if ((*c & 128) ||/* Meta-characters--we hope it's not formatting */
  182. X           (*c == 127)|| /* DEL */
  183. X           (*c < 32 && 
  184. X        *c != '\n' && *c != '\r' && *c != '\b' &&
  185. X        *c != '\t' && *c != '\f' && *c != 27 /*ESC*/))
  186. X    odd++;
  187. X    }
  188. X  
  189. X    fseek(fp,where,0); /* Go back to where we started */
  190. X
  191. X    if (odd * 10 > len)             /* allow 10% of the characters to be odd */
  192. X      return(TRUE);
  193. X    else
  194. X      return(FALSE);
  195. X  }
  196. X}
  197. X/*========================= I/O Routines ================================
  198. X  These may be useful for situations other than just gnuplot.  Note that I 
  199. X  have included the reading _and_ the writing routines, so others can create 
  200. X  the file as well as read the file.
  201. X*/
  202. X
  203. X/*
  204. X  This function reads a matrix from a stream
  205. X
  206. X  This routine never returns anything other than vectors and arrays
  207. X  that range from 0 to some number.  
  208. X
  209. X*/
  210. X#define START_ROWS 100/* Each of these must be at least 1 */
  211. X#define ADD_ROWS 50
  212. Xint
  213. X  fread_matrix(fin,ret_matrix,nr,nc,row_title,column_title)
  214. XFILE *fin;
  215. Xfloat GPFAR * GPFAR * GPFAR *ret_matrix,GPFAR * GPFAR * row_title, GPFAR * GPFAR *column_title;
  216. Xint *nr,*nc;
  217. X{
  218. X  float  GPFAR * GPFAR *m, GPFAR *rt, GPFAR *ct;
  219. X  register int num_rows = START_ROWS;
  220. X  register int num_cols;
  221. X  register int current_row = 0;
  222. X  register float  GPFAR * GPFAR *temp_array;
  223. X  float fdummy;
  224. X  
  225. X  fread(&fdummy,sizeof(fdummy),1,fin);
  226. X  num_cols = (int)fdummy;
  227. X  
  228. X  /* 
  229. X    Choose a reasonable number of rows,
  230. X    allocate space for it and continue until this space
  231. X    runs out, then extend the matrix as necessary.
  232. X    */
  233. X  ct = vector(0,num_cols-1);
  234. X  fread(ct,sizeof(*ct),num_cols,fin);
  235. X
  236. X  rt = vector(0,num_rows-1);
  237. X  m = matrix(0,num_rows-1,0,num_cols-1);
  238. X
  239. X  while(fread(&rt[current_row], sizeof(rt[current_row]), 1, fin)==1){ 
  240. X    /* We've got another row */
  241. X    if(fread(m[current_row],sizeof(*(m[current_row])),num_cols,fin)!=num_cols)
  242. X      return(FALSE);      /* Not a True matrix */
  243. X
  244. X    current_row++;
  245. X    if(current_row>=num_rows){ /* We've got to make a bigger rowsize */
  246. X      temp_array = extend_matrix(m,0,num_rows-1,0,num_cols-1,
  247. X                 num_rows+ADD_ROWS-1,num_cols-1);
  248. X      rt = extend_vector(rt,0,num_rows-1,num_rows+ADD_ROWS-1);
  249. X      
  250. X      num_rows+= ADD_ROWS;
  251. X      m = temp_array;
  252. X    }
  253. X  }
  254. X  /*  finally we force the matrix to be the correct row size */
  255. X  /*  bug fixed. procedure called with incorrect 6th argument. jvdwoude@hut.nl */
  256. X  temp_array = retract_matrix(m,0,num_rows-1,0,num_cols-1,current_row-1,num_cols-1);
  257. X  /* Now save the things that change */
  258. X  *ret_matrix = temp_array;
  259. X  *row_title = retract_vector(rt, 0, num_rows-1, current_row-1);
  260. X  *column_title = ct;
  261. X  *nr = current_row;/* Really the total number of rows */
  262. X  *nc = num_cols;
  263. X  return(TRUE);
  264. X}
  265. X
  266. X/* This writes a matrix to a stream 
  267. X   Note that our ranges are inclusive ranges--and we can specify subsets.
  268. X   This behaves similarly to the xrange and yrange operators in gnuplot
  269. X   that we all are familiar with.
  270. X*/
  271. Xint
  272. X  fwrite_matrix(fout,m,nrl,nrh,ncl,nch,row_title,column_title)
  273. Xregister FILE *fout;
  274. Xregister float  GPFAR * GPFAR *m, GPFAR *row_title, GPFAR *column_title;
  275. Xregister int nrl,nrh,ncl,nch;
  276. X{
  277. X  register int j;
  278. X  float length;
  279. X  register int col_length;
  280. X  register int status;
  281. X  float  GPFAR *title = NULL;
  282. X
  283. X  length = col_length = nch-ncl+1;
  284. X
  285. X  if((status = fwrite((char*)&length,sizeof(float),1,fout))!=1){
  286. X    fprintf(stderr,"fwrite 1 returned %d\n",status);
  287. X    return(FALSE);
  288. X  }
  289. X  
  290. X  if(!column_title){
  291. X    column_title = title = vector(ncl,nch);
  292. X    for(j=ncl; j<=nch; j++)
  293. X      title[j] = j;
  294. X  }
  295. X  fwrite((char*)column_title,sizeof(float),col_length,fout);
  296. X  if(title){
  297. X    free_vector(title,ncl,nch);
  298. X    title = NULL;
  299. X  }
  300. X
  301. X  if(!row_title){
  302. X    row_title = title = vector(nrl,nrh);
  303. X    for(j=nrl; j<=nrh; j++)
  304. X      title[j] = j;
  305. X  }
  306. X    
  307. X  for(j=nrl; j<=nrh; j++){
  308. X    fwrite((char*)&row_title[j],sizeof(float),1,fout);
  309. X    fwrite((char*)(m[j]+ncl),sizeof(float),col_length,fout);
  310. X  }
  311. X  if(title)
  312. X    free_vector(title,nrl,nrh);
  313. X
  314. X  return(TRUE);
  315. X}
  316. X
  317. X/*===================== Support routines ==============================*/
  318. X
  319. X/******************************** VECTOR *******************************
  320. X *       The following routines interact with vectors.
  321. X *
  322. X *   If there is an error we don't really return - int_error breaks us out.
  323. X *
  324. X *   This subroutine based on a subroutine listed in "Numerical Recipies in C",
  325. X *   by Press, Flannery, Teukoilsky and Vetterling (1988).
  326. X *
  327. X */
  328. Xfloat GPFAR *vector(nl,nh)
  329. X     register int nl,nh;
  330. X{
  331. X  register float GPFAR *vec;
  332. X
  333. X  if (!(vec = (float GPFAR *)gpfaralloc((unsigned long) (nh-nl+1)*sizeof(float),NULL))){
  334. X    int_error("not enough memory to create vector",NO_CARET);
  335. X    return NULL;/* Not reached */
  336. X  }
  337. X  return (vec-nl);
  338. X}
  339. X/* 
  340. X *  Free a vector allocated above
  341. X *
  342. X *   This subroutine based on a subroutine listed in "Numerical Recipies in C",
  343. X *   by Press, Flannery, Teukoilsky and Vetterling (1988).
  344. X *
  345. X */
  346. Xvoid 
  347. X  free_vector(vec,nl,nh)
  348. Xfloat  GPFAR *vec;
  349. Xint nl,nh;
  350. X{
  351. X  gpfarfree((char GPFAR *)(vec+nl));
  352. X}
  353. X/************ Routines to modify the length of a vector ****************/  
  354. Xfloat  GPFAR *
  355. X  extend_vector(vec,old_nl,old_nh,new_nh)
  356. Xfloat  GPFAR *vec;
  357. Xregister int old_nl,old_nh,new_nh;
  358. X{
  359. X  register float  GPFAR *new_v;
  360. X  if(!(new_v = (float GPFAR *)gpfarrealloc((void*)(vec+old_nl),
  361. X                       (unsigned long)(new_nh-old_nl+1)*sizeof(float)) )){
  362. X    int_error("not enough memory to extend vector",NO_CARET);
  363. X    return NULL;
  364. X  } 
  365. X  return new_v-old_nl;
  366. X}
  367. X
  368. Xfloat  GPFAR *
  369. X  retract_vector(v,old_nl,old_nh,new_nh)
  370. Xfloat  GPFAR *v;
  371. Xregister int old_nl,old_nh,new_nh;
  372. X{
  373. X  register float GPFAR *new_v;
  374. X  if(!(new_v = (float GPFAR *)gpfarrealloc((void*)(v+old_nl),
  375. X                               (unsigned long)(new_nh-old_nl+1)*sizeof(float)))){
  376. X    int_error("not enough memory to retract vector",NO_CARET);
  377. X    return NULL;
  378. X  }
  379. X  return new_v-old_nl;
  380. X}
  381. X/***************************** MATRIX ************************
  382. X *
  383. X *       The following routines work with matricies
  384. X *
  385. X *      I always get confused with this, so here I write it down:
  386. X *               for nrl<= nri <=nrh and
  387. X *               for ncl<= ncj <=nch
  388. X *  
  389. X *   This matrix is accessed as:
  390. X *   
  391. X *     matrix[nri][ncj];
  392. X *     where nri is the offset to the pointer to a vector where the
  393. X *     ncjth element lies.
  394. X * 
  395. X *   If there is an error we don't really return - int_error breaks us out.
  396. X *
  397. X *   This subroutine based on a subroutine listed in "Numerical Recipies in C",
  398. X *   by Press, Flannery, Teukoilsky and Vetterling (1988).
  399. X *
  400. X */
  401. Xfloat 
  402. X   GPFAR * GPFAR *matrix(nrl,nrh,ncl,nch)
  403. Xregister int nrl,nrh,ncl,nch;
  404. X{
  405. X  register int i;
  406. X  register float GPFAR * GPFAR *m;
  407. X
  408. X  if (!(m = (float GPFAR * GPFAR *)gpfaralloc((unsigned long)(nrh-nrl+1)*sizeof(float GPFAR *),NULL))){
  409. X    int_error("not enough memory to create matrix",NO_CARET);
  410. X    return NULL;
  411. X  }
  412. X  m -= nrl;
  413. X
  414. X  for (i=nrl; i<=nrh; i++)
  415. X    {
  416. X      if (!(m[i] = (float GPFAR *) gpfaralloc((unsigned long)(nch-ncl+1)*sizeof(float),NULL))){
  417. X    free_matrix(m,nrl,i-1,ncl,nch);
  418. X    int_error("not enough memory to create matrix",NO_CARET);
  419. X    return NULL;
  420. X      }
  421. X      m[i] -= ncl;
  422. X    }
  423. X  return m;
  424. X}
  425. X/* 
  426. X * Free a matrix allocated above
  427. X *
  428. X *
  429. X *   This subroutine based on a subroutine listed in "Numerical Recipies in C",
  430. X *   by Press, Flannery, Teukoilsky and Vetterling (1988).
  431. X *
  432. X */
  433. Xvoid 
  434. X  free_matrix(m,nrl,nrh,ncl,nch)
  435. Xfloat  GPFAR * GPFAR *m;
  436. Xunsigned nrl,nrh,ncl,nch;
  437. X{
  438. X  register int i;
  439. X
  440. X  for (i=nrl; i<=nrh; i++) 
  441. X    gpfarfree((char GPFAR *) (m[i]+ncl));
  442. X  gpfarfree((char GPFAR *) (m+nrl));
  443. X}
  444. X/*
  445. X  This routine takes a sub matrix and extends the number of rows and 
  446. X  columns for a new matrix
  447. X*/
  448. Xfloat GPFAR * GPFAR *extend_matrix(a,nrl,nrh,ncl,nch,srh,sch)
  449. X     register float  GPFAR * GPFAR *a;
  450. X     register int nrl,nrh,ncl,nch;
  451. X     register int srh,sch;
  452. X{
  453. X  register int i;
  454. X  register float GPFAR * GPFAR *m;
  455. X
  456. X  /*  bug fixed. realloc() called with incorrect 2nd argument. jvdwoude@hut.nl */
  457. X  if(!(m = (float GPFAR * GPFAR *)gpfarrealloc((void*)(a+nrl),(unsigned long)(srh-nrl+1)*sizeof(float GPFAR *)) )){
  458. X    int_error("not enough memory to extend matrix",NO_CARET);
  459. X    return NULL;
  460. X  }
  461. X
  462. X  m -= nrl;
  463. X
  464. X  if(sch != nch){
  465. X    for(i=nrl; i<=nrh; i++)
  466. X      {/* Copy and extend rows */
  467. X    if(!(m[i] = extend_vector(m[i],ncl,nch,sch))){
  468. X      free_matrix(m,nrl,nrh,ncl,sch);
  469. X      int_error("not enough memory to extend matrix",NO_CARET);
  470. X      return NULL;
  471. X    }
  472. X      }
  473. X  }
  474. X  for(i=nrh+1; i<=srh; i++)
  475. X    {
  476. X      if(!(m[i] = (float GPFAR *) gpfaralloc((unsigned long) (nch-ncl+1)*sizeof(float),NULL))){
  477. X    free_matrix(m,nrl,i-1,nrl,sch);
  478. X    int_error("not enough memory to extend matrix",NO_CARET);
  479. X    return NULL;
  480. X      }
  481. X      m[i] -= ncl;
  482. X    }
  483. X  return m;
  484. X}
  485. X/*
  486. X  this routine carves a large matrix down to size
  487. X*/
  488. Xfloat GPFAR * GPFAR *retract_matrix(a,nrl,nrh,ncl,nch,srh,sch)
  489. X     register float  GPFAR * GPFAR *a;
  490. X     register int nrl,nrh,ncl,nch;
  491. X     register int srh,sch;
  492. X{
  493. X  register int i;
  494. X  register float  GPFAR * GPFAR *m;
  495. X
  496. X  for(i=srh+1; i<=nrh; i++) {
  497. X    free_vector(a[i],ncl,nch);
  498. X  }
  499. X
  500. X  /*  bug fixed. realloc() called with incorrect 2nd argument. jvdwoude@hut.nl */
  501. X  if(!(m = (float GPFAR * GPFAR *)gpfarrealloc((void*)(a+nrl), (unsigned long)(srh-nrl+1)*sizeof(float GPFAR *)) )){
  502. X    int_error("not enough memory to retract matrix",NO_CARET);
  503. X    return NULL;
  504. X  }
  505. X
  506. X  m -= nrl;
  507. X
  508. X  if(sch != nch){
  509. X    for(i=nrl; i<=srh; i++)       
  510. X    if(!(m[i] = retract_vector(m[i],ncl,nch,sch))){ {/* Shrink rows */
  511. X      free_matrix(m,nrl,srh,ncl,sch);
  512. X      int_error("not enough memory to retract matrix",NO_CARET);
  513. X      return NULL;
  514. X    }
  515. X      }
  516. X  }
  517. X
  518. X  return m;
  519. X}
  520. X
  521. Xfloat 
  522. X   GPFAR * GPFAR *convert_matrix(a,nrl,nrh,ncl,nch)
  523. Xfloat GPFAR *a;
  524. Xregister int nrl,nrh,ncl,nch;
  525. X
  526. X/* allocate a float matrix m[nrl...nrh][ncl...nch] that points to the
  527. Xmatrix declared in the standard C manner as a[nrow][ncol], where 
  528. Xnrow=nrh-nrl+1, ncol=nch-ncl+1.  The routine should be called with
  529. Xthe address &a[0][0] as the first argument.  This routine does
  530. Xnot free the memory used by the original array a but merely assigns
  531. Xpointers to the rows. */
  532. X
  533. X{
  534. X  register int i,j,ncol,nrow;
  535. X  register float GPFAR * GPFAR *m;
  536. X
  537. X  nrow=nrh-nrl+1;
  538. X  ncol=nch-ncl+1;
  539. X  if (!(m = (float GPFAR * GPFAR *)gpfaralloc((unsigned long)(nrh-nrl+1)*sizeof(float GPFAR *),NULL))){
  540. X      int_error("allocation failure in convert_matrix()",NO_CARET);
  541. X      return NULL;
  542. X  }
  543. X  m -= nrl;
  544. X
  545. X  m[nrl]=a-ncl;
  546. X  for(i=1,j=nrl+1;i<=nrow-1;i++,j++) m[j]=m[j-1]+ncol;
  547. X  return m;
  548. X}
  549. X
  550. Xvoid free_convert_matrix(b,nrl,nrh,ncl,nch)
  551. Xfloat GPFAR* GPFAR *b;
  552. Xregister int nrl,nrh,ncl,nch;
  553. X{
  554. X    free((char*) (b+nrl));
  555. X}
  556. END_OF_FILE
  557.   if test 14608 -ne `wc -c <'gnuplot/binary.c'`; then
  558.     echo shar: \"'gnuplot/binary.c'\" unpacked with wrong size!
  559.   fi
  560.   # end of 'gnuplot/binary.c'
  561. fi
  562. if test -f 'gnuplot/demo/prob.dem' -a "${1}" != "-c" ; then 
  563.   echo shar: Will not clobber existing file \"'gnuplot/demo/prob.dem'\"
  564. else
  565.   echo shar: Extracting \"'gnuplot/demo/prob.dem'\" \(21935 characters\)
  566.   sed "s/^X//" >'gnuplot/demo/prob.dem' <<'END_OF_FILE'
  567. X#
  568. X# $Id: prob.demo 3.38.2.32 1992/12/04 18:33:59 woo Exp $
  569. X#
  570. X# Demo Statistical Functions version 2.3
  571. X#
  572. X# Permission granted to distribute freely for non-commercial purposes only
  573. X#
  574. X# Copyright (c) 1991, 1992 Jos van der Woude, jvdwoude@hut.nl
  575. X
  576. Xpause 0 "                   Statistical Library Demo, version 2.3"
  577. Xpause 0 ""
  578. Xpause 0 "          Copyright (c) 1991, 1992, Jos van de Woude, jvdwoude@hut.nl"
  579. Xpause 0 "Permission granted to distribute freely for non-commercial purposes only"
  580. Xpause 0 ""
  581. Xpause 0 ""
  582. Xpause 0 ""
  583. Xpause 0 ""
  584. Xpause 0 ""
  585. Xpause 0 ""
  586. Xpause 0 ""
  587. Xpause 0 ""
  588. Xpause 0 ""
  589. Xpause 0 ""
  590. Xpause 0 ""
  591. Xpause 0 ""
  592. Xpause 0 ""
  593. Xpause 0 ""
  594. Xpause 0 ""
  595. Xpause 0 "NOTE: contains 54 plots and consequently takes a lot of time to run"
  596. Xpause 0 "                      Press Ctrl-C to exit right now"
  597. Xpause -1 "                      Press Return to start demo ..."
  598. X
  599. Xsave set "defaults.ini"
  600. Xload "stat.inc"
  601. X
  602. X# Arcsinus PDF and CDF
  603. Xr = 2.0
  604. Xmu = 0.0
  605. Xsigma = r / sqrt2
  606. Xxmin = -r
  607. Xxmax = r
  608. Xymax = 1.1 * r #No mode
  609. Xset nokey
  610. Xset zeroaxis
  611. Xset xrange [xmin : xmax]
  612. Xset yrange [0 : ymax]
  613. Xset xlabel "x ->"
  614. Xset ylabel "probability density ->"
  615. Xset xtics
  616. Xset ytics
  617. Xset format x "%.1f"
  618. Xset format y "%.1f"
  619. Xset sample 200
  620. Xset title "arcsin PDF with r = 2.0"
  621. Xplot arcsin(x)
  622. Xpause -1 "Hit return to continue"
  623. Xset title "arcsin CDF with r = 2.0"
  624. Xset yrange [0 : 1.1]
  625. Xplot carcsin(x)
  626. Xpause -1 "Hit return to continue"
  627. X
  628. X# Beta PDF and CDF
  629. X#p = 0.5; q = 0.7
  630. X#mu = p / (p + q)
  631. X#sigma = sqrt(p**q) / ((p + q ) * sqrt(p + q + 1.0))
  632. X#xmin = 0.0
  633. X#xmax = 1.0
  634. X#Mode of beta PDF used
  635. X#ymax = (p < 1.0 || q < 1.0) ? 2.0 : 1.1 * beta((p - 1.0)/(p + q - 2.0))
  636. Xset key
  637. Xset zeroaxis
  638. X#set xrange [xmin : xmax]
  639. X#set yrange [0 : ymax]
  640. Xset xlabel "x ->"
  641. Xset ylabel "probability density ->"
  642. Xset xtics
  643. Xset ytics
  644. Xset format x "%.1f"
  645. Xset format y "%.1f"
  646. Xset sample 100
  647. Xset title "beta PDF"
  648. Xplot [0:1] [0:5] p = 0.5, q = 0.7, beta(x) title "p = 0.5, q = 0.7", \
  649. X                 p = 5.0, q = 3.0, beta(x) title "p = 5.0, q = 3.0", \
  650. X                 p = 0.5, q = 2.5, beta(x) title "p = 0.5, q = 2.5"
  651. Xpause -1 "Hit return to continue"
  652. Xset title "incomplete beta CDF"
  653. Xplot [0:1] [0:1.1] p = 0.5, q = 0.7, cbeta(x) title "p = 0.5, q = 0.7", \
  654. X                   p = 5.0, q = 3.0, cbeta(x) title "p = 5.0, q = 3.0", \
  655. X                   p = 0.5, q = 2.5, cbeta(x) title "p = 0.5, q = 2.5"
  656. Xpause -1 "Hit return to continue"
  657. X
  658. X# Binomial PDF and CDF
  659. Xn = 25; p = 0.15
  660. Xmu = n * p
  661. Xsigma = sqrt(n * p * (1.0 - p))
  662. Xxmin = int(mu - 4.0 * sigma)
  663. Xxmin = xmin < 0 ? 0 : xmin
  664. Xxmax = int(mu + 4.0 * sigma)
  665. Xymax = 1.1 * binom(mu) #Mode of normal PDF used
  666. Xxinc = ceil((xmax - xmin) / 10)
  667. Xxinc = xinc > 1 ? xinc : 1
  668. Xset nokey
  669. Xset nozeroaxis
  670. Xset xrange [xmin : xmax]
  671. Xset yrange [0 : ymax]
  672. Xset xlabel "k ->"
  673. Xset ylabel "probability density ->"
  674. Xset xtics xmin + 0.499, xinc, xmax
  675. Xset ytics 0, ymax / 10, ymax
  676. Xset format x "%2.0f"
  677. Xset format y "%3.2f"
  678. Xset sample (xmax - xmin) + 1
  679. Xset title "binomial PDF with n = 25, p = 0.15"
  680. Xplot binom(x) with steps
  681. Xpause -1 "Hit return to continue"
  682. Xset title "binomial CDF with n = 25, p = 0.15"
  683. Xset yrange [0 : 1.1]
  684. Xset ytics 0, 1.1 / 10.5, 1.1
  685. Xplot cbinom(x) with steps
  686. Xpause -1 "Hit return to continue"
  687. X
  688. X# Cauchy PDF and CDF
  689. X#a = 0.0; b = 2.0
  690. X#cauchy PDF has no moments
  691. X#xmin = a - 4.0 * b
  692. X#xmax = a + 4.0 * b
  693. X#ymax = 1.1 * cauchy(a) #Mode of cauchy PDF used
  694. Xset key
  695. Xset zeroaxis
  696. X#set xrange [xmin : xmax]
  697. X#set yrange [0 : ymax]
  698. Xset xlabel "x ->"
  699. Xset ylabel "probability density ->"
  700. Xset xtics
  701. Xset ytics
  702. Xset format x "%.1f"
  703. Xset format y "%.2f"
  704. Xset sample 100
  705. Xset title "cauchy PDF"
  706. Xplot [-15:15] [0:0.2] a = 0, b = 2, cauchy(x) title "a = 0, b = 2", \
  707. X                      a = 0, b = 4, cauchy(x) title "a = 0, b = 4"
  708. Xpause -1 "Hit return to continue"
  709. Xset title "cauchy CDF"
  710. Xplot [-30:30] [0:1.1] a = 0, b = 2, ccauchy(x) title "a = 0, b = 2", \
  711. X                      a = 0, b = 4, ccauchy(x) title "a = 0, b = 4"
  712. Xpause -1 "Hit return to continue"
  713. X
  714. X# Chi-square PDF and CDF
  715. X#df1 = 4.0
  716. X#mu = df1
  717. X#sigma = sqrt(2.0 * df1)
  718. X#xmin = mu - 4.0 * sigma
  719. X#xmin = xmin < 0 ? 0 : xmin
  720. X#xmax = mu + 4.0 * sigma
  721. X#ymax = 1.1 * (df1 > 2.0 ? chi(df1 - 2.0) : 1.0) #Mode of chi PDF used
  722. Xset key
  723. Xset zeroaxis
  724. X#set xrange [xmin : xmax]
  725. X#set yrange [0 : ymax]
  726. Xset xlabel "x ->"
  727. Xset ylabel "probability density ->"
  728. Xset xtics
  729. Xset ytics
  730. Xset format x "%.1f"
  731. Xset format y "%.2f"
  732. Xset sample 100
  733. Xset title "chi-square PDF"
  734. Xplot [0:15] [0:0.2] df1 = 4, chi(x) title "df = 4", \
  735. X                    df1 = 6, chi(x) title "df = 6", \
  736. X                    df1 = 8, chi(x) title "df = 8"
  737. Xpause -1 "Hit return to continue"
  738. Xset title "chi-square CDF"
  739. Xplot [0:15] [0:1.1] df1 = 4, cchi(x) title "df = 4", \
  740. X                    df1 = 6, cchi(x) title "df = 6", \
  741. X                    df1 = 8, cchi(x) title "df = 8"
  742. Xpause -1 "Hit return to continue"
  743. X
  744. X# Erlang PDF and CDF
  745. X#lambda = 1.0; n = 2.0
  746. X#mu = n / lambda
  747. X#sigma = sqrt(n) / lambda
  748. X#xmin = mu - 4.0 * sigma
  749. X#xmin = xmin < 0 ? 0 : xmin
  750. X#xmax = mu + 4.0 * sigma
  751. X#ymax = n < 2.0 ? 1.0 : 1.1 * erlang((n - 1.0) / lambda) #Mode of erlang PDF used
  752. Xset key
  753. Xset zeroaxis
  754. X#set xrange [xmin : xmax]
  755. X#set yrange [0 : ymax]
  756. Xset xlabel "x ->"
  757. Xset ylabel "probability density ->"
  758. Xset xtics
  759. Xset ytics
  760. Xset format x "%.1f"
  761. Xset format y "%.1f"
  762. Xset sample 100
  763. Xset title "erlang PDF"
  764. Xplot [0:10] [0:1] lambda = 1, n = 2, erlang(x) title "lambda = 1, n = 2", \
  765. X                  lambda = 2, n = 2, erlang(x) title "lambda = 2, n = 2"
  766. Xpause -1 "Hit return to continue"
  767. Xset title "erlang CDF"
  768. Xplot [0:10] [0:1.1] lambda = 1, n = 2, cerlang(x) title "lambda = 1, n = 2", \
  769. X                    lambda = 2, n = 2, cerlang(x) title "lambda = 2, n = 2"
  770. Xpause -1 "Hit return to continue"
  771. X
  772. X# Thanks to mrb2j@kelvin.seas.Virginia.EDU for telling us about this.
  773. X# Extreme (Gumbel extreme value) PDF and CDF
  774. X#alpha = 0.5; u = 1.0
  775. X#mu = u + (0.577215665/alpha)   # Euler's constant
  776. X#sigma = pi/(sqrt(6.0)*alpha)
  777. X#xmin = mu - 4.0 * sigma
  778. X#xmax = mu + 4.0 * sigma
  779. X#ymax = 1.1 * extreme(u) #Mode of extreme PDF used
  780. Xset key
  781. Xset zeroaxis
  782. X#set xrange [xmin : xmax]
  783. X#set yrange [0 : ymax]
  784. Xset xlabel "x ->"
  785. Xset ylabel "probability density ->"
  786. Xset xtics
  787. Xset ytics
  788. Xset format x "%.1f"
  789. Xset format y "%.2f"
  790. Xset sample 100
  791. Xset title "extreme PDF"
  792. Xplot [-10:10] [0:0.4] alpha = 0.5, u = 1.0, extreme(x) title "alpha = 0.5, u = 1.0", \
  793. X                      alpha = 1.0, u = 0.0, extreme(x) title "alpha = 1.0, u = 0.0"
  794. Xpause -1 "Hit return to continue"
  795. Xset title "extreme CDF"
  796. Xplot [-10:10] [0:1.1] alpha = 0.5, u = 1.0, cextreme(x) title "alpha = 0.5, u = 1.0", \
  797. X                      alpha = 1.0, u = 0.0, cextreme(x) title "alpha = 1.0, u = 0.0"
  798. Xpause -1 "Hit return to continue"
  799. X
  800. X# F PDF and CDF
  801. X#df1 = 5.0; df2 = 9.0
  802. X#mu = df2 < 2.0 ? 1.0 : df2 / (df2 - 2.0)
  803. X#sigma = df2 < 4.0 ? 1.0 : mu * sqrt(2.0 * (df1 + df2 - 2.0) / (df1 * (df2 - 4.0)))
  804. X#xmin = mu - 4.0 * sigma
  805. X#xmin = xmin < 0 ? 0 : xmin
  806. X#xmax = mu + 4.0 * sigma
  807. X#Mode of F PDF used
  808. X#ymax = df1 < 3.0 ? 1.0 : 1.1 * f((df1 / 2.0 - 1.0) / (df1 / 2.0 + df1 / df2))
  809. Xset key
  810. Xset zeroaxis
  811. X#set xrange [xmin : xmax]
  812. X#set yrange [0 : ymax]
  813. Xset xlabel "x ->"
  814. Xset ylabel "probability density ->"
  815. Xset xtics
  816. Xset ytics
  817. Xset format x "%.1f"
  818. Xset format y "%.2f"
  819. Xset sample 100
  820. Xset title "F PDF"
  821. Xplot [0:4] [0:0.8] df1 = 5.0, df2 = 9.0, f(x) title "df1 = 5, df2 = 9", \
  822. X                   df1 = 7.0, df2 = 6.0, f(x) title "df1 = 7, df2 = 6"
  823. Xpause -1 "Hit return to continue"
  824. Xset title "F CDF"
  825. Xplot [0:4] [0:1.1] df1 = 5.0, df2 = 9.0, cf(x) title "df1 = 5, df2 = 9", \
  826. X                   df1 = 7.0, df2 = 6.0, cf(x) title "df1 = 7, df2 = 6"
  827. Xpause -1 "Hit return to continue"
  828. X
  829. X# Gamma PDF and incomplete gamma CDF
  830. X#rho = 0.5; lambda = 1.0
  831. X#mu = rho / lambda
  832. X#sigma = sqrt(rho) / lambda
  833. X#xmin = mu - 4.0 * sigma
  834. X#xmin = xmin < 0 ? 0 : xmin
  835. X#xmax = mu + 4.0 * sigma
  836. X#ymax = rho < 1.0 ? 2.0 : 1.1 * g((rho - 1.0) / lambda) #Mode of gamma pdf used
  837. Xset key
  838. Xset zeroaxis
  839. X#set xrange [xmin: xmax]
  840. X#set yrange [0: ymax]
  841. Xset xlabel "x ->"
  842. Xset ylabel "probability density ->"
  843. Xset xtics
  844. Xset ytics
  845. Xset format x "%.1f"
  846. Xset format y "%.1f"
  847. Xset sample 100
  848. Xset title "gamma PDF"
  849. Xplot [0:5] [0:1.5] rho = 0.5, lambda = 1.0, g(x) title "rho = 0.5, lambda = 1.0", \
  850. X                   rho = 1.0, lambda = 1.0, g(x) title "rho = 1.0, lambda = 1.0", \
  851. X                   rho = 2.0, lambda = 2.0, g(x) title "rho = 2.0, lambda = 2.0"
  852. Xpause -1 "Hit return to continue"
  853. Xset title "incomplete gamma CDF (lambda == 1.0)"
  854. Xplot [0:5] [0:1.1] rho = 0.5, cgamma(x) title "rho = 0.5", \
  855. X                   rho = 1.0, cgamma(x) title "rho = 1.0", \
  856. X                   rho = 2.0, cgamma(x) title "rho = 2.0"
  857. Xpause -1 "Hit return to continue"
  858. X
  859. X# Geometric PDF and CDF
  860. Xp = 0.4
  861. Xmu = (1.0 - p) / p
  862. Xsigma = sqrt(mu / p)
  863. Xxmin = int(mu - 4.0 * sigma)
  864. Xxmin = xmin < 0 ? 0 : xmin
  865. Xxmax = int(mu + 4.0 * sigma)
  866. Xxinc = ceil((xmax - xmin) / 10)
  867. Xxinc = xinc > 1 ? xinc : 1
  868. Xymax = 1.1 * geometric(mu - 1/p) #mode of gamma PDF used
  869. Xset nokey
  870. Xset nozeroaxis
  871. Xset xrange [xmin : xmax]
  872. Xset yrange [0 : ymax]
  873. Xset xlabel "k ->"
  874. Xset ylabel "probability density ->"
  875. Xset xtics xmin + 0.499, xinc, xmax
  876. Xset ytics 0, ymax / 10, ymax
  877. Xset format x "%2.0f"
  878. Xset format y "%3.2f"
  879. Xset sample (xmax - xmin) + 1
  880. Xset title "geometric PDF with p = 0.4"
  881. Xplot geometric(x) with steps
  882. Xpause -1 "Hit return to continue"
  883. Xset title "geometric CDF with p = 0.4"
  884. Xset yrange [0 : 1.1]
  885. Xset ytics 0, 1.1 / 10.5, 1.1
  886. Xplot cgeometric(x) with steps
  887. Xpause -1 "Hit return to continue"
  888. X
  889. X# Half normal PDF and CDF
  890. Xmu = sqrt2invpi
  891. Xsigma = 1.0
  892. Xs = sigma*sqrt(1.0 - 2.0/pi)
  893. Xxmin = 0.0
  894. Xxmax = mu + 4.0 * s
  895. Xymax = 1.1 * halfnormal(0) #Mode of half normal PDF used
  896. Xset nokey
  897. Xset zeroaxis
  898. Xset xrange [xmin: xmax]
  899. Xset yrange [0: ymax]
  900. Xset xlabel "x ->"
  901. Xset ylabel "probability density ->"
  902. Xset xtics
  903. Xset ytics
  904. Xset format x "%.1f"
  905. Xset format y "%.1f"
  906. Xset sample 100
  907. Xset title "half normal PDF, sigma = 1.0"
  908. Xplot halfnormal(x)
  909. Xpause -1 "Hit return to continue"
  910. Xset title "half normal CDF, sigma = 1.0"
  911. Xset yrange [0:1.1]
  912. Xplot chalfnormal(x)
  913. Xpause -1 "Hit return to continue"
  914. X
  915. X# Hypergeometric PDF and CPF
  916. Xnn = 75; mm = 25; n = 10
  917. Xp = real(mm) / nn
  918. Xmu = n * p
  919. Xsigma = sqrt(real(nn - n) / (nn - 1.0) * n * p * (1.0 - p))
  920. Xxmin = int(mu - 4.0 * sigma)
  921. Xxmin = xmin < 0 ? 0 : xmin
  922. Xxmax = int(mu + 4.0 * sigma)
  923. Xxinc = ceil((xmax - xmin) / 10)
  924. Xxinc = xinc > 1 ? xinc : 1
  925. Xymax = 1.1 * hypgeo(mu) #mode of binomial PDF used
  926. Xset nokey
  927. Xset nozeroaxis
  928. Xset xrange [xmin : xmax]
  929. Xset yrange [0 : ymax]
  930. Xset xlabel "k ->"
  931. Xset ylabel "probability density ->"
  932. Xset xtics xmin + 0.499, xinc, xmax
  933. Xset ytics 0, ymax / 10, ymax
  934. Xset format x "%2.0f"
  935. Xset format y "%3.2f"
  936. Xset sample (xmax - xmin) + 1
  937. Xset title "hypergeometric PDF with nn = 75, mm = 25, n = 10"
  938. Xplot hypgeo(x) with steps
  939. Xpause -1 "Hit return to continue"
  940. Xset yrange [0 : 1.1]
  941. Xset ytics 0, 1.1 / 10.5, 1.1
  942. Xset title "hypergeometric CDF with nn = 75, mm = 25, n = 10"
  943. Xplot chypgeo(x) with steps
  944. Xpause -1 "Hit return to continue"
  945. X
  946. X# Laplace PDF
  947. Xa = 0.0; b = 1.0
  948. Xmu = a
  949. Xsigma = sqrt(2.0) * b
  950. Xxmin = mu - 4.0 * sigma
  951. Xxmax = mu + 4.0 * sigma
  952. Xymax = 1.1 * laplace(a) #Mode of laplace PDF used
  953. Xset nokey
  954. Xset zeroaxis
  955. Xset xrange [xmin: xmax]
  956. Xset yrange [0: ymax]
  957. Xset xlabel "x ->"
  958. Xset ylabel "probability density ->"
  959. Xset xtics
  960. Xset ytics
  961. Xset format x "%.1f"
  962. Xset format y "%.2f"
  963. Xset sample 100
  964. Xset title "laplace (or double exponential) PDF with a = 0, b = 1"
  965. Xplot laplace(x)
  966. Xpause -1 "Hit return to continue"
  967. Xset title "laplace (or double exponential) CDF with a = 0, b = 1"
  968. Xset yrange [0: 1.1]
  969. Xplot claplace(x)
  970. Xpause -1 "Hit return to continue"
  971. X
  972. X# Logistic PDF and CDF
  973. Xa = 0.0; lambda = 2.0
  974. Xmu = a
  975. Xsigma = pi / (sqrt(3.0) * lambda)
  976. Xxmin = mu - 4.0 * sigma
  977. Xxmax = mu + 4.0 * sigma
  978. Xymax = 1.1 * logistic(mu) #Mode of logistic PDF used
  979. Xset nokey
  980. Xset zeroaxis
  981. Xset xrange [xmin: xmax]
  982. Xset yrange [0: ymax]
  983. Xset nokey
  984. Xset zeroaxis
  985. Xset xlabel "x ->"
  986. Xset ylabel "probability density ->"
  987. Xset xtics
  988. Xset ytics
  989. Xset format x "%.1f"
  990. Xset format y "%.1f"
  991. Xset sample 100
  992. Xset title "logistic PDF with a = 0, lambda = 2"
  993. Xplot logistic(x)
  994. Xpause -1 "Hit return to continue"
  995. Xset title "logistic CDF with a = 0, lambda = 2"
  996. Xset yrange [0: 1.1]
  997. Xplot clogistic(x)
  998. Xpause -1 "Hit return to continue"
  999. X
  1000. X# Lognormal PDF and CDF
  1001. Xmu = 1.0; sigma = 0.5
  1002. Xm = exp(mu + 0.5 * sigma**2)
  1003. Xs = sqrt(exp(2.0 * mu + sigma**2) * (2.0 * exp(sigma) - 1.0))
  1004. Xxmin = m - 4.0 * s
  1005. Xxmin = xmin < 0 ? 0 : xmin
  1006. Xxmax = m + 4.0 * s
  1007. Xymax = 1.1 * lognormal(exp(mu - sigma**2)) #Mode of lognormal PDF used
  1008. Xset nokey
  1009. Xset zeroaxis
  1010. Xset xrange [xmin: xmax]
  1011. Xset yrange [0: ymax]
  1012. Xset xlabel "x ->"
  1013. Xset ylabel "probability density ->"
  1014. Xset xtics
  1015. Xset ytics
  1016. Xset format x "%.2f"
  1017. Xset format y "%.2f"
  1018. Xset sample 100
  1019. Xset title "lognormal PDF with mu = 1.0, sigma = 0.5"
  1020. Xplot lognormal(x)
  1021. Xpause -1 "Hit return to continue"
  1022. Xset title "lognormal CDF with mu = 1.0, sigma = 0.5"
  1023. Xset yrange [0: 1.1]
  1024. Xplot clognormal(x)
  1025. Xpause -1 "Hit return to continue"
  1026. X
  1027. X# Maxwell PDF
  1028. X#a = 0.1
  1029. X#mu = 2.0 / sqrt(pi) / a
  1030. X#sigma = sqrt(3.0 - 8.0/pi) / a
  1031. X#xmin = mu - 4.0 * sigma
  1032. X#xmin = xmin < 0 ? 0 : xmin
  1033. X#xmax = mu + 4.0 * sigma
  1034. X#ymax = 1.1 * maxwell(1.0 / a) #Mode of maxwell PDF used
  1035. Xset key
  1036. Xset zeroaxis
  1037. X#set xrange[xmin: xmax]
  1038. X#set yrange[0: ymax]
  1039. Xset xlabel "x ->"
  1040. Xset ylabel "probability density ->"
  1041. Xset xtics
  1042. Xset ytics
  1043. Xset format x "%.1f"
  1044. Xset format y "%.1f"
  1045. Xset sample 100
  1046. Xset title "maxwell PDF"
  1047. Xplot [0:6] [0:1.4] a = 1.5, maxwell(x) title "a = 1.5", \
  1048. X                   a = 1.0, maxwell(x) title "a = 1.0", \
  1049. X                   a = 0.5, maxwell(x) title "a = 0.5"
  1050. Xpause -1 "Hit return to continue"
  1051. Xset title "maxwell CDF"
  1052. Xplot [0:6] [0:1.1] a = 1.5, cmaxwell(x) title "a = 1.5", \
  1053. X                   a = 1.0, cmaxwell(x) title "a = 1.0", \
  1054. X                   a = 0.5, cmaxwell(x) title "a = 0.5"
  1055. Xpause -1 "Hit return to continue"
  1056. X
  1057. X# Negative binomial PDF and CDF
  1058. Xr = 8; p = 0.4
  1059. Xmu = r * (1.0 - p) / p
  1060. Xsigma = sqrt(mu / p)
  1061. Xxmin = int(mu - 4.0 * sigma)
  1062. Xxmin = xmin < 0 ? 0 : xmin
  1063. Xxmax = int(mu + 4.0 * sigma)
  1064. Xxinc = ceil((xmax - xmin) / 10)
  1065. Xxinc = xinc > 1 ? xinc : 1
  1066. Xymax = 1.1 * negbin(mu - 1.0/p) #mode of gamma PDF used
  1067. Xset nokey
  1068. Xset nozeroaxis
  1069. Xset xrange [xmin : xmax]
  1070. Xset yrange [0 : ymax]
  1071. Xset xlabel "k ->"
  1072. Xset ylabel "probability density ->"
  1073. Xset xtics xmin + 0.499, xinc, xmax
  1074. Xset ytics 0, ymax / 10, ymax
  1075. Xset format x "%2.0f"
  1076. Xset format y "%3.2f"
  1077. Xset sample (xmax - xmin) + 1
  1078. Xset title "negative binomial (or pascal or polya) PDF with r = 8, p = 0.4"
  1079. Xplot negbin(x) with steps
  1080. Xpause -1 "Hit return to continue"
  1081. Xset yrange [0 : 1.1]
  1082. Xset ytics 0, 1.1 / 10.5, 1.1
  1083. Xset title "negative binomial (or pascal or polya) CDF with r = 8, p = 0.4"
  1084. Xplot cnegbin(x) with steps
  1085. Xpause -1 "Hit return to continue"
  1086. X
  1087. X# Negative exponential PDF and CDF
  1088. Xlambda = 2.0
  1089. Xmu = 1.0 / lambda
  1090. Xsigma = 1.0 / lambda
  1091. Xxmax =  mu + 4.0 * sigma
  1092. Xymax = lambda #No mode
  1093. Xset nokey
  1094. Xset zeroaxis
  1095. Xset xrange [0: xmax]
  1096. Xset yrange [0: ymax]
  1097. Xset xlabel "x ->"
  1098. Xset ylabel "probability density ->"
  1099. Xset xtics
  1100. Xset ytics
  1101. Xset format x "%.2f"
  1102. Xset format y "%.1f"
  1103. Xset sample 100
  1104. Xset title "negative exponential (or exponential) PDF with lambda = 2.0"
  1105. Xplot nexp(x)
  1106. Xpause -1 "Hit return to continue"
  1107. Xset title "negative exponential (or exponential) CDF with lambda = 2.0"
  1108. Xset yrange [0: 1.1]
  1109. Xplot cnexp(x)
  1110. Xpause -1 "Hit return to continue"
  1111. X
  1112. X# Normal PDF and CDF
  1113. X#mu = 0.0; sigma = 1.0
  1114. X#xmin = mu - 4.0 * sigma
  1115. X#xmax = mu + 4.0 * sigma
  1116. X#ymax = 1.1 * normal(mu) #Mode of normal PDF used
  1117. Xset key
  1118. Xset zeroaxis
  1119. X#set xrange [xmin: xmax]
  1120. X#set yrange [0: ymax]
  1121. Xset xlabel "x ->"
  1122. Xset ylabel "probability density ->"
  1123. Xset xtics
  1124. Xset ytics
  1125. Xset format x "%.1f"
  1126. Xset format y "%.1f"
  1127. Xset sample 100
  1128. Xset title "normal (also called gauss or bell-curved) PDF"
  1129. Xplot [-4:4] [0:1] mu = 0, sigma = 1.0, normal(x) title "mu = 0, sigma = 1.0", \
  1130. X                  mu = 2, sigma = 0.5, normal(x) title "mu = 2, sigma = 0.5", \
  1131. X                  mu = 1, sigma = 2.0, normal(x) title "mu = 1, sigma = 2.0"
  1132. Xpause -1 "Hit return to continue"
  1133. Xset title "normal (also called gauss or bell-curved) CDF"
  1134. Xplot [-4:4] [0:1.1] mu = 0, sigma = 1.0, cnormal(x) title "mu = 0, sigma = 1.0", \
  1135. X                    mu = 2, sigma = 0.5, cnormal(x) title "mu = 2, sigma = 0.5", \
  1136. X                    mu = 1, sigma = 2.0, cnormal(x) title "mu = 1, sigma = 2.0"
  1137. Xpause -1 "Hit return to continue"
  1138. X
  1139. X# Pareto PDF and CDF
  1140. Xa = 1.0; b = 3.0
  1141. Xmu = a * b / (b - 1.0)
  1142. Xsigma = a * sqrt(b) / (sqrt(b - 2.0) * (b - 1.0))
  1143. Xxmin = mu - 4.0 * sigma
  1144. Xxmin = xmin < 0 ? 0 : xmin
  1145. Xxmax = mu + 4.0 * sigma
  1146. Xymax = 1.1 * pareto(a) #mode of pareto PDF used
  1147. Xset nokey
  1148. Xset zeroaxis
  1149. Xset xrange [xmin: xmax]
  1150. Xset yrange [0: ymax]
  1151. Xset xlabel "x ->"
  1152. Xset ylabel "probability density ->"
  1153. Xset xtics
  1154. Xset ytics
  1155. Xset format x "%.1f"
  1156. Xset format y "%.1f"
  1157. Xset sample 500
  1158. Xset title "pareto PDF with a = 1, b = 3"
  1159. Xplot pareto(x)
  1160. Xpause -1 "Hit return to continue"
  1161. Xset title "pareto CDF with a = 1, b = 3"
  1162. Xset yrange [0: 1.1]
  1163. Xplot cpareto(x)
  1164. Xpause -1 "Hit return to continue"
  1165. X
  1166. X# Poisson PDF and CDF
  1167. Xmu = 4.0
  1168. Xsigma = sqrt(mu)
  1169. Xxmin = int(mu - 4.0 * sigma)
  1170. Xxmin = xmin < 0 ? 0 : xmin
  1171. Xxmax = int(mu + 4.0 * sigma)
  1172. Xxinc = ceil((xmax - xmin) / 10)
  1173. Xxinc = xinc > 1 ? xinc : 1
  1174. Xymax = 1.1 * poisson(mu) #mode of poisson PDF used
  1175. Xset nokey
  1176. Xset nozeroaxis
  1177. Xset xrange [xmin : xmax]
  1178. Xset yrange [0 : ymax]
  1179. Xset xlabel "k ->"
  1180. Xset ylabel "probability density ->"
  1181. Xset xtics xmin + 0.499, xinc, xmax
  1182. Xset ytics 0, ymax / 10, ymax
  1183. Xset format x "%2.0f"
  1184. Xset format y "%3.2f"
  1185. Xset sample (xmax - xmin) + 1
  1186. Xset title "poisson PDF with mu = 4.0"
  1187. Xplot poisson(x) with steps
  1188. Xpause -1 "Hit return to continue"
  1189. Xset yrange [0 : 1.1]
  1190. Xset ytics 0, 1.1 / 10.5, 1.1
  1191. Xset title "poisson CDF with mu = 4.0"
  1192. Xplot cpoisson(x) with steps
  1193. Xpause -1 "Hit return to continue"
  1194. X
  1195. X# Rayleigh PDF and CDF
  1196. Xlambda = 2.0
  1197. Xmu = 0.5 * sqrt(pi / lambda)
  1198. Xsigma = sqrt((1.0 - pi / 4.0) / lambda)
  1199. Xxmax = mu + 4.0 * sigma
  1200. Xymax = 1.1 * rayleigh(1.0 / sqrt(2.0 * lambda)) #Mode of rayleigh PDF used
  1201. Xset nokey
  1202. Xset zeroaxis
  1203. Xset xrange [0: xmax]
  1204. Xset yrange [0: ymax]
  1205. Xset xlabel "x ->"
  1206. Xset ylabel "probability density ->"
  1207. Xset xtics
  1208. Xset ytics
  1209. Xset format x "%.2f"
  1210. Xset format y "%.1f"
  1211. Xset sample 100
  1212. Xset title "rayleigh PDF with lambda = 2.0"
  1213. Xplot rayleigh(x)
  1214. Xpause -1 "Hit return to continue"
  1215. Xset title "rayleigh CDF with lambda = 2.0"
  1216. Xset yrange [0: 1.1]
  1217. Xplot crayleigh(x)
  1218. Xpause -1 "Hit return to continue"
  1219. X
  1220. X# Sine PDF and CDF
  1221. X#a = 3.0; n = 2
  1222. X#mu = a / 2.0
  1223. X#sigma = sqrt(a * a / 3.0 * (1.0 - 3.0 / (2.0 * n * n * pi * pi)) - mu * mu)
  1224. X#xmin = 0.0
  1225. X#xmax = a
  1226. X#ymax = 1.1 * 2.0 / a #Mode of sine PDF used
  1227. Xset key
  1228. Xset zeroaxis
  1229. X#set xrange [xmin: xmax]
  1230. X#set yrange [0: ymax]
  1231. Xset xlabel "x ->"
  1232. Xset ylabel "probability density ->"
  1233. Xset xtics
  1234. Xset ytics
  1235. Xset format x "%.2f"
  1236. Xset format y "%.1f"
  1237. Xset sample 100
  1238. Xset title "sine PDF"
  1239. Xplot [0:2] [0:1.1] a = 2.0, n = 1, sine(x) title "a = 2.0, n = 1", \
  1240. X                   a = 2.0, n = 3, sine(x) title "a = 2.0, n = 3"
  1241. Xpause -1 "Hit return to continue"
  1242. Xset title "sine CDF"
  1243. Xplot [0:2] [0:1.1] a = 2.0, n = 1, csine(x) title "a = 2.0, n = 1", \
  1244. X                   a = 2.0, n = 3, csine(x) title "a = 2.0, n = 3"
  1245. Xpause -1 "Hit return to continue"
  1246. X
  1247. X# t PDF and CDF
  1248. Xdf1 = 3.0
  1249. Xmu = 0.0
  1250. Xsigma = df1 > 2.0 ? sqrt(df1 / (df1 - 2.0)) : 1.0
  1251. Xxmin = mu - 4.0 * sigma
  1252. Xxmax = mu + 4.0 * sigma
  1253. Xymax = 1.1 * t(mu) #Mode of t PDF used
  1254. Xset nokey
  1255. Xset zeroaxis
  1256. Xset xrange [xmin: xmax]
  1257. Xset yrange [0: ymax]
  1258. Xset xlabel "x ->"
  1259. Xset ylabel "probability density ->"
  1260. Xset xtics
  1261. Xset ytics
  1262. Xset format x "%.1f"
  1263. Xset format y "%.2f"
  1264. Xset sample 100
  1265. Xset title "t PDF with df1 = 3.0"
  1266. Xplot t(x)
  1267. Xpause -1 "Hit return to continue"
  1268. Xset title "t CDF with df1 = 3.0"
  1269. Xset yrange [0: 1.1]
  1270. Xplot ct(x)
  1271. Xpause -1 "Hit return to continue"
  1272. X
  1273. X# Thanks to efrank@upenn5.hep.upenn.edu for telling us about this
  1274. X# triangular PDF and CDF
  1275. Xm = 3.0
  1276. Xg = 2.0
  1277. Xmu = m
  1278. Xsigma = g/sqrt(6.0)
  1279. Xxmin = m - g
  1280. Xxmax = m + g
  1281. Xymax = 1.1 * triangular(m) #Mode of triangular PDF used
  1282. Xset nokey
  1283. Xset zeroaxis
  1284. Xset xrange [xmin: xmax]
  1285. Xset yrange [0: ymax]
  1286. Xset xlabel "x ->"
  1287. Xset ylabel "probability density ->"
  1288. Xset xtics
  1289. Xset ytics
  1290. Xset format x "%.1f"
  1291. Xset format y "%.2f"
  1292. Xset sample 100
  1293. Xset title "triangular PDF with m = 3.0, g = 2.0"
  1294. Xplot triangular(x)
  1295. Xpause -1 "Hit return to continue"
  1296. Xset title "triangular CDF with m = 3.0, g = 2.0"
  1297. Xset yrange [0: 1.1]
  1298. Xplot ctriangular(x)
  1299. Xpause -1 "Hit return to continue"
  1300. X
  1301. X# Uniform PDF and CDF
  1302. Xa = -2.0; b= 2.0
  1303. Xmu = (a + b) / 2.0
  1304. Xsigma = (b - a) / sqrt(12.0)
  1305. Xxmin = a
  1306. Xxmax = b
  1307. Xymax = 1.1 * uniform(mu) #No mode
  1308. Xset nokey
  1309. Xset zeroaxis
  1310. Xset xrange [xmin: xmax]
  1311. Xset yrange [0: ymax]
  1312. Xset xlabel "x ->"
  1313. Xset ylabel "probability density ->"
  1314. Xset xtics
  1315. Xset ytics
  1316. Xset format x "%.2f"
  1317. Xset format y "%.2f"
  1318. Xset sample 100
  1319. Xset title "uniform PDF with a = -2.0, b = 2.0"
  1320. Xplot uniform(x)
  1321. Xpause -1 "Hit return to continue"
  1322. Xset title "uniform CDF with a = -2.0, b = 2.0"
  1323. Xset yrange [0: 1.1]
  1324. Xplot cuniform(x)
  1325. Xpause -1 "Hit return to continue"
  1326. X
  1327. X# Weibull PDF and CDF
  1328. X#lambda = 1.0; n = 1.5
  1329. X#mu = lambda**(-1.0 / n) * gamma(1.0 / n) / n
  1330. X#sigma = sqrt(2.0 * lambda**(-2.0 / n) * gamma(2.0 / n) / n - mu * mu)
  1331. X#xmin = mu - 4.0 * sigma
  1332. X#xmin = xmin < 0 ? 0 : xmin
  1333. X#xmax = mu + 4.0 * sigma
  1334. X#Mode of weibull PDF used
  1335. X#ymax = 1.1 * (n > 1.0 ? weibull(((n - 1.0) / (lambda * n))**(1.0 / n)) : 2.0)
  1336. Xset key
  1337. Xset zeroaxis
  1338. X#set xrange [xmin : xmax]
  1339. X#set yrange [0: ymax]
  1340. Xset xlabel "x ->"
  1341. Xset ylabel "probability density ->"
  1342. Xset xtics
  1343. Xset ytics
  1344. Xset format x "%.2f"
  1345. Xset format y "%.1f"
  1346. Xset sample 100
  1347. Xset title "weibull PDF"
  1348. Xplot [0:2] [0:1.5] lambda = 1, n = 0.5, weibull(x) title "lambda = 1, n = 0.5", \
  1349. X                   lambda = 1, n = 1.0, weibull(x) title "lambda = 1, n = 1.0", \
  1350. X                   lambda = 1, n = 2.0, weibull(x) title "lambda = 1, n = 2.0", \
  1351. X                   lambda = 3, n = 2.0, weibull(x) title "lambda = 3, n = 2.0"
  1352. Xpause -1 "Hit return to continue"
  1353. Xset title "weibull CDF"
  1354. Xplot [0:3] [0:1.2] lambda = 1, n = 0.5, cweibull(x) title "lambda = 1, n = 0.5", \
  1355. X                   lambda = 1, n = 1.0, cweibull(x) title "lambda = 1, n = 1.0", \
  1356. X                   lambda = 1, n = 2.0, cweibull(x) title "lambda = 1, n = 2.0", \
  1357. X                   lambda = 3, n = 2.0, cweibull(x) title "lambda = 3, n = 2.0"
  1358. Xload "defaults.ini"
  1359. END_OF_FILE
  1360.   if test 21935 -ne `wc -c <'gnuplot/demo/prob.dem'`; then
  1361.     echo shar: \"'gnuplot/demo/prob.dem'\" unpacked with wrong size!
  1362.   fi
  1363.   # end of 'gnuplot/demo/prob.dem'
  1364. fi
  1365. if test -f 'gnuplot/graph3d.c.B' -a "${1}" != "-c" ; then 
  1366.   echo shar: Will not clobber existing file \"'gnuplot/graph3d.c.B'\"
  1367. else
  1368.   echo shar: Extracting \"'gnuplot/graph3d.c.B'\" \(39930 characters\)
  1369.   sed "s/^X//" >'gnuplot/graph3d.c.B' <<'END_OF_FILE'
  1370. X      xmin_box = 0x7fff; 
  1371. X      xmax_box = 0;
  1372. X      ymin_box = 0x7fff; 
  1373. X      ymax_box = 0;
  1374. X      TESTBOX(nodes[j].x-xleft,nodes[j].y-ybot);
  1375. X      TESTBOX(nodes[j+1].x-xleft,nodes[j+1].y-ybot);
  1376. X      TESTBOX(nodes[j+row_offset].x-xleft,nodes[j+row_offset].y-ybot);
  1377. X      TESTBOX(nodes[j+row_offset+1].x-xleft,nodes[j+row_offset+1].y-ybot);
  1378. X      z=0;
  1379. X      if(xmin_box < 0) xmin_box = 0;
  1380. X      if(ymin_box < 0) ymin_box = 0;
  1381. X      if(xmax_box > xright-xleft) xmax_box = xright-xleft;
  1382. X      if(ymax_box > ytop-ybot) ymax_box = ytop-ybot;
  1383. X      /* Now check bitmap.  These coordinates have not been reduced */
  1384. X      if(xmin_box <= xmax_box && ymin_box <= ymax_box){
  1385. X    ymin_box = YREDUCE(ymin_box);
  1386. X    ymax_box = YREDUCE(ymax_box);
  1387. X    xmin_box = XREDUCE(xmin_box);
  1388. X    xmax_box = XREDUCE(xmax_box);
  1389. X    indx1 = ymin_box >> 4;
  1390. X    indx2 = ymax_box >> 4;
  1391. X    mask1 = 0xffff << (ymin_box & 0x0f);
  1392. X    mask2 = 0xffff >> (0x0f-(ymax_box & 0x0f));
  1393. X    for(m=xmin_box;m<=xmax_box;m++) {
  1394. X      if(pnt[m] == 0) {z++; break;};
  1395. X      cpnt = pnt[m] + indx1;
  1396. X      if(indx1 == indx2){
  1397. X        if((*cpnt & mask1 & mask2) != (mask1 & mask2)) {z++; break;}
  1398. X      } else {
  1399. X        if((*cpnt++ & mask1) != mask1) {z++; break;}
  1400. X        k = indx1+1;
  1401. X        while (k != indx2) {
  1402. X          if((unsigned short)*cpnt++ != 0xffff) {z++; break;}
  1403. X          k++;
  1404. X        };
  1405. X        if((*cpnt++ & mask2) != mask2) {z++; break;}
  1406. X      };
  1407. X    };
  1408. X      };
  1409. X      /* z is 0 if all of the pixels used by the current box are already covered.
  1410. X     No point in proceeding, so we just skip all further processing of this
  1411. X     box. */
  1412. X      if(!z) continue;
  1413. X      /* Now we need to figure out whether we are looking at the top or the
  1414. X     bottom of the square.  A simple cross product will tell us this.
  1415. X     If the square is really distorted then this will not be accurate,
  1416. X     but in such cases we would actually be seeing both sides at the same
  1417. X     time.  We choose the vertex with the largest z component to
  1418. X     take the cross product at.  */
  1419. X      {
  1420. X    int z1, z2 ,z3, z4;
  1421. X    z1 = XPRD(j+row_offset,j,j+1);
  1422. X    z2 = XPRD(j,j+1,j+1+row_offset);
  1423. X    z3 = XPRD(j+1,j+row_offset+1,j+row_offset);
  1424. X    z4 = XPRD(j+row_offset+1,j+row_offset,j);
  1425. X    z=0;
  1426. X    z += (z1 > 0 ? 1 : -1);
  1427. X    z += (z2 > 0 ? 1 : -1);
  1428. X    z += (z3 > 0 ? 1 : -1);
  1429. X    z += (z4 > 0 ? 1 : -1);
  1430. X    /* See if the box is uniformly one side or another. */
  1431. X    if(z != 4 && z != -4) {
  1432. X/* It isn't.  Now find the corner of the box with the largest z value that
  1433. X   has already been plotted, and use the same style used for that node.  */
  1434. X      k = -1000;
  1435. X      x = -32768;
  1436. X      if (nodes[j].z > x && nodes[j].style_used !=-1000) {
  1437. X        k = nodes[j].style_used;
  1438. X        x = nodes[j].z;
  1439. X      };
  1440. X      if (nodes[j+1].z > x && nodes[j+1].style_used !=-1000) {
  1441. X        k = nodes[j+1].style_used;
  1442. X        x = nodes[j+1].z;
  1443. X      };
  1444. X      if (nodes[j+row_offset+1].z > x && nodes[j+row_offset+1].style_used !=-1000) {
  1445. X        k = nodes[j+row_offset+1].style_used;
  1446. X        x = nodes[j+row_offset+1].z;
  1447. X      };
  1448. X      if (nodes[j+row_offset].z > x && nodes[j+row_offset].style_used !=-1000) {
  1449. X        k = nodes[j+row_offset].style_used;
  1450. X        x = nodes[j+row_offset].z;
  1451. X      };
  1452. X      if( k != -1000){
  1453. X        z = 0; /* To defeat the logic to come.  */
  1454. X        current_style = k;
  1455. X        (*t->linetype)(current_style);
  1456. X      };
  1457. X    };
  1458. X    /* If k == -1000 then no corner found.  I guess it does not matter.  */
  1459. X      };
  1460. X      if(z > 0 && current_style != plot_info[nplot].above_color) {
  1461. X    current_style = plot_info[nplot].above_color;
  1462. X    (*t->linetype)(current_style);
  1463. X      };
  1464. X      if(z < 0 && current_style != plot_info[nplot].below_color) {
  1465. X    current_style = plot_info[nplot].below_color;
  1466. X    (*t->linetype)(current_style);
  1467. X      };
  1468. X      xmin_hl = (sizeof(xleft) == 4 ? 0x7fffffff : 0x7fff ); 
  1469. X      xmax_hl = 0;
  1470. X      clip_move(nodes[j].x,nodes[j].y);
  1471. X      clip_vector(nodes[j+1].x,nodes[j+1].y);
  1472. X      clip_vector(nodes[j+row_offset+1].x,nodes[j+row_offset+1].y);
  1473. X      clip_vector(nodes[j+row_offset].x,nodes[j+row_offset].y);
  1474. X      clip_vector(nodes[j].x,nodes[j].y);
  1475. X      nodes[j].style_used = current_style;
  1476. X      nodes[j+1].style_used = current_style;
  1477. X      nodes[j+row_offset+1].style_used = current_style;
  1478. X      nodes[j+row_offset].style_used = current_style;
  1479. X      MAYBE_LINEPOINT(j);
  1480. X      MAYBE_LINEPOINT(j+1);
  1481. X      MAYBE_LINEPOINT(j+row_offset+1);
  1482. X      MAYBE_LINEPOINT(j+row_offset);
  1483. X      if( xmin_hl < 0 || xmax_hl > XREDUCE(xright)-XREDUCE(xleft))
  1484. X    int_error("Logic error #3 in hidden line",NO_CARET);
  1485. X      /* now mark the area as being filled in the bitmap.  These coordinates
  1486. X         have already been reduced. */
  1487. X      if (xmin_hl < xmax_hl)
  1488. X    for(j=xmin_hl;j<=xmax_hl;j++) {
  1489. X      if (ymin_hl[j] == 0x7fff) 
  1490. X        int_error("Logic error #2 in hidden line",NO_CARET);
  1491. X      if(pnt[j] == 0) {
  1492. X        pnt[j] = (short int *) alloc((unsigned long)y_malloc,"hidden");
  1493. X        bzero(pnt[j],y_malloc);
  1494. X      };
  1495. X      if(ymin_hl[j] < 0 || ymax_hl[j] > YREDUCE(ytop)-YREDUCE(ybot))
  1496. X        int_error("Logic error #1 in hidden line",NO_CARET);
  1497. X/* this shift is wordsize dependent */
  1498. X      indx1 = ymin_hl[j] >> 4;
  1499. X      indx2 = ymax_hl[j] >> 4;
  1500. X      mask1 = 0xffff << (ymin_hl[j] & 0xf);
  1501. X      mask2 = 0xffff >> (0xf-(ymax_hl[j] & 0xf));
  1502. X      cpnt = pnt[j] + indx1;
  1503. X      if(indx1 == indx2){
  1504. X        *cpnt |= (mask1 & mask2);
  1505. X      } else {
  1506. X        *cpnt++ |= mask1;
  1507. X        k = indx1+1;
  1508. X        while (k != indx2) {
  1509. X          *cpnt++ = 0xffff; 
  1510. X          k++;
  1511. X        };
  1512. X        *cpnt |= mask2;
  1513. X      };
  1514. X      ymin_hl[j]=0x7fff; 
  1515. X      ymax_hl[j]=0;
  1516. X    };
  1517. X    };
  1518. X  };
  1519. X  free(nodes);
  1520. X  free(boxlist);
  1521. X  free(plot_info);
  1522. X}
  1523. X
  1524. X#endif /* not LITE */
  1525. X
  1526. Xstatic plot3d_lines(plot)
  1527. X    struct surface_points *plot;
  1528. X{
  1529. X    int i;
  1530. X    int x,y;                /* point in terminal coordinates */
  1531. X    struct iso_curve *icrvs = plot->iso_crvs;
  1532. X    struct coordinate GPHUGE *points;
  1533. X
  1534. X#ifndef LITE
  1535. X/* These are handled elsewhere.  */
  1536. X    if (plot->has_grid_topology && hidden3d)
  1537. X    return(0);
  1538. X#endif /* not LITE */
  1539. X
  1540. X    while (icrvs) {
  1541. X
  1542. X    for (i = 0, points = icrvs->points; i < icrvs->p_count; i++) {
  1543. X        if (real_z_max3d<points[i].z)
  1544. X        real_z_max3d=points[i].z;
  1545. X        if (real_z_min3d>points[i].z)
  1546. X        real_z_min3d=points[i].z;
  1547. X
  1548. X        map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  1549. X
  1550. X        if (i > 0)
  1551. X        clip_vector(x,y);
  1552. X        else
  1553. X        clip_move(x,y);
  1554. X    }
  1555. X
  1556. X    icrvs = icrvs->next;
  1557. X    }
  1558. X}
  1559. X
  1560. X/* plot3d_points:
  1561. X * Plot the surfaces in POINTSTYLE style
  1562. X */
  1563. Xstatic plot3d_points(plot)
  1564. X    struct surface_points *plot;
  1565. X{
  1566. X    int i,x,y;
  1567. X    struct termentry *t = &term_tbl[term];
  1568. X    struct iso_curve *icrvs = plot->iso_crvs;
  1569. X
  1570. X    while ( icrvs ) {
  1571. X    struct coordinate GPHUGE *points = icrvs->points;
  1572. X
  1573. X    for (i = 0; i < icrvs->p_count; i++) {
  1574. X        if (real_z_max3d<points[i].z)
  1575. X        real_z_max3d=points[i].z;
  1576. X        if (real_z_min3d>points[i].z)
  1577. X        real_z_min3d=points[i].z;
  1578. X
  1579. X        map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  1580. X
  1581. X        if (!clip_point(x,y))
  1582. X        (*t->point)(x,y, plot->point_type);
  1583. X    }
  1584. X
  1585. X    icrvs = icrvs->next;
  1586. X    }
  1587. X}
  1588. X
  1589. X/* plot3d_dots:
  1590. X * Plot the surfaces in DOTS style
  1591. X */
  1592. Xstatic plot3d_dots(plot)
  1593. X    struct surface_points *plot;
  1594. X{
  1595. X    int i,x,y;
  1596. X    struct termentry *t = &term_tbl[term];
  1597. X    struct iso_curve *icrvs = plot->iso_crvs;
  1598. X
  1599. X    while ( icrvs ) {
  1600. X    struct coordinate GPHUGE *points = icrvs->points;
  1601. X
  1602. X        for (i = 0; i < icrvs->p_count; i++) {
  1603. X        if (real_z_max3d<points[i].z)
  1604. X        real_z_max3d=points[i].z;
  1605. X        if (real_z_min3d>points[i].z)
  1606. X            real_z_min3d=points[i].z;
  1607. X
  1608. X            map3d_xy(points[i].x, points[i].y, points[i].z, &x, &y);
  1609. X
  1610. X            if (!clip_point(x,y))
  1611. X        (*t->point)(x,y, -1);
  1612. X        }
  1613. X
  1614. X    icrvs = icrvs->next;
  1615. X    }
  1616. X}
  1617. X
  1618. X/* cntr3d_impulses:
  1619. X * Plot a surface contour in IMPULSES style
  1620. X */
  1621. Xstatic cntr3d_impulses(cntr, plot)
  1622. X    struct gnuplot_contours *cntr;
  1623. X    struct surface_points *plot;
  1624. X{
  1625. X    int i;                /* point index */
  1626. X    int x,y,x0,y0;            /* point in terminal coordinates */
  1627. X
  1628. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  1629. X    for (i = 0; i < cntr->num_pts; i++) {
  1630. X        if (real_z_max3d<cntr->coords[i].z)
  1631. X        real_z_max3d=cntr->coords[i].z;
  1632. X        if (real_z_min3d>cntr->coords[i].z)
  1633. X        real_z_min3d=cntr->coords[i].z;
  1634. X
  1635. X        map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  1636. X             &x, &y);
  1637. X        map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  1638. X             &x0, &y0);
  1639. X
  1640. X        clip_move(x0,y0);
  1641. X        clip_vector(x,y);
  1642. X    }
  1643. X    }
  1644. X    else
  1645. X    cntr3d_points(cntr, plot);   /* Must be on base grid, so do points. */
  1646. X}
  1647. X
  1648. X/* cntr3d_lines:
  1649. X * Plot a surface contour in LINES style
  1650. X */
  1651. Xstatic cntr3d_lines(cntr)
  1652. X    struct gnuplot_contours *cntr;
  1653. X{
  1654. X    int i;                /* point index */
  1655. X    int x,y;                /* point in terminal coordinates */
  1656. X
  1657. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  1658. X    for (i = 0; i < cntr->num_pts; i++) {
  1659. X        if (real_z_max3d<cntr->coords[i].z)
  1660. X        real_z_max3d=cntr->coords[i].z;
  1661. X        if (real_z_min3d>cntr->coords[i].z)
  1662. X        real_z_min3d=cntr->coords[i].z;
  1663. X
  1664. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  1665. X                 &x, &y);
  1666. X
  1667. X             if (i > 0) {
  1668. X                 clip_vector(x,y);
  1669. X                 if(i == 1) suppressMove = TRUE;
  1670. X             } else {
  1671. X                 clip_move(x,y);
  1672. X             }
  1673. X        }
  1674. X    }
  1675. X     suppressMove = FALSE;  /* beginning a new contour level, so moveto() required */
  1676. X
  1677. X    if (draw_contour == CONTOUR_BASE || draw_contour == CONTOUR_BOTH) {
  1678. X    for (i = 0; i < cntr->num_pts; i++) {
  1679. X        if (real_z_max3d<cntr->coords[i].z)
  1680. X        real_z_max3d=cntr->coords[i].z;
  1681. X        if (real_z_min3d>cntr->coords[i].z)
  1682. X        real_z_min3d=cntr->coords[i].z;
  1683. X
  1684. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  1685. X                 &x, &y);
  1686. X
  1687. X             if (i > 0) {
  1688. X                 clip_vector(x,y);
  1689. X                 if(i == 1) suppressMove = TRUE;
  1690. X             } else {
  1691. X                 clip_move(x,y);
  1692. X             }
  1693. X         }
  1694. X     }
  1695. X     suppressMove = FALSE;  /* beginning a new contour level, so moveto() required */
  1696. X}
  1697. X
  1698. X/* cntr3d_points:
  1699. X * Plot a surface contour in POINTSTYLE style
  1700. X */
  1701. Xstatic cntr3d_points(cntr, plot)
  1702. X    struct gnuplot_contours *cntr;
  1703. X    struct surface_points *plot;
  1704. X{
  1705. X    int i;
  1706. X    int x,y;
  1707. X    struct termentry *t = &term_tbl[term];
  1708. X
  1709. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  1710. X    for (i = 0; i < cntr->num_pts; i++) {
  1711. X        if (real_z_max3d<cntr->coords[i].z)
  1712. X        real_z_max3d=cntr->coords[i].z;
  1713. X        if (real_z_min3d>cntr->coords[i].z)
  1714. X        real_z_min3d=cntr->coords[i].z;
  1715. X
  1716. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  1717. X                 &x, &y);
  1718. X
  1719. X        if (!clip_point(x,y))
  1720. X        (*t->point)(x,y, plot->point_type);
  1721. X        }
  1722. X    }
  1723. X
  1724. X    if (draw_contour == CONTOUR_BASE || draw_contour == CONTOUR_BOTH) {
  1725. X    for (i = 0; i < cntr->num_pts; i++) {
  1726. X        if (real_z_max3d<cntr->coords[i].z)
  1727. X        real_z_max3d=cntr->coords[i].z;
  1728. X        if (real_z_min3d>cntr->coords[i].z)
  1729. X        real_z_min3d=cntr->coords[i].z;
  1730. X
  1731. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  1732. X                 &x, &y);
  1733. X
  1734. X        if (!clip_point(x,y))
  1735. X        (*t->point)(x,y, plot->point_type);
  1736. X        }
  1737. X    }
  1738. X}
  1739. X
  1740. X/* cntr3d_dots:
  1741. X * Plot a surface contour in DOTS style
  1742. X */
  1743. Xstatic cntr3d_dots(cntr)
  1744. X    struct gnuplot_contours *cntr;
  1745. X{
  1746. X    int i;
  1747. X    int x,y;
  1748. X    struct termentry *t = &term_tbl[term];
  1749. X
  1750. X    if (draw_contour == CONTOUR_SRF || draw_contour == CONTOUR_BOTH) {
  1751. X    for (i = 0; i < cntr->num_pts; i++) {
  1752. X        if (real_z_max3d<cntr->coords[i].z)
  1753. X        real_z_max3d=cntr->coords[i].z;
  1754. X        if (real_z_min3d>cntr->coords[i].z)
  1755. X        real_z_min3d=cntr->coords[i].z;
  1756. X
  1757. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, cntr->coords[i].z,
  1758. X                 &x, &y);
  1759. X
  1760. X        if (!clip_point(x,y))
  1761. X        (*t->point)(x,y, -1);
  1762. X        }
  1763. X    }
  1764. X
  1765. X    if (draw_contour == CONTOUR_BASE || draw_contour == CONTOUR_BOTH) {
  1766. X    for (i = 0; i < cntr->num_pts; i++) {
  1767. X        if (real_z_max3d<cntr->coords[i].z)
  1768. X        real_z_max3d=cntr->coords[i].z;
  1769. X        if (real_z_min3d>cntr->coords[i].z)
  1770. X        real_z_min3d=cntr->coords[i].z;
  1771. X
  1772. X            map3d_xy(cntr->coords[i].x, cntr->coords[i].y, z_min3d,
  1773. X                 &x, &y);
  1774. X
  1775. X        if (!clip_point(x,y))
  1776. X        (*t->point)(x,y, -1);
  1777. X        }
  1778. X    }
  1779. X}
  1780. X
  1781. Xstatic update_extrema_pts(ix, iy, min_sx_x, min_sx_y, min_sy_x, min_sy_y,
  1782. X              x, y)
  1783. X    int ix, iy, *min_sx_x, *min_sx_y, *min_sy_x, *min_sy_y;
  1784. X    double x, y;
  1785. X{
  1786. X
  1787. X    if (*min_sx_x > ix + 2 ||         /* find (bottom) left corner of grid */
  1788. X    (abs(*min_sx_x - ix) <= 2 && *min_sx_y > iy)) {
  1789. X    *min_sx_x = ix;
  1790. X    *min_sx_y = iy;
  1791. X    min_sx_ox = x;
  1792. X    min_sx_oy = y;
  1793. X    }
  1794. X    if (*min_sy_y > iy + 2 ||         /* find bottom (right) corner of grid */
  1795. X    (abs(*min_sy_y - iy) <= 2 && *min_sy_x < ix)) {
  1796. X    *min_sy_x = ix;
  1797. X    *min_sy_y = iy;
  1798. X    min_sy_ox = x;
  1799. X    min_sy_oy = y;
  1800. X    }
  1801. X}
  1802. X
  1803. X/* Draw the bottom grid for the parametric case. */
  1804. Xstatic draw_parametric_grid(plot)
  1805. X    struct surface_points *plot;
  1806. X{
  1807. X    int i,ix,iy,            /* point in terminal coordinates */
  1808. X    min_sx_x = 10000,min_sx_y = 10000,min_sy_x = 10000,min_sy_y = 10000,
  1809. X        grid_iso_1 = plot->plot_type == DATA3D && plot->has_grid_topology ?
  1810. X                    plot->iso_crvs->p_count : iso_samples_1,
  1811. X        grid_iso_2 = plot->plot_type == DATA3D && plot->has_grid_topology ?
  1812. X                    plot->num_iso_read : iso_samples_2;
  1813. X    double x,y,dx,dy;
  1814. X
  1815. X    if (grid && plot->has_grid_topology) {
  1816. X
  1817. X    /* fix grid lines to tic marks, D. Taber, 02-01-93 */
  1818. X    if(xtics && xticdef.type == TIC_SERIES) {
  1819. X        dx = xticdef.def.series.incr;
  1820. X        x = xticdef.def.series.start;
  1821. X        grid_iso_1 = 1 + (xticdef.def.series.end - x) / dx;
  1822. X    } else {
  1823. X        x = x_min3d;
  1824. X    dx = (x_max3d-x_min3d) / (grid_iso_1-1);
  1825. X    }
  1826. X
  1827. X    if(ytics && yticdef.type == TIC_SERIES) {
  1828. X        dy = yticdef.def.series.incr;
  1829. X        y = yticdef.def.series.start;
  1830. X        grid_iso_2 = 1 + (yticdef.def.series.end - y) / dy;
  1831. X    } else {
  1832. X        y = y_min3d;
  1833. X    dy = (y_max3d-y_min3d) / (grid_iso_2-1);
  1834. X    }
  1835. X
  1836. X    for (i = 0; i < grid_iso_2; i++) {
  1837. X            if (i == 0 || i == grid_iso_2-1)            
  1838. X            setlinestyle(-2);
  1839. X        else
  1840. X            setlinestyle(-1);
  1841. X        map3d_xy(x_min3d, y, z_min3d, &ix, &iy);
  1842. X        clip_move(ix,iy);
  1843. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1844. X                   &min_sy_x,&min_sy_y,x_min3d,y);
  1845. X
  1846. X        map3d_xy(x_max3d, y, z_min3d, &ix, &iy);
  1847. X        clip_vector(ix,iy);
  1848. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1849. X                   &min_sy_x,&min_sy_y,x_max3d,y);
  1850. X
  1851. X        y += dy;
  1852. X    }
  1853. X
  1854. X    for (i = 0; i < grid_iso_1; i++) {
  1855. X            if (i == 0 || i == grid_iso_1-1)
  1856. X            setlinestyle(-2);
  1857. X        else
  1858. X            setlinestyle(-1);
  1859. X        map3d_xy(x, y_min3d, z_min3d, &ix, &iy);
  1860. X        clip_move(ix,iy);
  1861. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1862. X                   &min_sy_x,&min_sy_y,x,y_min3d);
  1863. X
  1864. X        map3d_xy(x, y_max3d, z_min3d, &ix, &iy);
  1865. X        clip_vector(ix,iy);
  1866. X        update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1867. X                   &min_sy_x,&min_sy_y,x,y_max3d);
  1868. X
  1869. X        x += dx;
  1870. X    }
  1871. X    }
  1872. X    else {
  1873. X    setlinestyle(-2);
  1874. X
  1875. X    map3d_xy(x_min3d, y_min3d, z_min3d, &ix, &iy);
  1876. X    clip_move(ix,iy);
  1877. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1878. X               &min_sy_x,&min_sy_y,x_min3d,y_min3d);
  1879. X
  1880. X    map3d_xy(x_max3d, y_min3d, z_min3d, &ix, &iy);
  1881. X    clip_vector(ix,iy);
  1882. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1883. X               &min_sy_x,&min_sy_y,x_max3d,y_min3d);
  1884. X
  1885. X    map3d_xy(x_max3d, y_max3d, z_min3d, &ix, &iy);
  1886. X    clip_vector(ix,iy);
  1887. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1888. X               &min_sy_x,&min_sy_y,x_max3d,y_max3d);
  1889. X
  1890. X    map3d_xy(x_min3d, y_max3d, z_min3d, &ix, &iy);
  1891. X    clip_vector(ix,iy);
  1892. X    update_extrema_pts(ix,iy,&min_sx_x,&min_sx_y,
  1893. X               &min_sy_x,&min_sy_y,x_min3d,y_max3d);
  1894. X
  1895. X
  1896. X    map3d_xy(x_min3d, y_min3d, z_min3d, &ix, &iy);
  1897. X    clip_vector(ix,iy);
  1898. X    }
  1899. X}
  1900. X
  1901. X/* Draw the bottom grid for non parametric case. */
  1902. Xstatic draw_non_param_grid(plot)
  1903. X    struct surface_points *plot;
  1904. X{
  1905. X    int i,is_boundary=TRUE,crv_count=0,
  1906. X    x,y,                /* point in terminal coordinates */
  1907. X    min_sx_x = 10000,min_sx_y = 10000,min_sy_x = 10000,min_sy_y = 10000,
  1908. X        grid_iso = plot->plot_type == DATA3D && plot->has_grid_topology ?
  1909. X                    plot->num_iso_read : iso_samples_2;
  1910. X    struct iso_curve *icrvs = plot->iso_crvs;
  1911. X
  1912. X    while ( icrvs ) {
  1913. X    struct coordinate GPHUGE *points = icrvs->points;
  1914. X    int saved_hidden_active = hidden_active;
  1915. X    int z1 = map3d_z(points[0].x, points[0].y, 0.0),
  1916. X           z2 = map3d_z(points[icrvs->p_count-1].x,
  1917. X                            points[icrvs->p_count-1].y, 0.0);
  1918. X
  1919. X    for (i = 0; i < icrvs->p_count; i += icrvs->p_count-1) {
  1920. X        map3d_xy(points[i].x, points[i].y, z_min3d, &x, &y);
  1921. X        if (is_boundary) {
  1922. X        setlinestyle(-2);
  1923. X        }
  1924. X        else {
  1925. X            setlinestyle(-1);
  1926. X        }
  1927. X
  1928. X        if (i > 0) {
  1929. X            clip_vector(x,y);
  1930. X        }
  1931. X        else {
  1932. X            clip_move(x,y);
  1933. X        }
  1934. X
  1935. X        if (draw_surface &&
  1936. X            is_boundary &&
  1937. X            (i == 0 || i == icrvs->p_count-1)) {
  1938. X            int x1,y1;            /* point in terminal coordinates */
  1939. X
  1940. X        /* Draw a vertical line to surface corner from grid corner. */
  1941. X            map3d_xy(points[i].x, points[i].y, points[i].z, &x1, &y1);
  1942. X#ifndef LITE
  1943. X            if (hidden3d) {
  1944. X            if ((i == 0 && z1 > z2) ||
  1945. X                (i == icrvs->p_count-1 && z2 > z1)) {
  1946. X                hidden_active = FALSE; /* This one is always visible. */
  1947. X            }                
  1948. X            }
  1949. X#endif /* not LITE */
  1950. X            clip_vector(x1,y1);
  1951. X            clip_move(x,y);
  1952. X        hidden_active = saved_hidden_active;
  1953. X        update_extrema_pts(x,y,&min_sx_x,&min_sx_y, &min_sy_x,&min_sy_y,
  1954. X                   points[i].x,points[i].y);
  1955. X        }
  1956. X    }
  1957. X
  1958. X    if (grid) {
  1959. X        crv_count++;
  1960. X        icrvs = icrvs->next;
  1961. X        is_boundary = crv_count == grid_iso - 1 ||
  1962. X              crv_count == grid_iso ||
  1963. X              (icrvs && icrvs->next == NULL);
  1964. X    }
  1965. X    else {
  1966. X        switch (crv_count++) {
  1967. X        case 0:
  1968. X            for (i = 0; i < grid_iso - 1; i++)
  1969. X            icrvs = icrvs->next;
  1970. X            break;
  1971. X        case 1:
  1972. X            icrvs = icrvs->next;
  1973. X            break;
  1974. X        case 2:
  1975. X            while (icrvs->next)
  1976. X            icrvs = icrvs->next;
  1977. X            break;
  1978. X        case 3:
  1979. X            icrvs = NULL;
  1980. X            break;
  1981. X        }
  1982. X        }
  1983. X    }
  1984. X    if(hidden3d){
  1985. X      struct iso_curve *lcrvs = plot->iso_crvs;
  1986. X      struct coordinate GPHUGE *points, GPHUGE *lpoints;
  1987. X      icrvs = lcrvs;
  1988. X      while(lcrvs->next) lcrvs = lcrvs->next;
  1989. X      points = icrvs->points;
  1990. X      lpoints = lcrvs->points;
  1991. X      is_boundary = TRUE;
  1992. X      for (i = 0; i < icrvs->p_count; i += (grid ? 1 : icrvs->p_count - 1)) {
  1993. X    if ((i == 0) || (i == icrvs->p_count - 1)) {
  1994. X      setlinestyle(-2);
  1995. X    }
  1996. X    else {
  1997. X      setlinestyle(-1);
  1998. X    }
  1999. X    map3d_xy(points[i].x, points[i].y, z_min3d, &x, &y);
  2000. X    clip_move(x, y);
  2001. X    map3d_xy(lpoints[i].x, lpoints[i].y, z_min3d, &x, &y);
  2002. X    clip_vector(x, y);
  2003. X      };
  2004. X    };
  2005. X}
  2006. X
  2007. X/* Draw the bottom grid that hold the tic marks for 3d surface. */
  2008. Xstatic draw_bottom_grid(plot, min_z, max_z)
  2009. X    struct surface_points *plot;
  2010. X    double min_z, max_z;
  2011. X{
  2012. X    int x,y;    /* point in terminal coordinates */
  2013. X    double xtic,ytic,ztic;
  2014. X    struct termentry *t = &term_tbl[term];
  2015. X
  2016. X    xtic = make_3dtics(x_min3d,x_max3d,'x',is_log_x,base_log_x);
  2017. X    ytic = make_3dtics(y_min3d,y_max3d,'y',is_log_y,base_log_y);
  2018. X    ztic = make_3dtics(min_z,max_z,'z',is_log_z,base_log_z);
  2019. X
  2020. X    if (draw_border)
  2021. X    if (parametric || !plot->has_grid_topology)
  2022. X        draw_parametric_grid(plot);
  2023. X    else
  2024. X        draw_non_param_grid(plot);
  2025. X
  2026. X    setlinestyle(-2); /* border linetype */
  2027. X
  2028. X/* label x axis tics */
  2029. X    if (xtics && xtic > 0.0) {
  2030. X        switch (xticdef.type) {
  2031. X            case TIC_COMPUTED:
  2032. X         if (x_min3d < x_max3d)
  2033. X            draw_3dxtics(xtic * floor(x_min3d/xtic),
  2034. X                     xtic,
  2035. X                     xtic * ceil(x_max3d/xtic),
  2036. X                     min_sy_oy);
  2037. X                else
  2038. X            draw_3dxtics(xtic * floor(x_max3d/xtic),
  2039. X                     xtic,
  2040. X                     xtic * ceil(x_min3d/xtic),
  2041. X                     min_sy_oy);
  2042. X            break;
  2043. X        case TIC_MONTH:
  2044. X        draw_month_3dxtics(min_sy_oy);
  2045. X        break;
  2046. X        case TIC_DAY:
  2047. X        draw_day_3dxtics(min_sy_oy);
  2048. X        break;
  2049. X        case TIC_SERIES:
  2050. X        draw_series_3dxtics(xticdef.def.series.start, 
  2051. X                    xticdef.def.series.incr, 
  2052. X                    xticdef.def.series.end,
  2053. X                    min_sy_oy);
  2054. X        break;
  2055. X        case TIC_USER:
  2056. X        draw_set_3dxtics(xticdef.def.user,
  2057. X                 min_sy_oy);
  2058. X        break;
  2059. X            default:
  2060. X            (*t->text)();
  2061. X            (void) fflush(outfile);
  2062. X            int_error("unknown tic type in xticdef in do_3dplot", NO_CARET);
  2063. X            break;        /* NOTREACHED */
  2064. X        }
  2065. X    }
  2066. X/* label y axis tics */
  2067. X    if (ytics && (ytic > 0.0)) {
  2068. X        switch (yticdef.type) {
  2069. X            case TIC_COMPUTED:
  2070. X         if (y_min3d < y_max3d) {
  2071. X            draw_3dytics(ytic * floor(y_min3d/ytic),
  2072. X                     ytic,
  2073. X                     ytic * ceil(y_max3d/ytic),
  2074. X                     min_sy_ox);
  2075. X         }else{
  2076. X            draw_3dytics(ytic * floor(y_max3d/ytic),
  2077. X                     ytic,
  2078. X                     ytic * ceil(y_min3d/ytic),
  2079. X                     min_sy_ox);
  2080. X        }
  2081. X            break;
  2082. X        case TIC_MONTH:
  2083. X        draw_month_3dytics(min_sy_ox);
  2084. X        break;
  2085. X        case TIC_DAY:
  2086. X        draw_day_3dytics(min_sy_ox);
  2087. X        break;
  2088. X        case TIC_SERIES:
  2089. X        draw_series_3dytics(yticdef.def.series.start, 
  2090. X                    yticdef.def.series.incr, 
  2091. X                    yticdef.def.series.end,
  2092. X                    min_sy_ox);
  2093. X        break;
  2094. X        case TIC_USER:
  2095. X        draw_set_3dytics(yticdef.def.user,
  2096. X                 min_sy_ox);
  2097. X        break;
  2098. X            default:
  2099. X            (*t->text)();
  2100. X            (void) fflush(outfile);
  2101. X            int_error("unknown tic type in yticdef in do_3dplot", NO_CARET);
  2102. X            break;        /* NOTREACHED */
  2103. X        }
  2104. X    }
  2105. X/* label z axis tics */
  2106. X    if (ztics && ztic > 0.0 && (draw_surface ||
  2107. X                draw_contour == CONTOUR_SRF ||
  2108. X                draw_contour == CONTOUR_BOTH)) {
  2109. X        switch (zticdef.type) {
  2110. X            case TIC_COMPUTED:
  2111. X         if (min_z < max_z)
  2112. X            draw_3dztics(ztic * floor(min_z/ztic),
  2113. X                     ztic,
  2114. X                     ztic * ceil(max_z/ztic),
  2115. X                 min_sx_ox,
  2116. X                     min_sx_oy,
  2117. X                     min_z,
  2118. X                 max_z);
  2119. X                else
  2120. X            draw_3dztics(ztic * floor(max_z/ztic),
  2121. X                     ztic,
  2122. X                     ztic * ceil(min_z/ztic),
  2123. X                     min_sx_ox,
  2124. X                 min_sx_oy,
  2125. X                     max_z,
  2126. X                 min_z);
  2127. X            break;
  2128. X        case TIC_MONTH:
  2129. X        draw_month_3dztics(min_sx_ox,min_sx_oy,min_z,max_z);
  2130. X        break;
  2131. X        case TIC_DAY:
  2132. X        draw_day_3dztics(min_sx_ox,min_sx_oy,min_z,max_z);
  2133. X        break;
  2134. X        case TIC_SERIES:
  2135. X        draw_series_3dztics(zticdef.def.series.start, 
  2136. X                    zticdef.def.series.incr, 
  2137. X                    zticdef.def.series.end,
  2138. X                    min_sx_ox,
  2139. X                    min_sx_oy,
  2140. X                    min_z,
  2141. X                    max_z);
  2142. X
  2143. X        break;
  2144. X        case TIC_USER:
  2145. X        draw_set_3dztics(zticdef.def.user,
  2146. X                 min_sx_ox,
  2147. X                     min_sx_oy,
  2148. X                     min_z,
  2149. X                 max_z);
  2150. X        break;
  2151. X            default:
  2152. X            (*t->text)();
  2153. X            (void) fflush(outfile);
  2154. X            int_error("unknown tic type in zticdef in do_3dplot", NO_CARET);
  2155. X            break;        /* NOTREACHED */
  2156. X        }
  2157. X    }
  2158. X
  2159. X/* PLACE XLABEL - along the middle grid X axis */
  2160. X    if (strlen(xlabel) > 0) {
  2161. X       int x1,y1;
  2162. X       double step = apx_eq( min_sy_oy, y_min3d ) ?    (y_max3d-y_min3d)/4
  2163. X                              : (y_min3d-y_max3d)/4;
  2164. X           map3d_xy((x_min3d+x_max3d)/2,min_sy_oy-step, z_min3d,&x1,&y1);
  2165. X       x1 += xlabel_xoffset * t->h_char;
  2166. X       y1 += xlabel_yoffset * t->v_char;
  2167. X       if ((*t->justify_text)(CENTRE))
  2168. X        clip_put_text(x1,y1,xlabel);
  2169. X       else
  2170. X        clip_put_text(x1 - strlen(xlabel)*(t->h_char)/2,y1,xlabel);
  2171. X    }
  2172. X
  2173. X/* PLACE YLABEL - along the middle grid Y axis */
  2174. X    if (strlen(ylabel) > 0) {
  2175. X       int x1,y1;
  2176. X       double step = apx_eq( min_sy_ox, x_min3d ) ?    (x_max3d-x_min3d)/4
  2177. X                              : (x_min3d-x_max3d)/4;
  2178. X           map3d_xy(min_sy_ox-step,(y_min3d+y_max3d)/2,z_min3d,&x1,&y1);
  2179. X       x1 += ylabel_xoffset * t->h_char;
  2180. X       y1 += ylabel_yoffset * t->v_char;
  2181. X       if ((*t->justify_text)(CENTRE))
  2182. X        clip_put_text(x1,y1,ylabel);
  2183. X       else
  2184. X        clip_put_text(x1 - strlen(ylabel)*(t->h_char)/2,y1,ylabel);
  2185. X    }
  2186. X
  2187. X/* PLACE ZLABEL - along the middle grid Z axis */
  2188. X    if (strlen(zlabel) > 0 &&
  2189. X        (draw_surface ||
  2190. X     draw_contour == CONTOUR_SRF ||
  2191. X     draw_contour == CONTOUR_BOTH)) {
  2192. X           map3d_xy(min_sx_ox,min_sx_oy,max_z + (max_z-min_z)/4, &x, &y);
  2193. X
  2194. X       x += zlabel_xoffset * t->h_char;
  2195. X       y += zlabel_yoffset * t->v_char;
  2196. X       if ((*t->justify_text)(CENTRE))
  2197. X        clip_put_text(x,y,zlabel);
  2198. X       else
  2199. X        clip_put_text(x - strlen(zlabel)*(t->h_char)/2,y,zlabel);
  2200. X    }
  2201. X}
  2202. X
  2203. X/* DRAW_3DXTICS: draw a regular tic series, x axis */
  2204. Xstatic draw_3dxtics(start, incr, end, ypos)
  2205. X    double start, incr, end, ypos; /* tic series definition */
  2206. X        /* assume start < end, incr > 0 */
  2207. X{
  2208. X    double ticplace;
  2209. X    int ltic;        /* for mini log tics */
  2210. X    double lticplace;    /* for mini log tics */
  2211. X
  2212. X    end = end + SIGNIF*incr; 
  2213. X
  2214. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  2215. X        if (ticplace < start || ticplace > end) continue;
  2216. X        xtick(ticplace, xformat, incr, 1.0, ypos);
  2217. X        if (is_log_x && incr == 1.0) {
  2218. X            /* add mini-ticks to log scale ticmarks */
  2219. X            for (ltic = 2; ltic < (int)base_log_x; ltic++) {
  2220. X                lticplace = ticplace+log((double)ltic)/log_base_log_x;
  2221. X                xtick(lticplace, "\0", incr, 0.5, ypos);
  2222. X            }
  2223. X        }
  2224. X    }
  2225. X}
  2226. X
  2227. X/* DRAW_3DYTICS: draw a regular tic series, y axis */
  2228. Xstatic draw_3dytics(start, incr, end, xpos)
  2229. X    double start, incr, end, xpos; /* tic series definition */
  2230. X        /* assume start < end, incr > 0 */
  2231. X{
  2232. X    double ticplace;
  2233. X    int ltic;        /* for mini log tics */
  2234. X    double lticplace;    /* for mini log tics */
  2235. X
  2236. X    end = end + SIGNIF*incr; 
  2237. X
  2238. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  2239. X        if (ticplace < start || ticplace > end) continue;
  2240. X        ytick(ticplace, yformat, incr, 1.0, xpos);
  2241. X        if (is_log_y && incr == 1.0) {
  2242. X            /* add mini-ticks to log scale ticmarks */
  2243. X            for (ltic = 2; ltic < (int)base_log_y; ltic++) {
  2244. X                lticplace = ticplace+log((double)ltic)/log_base_log_y;
  2245. X                ytick(lticplace, "\0", incr, 0.5, xpos);
  2246. X            }
  2247. X        }
  2248. X    }
  2249. X}
  2250. X
  2251. X/* DRAW_3DZTICS: draw a regular tic series, z axis */
  2252. Xstatic draw_3dztics(start, incr, end, xpos, ypos, z_min, z_max)
  2253. X    double start, incr, end, xpos, ypos, z_min, z_max;
  2254. X        /* assume start < end, incr > 0 */
  2255. X{
  2256. X    int x, y;
  2257. X    double ticplace;
  2258. X    int ltic;        /* for mini log tics */
  2259. X    double lticplace;    /* for mini log tics */
  2260. X
  2261. X    end = end + SIGNIF*incr; 
  2262. X
  2263. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  2264. X        if (ticplace < start || ticplace > end) continue;
  2265. X
  2266. X        ztick(ticplace, zformat, incr, 1.0, xpos, ypos);
  2267. X        if (is_log_z && incr == 1.0) {
  2268. X            /* add mini-ticks to log scale ticmarks */
  2269. X            for (ltic = 2; ltic < (int)base_log_z; ltic++) {
  2270. X                lticplace = ticplace+log((double)ltic)/log_base_log_z;
  2271. X                ztick(lticplace, "\0", incr, 0.5, xpos, ypos);
  2272. X            }
  2273. X        }
  2274. X    }
  2275. X
  2276. X    /* Make sure the vertical line is fully drawn. */
  2277. X    setlinestyle(-2);    /* axis line type */
  2278. X
  2279. X    map3d_xy(xpos, ypos, z_min3d, &x, &y);
  2280. X    clip_move(x,y);
  2281. X    map3d_xy(xpos, ypos, min(end,z_max)+(is_log_z ? incr : 0.0), &x, &y);
  2282. X    clip_vector(x,y);
  2283. X
  2284. X    setlinestyle(-1); /* border linetype */
  2285. X}
  2286. X
  2287. X/* DRAW_SERIES_3DXTICS: draw a user tic series, x axis */
  2288. Xstatic draw_series_3dxtics(start, incr, end, ypos)
  2289. X        double start, incr, end, ypos; /* tic series definition */
  2290. X        /* assume start < end, incr > 0 */
  2291. X{
  2292. X    double ticplace, place;
  2293. X    double ticmin, ticmax;    /* for checking if tic is almost inrange */
  2294. X    double spacing = is_log_x ? log(incr)/log_base_log_x : incr;
  2295. X
  2296. X    if (end == VERYLARGE)
  2297. X        end = max(CheckLog(is_log_x, base_log_x, x_min3d),
  2298. X              CheckLog(is_log_x, base_log_x, x_max3d));
  2299. X    else
  2300. X      /* limit to right side of plot */
  2301. X      end = min(end, max(CheckLog(is_log_x, base_log_x, x_min3d),
  2302. X                 CheckLog(is_log_x, base_log_x, x_max3d)));
  2303. X
  2304. X    /* to allow for rounding errors */
  2305. X    ticmin = min(x_min3d,x_max3d) - SIGNIF*incr;
  2306. X    ticmax = max(x_min3d,x_max3d) + SIGNIF*incr;
  2307. X    end = end + SIGNIF*incr; 
  2308. X
  2309. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  2310. X        place = (is_log_x ? log(ticplace)/log_base_log_x : ticplace);
  2311. X        if ( inrange(place,ticmin,ticmax) )
  2312. X         xtick(place, xformat, spacing, 1.0, ypos);
  2313. X    }
  2314. X}
  2315. X
  2316. X/* DRAW_SERIES_3DYTICS: draw a user tic series, y axis */
  2317. Xstatic draw_series_3dytics(start, incr, end, xpos)
  2318. X        double start, incr, end, xpos; /* tic series definition */
  2319. X        /* assume start < end, incr > 0 */
  2320. X{
  2321. X    double ticplace, place;
  2322. X    double ticmin, ticmax;    /* for checking if tic is almost inrange */
  2323. X    double spacing = is_log_y ? log(incr)/log_base_log_y : incr;
  2324. X
  2325. X    if (end == VERYLARGE)
  2326. X        end = max(CheckLog(is_log_y, base_log_y, y_min3d),
  2327. X              CheckLog(is_log_y, base_log_y, y_max3d));
  2328. X    else
  2329. X      /* limit to right side of plot */
  2330. X      end = min(end, max(CheckLog(is_log_y, base_log_y, y_min3d),
  2331. X                 CheckLog(is_log_y, base_log_y, y_max3d)));
  2332. X
  2333. X    /* to allow for rounding errors */
  2334. X    ticmin = min(y_min3d,y_max3d) - SIGNIF*incr;
  2335. X    ticmax = max(y_min3d,y_max3d) + SIGNIF*incr;
  2336. X    end = end + SIGNIF*incr; 
  2337. X
  2338. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  2339. X        place = (is_log_y ? log(ticplace)/log_base_log_y : ticplace);
  2340. X        if ( inrange(place,ticmin,ticmax) )
  2341. X         ytick(place, xformat, spacing, 1.0, xpos);
  2342. X    }
  2343. X}
  2344. X
  2345. X/* DRAW_SERIES_3DZTICS: draw a user tic series, z axis */
  2346. Xstatic draw_series_3dztics(start, incr, end, xpos, ypos, z_min, z_max)
  2347. X        double start, incr, end; /* tic series definition */
  2348. X        double xpos, ypos, z_min, z_max;
  2349. X        /* assume start < end, incr > 0 */
  2350. X{
  2351. X    int x, y;
  2352. X    double ticplace, place;
  2353. X    double ticmin, ticmax;    /* for checking if tic is almost inrange */
  2354. X    double spacing = is_log_x ? log(incr)/log_base_log_x : incr;
  2355. X
  2356. X    if (end == VERYLARGE)
  2357. X        end = max(CheckLog(is_log_z, base_log_z, z_min),
  2358. X              CheckLog(is_log_z, base_log_z, z_max));
  2359. X    else
  2360. X      /* limit to right side of plot */
  2361. X      end = min(end, max(CheckLog(is_log_z, base_log_z, z_min),
  2362. X                 CheckLog(is_log_z, base_log_z, z_max)));
  2363. X
  2364. X    /* to allow for rounding errors */
  2365. X    ticmin = min(z_min,z_max) - SIGNIF*incr;
  2366. X    ticmax = max(z_min,z_max) + SIGNIF*incr;
  2367. X    end = end + SIGNIF*incr; 
  2368. X
  2369. X    for (ticplace = start; ticplace <= end; ticplace +=incr) {
  2370. X        place = (is_log_z ? log(ticplace)/log_base_log_z : ticplace);
  2371. X        if ( inrange(place,ticmin,ticmax) )
  2372. X         ztick(place, zformat, spacing, 1.0, xpos, ypos);
  2373. X    }
  2374. X
  2375. X    /* Make sure the vertical line is fully drawn. */
  2376. X    setlinestyle(-2);    /* axis line type */
  2377. X
  2378. X    map3d_xy(xpos, ypos, z_min3d, &x, &y);
  2379. X    clip_move(x,y);
  2380. X    map3d_xy(xpos, ypos, min(end,z_max)+(is_log_z ? incr : 0.0), &x, &y);
  2381. X    clip_vector(x,y);
  2382. X
  2383. X    setlinestyle(-1); /* border linetype */
  2384. X}
  2385. Xextern char *month[];
  2386. Xextern char *day[];
  2387. Xdraw_month_3dxtics(ypos)
  2388. Xdouble ypos;
  2389. X{
  2390. X    long l_ticplace,l_incr,l_end,m_calc;
  2391. X
  2392. X    l_ticplace = (long)x_min3d;
  2393. X    if((double)l_ticplace<x_min3d)l_ticplace++;
  2394. X    l_end=(long)x_max3d;
  2395. X    l_incr=(l_end-l_ticplace)/12;
  2396. X    if(l_incr<1)l_incr=1;
  2397. X    while(l_ticplace<=l_end)
  2398. X    {    m_calc=(l_ticplace-1)%12;
  2399. X    if(m_calc<0)m_calc += 12;
  2400. X    xtick((double)l_ticplace,month[m_calc],(double)l_incr,1.0,ypos);
  2401. X    l_ticplace += l_incr;
  2402. X    }
  2403. X}
  2404. Xdraw_month_3dytics(xpos)
  2405. Xdouble xpos;
  2406. X{
  2407. X    long l_ticplace,l_incr,l_end,m_calc;
  2408. X
  2409. X    l_ticplace = (long)y_min3d;
  2410. X    if((double)l_ticplace<y_min3d)l_ticplace++;
  2411. X    l_end=(long)y_max3d;
  2412. X    l_incr=(l_end-l_ticplace)/12;
  2413. X    if(l_incr<1)l_incr=1;
  2414. X    while(l_ticplace<=l_end)
  2415. X    {    m_calc=(l_ticplace-1)%12;
  2416. X    if(m_calc<0)m_calc += 12;
  2417. X    ytick((double)l_ticplace,month[m_calc],(double)l_incr,1.0,xpos);
  2418. X    l_ticplace += l_incr;
  2419. X    }
  2420. X}
  2421. Xdraw_month_3dztics(xpos,ypos,z_min3d,z_max3d)
  2422. Xdouble xpos,ypos,z_min3d,z_max3d;
  2423. X{
  2424. X    long l_ticplace,l_incr,l_end,m_calc;
  2425. X
  2426. X    l_ticplace = (long)z_min3d;
  2427. X    if((double)l_ticplace<z_min3d)l_ticplace++;
  2428. X    l_end=(long)z_max3d;
  2429. X    l_incr=(l_end-l_ticplace)/12;
  2430. X    if(l_incr<1)l_incr=1;
  2431. X    while(l_ticplace<=l_end)
  2432. X    {    m_calc=(l_ticplace-1)%12;
  2433. X    if(m_calc<0)m_calc += 12;
  2434. X    ztick((double)l_ticplace,month[m_calc],(double)l_incr,1.0,xpos,ypos);
  2435. X    l_ticplace += l_incr;
  2436. X    }
  2437. X}
  2438. Xdraw_day_3dxtics(ypos)
  2439. Xdouble ypos;
  2440. X{
  2441. X    long l_ticplace,l_incr,l_end,m_calc;
  2442. X
  2443. X    l_ticplace = (long)x_min3d;
  2444. X    if((double)l_ticplace<x_min3d)l_ticplace++;
  2445. X    l_end=(long)x_max3d;
  2446. X    l_incr=(l_end-l_ticplace)/14;
  2447. X    if(l_incr<1)l_incr=1;
  2448. X    while(l_ticplace<=l_end)
  2449. X    {    m_calc=l_ticplace%7;
  2450. X    if(m_calc<0)m_calc += 7;
  2451. X    xtick((double)l_ticplace,day[m_calc],(double)l_incr,1.0,ypos);
  2452. X    l_ticplace += l_incr;
  2453. X    }
  2454. X}
  2455. Xdraw_day_3dytics(xpos)
  2456. Xdouble xpos;
  2457. X{
  2458. X    long l_ticplace,l_incr,l_end,m_calc;
  2459. X
  2460. X    l_ticplace = (long)y_min3d;
  2461. X    if((double)l_ticplace<y_min3d)l_ticplace++;
  2462. X    l_end=(long)y_max3d;
  2463. X    l_incr=(l_end-l_ticplace)/14;
  2464. X    if(l_incr<1)l_incr=1;
  2465. X    while(l_ticplace<=l_end)
  2466. X    {    m_calc=l_ticplace%7;
  2467. X    if(m_calc<0)m_calc += 7;
  2468. X    ytick((double)l_ticplace,day[m_calc],(double)l_incr,1.0,xpos);
  2469. X    l_ticplace += l_incr;
  2470. X    }
  2471. X}
  2472. Xdraw_day_3dztics(xpos,ypos,z_min3d,z_max3d)
  2473. Xdouble xpos,ypos,z_min3d,z_max3d;
  2474. X{
  2475. X    long l_ticplace,l_incr,l_end,m_calc;
  2476. X
  2477. X    l_ticplace = (long)z_min3d;
  2478. X    if((double)l_ticplace<z_min3d)l_ticplace++;
  2479. X    l_end=(long)z_max3d;
  2480. X    l_incr=(l_end-l_ticplace)/14;
  2481. X    if(l_incr<1)l_incr=1;
  2482. X    while(l_ticplace<=l_end)
  2483. X    {    m_calc=l_ticplace%7;
  2484. X    if(m_calc<0)m_calc += 7;
  2485. X    ztick((double)l_ticplace,day[m_calc],(double)l_incr,1.0,xpos,ypos);
  2486. X    l_ticplace += l_incr;
  2487. X    }
  2488. X}
  2489. X/* DRAW_SET_3DXTICS: draw a user tic set, x axis */
  2490. Xstatic draw_set_3dxtics(list, ypos)
  2491. X    struct ticmark *list;    /* list of tic marks */
  2492. X    double ypos;
  2493. X{
  2494. X    double ticplace;
  2495. X    double incr = (x_max3d - x_min3d) / 10;
  2496. X    /* global x_min3d, x_max3d, xscale, y_min3d, y_max3d, yscale */
  2497. X
  2498. X    while (list != NULL) {
  2499. X       ticplace = (is_log_x ? log(list->position)/log_base_log_x
  2500. X                : list->position);
  2501. X       if ( inrange(ticplace, x_min3d, x_max3d)         /* in range */
  2502. X          || NearlyEqual(ticplace, x_min3d, incr)    /* == x_min */
  2503. X          || NearlyEqual(ticplace, x_max3d, incr))    /* == x_max */
  2504. X        xtick(ticplace, list->label, incr, 1.0, ypos);
  2505. X
  2506. X       list = list->next;
  2507. X    }
  2508. X}
  2509. X
  2510. X/* DRAW_SET_3DYTICS: draw a user tic set, y axis */
  2511. Xstatic draw_set_3dytics(list, xpos)
  2512. X    struct ticmark *list;    /* list of tic marks */
  2513. X    double xpos;
  2514. X{
  2515. X    double ticplace;
  2516. X    double incr = (y_max3d - y_min3d) / 10;
  2517. X    /* global x_min3d, x_max3d, xscale, y_min3d, y_max3d, yscale */
  2518. X
  2519. X    while (list != NULL) {
  2520. X       ticplace = (is_log_y ? log(list->position)/log_base_log_y
  2521. X                : list->position);
  2522. X       if ( inrange(ticplace, y_min3d, y_max3d)           /* in range */
  2523. X          || NearlyEqual(ticplace, y_min3d, incr)    /* == y_min3d */
  2524. X          || NearlyEqual(ticplace, y_max3d, incr))    /* == y_max3d */
  2525. X        ytick(ticplace, list->label, incr, 1.0, xpos);
  2526. X
  2527. X       list = list->next;
  2528. X    }
  2529. X}
  2530. X
  2531. X/* DRAW_SET_3DZTICS: draw a user tic set, z axis */
  2532. Xstatic draw_set_3dztics(list, xpos, ypos, z_min, z_max)
  2533. X    struct ticmark *list;    /* list of tic marks */
  2534. X    double xpos, ypos, z_min, z_max;
  2535. X{
  2536. X    int x, y;
  2537. X    double ticplace;
  2538. X    double incr = (z_max - z_min) / 10;
  2539. X
  2540. X    while (list != NULL) {
  2541. X       ticplace = (is_log_z ? log(list->position)/log_base_log_z
  2542. X                : list->position);
  2543. X       if ( inrange(ticplace, z_min, z_max)         /* in range */
  2544. X          || NearlyEqual(ticplace, z_min, incr)        /* == z_min */
  2545. X          || NearlyEqual(ticplace, z_max, incr))    /* == z_max */
  2546. X        ztick(ticplace, list->label, incr, 1.0, xpos, ypos);
  2547. X
  2548. X       list = list->next;
  2549. X    }
  2550. X
  2551. X    /* Make sure the vertical line is fully drawn. */
  2552. X    setlinestyle(-2);    /* axis line type */
  2553. X
  2554. X    map3d_xy(xpos, ypos, z_min, &x, &y);
  2555. X    clip_move(x,y);
  2556. X    map3d_xy(xpos, ypos, z_max+(is_log_z ? incr : 0.0), &x, &y);
  2557. X    clip_vector(x,y);
  2558. X
  2559. X    setlinestyle(-1); /* border linetype */
  2560. X}
  2561. X
  2562. X/* draw and label a x-axis ticmark */
  2563. Xstatic xtick(place, text, spacing, ticscale, ypos)
  2564. X        double place;                   /* where on axis to put it */
  2565. X        char *text;                     /* optional text label */
  2566. X        double spacing;         /* something to use with checkzero */
  2567. X        double ticscale;         /* scale factor for tic mark (0..1] */
  2568. X    double ypos;
  2569. X{
  2570. X    register struct termentry *t = &term_tbl[term];
  2571. X    char ticlabel[101];
  2572. X    int x0,y0,x1,y1,x2,y2,x3,y3;
  2573. X    int ticsize = (int)((t->h_tic) * ticscale);
  2574. X    double v[2], len;
  2575. X
  2576. X    place = CheckZero(place,spacing); /* to fix rounding error near zero */
  2577. X
  2578. X
  2579. X    if(x_max3d> x_min3d){
  2580. X        if (place > x_max3d || place < x_min3d) return(0);
  2581. X    }else{
  2582. X        if (place > x_min3d || place < x_max3d) return(0);
  2583. X    }
  2584. X
  2585. X    map3d_xy(place, ypos, z_min3d, &x0, &y0);
  2586. X    /* need to figure out which is in. pick the middle point along the */
  2587. X    /* axis as in.                               */
  2588. X    map3d_xy(place, (y_max3d + y_min3d) / 2, z_min3d, &x1, &y1);
  2589. X
  2590. X    /* compute a vector of length 1 into the grid: */
  2591. X    v[0] = x1 - x0;
  2592. X    v[1] = y1 - y0;
  2593. X    len = sqrt(v[0] * v[0] + v[1] * v[1]);
  2594. X    if (len == 0.0) return;
  2595. X    v[0] /= len;
  2596. X    v[1] /= len;
  2597. X
  2598. X    if (tic_in) {
  2599. X    x1 = x0;
  2600. X    y1 = y0;
  2601. X    x2 = x1 + ((int) (v[0] * ticsize));
  2602. X    y2 = y1 + ((int) (v[1] * ticsize));
  2603. X        x3 = x0 - ((int) (v[0] * ticsize * 3)); /* compute text position */
  2604. X        y3 = y0 - ((int) (v[1] * ticsize * 3));
  2605. X    } else {
  2606. X    x1 = x0;
  2607. X    y1 = y0;
  2608. X    x2 = x0 - ((int) (v[0] * ticsize));
  2609. X    y2 = y0 - ((int) (v[1] * ticsize));
  2610. X        x3 = x0 - ((int) (v[0] * ticsize * 4)); /* compute text position */
  2611. X        y3 = y0 - ((int) (v[1] * ticsize * 4));
  2612. X    }
  2613. X    clip_move(x1,y1);
  2614. X    clip_vector(x2,y2);
  2615. X
  2616. X    /* label the ticmark */
  2617. X    if (text == NULL)
  2618. X     text = xformat;
  2619. X
  2620. X    (void) sprintf(ticlabel, text, CheckLog(is_log_x, base_log_x, place));
  2621. X    if (apx_eq(v[0], 0.0)) {
  2622. X        if ((*t->justify_text)(CENTRE)) {
  2623. X            clip_put_text(x3,y3,ticlabel);
  2624. X        } else {
  2625. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel)/2,y3,ticlabel);
  2626. X        }
  2627. X    }
  2628. X    else if (v[0] > 0) {
  2629. X        if ((*t->justify_text)(RIGHT)) {
  2630. X            clip_put_text(x3,y3,ticlabel);
  2631. X        } else {
  2632. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel),y3,ticlabel);
  2633. X        }
  2634. X    } else {
  2635. X        (*t->justify_text)(LEFT);
  2636. X    clip_put_text(x3,y3,ticlabel);
  2637. X    }
  2638. X}
  2639. X
  2640. X/* draw and label a y-axis ticmark */
  2641. Xstatic ytick(place, text, spacing, ticscale, xpos)
  2642. X        double place;                   /* where on axis to put it */
  2643. X        char *text;                     /* optional text label */
  2644. X        double spacing;         /* something to use with checkzero */
  2645. X        double ticscale;         /* scale factor for tic mark (0..1] */
  2646. X    double xpos;
  2647. X{
  2648. X    register struct termentry *t = &term_tbl[term];
  2649. X    char ticlabel[101];
  2650. X    int x0,y0,x1,y1,x2,y2,x3,y3;
  2651. X    int ticsize = (int)((t->h_tic) * ticscale);
  2652. X    double v[2], len;
  2653. X
  2654. X    place = CheckZero(place,spacing); /* to fix rounding error near zero */
  2655. X
  2656. X    if(y_max3d> y_min3d){
  2657. X        if (place > y_max3d || place < y_min3d) return(0);
  2658. X    }else{
  2659. X        if (place > y_min3d || place < y_max3d) return(0);
  2660. X    }
  2661. X
  2662. X    map3d_xy(xpos, place, z_min3d, &x0, &y0);
  2663. X    /* need to figure out which is in. pick the middle point along the */
  2664. X    /* axis as in.                               */
  2665. X    map3d_xy((x_max3d + x_min3d) / 2, place, z_min3d, &x1, &y1);
  2666. X
  2667. X    /* compute a vector of length 1 into the grid: */
  2668. X    v[0] = x1 - x0;
  2669. X    v[1] = y1 - y0;
  2670. X    len = sqrt(v[0] * v[0] + v[1] * v[1]);
  2671. X    if (len == 0.0) return(0);
  2672. X    v[0] /= len;
  2673. X    v[1] /= len;
  2674. X
  2675. X    if (tic_in) {
  2676. X    x1 = x0;
  2677. X    y1 = y0;
  2678. X    x2 = x1 + ((int) (v[0] * ticsize));
  2679. X    y2 = y1 + ((int) (v[1] * ticsize));
  2680. X        x3 = x0 - ((int) (v[0] * ticsize * 3)); /* compute text position */
  2681. X        y3 = y0 - ((int) (v[1] * ticsize * 3));
  2682. X    } else {
  2683. X    x1 = x0;
  2684. X    y1 = y0;
  2685. X    x2 = x0 - ((int) (v[0] * ticsize));
  2686. X    y2 = y0 - ((int) (v[1] * ticsize));
  2687. X        x3 = x0 - ((int) (v[0] * ticsize * 4)); /* compute text position */
  2688. X        y3 = y0 - ((int) (v[1] * ticsize * 4));
  2689. X    }
  2690. X    clip_move(x1,y1);
  2691. X    clip_vector(x2,y2);
  2692. X
  2693. X    /* label the ticmark */
  2694. X    if (text == NULL)
  2695. X     text = yformat;
  2696. X
  2697. X    (void) sprintf(ticlabel, text, CheckLog(is_log_y, base_log_y, place));
  2698. X    if (apx_eq(v[0], 0.0)) {
  2699. X        if ((*t->justify_text)(CENTRE)) {
  2700. X            clip_put_text(x3,y3,ticlabel);
  2701. X        } else {
  2702. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel)/2,y3,ticlabel);
  2703. X        }
  2704. X    }
  2705. X    else if (v[0] > 0) {
  2706. X        if ((*t->justify_text)(RIGHT)) {
  2707. X            clip_put_text(x3,y3,ticlabel);
  2708. X        } else {
  2709. X            clip_put_text(x3-(t->h_char)*strlen(ticlabel),y3,ticlabel);
  2710. X        }
  2711. X    } else {
  2712. X        (*t->justify_text)(LEFT);
  2713. X    clip_put_text(x3,y3,ticlabel);
  2714. X    }
  2715. X}
  2716. X
  2717. X/* draw and label a z-axis ticmark */
  2718. Xstatic ztick(place, text, spacing, ticscale, xpos, ypos)
  2719. X        double place;                   /* where on axis to put it */
  2720. X        char *text;                     /* optional text label */
  2721. X        double spacing;         /* something to use with checkzero */
  2722. X        double ticscale;         /* scale factor for tic mark (0..1] */
  2723. X    double xpos, ypos;
  2724. X{
  2725. X    register struct termentry *t = &term_tbl[term];
  2726. X    char ticlabel[101];
  2727. X    int x0,y0,x1,y1,x2,y2,x3,y3;
  2728. X    int ticsize = (int)((t->h_tic) * ticscale);
  2729. X
  2730. X    place = CheckZero(place,spacing); /* to fix rounding error near zero */
  2731. X
  2732. X    map3d_xy(xpos, ypos, place, &x0, &y0);
  2733. X
  2734. X    if (tic_in) {
  2735. X    x1 = x0;
  2736. X    y1 = y0;
  2737. X    x2 = x0 + ticsize;
  2738. X    y2 = y0;
  2739. X        x3 = x0 - ticsize;
  2740. X        y3 = y0;
  2741. X    } else {
  2742. X    x1 = x0;
  2743. X    y1 = y0;
  2744. X    x2 = x0 - ticsize;
  2745. X    y2 = y0;
  2746. X        x3 = x0 - ticsize * 2; /* compute text position */
  2747. X        y3 = y0;
  2748. X    }
  2749. X    clip_move(x1,y1);
  2750. X    clip_vector(x2,y2);
  2751. X
  2752. X    /* label the ticmark */
  2753. X    if (text == NULL)
  2754. X     text = zformat;
  2755. X
  2756. X    (void) sprintf(ticlabel, text, CheckLog(is_log_z, base_log_z, place));
  2757. X    if ((*t->justify_text)(RIGHT)) {
  2758. X        clip_put_text(x3,y3,ticlabel);
  2759. X    } else {
  2760. X        clip_put_text(x3-(t->h_char)*(strlen(ticlabel)+1),y3,ticlabel);
  2761. X    }
  2762. X}
  2763. END_OF_FILE
  2764.   if test 39930 -ne `wc -c <'gnuplot/graph3d.c.B'`; then
  2765.     echo shar: \"'gnuplot/graph3d.c.B'\" unpacked with wrong size!
  2766.   elif test -f 'gnuplot/graph3d.c.A' ; then
  2767.     echo shar: Combining  \"'gnuplot/graph3d.c'\" \(82372 characters\)
  2768.     cat 'gnuplot/graph3d.c.A' 'gnuplot/graph3d.c.B' > 'gnuplot/graph3d.c'
  2769.     if test 82372 -ne `wc -c <'gnuplot/graph3d.c'`; then
  2770.       echo shar: \"'gnuplot/graph3d.c'\" combined with wrong size!
  2771.     else  
  2772.       rm gnuplot/graph3d.c.A gnuplot/graph3d.c.B
  2773.     fi
  2774.   fi
  2775.   # end of 'gnuplot/graph3d.c.B'
  2776. fi
  2777. echo shar: End of archive 16 \(of 33\).
  2778. cp /dev/null ark16isdone
  2779. MISSING=""
  2780. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ; do
  2781.     if test ! -f ark${I}isdone ; then
  2782.     MISSING="${MISSING} ${I}"
  2783.     fi
  2784. done
  2785. if test "${MISSING}" = "" ; then
  2786.     echo You have unpacked all 33 archives.
  2787.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2788. else
  2789.     echo You still must unpack the following archives:
  2790.     echo "        " ${MISSING}
  2791. fi
  2792. exit 0
  2793. exit 0 # Just in case...
  2794.