Exemplo n.º 1
0
int main(int argc, char *argv[])
{
  dd_MatrixPtr M=NULL;
  dd_rowrange i,m;
  dd_ErrorType err=dd_NoError;
  dd_rowindex newpos;
  dd_rowset impl_linset,redset;
  time_t starttime, endtime;
  dd_DataFileType inputfile;
  FILE *reading=NULL;

  dd_set_global_constants();  /* First, this must be called. */

  if (argc>1) strcpy(inputfile,argv[1]);
  if (argc<=1 || !SetInputFile(&reading,argv[1])){
    dd_WriteProgramDescription(stdout);
    fprintf(stdout,"\ncddlib test program to check redundancy of an H/V-representation.\n");
    dd_SetInputFile(&reading,inputfile, &err);
  }
  if (err==dd_NoError) {
    M=dd_PolyFile2Matrix(reading, &err);
  }
  else {
    fprintf(stderr,"Input file not found\n");
    goto _L99;
  }

  if (err!=dd_NoError) goto _L99;

  m=M->rowsize;
  fprintf(stdout, "Canonicalize the matrix.\n");
    
  time(&starttime);
  dd_MatrixCanonicalize(&M, &impl_linset, &redset, &newpos, &err);
  time(&endtime);
  
  if (err!=dd_NoError) goto _L99;

  fprintf(stdout, "Implicit linearity rows are:"); set_fwrite(stdout, impl_linset);

  fprintf(stdout, "\nRedundant rows are:"); set_fwrite(stdout, redset);
  fprintf(stdout, "\n");
  
  fprintf(stdout, "Nonredundant representation:\n");
  fprintf(stdout, "The new row positions are as follows (orig:new).\nEach redundant row has the new number 0.\nEach deleted duplicated row has a number nagative of the row that\nrepresents its equivalence class.\n");
  
  for (i=1; i<=m; i++){
   fprintf(stdout, " %ld:%ld",i, newpos[i]); 
  }
  fprintf(stdout, "\n");
  dd_WriteMatrix(stdout, M);
  
  dd_WriteTimes(stdout,starttime,endtime);

  set_free(redset);
  set_free(impl_linset);
  dd_FreeMatrix(M);
  free(newpos);

_L99:;
  if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err);
  return 0;
}
Exemplo n.º 2
0
GenericAgentConfig CheckOpts(int argc, char **argv)
{
    extern char *optarg;
    int optindex = 0;
    int c;
    GenericAgentConfig config = GenericAgentDefaultConfig(cf_common);

    while ((c = getopt_long(argc, argv, "advnIf:D:N:VSrxMb:pg:h", OPTIONS, &optindex)) != EOF)
    {
        switch ((char) c)
        {
        case 'f':

            if (optarg && strlen(optarg) < 5)
            {
                FatalError(" -f used but argument \"%s\" incorrect", optarg);
            }

            SetInputFile(optarg);
            MINUSF = true;
            break;

        case 'd':
            NewClass("opt_debug");
            DEBUG = true;
            break;

        case 'b':
            if (optarg)
            {
                config.bundlesequence = SplitStringAsRList(optarg, ',');
                CBUNDLESEQUENCE_STR = optarg;
            }
            break;

        case 'K':
            IGNORELOCK = true;
            break;

        case 'D':
            NewClassesFromString(optarg);
            break;

        case 'N':
            NegateClassesFromString(optarg);
            break;

        case 'I':
            INFORM = true;
            break;

        case 'v':
            VERBOSE = true;
            break;

        case 'n':
            DONTDO = true;
            IGNORELOCK = true;
            LOOKUP = true;
            NewClass("opt_dry_run");
            break;

        case 'V':
            PrintVersionBanner("cf-promises");
            exit(0);

        case 'h':
            Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID);
            exit(0);

        case 'M':
            ManPage("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID);
            exit(0);

        case 'r':
            PrependRScalar(&GOALS, "goal.*", CF_SCALAR);
            SHOWREPORTS = true;
            break;

        case 'x':
            SelfDiagnostic();
            exit(0);

        case 'a':
            printf("Self-analysis is not yet implemented.\n");
            exit(0);
            break;

        /*
        case 'p':
            SHOW_PARSE_TREE = true;
            break;
        */

        case 'g':
            USE_GCC_BRIEF_FORMAT = true;
            break;

        default:
            Syntax("cf-promises - cfengine's promise analyzer", OPTIONS, HINTS, ID);
            exit(1);

        }
    }

    if (argv[optind] != NULL)
    {
        CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]);
    }

    CfDebug("Set debugging\n");

    return config;
}
Exemplo n.º 3
0
int main(int argc, char *argv[])
{
  dd_PolyhedraPtr poly;
  dd_LPPtr lp;
  dd_MatrixPtr M,A;
  dd_ErrorType err=dd_NoError;
  dd_DataFileType inputfile,outputfile;
  FILE *reading=NULL, *writing;

  dd_set_global_constants();  /* First, this must be called. */

  if (argc>1) strcpy(inputfile,argv[1]);
  if (argc<=1 || !SetInputFile(&reading,argv[1])){
    dd_WriteProgramDescription(stdout);
    dd_SetInputFile(&reading,inputfile, &err);
  }
  if (err==dd_NoError) {
    M=dd_PolyFile2Matrix(reading, &err);
  }
  else {
    printf("Input file not found\n");
    goto _L99;
  }

  if (err!=dd_NoError) goto _L99;

  if (M->objective==dd_LPnone){ /* do representation conversion */
    poly=dd_DDMatrix2Poly2(M, dd_LexMin, &err);
    /* equivalent to poly=dd_DDMatrix2Poly2(M, &err) when the second argument is set to dd_LexMin. */
    if (err!=dd_NoError) goto _L99;

    dd_SetWriteFileName(inputfile, outputfile, 'o', poly->representation);
    SetWriteFile(&writing, outputfile);
    dd_WriteProgramDescription(writing);
    dd_WriteRunningMode(writing, poly);
    switch (poly->representation) {
    case dd_Inequality:
      fprintf(writing, "ext_file: Generators\n");
      A=dd_CopyGenerators(poly);
      dd_WriteMatrix(writing,A);
      dd_FreeMatrix(A);
      break;

    case dd_Generator:
      fprintf(writing, "ine_file: Inequalities\n");
      A=dd_CopyInequalities(poly);
      dd_WriteMatrix(writing,A);
      dd_FreeMatrix(A);
      break;

    default:
      break;
    }
    dd_WriteDDTimes(writing,poly);
    fclose(writing);

    dd_SetWriteFileName(inputfile, outputfile, 'a', poly->representation);
    SetWriteFile(&writing, outputfile);
    dd_WriteAdjacency(writing,poly);
    fclose(writing);

    dd_SetWriteFileName(inputfile, outputfile, 'j', poly->representation);
    SetWriteFile(&writing, outputfile);
    dd_WriteInputAdjacency(writing,poly);
    fclose(writing);

    dd_SetWriteFileName(inputfile, outputfile, 'i', poly->representation);
    SetWriteFile(&writing, outputfile);
    dd_WriteIncidence(writing,poly);
    fclose(writing);

    dd_SetWriteFileName(inputfile, outputfile, 'n', poly->representation);
    SetWriteFile(&writing, outputfile);
    dd_WriteInputIncidence(writing,poly);
    fclose(writing);

    dd_FreeMatrix(M);
    dd_FreePolyhedra(poly);

  } else { /* solve the LP */
    lp=dd_Matrix2LP(M, &err);  if (err!=dd_NoError) goto _L99;
    dd_LPSolve(lp,dd_DualSimplex,&err);  if (err!=dd_NoError) goto _L99;

    dd_SetWriteFileName(inputfile, outputfile, 's', M->representation);
    SetWriteFile(&writing, outputfile);
    dd_WriteLPResult(writing, lp, err);
    fclose(writing);

    dd_FreeMatrix(M);
    dd_FreeLPData(lp);
  }
_L99:
  if (err!=dd_NoError) dd_WriteErrorMessages(stdout,err);
  return 0;
}
Exemplo n.º 4
0
GenericAgentConfig CheckOpts(int argc, char **argv)
{
    extern char *optarg;
    char ld_library_path[CF_BUFSIZE];
    int optindex = 0;
    int c;
    GenericAgentConfig config = GenericAgentDefaultConfig(cf_server);

    while ((c = getopt_long(argc, argv, "dvIKf:D:N:VSxLFMh", OPTIONS, &optindex)) != EOF)
    {
        switch ((char) c)
        {
        case 'f':

            if (optarg && (strlen(optarg) < 5))
            {
                FatalError(" -f used but argument \"%s\" incorrect", optarg);
            }

            SetInputFile(optarg);
            MINUSF = true;
            break;

        case 'd':
            DEBUG = true;
            NO_FORK = true;

        case 'K':
            IGNORELOCK = true;
            break;

        case 'D':
            NewClassesFromString(optarg);
            break;

        case 'N':
            NegateClassesFromString(optarg);
            break;

        case 'I':
            INFORM = true;
            break;

        case 'v':
            VERBOSE = true;
            NO_FORK = true;
            break;

        case 'F':
            NO_FORK = true;
            break;

        case 'L':
            CfOut(cf_verbose, "", "Setting LD_LIBRARY_PATH=%s\n", optarg);
            snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg);
            putenv(ld_library_path);
            break;

        case 'V':
            PrintVersionBanner("cf-serverd");
            exit(0);

        case 'h':
            Syntax("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'M':
            ManPage("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'x':
            SelfDiagnostic();
            exit(0);

        default:
            Syntax("cf-serverd - cfengine's server agent", OPTIONS, HINTS, ID);
            exit(1);

        }
    }

    if (argv[optind] != NULL)
    {
        CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]);
        FatalError("Aborted");
    }

    CfDebug("Set debugging\n");

    return config;
}
Exemplo n.º 5
0
static GenericAgentConfig CheckOpts(int argc, char **argv)
{
    extern char *optarg;
    int optindex = 0;
    int c;
    GenericAgentConfig config = GenericAgentDefaultConfig(AGENT_TYPE_RUNAGENT);

    DEFINECLASSES[0] = '\0';
    SENDCLASSES[0] = '\0';

    while ((c = getopt_long(argc, argv, "t:q:db:vnKhIif:D:VSxo:s:MH:", OPTIONS, &optindex)) != EOF)
    {
        switch ((char) c)
        {
        case 'f':
            SetInputFile(optarg);
            MINUSF = true;
            break;

        case 'b':
            BACKGROUND = true;
            if (optarg)
            {
                MAXCHILD = atoi(optarg);
            }
            break;

        case 'd':
            HardClass("opt_debug");
            DEBUG = true;
            break;

        case 'q':

            if (optarg == NULL)
            {
                strcpy(MENU, "delta");
            }
            else
            {
                strncpy(MENU, optarg, CF_MAXVARSIZE);
            }

            break;

        case 'K':
            IGNORELOCK = true;
            break;

        case 's':
            strncpy(SENDCLASSES, optarg, CF_MAXVARSIZE);

            if (strlen(optarg) > CF_MAXVARSIZE)
            {
                FatalError("Argument too long\n");
            }
            break;

        case 'D':
            strncpy(DEFINECLASSES, optarg, CF_MAXVARSIZE);

            if (strlen(optarg) > CF_MAXVARSIZE)
            {
                FatalError("Argument too long\n");
            }
            break;

        case 'H':
            HOSTLIST = SplitStringAsRList(optarg, ',');
            break;

        case 'o':
            strncpy(REMOTE_AGENT_OPTIONS, optarg, CF_MAXVARSIZE);
            break;

        case 'I':
            INFORM = true;
            break;

        case 'i':
            INTERACTIVE = true;
            break;

        case 'v':
            VERBOSE = true;
            break;

        case 'n':
            DONTDO = true;
            IGNORELOCK = true;
            HardClass("opt_dry_run");
            break;

        case 't':
            CONNTIMEOUT = atoi(optarg);
            break;

        case 'V':
            PrintVersionBanner("cf-runagent");
            exit(0);

        case 'h':
            Syntax("cf-runagent - Run agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'M':
            ManPage("cf-runagent - Run agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'x':
            SelfDiagnostic();
            exit(0);

        default:
            Syntax("cf-runagent - Run agent", OPTIONS, HINTS, ID);
            exit(1);

        }
    }

    CfDebug("Set debugging\n");

    return config;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{
    GenericAgentConfig config = CheckOpts(argc, argv);

    ReportContext *report_context = OpenReports("executor");
    Policy *policy = GenericInitialize("executor", config, report_context);
    ThisAgentInit();

    ExecConfig exec_config = {
        .scheduled_run = !ONCE,
        .exec_command = SafeStringDuplicate(""),
        .mail_server = SafeStringDuplicate(""),
        .mail_from_address = SafeStringDuplicate(""),
        .mail_to_address = SafeStringDuplicate(""),
        .mail_max_lines = 30,
        .fq_name = VFQNAME,
        .ip_address = VIPADDRESS,
        .agent_expireafter = 10080,
    };

    KeepPromises(policy, &exec_config);

#ifdef MINGW
    if (WINSERVICE)
    {
        NovaWin_StartExecService();
    }
    else
#endif /* MINGW */
    {
        StartServer(policy, &exec_config, report_context);
    }

    ReportContextDestroy(report_context);

    return 0;
}

/*****************************************************************************/
/* Level 1                                                                   */
/*****************************************************************************/

static GenericAgentConfig CheckOpts(int argc, char **argv)
{
    extern char *optarg;
    int optindex = 0;
    int c;
    char ld_library_path[CF_BUFSIZE];
    GenericAgentConfig config = GenericAgentDefaultConfig(AGENT_TYPE_EXECUTOR);

    while ((c = getopt_long(argc, argv, "dvnKIf:D:N:VxL:hFOV1gMW", OPTIONS, &optindex)) != EOF)
    {
        switch ((char) c)
        {
        case 'f':

            if (optarg && strlen(optarg) < 5)
            {
                FatalError(" -f used but argument \"%s\" incorrect", optarg);
            }

            SetInputFile(optarg);
            MINUSF = true;
            break;

        case 'd':
            HardClass("opt_debug");
            DEBUG = true;
            break;

        case 'K':
            IGNORELOCK = true;
            break;

        case 'D':
            NewClassesFromString(optarg);
            break;

        case 'N':
            NegateClassesFromString(optarg);
            break;

        case 'I':
            INFORM = true;
            break;

        case 'v':
            VERBOSE = true;
            NO_FORK = true;
            break;

        case 'n':
            DONTDO = true;
            IGNORELOCK = true;
            HardClass("opt_dry_run");
            break;

        case 'L':
            snprintf(ld_library_path, CF_BUFSIZE - 1, "LD_LIBRARY_PATH=%s", optarg);
            if (putenv(xstrdup(ld_library_path)) != 0)
            {
            }
            break;

        case 'W':
            WINSERVICE = false;
            break;

        case 'F':
            NO_FORK = true;
            break;

        case 'O':
            ONCE = true;
            break;

        case 'V':
            PrintVersionBanner("cf-execd");
            exit(0);

        case 'h':
            Syntax("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'M':
            ManPage("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'x':
            SelfDiagnostic();
            exit(0);

        default:
            Syntax("cf-execd - cfengine's execution agent", OPTIONS, HINTS, ID);
            exit(1);

        }
    }

    if (argv[optind] != NULL)
    {
        CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]);
    }

    return config;
}

/*****************************************************************************/

static void LoadDefaultSchedule(void)
{
    CfDebug("Loading default schedule...\n");
    DeleteItemList(SCHEDULE);
    SCHEDULE = NULL;
    AppendItem(&SCHEDULE, "Min00", NULL);
    AppendItem(&SCHEDULE, "Min05", NULL);
    AppendItem(&SCHEDULE, "Min10", NULL);
    AppendItem(&SCHEDULE, "Min15", NULL);
    AppendItem(&SCHEDULE, "Min20", NULL);
    AppendItem(&SCHEDULE, "Min25", NULL);
    AppendItem(&SCHEDULE, "Min30", NULL);
    AppendItem(&SCHEDULE, "Min35", NULL);
    AppendItem(&SCHEDULE, "Min40", NULL);
    AppendItem(&SCHEDULE, "Min45", NULL);
    AppendItem(&SCHEDULE, "Min50", NULL);
    AppendItem(&SCHEDULE, "Min55", NULL);
}
Exemplo n.º 7
0
static GenericAgentConfig CheckOpts(int argc, char **argv)
{
    extern char *optarg;
    int optindex = 0;
    int c;
    GenericAgentConfig config = GenericAgentDefaultConfig(cf_monitor);

    while ((c = getopt_long(argc, argv, "dvnIf:VSxHTKMFh", OPTIONS, &optindex)) != EOF)
    {
        switch ((char) c)
        {
        case 'f':
            SetInputFile(optarg);
            MINUSF = true;
            break;

        case 'd':
            HardClass("opt_debug");
            DEBUG = true;
            NO_FORK = true;
            break;

        case 'K':
            IGNORELOCK = true;
            break;

        case 'I':
            INFORM = true;
            break;

        case 'v':
            VERBOSE = true;
            NO_FORK = true;
            break;

        case 'F':
            NO_FORK = true;
            break;

        case 'H':              /* Keep accepting this option for compatibility -- no longer used */
            break;

        case 'T':
            MonNetworkSnifferEnable(true);
            break;

        case 'V':
            PrintVersionBanner("cf-monitord");
            exit(0);

        case 'h':
            Syntax("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'M':
            ManPage("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'x':
            SelfDiagnostic();
            exit(0);

        default:
            Syntax("cf-monitord - cfengine's monitoring agent", OPTIONS, HINTS, ID);
            exit(1);
        }
    }

    CfDebug("Set debugging\n");

    return config;
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
  dd_MatrixPtr M1=NULL,M2=NULL,M2row=NULL,M1plus=NULL;
  dd_colrange d1;
  dd_rowrange i,m1,m2,m1plus;
  dd_ErrorType err=dd_NoError,err1=dd_NoError,err2=dd_NoError;
  dd_rowset delset,rowset2;
  dd_Arow cvec; /* certificate */  

  time_t starttime, endtime;
  dd_DataFileType inputfile1,inputfile2;
  FILE *reading1=NULL,*reading2=NULL;

  dd_set_global_constants();  /* First, this must be called. */

  dd_WriteProgramDescription(stdout);
  fprintf(stdout,"\ncddlib test program to check redundancy of additional data.\n");
  if (argc>2){
    strcpy(inputfile1,argv[1]);
    strcpy(inputfile2,argv[2]);
  }
  /* 
  if (argc<=2){
    fprintf(stdout,"\nUsage:\n   redexter file1 file2\n");
	goto _L99;
  }
  */
  if (!SetInputFile(&reading1,argv[1])){
    fprintf(stdout,"\nSpecify file1.\n");
    dd_SetInputFile(&reading1,inputfile1, &err1);
  }
  if (!SetInputFile(&reading2,argv[2])){
    fprintf(stdout,"\nSpecify the secondary file.\n");
    dd_SetInputFile(&reading2,inputfile2, &err2);
  }
  if ((err1==dd_NoError) && (err2==dd_NoError)) {
    M1=dd_PolyFile2Matrix(reading1, &err1);
    M2=dd_PolyFile2Matrix(reading2, &err2);
  }
  else {
    fprintf(stderr,"Input file(s) not found\n");
    goto _L99;
  }

  if ((err1!=dd_NoError) || (err2!=dd_NoError)) goto _L99;

  m1=M1->rowsize;
  m2=M2->rowsize;
  set_initialize(&delset,m2);
  m1plus=m1+1;
  if (M1->representation==dd_Generator){
    d1=(M1->colsize)+1;
  } else {
    d1=M1->colsize;
  }
  dd_InitializeArow(d1,&cvec);

  fprintf(stdout, "\nThe first matrix\n");
  dd_WriteMatrix(stdout, M1);
  fprintf(stdout, "\nThe second matrix\n");
  dd_WriteMatrix(stdout, M2);
  
  printf("\nChecking whether each row of the second matrix is redundant w.r.t. the first.\n");

  time(&starttime);

  for (i=1; i<=m2; i++){
    set_initialize(&rowset2,m2);
	set_addelem(rowset2, i);
    set_compl(delset, rowset2);
    M2row=dd_MatrixSubmatrix(M2, delset);
	M1plus=dd_MatrixAppend(M1,M2row); 
	
    if (dd_Redundant(M1plus, m1plus, cvec, &err)) {
	  printf("%ld-th row: redundant\n", i);
	} else {
	  printf("%ld-th row: non-redundant\n A certificate:", i);
	  dd_WriteArow(stdout, cvec, d1);
	}

    dd_FreeMatrix(M1plus);
	dd_FreeMatrix(M2row);
    set_free(rowset2);
  }

  time(&endtime);

  dd_WriteTimes(stdout,starttime,endtime);

  set_free(delset);
  dd_FreeMatrix(M1);
  dd_FreeMatrix(M2);

_L99:;
  if (err1!=dd_NoError) dd_WriteErrorMessages(stderr,err1);
  if (err2!=dd_NoError) dd_WriteErrorMessages(stderr,err2);
  return 0;
}
Exemplo n.º 9
0
static GenericAgentConfig CheckOpts(int argc, char **argv)
{
    extern char *optarg;
    int optindex = 0;
    int c;
    GenericAgentConfig config = GenericAgentDefaultConfig(cf_know);

    LOOKUP = false;

    while ((c = getopt_long(argc, argv, "Ihbd:vVf:mxMz:St:ruT", OPTIONS, &optindex)) != EOF)
    {
        switch ((char) c)
        {
        case 'f':

            if (optarg && strlen(optarg) < 5)
            {
                FatalError(" -f used but argument \"%s\" incorrect", optarg);
            }

            SetInputFile(optarg);
            MINUSF = true;
            break;

        case 'd':
            DEBUG = true;
            break;

        case 'I':
            INFORM = true;
            break;

        case 'z':
            if (optarg)
               {
               strncpy(STORY,optarg,CF_BUFSIZE-1);
               }
            break;

        case 'b':
            WRITE_KMDB = true;
            break;

        case 'v':
            VERBOSE = true;
            break;

        case 'V':
            PrintVersionBanner("cf-know");
            exit(0);

        case 'h':
            Syntax("cf-know - cfengine's knowledge agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'M':
            ManPage("cf-know - cfengine's knowledge agent", OPTIONS, HINTS, ID);
            exit(0);

        case 'H':
            HTML = 1;
            break;

        case 'S':
            if (optarg)
            {
                SyntaxCompletion(optarg);
                exit(0);
            }
            break;

        case 'm':
            GENERATE_MANUAL = true;
            break;

        case 'x':
            GENERATE_XML = true;
            break;

        case 'o':
            OUTPUT_FILE = optarg;
            break;

        case 't':
            if (atoi(optarg))
            {
                CfGenerateTestData(atoi(optarg));
                exit(0);
            }
            break;

        case 'r':
            CfRemoveTestData();
            exit(0);

        case 'u':
            CfUpdateTestData();
            exit(0);

        case 'T':
            WORDS = true;
            break;

        default:
            Syntax("cf-know - knowledge agent", OPTIONS, HINTS, ID);
            exit(1);
        }
    }

    if (argv[optind] != NULL)
    {
        CfOut(cf_error, "", "Unexpected argument with no preceding option: %s\n", argv[optind]);
    }

    return config;
}
Exemplo n.º 10
0
int main(int argc, char *argv[])
{
  dd_MatrixPtr M=NULL,M1=NULL,M2=NULL;
  dd_colrange j,s,d;
  dd_ErrorType err=dd_NoError;
  dd_rowset redset,impl_linset;
  dd_rowindex newpos;
  mytype val;
  dd_DataFileType inputfile;
  FILE *reading=NULL;

  dd_set_global_constants();  /* First, this must be called. */

  dd_init(val);
  if (argc>1) strcpy(inputfile,argv[1]);
  if (argc<=1 || !SetInputFile(&reading,argv[1])){
    dd_WriteProgramDescription(stdout);
    fprintf(stdout,"\ncddlib test program to apply Fourier's Elimination to an H-polyhedron.\n");
    dd_SetInputFile(&reading,inputfile, &err);
  }
  if (err==dd_NoError) {
    M=dd_PolyFile2Matrix(reading, &err);
  }
  else {
    fprintf(stderr,"Input file not found\n");
    goto _L99;
  }

  if (err!=dd_NoError) goto _L99;

  d=M->colsize;
  M2=dd_CopyMatrix(M);

  printf("How many variables to elminate? (max %ld): ",d-1);
  scanf("%ld",&s);
  
  if (s>0 && s < d){
    for (j=1; j<=s; j++){
      M1=dd_FourierElimination(M2, &err);
      printf("\nRemove the variable %ld.  The resulting redundant system.\n",d-j);
      dd_WriteMatrix(stdout, M1);

      dd_MatrixCanonicalize(&M1, &impl_linset, &redset, &newpos, &err);
      if (err!=dd_NoError) goto _L99;

      fprintf(stdout, "\nRedundant rows: ");
      set_fwrite(stdout, redset);

      dd_FreeMatrix(M2);
      M2=M1;
      set_free(redset);
      set_free(impl_linset);
      free(newpos);
    }

    printf("\nNonredundant representation:\n");
    dd_WriteMatrix(stdout, M1);
  } else {
    printf("Value out of range\n");
  }

  dd_FreeMatrix(M);
  dd_FreeMatrix(M1);
  dd_clear(val);

_L99:;
  /* if (err!=dd_NoError) dd_WriteErrorMessages(stderr,err); */
  dd_free_global_constants();  /* At the end, this should be called. */
  return 0;
}