Example #1
0
int main (void)
{
   unif01_Gen *gen1, *gen2, *gen3;
   long I[3] = { 3, 7, 9 };
   int i, n = 20;
   double x;

   gen1 = utaus_CreateTaus (31, 3, 12, 12345);
   for (i = 0; i < n; i++)
      printf ("%f\n", unif01_StripD (gen1, 0));
   utaus_DeleteGen (gen1);
   printf ("\n");

   gen1 = utaus_CreateTaus (31, 3, 12, 12345);
   gen2 = unif01_CreateLacGen (gen1, 3, I);
   for (i = 0; i < n; i++)
      printf ("%f\n", unif01_StripD (gen2, 0));

   gen3 = unif01_CreateDoubleGen (gen2, 24);
   for (i = 0; i < n; i++)
      x = unif01_StripD (gen3, 0);
   unif01_DeleteDoubleGen (gen3);
   unif01_DeleteLacGen (gen2);

   gen2 = utaus_CreateTaus (28, 7, 14, 12345);
   gen3 = unif01_CreateCombXor2 (gen1, gen2, "A Combined Tausworthe Gener.");
   for (i = 0; i < n; i++)
      x = unif01_StripD (gen3, 0);
   unif01_DeleteCombGen (gen3);
   utaus_DeleteGen (gen2);
   utaus_DeleteGen (gen1);
   return 0;
}
Example #2
0
void scatter_PlotUnif1 (unif01_Gen * gen, long N, int Dim, lebool Over,
   int Proj[2], double Lower[], double Upper[], scatter_OutputType Output,
   int Prec, lebool Lac, long LacI[], char *Name)
{
   int j;
   unif01_Gen *genL;
   chro = chrono_Create ();
   scatter_N = N;
   scatter_t = Dim;
   scatter_Over = Over;
   scatter_x = Proj[0];
   scatter_y = Proj[1];
   for (j = 1; j <= scatter_t; j++) {
      scatter_L[j] = Lower[j - 1];
      scatter_H[j] = Upper[j - 1];
      util_Assert (scatter_L[j] >= 0.0, "scatter_PlotUnif1:   Lower[r] < 0");
      util_Assert (scatter_H[j] <= 1.0, "scatter_PlotUnif1:   Upper[r] > 1");
      util_Assert (scatter_L[j] < scatter_H[j],
                   "scatter_PlotUnif1:   Upper[r] <= Lower[r]");
   }
   if (scatter_Width <= 0.0)
      scatter_Width = 13.0;       /* cm */
   if (scatter_Height <= 0.0)
      scatter_Height = 13.0;      /* cm */
   scatter_Output = Output;
   scatter_Lacunary = Lac;
   if (scatter_Lacunary) {
      for (j = 0; j < scatter_t; j++)
         scatter_LacI[j] = LacI[j];
      genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI);
   } else
      genL = gen;
   strncpy (Nin, Name, (size_t) NUM_CHAR - 5);
   Plot (genL, Nin, Prec);
   chrono_Delete (chro);
}
Example #3
0
static unif01_Gen * scatter_ReadData (
   unif01_Gen *gen,
   char *F               /* Input file name without its extension .dat */
   )
/*
 * Reads the data in file <F>.dat for scatter_PlotUnif, according to the
 * format of the figure in the documentation scatter.tex.
 */
{
   FILE *fin;                     /* Input file */
   int i, j;
   double xa, xb;
   unif01_Gen *genL;

   strncpy (Nin, F, (size_t) NUM_CHAR - 5);
   /* Add the extension .dat to input data file */
   strcat (Nin, ".dat");
   fin = util_Fopen (Nin, "r");

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %ld", &scatter_N);
   util_Assert (j > 0, "scatter_ReadData:   on reading scatter_N");

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %d", &scatter_t);
   util_Assert (j > 0, "scatter_ReadData:   on reading scatter_t");
   util_Assert (scatter_t <= scatter_MAXDIM,
                "scatter_ReadData:   scatter_t > scatter_MAXDIM");
   util_Assert (scatter_t > 1, "scatter_ReadData:   scatter_t < 2");

   fgets (S, NUM_CHAR, fin);
   util_ReadBool (S, &scatter_Over);

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %d %d", &scatter_x, &scatter_y);
   util_Assert (j > 0,
                "scatter_ReadData:   on reading scatter_x or scatter_y");
   util_Assert (scatter_x <= scatter_t,
                "scatter_ReadData:  scatter_x > scatter_t");
   util_Assert (scatter_y <= scatter_t,
                "scatter_ReadData:  scatter_y > scatter_t");

   /* By default, bounds are [0, 1] */
   for (i = 1; i < scatter_t; i++) {
      scatter_L[i] = 0.0;
      scatter_H[i] = 1.0;
   }

   do {
      fgets (S, NUM_CHAR, fin);
      j = sscanf (S, " %d %lf %lf", &i, &xa, &xb);
      util_Assert (j > 0,
         "scatter_ReadData:   on reading r, scatter_L[r], scatter_H[r]");
      util_Assert (i <= scatter_t,
                   "scatter_ReadData:   r > scatter_t");
      scatter_L[i] = xa;
      scatter_H[i] = xb;
      util_Assert (scatter_L[i] >= 0.0,
         "scatter_ReadData:   scatter_L[r] < 0");
      util_Assert (scatter_H[i] <= 1.0,
                   "scatter_ReadData:   scatter_H[r] > 1");
      util_Assert (scatter_L[i] < scatter_H[i],
                   "scatter_ReadData:   scatter_H[r] <= scatter_L[r]");
   } while (i != scatter_t);

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %lf %lf", &scatter_Width, &scatter_Height);
   util_Assert (j > 0,
      "scatter_ReadData:   on reading scatter_Width, scatter_Height");

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %12s", str);
   if (!strcmp (str, "latex"))
      scatter_Output = scatter_latex;
   else if (!strcmp (str, "gnu_term"))
      scatter_Output = scatter_gnu_term;
   else if (!strcmp (str, "gnu_ps"))
      scatter_Output = scatter_gnu_ps;
   else {
      util_Error ("scatter_ReadData:   on reading scatter_Output");
   }

   fgets (S, NUM_CHAR, fin);
   j = sscanf (S, " %d", &precision);
   util_Assert (j > 0, "scatter_ReadData:   on reading Precision");

   fgets (S, NUM_CHAR, fin);
   util_ReadBool (S, &scatter_Lacunary);

   if (scatter_Lacunary) {
      for (i = 0; i < scatter_t; i++) {
         fgets (S, NUM_CHAR, fin);
         j = sscanf (S, " %ld", &scatter_LacI[i]);
         util_Assert (j > 0,
            "scatter_ReadData:   on reading scatter_LacI[]");
      }
      genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI);
   } else
      genL = gen;

   util_Fclose (fin);
   return genL;
}
Example #4
0
static unif01_Gen * scatter_ReadDataInterac (unif01_Gen *gen)
/*
 * Reads the data for scatter_PlotUnifInterac, interactively on the terminal
 */
{
   char rep;
   int i, j;
   lebool erreur;
   char format[12];
   unif01_Gen *genL;

   do {
      erreur = FALSE;
      printf ("What kind of output?\n"
              "latex:     (l)\n"
              "gnu_ps:    (p)\n"
              "gnu_term:  (t)\n");
      fgets (S, NUM_CHAR, stdin);
      j = sscanf (S, " %1s", str);

      rep = str[0];
      switch ((unsigned) rep) {
      case 'l':
      case 'L':
         scatter_Output = scatter_latex;
         break;
      case 'p':
      case 'P':
         scatter_Output = scatter_gnu_ps;
         break;
      case 't':
      case 'T':
         scatter_Output = scatter_gnu_term;
         break;
      default:
	 printf ("Please, answer with one letter amongst l, p, t.\n");
         erreur = TRUE;
         break;
      }
   } while (erreur);

   sprintf (S, "%1d", NUM_CHAR - 5);
   strcpy (format, " %");
   strcat (format, S);
   strcat (format, "s");
   printf ("Name of output file (without extension): ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, format, Nin);
   util_Assert (j > 0, "scatter_ReadDataInterac");

   printf ("Number of points: ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %ld", &scatter_N);
   util_Assert (j > 0, "scatter_ReadDataInterac");

   printf ("Number of dimensions: ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %d", &scatter_t);
   util_Assert (j > 0, "scatter_ReadDataInterac");

   printf ("Overlapping:\n TRUE (t)\n FALSE (f)\n  ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %1s", str);
   if (str[0] == 't')
      scatter_Over = TRUE;
   else
      scatter_Over = FALSE;

   printf ("Which dimension for the x-axis: ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %d", &scatter_x);
   util_Assert (j > 0, "scatter_ReadDataInterac");

   printf ("Which dimension for the y-axis: ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %d", &scatter_y);
   util_Assert (j > 0, "scatter_ReadDataInterac");

   for (i = 1; i <= scatter_t; i++) {
      printf ("Lower bound for x%1d: ", i);
      fgets (S, NUM_CHAR, stdin);
      j = sscanf (S, " %lf", &scatter_L[i]);
      util_Assert (j > 0, "scatter_ReadDataInterac");

      printf ("Upper bound for x%1d: ", i);
      fgets (S, NUM_CHAR, stdin);
      j = sscanf (S, " %lf", &scatter_H[i]);
      util_Assert (j > 0, "scatter_ReadDataInterac");
      util_Assert (scatter_L[i] >= 0.0,
                   "scatter_ReadDataInterac:   scatter_L[r] < 0");
      util_Assert (scatter_H[i] <= 1.0,
                   "scatter_ReadDataInterac:   scatter_H[r] > 1");
      util_Assert (scatter_L[i] < scatter_H[i],
                   "scatter_ReadDataInterac:   scatter_H[r] >= scatter_L[r]");
   }
   scatter_Height = 13.0;
   scatter_Width = 13.0;


   printf ("Lacunary:\n TRUE (t)\n FALSE (f)\n  ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %1s", str);
   if (str[0] == 't')
      scatter_Lacunary = TRUE;
   else
      scatter_Lacunary = FALSE;

   if (scatter_Lacunary) {
      for (i = 0; i < scatter_t; i++) {
         printf ("Lacunary index %1d: ", i + 1);
         fgets (S, NUM_CHAR, stdin);
         j = sscanf (S, " %ld", &scatter_LacI[i]);
         util_Assert (j > 0,
             "scatter_ReadDataInterac:   on reading scatter_LacI[]");
      }
      genL = unif01_CreateLacGen (gen, scatter_t, scatter_LacI);
   } else
      genL = gen;

   printf ("Number of decimals of precision : ");
   fgets (S, NUM_CHAR, stdin);
   j = sscanf (S, " %d", &precision);
   util_Assert (j > 0, "scatter_ReadDataInterac:   on reading Precision");
   return genL;
}