コード例 #1
0
ファイル: base.c プロジェクト: gieseke/bufferkdtree
/**
 * Initializes the *params struct with the parameters provided.
 *
 * @param n_neighbors The number of nearest neighbors to be found
 * @param tree_depth The tree depth of the tree to be built
 * @param num_threads The number of threads that should be used
 * @param num_nXtrain_chunks The number of chunks the training data should be split into
 * @param platform_id The OpenCL platform that should be used
 * @param device_id The id of the OpenCL device that should be used
 * @param allowed_train_mem_percent_chunk The amount of memory (percentage) that the training data may occupy
 * @param allowed_test_mem_percent  The amount of memory (percentage) that the test data may occupy
 * @param splitting_type The splitting type that can be used during the construction of the tree
 * @param *kernels_source_directory Pointer to string that contains the path to the OpenCL kernels
 * @param verbosity_level The verbosity level (0==no output, 1==more output, 2==...)
 * @param *params Pointer to struct that is used to store all parameters
 *
 */
void init_extern(int n_neighbors,
		int tree_depth,
		int num_threads,
		int num_nXtrain_chunks,
		int platform_id,
		int device_id,
		double allowed_train_mem_percent_chunk,
		double allowed_test_mem_percent,
		int splitting_type,
		char *kernels_source_directory,
		int verbosity_level,
		TREE_PARAMETERS *params) {

	set_default_parameters(params);

	params->n_neighbors = n_neighbors;
	params->tree_depth = tree_depth;
	params->num_threads = num_threads;
	params->n_train_chunks = num_nXtrain_chunks;
	params->splitting_type = splitting_type;
	params->kernels_source_directory = (char*) malloc((strlen(kernels_source_directory) + 10) * sizeof(char));
	strcpy(params->kernels_source_directory, kernels_source_directory);
	params->verbosity_level = verbosity_level;
	params->platform_id = platform_id;
	params->device_id = device_id;
	params->allowed_train_mem_percent_chunk = allowed_train_mem_percent_chunk;
	params->allowed_test_mem_percent = allowed_test_mem_percent;
	check_parameters(params);

	omp_set_num_threads(params->num_threads);

}
コード例 #2
0
ファイル: RegulatorGPC.cpp プロジェクト: pobieralnia/PSS
/**
 * Set parameters for Regulator
 *
 * @param		std::map<std::string, double> parm
 * @return		void
 */
void RegulatorGPC::set_parameters(std::map<std::string, double> & parm)
{
	// Clear all tmp values
	m_tmp_parameter.clear();

	// Copy values to temporary map
	m_tmp_parameter = parm;

	// Check parameters if they are correct
	try
	{
		if(check_parameters())
		{
			m_H = static_cast<int>(parm["H"]);
			m_L = static_cast<int>(parm["L"]);
			m_alpha = static_cast<double>(parm["alpha"]);
			m_ro =  static_cast<double>(parm["ro"]);
			m_rankA = static_cast<int>(parm["rankA"]);
			m_rankB = static_cast<int>(parm["rankB"]);
			m_lambda = parm["lambda"];
		}
     }
	 catch ( std::string & e )
	 {
        throw;
     }

}
コード例 #3
0
static int my_fault_init(void){
    //check all the module_parameters are set properly
    if(check_parameters())
        return -1;
    //get the address of 'adjust_exception_frame' from pv_irq_ops struct
    addr_adjust_exception_frame = *(unsigned long *)(addr_pv_irq_ops + 0x30);
    return 0;
}
コード例 #4
0
ファイル: cpia2_v4l.c プロジェクト: Anjali05/linux
/******************************************************************************
 *
 * cpia2_init/module_init
 *
 *****************************************************************************/
static int __init cpia2_init(void)
{
	LOG("%s v%s\n",
	    ABOUT, CPIA_VERSION);
	check_parameters();
	cpia2_usb_init();
	return 0;
}
コード例 #5
0
ファイル: RegulatorGPC.cpp プロジェクト: pobieralnia/PSS
/**
 * Set one parameter for Regulator
 *
 * @param		const std::string & param_name
 * @param		double value
 * @return		void
 */
void RegulatorGPC::set_parameters(const std::string & param_name, double value)
{
	// Clear all tmp values
	m_tmp_parameter.clear();

	m_tmp_parameter["H"] = m_H;
	m_tmp_parameter["L"] = m_L;
	m_tmp_parameter["alpha"] = m_alpha;
	m_tmp_parameter["lambda"] = m_lambda;
	m_tmp_parameter["rankA"] = m_rankA;
	m_tmp_parameter["rankB"] = m_rankB;
	m_tmp_parameter["ro"] = m_ro;

	if(param_name == "H")
		m_tmp_parameter["H"] = value;
	else if(param_name == "L")
		m_tmp_parameter["L"] = value;
	else if(param_name == "alpha")
		m_tmp_parameter["alpha"] = value;
	else if(param_name == "lambda")
		m_tmp_parameter["lambda"] = value;
	else if(param_name == "rankA")
		m_tmp_parameter["rankA"] = value;
	else if(param_name == "rankB")
		m_tmp_parameter["rankB"] = value;
	else if(param_name == "rankB")
		m_tmp_parameter["rankB"] = value;
	else if(param_name == "ro")
		m_tmp_parameter["ro"] = value;

	// Check parameters if they are correct
	try
	{
		if(check_parameters())
		{
			// TODO Bezsens nie mam pomys³u jak tego nie dublowac
			if(param_name == "H")
				m_H = static_cast<int>(value);
			else if(param_name == "L")
				m_L = static_cast<int>(value);
			else if(param_name == "alpha")
				m_alpha = value;
			else if(param_name == "lambda")
				m_lambda = value;
			else if(param_name == "rankA")
				m_rankA = static_cast<int>(value);
			else if(param_name == "rankB")
				m_rankB = static_cast<int>(value);
			else if(param_name == "ro")
				m_ro = value;
		}
	}
	catch (std::string & e)
	{
		throw; // rethrow exception
	}
}
コード例 #6
0
ファイル: lsh_dfe.cpp プロジェクト: Terranlee/LSH
 bool LSH_DFE::prepare_max_file(){
     cout<<"----------loading DFE----------"<<endl;
     mf = LSH_init();
     bool check = check_parameters();
     if(!check)
         return false;
     me = max_load(mf, "*");
     cout<<"----------loading DFE finished----------"<<endl;
     return true;
 }
コード例 #7
0
ファイル: xall.c プロジェクト: rforge/muste
void muste_xall(char *argv)
{
    int i;

    s_init(argv);
    i=spec_init(r1+r-1); if (i<0) return;
    i=check_parameters(); if (i<0) return;
    xall();
    s_end(argv);
    return;
}
コード例 #8
0
ファイル: base.c プロジェクト: chidcha/bufferkdtree
/* --------------------------------------------------------------------------------
 * Interface (extern): Initialize all components
 * --------------------------------------------------------------------------------
 */
void init_extern(int n_neighbors, int tree_depth, int num_threads, int splitting_type,
		int verbosity_level, KD_TREE_PARAMETERS *params) {

	set_default_parameters(params);

	params->n_neighbors = n_neighbors;
	params->tree_depth = tree_depth;
	params->num_threads = num_threads;
	params->verbosity_level = verbosity_level;
	params->splitting_type = splitting_type;

	check_parameters(params);

	omp_set_num_threads(params->num_threads);

}
コード例 #9
0
ファイル: 01.c プロジェクト: mjuli/algoritmos
int main(int argc, char * argv[]) { 
	FILE * arq_divisores; 
	if (!check_parameters(argc, argv)){ 
		usage(); 
		return 1; 
	} 
	arq_divisores = fopen(argv[2],"w"); 
	if (arq_divisores== NULL){ 
		printf("ERROR: Não foi possível abrir o arquivo %s.\n",argv[2]); 
		return 2; 
	} 
	if (gera_divisores(converte(argv[1]),arq_divisores) != 0){ 
		printf("ERROR: Problemas ao escrever dados no arquivo %s.\n", argv[2]); 
		return 3; 
	} 
	gera_divisores(converte(argv[1]), arq_divisores);
	fclose(arq_divisores); 
	return 0; 
}
コード例 #10
0
ファイル: bp_image.c プロジェクト: DanIverson/OpenVnmrJ
pulsesequence()  
{
   get_parameters();
   check_parameters();
   set_powers();
   calc_gradients();
   if(!strcmp(bptype,"slice")) {
      slice_timing();
   } else if(!strcmp(bptype,"noslice")) {
      noslice_timing();
   }
   status(A);
   if (!strcmp(prep,"sr")) {
       saturation_pulse();
   } else if (!strcmp(prep,"ir")) {
       inversion_pulse();
   } else if (!strcmp(prep,"aps")) {
       aps_pulse();
   } else if (!strcmp(prep,"t1r")) {
       spinlock_pulse();
   } else {
       delay(tr-te-p1/2.0);
   }
   if(!strcmp(bptype,"slice")) {
       slice_offset();
       status(B);
       selective_90();
       slice_compensate();
       delay(dx);
       selective_180();
       delay(dy);
       read_out();
   } else if(!strcmp(bptype,"noslice")) {
       status(B);
       bp_noslice();
   }
}
コード例 #11
0
ファイル: graphobject.cpp プロジェクト: CxAalto/himmeli_3.0.1
GraphObject::GraphObject(const string& fname) {
  /* Check configuration file. */
  cfg = ConfigTable(fname, '\0');
  if(cfg.size() < 1) {
    cout << "WARNING! Configuration file '" << cfg.source()
	 << "' is empty or cannot be opened.\n";
    return;
  }

  /* Load data from input file(s). */
  if(cfg["VerboseMode"][1] != "off") print_greeting(0);
  if(!check_parameters(cfg)) {
    cerr << "ERROR! Erroneous instructions found.\n";
    print_checklist();
  }  
  else if(!configure()) {
    cerr << "ERROR! Configuration failed.\n";
    print_checklist();
  }
  else if(!import()) {
    cerr << "ERROR! Import failed.\n";
    print_checklist();
  }
}
コード例 #12
0
ファイル: platform.c プロジェクト: embest-amp/cycloneV_evm
static int __devinit dwc_otg_driver_probe(struct platform_device *ofdev)
{
	int retval;
	struct dwc_otg_device *dwc_dev;
	struct device *dev = &ofdev->dev;
	struct resource res;
	ulong gusbcfg_addr;
	u32 usbcfg = 0;
	struct resource *nres = 0;
#ifdef CONFIG_OF
	u32 prop;
	u32 prop_array[15];
#endif

	dwc_dev = kzalloc(sizeof(*dwc_dev), GFP_KERNEL);
	if (!dwc_dev) {
		dev_err(dev, "kmalloc of dwc_otg_device failed\n");
		retval = -ENOMEM;
		goto fail_dwc_dev;
	}

	/* Retrieve the memory and IRQ resources. */
	dwc_dev->irq = platform_get_irq(ofdev, 0);
	if (dwc_dev->irq == NO_IRQ) {
		dev_err(dev, "no device irq\n");
		retval = -ENODEV;
		goto fail_of_irq;
	}

	nres = platform_get_resource(ofdev, IORESOURCE_MEM, 0);
	res = *nres;
	if(nres == 0) {
		dev_err(dev, "%s: Can't get USB-OTG register address\n",
			__func__);
		retval = -ENOMEM;
		goto fail_of_irq;
	}

	dwc_dev->phys_addr = res.start;
	dwc_dev->base_len = res.end - res.start + 1;
	if (!request_mem_region(dwc_dev->phys_addr,
				dwc_dev->base_len, dwc_driver_name)) {
		dev_err(dev, "request_mem_region failed\n");
		retval = -EBUSY;
		goto fail_of_irq;
	}

	/* Map the DWC_otg Core memory into virtual address space. */
	dwc_dev->base = ioremap(platform_get_resource(ofdev, IORESOURCE_MEM, 0)->start, SZ_256K);
	if (!dwc_dev->base) {
		dev_err(dev, "ioremap() failed\n");
		retval = -ENOMEM;
		goto fail_ioremap;
	}
	dev_dbg(dev, "mapped base=0x%08x\n", (__force u32)dwc_dev->base);

	/*
	 * Initialize driver data to point to the global DWC_otg
	 * Device structure.
	 */
	dev_set_drvdata(dev, dwc_dev);//driver

	dwc_dev->core_if =
	    dwc_otg_cil_init(dwc_dev->base, &dwc_otg_module_params);
	if (!dwc_dev->core_if) {
		dev_err(dev, "CIL initialization failed!\n");
		retval = -ENOMEM;
		goto fail_cil_init;
	}

	/*
	* Set the wqfunc of this core_if as "not set"
	*/
	dwc_dev->core_if->wqfunc_setup_done = 0;

	/*
	 * Validate parameter values after dwc_otg_cil_init.
	 */
	if (check_parameters(dwc_dev->core_if)) {
		retval = -EINVAL;
		goto fail_check_param;
	}

#ifdef CONFIG_OF
	if(!of_property_read_u32(ofdev->dev.of_node,
		"dma-mask", (u32*)&dwc_otg_dma_mask)) {
		dev->dma_mask = &dwc_otg_dma_mask;
	}
	else {
		dev->dma_mask = NULL;
	}

	if(!of_property_read_u32(ofdev->dev.of_node,
		"ulpi-ddr", &prop)) {
		dwc_otg_module_params.phy_ulpi_ddr = prop;
	}

	if(!of_property_read_u32(ofdev->dev.of_node,
		"host-rx-fifo-size", &prop)) {
		dwc_otg_module_params.host_rx_fifo_size = prop;
	}
	if(!of_property_read_u32(ofdev->dev.of_node,
		"dev-rx-fifo-size", &prop)) {
		dwc_otg_module_params.dev_rx_fifo_size = prop;
	}
	if(!of_property_read_u32(ofdev->dev.of_node,
		"host-nperio-tx-fifo-size", &prop)) {
		dwc_otg_module_params.host_nperio_tx_fifo_size = prop;
	}
	if(!of_property_read_u32(ofdev->dev.of_node,
		"dev-nperio-tx-fifo-size", &prop)) {
		dwc_otg_module_params.dev_nperio_tx_fifo_size = prop;
	}
	if(!of_property_read_u32(ofdev->dev.of_node,
		"host-perio-tx-fifo-size", &prop)) {
		dwc_otg_module_params.host_perio_tx_fifo_size = prop;
	}
	if(!of_property_read_u32_array(ofdev->dev.of_node,
		"dev-perio-tx-fifo-size", prop_array, MAX_PERIO_FIFOS)) {
		int i;
		for(i=0; i<MAX_PERIO_FIFOS; i++)
			dwc_otg_module_params.dev_tx_fifo_size[i]
				= prop_array[i];
	}
	if(!of_property_read_u32_array(ofdev->dev.of_node,
		"dev-tx-fifo-size", prop_array, MAX_TX_FIFOS)) {
		int i;
		for(i=0; i<MAX_TX_FIFOS; i++)
			dwc_otg_module_params.dev_perio_tx_fifo_size[i]
				= prop_array[i];
	}
#endif

	usb_nop_xceiv_register();
	dwc_dev->core_if->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
	if (!dwc_dev->core_if->xceiv) {
		retval = -ENODEV;
		goto fail_xceiv;
	}
	dwc_set_feature(dwc_dev->core_if);

	/* Initialize the DWC_otg core. */
	dwc_otg_core_init(dwc_dev->core_if);

	/*
	 * Disable the global interrupt until all the interrupt
	 * handlers are installed.
	 */
	spin_lock(&dwc_dev->lock);
	dwc_otg_disable_global_interrupts(dwc_dev->core_if);
	spin_unlock(&dwc_dev->lock);

	/*
	 * Install the interrupt handler for the common interrupts before
	 * enabling common interrupts in core_init below.
	 */
	retval = request_irq(dwc_dev->irq, dwc_otg_common_irq,
			     IRQF_SHARED, "dwc_otg", dwc_dev);
	if (retval) {
		dev_err(dev, "request of irq%d failed retval: %d\n",
			dwc_dev->irq, retval);
		retval = -EBUSY;
		goto fail_req_irq;
	} else {
		dwc_dev->common_irq_installed = 1;
	}

	if (!dwc_has_feature(dwc_dev->core_if, DWC_HOST_ONLY)) {
	//if (dwc_has_feature(dwc_dev->core_if, DWC_DEVICE_ONLY)) {
		/* Initialize the PCD */
		retval = dwc_otg_pcd_init(dev);
		if (retval) {
			dev_err(dev, "dwc_otg_pcd_init failed\n");
			dwc_dev->pcd = NULL;
			goto fail_req_irq;
		}
	}

	gusbcfg_addr = (ulong) (dwc_dev->core_if->core_global_regs)
		+ DWC_GUSBCFG;
	if (!dwc_has_feature(dwc_dev->core_if, DWC_DEVICE_ONLY)) {
	//if (dwc_has_feature(dwc_dev->core_if, DWC_HOST_ONLY)) {
		/* Initialize the HCD and force_host_mode */
		usbcfg = dwc_reg_read(gusbcfg_addr, 0);
		usbcfg |= DWC_USBCFG_FRC_HST_MODE;
		dwc_reg_write(gusbcfg_addr, 0, usbcfg);

		retval = dwc_otg_hcd_init(dev, dwc_dev);
		if (retval) {
			dev_err(dev, "dwc_otg_hcd_init failed\n");
			dwc_dev->hcd = NULL;
			goto fail_hcd;
		}
		/* configure chargepump interrupt */
		dwc_dev->hcd->cp_irq = platform_get_irq_byname(ofdev, "chargepumpirq");
		if(dwc_dev->hcd->cp_irq != -ENXIO) {
			retval = request_irq(dwc_dev->hcd->cp_irq,
					     dwc_otg_externalchgpump_irq,
					     IRQF_SHARED,
					     "dwc_otg_ext_chg_pump", dwc_dev);
			if (retval) {
				dev_err(dev,
					"request of irq failed retval: %d\n",
					retval);
				retval = -EBUSY;
				goto fail_hcd;
			} else {
				dev_dbg(dev, "%s: ExtChgPump Detection "
					"IRQ registered\n", dwc_driver_name);
			}
		}
	}
	/*
	 * Enable the global interrupt after all the interrupt
	 * handlers are installed.
	 */
	dwc_otg_enable_global_interrupts(dwc_dev->core_if);

#if 0
	usbcfg = dwc_reg_read(gusbcfg_addr, 0);
	usbcfg &= ~DWC_USBCFG_FRC_HST_MODE;
	dwc_reg_write(gusbcfg_addr, 0, usbcfg);
#endif

	return 0;
fail_hcd:
	free_irq(dwc_dev->irq, dwc_dev);
	if (!dwc_has_feature(dwc_dev->core_if, DWC_HOST_ONLY)) {
		if (dwc_dev->pcd)
			dwc_otg_pcd_remove(dev);
	}
fail_req_irq:
	usb_put_phy(dwc_dev->core_if->xceiv);
fail_xceiv:
	usb_nop_xceiv_unregister();
fail_check_param:
	dwc_otg_cil_remove(dwc_dev->core_if);
fail_cil_init:
	dev_set_drvdata(dev, NULL);
	iounmap(dwc_dev->base);
fail_ioremap:
	release_mem_region(dwc_dev->phys_addr, dwc_dev->base_len);
fail_of_irq:
	kfree(dwc_dev);
fail_dwc_dev:
	return retval;
}
コード例 #13
0
static
void
process(char* edges_sql,
        int64_t start_vid,
        int64_t end_vid,
        bool directed,
        int heuristic,
        double factor,
        double epsilon,
        bool only_cost,
        General_path_element_t **result_tuples,
        size_t *result_count) {
    check_parameters(heuristic, factor, epsilon);

    pgr_SPI_connect();

    PGR_DBG("Load data");
    Pgr_edge_xy_t *edges = NULL;
    size_t total_edges = 0;

    pgr_get_edges_xy(edges_sql, &edges, &total_edges);
    PGR_DBG("Total %ld edges in query:", total_edges);

    if (total_edges == 0) {
        PGR_DBG("No edges found");
        (*result_count) = 0;
        (*result_tuples) = NULL;
        pgr_SPI_finish();
        return;
    }

    PGR_DBG("Starting processing");
    char* log_msg = NULL;
    char* notice_msg = NULL;
    char* err_msg = NULL;
    clock_t start_t = clock();
    do_pgr_astarManyToMany(
            edges, total_edges,
            &start_vid, 1,
            &end_vid, 1,
            directed,
            heuristic,
            factor,
            epsilon,
            only_cost,
            true,
            result_tuples,
            result_count,
            &log_msg,
            &notice_msg,
            &err_msg);

    if (only_cost) {
        time_msg("processing pgr_astarCost(one to one)", start_t, clock());
    } else {
        time_msg("processing pgr_astar(one to one)", start_t, clock());
    }

    if (err_msg && (*result_tuples)) {
        pfree(*result_tuples);
        (*result_count) = 0;
        (*result_tuples) = NULL;
    }

    pgr_global_report(log_msg, notice_msg, err_msg);

    if (log_msg) pfree(log_msg);
    if (notice_msg) pfree(notice_msg);
    if (err_msg) pfree(err_msg);
    if (edges) pfree(edges);

    pgr_SPI_finish();
}
コード例 #14
0
ファイル: main.c プロジェクト: rashadkm/grass_cmake
int main(int argc, char *argv[])
{
    struct GModule *module;
    struct GParams *params;

    int i, ret;
    int red, grn, blu;
    float size;
    double vp_height, z_exag;	/* calculated viewpoint height, z-exag */
    int width, height;		/* output image size */
    char *output_name;

    nv_data data;
    struct render_window *offscreen;

    /* initialize GRASS */
    G_gisinit(argv[0]);

    module = G_define_module();
    G_add_keyword(_("visualization"));
    G_add_keyword(_("graphics"));
    G_add_keyword(_("raster"));
    G_add_keyword(_("vector"));
    G_add_keyword(_("raster3d"));
    module->label = _("Creates a 3D rendering of GIS data.");
    module->description = _("Renders surfaces (raster data), "
			    "2D/3D vector data, and "
			    "volumes (3D raster data) in 3D.");

    params = (struct GParams *)G_malloc(sizeof(struct GParams));

    /* define options, call G_parser() */
    parse_command(argc, argv, params);

    /* check parameters consistency */
    check_parameters(params);

    width = atoi(params->size->answers[0]);
    height = atoi(params->size->answers[1]);
    G_asprintf(&output_name, "%s.%s", params->output->answer,
	       params->format->answer);

    GS_libinit();
    GVL_libinit();

    GS_set_swap_func(swap_gl);

    /* define render window */
    offscreen = Nviz_new_render_window();
    Nviz_init_render_window(offscreen);
    if (Nviz_create_render_window(offscreen, NULL, width, height) == -1)
	G_fatal_error(_("Unable to render data"));
    Nviz_make_current_render_window(offscreen);

    /* initialize nviz data */
    Nviz_init_data(&data);

    /* define default attributes for map objects */
    Nviz_set_surface_attr_default();

    /* set background color */
    Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer));

    /* init view, lights */
    Nviz_init_view(&data);

    /* load raster maps (surface topography) & set attributes (map/constant) */
    load_rasters(params, &data);

    /* set draw mode of loaded surfaces */
    surface_set_draw_mode(params);

    /* load line vector maps */
    if (params->vlines->answer) {
	load_vlines(params, &data);
	/* set attributes of 2d lines */
	vlines_set_attrb(params);
    }

    /* load point vector maps */
    if (params->vpoints->answer) {
	load_vpoints(params, &data);
	/* set attributes for points */
	vpoints_set_attrb(params);
    }

    /* load volumes */
    if (params->volume->answer) {
	load_rasters3d(params, &data);
    }

    /* define isosurfaces for displaying volumes */
    if (params->isosurf_level->answer) {
	add_isosurfs(params, &data);
    }

    /* define slices for displaying volumes */
    if (params->slice->answer) {
	add_slices(params, &data);
    }

    /* focus on loaded data */
    Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);

    /* define view point */
    if (params->exag->answer) {
	z_exag = atof(params->exag->answer);
    }
    else {
	z_exag = Nviz_get_exag();
	G_verbose_message(_("Vertical exaggeration not given, using calculated "
			   "value %.0f"), z_exag);
    }
    Nviz_change_exag(&data, z_exag);

    if (params->height->answer) {
	vp_height = atof(params->height->answer);
    }
    else {
	double min, max;

	Nviz_get_exag_height(&vp_height, &min, &max);
	G_verbose_message(_("Viewpoint height not given, using calculated "
			    "value %.0f"), vp_height);
    }
    Nviz_set_viewpoint_height(vp_height);

    Nviz_set_viewpoint_position(atof(params->pos->answers[0]),
				atof(params->pos->answers[1]));
    Nviz_set_viewpoint_twist(atoi(params->twist->answer));
    Nviz_set_viewpoint_persp(atoi(params->persp->answer));

    if (params->focus->answer) {
	Nviz_set_focus(&data, atof(params->focus->answers[0]),
		       atof(params->focus->answers[1]),
		       atof(params->focus->answers[2]));
    }

    /* set lights */
    Nviz_set_light_position(&data, 1,
			    atof(params->light_pos->answers[0]),
			    atof(params->light_pos->answers[1]),
			    atof(params->light_pos->answers[2]), 0.0);
    Nviz_set_light_bright(&data, 1,
			  atoi(params->light_bright->answer) / 100.0);
    if (G_str_to_color(params->light_color->answer, &red, &grn, &blu) != 1) {
	red = grn = blu = 255;
    }
    Nviz_set_light_color(&data, 1, red, grn, blu);
    Nviz_set_light_ambient(&data, 1,
			   atof(params->light_ambient->answer) / 100.0);

    /* define fringes */
    if (params->fringe->answer) {
	int nw, ne, sw, se;

	i = 0;
	nw = ne = sw = se = 0;
	while (params->fringe->answers[i]) {
	    const char *edge = params->fringe->answers[i++];

	    if (strcmp(edge, "nw") == 0)
		nw = 1;
	    else if (strcmp(edge, "ne") == 0)
		ne = 1;
	    else if (strcmp(edge, "sw") == 0)
		sw = 1;
	    else if (strcmp(edge, "se") == 0)
		se = 1;
	}
	Nviz_new_fringe(&data, -1,
			Nviz_color_from_str(params->fringe_color->answer),
			atof(params->fringe_elev->answer), nw, ne, sw, se);
    }

    /* draw north arrow */
    if (params->north_arrow->answer) {

	if (!params->north_arrow_size->answer)
	    size = Nviz_get_longdim(&data) / 8.;
	else
	    size = atof(params->north_arrow_size->answer);

	Nviz_set_arrow(&data, atoi(params->north_arrow->answers[0]),
		       atoi(params->north_arrow->answers[1]),
		       size,
		       Nviz_color_from_str(params->north_arrow_color->
					   answer));
	Nviz_draw_arrow(&data);
    }

    GS_clear(data.bgcolor);

    /* cutting planes */
    if (params->cplane->answer)
	draw_cplane(params, &data);

    /* draw */
    Nviz_draw_all(&data);

    /* write to image */
    ret = 0;
    if (strcmp(params->format->answer, "ppm") == 0)
	ret = write_img(output_name, FORMAT_PPM);
    if (strcmp(params->format->answer, "tif") == 0)
	ret = write_img(output_name, FORMAT_TIF);

    if (!ret)
	G_fatal_error(_("Unsupported output format"));

    G_done_msg(_("File <%s> created."), output_name);

    Nviz_destroy_data(&data);
    Nviz_destroy_render_window(offscreen);

    G_free((void *)output_name);
    G_free((void *)params);

    exit(EXIT_SUCCESS);
}
コード例 #15
0
ファイル: mainenc.c プロジェクト: cisco/thor
int main(int argc, char **argv)
{
  FILE *infile, *strfile, *reconfile;

  long input_file_size;
  yuv_frame_t orig,ref[MAX_REF_FRAMES];
  yuv_frame_t rec[MAX_REORDER_BUFFER+1];  // Last one is for temp use
  int rec_available[MAX_REORDER_BUFFER] = {0};
  int last_frame_output=-1;
  int num_encoded_frames,num_bits,start_bits,end_bits;
  int sub_gop=1;
  int rec_buffer_idx;
  int k,frame_num,frame_num0,r;
  int frame_offset;
  int ysize,csize;
  long frame_size;
  int width,height;
  int min_interp_depth;
  int last_intra_frame_num = 0;
  uint32_t acc_num_bits;
  snrvals psnr;
  snrvals accsnr;
  double bit_rate_in_kbps;
  enc_params *params;
  encoder_info_t encoder_info;

  int y4m_output;
  // Keep track of last P frame for using the right references for the tail of a sequence in re-ordered modes
  int last_PorI_frame;

  init_use_simd();

  /* Read commands from command line and from configuration file(s) */
  if (argc < 3)
  {
    fprintf(stdout,"usage: %s <parameters>\n",argv[0]);
    fatalerror("");
  }
  params = parse_config_params(argc, argv);
  if (params == NULL)
  {
    fatalerror("Error while reading encoder paramaters.");
  }
  check_parameters(params);

  /* Open files */
  if (!(infile = fopen(params->infilestr,"rb")))
  {
    fatalerror("Could not open in-file for reading.");
  }
  if (!(strfile = fopen(params->outfilestr,"wb")))
  {
    fatalerror("Could not open out-file for writing.");
  }
  reconfile = NULL;
  y4m_output = 0;
  if (params->reconfilestr) {
    char *p;
    if (!(reconfile = fopen(params->reconfilestr,"wb")))
    {
      fatalerror("Could not open recon-file for reading.");
    }
    p = strrchr(params->reconfilestr,'.');
    y4m_output = p != NULL && strcmp(p,".y4m") == 0;
  }
  
  fseek(infile, 0, SEEK_END);
  input_file_size = ftell(infile);
  fseek(infile, 0, SEEK_SET);

  if (y4m_output) {
    fprintf(reconfile,
            "YUV4MPEG2 W%d H%d F%d:1 Ip A%d:%d C%d",
            params->width, params->height, (int)params->frame_rate, params->aspectnum, params->aspectden, params->subsample);
    if (params->input_bitdepth > 8)
      fprintf(reconfile, "p%d XYSCSS=%dp%d", params->input_bitdepth, params->subsample, params->input_bitdepth);
    fprintf(reconfile, "\x0a");
  }

  accsnr.y = 0;
  accsnr.u = 0;
  accsnr.v = 0;
  acc_num_bits = 0;

  height = params->height;
  width = params->width;
  ysize = height * width;
  csize = ysize >> 2*(params->subsample == 420);
  frame_size = (ysize + 2*csize) * (1 + (params->input_bitdepth > 8));
  encoder_info.params = params;

  /* Create frames*/
  TEMPLATE(create_yuv_frame)(&orig,width,height,params->subsample == 420,0,0,params->bitdepth,params->input_bitdepth);
  for (r=0;r<MAX_REORDER_BUFFER+1;r++){
    TEMPLATE(create_yuv_frame)(&rec[r],width,height,params->subsample == 420,0,0,params->bitdepth,params->input_bitdepth);
  }
  for (r=0;r<MAX_REF_FRAMES;r++){ //TODO: Use Long-term frame instead of a large sliding window
    TEMPLATE(create_yuv_frame)(&ref[r],width,height,params->subsample == 420,PADDING_Y,PADDING_Y,params->bitdepth,params->input_bitdepth);
  }
  if (params->interp_ref) {
    for (r=0;r<MAX_SKIP_FRAMES;r++){
      encoder_info.interp_frames[r] = malloc(sizeof(yuv_frame_t));
      TEMPLATE(create_yuv_frame)(encoder_info.interp_frames[r],width,height,params->subsample == 420,PADDING_Y,PADDING_Y,params->bitdepth,params->input_bitdepth);
    }
  }

  /* Initialize main bit stream */
  stream_t stream;
  stream.bitstream = (uint8_t *)malloc(MAX_BUFFER_SIZE * sizeof(uint8_t));
  stream.bitbuf = 0;
  stream.bitrest = 32;
  stream.bytepos = 0;
  stream.bytesize = MAX_BUFFER_SIZE;

  /* Configure encoder */
  encoder_info.orig = &orig;
  for (r=0;r<MAX_REF_FRAMES;r++){
    encoder_info.ref[r] = &ref[r];
  }
  encoder_info.stream = &stream;
  encoder_info.width = width;
  encoder_info.height = height;
  encoder_info.frame_info.max_clpf_strength = encoder_info.params->max_clpf_strength;

  encoder_info.deblock_data = (deblock_data_t *)malloc((height/MIN_PB_SIZE) * (width/MIN_PB_SIZE) * sizeof(deblock_data_t));

  alloc_wmatrices(encoder_info.wmatrix, 0);
  alloc_wmatrices(encoder_info.iwmatrix, 1);

  /* Write sequence header */ //TODO: Separate function for sequence header
  start_bits = get_bit_pos(&stream);
  write_sequence_header(&stream, params);

  end_bits = get_bit_pos(&stream);
  num_bits = end_bits-start_bits;
  acc_num_bits += num_bits;
  printf("SH:  %4d bits\n",num_bits);

  /* Start encoding sequence */
  num_encoded_frames = 0;
  sub_gop = max(1,params->num_reorder_pics+1);

  min_interp_depth = log2i(params->num_reorder_pics+1)-3;
  if (params->frame_rate > 30) min_interp_depth--;

  last_PorI_frame = -1;

  rate_control_t rc;
  encoder_info.rc = &rc;
  if (params->bitrate > 0) {
    int target_bits = (int)(params->bitrate / params->frame_rate);
    int sb_size = 1 << params->log2_sb_size;
    int num_sb = ((width + sb_size - 1) / sb_size) * ((height + sb_size - 1) / sb_size);
    init_rate_control_per_sequence(&rc, target_bits, num_sb);
  }

  for (frame_num0 = params->skip; frame_num0 < (params->skip + params->num_frames) && (frame_num0+1)*frame_size <= input_file_size; frame_num0+=sub_gop)
  {
    for (k=0; k<sub_gop; k++) {
      int r,r1,r2,r3;
      /* Initialize frame info */
      frame_offset = reorder_frame_offset(k,sub_gop,params->dyadic_coding);
      frame_num = frame_num0 + frame_offset;
      // If there is an initial I frame and reordering need to jump to the next P frame
      if (frame_num<params->skip) continue;

      encoder_info.frame_info.frame_num = frame_num - params->skip;
      rec_buffer_idx = encoder_info.frame_info.frame_num%MAX_REORDER_BUFFER;
      encoder_info.rec = &rec[rec_buffer_idx];
      encoder_info.tmp = &rec[MAX_REORDER_BUFFER];
      encoder_info.rec->frame_num = encoder_info.frame_info.frame_num;
      if (params->num_reorder_pics==0) {
        if (params->intra_period > 0)
          encoder_info.frame_info.frame_type = ((num_encoded_frames%params->intra_period) == 0 ? I_FRAME : P_FRAME);
        else
          encoder_info.frame_info.frame_type = (num_encoded_frames == 0 ? I_FRAME : P_FRAME);
      } else {
        if (params->intra_period > 0)
          encoder_info.frame_info.frame_type = ((encoder_info.frame_info.frame_num%params->intra_period) == 0 ? I_FRAME :
              ((encoder_info.frame_info.frame_num%sub_gop)==0 ? P_FRAME : B_FRAME));
        else
          encoder_info.frame_info.frame_type = (encoder_info.frame_info.frame_num == 0 ? I_FRAME :
              ((encoder_info.frame_info.frame_num%sub_gop)==0 ? P_FRAME : B_FRAME));
      }

      int coded_phase = (num_encoded_frames + sub_gop - 2) % sub_gop + 1;
      int b_level = log2i(coded_phase);
      encoder_info.frame_info.b_level = b_level;

      encoder_info.frame_info.phase = encoder_info.frame_info.frame_num % (encoder_info.params->num_reorder_pics + 1);

      if (encoder_info.frame_info.frame_type == I_FRAME){
        encoder_info.frame_info.qp = params->qp + params->dqpI;
        last_intra_frame_num = encoder_info.frame_info.frame_num;
      }
      else if (params->num_reorder_pics==0) {
        if (num_encoded_frames % params->HQperiod)
          encoder_info.frame_info.qp = (int)(params->mqpP*(float)params->qp) + params->dqpP;
        else
          encoder_info.frame_info.qp = params->qp;
      } else {
        if (encoder_info.frame_info.frame_num % sub_gop) {
          if (params->dyadic_coding){
            if (b_level == 0)
              encoder_info.frame_info.qp = (int)(params->mqpB0*(float)params->qp) + params->dqpB0;
            else if (b_level == 1)
              encoder_info.frame_info.qp = (int)(params->mqpB1*(float)params->qp) + params->dqpB1;
            else if (b_level == 2)
              encoder_info.frame_info.qp = (int)(params->mqpB2*(float)params->qp) + params->dqpB2;
            else if (b_level == 3)
              encoder_info.frame_info.qp = (int)(params->mqpB3*(float)params->qp) + params->dqpB3;
            else
              encoder_info.frame_info.qp = (int)(params->mqpB*(float)params->qp) + params->dqpB;
          }
          else {
            encoder_info.frame_info.qp = (int)(params->mqpB*(float)params->qp) + params->dqpB;
          }
        }  else {
          if (encoder_info.frame_info.frame_num % params->HQperiod) {
            encoder_info.frame_info.qp = (int)(params->mqpP*(float)params->qp) + params->dqpP;
          } else
            encoder_info.frame_info.qp = params->qp;
        }
      }
      encoder_info.frame_info.qp = clip(encoder_info.frame_info.qp, 0, MAX_QP);

      encoder_info.frame_info.num_ref = encoder_info.frame_info.frame_type == I_FRAME ? 0 : min(num_encoded_frames,params->max_num_ref);
      encoder_info.frame_info.interp_ref = 0;

      if (encoder_info.frame_info.num_ref > 0) {
        if (params->num_reorder_pics > 0) {
          if (params->dyadic_coding) {
            /* if we have a P frame then use the previous P frame as a reference */
            if ((num_encoded_frames-1) % sub_gop == 0) {
              if (num_encoded_frames==1)
                encoder_info.frame_info.ref_array[0] = 0;
              else
                encoder_info.frame_info.ref_array[0] = sub_gop-1;
              if (encoder_info.frame_info.num_ref>1 )
                encoder_info.frame_info.ref_array[1] = min(MAX_REF_FRAMES-1,min(num_encoded_frames-1,2*sub_gop-1));

              for (r=2;r<encoder_info.frame_info.num_ref;r++){
                encoder_info.frame_info.ref_array[r] = r-2;
              }

            } else if (encoder_info.frame_info.num_ref>0){

              int display_phase =  (encoder_info.frame_info.frame_num-1) % sub_gop;
              int ref_offset=sub_gop>>(b_level+1);
              if (b_level >= min_interp_depth && params->interp_ref == 1) {
                // Need to add another reference if we are at the beginning
                if (encoder_info.frame_info.num_ref==2) encoder_info.frame_info.num_ref++;

                encoder_info.frame_info.interp_ref = params->interp_ref;

                encoder_info.frame_info.ref_array[1]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase-ref_offset+1]-1);
                encoder_info.frame_info.ref_array[2]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase+ref_offset+1]-1);

                // Interpolate these two reference frames to make a new frame
                encoder_info.frame_info.ref_array[0]=-1;
                // Add this interpolated frame to the reference buffer and use it as the first reference
                yuv_frame_t* ref1=encoder_info.ref[encoder_info.frame_info.ref_array[1]];
                yuv_frame_t* ref2=encoder_info.ref[encoder_info.frame_info.ref_array[2]];
                TEMPLATE(interpolate_frames)(encoder_info.interp_frames[0], ref1, ref2, 2, 1);
                TEMPLATE(pad_yuv_frame)(encoder_info.interp_frames[0]);
                encoder_info.interp_frames[0]->frame_num = encoder_info.frame_info.frame_num;
                /* use most recent frames for the last ref(s)*/
                for (r=3;r<encoder_info.frame_info.num_ref;r++){
                  encoder_info.frame_info.ref_array[r] = r-3;
                }
              } else {
                encoder_info.frame_info.ref_array[0]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase-ref_offset+1]-1);
                encoder_info.frame_info.ref_array[1]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase+ref_offset+1]-1);

                /* use most recent frames for the last ref(s)*/
                for (r=2;r<encoder_info.frame_info.num_ref;r++){
                  encoder_info.frame_info.ref_array[r] = r-2;
                }

              }
            }
          } else {
            /* if we have a P frame then use the previous P frame as a reference */
            if ((num_encoded_frames-1) % sub_gop == 0) {
              if (num_encoded_frames==1)
                encoder_info.frame_info.ref_array[0] = 0;
              else
                encoder_info.frame_info.ref_array[0] = sub_gop-1;
              if (encoder_info.frame_info.num_ref>1 )
                encoder_info.frame_info.ref_array[1] = min(MAX_REF_FRAMES-1,min(num_encoded_frames-1,2*sub_gop-1));

              for (r=2;r<encoder_info.frame_info.num_ref;r++){
                encoder_info.frame_info.ref_array[r] = r-1;
              }

            } else {
              if (params->interp_ref > 0 && params->interp_ref == 1) {
                // Need to add another reference if we are at the beginning
                if (encoder_info.frame_info.num_ref==2) encoder_info.frame_info.num_ref++;

                encoder_info.frame_info.interp_ref = params->interp_ref;

                // Use the last encoded frame as the first true ref
                if (encoder_info.frame_info.num_ref>0) {
                  encoder_info.frame_info.ref_array[1] = 0;
                }
                /* Use the subsequent P frame as the 2nd ref */
                int phase = (num_encoded_frames + sub_gop - 2) % sub_gop;
                if (encoder_info.frame_info.num_ref>1) {
                  if (phase==0)
                    encoder_info.frame_info.ref_array[2] = min(sub_gop, num_encoded_frames-1);
                  else
                    encoder_info.frame_info.ref_array[2] = min(phase, num_encoded_frames-1);
                }
                // Interpolate these two reference frames to make a new frame
                encoder_info.frame_info.ref_array[0]=-1;
                // Add this interpolated frame to the reference buffer and use it as the first reference
                yuv_frame_t* ref1=encoder_info.ref[encoder_info.frame_info.ref_array[1]];
                yuv_frame_t* ref2=encoder_info.ref[encoder_info.frame_info.ref_array[2]];
                TEMPLATE(interpolate_frames)(encoder_info.interp_frames[0], ref1, ref2, sub_gop-phase,phase!=0 ? 1 : sub_gop-phase-1);
                TEMPLATE(pad_yuv_frame)(encoder_info.interp_frames[0]);
                encoder_info.interp_frames[0]->frame_num = encoder_info.frame_info.frame_num;

                /* Use the prior P frame as the 4th ref */
                if (encoder_info.frame_info.num_ref>2) {
                  encoder_info.frame_info.ref_array[3] = min(phase ? phase + sub_gop : 2*sub_gop, num_encoded_frames-1);
                }
                /* use most recent frames for the last ref(s)*/
                for (r=4;r<encoder_info.frame_info.num_ref;r++){
                  encoder_info.frame_info.ref_array[r] = r-4+1;
                }


              } else {
                // Use the last encoded frame as the first ref
                if (encoder_info.frame_info.num_ref>0) {
                  encoder_info.frame_info.ref_array[0] = 0;
                }
                /* Use the subsequent P frame as the 2nd ref */
                int phase = (num_encoded_frames + sub_gop - 2) % sub_gop;
                if (encoder_info.frame_info.num_ref>1) {
                  if (phase==0)
                    encoder_info.frame_info.ref_array[1] = min(sub_gop, num_encoded_frames-1);
                  else
                    encoder_info.frame_info.ref_array[1] = min(phase, num_encoded_frames-1);
                }
                /* Use the prior P frame as the 3rd ref */
                if (encoder_info.frame_info.num_ref>2) {
                  encoder_info.frame_info.ref_array[2] = min(phase ? phase + sub_gop : 2*sub_gop, num_encoded_frames-1);
                }
                /* use most recent frames for the last ref(s)*/
                for (r=3;r<encoder_info.frame_info.num_ref;r++){
                  encoder_info.frame_info.ref_array[r] = r-3+1;
                }
              }
            }
          }

          if (encoder_info.params->num_reorder_pics == 2 && encoder_info.frame_info.frame_type == B_FRAME && b_level == 0) {
            int off = encoder_info.params->interp_ref == 1 ? 1 : 0;
            int tmp = encoder_info.frame_info.ref_array[0 + off];
            encoder_info.frame_info.ref_array[0 + off] = encoder_info.frame_info.ref_array[1 + off];
            encoder_info.frame_info.ref_array[1 + off] = tmp;
          }

        } else {
          if (encoder_info.frame_info.num_ref>=1){
            /* If num_ref==1 always use most recent frame */
            encoder_info.frame_info.ref_array[0] = last_PorI_frame;
          }

          if (encoder_info.frame_info.num_ref==2){
            /* If num_ref==2 use most recent LQ frame and most recent HQ frame */
            r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1;
            encoder_info.frame_info.ref_array[1] = r1;
          }
          else if (encoder_info.frame_info.num_ref==3){
            r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1;
            r2 = r1==1 ? 2 : 1;
            encoder_info.frame_info.ref_array[1] = r1;
            encoder_info.frame_info.ref_array[2] = r2;
          }
          else if (encoder_info.frame_info.num_ref==4){
            r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1;
            r2 = r1==1 ? 2 : 1;
            r3 = r2+1;
            if (r3==r1) r3 += 1;
            encoder_info.frame_info.ref_array[1] = r1;
            encoder_info.frame_info.ref_array[2] = r2;
            encoder_info.frame_info.ref_array[3] = r3;
          }
          else{
            for (r=1;r<encoder_info.frame_info.num_ref;r++){
              encoder_info.frame_info.ref_array[r] = r;
            }
          }
        }
      }
コード例 #16
0
int main(int argc, char **argv) {

  // Parameters
  po::variables_map vm = get_parameters(argc,argv);
  // vector for options values
  std::vector<str> opt;

  // Read PDB
  IMP_NEW(IMP::Model, smodel, ());
  IMP::Pointer<atom::ATOMPDBSelector> ssel= new atom::ATOMPDBSelector();
  // Read only first model
  if(digest_parameter("i",vm,opt) == false) {
      std::cout << "Input file not found or missing parameter." << std::endl;
      exit(0);
  }
  atom::Hierarchy smh = atom::read_pdb(opt[0],smodel,ssel,true);
  IMP::ParticlesTemp sps = core::get_leaves(smh);
//  atom::add_radii(smh);
  double resolution = vm["res"].as<double>();
  IMP_NEW(em2d::SpiderImageReaderWriter,  srw, ());
  IMP_NEW(em::MRCReaderWriter,  mrw, ());


  // Generate a map
  if(digest_parameter("map",vm,opt)) {
    if( check_parameters(vm,"apix") == false) {
      std::cerr << "The requested --map option is missing "
                   "additional parameters"  << std::endl;
      std::exit(0);
    }
    double apix= vm["apix"].as<double>();
    str fn_map= vm["map"].as<str>();
    std::cout << "Generating map ... " << fn_map << std::endl;
    em::SampledDensityMap *map= new em::SampledDensityMap(sps,resolution,apix);
    em::write_map(map,fn_map.c_str(),mrw);
  }

  // Project IMAGES
  if( vm.count("proj_img")) {
    if(check_parameters(vm,"np,apix,size_i,proj_dist,proj_params") == false) {
      std::cerr << "--proj is missing additional parameters." << std::endl;
      std::exit(0);
    }
    // Parameters
    unsigned int np=vm["np"].as<unsigned int>();
    double apix       = vm["apix"].as<double>();
    digest_parameter("size_i",vm,opt);
    unsigned int cols = std::atoi(opt[0].c_str());
    unsigned int rows =std::atoi(opt[1].c_str());
    digest_parameter("proj_dist",vm,opt);
    em2d::RegistrationResults registration_values=
                            get_registration_values(opt,np);
    em2d::ProjectingOptions options( apix, resolution);
    em2d::Images projections = em2d::get_projections(sps,
                                                     registration_values,
                                                     rows,
                                                     cols,
                                                     options);
    // Normalize and add noise if requested
    np = registration_values.size(); // for the case when the values are read
    if(vm.count("SNR")) {
      double SNR = vm["SNR"].as<double>();
      for (unsigned int i=0;i<np;++i) {
        em2d::do_normalize(projections[i]);
        // Noise added of mean = 0  and stddev = stddev_signal / sqrt(SNR)
        // As the image is normalized, stddev_signal is 1.0
        em2d::add_noise(
                  projections[i]->get_data(),0.0,1./sqrt(SNR), "gaussian");
      }
    }
    // Save projections and projection parameters
    IMP::Strings proj_names;
    if(digest_parameter("proj_names",vm,opt)) {
      proj_names = em2d::read_selection_file(opt[0]);
    } else {
      proj_names = em2d::create_filenames(np,"proj","spi");
    }
    for (unsigned int i=0;i<np;++i) {
      projections[i]->write(proj_names[i],srw);
    }
    if(digest_parameter("proj_params",vm,opt)) {
      em2d::write_registration_results(opt[0],registration_values);
    }
  }

  // Project PDBs
  if(vm.count("proj_pdb")) {
    IMP::String param_error = "More parameters are required with --proj_pdb\n";
    IMP_USAGE_CHECK(check_parameters(vm,"np,proj_dist"),param_error);
    // Parameters
    unsigned int np=vm["np"].as<unsigned int>();
    digest_parameter("proj_dist",vm,opt);
    em2d::RegistrationResults registration_values=
                      get_registration_values(opt,np);
    np = registration_values.size(); // for the case when the values are read
    // Get coordinates
    unsigned int n_atoms=sps.size();
    alg::Vector3Ds pdb_atoms(n_atoms);
    for (unsigned i=0;i<n_atoms;++i ) {
      core::XYZ xyz(sps[i]);
      pdb_atoms[i] = xyz.get_coordinates();
    }
    alg::Vector3D centroid = alg::get_centroid(pdb_atoms);
    // Project
    IMP::Strings proj_names;
    if(vm.count("proj_names")) {
      proj_names=em2d::read_selection_file(vm["proj_names"].as<IMP::String>());
    } else {
      proj_names = em2d::create_filenames(np,"proj","pdb");
    }
    for(unsigned int i=0;i<np;++i) {
      // To project vectors here, the shift is understood a as translation
      alg::Vector3D translation = registration_values[i].get_shift_3d();
      alg::Rotation3D R = registration_values[i].get_rotation();
      alg::Vector2Ds projected_points=
                em2d::do_project_vectors(pdb_atoms,R,translation,centroid);
      // Save projection
      em2d::write_vectors_as_pdb(projected_points,proj_names[i]);
    }
    // Save projection parameters
    if(digest_parameter("proj_params",vm,opt)) {
      em2d::write_registration_results(opt[0],registration_values);
    }
  }
}
コード例 #17
0
ファイル: sfs_c_pnt.c プロジェクト: richwolski/bluesky
/*
 * Parent: wait for kids to get ready, start them, wait for them to
 * finish, read and accumulate results.
 */
void
parent(
    int		children,
    int		load,
    char *	mix_file,
    char *	iodist_file)
{
    char	string[80];	/* for interactive startup */
    int		result;
    int		invalid_run;	/* holds INVALID RUN status */
    int		runtime_val;	/* store Runtime value to be printed later */
    int		Saveerrno;
    char	*nameptr;
#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
    struct sigaction sig_act, old_sig_act;
#endif

    /*
     * Setup a SIGCHLD handler in case one of our beloved children dies
     * before its time.
     */
#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
    /* use XOPEN signal handling */

    sig_act.sa_handler = sfs_reaper;
    (void)sigemptyset(&sig_act.sa_mask);
    sig_act.sa_flags = 0;
    if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) {
        perror("sigaction failed: SIGCHLD");
        exit(66);
    }
#else
    (void) signal(SIGCHLD, sfs_reaper);
#endif

    /* Change my name for error logging */
    if ((nameptr = strrchr(sfs_Myname, '/')) != NULL)
        sfs_Myname = ++nameptr;

    /*
     * store the Runtime value; to be printed in results
     */
    if (Prime_client)
	runtime_val = Runtime - MULTICLIENT_OFFSET;
    else runtime_val = Runtime;

    /* print logfile header information */
    (void) fprintf(stdout,"\n");
    (void) fprintf(stdout,
    "************************************************************************");
    (void) fprintf(stdout,"\n");
    (void) fflush(stdout);

    /* print sfs information */
    if (Prime_client) {
	(void) fprintf(stderr,
		"\nSFS NFS Version %d Benchmark Client Logfile, %s\n",
			nfs_version, lad_timestamp());
	(void) fprintf(stderr, "\tClient hostname = %s\n", lad_hostname);
	(void) fprintf(stderr, "\tPrime Client hostname = %s\n",
			Prime_client);
    }

    (void) fprintf(stderr, "\nSPEC SFS Benchmark Version %s, Creation - %s\n",
				SFS_VERSION_NUM, SFS_VERSION_DATE);
    (void) fprintf(stderr, "NFS Protocol Version %d\n", nfs_version);

    /* mount test directories */
    (void) fprintf(stderr, "%s Mounting %d remote test directories.\n",
		lad_timestamp(), children);
    synchronize_children(children);
    (void) fprintf(stderr, "%s Completed.", lad_timestamp());

    /*
     * if multi-client execution then tell Prime-Client I'm done mounting
     * test directories.
     */
    if (Prime_client) {
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
		       "%s Sending DONE-MOUNT message to Prime Client(%s).\n",
			lad_timestamp(), Prime_client);
	if ((result =
	    (int) signal_Prime_Client("CLIENT_SIGNAL", ""))
		== (int) RPC_SUCCESS) {
	    (void) fprintf(stderr, "%s Completed.",lad_timestamp());
	    (void) fflush(stderr);
	} else {
	    (void) fprintf(stderr, "\n");
	    (void) fprintf(stderr,
		"%s:  error %d sending DONE-MOUNT message to Prime Client\n",
		sfs_Myname, result);
	    /* cleanup and exit */
#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
	    sig_act.sa_handler = SIG_DFL;
	    (void)sigemptyset(&sig_act.sa_mask);
	    sig_act.sa_flags = 0;
	    if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) {
	        perror("sigaction failed: SIGCHLD");
	        exit(67);
	    }
#else
	    (void) signal(SIGCHLD, SIG_DFL);
#endif
	    (void) generic_kill(0, SIGINT);
	    exit(68);
	}

	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
		    "%s Waiting on DO-INIT message from Prime Client(%s).\n",
		    lad_timestamp(), Prime_client);
	(void) fflush(stderr);

	/*
	 * wait for DO-INIT message from Prime Client
	 * sfs_syncd (rpc server) sends a SIGUSR1 signal;
	 * user can also terminate experiment anytime they wish
	 * with SIGINT or SIGTERM signal
	 */
	(void) pause();
	(void) fprintf(stderr, "%s Received.",lad_timestamp());
	(void) fflush(stderr);

    } /* send DONE-MOUNT and got DO-INIT message */

    /* initialize test directories */
    (void) fprintf(stderr, "\n");
    (void) fprintf(stderr, "%s Initializing test directories.\n",
		    lad_timestamp());

    /* send SIGUSR1 to child processes */
    (void) generic_kill(0, SIGUSR1);
    synchronize_children(children);
    (void) fprintf(stderr, "%s Completed.", lad_timestamp());
    (void) fflush(stderr);

    /*
     * if multi-client execution then tell Prime-Client I'm done initializing
     * and wait for synchronized do warmupmessage.
     */
    if (Prime_client) {
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
		    "%s Sending DONE-INIT message to Prime Client(%s).\n",
			lad_timestamp(), Prime_client);
	if ((result =
	    (int) signal_Prime_Client("CLIENT_SIGNAL",""))
		== (int) RPC_SUCCESS) {
	    (void) fprintf(stderr, "%s Completed.",lad_timestamp());
	    (void) fflush(stderr);
	} else {
	    (void) fprintf(stderr, "\n");
	    (void) fprintf(stderr,
		    "%s:  error %d sending DONE-INIT message to Prime Client\n",
		    sfs_Myname, result);
	    /* cleanup and exit */
#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
	    sig_act.sa_handler = SIG_DFL;
	    (void)sigemptyset(&sig_act.sa_mask);
	    sig_act.sa_flags = 0;
	    if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) {
	        perror("sigaction failed: SIGCHLD");
	        exit(69);
	    }
#else
	    (void) signal(SIGCHLD, SIG_DFL);
#endif
	    (void) generic_kill(0, SIGINT);
	    exit(70);
	}
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
		  "%s Waiting on DO-WARMUP message from Prime Client(%s).\n",
		    lad_timestamp(), Prime_client);
	(void) fflush(stderr);

	/*
	 * wait for DO-WARMUP message from Prime Client
	 * sfs_syncd (rpc server) sends a SIGUSR1 signal;
	 * user can also terminate experiment anytime they wish
	 * with SIGINT or SIGTERM signal
	 */
	(void) pause();
	(void) fprintf(stderr, "%s Received.",lad_timestamp());
	(void) fflush(stderr);

    } /* send DONE-INIT and got DO-WARMUP message */

    if (Populate_only) {
	(void) fprintf(stderr, "\nPopulating directories and exiting.\n");
#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
	sig_act.sa_handler = SIG_DFL;
	(void)sigemptyset(&sig_act.sa_mask);
	sig_act.sa_flags = 0;
	if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) {
	    perror("sigaction failed: SIGCHLD");
	    exit(71);
	}
#else
	(void) signal(SIGCHLD, SIG_DFL);
#endif
	(void) generic_kill(0, SIGUSR1);
	while (wait((int *) 0) != -1) {
	    /* nop */
	}
	return;
    }

    /* do warm-up */
    if (Warmuptime) {
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr, "%s Performing %d seconds pretest warmup.\n",
		lad_timestamp(), Warmuptime);
	(void) generic_kill(0, SIGUSR1);
	(void) sleep(Warmuptime);
	(void) fprintf(stderr, "%s Completed.", lad_timestamp());
	(void) fflush(stderr);
    }

    if (Interactive) {
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr, "Hit <return> when ready to start test ...");
	(void) fgets(string,10,stdin);
    }

    /*
     * if multi-client execution then tell Prime-Client I'm done warm-up
     * and wait for synchronized Start message.
     */
    if (Prime_client) {
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
			"%s Sending READY message to Prime Client(%s).\n",
			lad_timestamp(), Prime_client);
	if ((result =
	    (int) signal_Prime_Client("CLIENT_SIGNAL",""))
		== (int) RPC_SUCCESS) {
	    (void) fprintf(stderr, "%s Completed.",lad_timestamp());
	    (void) fflush(stderr);
	} else {
	    (void) fprintf(stderr, "\n");
	    (void) fprintf(stderr,
		    "%s:  error %d sending READY message to Prime Client\n",
		    sfs_Myname, result);
	    /* cleanup and exit */
#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
	    sig_act.sa_handler = SIG_DFL;
	    (void)sigemptyset(&sig_act.sa_mask);
	    sig_act.sa_flags = 0;
	    if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) {
	        perror("sigaction failed: SIGCHLD");
	        exit(72);
	    }
#else
	    (void) signal(SIGCHLD, SIG_DFL);
#endif
	    (void) generic_kill(0, SIGINT);
	    exit(73);
	}

	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
		    "%s Waiting on START message from Prime Client(%s).\n",
		    lad_timestamp(), Prime_client);
	(void) fflush(stderr);

	/*
	 * wait for START message from Prime Client
	 * sfs_syncd (rpc server) sends a SIGUSR1 signal;
	 * user can also terminate experiment anytime they wish
	 * with SIGINT or SIGTERM signal
	 */
	(void) pause();
	(void) fprintf(stderr, "%s Received.",lad_timestamp());
	(void) fflush(stderr);

    } /* send READY and got START message */

    (void) fprintf(stderr, "\n");
    if (Timed_run) {
	if (Prime_client) {
	    (void) fprintf(stderr, "%s Starting %d seconds test run.\n",
		    lad_timestamp(), Runtime - MULTICLIENT_OFFSET);
	} else {
	    (void) fprintf(stderr, "%s Starting %d seconds test run.\n",
		    lad_timestamp(), Runtime);
	}
    } else {
	(void) fprintf(stderr, "%s Starting %d call test run.\n",
		lad_timestamp(), Ops[TOTAL].target_calls);
    }
    (void) fflush(stderr);

    /* signal child processes to go */
    (void) generic_kill(0, SIGUSR1);

    if (Timed_run)
	(void) sleep(Runtime);

#if (defined(_XOPEN_SOURCE) || defined(USE_POSIX_SIGNALS))
    sig_act.sa_handler = SIG_DFL;
    (void)sigemptyset(&sig_act.sa_mask);
    sig_act.sa_flags = 0;
    if (sigaction(SIGCHLD,&sig_act,&old_sig_act) == -1) {
        perror("sigaction failed: SIGCHLD");
        exit(74);
    }
#else
    (void) signal(SIGCHLD, SIG_DFL);
#endif

    if (Timed_run) {
	/*
	 * The parent and the prime are both sleeping for Runtime.
	 * If the parent wakes up first, he'll tell the children to stop.
	 * If the prime wakes up first, he'll send an SIGALRM (via syncd)
	 * to the parent.  That alarm may arrive while the parent is still
	 * asleep, which is ok, or after he has starting running.  Since
	 * the parent SIGARLM catcher does nothing, there is no harm done
	 * by the extra signal in this case.
	 *
	 * Perhaps, if running multi we should just wait (pause()) for
	 * the STOP signal, like we waited for the start signal.  It would
	 * be more obvious.  The only drawback is the OTW rpc delay in
	 * receiving the stop signal from the prime.
	 */
	(void) generic_kill(0, SIGUSR2); /* tell children to finish */
    }

    /* Wait for all the children to finish/die */
    while (wait((int *) 0) != -1) {
	/* nop */
    }

    (void) fprintf(stderr, "%s Completed.", lad_timestamp());
    (void) fflush(stdout);
    (void) fflush(stderr);

    /* Initialize and sum up counters */
    collect_counters(children);
    if ((invalid_run = check_counters()) == 0)
	invalid_run = check_parameters(iodist_file, mix_file, runtime_val);

    /* print test results */
    print_results(children, load, mix_file,
		  invalid_run, runtime_val, iodist_file);

    /*
     * if multi-client execution then tell Prime client that
     * I'm done with 'real' work and wait for move-data message
     * and send data across
     */
    if (Prime_client) {
	(void) fprintf(stderr,
			"%s Sending DONE-TEST message to Prime Client(%s).\n",
			lad_timestamp(), Prime_client);
	if ((result =
	    (int) signal_Prime_Client("CLIENT_SIGNAL",""))
		== (int) RPC_SUCCESS) {
	    (void) fprintf(stderr, "%s Completed.", lad_timestamp());
	    (void) fflush(stderr);
	} else {
	    Saveerrno = errno;
	    (void) fprintf(stderr, "\n");
	    (void) fprintf(stderr,
		    "%s:  error %d sending DONE-TEST message to Prime Client\n",
		    sfs_Myname, result);
	    errno = Saveerrno;
	    perror("signal_Prime_Client");
	    /* cleanup and exit */
	    (void) generic_kill(0, SIGINT);
	    exit(75);
	}

	/*
	 * wait for MOVE-DATA message from Prime Client before
	 * sending send results.
	 */
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr,
		"%s Waiting on MOVE-DATA message from Prime Client(%s).\n",
		lad_timestamp(), Prime_client);
	(void) fflush(stderr);
	(void) pause();
	(void) fprintf(stderr, "%s Received.", lad_timestamp());
	(void) fprintf(stderr, "\n");
	(void) fprintf(stderr, "%s Sending results to Prime Client(%s)\n",
		lad_timestamp(), Prime_client);
	(void) fflush(stderr);


	if ((result = (int) signal_Prime_Client("CLIENT_DATA",
	    Client_results)) == (int) RPC_SUCCESS) {
	    (void) fprintf(stderr, "%s Completed.\n", lad_timestamp());
	    (void) fflush(stderr);
	} else {
	    Saveerrno = errno;
	    (void) fprintf(stderr, "\n");
	    (void) fprintf(stderr,
		    "%s: error %d sending client's result to Prime Client\n",
		    sfs_Myname, result);
	    errno = Saveerrno;
	    perror("signal_Prime_Client");
	    /* cleanup and exit */
	    (void) generic_kill(0, SIGINT);
	    exit(76);
	}
    } /* sent done, got move-data and sent data */

    (void) fprintf(stdout,"\n");
    (void) fprintf(stdout,
    "************************************************************************");
    (void) fprintf(stdout,"\n");

} /* parent */
コード例 #18
0
ファイル: parameters.cpp プロジェクト: b1234561/viterbi
void parameters::read_parameters()
{
	unsigned int i=1;
	string in_str;
	while (i<argv.size())
	{
		in_str = argv[i];
		if (in_str == "--vcf") // VCF file to process
		{
			vcf_format.push_back( true );
			vcf_compressed.push_back( false );
			if (!stream_in)
			{
				vcf_filenames.push_back(get_arg(i+1));
				i++;
			}
		}
		else if (in_str == "--bcf") // BCF file to process
		{
			vcf_format.push_back( false );
			vcf_compressed.push_back( false );
			if (!stream_in)
			{
				vcf_filenames.push_back(get_arg(i+1));
				i++;
			}
		}
		else if (in_str == "--bed") {
			if (BED_file == "")
			{
				BED_file = get_arg(i+1); i++; BED_exclude=false;
			}
			else
				LOG.error(" Multiple --bed/--exclude-bed options can not be used together.");
		}
		else if (in_str == "-c") {stream_out = true;}						// Write output to stream
		else if (in_str == "--chr") { chrs_to_keep.insert(get_arg(i+1)); i++; }					// Chromosome to process
		else if (in_str == "--contigs") { contigs_file = get_arg(i+1); i++;}	// Contigs file for header
		else if (in_str == "--exclude-bed") {
			if (BED_file == "")
			{
				BED_file = get_arg(i+1); i++; BED_exclude=true;
			}
			else
				LOG.error(" Multiple --bed/--exclude-bed options can not be used together.");
		}
		else if (in_str == "--exclude") { snps_to_exclude_file = get_arg(i+1); i++; }				// List of SNPs to exclude
		else if (in_str == "--exclude-positions") { exclude_positions_file = get_arg(i+1); i++; }
		else if (in_str == "--exclude-positions-overlap") { exclude_positions_overlap_file = get_arg(i+1); i++; }
		else if (in_str == "--from-bp") { start_pos = atoi(get_arg(i+1).c_str()); i++; }					// Start position
		else if (in_str == "--get-INFO") {
			if (INFO_to_extract.empty())
				num_outputs++;
			INFO_to_extract.push_back(get_arg(i+1)); i++;}	// Add to list of INFO fields to extract
		else if (in_str == "--gzvcf") // Compressed VCF file to process
		{
			vcf_format.push_back( true );
			vcf_compressed.push_back( true );
			if (!stream_in)
			{
				vcf_filenames.push_back(get_arg(i+1));
				i++;
			}
		}
		else if (in_str == "--hwe") { max_alleles = 2; min_HWE_pvalue = atof(get_arg(i+1).c_str()); i++; }					// Minimum per-site HWE p-value
		else if (in_str == "--indv") { indv_to_keep.insert(get_arg(i+1)); i++; }						// List of individuals to keep
		else if (in_str == "--invert-mask") { mask_file = get_arg(i+1); i++; invert_mask = true; }
		else if (in_str == "--keep-filtered") { site_filter_flags_to_keep.insert(get_arg(i+1)); i++; }	// Remove a specific filter flag
		else if (in_str == "--keep") { indv_keep_file = get_arg(i+1); i++; }						// List of individuals to keep
		else if (in_str == "--keep-only-indels") { keep_only_indels = true; }
		else if (in_str == "--keep-INFO") { site_INFO_flags_to_keep.insert(get_arg(i+1)); i++; }	// Filter sites by INFO flags
		else if (in_str == "--mac") { min_mac = atoi(get_arg(i+1).c_str()); i++; }								// Minimum Site MAC
		else if (in_str == "--maf") { min_maf = atof(get_arg(i+1).c_str()); i++; }								// Minimum Site MAF
		else if (in_str == "--mask-min") { min_kept_mask_value = atoi(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--mask") { mask_file = get_arg(i+1); i++; invert_mask = false; }
		else if (in_str == "--max-alleles") { max_alleles = atoi(get_arg(i+1).c_str()); i++; }				// Maximum number of alleles per-site
		else if (in_str == "--max-mac") { max_mac = atoi(get_arg(i+1).c_str()); i++; }						// Maximum site MAC
		else if (in_str == "--max-maf") { max_maf = atof(get_arg(i+1).c_str()); i++; }						// Maximum Site MAF
		else if (in_str == "--max-meanDP") { max_mean_depth = atof(get_arg(i+1).c_str()); i++; }			// Site Maximum mean depth across individuals
		else if (in_str == "--max-missing") { min_site_call_rate = atof(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--max-missing-count") { max_missing_call_count = atoi(get_arg(i+1).c_str()); i++; } // Site maximum missing genotypes
		else if (in_str == "--max-non-ref-ac") { max_non_ref_ac = atoi(get_arg(i+1).c_str()); i++; }		// Minimum Site non-ref AC
		else if (in_str == "--max-non-ref-af") { max_non_ref_af = atof(get_arg(i+1).c_str()); i++; }		// Minimum Site non-ref AF
		else if (in_str == "--maxDP") { max_genotype_depth = atoi(get_arg(i+1).c_str()); i++; }				// Maximum genotype depth
		else if (in_str == "--max-indv") {max_N_indv = atoi(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--min-alleles") { min_alleles = atoi(get_arg(i+1).c_str()); i++; }				// Minimum number of alleles per-site
		else if (in_str == "--min-meanDP") { min_mean_depth = atof(get_arg(i+1).c_str()); i++; }			// Site Minimum mean depth
		else if (in_str == "--min-r2") { min_r2 = atof(get_arg(i+1).c_str()); i++; }					// Min r^2 for LD output
		else if (in_str == "--minDP") { min_genotype_depth = atoi(get_arg(i+1).c_str()); i++; }				// Minimum genotype depth
		else if (in_str == "--minGQ") { min_genotype_quality = atof(get_arg(i+1).c_str()); i++; }			// Minimum genotype quality
		else if (in_str == "--minQ") { min_quality = atof(get_arg(i+1).c_str()); i++; }						// Minimum per-site quality
		else if (in_str == "--non-ref-ac") { min_non_ref_ac = atoi(get_arg(i+1).c_str()); i++; }				// Minimum Site non-ref AC
		else if (in_str == "--non-ref-af") { min_non_ref_af = atof(get_arg(i+1).c_str()); i++; }				// Minimum Site non-ref AF
		else if (in_str == "--not-chr") { chrs_to_exclude.insert(get_arg(i+1)); i++; }					// Chromosome to process
		else if (in_str == "--out") { output_prefix = get_arg(i+1); i++; }							// Output file prefix
		else if (in_str == "--phased") phased_only = true;								// Keep only phased individuals / sites
		else if (in_str == "--positions") { positions_file = get_arg(i+1); i++; }
		else if (in_str == "--positions-overlap") { positions_overlap_file = get_arg(i+1); i++; }
		else if (in_str == "--remove-filtered-all") remove_all_filtered_sites = true;							// Remove sites flagged as filtered
		else if (in_str == "--remove-filtered-geno-all") remove_all_filtered_genotypes = true;			// Remove genotypes flagged as filtered
		else if (in_str == "--remove-filtered-geno") { geno_filter_flags_to_exclude.insert(get_arg(i+1)); i++; }		// Remove genotypes flagged as filtered
		else if (in_str == "--remove-filtered") { site_filter_flags_to_exclude.insert(get_arg(i+1)); i++; }	// Remove a specific filter flag
		else if (in_str == "--remove-indels") { remove_indels = true; }
		else if (in_str == "--remove-indv") { indv_to_exclude.insert(get_arg(i+1)); i++; }						// List of individuals to keep
		else if (in_str == "--remove-INFO") { site_INFO_flags_to_remove.insert(get_arg(i+1)); i++; }	// Filter sites by INFO flags
		else if (in_str == "--remove") { indv_exclude_file = get_arg(i+1); i++; }					// List of individuals to exclude
		else if (in_str == "--seed") { seed = atoi(get_arg(i+1).c_str()); generator.seed(seed); i++; }
		else if (in_str == "--snp") { snps_to_keep.insert(get_arg(i+1)); i++; }						// SNP to keep
		else if (in_str == "--snps") { snps_to_keep_file = get_arg(i+1); i++; }						// List of SNPs to keep
		else if (in_str == "--stdout") {stream_out = true; }						// Write output to stream
		else if (in_str == "--temp") { temp_dir = get_arg(i+1); i++;}	// Directory for vcftools temporary files
		else if (in_str == "--to-bp") { end_pos = atoi(get_arg(i+1).c_str()); i++; }						// End position
		else if (in_str == "--thin") { min_interSNP_distance = atoi(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--Ne") { Ne = atof(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--map") { map_filename = get_arg(i+1); i++; }
		else if (in_str == "--recomb") { recomb_rate = atof(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--test-indv") { viterbi_indv.insert(get_arg(i+1)); i++; }
		else if (in_str == "--error") { p_error = atof(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--maxthreads") { max_threads = atoi(get_arg(i+1).c_str()); i++; }
		else if (in_str == "--fwdbck") { run_viterbi = false; }
		else
			error("Unknown option: " + string(in_str), 0);
		i++;
	}
	check_parameters();
}
コード例 #19
0
static void parse_command_line(int argc, char **argv,
                               vpx_codec_enc_cfg_t *cfg) {
  unsigned int width = 1920;
  unsigned int height = 1080;
  unsigned int timebase_num = 1;
  unsigned int timebase_den = 60;
  unsigned int bitrate = 1000;
  int c;
  vpx_codec_err_t res;

  opterr = 0;
  while ((c = getopt(argc, argv, "f:w:h:n:d:b:s:l:p:")) != -1) switch (c) {
      case 'f':
        number_frames_to_code = atoi(optarg);
        break;
      case 'w':
        width = atoi(optarg);
        break;
      case 'h':
        height = atoi(optarg);
        break;
      case 'n':
        timebase_num = atoi(optarg);
        break;
      case 'd':
        timebase_den = atoi(optarg);
        break;
      case 'b':
        bitrate = atoi(optarg);
        break;
      case 's':
        number_frames_to_skip = atoi(optarg);
        break;
      case 'l':
        number_spatial_layers = atoi(optarg);
        break;
      case 'p':
        key_period = atoi(optarg);
        break;
      case '?':
        usage(argv[0]);
    }

  // Parse required parameters
  if (argc - optind != 2) {
    usage(argv[0]);
  }

  input_filename = argv[optind];
  output_filename = argv[optind + 1];

  if (width < 16 || width % 2 || height < 16 || height % 2)
    die("Invalid resolution: %d x %d", width, height);

  /* Populate encoder configuration */
//  res = vpx_codec_enc_config_default(interface, cfg, 0);
//  if (res) {
//    die("Failed to get config: %s\n", vpx_codec_err_to_string(res));
//  }
  printf(
      "Codec %s\nframes: %d, skip: %d, layers: %d\n"
      "width %d, height: %d, \n"
      "num: %d, den: %d, bitrate: %d, \n"
      "key period: %d \n",
//      vpx_codec_iface_name(interface), number_frames_to_code,
      number_frames_to_code,
      number_frames_to_skip, number_spatial_layers, width, height, timebase_num,
      timebase_den, bitrate, key_period);

  // Do minimal check at the application level. Encoder parameters will be
  // checked internally
  check_parameters();

  cfg->rc_target_bitrate = bitrate;
  cfg->g_w = width;
  cfg->g_h = height;
  cfg->g_timebase.num = timebase_num;
  cfg->g_timebase.den = timebase_den;
  cfg->ss_number_layers = number_spatial_layers;
}
コード例 #20
0
ファイル: mpi.c プロジェクト: dnoliver/openssl-bruteforce
int main( int argc, char* argv[] )
{
	check_parameters( argc, argv );

	int encryption_method = -1;
	long success_key = -1;
    int proc_id, num_procs;
	int chunk, first, last;
	long work_size;
	unsigned char encrypted_text[8];
	unsigned char iv[ IV_LENGTH ] = {1,2,3,4,5,6,7,8};
	unsigned char key[ KEY_LENGTH ];
	int keygen_characters[10] = {'0','1','2','3','4','5','6','7','8','9'};
	time_t start_time, end_time;

	// init mpi
    MPI_Init( &argc, &argv );

	// check this process id
    MPI_Comm_rank( MPI_COMM_WORLD, &proc_id );

	// check how many process are available
    MPI_Comm_size( MPI_COMM_WORLD, &num_procs );

	//take timestamp and alocate result array
	start_time = time(NULL);

	read_parameters( argv, encrypted_text, &work_size );

	Encryptor decryptor[2];
	init_decryptor( &decryptor[0], DECRYPT, BLOWFISH, iv, encrypted_text );
	init_decryptor( &decryptor[1], DECRYPT, CAST5, iv, encrypted_text );

	chunk = work_size / num_procs;
	first = proc_id * chunk;

	// if i am the last process, take the last portion of work
	// is to prevent bad chunk calculation
	if( proc_id == num_procs - 1 ) {
		last = work_size;
	}
	else {
		last = first + chunk;
	}
	
	memset(key,ASCII_SPACE,KEY_LENGTH);

	for( long i = first; i < last && success_key == - 1; i++ ) {

		key[KEY_LENGTH-1] = keygen_characters[i % 10];
		key[KEY_LENGTH-2] = i/10? keygen_characters[(i/10) % 10] : ASCII_SPACE;
		key[KEY_LENGTH-3] = i/100? keygen_characters[(i/100) % 10] : ASCII_SPACE;
		key[KEY_LENGTH-4] = i/1000? keygen_characters[(i/1000) % 10] : ASCII_SPACE;
		key[KEY_LENGTH-5] = i/10000? keygen_characters[(i/10000) % 10] : ASCII_SPACE;
		key[KEY_LENGTH-6] = i/100000? keygen_characters[(i/100000) % 10] : ASCII_SPACE;
		key[KEY_LENGTH-7] = i/1000000? keygen_characters[(i/1000000) % 10] : ASCII_SPACE;
		key[KEY_LENGTH-8] = i/10000000? keygen_characters[(i/10000000) % 10] : ASCII_SPACE;
		
		encryptor_execute( &decryptor[0], key );
		//encryptor_set_key( &decryptor[0], key );
        //encryptor_init( &decryptor[0] );
        //encryptor_update( &decryptor[0] );
        //encryptor_final( &decryptor[0] );

        if( memcmp( (char *)decryptor[0].output, "Frase", 5 ) == 0 ) {
			success_key = i;
            encryption_method = BLOWFISH;
            break;
        }
		
		encryptor_execute( &decryptor[1], key );
		//encryptor_set_key( &decryptor[1], key );
        //encryptor_init( &decryptor[1] );
        //encryptor_update( &decryptor[1] );
        //encryptor_final( &decryptor[1] );

        if( memcmp( (char *)decryptor[1].output, "Frase", 5 ) == 0 ) {
			success_key = i;
            encryption_method = CAST5;
            break;
        }
	}

	//master wait to all proccess to finalize
	end_time = time( NULL );

	if( success_key != -1 ) {
		print_result( success_key, encryption_method, difftime( end_time, start_time ) );
	}

	// close mpi
    MPI_Finalize();

    return 0;
}
コード例 #21
0
ファイル: mainenc.c プロジェクト: metajack/thor
int main(int argc, char **argv)
{
  FILE *infile, *strfile, *reconfile;

  uint32_t input_file_size; //TODO: Support file size values larger than 32 bits 
  yuv_frame_t orig,ref[MAX_REF_FRAMES];
  yuv_frame_t rec[MAX_REORDER_BUFFER];
  int rec_available[MAX_REORDER_BUFFER] = {0};
  int last_frame_output=-1;
  int num_encoded_frames,num_bits,start_bits,end_bits;
  int sub_gop=1;
  int rec_buffer_idx;
  int frame_num,frame_num0,k,r;
  int frame_offset;
  int ysize,csize,frame_size;
  int width,height,input_stride_y,input_stride_c;
  uint32_t acc_num_bits;
  snrvals psnr;
  snrvals accsnr;
  double bit_rate_in_kbps;
  enc_params *params;
  encoder_info_t encoder_info;

  init_use_simd();

  /* Read commands from command line and from configuration file(s) */
  if (argc < 3)
  {
    fprintf(stdout,"usage: %s <parameters>\n",argv[0]);
    fatalerror("");
  }
  params = parse_config_params(argc, argv);
  if (params == NULL)
  {
    fatalerror("Error while reading encoder paramaters.");
  }
  check_parameters(params);

  /* Open files */
  if (!(infile = fopen(params->infilestr,"rb")))
  {
    fatalerror("Could not open in-file for reading.");
  }
  if (!(strfile = fopen(params->outfilestr,"wb")))
  {
    fatalerror("Could not open out-file for writing.");
  }
  reconfile = NULL;
  if (params->reconfilestr && !(reconfile = fopen(params->reconfilestr,"wb")))
  {
    fatalerror("Could not open recon-file for reading.");
  }

  fseek(infile, 0, SEEK_END);
  input_file_size = ftell(infile);
  fseek(infile, 0, SEEK_SET);

  accsnr.y = 0;
  accsnr.u = 0;
  accsnr.v = 0;
  acc_num_bits = 0;

  height = params->height;
  width = params->width;
  input_stride_y = width;
  input_stride_c = width/2;
  ysize = height * width;
  csize = ysize / 4;
  frame_size = ysize + 2*csize;

  /* Create frames*/
  create_yuv_frame(&orig,width,height,0,0,0,0);
  for (r=0;r<MAX_REORDER_BUFFER;r++){
    create_yuv_frame(&rec[r],width,height,0,0,0,0);
  }
  for (r=0;r<MAX_REF_FRAMES;r++){ //TODO: Use Long-term frame instead of a large sliding window
    create_yuv_frame(&ref[r],width,height,PADDING_Y,PADDING_Y,PADDING_Y/2,PADDING_Y/2);
  }

  /* Initialize main bit stream */
  stream_t stream;
  stream.bitstream = (uint8_t *)malloc(MAX_BUFFER_SIZE * sizeof(uint8_t));
  stream.bitbuf = 0;
  stream.bitrest = 32;
  stream.bytepos = 0;
  stream.bytesize = MAX_BUFFER_SIZE;

  /* Configure encoder */
  encoder_info.params = params;
  encoder_info.orig = &orig;
  for (r=0;r<MAX_REF_FRAMES;r++){
    encoder_info.ref[r] = &ref[r];
  }
  encoder_info.stream = &stream;
  encoder_info.width = width;
  encoder_info.height = height;

  encoder_info.deblock_data = (deblock_data_t *)malloc((height/MIN_PB_SIZE) * (width/MIN_PB_SIZE) * sizeof(deblock_data_t));


  /* Write sequence header */ //TODO: Separate function for sequence header
  start_bits = get_bit_pos(&stream);
  putbits(16,width,&stream);
  putbits(16,height,&stream);
  putbits(1,params->enable_pb_split,&stream);
  putbits(1,params->enable_tb_split,&stream);
  putbits(2,params->max_num_ref-1,&stream); //TODO: Support more than 4 reference frames
  putbits(4,params->num_reorder_pics,&stream);// Max 15 reordered pictures
  putbits(2,params->max_delta_qp,&stream);
  putbits(1,params->deblocking,&stream);
  putbits(1,params->clpf,&stream);
  putbits(1,params->use_block_contexts,&stream);
  putbits(1,params->enable_bipred,&stream);

  end_bits = get_bit_pos(&stream);
  num_bits = end_bits-start_bits;
  acc_num_bits += num_bits;
  printf("SH:  %4d bits\n",num_bits);

  /* Start encoding sequence */
  num_encoded_frames = 0;
  sub_gop = max(1,params->num_reorder_pics+1);
  for (frame_num0 = params->skip; frame_num0 < (params->skip + params->num_frames) && (frame_num0+sub_gop)*frame_size <= input_file_size; frame_num0+=sub_gop)
  {
    for (k=0; k<sub_gop; k++) {
      int r,r0,r1,r2,r3;
      /* Initialize frame info */
      frame_offset = reorder_frame_offset(k,sub_gop);
      frame_num = frame_num0 + frame_offset;
      // If there is an initial I frame and reordering need to jump to the next P frame
      if (frame_num<params->skip) continue;

      encoder_info.frame_info.frame_num = frame_num - params->skip;
      rec_buffer_idx = encoder_info.frame_info.frame_num%MAX_REORDER_BUFFER;
      encoder_info.rec = &rec[rec_buffer_idx];
      encoder_info.rec->frame_num = encoder_info.frame_info.frame_num;
      if (params->num_reorder_pics==0) {
        if (params->intra_period > 0)
          encoder_info.frame_info.frame_type = ((num_encoded_frames%params->intra_period) == 0 ? I_FRAME : P_FRAME);
        else
          encoder_info.frame_info.frame_type = (num_encoded_frames == 0 ? I_FRAME : P_FRAME);
      } else {
        if (params->intra_period > 0)
          encoder_info.frame_info.frame_type = ((encoder_info.frame_info.frame_num%params->intra_period) == 0 ? I_FRAME :
              ((encoder_info.frame_info.frame_num%sub_gop)==0 ? P_FRAME : B_FRAME));
        else
          encoder_info.frame_info.frame_type = (encoder_info.frame_info.frame_num == 0 ? I_FRAME :
              ((encoder_info.frame_info.frame_num%sub_gop)==0 ? P_FRAME : B_FRAME));
      }

      int coded_phase = (num_encoded_frames + sub_gop - 2) % sub_gop + 1;
      int b_level = log2i(coded_phase);

      if (encoder_info.frame_info.frame_type == I_FRAME){
        encoder_info.frame_info.qp = params->qp + params->dqpI;
      }
      else if (params->num_reorder_pics==0) {
        if (num_encoded_frames % params->HQperiod)
          encoder_info.frame_info.qp = (int)(params->mqpP*(float)params->qp) + params->dqpP;
        else
          encoder_info.frame_info.qp = params->qp;
      } else {
        if (encoder_info.frame_info.frame_num % sub_gop){
          float mqpB = params->mqpB;
#if DYADIC_CODING
          mqpB = 1.0+(b_level+1)*((mqpB-1.0)/2.0);
#endif
          encoder_info.frame_info.qp = (int)(mqpB*(float)params->qp) + params->dqpB;
        }  else
          encoder_info.frame_info.qp = params->qp;
      }

      encoder_info.frame_info.num_ref = min(num_encoded_frames,params->max_num_ref);
      if (params->num_reorder_pics > 0) {
#if DYADIC_CODING
        /* if we have a P frame then use the previous P frame as a reference */
        if ((num_encoded_frames-1) % sub_gop == 0) {
          if (num_encoded_frames==1)
            encoder_info.frame_info.ref_array[0] = 0;
          else
            encoder_info.frame_info.ref_array[0] = sub_gop-1;
          if (encoder_info.frame_info.num_ref>1 )
            encoder_info.frame_info.ref_array[1] = min(MAX_REF_FRAMES-1,min(num_encoded_frames-1,2*sub_gop-1));

          for (r=2;r<encoder_info.frame_info.num_ref;r++){
            encoder_info.frame_info.ref_array[r] = r-1;
          }

        } else {
          int display_phase =  (encoder_info.frame_info.frame_num-1) % sub_gop;
          int ref_offset=sub_gop>>(b_level+1);

           encoder_info.frame_info.ref_array[0]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase-ref_offset+1]-1);
           encoder_info.frame_info.ref_array[1]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase+ref_offset+1]-1);
          /* use most recent frames for the last ref(s)*/
          for (r=2;r<encoder_info.frame_info.num_ref;r++){
            encoder_info.frame_info.ref_array[r] = r-2;
          }
        }
#else
        /* if we have a P frame then use the previous P frame as a reference */
        if ((num_encoded_frames-1) % sub_gop == 0) {
          if (num_encoded_frames==1)
            encoder_info.frame_info.ref_array[0] = 0;
          else
            encoder_info.frame_info.ref_array[0] = sub_gop-1;
          if (encoder_info.frame_info.num_ref>1 )
            encoder_info.frame_info.ref_array[1] = min(MAX_REF_FRAMES-1,min(num_encoded_frames-1,2*sub_gop-1));

          for (r=2;r<encoder_info.frame_info.num_ref;r++){
            encoder_info.frame_info.ref_array[r] = r-1;
          }

        } else {
          // Use the last encoded frame as the first ref
          if (encoder_info.frame_info.num_ref>0) {
            encoder_info.frame_info.ref_array[0] = 0;
          }
          /* Use the subsequent P frame as the 2nd ref */
          int phase = (num_encoded_frames + sub_gop - 2) % sub_gop;
          if (encoder_info.frame_info.num_ref>1) {
            if (phase==0)
              encoder_info.frame_info.ref_array[1] = min(sub_gop, num_encoded_frames-1);
            else
              encoder_info.frame_info.ref_array[1] = min(phase, num_encoded_frames-1);
          }
          /* Use the prior P frame as the 3rd ref */
          if (encoder_info.frame_info.num_ref>2) {
            encoder_info.frame_info.ref_array[2] = min(phase ? phase + sub_gop : 2*sub_gop, num_encoded_frames-1);
          }
          /* use most recent frames for the last ref(s)*/
          for (r=3;r<encoder_info.frame_info.num_ref;r++){
            encoder_info.frame_info.ref_array[r] = r-3+1;
          }
        }

#endif
      } else {
        if (encoder_info.frame_info.num_ref==1){
          /* If num_ref==1 always use most recent frame */
          encoder_info.frame_info.ref_array[0] = 0;
        }
        else if (encoder_info.frame_info.num_ref==2){
          /* If num_ref==2 use most recent LQ frame and most recent HQ frame */
          r0 = 0;
          r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1;
          encoder_info.frame_info.ref_array[0] = r0;
          encoder_info.frame_info.ref_array[1] = r1;
        }
        else if (encoder_info.frame_info.num_ref==3){
          r0 = 0;
          r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1;
          r2 = r1==1 ? 2 : 1;
          encoder_info.frame_info.ref_array[0] = r0;
          encoder_info.frame_info.ref_array[1] = r1;
          encoder_info.frame_info.ref_array[2] = r2;
        }
        else if (encoder_info.frame_info.num_ref==4){
          r0 = 0;
          r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1;
          r2 = r1==1 ? 2 : 1;
          r3 = r2+1;
          if (r3==r1) r3 += 1;
          encoder_info.frame_info.ref_array[0] = r0;
          encoder_info.frame_info.ref_array[1] = r1;
          encoder_info.frame_info.ref_array[2] = r2;
          encoder_info.frame_info.ref_array[3] = r3;
        }
        else{
          for (r=0;r<encoder_info.frame_info.num_ref;r++){
            encoder_info.frame_info.ref_array[r] = r;
          }
        }
      }

      if (params->intra_rdo){
        if (encoder_info.frame_info.frame_type == I_FRAME){
          encoder_info.frame_info.num_intra_modes = 10;
        }
        else{
          encoder_info.frame_info.num_intra_modes = params->encoder_speed > 0 ? 4 : 10;
        }
      }
      else{
        encoder_info.frame_info.num_intra_modes = 4;
      }

#if 0
      /* To test sliding window operation */
      int offsetx = 500;
      int offsety = 200;
      int offset_rec = encoder_info.rec->offset_y + offsety * encoder_info.rec->stride_y +  offsetx;
      int offset_ref = encoder_info.ref[0]->offset_y + offsety * encoder_info.ref[0]->stride_y +  offsetx;
      if (encoder_info.frame_info.num_ref==2){
        int r0 = encoder_info.frame_info.ref_array[0];
        int r1 = encoder_info.frame_info.ref_array[1];
        printf("ref0=%3d ref1=%3d ",encoder_info.ref[r0]->y[offset_ref],encoder_info.ref[r1]->y[offset_ref]);
      }
      else{
        printf("ref0=XXX ref1=XXX ");
      }
#endif

      /* Read input frame */
      fseek(infile, frame_num*(frame_size+params->frame_headerlen)+params->file_headerlen+params->frame_headerlen, SEEK_SET);
      read_yuv_frame(&orig,width,height,infile);
      orig.frame_num = encoder_info.frame_info.frame_num;

      /* Encode frame */
      start_bits = get_bit_pos(&stream);
      encode_frame(&encoder_info);
      rec_available[rec_buffer_idx]=1;
      end_bits =  get_bit_pos(&stream);
      num_bits = end_bits-start_bits;
      num_encoded_frames++;

      /* Compute SNR */
      if (params->snrcalc){
        snr_yuv(&psnr,&orig,&rec[rec_buffer_idx],height,width,input_stride_y,input_stride_c);
      }
      else{
        psnr.y =  psnr.u = psnr.v = 0.0;
      }
      accsnr.y += psnr.y;
      accsnr.u += psnr.u;
      accsnr.v += psnr.v;

      acc_num_bits += num_bits;

      if (encoder_info.frame_info.frame_type==I_FRAME)
        fprintf(stdout,"%4d I %4d %10d %10.4f %8.4f %8.4f ",frame_num,encoder_info.frame_info.qp,num_bits,psnr.y,psnr.u,psnr.v);
      else if (encoder_info.frame_info.frame_type==P_FRAME)
        fprintf(stdout,"%4d P %4d %10d %10.4f %8.4f %8.4f ",frame_num,encoder_info.frame_info.qp,num_bits,psnr.y,psnr.u,psnr.v);
      else 
        fprintf(stdout,"%4d B %4d %10d %10.4f %8.4f %8.4f ",frame_num,encoder_info.frame_info.qp,num_bits,psnr.y,psnr.u,psnr.v);

      for (r=0;r<encoder_info.frame_info.num_ref;r++){
        fprintf(stdout,"%3d",encoder_info.frame_info.ref_array[r]);
      }
      fprintf(stdout,"\n");
      fflush(stdout);

      /* Write compressed bits for this frame to file */
      flush_bytebuf(&stream, strfile);

      if (reconfile){
        /* Write output frame */
        rec_buffer_idx = (last_frame_output+1) % MAX_REORDER_BUFFER;
        if (rec_available[rec_buffer_idx]) {
          last_frame_output++;
          write_yuv_frame(&rec[rec_buffer_idx],width,height,reconfile);
          rec_available[rec_buffer_idx]=0;
        }
      }
    }
  }