
/* NAME
 *   gen1d - generate time series from a one-dimensional map
 * NOTES
 *   Includes the file "maps1d.c".
 * MAPS
 *   The following four one-dimensional maps are allowed:
 *   .IP Logistic\ Map:
 *   x(t+1) = 4 * r * x(t) * (1.0 - x(t))
 *   .IP Tent\ Map:
 *   x(t+1) = (x(t) <= 0.5) ? 2 * r * x(t) : 2r * (1.0 - x(t))
 *   .IP Sine\ Map:
 *   x(t+1) = sin(x(t) * PI * aux * 2 * r) / 2 + 0.5
 *   .IP Gaussian\ Map:
 *   x(t+1) = r * exp(-aux * (x(t) - 0.5) * (x(t) - 0.5))
 *   .LP
 *   See the file "maps1d.c" to see how to add user-defined maps.
 * MISCELLANY
 *   Use a plotting program (such as gnuplot) or a spreadsheet
 *   to plot the data.
 * BUGS
 *   No sanity checks are performed to make sure that any of the
 *   options make sense.
 * AUTHOR
 *   Copyright (c) 1997, Gary William Flake.
 *   
 *   Permission granted for any use according to the standard GNU
 *   ``copyleft'' agreement provided that the author's comments are
 *   neither modified nor removed.  No warranty is given or implied.
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "misc.h"

int points = 10, skip = 0, box = 0, invert = 0;
double r = 1.0, x0 = 0.123456, aux = 1.0;
char *func = "log";

char help_string[] = "\
A time series data set is generated by a one-dimensional map \
according to the specified options.  See the MAPS section of the manual \
page for details of what maps are supported.  User defined maps can be \
added to the file maps1d.c, but you must recompile the program. \
";

OPTION options[] = {
  { "-points", OPT_INT,     &points, "Number of points to plot." },
  { "-skip",   OPT_INT,     &skip,   "Number of initial points to skip." },
  { "-r",      OPT_DOUBLE,  &r,      "Value for the r parameter." },
  { "-aux",    OPT_DOUBLE,  &aux,    "Auxiliary map parameter." },
  { "-x0",     OPT_DOUBLE,  &x0,     "Initial value for x." },
  { "-func",   OPT_STRING,  &func,
    "Map function to use (one of 'log', 'tent', 'sin', or 'gauss')." },
  { NULL,      OPT_NULL,    NULL,    NULL }
};

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

#include "maps1d.c"

int main(int argc, char **argv)
{
  int i;
  double x, (*f)(double, double);

  get_options(argc, argv, options, help_string);

  f = get_named_function(func);

  /* Generate the points. */

  x = x0;
  for(i = 0; i < points + skip; i++) {
    x = f(x, r);
    if(i >= skip)
      printf("%f\n", x);
  }

  exit(0);
}

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

