Exemple #1
0
int main(int argc, char *argv[])
{
    scew_parser *parser = NULL;
    if (init() != 0) {
        return 1;
    }

    if (argc == 2) {
        if (exists(argv[1])) {
            parser = scew_parser_create();
            scew_parser_ignore_whitespaces(parser, 1);
            scew_parser_load_file(parser, argv[1]);
            maptree = scew_parser_tree(parser);
        } else {
            allegro_message("Cannot load file: %s", argv[1]);
            close_program = 1;
        }
    } else if (argc == 4) {
        maptree = new_map(0, MAP_WIN.w / TILE_W, atoi(argv[1]), 1, argv[2]);
        map_offset = atoi(argv[1]) * TILE_H - EDITOR_WIN_H;
    } else {
        /* print usage */
        allegro_message
            ("Usage:\n\"editor.exe <filename>\" to load a file\n \"editor.exe <height_in_tiles> <default_tile_name> <newmapfile>\" to create a new map");

        close_program = 1;
    }

    while (!close_program) {
        /* get input */
        parse_mouse();
        get_grid_item();
        if (keypressed()) {
            parse_keyboard();
        }

        /* blit virtual screen */
        clear_to_color(vscreen, DEAD_COLOR);
        draw_select_lists(vscreen);
        draw_ctrl_box(vscreen);

        update_screen();
    }

    if (argc == 2) {
        write_map(argv[1], maptree);
        scew_parser_free(parser);
    } else if (argc == 4) {
        write_map(argv[3], maptree);
        scew_tree_free(maptree);
    }
    destroy_bitmap(vscreen);
    cleanup();
    return 0;
}
void init_maps(void)
{
	uint32 i = 0;
	uint32 n = 0;
	char *path;

	map_array = (map_t *)calloc(MAX_MAPS, sizeof(map_t));
	map_array_cache = (buffer_t *)calloc(MAX_MAPS, sizeof(buffer_t));

	for( i = 0; i < MAX_MAPS; i++){
		map_array[i].name = (char *)calloc(MAX_NAME_LENGTH, sizeof(char));
		map_array[i].npc = (map_npc_t *)calloc(MAX_MAP_NPCS, sizeof(map_npc_t));
		map_array[i].tile = (tile_t *)calloc(MAX_MAPX * MAX_MAPY, sizeof(tile_t));
		map_array[i].items = (map_item_t *)calloc(MAX_MAP_ITEMS, sizeof(map_item_t));

		for( n = 0; n < MAX_MAP_NPCS; n++)
			map_array[i].npc[n].vitals = (uint16 *)calloc(VITAL_COUNT, sizeof(uint16));

		path = get_path(MAP_PATH, i, FILE_ENDING);

		check_dir(MAP_PATH);

		if(file_readable(path))
			read_map(path,i);
		else
			write_map(path,i);

		mapcache_create(i);
	}
}
Exemple #3
0
int avro_schema_to_json(const avro_schema_t schema, avro_writer_t out)
{
	check_param(EINVAL, is_avro_schema(schema), "schema");
	check_param(EINVAL, out, "writer");

	int rval;

	if (is_avro_primitive(schema)) {
		check(rval, avro_write_str(out, "{\"type\":\""));
	}

	switch (avro_typeof(schema)) {
	case AVRO_STRING:
		check(rval, avro_write_str(out, "string"));
		break;
	case AVRO_BYTES:
		check(rval, avro_write_str(out, "bytes"));
		break;
	case AVRO_INT32:
		check(rval, avro_write_str(out, "int"));
		break;
	case AVRO_INT64:
		check(rval, avro_write_str(out, "long"));
		break;
	case AVRO_FLOAT:
		check(rval, avro_write_str(out, "float"));
		break;
	case AVRO_DOUBLE:
		check(rval, avro_write_str(out, "double"));
		break;
	case AVRO_BOOLEAN:
		check(rval, avro_write_str(out, "boolean"));
		break;
	case AVRO_NULL:
		check(rval, avro_write_str(out, "null"));
		break;
	case AVRO_RECORD:
		return write_record(out, avro_schema_to_record(schema));
	case AVRO_ENUM:
		return write_enum(out, avro_schema_to_enum(schema));
	case AVRO_FIXED:
		return write_fixed(out, avro_schema_to_fixed(schema));
	case AVRO_MAP:
		return write_map(out, avro_schema_to_map(schema));
	case AVRO_ARRAY:
		return write_array(out, avro_schema_to_array(schema));
	case AVRO_UNION:
		return write_union(out, avro_schema_to_union(schema));
	case AVRO_LINK:
		return write_link(out, avro_schema_to_link(schema));
	}

	if (is_avro_primitive(schema)) {
		return avro_write_str(out, "\"}");
	}
	avro_set_error("Unknown schema type");
	return EINVAL;
}
Exemple #4
0
void write_maps(char *prefix_out,int nside,int n_nu,
		flouble **maps_i,flouble **maps_q,
		flouble **maps_u)
{
  long ii;
  int with_pol,nfields;
  flouble *map_aux_q,*map_aux_u;

  printf("*** Writing maps %s_###.fits\n",prefix_out);

  if(maps_q==NULL) {
    with_pol=0;
    nfields=1;
    map_aux_q=NULL;
    map_aux_u=NULL;
  }
  else {
    with_pol=1;
    nfields=3;
    map_aux_q=(flouble *)my_malloc(nside2npix(nside)*sizeof(flouble));
    map_aux_u=(flouble *)my_malloc(nside2npix(nside)*sizeof(flouble));
  }
      
  map_aux=(float **)my_malloc(nfields*sizeof(float *));
  for(ii=0;ii<nfields;ii++)
    map_aux[ii]=(float *)my_malloc(nside2npix(nside)*sizeof(float));

  timer(0);
  for(ii=0;ii<n_nu;ii++) {
    char fname[256];

    if(with_pol) {
      he_udgrade(maps_q[ii],NSIDE_POL,map_aux_q,nside,0);
      he_udgrade(maps_u[ii],NSIDE_POL,map_aux_u,nside,0);
    }
    sprintf(fname,"%s_%03ld.fits",prefix_out,ii+1);
    write_map(fname,nside,maps_i[ii],map_aux_q,map_aux_u);
  }

  for(ii=0;ii<nfields;ii++)
    free(map_aux[ii]);
  free(map_aux);

  if(with_pol) {
    free(map_aux_q);
    free(map_aux_u);
  }

  timer(1);
  printf("\n");
}
int main(void)
{
  if ((ipass=fopen(scans,"r"))==NULL)
    {
      printf("Cannot open file. \n");
      exit(1);
    }
  fscanf(ipass,"%i", &Ptotal);
 
   for (Pindex=1; Pindex<=Ptotal; Pindex++)
    {
      fscanf(ipass,"%s", powerfile);
      //      printf("%s\n",powerfile);
      if ((fp=fopen(powerfile,"r"))==NULL)
	{
      	  printf("Cannot open file. \n");
	  exit(1);
	}
      strcpy(passfile,"");
      strcat(passfile,prefix);
      p=strpbrk(powerfile,"2");
      strcat(passfile,p);
      //     printf("%s\n",passfile);
  if ((fpass=fopen(passfile,"r"))==NULL)
    {
      printf("Cannot open file. \n");
      exit(1);
    }
  printf("\nReading data file %s \n",powerfile);

  for (acqcount=1; acqcount < (numofacqs+1); acqcount++) read_data();
  read_pass_file();
  //  test_data();
  fclose(fpass);
  fclose(fp);
    }
  group_data();
  pg_id = cpgopen("/XSERVE");

  while (sat_choice <100)
    {
      printf("\nPlot Satellite: ");
      scanf("%i", &sat_choice);
      if (sat_choice<40) plot_map();
    }
      
  write_map();
  fclose(ipass);
  printf("End of Program\n");
  return 0;
}
void test_map(uint32 mapnum)
{
	uint32 x = 0;
	uint32 y = 0;
	char *path;

	map(mapnum)->name = "A Test Map";
	map(mapnum)->moral = 0;
	map(mapnum)->music = 0;
	map(mapnum)->left = 0;
	map(mapnum)->right = 0;
	map(mapnum)->up = 0;
	map(mapnum)->down = 0;
	map(mapnum)->shop = 0;
	map(mapnum)->bootmap = 1;
	map(mapnum)->bootx = 4;
	map(mapnum)->booty = 4;
	map(mapnum)->revision = 1;

	for( x = 0; x < MAX_MAP_NPCS; x++)
		map(mapnum)->npc[x].num = 0;

	for( y = 0; y < MAX_MAPY; y++){
		for( x = 0; x < MAX_MAPX; x++){
			map(mapnum)->tile[GETXY(x,y)].ground.y = 1;
			map(mapnum)->tile[GETXY(x,y)].ground.x = 1;
			map(mapnum)->tile[GETXY(x,y)].ground.tileset = 1;

			map(mapnum)->tile[GETXY(x,y)].mask.y = 0;
			map(mapnum)->tile[GETXY(x,y)].mask.x = 0;
			map(mapnum)->tile[GETXY(x,y)].mask.tileset = 0;

			map(mapnum)->tile[GETXY(x,y)].anim.y = 0;
			map(mapnum)->tile[GETXY(x,y)].anim.x = 0;
			map(mapnum)->tile[GETXY(x,y)].anim.tileset = 0;

			map(mapnum)->tile[GETXY(x,y)].fringe.y = 0;
			map(mapnum)->tile[GETXY(x,y)].fringe.x = 0;
			map(mapnum)->tile[GETXY(x,y)].fringe.tileset = 0;

			map(mapnum)->tile[GETXY(x,y)].data1 = 0;
			map(mapnum)->tile[GETXY(x,y)].data2 = 0;
			map(mapnum)->tile[GETXY(x,y)].data3 = 0;
			map(mapnum)->tile[GETXY(x,y)].type = TILE_TYPE_WALKABLE;
		}
	}
	path = get_path(MAP_PATH, mapnum, FILE_ENDING);
	write_map(path,mapnum);
}
int main(int argc, const char * argv[]) {

    namespace prog_opt = boost::program_options;
    namespace file_sys = boost::filesystem;
    
    
    ///////////////////////////////////////////////////////////////////////////
    ///                                                                     ///
    ///    PROGRAM OPTIONS                                                  ///
    ///                                                                     ///
    ///////////////////////////////////////////////////////////////////////////
    
    
    std::string base_dir_str;
    std::string output_path_str;
	bool use_int_signals;
	std::string climate_signal;
	std::vector<std::string> portfolio_signal;
	int ari_signal;
	int year;

    
    
    prog_opt::options_description desc("Allowed options");
    desc.add_options()
    ("help,h", "produce help message")
    ("base-directory,d", prog_opt::value<std::string>(&base_dir_str), "The base directory for the map database")
	("climate-signal,c", prog_opt::value<std::string>(&climate_signal)->default_value("1"), "The climate change projection that should be used")
	("portfolio-signal,p", prog_opt::value<std::vector<std::string> >(&portfolio_signal), "The mitigation portfolios that should be used. Need to specify exactly the number of portfolios as there are catchments")
	("ARI,r", prog_opt::value<int>(&ari_signal)->default_value(20), "The 1:ari value indicating expected frequency of flood hazard")
	("year,y", prog_opt::value<int>(&year)->default_value(2015), "specify year in which to calculate flood hazard for")
    ("output,o", prog_opt::value<std::string>(&output_path_str)->default_value("output.tif"), "The path to print output interpolated map to")
	("int-signam,i", prog_opt::value<bool>(&use_int_signals)->default_value(true), "Whether to use string or int representation of mitigation and climate scanario signals");

	prog_opt::positional_options_description p;
	p.add("portfolio-signal", -1);

    prog_opt::variables_map vm;
	prog_opt::store(prog_opt::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
    prog_opt::notify(vm);

    if (vm.count("help"))
    {
        std::cout << desc << "\n";
        return 1;
    }
	if (vm.count("portfolio-signal"))
	{
		std::cout << "Mitigation portfolios are: "
			<< vm["portfolio-signal"].as< std::vector<std::string> >() << "\n";
	}
    
    file_sys::path base_dir(base_dir_str);
    //Check if base directory exists
    if (!file_sys::exists(base_dir))
    {
        std::cerr << "Base directory of database does not exist" << std::endl;
        //Could throw an error here instead
    }

	
    

    Database my_data;
    processDatabase(my_data, base_dir);
	//Read in template map.
	fs::path template_map = base_dir / "template.tif";
	std::tuple<Map_Double_SPtr, std::string, GeoTransform> gdal_map = read_in_map<double>(template_map, GDT_Float64, NO_CATEGORISATION);
	Map_Double_SPtr map(std::get<0>(gdal_map));
	std::string & map_WKT_projection = (std::get<1>(gdal_map));
	GeoTransform & map_transform = (std::get<2>(gdal_map));
	int nrows = map->NRows();
	int ncols = map->NCols();
	double no_data_val = map->NoDataValue();

	//Set number of mitigaiton portfolios and scenarios
	int num_of_scenarios = my_data.get_catchment(1)->clim_scnrios_ik.size();
	int num_of_portfolios = my_data.get_catchment(1)->get_scenario(1)->mit_prtflios_ik.size();

    StitchedMapSet maps;

	if (use_int_signals == true)
	{
		std::vector<int> portfolios;
		for (int i = 0; i < num_of_portfolios; ++i)
		{
			portfolios[i] = std::stoi(portfolio_signal[i]);
		}
		int scenario = std::stoi(climate_signal);
		getMapSet(climate_signal, portfolio_signal, my_data, maps, ncols, nrows, no_data_val);
	}
	else
	{
		getMapSet(climate_signal, portfolio_signal, my_data, maps, ncols, nrows, no_data_val);
	}

    
    
    Map_Float_SPtr interped_map = interpolatedmap(ari_signal, year, maps);
    
    /********************************************/
    /* Print resultent map                      */
    /********************************************/
    
    //Open template map to get projection and transformation information.
    file_sys::path template_path = base_dir / "template.tif";
    std::string wKTprojection;
    GeoTransform transform;
    Map_Float_SPtr template_map;
    std::tie(template_map, wKTprojection, transform) = read_in_map<float>(template_path, GDT_Float32, NO_CATEGORISATION);
    
    
    file_sys::path output_path(output_path_str);
    std::cout << "\n\n*************************************\n";
    std::cout << "*         Saving output file        *\n";
    std::cout << "*************************************" << std::endl;
    std::string driverName = "GTiff";
    write_map(output_path, GDT_Float32, interped_map, wKTprojection, transform, driverName);
    
    
    std::cout << "finished processing database" << std::endl;
    std::cout << "Another breakpoint" << std::endl;
}
Exemple #8
0
static int write_datum(avro_writer_t writer, const avro_encoding_t * enc,
		       avro_schema_t writers_schema, avro_datum_t datum)
{
	if (is_avro_schema(writers_schema) && is_avro_link(writers_schema)) {
		return write_datum(writer, enc,
				   (avro_schema_to_link(writers_schema))->to,
				   datum);
	}

	switch (avro_typeof(datum)) {
	case AVRO_NULL:
		return enc->write_null(writer);

	case AVRO_BOOLEAN:
		return enc->write_boolean(writer,
					  avro_datum_to_boolean(datum)->i);

	case AVRO_STRING:
		return enc->write_string(writer,
					 avro_datum_to_string(datum)->s);

	case AVRO_BYTES:
		return enc->write_bytes(writer,
					avro_datum_to_bytes(datum)->bytes,
					avro_datum_to_bytes(datum)->size);

	case AVRO_INT32:
	case AVRO_INT64:{
			int64_t val = avro_typeof(datum) == AVRO_INT32 ?
			    avro_datum_to_int32(datum)->i32 :
			    avro_datum_to_int64(datum)->i64;
			if (is_avro_schema(writers_schema)) {
				/* handle promotion */
				if (is_avro_float(writers_schema)) {
					return enc->write_float(writer,
								(float)val);
				} else if (is_avro_double(writers_schema)) {
					return enc->write_double(writer,
								 (double)val);
				}
			}
			return enc->write_long(writer, val);
		}

	case AVRO_FLOAT:{
			float val = avro_datum_to_float(datum)->f;
			if (is_avro_schema(writers_schema)
			    && is_avro_double(writers_schema)) {
				/* handle promotion */
				return enc->write_double(writer, (double)val);
			}
			return enc->write_float(writer, val);
		}

	case AVRO_DOUBLE:
		return enc->write_double(writer,
					 avro_datum_to_double(datum)->d);

	case AVRO_RECORD:
		return write_record(writer, enc,
				    avro_schema_to_record(writers_schema),
				    datum);

	case AVRO_ENUM:
		return write_enum(writer, enc,
				  avro_schema_to_enum(writers_schema),
				  avro_datum_to_enum(datum));

	case AVRO_FIXED:
		return avro_write(writer,
				  avro_datum_to_fixed(datum)->bytes,
				  avro_datum_to_fixed(datum)->size);

	case AVRO_MAP:
		return write_map(writer, enc,
				 avro_schema_to_map(writers_schema),
				 avro_datum_to_map(datum));

	case AVRO_ARRAY:
		return write_array(writer, enc,
				   avro_schema_to_array(writers_schema),
				   avro_datum_to_array(datum));

	case AVRO_UNION:
		return write_union(writer, enc,
				   avro_schema_to_union(writers_schema),
				   avro_datum_to_union(datum));

	case AVRO_LINK:
		break;
	}

	return 0;
}
Exemple #9
0
int map_read_line(const char **s)
{
  const char *id;
  
  if ( is_inside_proc != 0 )
  {
    if ( uglReadLine(s) == 0 )
      is_inside_proc = 0;
    return 1;
  }
  skip_space(s);
  
  if ( **s == '#' )		/* comment (hmm handled by skip_space) */
    return 1;

  if ( **s == '\0' )		/* empty line */
    return 1;
  
  if ( **s == ':' )
  {
    (*s)++;
    return map_read_row(s);
  }
  
  id = get_identifier(s);
  if ( strcmp(id, "tile") == 0 )
  {
     return map_read_tile(s, 0, -1);
  }
  else if ( strcmp(id, "thing") == 0 )
  {
     return map_read_tile(s, 1, -1);
  }
  else if ( strcmp(id, "itemkey") == 0 )
  {
    const char *id;
    int idx;
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    if ( idx < 0 )
    {
      printf("code line %d, item '%s' unknown.\n", ugl_current_input_line, id);
    }
    else
    {
     return map_read_tile(s, 1, idx);
    }
  }
  else if ( strcmp(id, "item") == 0 )
  {
    const char *id;
    int idx;
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    if ( idx >= 0 )
    {
      printf("code line %d, item '%s' already exists.\n", ugl_current_input_line, id);
    }
    else
    {
      if ( item_add(id) < 0 )
      {
	printf("code line %d, item '%s': Too many items.\n", ugl_current_input_line, id);
      }
      else
      {
	idx = item_get_idx_by_name(id);
	assert( idx >= 0 );
	item_list[idx].fg_tile = get_num(s);
      }
    }  
    
    return 1;
  }
  else if ( strcmp(id, "mapinit") == 0 )
  {
    map_init_code_pos = uglStartNamelessProc(0);
    is_inside_proc = 1;
    return 1;
  }  
  else if ( strcmp(id, "iteminit") == 0 )
  {
    const char *id;
    int idx;
    uint16_t code_pos;
    
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    code_pos = uglStartNamelessProc(0);
    if ( idx < 0 )
    {
	printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
    }
    else
    {
      item_list[idx].init_proc= code_pos;
    }    
    is_inside_proc = 1;
    return 1;
  }
  else if ( strcmp(id, "itemhit") == 0 )
  {
    const char *id;
    int idx;
    uint16_t code_pos;
    
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    code_pos = uglStartNamelessProc(0);
    if ( idx < 0 )
    {
	printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
    }
    else
    {
      item_list[idx].hit_proc= code_pos;
    }    
    is_inside_proc = 1;
    return 1;
  }
  else if ( strcmp(id, "itemstep") == 0 )
  {
    const char *id;
    int idx;
    uint16_t code_pos;
    
    id = get_identifier(s);
    idx = item_get_idx_by_name(id);
    code_pos = uglStartNamelessProc(0);
    if ( idx < 0 )
    {
	printf("code line %d, item '%s' not found.\n", ugl_current_input_line, id);
    }
    else
    {
      item_list[idx].step_proc= code_pos;
    }    
    is_inside_proc = 1;
    return 1;
  }
  else if ( strcmp(id, "map") == 0 )
  {
    is_inside_map = 1;

    return map_read_map_cmd(s);
  }
  else if ( strcmp(id, "endmap") == 0 )
  {
    /* write existing map: once a map has been read, transform it to the target */
    if ( map_width > 0 && map_height > 0 )
    {
      if ( map_all_tiles() )
      {
	char buf[128];
	write_map();
	write_item_onmap();
	sprintf(buf, "%s.tga", map_name);
	write_tga_map(buf);
	write_map_struct();
      }
    }
    is_inside_map = 0;
    return 1;
  }
  else
  {
    printf("code line %d, map line %d: unkown command '%s'\n", ugl_current_input_line, map_curr_line, id);
  }
  
  return 1;
}
int main(int argc, char **argv)
{
    
    
    /**********************************/
    /*        Program options         */
    /**********************************/
    // Need to specify elevation grid
    // Need to specify channel
    //	std::string feature_file;
    std::string dem_file;
    std::string guage_file("no_file");
    //	std::string changes_file;
    //	std::string log_file;
    //    std::string fd_file;
    std::string hydro_paths_file;
    std::string output_file;
    std::string channel_graph_file;
    std::string controls_file("no_file");
    //	bool do_print = false;
    //	std::string file_print;
    //    unsigned int trim_level;
    bool do_interp_hgl = true;
    bool write_controls= false;
    double outflow_levels = 1.0;
    double source_levels = 0.0;
    bool use_controls_file = false;
    
    namespace prog_opt = boost::program_options;
    prog_opt::options_description desc("Allowed options");
    desc.add_options()
    ("help,h", "produce help message")
    //		("feature-map,f", prog_opt::value<std::string>(&feature_file), "path of the gdal capatible raster feature file")
    ("dem-map,d", prog_opt::value<std::string>(&dem_file), "path of the gdal capatible elevation data file")
    //        ("flow-dir-map,i", prog_opt::value<std::string>(&fd_file), "path of the gdal capatible flow direction data file")
    ("hydro-paths-file,p", prog_opt::value<std::string>(&hydro_paths_file)->default_value("hydro-paths.tif"), "path of the output map where each pixel is assigned the location on channel that the pixel is hydrologically connected to ")
    ("channel-graph,g", prog_opt::value<std::string>(&channel_graph_file), "path of the graphml representation of the channel")
    ("guage-table,t", prog_opt::value<std::string>(&guage_file), "path of text file with guage location and levels, takes precedence over channel graph")
    ("output-flood-height-file,o", prog_opt::value<std::string>(&output_file)->default_value("flood_height.tif"), "path of the output map where each pixel is assigned the flood height at that pixel")
    //        ("trim-branches,t", prog_opt::value<unsigned int>(&trim_level)->default_value(0), "remove branches if they are composed with a number of pixels less than this amount")
    ("interp-hgl,n", prog_opt::value<bool>(&do_interp_hgl)->default_value(true), "True for interpolation based on hgl, false if based on water column depth")
    ("write-controls,w", prog_opt::value<bool>(&write_controls)->default_value(false), "Write list of control nodes to file")
    ("read-controls,r", prog_opt::value<std::string>(&controls_file), "Name of controls file to read into. Take precedence over guage table file")
    ("outflow-levels,u", prog_opt::value<double>(&outflow_levels), "Flood level assigned to outflow nodes (least precedence)")
    ("source-levels,s", prog_opt::value<double>(&source_levels), "Flood level assigned to outflow nodes (least precedence)");
    //		("log_file,l", prog_opt::value<std::string>(&log_file)->default_value("moves.log"), "path of the file which logs feature cell movements")
    //		("print,p", prog_opt::value<std::string>(&file_print), "Print map to text file (space seperated values) - specify file name prefix");
    
    prog_opt::variables_map vm;
    prog_opt::store(prog_opt::parse_command_line(argc, argv, desc), vm);
    prog_opt::notify(vm);
    if (vm.count("help"))
    {
        std::cout << desc << "\n";
        return 1;
    }
    if (vm.count("read-controls"))
    {
        use_controls_file = true;
    }
    //	if (vm.count("print"))
    //	{
    //		do_print = true;
    //	}
    
    
    fs::path channel_graph_path(channel_graph_file);
    fs::path dem_file_path(dem_file);
    //	fs::path changes_file_path(changes_file);
    fs::path guage_table_path(guage_file);
    //  fs::path fd_file_path(fd_file);
    fs::path hydro_paths_file_path(hydro_paths_file);
    fs::path output_file_path(output_file);

    
    
    /********************************************/
    /* Print resultent DEM					    */
    /********************************************/
    std::cout << "\n\n*************************************\n";
    std::cout << "*         Saving output file        *\n";
    std::cout << "*************************************" << std::endl;
    std::string driverName = "GTiff";
    write_map(output_file_path, GDT_Float64, output_map, demWKTprojection, demTransform, driverName);
    
    return (EXIT_SUCCESS);
    //	double no_changes_val = 0.0;
    //	if (dem_map->HasNoDataValue()) no_changes_val = dem_map->NoDataValue();
    //	Map_Double_SPtr changes_map(new Map_Double(feature_map->NRows(), feature_map->NCols(), no_changes_val));
    //	changes_map->SetNoDataValue(no_changes_val);
    
    
    //	boost::progress_display show_progress3(boost::num_vertices(channel_grph));
    //	dfs_interpolate_visitor vis(dem_map, changes_map, show_progress3);
    //	boost::depth_first_search(channel_grph, visitor(vis));
    
    /********************************************/
    /* //Create map of downstream control IDs, upstream control IDs, Distance to downstram and upstream IDs					    */
    /********************************************/
    //	std::string driverName = "GTiff";
    //	write_map(incised_dem_file_path, GDT_Float64, dem_map, demWKTprojection, demTransform, driverName);
    //	write_map(changes_file_path, GDT_Float64, changes_map, demWKTprojection, demTransform, driverName);
    
}
Exemple #11
0
pdf_obj *
CMap_create_stream (CMap *cmap)
{
  pdf_obj         *stream;
  pdf_obj         *stream_dict;
  CIDSysInfo      *csi;
  struct sbuf      wbuf;
  struct rangeDef *ranges;
  unsigned char   *codestr;
  int              i, j, count = 0;

  if (!cmap || !CMap_is_valid(cmap)) {
    WARN("Invalid CMap");
    return NULL;
  }

  if (cmap->type == CMAP_TYPE_IDENTITY)
    return NULL;

  stream      = pdf_new_stream(STREAM_COMPRESS);
  stream_dict = pdf_stream_dict(stream);

  csi = CMap_get_CIDSysInfo(cmap);
  if (!csi) {
    csi = (cmap->type != CMAP_TYPE_TO_UNICODE) ?
      &CSI_IDENTITY : &CSI_UNICODE;
  }

  if (cmap->type != CMAP_TYPE_TO_UNICODE) {
    pdf_obj *csi_dict;

    csi_dict = pdf_new_dict();
    pdf_add_dict(csi_dict,
		 pdf_new_name("Registry"),
		 pdf_new_string(csi->registry, strlen(csi->registry)));
    pdf_add_dict(csi_dict,
		 pdf_new_name("Ordering"),
		 pdf_new_string(csi->ordering, strlen(csi->ordering)));
    pdf_add_dict(csi_dict,
		 pdf_new_name("Supplement"),
		 pdf_new_number(csi->supplement));

    pdf_add_dict(stream_dict,
		 pdf_new_name("Type"),
		 pdf_new_name("CMap"));
    pdf_add_dict(stream_dict,
		 pdf_new_name("CMapName"),
		 pdf_new_name(cmap->name));
    pdf_add_dict(stream_dict,
		 pdf_new_name("CIDSystemInfo"), csi_dict);
    if (cmap->wmode != 0)
      pdf_add_dict(stream_dict,
		   pdf_new_name("WMode"),
		   pdf_new_number(cmap->wmode));
  }

  /* TODO:
   * Predefined CMaps need not to be embedded.
   */
  if (cmap->useCMap) {
    ERROR("UseCMap found (not supported yet)...");
    if (CMap_is_Identity(cmap->useCMap)) { /* not sure */
      if (CMap_get_wmode(cmap) == 1) {
	pdf_add_dict(stream_dict,
		     pdf_new_name("UseCMap"),
		     pdf_new_name("Identity-V"));
      } else {
    	pdf_add_dict(stream_dict,
		     pdf_new_name("UseCMap"),
		     pdf_new_name("Identity-H"));
      }
    } else {
      int      res_id;
      pdf_obj *ucmap_ref;

      res_id = pdf_findresource("CMap", CMap_get_name(cmap->useCMap));
      if (res_id >= 0) {
	ucmap_ref = pdf_get_resource_reference(res_id);
      } else {
	pdf_obj *ucmap_obj;

	ucmap_obj = CMap_create_stream(cmap->useCMap);
	if (!ucmap_obj) {
	  ERROR("Uh ah. I cannot continue...");
	}

	res_id = pdf_defineresource("CMap",
				    CMap_get_name(cmap->useCMap),
				    ucmap_obj, PDF_RES_FLUSH_IMMEDIATE);
	ucmap_ref = pdf_get_resource_reference(res_id);
      }
      pdf_add_dict(stream_dict, pdf_new_name("UseCMap"), ucmap_ref);
    }
  }

#define WBUF_SIZE 40960
  wbuf.buf = NEW(WBUF_SIZE, char);
  codestr  = NEW(cmap->profile.maxBytesIn, unsigned char);
  memset(codestr, 0, cmap->profile.maxBytesIn);

  wbuf.curptr = wbuf.buf;
  wbuf.limptr = wbuf.buf + WBUF_SIZE -
    2 * (cmap->profile.maxBytesIn + cmap->profile.maxBytesOut) + 16;

  /* Start CMap */
  pdf_add_stream(stream, (const void *) CMAP_BEGIN, strlen(CMAP_BEGIN));

  wbuf.curptr += sprintf(wbuf.curptr, "/CMapName ");
  write_name(&wbuf.curptr, wbuf.limptr, cmap->name);
  wbuf.curptr += sprintf(wbuf.curptr, " def\n");
  wbuf.curptr += sprintf(wbuf.curptr, "/CMapType %d def\n" , cmap->type);
  if (cmap->wmode != 0 &&
      cmap->type != CMAP_TYPE_TO_UNICODE)
    wbuf.curptr += sprintf(wbuf.curptr, "/WMode %d def\n", cmap->wmode);

#define CMAP_CSI_FMT "/CIDSystemInfo <<\n\
  /Registry (%s)\n\
  /Ordering (%s)\n\
  /Supplement %d\n\
>> def\n"
  wbuf.curptr += sprintf(wbuf.curptr, "/CIDSystemInfo <<\n");
  wbuf.curptr += sprintf(wbuf.curptr, "  /Registry ");
  write_string(&wbuf.curptr, wbuf.limptr, csi->registry);
  wbuf.curptr += sprintf(wbuf.curptr, "\n");
  wbuf.curptr += sprintf(wbuf.curptr, "  /Ordering ");
  write_string(&wbuf.curptr, wbuf.limptr, csi->ordering);
  wbuf.curptr += sprintf(wbuf.curptr, "\n");
  wbuf.curptr += sprintf(wbuf.curptr, "  /Supplement %d\n>> def\n",
    csi->supplement);
  pdf_add_stream(stream, wbuf.buf, (int)(wbuf.curptr - wbuf.buf));
  wbuf.curptr = wbuf.buf;

  /* codespacerange */
  ranges = cmap->codespace.ranges;
  wbuf.curptr += sprintf(wbuf.curptr,
			 "%d begincodespacerange\n", cmap->codespace.num);
  for (i = 0; i < cmap->codespace.num; i++) {
    *(wbuf.curptr)++ = '<';
    for (j = 0; j < ranges[i].dim; j++) {
      sputx(ranges[i].codeLo[j], &(wbuf.curptr), wbuf.limptr);
    }
    *(wbuf.curptr)++ = '>';
    *(wbuf.curptr)++ = ' ';
    *(wbuf.curptr)++ = '<';
    for (j = 0; j < ranges[i].dim; j++) {
      sputx(ranges[i].codeHi[j], &(wbuf.curptr), wbuf.limptr);
    }
    *(wbuf.curptr)++ = '>';
    *(wbuf.curptr)++ = '\n';
  }
  pdf_add_stream(stream, wbuf.buf, (int)(wbuf.curptr - wbuf.buf));
  wbuf.curptr = wbuf.buf;
  pdf_add_stream(stream,
		 "endcodespacerange\n", strlen("endcodespacerange\n"));

  /* CMap body */
  if (cmap->mapTbl) {
    count = write_map(cmap->mapTbl,
		      0, codestr, 0, &wbuf, stream); /* Top node */
    if (count > 0) { /* Flush */
      char fmt_buf[32];
      if (count > 100)
	ERROR("Unexpected error....: %d", count);
      sprintf(fmt_buf, "%d beginbfchar\n", count);
      pdf_add_stream(stream, fmt_buf,  strlen(fmt_buf));
      pdf_add_stream(stream,
		     wbuf.buf, (int) (wbuf.curptr - wbuf.buf));
      pdf_add_stream(stream,
		     "endbfchar\n", strlen("endbfchar\n"));
      count = 0;
      wbuf.curptr = wbuf.buf;
    }
  }
  /* End CMap */
  pdf_add_stream(stream, CMAP_END, strlen(CMAP_END));

  RELEASE(codestr);
  RELEASE(wbuf.buf);

  return stream;
}
Exemple #12
0
static int
write_map (mapDef *mtab, int count,
	   unsigned char *codestr, int depth,
	   struct sbuf *wbuf, pdf_obj *stream)
{
  int     c, i, block_length;
  mapDef *mtab1;
  /* Must be greater than 1 */
#define BLOCK_LEN_MIN 2
  struct {
    int start, count;
  } blocks[256/BLOCK_LEN_MIN+1];
  int num_blocks = 0;

  for (c = 0; c < 256; c++) {
    codestr[depth] = (unsigned char) (c & 0xff);
    if (LOOKUP_CONTINUE(mtab[c].flag)) {
      mtab1 = mtab[c].next;
      count = write_map(mtab1, count,
			codestr, depth + 1, wbuf, stream);
    } else {
      if (MAP_DEFINED(mtab[c].flag)) {
	switch (MAP_TYPE(mtab[c].flag)) {
	case MAP_IS_CID: case MAP_IS_CODE:
	  block_length = block_count(mtab, c);
	  if (block_length >= BLOCK_LEN_MIN) {
	    blocks[num_blocks].start = c;
	    blocks[num_blocks].count = block_length;
	    num_blocks++;
	    c += block_length;
	  } else {
	    *(wbuf->curptr)++ = '<';
	    for (i = 0; i <= depth; i++)
	      sputx(codestr[i], &(wbuf->curptr), wbuf->limptr);
	    *(wbuf->curptr)++ = '>';
	    *(wbuf->curptr)++ = ' ';
	    *(wbuf->curptr)++ = '<';
	    for (i = 0; i < mtab[c].len; i++)
	      sputx(mtab[c].code[i], &(wbuf->curptr), wbuf->limptr);
	    *(wbuf->curptr)++ = '>';
	    *(wbuf->curptr)++ = '\n';
	    count++;
	  }
	  break;
	case MAP_IS_NAME:
	  ERROR("%s: Unexpected error...", CMAP_DEBUG_STR);
	  break;
	case MAP_IS_NOTDEF:
	  break;
	default:
	  ERROR("%s: Unknown mapping type: %d",
		CMAP_DEBUG_STR, MAP_TYPE(mtab[c].flag));
	}
      }
    }

    /* Flush if necessary */
    if (count >= 100 ||
	wbuf->curptr >= wbuf->limptr ) {
      char fmt_buf[32];
      if (count > 100)
	ERROR("Unexpected error....: %d", count);
      sprintf(fmt_buf, "%d beginbfchar\n", count);
      pdf_add_stream(stream, fmt_buf,  strlen(fmt_buf));
      pdf_add_stream(stream,
		     wbuf->buf, (int) (wbuf->curptr - wbuf->buf));
      wbuf->curptr = wbuf->buf;
      pdf_add_stream(stream,
		     "endbfchar\n", strlen("endbfchar\n"));
      count = 0;
    }
  }

  if (num_blocks > 0) {
    char fmt_buf[32];

    if (count > 0) {
      sprintf(fmt_buf, "%d beginbfchar\n", count);
      pdf_add_stream(stream, fmt_buf,  strlen(fmt_buf));
      pdf_add_stream(stream,
		     wbuf->buf, (int) (wbuf->curptr - wbuf->buf));
      wbuf->curptr = wbuf->buf;
      pdf_add_stream(stream,
		     "endbfchar\n", strlen("endbfchar\n"));
      count = 0;
    }
    sprintf(fmt_buf, "%d beginbfrange\n", num_blocks);
    pdf_add_stream(stream, fmt_buf, strlen(fmt_buf));
    for (i = 0; i < num_blocks; i++) {
      int j;

      c = blocks[i].start;
      *(wbuf->curptr)++ = '<';
      for (j = 0; j < depth; j++)
	sputx(codestr[j], &(wbuf->curptr), wbuf->limptr);
      sputx((unsigned char)c, &(wbuf->curptr), wbuf->limptr);
      *(wbuf->curptr)++ = '>';
      *(wbuf->curptr)++ = ' ';
      *(wbuf->curptr)++ = '<';
      for (j = 0; j < depth; j++)
	sputx(codestr[j], &(wbuf->curptr), wbuf->limptr);
      sputx((unsigned char)(c + blocks[i].count), &(wbuf->curptr), wbuf->limptr);
      *(wbuf->curptr)++ = '>';
      *(wbuf->curptr)++ = ' ';
      *(wbuf->curptr)++ = '<';
      for (j = 0; j < mtab[c].len; j++)
	sputx(mtab[c].code[j], &(wbuf->curptr), wbuf->limptr);
      *(wbuf->curptr)++ = '>';
      *(wbuf->curptr)++ = '\n';
    }
    pdf_add_stream(stream,
		   wbuf->buf, (int) (wbuf->curptr - wbuf->buf));
    wbuf->curptr = wbuf->buf;
    pdf_add_stream(stream,
		   "endbfrange\n", strlen("endbfrange\n"));
  }

  return count;
}