Exemplo n.º 1
0
static void _processArgs(int argc, char *argv[]) {
    int i;

    /* HERE on the ones that use the next arg make sure it is there */
    for(i = 1 ; i < argc ; i++) {
        if(!strcmp(argv[i], "-f")) {
            gFileStem = argv[i+1];
            /* ignore the next argument */
            i++;
        } else if(!strcmp(argv[i], "-args")) {
            gArgs = argv[i+1];
            /* ignore the next argument */
            i++;
        } else if(!strcmp(argv[i], "-v")) {
            gMessageLevel++;
        } else if(!strcmp(argv[i], "-noPrune")) {
            gPrune = 0;
        } else if(!strcmp(argv[i], "-noTest")) {
            gTest = "";
        } else if(!strcmp(argv[i], "-h")) {
            _printUsage(argv[0]);
            exit(0);
        } else {
            printf("Unknown argument: %s.  use -h for help\n", argv[i]);
            exit(0);
        }
    }

    if(gMessageLevel >= 1) {
        printf("Stem: %s\n", gFileStem);
    }
}
Exemplo n.º 2
0
int _tmain(int argc, _TCHAR* argv[])
{
	_printCopyright();
	if(argc<5)
	{
		_printUsage();
		return 0;
	}

	g_strSourceFile = argv[1];
	g_strTargetFile = argv[2];
	g_nFileSize = atoi(argv[3]);
	bool horz = atoi(argv[4])!=0;

	CBitmapFile bmpFile;
	if(!bmpFile.openFromFile(g_strSourceFile.c_str()))
	{
		return 0;
	}

	printf("Open source file: %s OK!\n", g_strSourceFile.c_str());

	if(!bmpFile.splitToFile(g_strTargetFile.c_str(), g_nFileSize, horz))
	{
		return 0;
	}

	printf("Cut OK!\n");

	return 0;
}
Exemplo n.º 3
0
static void _processArgs(int argc, char *argv[]) {
   int i;

   /* HERE on the ones that use the next arg make sure it is there */
   for(i = 1 ; i < argc ; i++) {
      if(!strcmp(argv[i], "-f")) {
         gFileStem = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-fout")) {
         gOutputStem = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-target")) {
         gTargetDirectory = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-source")) {
         gSourceDirectory = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-sample")) {
         sscanf(argv[i+1], "%f", &gSamplePercent);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-v")) {
         gMessageLevel++;
      } else if(!strcmp(argv[i], "-stdin")) {
         gStdin = 1;
      } else if(!strcmp(argv[i], "-stdout")) {
         gStdout = 1;
      } else if(!strcmp(argv[i], "-outputTest")) {
         gOutputTest = 1;
      } else if(!strcmp(argv[i], "-seed")) {
         sscanf(argv[i+1], "%ld", &gSeed);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-h")) {
         _printUsage(argv[0]);
         exit(0);
      } else {
         printf("Unknown argument: %s.  use -h for help\n", argv[i]);
         exit(0);
      }
   }

   if(gMessageLevel >= 1) {
      printf("File stem: %s\n", gFileStem);
      printf("Target: %s\n", gTargetDirectory);
      printf("Source: %s\n", gSourceDirectory);
      printf("Sample Percentage: %.5f\n", gSamplePercent);
      printf("Seed: %ld\n", gSeed);
   }
}
Exemplo n.º 4
0
static void _processArgs(int argc, char *argv[], BNLearnParams *params) {
   int i;
   int cacheTrainSet=1;
   char filename[2000];
   ExampleSpecPtr es;
   char *sourceDirectory=".", *fileStem="DF";
   char *inputNetFilename=NULL;
   int useStdin=0;
   FILE *in;

   /* HERE on the ones that use the next arg make sure it is there */
   for(i = 1 ; i < argc ; i++) {
      if(!strcmp(argv[i], "-f")) {
         fileStem = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-startFrom")) {
         inputNetFilename = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-outputTo")) {
         params->gOutputNetFilename = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-source")) {
         sourceDirectory = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-v")) {
         DebugSetMessageLevel(DebugGetMessageLevel() + 1);
      } else if(!strcmp(argv[i], "-h")) {
         _printUsage(argv[0]);
         exit(0);
      } else if(!strcmp(argv[i], "-kappa")) {
         sscanf(argv[i+1], "%lf", &params->gKappa);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-limitMegs")) {
         sscanf(argv[i+1], "%ld", &params->gLimitBytes);
         params->gLimitBytes *= 1024 * 1024;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-limitMinutes")) {
         sscanf(argv[i+1], "%lf", &params->gLimitSeconds);
         params->gLimitSeconds *= 60;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxSearchSteps")) {
         sscanf(argv[i+1], "%d", &params->gMaxSearchSteps);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxParentsPerNode")) {
         sscanf(argv[i+1], "%d", &params->gMaxParentsPerNode);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxParameterGrowthMult")) {
         sscanf(argv[i+1], "%d", &params->gMaxParameterGrowthMult);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxParameterCount")) {
         sscanf(argv[i+1], "%ld", &params->gMaxParameterCount);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-noCacheTrainSet")) {
         cacheTrainSet=0;
      } else if(!strcmp(argv[i], "-stdin")) {
         sleep(2);
         useStdin=1;
      } else if(!strcmp(argv[i], "-parametersOnly")) {
         params->gOnlyEstimateParameters = 1;
      } else if(!strcmp(argv[i], "-noReverse")) {
         params->gNoReverse = 1;
      } else if(!strcmp(argv[i], "-seed")) {
         sscanf(argv[i+1], "%d", &params->gSeed);
         /* ignore the next argument */
         i++;
      } else {
         printf("Unknown argument: %s.  use -h for help\n", argv[i]);
         exit(0);
      }
   }

   // Verify params
   if(useStdin && (cacheTrainSet == 0)) {
      DebugError(1, "Can not use -stdin with -noCacheTrainSet\n");
   }
   // Set up the input data
   sprintf(filename, "%s/%s.names", sourceDirectory, fileStem);
   es = ExampleSpecRead(filename);
   DebugError(es == 0, "Unable to open the .names file");

   sprintf(filename, "%s/%s.data", sourceDirectory, fileStem);
   in = fopen(filename, "r");
   DebugError(in == 0, "Unable to open the .data file");

   if (cacheTrainSet) {
      params->gDataMemory = ExamplesRead(in,es);
      DebugError(!params->gDataMemory, "Unable to read the .data file");
   }
   else {
      params->gDataFile = in;
   }
   DebugMessage(1, 1, "Stem: %s\n", fileStem);
   DebugMessage(1, 1, "Source: %s\n", sourceDirectory);
   DebugMessage(useStdin, 1, "Reading examples from standard in.\n");

   // Set up the input network
   if (inputNetFilename) {
      params->gInputNetFile = fopen(inputNetFilename, "r");
      DebugError(!params->gInputNetFile, "Unable to reading input network");
   }
   else {
      params->gInputNetEmptySpec = es;
   }

}
Exemplo n.º 5
0
int main(int argc, char** argv)
{
    int rc;
    struct ketty* ketty;
    struct ketty_logger* logger;
    struct _options opts = { .port = 8888 };

    signal(SIGINT, _exitHandler);

    rc = _readOpts(argc, argv, &opts);
    if (rc != 0) {
        _printUsage();
        exit(EXIT_FAILURE);
    }

    logger = ketty_default_logger_new();
    if (logger == NULL) {
        fprintf(stderr, "Failed to create logger\n");
        goto error;
    }
    ketty_set_logger(logger);

    ketty = ketty_new();
    if (ketty == NULL) {
        fprintf(stderr, "Failed to allocate memory for ketty\n");
        goto error;
    }

    ketty_set_document_root(ketty, opts.root);
    if (ketty_start(ketty, opts.port) != 0) goto error;

    _keepRunning = 1;
    while (_keepRunning == 1) sleep(1);

    ketty_stop(ketty);

error:
    if (ketty != NULL) ketty_free(ketty);
    if (logger != NULL) ketty_default_logger_free(logger);

    return 0;
}

static int _readOpts(int argc, char** argv, struct _options* opts)
{
    int c;
    int rc = 0;

    do {
        if ((c = getopt(argc, argv, "p:r:")) == -1) break;

        switch(c) {
        case 'p': // which port to listen
            opts->port = atoi(optarg);
            rc = 0;
            break;
        case 'r': // which port to listen
            opts->root = optarg;
            rc = 0;
            break;
        default:
            rc = 1;
            break;
        }
    } while (rc == 0);

    if (opts->port < 1 || opts->port > 65535) return -1;
    if (opts->root == NULL) return -1;

    return rc;
}
Exemplo n.º 6
0
static void _processArgs(int argc, char *argv[]) {
   int i;

   /* the last argument is the command to run */

   /* HERE on the ones that use the next arg make sure it is there */
   for(i = 1 ; i < argc ; i++) {
      if(!strcmp(argv[i], "-f")) {
         gFileStem = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-source")) {
         gSourceDirectory = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-c")) {
         gCommand = argv[i+1];
         gGotCommand = 1;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-shuffle")) {
         printf("-shuffle is not supported yet\n");
         exit(0);
         gShuffleData = 1;
      } else if(!strcmp(argv[i], "-fc45")) {
         printf("learner output formats are not supported yet\n");
         exit(0);
         gc45Format = 1;
         gvfdtFormat = 0;
      } else if(!strcmp(argv[i], "-fvfdt")) {
         printf("learner output formats are not supported yet\n");
         exit(0);
         gc45Format = 0;
         gvfdtFormat = 1;
      } else if(!strcmp(argv[i], "-table")) {
         gTableOutput = 1;
      } else if(!strcmp(argv[i], "-v")) {
         gMessageLevel++;
      } else if(!strcmp(argv[i], "-folds")) {
         sscanf(argv[i+1], "%d", &gFoldCount);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-seed")) {
         sscanf(argv[i+1], "%d", &gSeed);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-h")) {
         _printUsage(argv[0]);
         exit(0);
      } else {
         printf("Unknown argument: %s.  use -h for help\n", argv[i]);
         exit(0);
      }
   }

   if(!gGotCommand) {
      printf("*** Didn't get the required -c option\n");
      _printUsage(argv[0]);
      exit(0);
   }

   if(gMessageLevel >= 1) {
      printf("Stem: %s\n", gFileStem);
      printf("Source: %s\n", gSourceDirectory);
      printf("Command %s\n", gCommand);
      printf("folds %d\n", gFoldCount);
      printf("seed %d\n", gSeed);
   }
}
Exemplo n.º 7
0
Arquivo: vfbn2.c Projeto: burnmg/vfml
static void _processArgs(int argc, char *argv[]) {
   int i;

   /* HERE on the ones that use the next arg make sure it is there */
   for(i = 1 ; i < argc ; i++) {
      if(!strcmp(argv[i], "-f")) {
         gFileStem = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-startFrom")) {
         gStartingNetFile = argv[i+1];
         gUseStartingNet = 1;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-outputTo")) {
         gNetOutput = argv[i+1];
         gOutputNet = 1;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-source")) {
         gSourceDirectory = argv[i+1];
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-v")) {
         DebugSetMessageLevel(DebugGetMessageLevel() + 1);
      } else if(!strcmp(argv[i], "-h")) {
         _printUsage(argv[0]);
         exit(0);
      } else if(!strcmp(argv[i], "-delta")) {
         sscanf(argv[i+1], "%f", &gDelta);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-tau")) {
         sscanf(argv[i+1], "%f", &gTau);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-chunk")) {
         sscanf(argv[i+1], "%d", &gChunk);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-limitMegs")) {
         sscanf(argv[i+1], "%ld", &gLimitBytes);
         gLimitBytes *= 1024 * 1024;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-limitMinutes")) {
         sscanf(argv[i+1], "%lf", &gLimitSeconds);
         gLimitSeconds *= 60;
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxSearchSteps")) {
         sscanf(argv[i+1], "%d", &gMaxSearchSteps);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxParentsPerNode")) {
         sscanf(argv[i+1], "%d", &gMaxParentsPerNode);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-maxParameterCount")) {
         sscanf(argv[i+1], "%ld", &gMaxParameterCount);
         /* ignore the next argument */
         i++;
      } else if(!strcmp(argv[i], "-stdin")) {
         sleep(2);
         gStdin = 1;
      } else if(!strcmp(argv[i], "-noRemove")) {
         gAllowRemove = 0;
      } else if(!strcmp(argv[i], "-inStep")) {
         gInStep = 1;
      } else if(!strcmp(argv[i], "-seed")) {
         sscanf(argv[i+1], "%d", &gSeed);
         /* ignore the next argument */
         i++;
      } else {
         printf("Unknown argument: %s.  use -h for help\n", argv[i]);
         exit(0);
      }
   }

   DebugMessage(1, 1, "Stem: %s\n", gFileStem);
   DebugMessage(1, 1, "Source: %s\n", gSourceDirectory);
   DebugMessage(1, 1, "Delta: %.13f\n", gDelta);
   DebugMessage(1, 1, "Tau: %f\n", gTau);

   DebugMessage(gStdin, 1, "Reading examples from standard in.\n");
   DebugMessage(1, 1, 
             "Gather %d examples before checking for winner\n", gChunk);
}