File: test_data.c

package info (click to toggle)
quickplot 0.4.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 352 kB
  • ctags: 276
  • sloc: ansic: 4,124; makefile: 124; sh: 12
file content (126 lines) | stat: -rw-r--r-- 2,898 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************
LanceMan's quickplot --- a fast interactive 2D plotter

Copyright (C) 1998, 1999  Lance Arsenault

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

Or look at http://www.gnu.org/copyleft/gpl.html .

**********************************************************************/
/* $Id: test_data.c,v 1.1 1998/02/28 18:09:06 lance Exp $ */
#include <stdio.h>
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#include "GNUgetopt.h"


static struct option long_options[] =
{
  {"binary", 0, 0, 'b'},
  {"number-fields", 1, 0, 'f'},
  {"number-lines", 1, 0, 'l'},
  {0, 0, 0, 0}
};

static char * short_options  = {"bf:l:"};


/* default values */
static int num_lines = 2000;
static int num_fields = 4;
static int flag = 0;

#define BINARY_OUT   1  /* binary output flag */


#define RANDOMNESS     0.0
#define SIN_AMPLITUDE  1.0

#ifndef PI /* needed for SGI IRIX */
#define PI 3.14159265358979323846
#endif
 
void get_options(int argc, char **argv)
{
  if(argc < 2)
    return;

  while (1)
    {
      int c,i;
      int option_index = 1;

      if (-1 == (c = GNUgetopt_long (argc, argv, short_options,
               long_options, &option_index)))
	break;

      switch (c)
        {
        case 'b':
          flag |= BINARY_OUT;
          break;
	case 'f':
	  i = atoi(optarg);
	  if(i<1)
	    break;
	  num_fields = i;
	  break;
	case 'l':
	  i = atoi(optarg);
	  if(i<1)
	    break;
	  num_lines = i;
	  break;
	}
    }
}

int main(int argc, char **argv)
{
  double *x,y,dx;
  int i,j;

  get_options(argc, argv);
  assert(NULL != (x = (double *) malloc(num_fields*sizeof(double))));
  srand((unsigned int) (&y));/* random seed */
  if(flag & BINARY_OUT)
    {
      i = num_fields;
      fwrite(&i,sizeof(int),1,stdout);
    }
  dx = 10.0/num_lines;
  x[0] = -1.0;
  for(i=0;i<num_lines;i++)
    {
      for(j=1;j<num_fields;j++)
	x[j] = SIN_AMPLITUDE*(0.07*sin(2.0*PI*j/num_fields + 100.0*x[0]) +
			      cos(x[0] + 
	       2.0*PI*j/num_fields)) + 
	       RANDOMNESS*rand()/RAND_MAX; /* fuNKy function to plot */
      if(flag & BINARY_OUT)
	fwrite(x,sizeof(double),num_fields,stdout);
      else
	{
	  for(j=0;j<num_fields;j++)
	    printf("%.12g ",x[j]);
	  printf("\n");
	}
      x[0] += dx;
    }
  return 0;
}