void
main_config()
{
	bool done_allocating;

		// Reread config file for global settings.
	init_params(0);
		// Process any changes in the slot type specifications
	done_allocating = resmgr->reconfig_resources();
	if( done_allocating ) {
		finish_main_config();
	}
}
Exemple #2
0
int main(int argc, char *argv[])
{
    int ret;
    
    init_params(argc, argv);
    alloc_block_buf();

    ret = op_testpattern(argv[2], !strcmp(argv[1], "write"));
    
    free_block_buf();

    return ret;
}
Exemple #3
0
/*
 * Routine: set_int(int var, char *value)
 * Purpose: set an integer parameter
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By: 
 * Calls: 
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
void 
set_int(char *var, char *val)
{
	int nParam;

	init_params();
	nParam = fnd_param(var);
	if (nParam >= 0)
	{
		strcpy(params[options[nParam].index], val);
		options[nParam].flags |= OPT_SET;
	}
	return;
}
Exemple #4
0
int kf_main(int argc, char* argv[])
{
	ros::init(argc, argv, "kf");
	ros::NodeHandle n;
	ros::NodeHandle private_nh("~");

	image_objects = n.advertise<cv_tracker::image_obj_tracked>("image_obj_tracked", 1);

	cv::generateColors(_colors, 25);

	std::string image_topic;
	std::string obj_topic;
	if (private_nh.getParam("image_node", image_topic))
    	{
        	ROS_INFO("Setting image node to %s", image_topic.c_str());
    	}
	else
	{
		ROS_INFO("No image node received, defaulting to image_raw, you can use _image_node:=YOUR_TOPIC");
		image_topic = "/image_raw";
	}
	if (private_nh.getParam("object_node", image_topic))
    	{
        	ROS_INFO("Setting object node to %s", image_topic.c_str());
    	}
	else
	{
		ROS_INFO("No object node received, defaulting to image_obj_ranged, you can use _object_node:=YOUR_TOPIC");
		obj_topic = "image_obj_ranged";
	}

	init_params();

	ros::Subscriber sub_image = n.subscribe(image_topic, 1, image_callback);
	ros::Subscriber sub_dpm = n.subscribe(obj_topic, 1, detections_callback);


	std::string config_topic("/config");
	config_topic += ros::this_node::getNamespace() + "/kf";
	ros::Subscriber config_subscriber = n.subscribe(config_topic, 1, kf_config_cb);

	//TimeSynchronizer<Image, dpm::ImageObjects> sync(image_sub, pos_sub, 10);

	//sync.registerCallback(boost::bind(&sync_callback, _1, _2));
	track_ready_ = false;
	detect_ready_ = false;

	ros::spin();
	return 0;
}
Exemple #5
0
/* ////////////////////////////////////////////////////////////////////////// */
int
main(void)
{
    int rc = FAILURE;
    int erc = EXIT_FAILURE;
    simulation_params_t *params = NULL;
    simulation_t *sim = NULL;

    /* print application banner */
    printf("o %s %s\n", app_name, app_ver);

    if (SUCCESS != (rc = params_construct(&params))) {
        fprintf(stderr, "params_construct failure @ %s:%d: rc = %d\n", __FILE__,
                __LINE__, rc);
        goto cleanup;
    }
    if (SUCCESS != (rc = init_params(params, N, THERM_COND, T_MAX))) {
        fprintf(stderr, "init_params failure @ %s:%d: rc = %d\n", __FILE__,
                __LINE__, rc);
        goto cleanup;
    }
    if (SUCCESS != (rc = simulation_construct(&sim, params))) {
        fprintf(stderr, "simulation_construct failure @ %s:%d: rc = %d\n",
                __FILE__, __LINE__, rc);
        goto cleanup;
    }
    if (SUCCESS != (rc = set_initial_conds(sim->old_mesh))) {
        fprintf(stderr, "set_initial_conds failure @ %s:%d: rc = %d\n",
                __FILE__, __LINE__, rc);
        goto cleanup;
    }
    if (SUCCESS != (rc = run_simulation(sim))) {
        fprintf(stderr, "run_simulation failure @ %s:%d: rc = %d\n",
                __FILE__, __LINE__, rc);
        goto cleanup;
    }
    if (SUCCESS != dump(sim)) {
        fprintf(stderr, "dump failure @ %s:%d: rc = %d\n",
                __FILE__, __LINE__, rc);
        goto cleanup;
    }
    /* all is well */
    erc = EXIT_SUCCESS;

cleanup:
    (void)simulation_destruct(sim);
    (void)params_destruct(params);
    return erc;
}
Exemple #6
0
void init_once(void)
{
	// Required for QuRT
	//_posix_init();

//	_shell_task_id = pthread_self();
//	PX4_INFO("Shell id is %lu", _shell_task_id);

	work_queues_init();
	hrt_work_queue_init();
	hrt_init();

	/* Shared memory param sync*/
	init_params();
}
Exemple #7
0
/*
 * Routine: set_str(int var, char *value)
 * Purpose: set a character parameter
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By: 
 * Calls: 
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
void 
set_str(char *var, char *val)
{
	int nParam;
	
	init_params();
	nParam = fnd_param(var);
	if (nParam >= 0)
	{
		strncpy(params[options[nParam].index], val, PARAM_MAX_LEN);
		options[nParam].flags |= OPT_SET;
	}


	return;
}
Exemple #8
0
void SetupParams(int argc, char **argv) {
	char fname[STRLEN];

	init_params(argc, argv);

	// PARAMETER DEFINITIONS GO HERE
	STRING_PARAM(FileBase);
	INT_PARAM(ElecNo);
	INT_PARAM(MinClusters);
	INT_PARAM(MaxClusters);
	INT_PARAM(MaxPossibleClusters);
	INT_PARAM(nStarts);
	INT_PARAM(RandomSeed);
	BOOLEAN_PARAM(Debug);
	INT_PARAM(Verbose);
	STRING_PARAM(UseFeatures);
	INT_PARAM(DistDump);
	FLOAT_PARAM(DistThresh);
	INT_PARAM(FullStepEvery);
	FLOAT_PARAM(ChangedThresh);
	BOOLEAN_PARAM(Log);
	BOOLEAN_PARAM(Screen);
	INT_PARAM(MaxIter);
	STRING_PARAM(StartCluFile);
	INT_PARAM(SplitEvery);
	FLOAT_PARAM(PenaltyMix);
	INT_PARAM(Subset);
	
	if (argc<3) {
		fprintf(stderr, "Usage: KlustaKwik FileBase ElecNo [Arguments]\n\n");
		fprintf(stderr, "Default Parameters: \n");
		print_params(stderr);
		exit(1);
	}

	strcpy(FileBase, argv[1]);
	ElecNo = atoi(argv[2]);

	if (Screen) print_params(stdout);
	
	// open log file, if required
	if (Log) {
		sprintf(fname, "%s.klg.%d", FileBase, ElecNo);
		logfp = fopen_safe(fname, "w");
		print_params(logfp);
	}
}
Exemple #9
0
/*
 * Routine: save_file(char *path)
 * Purpose: print a summary of options
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By: 
 * Calls: 
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
int
save_file(char *path)
{
	int i,
	w_adjust;
	FILE *ofp;
	time_t timestamp;

	init_params();
	time(&timestamp);
	
	if ((ofp = fopen(path, "w")) == NULL)
		return(-1);

	fprintf(ofp, "--\n-- %s Benchmark Parameter File\n-- Created: %s",
		get_str("PROG"), ctime(&timestamp));
	fprintf(ofp, "--\n-- Each entry is of the form: '<parameter> = <value> -- optional comment'\n");
	fprintf(ofp, "-- Refer to benchmark documentation for more details\n--\n");
	
	for (i=0; options[i].name != NULL; i++)
	{
		if (options[i].flags & OPT_HIDE)		/* hidden option */
			continue;
		if (strlen(params[options[i].index]) == 0)
			continue;

		fprintf(ofp, "%s = ", options[i].name);
		w_adjust = strlen(options[i].name) + 3;
		if (options[i].flags & OPT_STR)
		{
			fprintf(ofp, "\"%s\"", params[options[i].index]);
			w_adjust += 2;
		}
		else
			fprintf(ofp, "%s", params[options[i].index]);
		w_adjust += strlen(params[options[i].index]) + 3;
		w_adjust = 60 - w_adjust;
		fprintf(ofp, "%*s-- %s", w_adjust, " ", options[i].usage);
		if (options[i].flags & OPT_NOP)
			fprintf(ofp, " NOT IMPLEMENTED");
		fprintf(ofp, "\n");
	}

	fclose(ofp);

	return(0);
}
Exemple #10
0
void
Echotron::loaddefault()
{
    Plength = 1;
    fPan[0] = 0.0f;  //
    fTime[0] = 1.0f;  //default 1 measure delay
    fLevel[0] = 0.7f;
    fLP[0] = 1.0f;
    fBP[0] = -1.0f;
    fHP[0] = 1.0f;
    fFreq[0]=800.0f;;
    fQ[0]=2.0f;
    iStages[0]=1;
    subdiv_dmod = 1.0f;
    subdiv_fmod = 1.0f;
    init_params();
}
Exemple #11
0
/*
 * Routine: is_set(int f)
 * Purpose: return the state of a toggle parameter, or whether or not a string or int parameter
 *          has been set
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By: 
 * Calls: 
 * Assumptions:
 * Side Effects:
 * TODO: None
 */
int
is_set(char *flag)
{
   int nParam,
      bIsSet = 0;
   
   init_params();
   nParam = fnd_param(flag);
   if (nParam >= 0)
   {
      if ((options[nParam].flags & TYPE_MASK) == OPT_FLG)
         bIsSet = (params[options[nParam].index][0] == 'Y')?1:0;
      else
         bIsSet = (options[nParam].flags & OPT_SET) || (strlen(options[nParam].dflt) > 0);
   }
   
   return(bIsSet );	/* better a false negative than a false positive ? */
}
Exemple #12
0
int main(int argc, char** argv) {
	// handle parameters
	po::variables_map cfg;
	if (!init_params(argc,argv, &cfg)) exit(1);
	ReadFile in(cfg["input"].as<string>());
	WriteFile out(cfg["output"].as<string>());
	cerr << "CREATE-INDEX::Reading input from " << cfg["input"].as<string>() << endl;
	cerr << "CREATE-INDEX::Writing index to   " << cfg["output"].as<string>() << endl;
	if (cfg.count("text-input")) cerr << "CREATE-INDEX::Textual input from " << cfg["input"].as<string>() << endl;
	if (cfg.count("stopwords")) {
		sw::loadStopwords(cfg["stopwords"].as<string>());
		cerr << "CREATE-INDEX::" << sw::stopwordCount() << " stopwords loaded from '" << cfg["stopwords"].as<string>() << "'\n";
	}
	istream *ins = in.stream();
	ostream *outs = out.stream();
	assert(*ins);
	assert(*outs);
	Index::Index idx;
	string line;
	unsigned c=0;
	const bool is_text = cfg.count("text-input");
	const bool swf = cfg.count("stopwords");
	cerr << "CREATE-INDEX::Parsing documents.";
	while (getline(*ins, line)) {
		if (line.empty()) continue;
		CLIR::Document d(line, !is_text);
		if (is_text) d.computeTfVector(swf);
		if (!d.parsed_ || d.v_.empty())
			cerr << "CREATE-INDEX::WARNING: input vector (id=" << TD::Convert(d.id_) << ",len=" << d.len_ << ") empty!" << endl;
		else
			idx.AddDocument(d);
		if (c%10000==0) cerr << "." << c << ".";
		c++;
	}
	cerr << endl;
	cerr.flush();
	idx.ComputeAverageDocumentLength();
	idx.SortPostingsLists();
	cerr << "CREATE-INDEX::" << idx << endl;
	cerr << "CREATE-INDEX::Saving Index\n";
	idx.Save(*outs);
	cerr << "CREATE-INDEX::Done.\n";
	return 0;
}
Exemple #13
0
static int __init sscape_manual_probe(struct params *params)
{
	int ret;
	unsigned i;
	snd_card_t *card;

	for (i = 0; i < SNDRV_CARDS; ++i) {
		/*
		 * We do NOT probe for ports.
		 * If we're not given a port number for this
		 * card then we completely ignore this line
		 * of parameters.
		 */
		if (port[i] == SNDRV_AUTO_PORT)
			continue;

		/*
		 * Make sure we were given ALL of the other parameters.
		 */
		if ( (irq[i] == SNDRV_AUTO_IRQ) ||
		     (mpu_irq[i] == SNDRV_AUTO_IRQ) ||
		     (dma[i] == SNDRV_AUTO_DMA) ) {
			printk(KERN_INFO
			       "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n");
			return -ENXIO;
		}

		/*
		 * This cards looks OK ...
		 */
		init_params(params, index[i], id[i], port[i], irq[i], mpu_irq[i], dma[i]);

		ret = create_sscape(params, &card);
		if (ret < 0)
			return ret;

		sscape_card[sscape_cards] = card;
		params++;
		sscape_cards++;
	} /* for */

	return 0;
}
Exemple #14
0
SECStatus
ectest_validate_point(ECDH_BAD *bad)
{
    ECParams ecParams = { 0 };
    SECItem point = { siBuffer, NULL, 0 };
    SECStatus rv = SECFailure;
    PLArenaPool *arena = NULL;

    rv = init_params(&ecParams, bad->curve, &arena, bad->fieldType);
    if (rv != SECSuccess) {
        return rv;
    }

    SECU_HexString2SECItem(arena, &point, bad->point);
    rv = EC_ValidatePublicKey(&ecParams, &point);

    PORT_FreeArena(arena, PR_FALSE);
    return rv;
}
Exemple #15
0
int main(int argc, char** argv) {
    //destroy_params();
    argc--; argv++;
    flags = 0;
    if (argc > 0) {
        readParams(argc, argv);
    }
    init_params(cam);
    train();
    if ((flags & P_TREE) != 0) {
        printTree(ptree->get_root());
        printf("\n\n");
    }
    if ((flags & F_CHK) != 0)
        runTest();
    predict();
    destroy_params();
    return (EXIT_SUCCESS);
}
main()
{
	int i_res;
	char *c_res;
	decimal_t dec_res;
	
	init_params();
	
	dist_member(&i_res, "test_dist", 1, 1);
	if (i_res != 10)
	{
		printf("dist_member(\"test_dist\", 1, 1): %d != 10\n", i_res);
		exit(1);
	}
	dist_member(&i_res, "test_dist", 1, 2);
	if (i_res != 60)
	{
		printf("dist_member(\"test_dist\", 1, 2): %d != 60\n", i_res);
		exit(1);
	}
	dist_member((void *)&c_res, "test_dist", 1, 3);
	if (strcmp(c_res, "El Camino"))
	{
		printf("dist_member(\"test_dist\", 1, 3): %s != El Camino\n", 
			c_res);
		exit(1);
	}
	dist_member((void *)&dec_res, "test_dist", 1, 4);
	if (strcmp(dec_res.number, "1") || strcmp(dec_res.fraction, "23"))
	{
		printf("dist_member(\"test_dist\", 1, 4): %s.%s != 1.23\n",
			dec_res.number, dec_res.fraction);
		exit(1);
	}
	dist_weight(&i_res, "test_dist", 2, 2);
	if (3 != i_res)
	{
		printf("dist_weight(\"test_dist\", 2, 2): %d != 3\n", i_res);
		exit(1);
	}
}
Exemple #17
0
/* fdp_tLayout:
 * Given graph g with ports nodes, layout g respecting ports.
 * If some node have position information, it may be useful to
 * reset temperature and other parameters to reflect this.
 */
void
fdp_tLayout (graph_t* g, xparams* xpms)
{
  int       i;
  int       reset;
  bport_t*  pp = PORTS(g);
  double    temp;
  Grid*     grid;
  pointf    ctr;
  Agnode_t* n;

  reset = init_params(g, xpms);
  temp = T0;

  ctr = initPositions (g, pp);
  
  if (T_useGrid) {
    grid = mkGrid (agnnodes (g));
    adjustGrid (grid, agnnodes (g));
    for (i = 0; i < loopcnt; i++) {
      temp = cool (temp, i);
      gAdjust (g, temp, pp, grid);
    }
    delGrid (grid);
  }
  else {
    for (i = 0; i < loopcnt; i++) {
      temp = cool (temp, i);
      adjust (g, temp, pp);
    }
  }

  if ((ctr.x != 0.0) || (ctr.y != 0.0)) {
    for (n = agfstnode(g); n; n = agnxtnode(g,n)) {
      ND_pos(n)[0] += ctr.x;
      ND_pos(n)[1] += ctr.y;
    }
  }
dumpstat (g);
  if (reset) reset_params ();
}
Exemple #18
0
t_params*	create_params(char** av, int ac)
{
  t_params* params;
  int	i;

  if ((params = malloc(sizeof(t_params))) == NULL)
    return NULL;
  init_params(params);
  i = 1;
  while (i < ac)
  {
    if (av[i][0] == '-')
      handle_param(params, av, i);
    else if (!params->file)
      params->file = strdup(av[i]);
    ++i;
  }
  if (!params->file)
    params->file = strdup("typescript");
  return params;
}
Exemple #19
0
int
main(int argc, char **argv)
{
    double *mins;
    double *maxs;
    double out;
    double min=0.0, max=0.0;
    size_t pop_count = POP_COUNT, max_gen = MAX_GEN;
    size_t i = 0, dimension = 2;
    size_t nffa = 0, nffasa = 0;

    init_params(argc, argv, &pop_count, &max_gen, &dimension, &min, &max);

    //this should change to be some parameter soon...
    obj_func func = &dejung;

    mins = (double*)calloc(dimension, sizeof(double));
    maxs = (double*)calloc(dimension, sizeof(double));

    for (i=0; i < dimension; i++)
    {
        mins[i] = min;
        maxs[i] = max;
    }

    //initialize our PRNG
    srand48(time(NULL));
    
    nffa = test_ffa(pop_count, dimension, mins, maxs, func, &out);
    printf("FF Algo did %ld evaluations, min = %.5lf\n", nffa, out);

    nffasa = test_ffasa(pop_count, dimension, mins, maxs, func, &out);
    printf("Hybrid FF Algo did %ld evaluations, min = %.5lf\n", nffasa, out);

    free(mins);
    free(maxs);

    return EXIT_SUCCESS;
};
/**
 * Read the command line parameters
 */
int read_params(s_parameters *params, int argc, char *argv[]) {
	init_params(params);
	int c;
	opterr = 0;
	while ((c = getopt(argc, argv, "m:yb:vo:")) != -1) {
		switch (c) {
		case 'm':
			params->max_messages = atoi(optarg);
			break;
		case 'y':
			params->serial = 1;
			break;
		case 'b':
			params->baudrate = atoi(optarg);
			break;
		case 'v':
			params->verbose = 1;
			break;
		case 'o':
			params->output = optarg;
			break;
		case '?':
			if(optopt == 'm' || optopt == 'b' || optopt == 'o')
			{
				fprintf(stderr, "Option -%c requires an argument.\n", optopt);
			}
			if (isprint(optopt)) {
				fprintf(stderr, "Unknown option '-%c'.\n", optopt);
			} else {
				fprintf(stderr, "Unknown option character '\\x%x'.\n", optopt);
			}
			return -1;
			break;
		default:
			return -1;
		}
	}
	return 0;
}
Exemple #21
0
static int ffmpeg_mux_init_internal(struct ffmpeg_mux *ffm, int argc,
		char *argv[])
{
	argc--;
	argv++;
	if (!init_params(&argc, &argv, &ffm->params, &ffm->audio))
		return FFM_ERROR;

	if (ffm->params.tracks) {
		ffm->audio_header =
			calloc(1, sizeof(struct header) * ffm->params.tracks);
	}

	av_register_all();

	if (!ffmpeg_mux_get_extra_data(ffm))
		return FFM_ERROR;

	/* ffmpeg does not have a way of telling what's supported
	 * for a given output format, so we try each possibility */
	return ffmpeg_mux_init_context(ffm);
}
Exemple #22
0
/*
 * Routine: process_options(int count, char **vector)
 * Purpose:  process a set of command line options
 * Algorithm:
 * Data Structures:
 *
 * Params:
 * Returns:
 * Called By: 
 * Calls: 
 * Assumptions:
 * Side Effects:
 * TODO: 20000309 need to return integer to allow processing of left-over args
 */
int
process_options (int count, char **vector)
{
	int option_num = 1,
	res = 1;

	init_params();

	while (option_num < count)
	{
		if (*vector[option_num] == OPTION_START)
		{
			if (option_num == (count - 1))
				res = set_option(vector[option_num] + 1, NULL);
			else
				res = set_option(vector[option_num] + 1, 
				    vector[option_num + 1]);
		}

		if (res < 0)
		{
			printf ("ERROR: option '%s' or its argument unknown.\n", 
			    (vector[option_num] + 1));
			usage (NULL, NULL);
			exit (1);
		}
		else
			option_num += res;
	}

#ifdef JMS
	if (is_set("VERBOSE"))
		print_params();
#endif

	return(option_num);
}
  System::System (int& argc, char**& argv)
      : m_impl(new Impl)
  {
      visual_log (VISUAL_LOG_INFO, "Starting Libvisual %s", get_version ().c_str ());

#if ENABLE_NLS
      bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
      bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif

      __lv_progname = visual_strdup (argv[0]);

      /* Initialize CPU caps */
      visual_cpu_initialize ();

      /* Initialize Mem system */
      visual_mem_initialize ();

      /* Initialize CPU-accelerated graphics functions */
      visual_alpha_blend_initialize ();

      /* Initialize high-resolution timer system */
	  Time::init ();

      /* Initialize Thread system */
      visual_thread_initialize ();

      /* Initialize FFT system */
      Fourier::init ();

      /* Initialize the plugin registry */
      PluginRegistry::init ();

      m_impl->params = visual_param_container_new ();
      init_params (m_impl->params);
  }
Exemple #24
0
/**
 * parses a "pipe_no:algorithm:bandwidth" line
 * \return      0 on success
 */
static int parse_pipe_params(char * line, pipe_params_t * params)
{
	regmatch_t m[4];
	str algo_str;

	if (! params_inited && init_params())
		return -1;
	if (regexec(&pipe_params_regex, line, 4, m, 0)) {
		LM_ERR("invalid param tuple: %s\n", line);
		return -1;
	}
	LM_DBG("pipe: [%.*s|%.*s|%.*s]\n",
		RXLS(m, line, 1), RXLS(m, line, 2), RXLS(m, line, 3));
	
	params->no = atoi(RXS(m, line, 1));
	params->limit = atoi(RXS(m, line, 3));

	algo_str.s   = RXS(m, line, 2);
	algo_str.len = RXL(m, line, 2);
	if (str_map_str(algo_names, &algo_str, &params->algo))
		return -1;

	return 0;
}
void mexFunction(int nout, mxArray *pout[], int nin, const mxArray *pin[]) {
  FILE *f = fopen("log.txt", "wt");
  fclose(f);

  if (nin < 2) { mexErrMsgTxt("nnmex called with < 2 input arguments"); }

  const mxArray *A = pin[0], *B = pin[1];
  const mxArray *ANN_PREV = NULL, *ANN_WINDOW = NULL, *AWINSIZE = NULL;
  int aw = -1, ah = -1, bw = -1, bh = -1;
  BITMAP *a = NULL, *b = NULL, *ann_prev = NULL, *ann_window = NULL, *awinsize = NULL;
  VECBITMAP<unsigned char> *ab = NULL, *bb = NULL;
  VECBITMAP<float> *af = NULL, *bf = NULL;

  if (mxGetNumberOfDimensions(A) != 3 || mxGetNumberOfDimensions(B) != 3) { mexErrMsgTxt("dims != 3"); }
  if (mxGetDimensions(A)[2] != mxGetDimensions(B)[2]) { mexErrMsgTxt("3rd dimension not same size"); }

  int mode = MODE_IMAGE;
  if (mxGetDimensions(A)[2] != 3) { // a discriptor rather than rgb
    if (mxIsUint8(A) && mxIsUint8(B)) { mode = MODE_VECB; } 
    else if (is_float(A) && is_float(B)) { mode = MODE_VECF; } 
    else { mexErrMsgTxt("input not uint8, single, or double"); }
  }

  Params *p = new Params();
  RecomposeParams *rp = new RecomposeParams();
  BITMAP *borig = NULL;
  if (mode == MODE_IMAGE) {
    a = convert_bitmap(A);
    b = convert_bitmap(B);
	borig = b;
    aw = a->w; ah = a->h;
    bw = b->w; bh = b->h;
  } 
  else if (mode == MODE_VECB) {
    ab = convert_vecbitmap<unsigned char>(A);
    bb = convert_vecbitmap<unsigned char>(B);
    if (ab->n != bb->n) { mexErrMsgTxt("3rd dimension differs"); }
    aw = ab->w; ah = ab->h;
    bw = bb->w; bh = bb->h;
    p->vec_len = ab->n;
  } 
  else if (mode == MODE_VECF) {
    af = convert_vecbitmap<float>(A);
    bf = convert_vecbitmap<float>(B);
    if (af->n != bf->n) { mexErrMsgTxt("3rd dimension differs"); }
    aw = af->w; ah = af->h;
    bw = bf->w; bh = bf->h;
    p->vec_len = af->n;
  }

  double *win_size = NULL;
  BITMAP *amask = NULL, *bmask = NULL;

  double scalemin = 0.5, scalemax = 2.0;  // The product of these must be one.
  /* parse parameters */
  int i = 2;
  int sim_mode = 0;
  int knn_chosen = -1;
  p->algo = ALGO_CPU;
  int enrich_mode = 0;
  if (nin > i && !mxIsEmpty(pin[i])) {
    if (mxStringEquals(pin[i], "cpu")) { p->algo = ALGO_CPU; }
    else if (mxStringEquals(pin[i], "gpucpu")) { p->algo = ALGO_GPUCPU; }
    else if (mxStringEquals(pin[i], "cputiled")) { p->algo = ALGO_CPUTILED; }
    else if (mxStringEquals(pin[i], "rotscale")) { sim_mode = 1; }
    else if (mxStringEquals(pin[i], "enrich")) { p->algo = ALGO_CPUTILED; enrich_mode = 1; }
    else { mexErrMsgTxt("Unknown algorithm"); }
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->patch_w = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->nn_iters = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_max = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_min = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_ratio = mxGetScalar(pin[i]); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->rs_iters = mxGetScalar(pin[i]); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { p->cores = int(mxGetScalar(pin[i])); } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { bmask = convert_bitmap(pin[i]); } i++; // XC+
  if (nin > i && !mxIsEmpty(pin[i])) { 
    if (!mxIsDouble(pin[i])) { mexErrMsgTxt("\nwin_size should be of type double."); }
    win_size = (double*)mxGetData(pin[i]);
    if (mxGetNumberOfElements(pin[i])==1) { p->window_h = p->window_w = int(win_size[0]); }
    else if (mxGetNumberOfElements(pin[i])==2) { p->window_h = int(win_size[0]); p->window_w = int(win_size[1]); }
    else { mexErrMsgTxt("\nwin_size should be a scalar for square window or [h w] for a rectangular one."); }
  } i++;
  /* continue parsing parameters */
  // [ann_prev=NULL], [ann_window=NULL], [awinsize=NULL], 
  if (nin > i && !mxIsEmpty(pin[i])) { 
    ANN_PREV = pin[i];
    int clip_count = 0;
    ann_prev = convert_field(p, ANN_PREV, bw, bh, clip_count);       // Bug fixed by Connelly
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    ANN_WINDOW = pin[i];
    int clip_count = 0;
    ann_window = convert_field(p, ANN_WINDOW, bw, bh, clip_count);      
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    AWINSIZE = pin[i];
    awinsize = convert_winsize_field(p, AWINSIZE, aw, ah);  
    if (p->window_w==INT_MAX||p->window_h==INT_MAX) { p->window_w = -1; p->window_h = -1; }
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    knn_chosen = int(mxGetScalar(pin[i]));
    if (knn_chosen == 1) { knn_chosen = -1; }
    if (knn_chosen <= 0) { mexErrMsgTxt("\nknn is less than zero"); }
  } i++;
  if (nin > i && !mxIsEmpty(pin[i])) { 
    scalemax = mxGetScalar(pin[i]);
    if (scalemax <= 0) { mexErrMsgTxt("\nscalerange is less than zero"); }
    scalemin = 1.0/scalemax;
    if (scalemax < scalemin) {
      double temp = scalemax;
      scalemax = scalemin;
      scalemin = temp;
    }
  } i++;

  if (ann_window&&!awinsize&&!win_size) {
    mexErrMsgTxt("\nUsing ann_window - either awinsize or win_size should be defined.\n");
  }

  if (enrich_mode) {
	int nn_iters = p->nn_iters;
    p->enrich_iters = nn_iters/2;
	p->nn_iters = 2;
	if (A != B) { mexErrMsgTxt("\nOur implementation of enrichment requires that image A = image B.\n"); }
	if (mode == MODE_IMAGE) {
	  b = a;
	} else {
	  mexErrMsgTxt("\nEnrichment only implemented for 3 channel uint8 inputs.\n");
	}
  }

  init_params(p);
  if (sim_mode) {
    init_xform_tables(scalemin, scalemax, 1);
  }
  
  RegionMasks *amaskm = amask ? new RegionMasks(p, amask): NULL;

  BITMAP *ann = NULL; // NN field
  BITMAP *annd_final = NULL; // NN patch distance field
  BITMAP *ann_sim_final = NULL;

  VBMP *vann_sim = NULL;
  VBMP *vann = NULL;
  VBMP *vannd = NULL;

  if (mode == MODE_IMAGE) {
    // input as RGB image
    if (!a || !b) { mexErrMsgTxt("internal error: no a or b image"); }
    if (knn_chosen > 1) {
      p->knn = knn_chosen;
      if (sim_mode) { mexErrMsgTxt("rotating+scaling patches not implemented with knn (actually it is implemented it is not exposed by the wrapper)"); }
      PRINCIPAL_ANGLE *pa = NULL;
      vann_sim = NULL;
      vann = knn_init_nn(p, a, b, vann_sim, pa);
      vannd = knn_init_dist(p, a, b, vann, vann_sim);
      knn(p, a, b, vann, vann_sim, vannd, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, pa);
//      sort_knn(p, vann, vann_sim, vannd);
    } else if (sim_mode) {
      BITMAP *ann_sim = NULL;
      ann = sim_init_nn(p, a, b, ann_sim);
      BITMAP *annd = sim_init_dist(p, a, b, ann, ann_sim);
      sim_nn(p, a, b, ann, ann_sim, annd);
      if (ann_prev) { mexErrMsgTxt("when searching over rotations+scales, previous guess is not supported"); }
      annd_final = annd;
      ann_sim_final = ann_sim;
    } else {
      ann = init_nn(p, a, b, bmask, NULL, amaskm, 1, ann_window, awinsize);
      BITMAP *annd = init_dist(p, a, b, ann, bmask, NULL, amaskm);
      nn(p, a, b, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores, ann_window, awinsize); 
      if (ann_prev) minnn(p, a, b, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
      annd_final = annd;
    }
  } 
/*
  else if (mode == MODE_VECB) {
//    mexPrintf("mode vecb %dx%dx%d, %dx%dx%d\n", ab->w, ab->h, ab->n, bb->w, bb->h, bb->n);
//    mexPrintf("  %d %d %d %d\n", ab->get(0,0)[0], ab->get(1,0)[0], ab->get(0,1)[0], ab->get(0,0)[1]);
    if (!ab || !bb) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = vec_init_nn<unsigned char>(p, ab, bb, bmask, NULL, amaskm);
    VECBITMAP<int> *annd = vec_init_dist<unsigned char, int>(p, ab, bb, ann, bmask, NULL, amaskm);
//    mexPrintf("  %d %d %d %p %p\n", annd->get(0,0)[0], annd->get(1,0)[0], annd->get(0,1)[0], amaskm, bmask);
    vec_nn<unsigned char, int>(p, ab, bb, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) vec_minnn<unsigned char, int>(p, ab, bb, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = vecbitmap_to_bitmap(annd);
    delete annd;
  } 
  else if (mode == MODE_VECF) {
//    mexPrintf("mode vecf %dx%dx%d, %dx%dx%d\n", af->w, af->h, af->n, bf->w, bf->h, bf->n);
//    mexPrintf("  %f %f %f %f\n", af->get(0,0)[0], af->get(1,0)[0], af->get(0,1)[0], af->get(0,0)[1]);
    if (!af || !bf) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = vec_init_nn<float>(p, af, bf, bmask, NULL, amaskm);
    VECBITMAP<float> *annd = vec_init_dist<float, float>(p, af, bf, ann, bmask, NULL, amaskm);
    vec_nn<float, float>(p, af, bf, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) vec_minnn<float, float>(p, af, bf, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = create_bitmap(annd->w, annd->h);
    clear(annd_final);
    delete annd;
  }
*/
  else if(mode == MODE_VECB) {
    if (sim_mode) { mexErrMsgTxt("internal error: rotation+scales not implemented with descriptor mode"); }
    if (knn_chosen > 1) { mexErrMsgTxt("internal error: kNN not implemented with descriptor mode"); }
//    mexPrintf("mode vecb_xc %dx%dx%d, %dx%dx%d\n", ab->w, ab->h, ab->n, bb->w, bb->h, bb->n);
    // input as uint8 discriptors per pixel
    if (!ab || !bb) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = XCvec_init_nn<unsigned char>(p, ab, bb, bmask, NULL, amaskm);
    VECBITMAP<int> *annd = XCvec_init_dist<unsigned char, int>(p, ab, bb, ann, bmask, NULL, amaskm);
    XCvec_nn<unsigned char, int>(p, ab, bb, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) XCvec_minnn<unsigned char, int>(p, ab, bb, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = vecbitmap_to_bitmap(annd);
    delete annd;
  } else if(mode == MODE_VECF) {
    if (sim_mode) { mexErrMsgTxt("internal error: rotation+scales not implemented with descriptor mode"); }
    if (knn_chosen > 1) { mexErrMsgTxt("internal error: kNN not implemented with descriptor mode"); }
    // input as float/double discriptors per pixel
    if (!af || !bf) { mexErrMsgTxt("internal error: no a or b image"); }
    ann = XCvec_init_nn<float>(p, af, bf, bmask, NULL, amaskm);
    VECBITMAP<float> *annd = XCvec_init_dist<float, float>(p, af, bf, ann, bmask, NULL, amaskm);
    XCvec_nn<float, float>(p, af, bf, ann, annd, amaskm, bmask, 0, 0, rp, 0, 0, 0, NULL, p->cores); 
    if (ann_prev) XCvec_minnn<float, float>(p, af, bf, ann, annd, ann_prev, bmask, 0, 0, rp, NULL, amaskm, p->cores);  
    annd_final = create_bitmap(annd->w, annd->h);
    clear(annd_final);
    delete annd;	
  }

  destroy_region_masks(amaskm);

  // output ann: x | y | patch_distance
  if(nout >= 1) {
    mxArray *ans = NULL;
    if (knn_chosen > 1) {
      if (sim_mode) { mexErrMsgTxt("rotating+scaling patches return value not implemented with knn"); }
      mwSize dims[4] = { ah, aw, 3, knn_chosen };
      ans = mxCreateNumericArray(4, dims, mxINT32_CLASS, mxREAL);
      int *data = (int *) mxGetData(ans);
      for (int kval = 0; kval < knn_chosen; kval++) {
        int *xchan = &data[aw*ah*3*kval+0];
        int *ychan = &data[aw*ah*3*kval+aw*ah];
        int *dchan = &data[aw*ah*3*kval+2*aw*ah];
        for (int y = 0; y < ah; y++) {
//          int *ann_row = (int *) ann->line[y];
//          int *annd_row = (int *) annd_final->line[y];
          for (int x = 0; x < aw; x++) {
//            int pp = ann_row[x];
            int pp = vann->get(x, y)[kval];
            int pos = y + x * ah;
            xchan[pos] = INT_TO_X(pp);
            ychan[pos] = INT_TO_Y(pp);
            dchan[pos] = vannd->get(x, y)[kval];
          }
        }
      }
    } else if (ann_sim_final) {
      mwSize dims[3] = { ah, aw, 5 };
      ans = mxCreateNumericArray(3, dims, mxSINGLE_CLASS, mxREAL);
      float *data = (float *) mxGetData(ans);
      float *xchan = &data[0];
      float *ychan = &data[aw*ah];
      float *dchan = &data[2*aw*ah];
      float *tchan = &data[3*aw*ah];
      float *schan = &data[4*aw*ah];
      double angle_scale = 2.0*M_PI/NUM_ANGLES;
      for (int y = 0; y < ah; y++) {
        int *ann_row = (int *) ann->line[y];
        int *annd_row = (int *) annd_final->line[y];
        int *ann_sim_row = ann_sim_final ? (int *) ann_sim_final->line[y]: NULL;
        for (int x = 0; x < aw; x++) {
          int pp = ann_row[x];
          int pos = y + x * ah;
          xchan[pos] = INT_TO_X(pp);
          ychan[pos] = INT_TO_Y(pp);
          dchan[pos] = annd_row[x];
          if (ann_sim_final) {
            int v = ann_sim_row[x];
            int tval = INT_TO_Y(v)&(NUM_ANGLES-1);
            int sval = INT_TO_X(v);

            tchan[pos] = tval*angle_scale;
            schan[pos] = xform_scale_table[sval]*(1.0/65536.0);
          }
        }
      }
    } else {
      mwSize dims[3] = { ah, aw, 3 };
      ans = mxCreateNumericArray(3, dims, mxINT32_CLASS, mxREAL);
      int *data = (int *) mxGetData(ans);
      int *xchan = &data[0];
      int *ychan = &data[aw*ah];
      int *dchan = &data[2*aw*ah];
      for (int y = 0; y < ah; y++) {
        int *ann_row = (int *) ann->line[y];
        int *annd_row = (int *) annd_final->line[y];
        for (int x = 0; x < aw; x++) {
          int pp = ann_row[x];
          int pos = y + x * ah;
          xchan[pos] = INT_TO_X(pp);
          ychan[pos] = INT_TO_Y(pp);
          dchan[pos] = annd_row[x];
        }
      }
    }
    pout[0] = ans;
  }

  // clean up
  delete vann;
  delete vann_sim;
  delete vannd;
  delete p;
  delete rp;
  destroy_bitmap(a);
  destroy_bitmap(borig);
  delete ab;
  delete bb;
  delete af;
  delete bf;
  destroy_bitmap(ann);
  destroy_bitmap(annd_final);
  destroy_bitmap(ann_sim_final);
  if (ann_prev) destroy_bitmap(ann_prev);
  if (ann_window) destroy_bitmap(ann_window);
  if (awinsize) destroy_bitmap(awinsize);
}
Exemple #26
0
/*
 ** Re read the config file, and send all the daemons a signal telling
 ** them to do so also.
 */
void
main_config()
{
	StringList old_daemon_list;
	char *list = daemons.ordered_daemon_names.print_to_string();
	char *daemon_name;
	class daemon	*adaemon;

	if( list ) {
		old_daemon_list.initializeFromString(list);
		free(list);
	}

		// Re-read the config files and create a new classad
	init_classad(); 

		// Reset our config values
	init_params();

		// Reset the daemon list
	init_daemon_list();

		// Remove daemons that should no longer be running
	old_daemon_list.rewind();
	while( (daemon_name = old_daemon_list.next()) ) {
		if( !daemons.ordered_daemon_names.contains(daemon_name) ) {
			if( NULL != daemons.FindDaemon(daemon_name) ) {
				daemons.StopDaemon(daemon_name);
			}
		}
	}

		// Re-read the paths to our executables.  If any paths
		// changed, the daemons will be marked as having a new
		// executable.
	daemons.InitParams();

	if( StartDaemons ) {
			// Restart any daemons who's executables are new or ones
			// that the path to the executable has changed.  
		daemons.immediate_restart = TRUE;
		daemons.CheckForNewExecutable();
		daemons.immediate_restart = FALSE;
			// Tell all the daemons that are running to reconfig.
		daemons.ReconfigAllDaemons();

			// Setup and configure controllers for all daemons in
			// case the reconfig changed controller setup.  Start
			// any new daemons as well
		daemons.ordered_daemon_names.rewind();
		while( ( daemon_name = daemons.ordered_daemon_names.next() ) ) {
			adaemon = daemons.FindDaemon(daemon_name);
			if ( adaemon == NULL ) {
				dprintf( D_ALWAYS, "ERROR: Setup for daemon %s failed\n", daemon_name );
			}
			else if ( adaemon->SetupController() < 0 ) {
				dprintf( D_ALWAYS,
						"ERROR: Setup of controller for daemon %s failed\n",
						daemon_name );
				daemons.StopDaemon( daemon_name );
			}
			else if( !old_daemon_list.contains(daemon_name) ) {
				daemons.StartDaemonHere(adaemon);
			}

		}

	} else {
		daemons.DaemonsOff();
	}
    // Invalide session if necessary
    daemonCore->invalidateSessionCache();
		// Re-register our timers, since their intervals might have
		// changed.
	daemons.StartTimers();
	daemons.UpdateCollector();
}
Exemple #27
0
void
main_init( int argc, char* argv[] )
{
    extern int runfor;
	char	**ptr;

	if ( argc > 3 ) {
		usage( argv[0] );
	}
	
	int argc_count = 1;
	for( ptr=argv+1, argc_count = 1; argc_count<argc && *ptr; ptr++,argc_count++) {
		if( ptr[0][0] != '-' ) {
			usage( argv[0] );
		}
		switch( ptr[0][1] ) {
		case 'n':
			ptr++;
			if( !(ptr && *ptr) ) {
				EXCEPT( "-n requires another argument" );
			}
			MasterName = build_valid_daemon_name( *ptr );
			dprintf( D_ALWAYS, "Using name: %s\n", MasterName );
			break;
		default:
			usage( argv[0] );
		}
	}

    if (runfor != 0) {
        // We will construct an environment variable that 
        // tells the daemon what time it will be shut down. 
        // We'll give it an absolute time, though runfor is a 
        // relative time. This means that we don't have to update
        // the time each time we restart the daemon.
		MyString runfor_env;
		runfor_env.formatstr("%s=%ld", EnvGetName(ENV_DAEMON_DEATHTIME),
						   time(NULL) + (runfor * 60));
		SetEnv(runfor_env.Value());
    }

	daemons.SetDefaultReaper();
	
		// Grab all parameters needed by the master.
	init_params();
		// param() for DAEMON_LIST and initialize our daemons object.
	init_daemon_list();
	if ( daemons.SetupControllers() < 0 ) {
		EXCEPT( "Daemon initialization failed" );
	}
		// Lookup the paths to all the daemons we now care about.
	daemons.InitParams();
		// Initialize our classad;
	init_classad();  
		// Initialize the master entry in the daemons data structure.
	daemons.InitMaster();
		// Make sure if PrivSep is on we're not running as root
	check_uid_for_privsep();
		// open up the windows firewall 
	init_firewall_exceptions();

#if defined(WANT_CONTRIB) && defined(WITH_MANAGEMENT)
#if defined(HAVE_DLOPEN)
	MasterPluginManager::Load();
#elif defined(WIN32)
	load_master_mgmt();
#endif
	MasterPluginManager::Initialize();
#endif

		// Register admin commands
	daemonCore->Register_Command( RESTART, "RESTART",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( RESTART_PEACEFUL, "RESTART_PEACEFUL",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMONS_OFF, "DAEMONS_OFF",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMONS_OFF_FAST, "DAEMONS_OFF_FAST",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMONS_OFF_PEACEFUL, "DAEMONS_OFF_PEACEFUL",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMONS_ON, "DAEMONS_ON",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( MASTER_OFF, "MASTER_OFF",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( MASTER_OFF_FAST, "MASTER_OFF_FAST",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMON_ON, "DAEMON_ON",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMON_OFF, "DAEMON_OFF",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMON_OFF_FAST, "DAEMON_OFF_FAST",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( DAEMON_OFF_PEACEFUL, "DAEMON_OFF_PEACEFUL",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( CHILD_ON, "CHILD_ON",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( CHILD_OFF, "CHILD_OFF",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( CHILD_OFF_FAST, "CHILD_OFF_FAST",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	daemonCore->Register_Command( SET_SHUTDOWN_PROGRAM, "SET_SHUTDOWN_PROGRAM",
								  (CommandHandler)admin_command_handler, 
								  "admin_command_handler", 0, ADMINISTRATOR );
	// Command handler for stashing the pool password
	daemonCore->Register_Command( STORE_POOL_CRED, "STORE_POOL_CRED",
								(CommandHandler)&store_pool_cred_handler,
								"store_pool_cred_handler", NULL, CONFIG_PERM,
								D_FULLDEBUG );
	/*
	daemonCore->Register_Command( START_AGENT, "START_AGENT",
					  (CommandHandler)admin_command_handler, 
					  "admin_command_handler", 0, ADMINISTRATOR );
	*/

	daemonCore->RegisterTimeSkipCallback(time_skip_handler,0);

	_EXCEPT_Cleanup = DoCleanup;

#if !defined(WIN32)
	if( !dprintf_to_term_check() && param_boolean( "USE_PROCESS_GROUPS", true ) ) {
			// If we're not connected to a terminal, start our own
			// process group, unless the config file says not to.
		setsid();
	}
#endif

	if( StartDaemons ) {
		daemons.StartAllDaemons();
	}
	daemons.StartTimers();
}
int
main (int argc, char **argv)
{
  struct params p;
  processArgsAnalyze (argc, argv, p);
  VERBOSE = p.verbose;
  init_params (&p);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "phcdet", p.det);


  Fermions *f = new Fermions (&p);
  f->LoadFITS ();		// LoadFITS already computes the column density

  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "maxOD", f->maxOD);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "maxPHI", f->maxPHI);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "maxPHCSIG",
	      f->maxPHCSIG);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "maxCD", f->maxCD);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "maxI", f->maxI);

  if (p.onlyCD)
    {
      f->SaveColumnDensity ();
      return EXIT_SUCCESS;
    }
//  f->FindMoments ();
  if (!p.keeproi)
    {
      f->MinimalCrop (5.0);
    }
  f->Fit2DGauss (p.gaus2d_mott);
  f->SaveColumnDensity ();
  if (!p.keeproi)
    {
      f->MinimalCrop (3.5);
      f->Fit2DGauss ();
      f->SaveColumnDensity ();
    }
//  f->FitScatt2DGauss ();
//  f->FitProbe2DGauss ();

  //Get center of cloud with respect to the Andor full frame
  f->abs_ci += f->gaus2dfit[0];
  f->abs_cj += f->gaus2dfit[2];

  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "offset",
	      f->gaus2dfit[5] * f->GetNPixels ());

  if (p.gaus2d_mott)
    {
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "nfit_mott",
		  f->nfit_mott);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "r0_mott",
		  f->gaus2dfit_mott[5]);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "peakd_mott",
		  f->peakd_mott);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax0w_mott",
		  f->gaus2dfit_mott[1] * p.magnif);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax1w_mott",
		  f->gaus2dfit_mott[3] * p.magnif);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax0c_mott",
		  f->abs_ci - f->gaus2dfit[0] + f->gaus2dfit_mott[0]);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax1c_mott",
		  f->abs_cj - f->gaus2dfit[2] + f->gaus2dfit_mott[2]);
    }
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "nfit", f->nfit);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "nfit_err",
	      f->nfit_err);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "peakd", f->peakd);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "peakd_sph",
	      f->peakd_sph);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax0w",
	      f->gaus2dfit[1] * p.magnif);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax1w",
	      f->gaus2dfit[3] * p.magnif);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax0c", f->abs_ci);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ax1c", f->abs_cj);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "TF", f->TF);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ph_per_at",
	      f->Tsp / f->nfit);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "peak_cd",
	      f->gaus2dfit[4]);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "photons_in_pulse",
	      f->Tp0);
  setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "alphastar",
	      p.alphastar);

  f->GetAzimuthalAverageEllipse ();

  if (p.fermiazimuth)
    {
      //f->GetAzimuthalAverage ();
      f->FitAzimuthalFermi ();
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "n0_az", f->n0_az);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "BetaMu_az",
		  f->BetaMu_az);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "r_az", f->r_az);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "B_az", f->B_az);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "mx_az", f->mx_az);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "TF_az", f->TF_az);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "T_az", f->T_az);
    }

  if (p.fermi2d)
    {
      f->Fit2DFermi ();
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "n0_Fermi", f->n0);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "BetaMU_Fermi",
		  f->BetaMu);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ri_Fermi",
		  f->ri_Fermi);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "rj_Fermi",
		  f->rj_Fermi);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "ci_Fermi",
		  f->ci_Fermi);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "cj_Fermi",
		  f->cj_Fermi);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "B_Fermi",
		  f->B_Fermi);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "TF_2d", f->TF_2d);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "T_2d_rd",
		  f->T_2d_rd);
      setINI_num (p.reportfile, p.andor2 ? "CPP2" : "CPP", "T_2d_ax",
		  f->T_2d_ax);
    }


  if (p.fitfermi1D || p.fermiazimuth || p.fermi2d || true)
    {
      f->ComputeIntegrated1DDensity ();
      f->MakePlots ();
    }

  printf ("%s  %sN = %.2e%s", p.shotnum.c_str (), KCYN, f->nfit, KNRM);

  //Print number
  if (f->nfit_err * 50. > f->nfit)
    {
      printf
	("\nNumber determination uncertainty might be too high: N = %.2e +/- %.0e\n",
	 f->nfit, f->nfit_err);
    }



  if (!p.phc && !p.fluor)
    {
      //Print number from scattered photons
      //printf (", Nsp = %.2e", f->Nsp);

      //Print total number of photons in probe pulse
      //printf (", Ph = %.2e", f->Tp0);

      //Print average number of photons scattered per atom
      printf (", Ph/At = %.0f", f->Tsp / f->nfit);

      //Print peak density
      printf (", n = %.2e", f->peakd);

      //Print peak density
      printf (", %sn_sph = %.2e%s", KMAG, f->peakd_sph, KNRM);

      //Print axial size
      printf (", ax0w = %.1f +/- %.1f", f->gaus2dfit[1] * p.magnif,
	      f->gaus2dfit_err[1] * p.magnif);

      //Print center
      printf (", %sc = (%.0f,%.0f)%s", KGRN, f->abs_ci, f->abs_cj, KNRM);

      //Print max intensity
      //printf (", Imax = %.2f", f->maxI);

      //Print max intensity smoothed
      //printf (", Imax(smoothed) = %.2f", f->maxIsmooth);

      //Print average intensity
      //printf (", Iave = %.2f", f->aveI);

      //Print average intensity
      printf (", I/Isat = %.2f", f->aveIweighted);

      //Print max optical density
      printf (", ODmax = %.1f", f->maxOD);
      //Print max column density
      printf (", CDmax = %.1f", f->maxCD);

    }

  else if (p.fluor || p.Nframes == 2)
    {
      printf (", MAX Counts/Px = %.1f", f->maxCD);

      //Print axial size
      printf (", ax0w = %.1f +/- %.1f", f->gaus2dfit[1] * p.magnif,
	      f->gaus2dfit_err[1] * p.magnif);

      //Print center
      printf (", c = (%.0f,%.0f)", f->abs_ci, f->abs_cj);

      //Print range of counts in atoms and noatoms frames
      printf (", atoms:(%d to %d),  noatoms:(%d to %d)", (int) f->minCA,
	      (int) f->maxCA, (int) f->minCN, (int) f->maxCN);
    }

  else
    {
      //Print total number of photons in probe pulse
      printf (", Ph = %.2e", f->Tp0);
      //Print peak density
      printf (", n = %.2e", f->peakd);
      //Print peak density
      printf (", %sn_sph = %.2e%s", KMAG, f->peakd_sph, KNRM);
      //Print axial size
      printf (", ax0w = %.1f +/- %.1f", f->gaus2dfit[1] * p.magnif,
	      f->gaus2dfit_err[1] * p.magnif);
      //Print center
      printf (", %sc = (%.0f,%.0f)%s", KGRN, f->abs_ci, f->abs_cj, KNRM);
      //Print max intensity
      //printf (", Imax = %.2f", f->maxI);
      //Print average intensity
      printf (", I/Isat = %.2f", f->aveIweighted);
      //Print max phase shift
      printf (", PHImax = %.3f", f->maxPHI);
      //Print max phase-contrast signal
      printf (", SIGmax = %.3f", f->maxPHCSIG);
      //Print max column density
      printf (", CDmax = %.1f", f->maxCD);

      //Print sqrt(N)/n parameter
      printf (", %ssqrt(N)/n = %.2e%s", KYEL, sqrt (f->nfit) / f->peakd_sph,
	      KNRM);

    }
//  printf
//    ("%s  N = %.2e +/- %.0e, n =  %.2e , ax0w = %.1f +/- %.1f, c = (%.0f,%.0f), I_max = %.2f, OD_max = %.1f",
//     p.shotnum.c_str (), f->nfit, f->nfit_err, f->peakd,
//     f->wi_1e * p.magnif, f->gaus2dfit_err[1] * p.magnif, f->abs_ci,
//     f->abs_cj, f->maxI, f->maxOD);

  if (p.fermi2d)
    printf (", T/TF_2d = %.2f, z = %.2f, f(z) = %.2f", f->TF_2d,
	    f->Fugacity_Fermi, f->f_Fermi);
  if (p.fermiazimuth)
    printf (", T/TF_az = %.2f, z = %.2f, f(z) = %.2f", f->TF_az,
	    f->Fugacity_az, f->f_az);
  printf ("\n");
/*

  double pos[2];

  double cts = img_counts (signal);
  double peak = img_peak (signal, pos);

  setINI_num (p.reportfile, p.andor2?"CPP2":"CPP", "peak", peak);
  setINI_num (p.reportfile, p.andor2?"CPP2":"CPP", "ipeak", pos[0]);
  setINI_num (p.reportfile, p.andor2?"CPP2":"CPP", "jpeak", pos[1]);
  cout << "#" << p.
    shotnum << " Counts=" << img_counts (signal) << " Peak=" << peak << endl;
*/
  return EXIT_SUCCESS;
}
char* parse_string(char* input_str) 
{
	char* begin_str; 
	char* end_str;
	char* out_buf = malloc(sizeof(char) * strlen(input_str) * BIZZBUZZ_LEN);
	int is_begin = 0, is_div = 0, lenght = 0, last_char = 0;
	unsigned long long sum = 0;
	
	while (input_str[0] != '\0')
	{
		if (!(input_str[0] >= '0' && input_str[0] <= '9'))
		{
			if (is_begin)
	 		{
	 			if (is_div = check_sum(sum, lenght, last_char))
				{
					fill_out_buf(is_div, &out_buf);	 				
	 				deinit_params(&is_begin, &sum, &lenght);
	 			}
	 			else
	 			{
					init_pointers(&input_str, &begin_str, &end_str);
					deinit_params(&is_begin, &sum, &lenght);					
					
					while (input_str != end_str)
					{
			 			out_buf[strlen(out_buf)] = input_str[0];
			 			input_str++;
					}				 
						
				}	 			
	 		}
	 		else
	 		{
				out_buf[strlen(out_buf)] = input_str[0];
	 			input_str++;
	 		}
	 	}
		else
	 	{
			if (!is_begin)
	 		{
	 			begin_str = input_str;
	 			is_begin = 1;
	 		}

	 		init_params(&lenght, input_str[0], &sum, &last_char);
	 			 
	 		if (input_str[1] == '\0') 
			{
				if (is_div = check_sum(sum, lenght, last_char))
				{
					fill_out_buf(is_div, &out_buf);	 				
	 				deinit_params(&is_begin, &sum, &lenght);
				}
				else
				{
					init_pointers(&input_str, &begin_str, &end_str);

					while (input_str != end_str )
					{
			 			out_buf[strlen(out_buf)] = input_str[0];
			 			input_str++;
					}				
				 		
			 		out_buf[strlen(out_buf)] = input_str[0];
				}	
			}
				
			input_str++;
		}	
	}
	
	return out_buf;
}
Exemple #30
0
static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
				       const struct pnp_card_device_id *pid)
{
	struct pnp_dev *dev;
	static int idx = 0;
	int ret;

	/*
	 * Allow this function to fail *quietly* if all the ISA PnP
	 * devices were configured using module parameters instead.
	 */
	if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS) {
		return -ENOSPC;
	}

	/*
	 * We have found a candidate ISA PnP card. Now we
	 * have to check that it has the devices that we
	 * expect it to have.
	 *
	 * We will NOT try and autoconfigure all of the resources
	 * needed and then activate the card as we are assuming that
	 * has already been done at boot-time using /proc/isapnp.
	 * We shall simply try to give each active card the resources
	 * that it wants. This is a sensible strategy for a modular
	 * system where unused modules are unloaded regularly.
	 *
	 * This strategy is utterly useless if we compile the driver
	 * into the kernel, of course.
	 */
	// printk(KERN_INFO "sscape: %s\n", card->name);

	/*
	 * Check that we still have room for another sound card ...
	 */
	if (sscape_cards >= SNDRV_CARDS) {
		printk(KERN_ERR "sscape: No room for another ALSA device\n");
		return -ENOSPC;
	}

	ret = -ENODEV;

	dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
	if (dev) {
		struct params *this;
		if (!pnp_is_active(dev)) {
			if (pnp_activate_dev(dev) < 0) {
				printk(KERN_INFO "sscape: device is inactive\n");
				return -EBUSY;
			}
		}
		/*
		 * Read the correct parameters off the ISA PnP bus ...
		 */
		this = init_params(&sscape_params[sscape_cards],
				   index[idx],
				   id[idx],
				   pnp_port_start(dev, 0),
				   pnp_irq(dev, 0),
				   pnp_irq(dev, 1),
				   pnp_dma(dev, 0));

		/*
		 * Do we know about this sound card already?
		 */
		if ( !is_port_known(this->port, sscape_params, sscape_cards) ) {
			snd_card_t *card;

			ret = create_sscape(this, &card);
			if (ret < 0)
				return ret;
			snd_card_set_dev(card, &pcard->card->dev);
			pnp_set_card_drvdata(pcard, card);
			++sscape_cards;
			++idx;
		}
	}

	return ret;
}