std::vector<std::string> genericFilechooserWindow::getPathToFiles
(
	void
)
{
	return (get_action() != Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER)
		? get_filenames()
		: genericFeatures::listFiles(get_filenames().at(0));
}
예제 #2
0
static char * test_get_filename() {
    char **argv;
    char filename[FILENAME_MAX];
    char fileout[FILENAME_MAX];
    int argc, i, ret;
    printf("Testing %s\n", __FUNCTION__);
    
    /* malloc the argv */
    argv = (char **) malloc (NUM_ARGS * sizeof(char *));
    for (i=0; i<NUM_ARGS; i++) {
        /* give it a length of 30, and use calloc for memset */
        argv[i] = (char *) calloc (30, sizeof(char));
    }
    argc = i;
    /* give it some values */
    strcpy(argv[0], "parse");
    strcpy(argv[1], "filename.txt");
    strcpy(argv[2], "fileout.txt");
    
    ret = get_filenames(argc, argv, filename, fileout);
    mu_assert("error, ret != 0", ret == 0);
    /* filename should have "filename.txt" */
    mu_assert("error, filename != \"filename.txt\"", strcmp(filename, "filename.txt") == 0);
    mu_assert("error, fileout != \"fileout.txt\"", strcmp(fileout, "fileout.txt") == 0);    
    
    /* what if the num args are not right? */
    argc = 1;
    /* there should be an error */
    ret = get_filenames(argc, argv, filename, fileout);
    mu_assert("error, ret != ARGS_ERR", ret == ARGS_ERR);
    
    /* no output file */
    argc = 2;
    /* there should be an error */
    ret = get_filenames(argc, argv, filename, fileout);
    mu_assert("error, ret != ARGS_ERR", ret == ARGS_ERR);    
   
    for (i=0; i<NUM_ARGS; i++) {
        free(argv[i]);
    }
    free(argv);

    return 0;
}
예제 #3
0
std::vector<std::string>
ArchiveManager::get_filenames(const std::string& zip_filename, 
                              const ArchiveLoader** loader_out) const
{
  auto loader = find_loader_by_filename(zip_filename);
  if (!loader)
  {
    raise_exception(std::runtime_error, "failed to find loader for archive file: " << zip_filename);
  }
  else
  {
    try
    {
      if (loader_out) { *loader_out = loader; }
      return loader->get_filenames(zip_filename);
    }
    catch(const std::exception& err)
    {
      auto new_loader = find_loader_by_magic(zip_filename);
      
      if (!new_loader || new_loader == loader)
      {
        throw;
        return std::vector<std::string>();
      }
      else
      {
        loader = new_loader;
        if (!loader)
        {
          raise_exception(std::runtime_error, "failed to find loader for archive file: " << zip_filename);
        }
        else
        {
          log_warning << err.what() << std::endl;
          if (loader_out) { *loader_out = loader; }
          return loader->get_filenames(zip_filename);
        }
      }
    }
  }
}
예제 #4
0
void chan_post::print() const {
    std::cout 
        << "Board = " << get_board() << "\n"
        << "Thread_id = " << get_thread_id() << "\n"
        << "Post_id = " << get_id() << "\n"
        << "Content = " << get_com().substr(0, 160) << "\n"
        << "Filenames = [" << std::endl;
    for (const auto &a : get_filenames()) {
        std::cout << a << "\n";
    }
        std::cout << "]" << std::endl;
}
예제 #5
0
MStatus OxDnaTranslator::reader (const MFileObject& file, const MString & options, MPxFileTranslator::FileAccessMode mode) {
    MStatus status;

    MString top_filename, conf_filename, vhelix_filename;
    get_filenames(file, top_filename, conf_filename, vhelix_filename);

    OxDnaImportWithAdvanceProgress importer;

    HMEVALUATE(status = importer.read(top_filename.asChar(), conf_filename.asChar(), vhelix_filename.asChar()), status);

    MProgressWindow::endProgress();

    return status;
}
예제 #6
0
bool chan_post::operator==(const chan_post &other) const
{
    if (this->id != other.id 
        || this->sub != other.sub
        || this->thread_id != other.thread_id
        || this->com != other.com) 
    {
        return false;
    }
    
    const auto &o = other.get_filenames();
    for (const auto &a : get_filenames()) {
        if (std::find(o.begin(), o.end(), a) == o.end()) {
            return false;
        }
    }

    return true;
}
예제 #7
0
		int get_filenames(const std::string& dir, std::vector<std::string>& filenames)
		{
			fs::path path(dir);
			if (!fs::exists(path))
			{
				return -1;
			}

			fs::directory_iterator end_iter;
			for (fs::directory_iterator iter(path); iter != end_iter; ++iter)
			{
				if (fs::is_regular_file(iter->status()))
				{
					filenames.push_back(iter->path().string());
				}

				if (fs::is_directory(iter->status()))
				{
					get_filenames(iter->path().string(), filenames);
				}
			}

			return filenames.size();
		}
예제 #8
0
int run_game(int game)
{
	int err;

	/* copy some settings into easier-to-handle variables */
	record     = options.record;
	playback   = options.playback;
	mame_debug = options.mame_debug;

	Machine->gamedrv = gamedrv = drivers[game];
	Machine->drv = drv = gamedrv->drv;

	/* copy configuration */
	if (options.color_depth == 16 ||
			(options.color_depth != 8 && (Machine->gamedrv->flags & GAME_REQUIRES_16BIT)))
		Machine->color_depth = 16;
	else
		Machine->color_depth = 8;

	//if (options.vector_width == 0) options.vector_width = 640;
	//if (options.vector_height == 0) options.vector_height = 480;
	if (options.vector_width == 0) options.vector_width = 320;
	if (options.vector_height == 0) options.vector_height = 240;

	Machine->sample_rate = options.samplerate;

	/* get orientation right */
	Machine->orientation = gamedrv->flags & ORIENTATION_MASK;
	Machine->ui_orientation = ROT0;
	if (options.norotate)
		Machine->orientation = ROT0;
	if (options.ror)
	{
		/* if only one of the components is inverted, switch them */
		if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->orientation ^= ROT180;

		Machine->orientation ^= ROT90;

		/* if only one of the components is inverted, switch them */
		if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->ui_orientation ^= ROT180;

		Machine->ui_orientation ^= ROT90;
	}
	if (options.rol)
	{
		/* if only one of the components is inverted, switch them */
		if ((Machine->orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->orientation ^= ROT180;

		Machine->orientation ^= ROT270;

		/* if only one of the components is inverted, switch them */
		if ((Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_X ||
				(Machine->ui_orientation & ROT180) == ORIENTATION_FLIP_Y)
			Machine->ui_orientation ^= ROT180;

		Machine->ui_orientation ^= ROT270;
	}
	if (options.flipx)
	{
		Machine->orientation ^= ORIENTATION_FLIP_X;
		Machine->ui_orientation ^= ORIENTATION_FLIP_X;
	}
	if (options.flipy)
	{
		Machine->orientation ^= ORIENTATION_FLIP_Y;
		Machine->ui_orientation ^= ORIENTATION_FLIP_Y;
	}

	set_pixel_functions();

	/* Do the work*/
	err = 1;
	bailing = 0;

	#ifdef MESS
	if (get_filenames())
		return err;
	#endif

	if (osd_init() == 0)
	{
		if (init_machine() == 0)
		{
			if (run_machine() == 0)
				err = 0;
			else if (!bailing)
			{
				bailing = 1;
				printf("Unable to start machine emulation\n");
			}

			shutdown_machine();
		}
		else if (!bailing)
		{
			bailing = 1;
			printf("Unable to initialize machine emulation\n");
		}

		osd_exit();
	}
	else if (!bailing)
	{
		bailing = 1;
		printf ("Unable to initialize system\n");
	}

	return err;
}
/* 
 * See the header file for the use of this function
 */
EDITORCONFIG_EXPORT
int editorconfig_parse(const char* full_filename, editorconfig_handle h)
{
    handler_first_param                 hfp;
    char**                              config_file;
    char**                              config_files;
    int                                 err_num;
    int                                 i;
    struct editorconfig_handle*         eh = (struct editorconfig_handle*)h;
    struct editorconfig_version         cur_ver;
    struct editorconfig_version         tmp_ver;

    /* get current version */
    editorconfig_get_version(&cur_ver.major, &cur_ver.minor,
            &cur_ver.subminor);

    /* if version is set to 0.0.0, we set it to current version */
    if (eh->ver.major == 0 &&
            eh->ver.minor == 0 &&
            eh->ver.subminor == 0)
        eh->ver = cur_ver;

    if (editorconfig_compare_version(&eh->ver, &cur_ver) > 0)
        return EDITORCONFIG_PARSE_VERSION_TOO_NEW;

    if (!eh->err_file) {
        free(eh->err_file);
        eh->err_file = NULL;
    }

    /* if eh->conf_file_name is NULL, we set ".editorconfig" as the default
     * conf file name */
    if (!eh->conf_file_name)
        eh->conf_file_name = ".editorconfig";

    if (eh->name_values) {
        /* free name_values */
        for (i = 0; i < eh->name_value_count; ++i) {
            free(eh->name_values[i].name);
            free(eh->name_values[i].value);
        }
        free(eh->name_values);

        eh->name_values = NULL;
        eh->name_value_count = 0;
    }
    memset(&hfp, 0, sizeof(hfp));

    hfp.full_filename = strdup(full_filename);

    /* return an error if file path is not absolute */
    if (!is_file_path_absolute(full_filename)) {
        return EDITORCONFIG_PARSE_NOT_FULL_PATH;
    }

#ifdef WIN32
    /* replace all backslashes with slashes on Windows */
    str_replace(hfp.full_filename, '\\', '/');
#endif

    array_editorconfig_name_value_init(&hfp.array_name_value);

    config_files = get_filenames(hfp.full_filename, eh->conf_file_name);
    for (config_file = config_files; *config_file != NULL; config_file++) {
        split_file_path(&hfp.editorconfig_file_dir, NULL, *config_file);
        if ((err_num = ini_parse(*config_file, ini_handler, &hfp)) != 0 &&
                /* ignore error caused by I/O, maybe caused by non exist file */
                err_num != -1) {
            eh->err_file = strdup(*config_file);
            free(*config_file);
            free(hfp.full_filename);
            free(hfp.editorconfig_file_dir);
            return err_num;
        }

        free(hfp.editorconfig_file_dir);
        free(*config_file);
    }

    /* value proprocessing */

    /* For v0.9 */
    SET_EDITORCONFIG_VERSION(&tmp_ver, 0, 9, 0);
    if (editorconfig_compare_version(&eh->ver, &tmp_ver) >= 0) {
    /* Set indent_size to "tab" if indent_size is not specified and
     * indent_style is set to "tab". Only should be done after v0.9 */
        if (hfp.array_name_value.spnvp.indent_style &&
                !hfp.array_name_value.spnvp.indent_size &&
                !strcmp(hfp.array_name_value.spnvp.indent_style->value, "tab"))
            array_editorconfig_name_value_add(&hfp.array_name_value,
                    "indent_size", "tab");
    /* Set indent_size to tab_width if indent_size is "tab" and tab_width is
     * specified. This behavior is specified for v0.9 and up. */
        if (hfp.array_name_value.spnvp.indent_size &&
            hfp.array_name_value.spnvp.tab_width &&
            !strcmp(hfp.array_name_value.spnvp.indent_size->value, "tab"))
        array_editorconfig_name_value_add(&hfp.array_name_value, "indent_size",
                hfp.array_name_value.spnvp.tab_width->value);
    }

    /* Set tab_width to indent_size if indent_size is specified. If version is
     * not less than 0.9.0, we also need to check when the indent_size is set
     * to "tab", we should not duplicate the value to tab_width */
    if (hfp.array_name_value.spnvp.indent_size &&
            !hfp.array_name_value.spnvp.tab_width &&
            (editorconfig_compare_version(&eh->ver, &tmp_ver) < 0 ||
             strcmp(hfp.array_name_value.spnvp.indent_size->value, "tab")))
        array_editorconfig_name_value_add(&hfp.array_name_value, "tab_width",
                hfp.array_name_value.spnvp.indent_size->value);

    eh->name_value_count = hfp.array_name_value.current_value_count;

    if (eh->name_value_count == 0) {  /* no value is set, just return 0. */
        free(hfp.full_filename);
        free(config_files);
        return 0;
    }
    eh->name_values = hfp.array_name_value.name_values;
    eh->name_values = realloc(      /* realloc to truncate the unused spaces */
            eh->name_values,
            sizeof(editorconfig_name_value) * eh->name_value_count);
    if (eh->name_values == NULL) {
        free(hfp.full_filename);
        return EDITORCONFIG_PARSE_MEMORY_ERROR;
    }

    free(hfp.full_filename);
    free(config_files);

    return 0;
}
예제 #10
0
MStatus OxDnaTranslator::writer (const MFileObject& file, const MString& optionsString, MPxFileTranslator::FileAccessMode mode) {
    MStatus status;
    MObjectArray helices;
    HMEVALUATE_RETURN(status = Model::Helix::AllSelected(helices), status);

    if (helices.length() == 0) {
        HMEVALUATE_RETURN(status = Model::Helix::All(helices), status);
    }

    if (helices.length() == 0) {
        MGlobal::displayError("Nothing to export. Aborting...");
        return MStatus::kSuccess;
    }

    if (!MProgressWindow::reserve())
        MGlobal::displayWarning("Failed to reserve the progress window");

    MProgressWindow::setTitle("oxDNA Exporter");
    MProgressWindow::setProgressStatus("Identifying strands...");
    MProgressWindow::setProgressRange(0, helices.length());
    MProgressWindow::startProgress();

    MVector minTranslation(std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()),
            maxTranslation(-std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity(), -std::numeric_limits<double>::infinity());

    // Since a strand is defined by any base along it, the same strand will be obtained multiple times if we don't track them.
    // This is pretty slow but, since it is only run once it should be ok.
    std::list<Model::Strand> strands;

    for (unsigned int i = 0; i < helices.length(); ++i) {
        Model::Helix helix(helices[i]);

        for (Model::Helix::BaseIterator it = helix.begin(); it != helix.end(); ++it) {
            MVector translation;
            HMEVALUATE_RETURN(status = it->getTranslation(translation, MSpace::kWorld), status);

            minTranslation.x = std::min(minTranslation.x, translation.x);
            minTranslation.y = std::min(minTranslation.y, translation.y);
            minTranslation.z = std::min(minTranslation.z, translation.z);

            maxTranslation.x = std::max(maxTranslation.x, translation.x);
            maxTranslation.y = std::max(maxTranslation.y, translation.y);
            maxTranslation.z = std::max(maxTranslation.z, translation.z);

            if (std::find_if(strands.begin(), strands.end(), std::bind2nd(std::ptr_fun(&Model::Strand::Contains_base), *it)) == strands.end())
                strands.push_back(*it);
        }

        MProgressWindow::advanceProgress(1);
    }

    MProgressWindow::endProgress();

    if (!MProgressWindow::reserve())
        MGlobal::displayWarning("Failed to reserve the progress window");

    MProgressWindow::setTitle("oxDNA Exporter");
    MProgressWindow::setProgressStatus("Writing strands...");
    MProgressWindow::setProgressRange(0, helices.length());
    MProgressWindow::startProgress();

    OxDnaExporterWithAdvanceProgress exporter;
    HMEVALUATE(std::for_each(strands.begin(), strands.end(), exporter.execute()), exporter.status());

    MProgressWindow::endProgress();

    if (!exporter.status())
        return exporter.status();

    MString top_filename, conf_filename, vhelix_filename;
    get_filenames(file, top_filename, conf_filename, vhelix_filename);

    HMEVALUATE_RETURN(status = exporter.write(
                                   top_filename.asChar(), conf_filename.asChar(), vhelix_filename.asChar(), minTranslation, maxTranslation), status);

    return status;
}
예제 #11
0
void write_test_theta_file()
{
  // first: merge processes to have the right input files
  //merge_processes();

  TFile* of = new TFile("thetainput.root", "RECREATE");

  TString dir = string(".");
  vector<TString> fnames = vector<TString>();
  get_filenames(fnames);

  for (unsigned int i = 0;i < fnames.size();i++) {
    cout << "opening file " << fnames[i] << endl;
    TFile* f = new TFile(fnames[i], "READ");



    
    /*
    TH1D* h = f->Get("Chi2_BTag/M_ttbar_rec");
    of->cd();
    TH1D* wh = (TH1D*) h->Clone();
    TString name = get_full_name(fnames[i], "mu_btag_mttbar");
    wh->SetName(name);

    
    TH1D* h2 = f->Get("Chi2_NoBTag/M_ttbar_rec");
    of->cd();
    TH1D* wh2 = (TH1D*) h2->Clone();
    TString name = get_full_name(fnames[i], "mu_nobtag_mttbar");
    wh2->SetName(name);
    */
       
    TH1D* h = f->Get("t1__hyp_chi2min/M_ttbar_rec");
    of->cd();
    TH1D* wh = (TH1D*) h->Clone();
    TString name = get_full_name(fnames[i], "mu_toptag_mttbar");
       wh->SetName(name);

    
    TH1D* h2 = f->Get("t0b1__hyp_chi2min/M_ttbar_rec");
    of->cd();
    TH1D* wh2 = (TH1D*) h2->Clone();
    TString name = get_full_name(fnames[i], "mu_notoptagbtag_mttbar");
    //  name.ReplaceAll("mu_toptagsumbtag1_mttbar", "mu_1top1btag_mttbar");
    wh2->SetName(name);
    
    TH1D* h3 = f->Get("t0b0__hyp_chi2min/M_ttbar_rec");
    of->cd();
    TH1D* wh3 = (TH1D*) h3->Clone();
    TString name = get_full_name(fnames[i], "mu_notoptagnobtag_mttbar");
    //  name.ReplaceAll("mu_toptagsumbtag2_mttbar", "mu_1top2btag_mttbar");
    wh3->SetName(name);

    
    
    f->Close();
    delete f;
  }

  cout << "\nwrote file " << of->GetName() << endl;

  of->Write();
  of->Close();
  delete of;
  

}
예제 #12
0
int main( int argc, const char *argv[] )
{
    const int minargs = 4;  // including command name
    
    int last_count = -1;

    struct Terrain_Progress_Callback progress = { print_progress, &last_count };

    int argnum;

    const char *thisarg;
    char *endptr;
    char extension[4];  // 3 chars plus null terminator

    char *in_dat_name;
    char *in_hdr_name;
    char *in_prj_name;
    char *out_dat_name;
    char *out_hdr_name;
    char *out_prj_name;

    double detail;

    FILE *in_dat_file;
    FILE *in_hdr_file;
    FILE *in_prj_file;
    FILE *out_dat_file;
    FILE *out_hdr_file;
    FILE *out_prj_file;
    
    int nrows;
    int ncols;
    double xmin;
    double xmax;
    double ymin;
    double ymax;
    double xdim;
    double ydim;
    float *data;
    char *software;
    
    enum Terrain_Coord_Type coord_type;
    
    int proj_type;
    int has_nulls;
    int all_ints;

    double lat1 = 0.0;  // default unless -merc option used
    double lat2 = 0.0;  // default unless -merc option used
    double center_lat;
    double temp;

    int error;

    printf( "\nTerrain texture shading program - version %s, built %s\n", sw_version, sw_date );

    // Validate parameters:

//  command_name = "TEXTURE";
    command_name = get_command_name( argv );

    if (argc == 1) {
        usage_exit( 0 );
    } else if (argc < minargs) {
        usage_exit( "Not enough command-line parameters." );
    }
    
    argnum = 1;
    
    thisarg = argv[argnum++];
    if ( strchr( thisarg, '/' ) ) {
        // read fraction: integer/integer
        detail = (double)strtol( thisarg, &endptr, 10 );
        if (endptr == thisarg || *endptr != '/' || endptr[1] < '1' || endptr[1] > '9') {
            usage_exit( "First parameter (detail) must be a number or fraction." );
        }
        detail /= (double)strtol( endptr+1, &endptr, 10 );
    } else {
        // read decimal number
        detail = strtod( thisarg, &endptr );
    }
    if (endptr == thisarg || *endptr != '\0') {
        usage_exit( "First parameter (detail) must be a number or fraction." );
    }

    software = (char *)malloc( strlen(sw_format) + strlen(sw_name) + strlen(sw_version) + strlen(sw_date) );
    if (!software) {
        prefix_error();
        fprintf( stderr, "Memory allocation error occurred.\n" );
        exit( EXIT_FAILURE );
    }
    sprintf( software, sw_format, sw_name, sw_version, sw_date );

    // Validate filenames and open files:

    strncpy( extension, "flt", 4 );
    get_filenames( argv[argnum++], &in_dat_name, &in_hdr_name, &in_prj_name, extension );
    
    strncpy( extension, "flt", 4 );
    get_filenames( argv[argnum++], &out_dat_name, &out_hdr_name, &out_prj_name, extension );
    
    if (!strcmp( in_hdr_name, out_hdr_name )) {
        usage_exit( "Input and outfile filenames must not be the same." );
    }
    
    while (argnum < argc) {
        thisarg = argv[argnum++];
        if (*thisarg != '-') {
            prefix_error();
            fprintf( stderr, "Extra command-line parameter '%s' not recognized.\n", thisarg );
            usage_exit( 0 );
        }
        ++thisarg;
        if (strncmp( thisarg, "mercator", 4 ) == 0 || strncmp( thisarg, "Mercator", 4 ) == 0) {
            if (argnum+1 >= argc) {
                usage_exit( "Option -mercator must be followed by two numeric latitude values." );
            }
            thisarg = argv[argnum++];
            lat1 = strtod( thisarg, &endptr );
            if (endptr == thisarg || *endptr != '\0') {
                usage_exit( "Option -mercator must be followed by two numeric latitude values." );
            }
            thisarg = argv[argnum++];
            lat2 = strtod( thisarg, &endptr );
            if (endptr == thisarg || *endptr != '\0') {
                usage_exit( "Option -mercator must be followed by two numeric latitude values." );
            }
            if (lat1 == lat2) {
                usage_exit( "Min & max mercator latitudes cannot be equal." );
            }
            if (lat1 > lat2) {
                temp = lat1;
                lat1 = lat2;
                lat2 = temp;
            }
            if (lat1 <= -90.0 || lat2 >= 90.0) {
                usage_exit( "Mercator latitude limits must be between -90 and +90 (exclusive)." );
            }
        } else if (strncmp( thisarg, "cellreg", 4 ) == 0 ||
                   strncmp( thisarg, "corner",  6 ) == 0)
        {
            // ignore flag - cellreg is currently assumed
        } else if (strncmp( thisarg, "gridreg", 4 ) == 0 ||
                   strncmp( thisarg, "center",  6 ) == 0)
        {
            fprintf( stderr, "\n" );
            fprintf( stderr, "*** WARNING: " );
            fprintf( stderr, "Option -%s is not yet implemented.\n", thisarg );
            fprintf( stderr, "***          " );
            fprintf( stderr, "Treating data as cell-registered (corner-aligned).\n" );
        } else {
            prefix_error();
            fprintf( stderr, "Command-line option '-%s' not recognized.\n", thisarg );
            usage_exit( 0 );
        }
    }
    
    in_hdr_file = fopen( in_hdr_name, "rb" );   // use binary mode for compatibility
    if (!in_hdr_file) {
        prefix_error();
        fprintf( stderr, "Could not open input file '%s'.\n", in_hdr_name );
        usage_exit( 0 );
    }

    in_dat_file = fopen( in_dat_name, "rb" );
    if (!in_dat_file) {
        prefix_error();
        fprintf( stderr, "Could not open input file '%s'.\n", in_dat_name );
        usage_exit( 0 );
    }
    
    free( in_dat_name );
    free( in_hdr_name );

    out_hdr_file = fopen( out_hdr_name, "wb" ); // use binary mode for compatibility
    if (!out_hdr_file) {
        prefix_error();
        fprintf( stderr, "Could not open output file '%s'.\n", out_hdr_name );
        usage_exit( 0 );
    }

    out_dat_file = fopen( out_dat_name, "wb" );
    if (!out_dat_file) {
        prefix_error();
        fprintf( stderr, "Could not open output file '%s'.\n", out_dat_name );
        usage_exit( 0 );
    }
    
    free( out_dat_name );
    free( out_hdr_name );

    // Read .flt and .hdr files:

    printf( "Reading input files...\n" );
    fflush( stdout );

    data = read_flt_hdr_files(
        in_dat_file, in_hdr_file, &nrows, &ncols, &xmin, &xmax, &ymin, &ymax,
        &has_nulls, &all_ints, 0 );
    
    fclose( in_dat_file );
    fclose( in_hdr_file );

    if (has_nulls) {
        fprintf( stderr, "*** WARNING: " );
        fprintf( stderr, "Input .flt file contains void (NODATA) points.\n" );
        fprintf( stderr, "***          " );
        fprintf( stderr, "Assuming these are ocean points - setting these elevations to 0.\n" );
    }
    
    if (all_ints && detail > 0.0) {
        fprintf( stderr, "*** WARNING: " );
        fprintf( stderr, "Input .flt file appears to contain only integer values.\n" );
        fprintf( stderr, "***          " );
        fprintf( stderr, "This may degrade the quality of the result.\n" );
    }

    // Process data:

    xdim = (xmax - xmin) / (double)ncols;
    ydim = (ymax - ymin) / (double)nrows;

    // determine projection type
    proj_type = determine_projection( xmin, xmax, ymin, ymax, xdim, ydim );
    
    if (proj_type < 0) {
        coord_type = TERRAIN_DEGREES;
        center_lat = 0.5 * (ymin + ymax);
        
        printf( "\nInput data appears to be in lat/lon (geographic) coordinates.\n" );
        fflush( stdout );
    } else if (proj_type > 0) {
        coord_type = TERRAIN_METERS;
        center_lat = 0.0;   // ignored when coord_type == TERRAIN_METERS
        
        printf( "\nInput data appears to be projected into linear coordinates " );
        printf( "(easting/northing).\n" );
        fflush( stdout );
    } else {
        prefix_error();
        fprintf( stderr, "Unable to determine projection type from info in .hdr file.\n" );
        exit( EXIT_FAILURE );
    }

    if (lat1 != lat2) {
        if (proj_type < 0) {
            usage_exit( "Option -mercator is invalid for data in geographic coordinates." );
        }
        proj_type = 2;  // indicate Mercator projection
        
        printf( "Assuming input data is in normal-aspect Mercator projection.\n" );
        printf( "Latitude range %.3f deg %c to %.3f deg %c.\n",
            fabs(lat1), lat1>=0.0 ? 'N' : 'S', fabs(lat2), lat2>=0.0 ? 'N' : 'S' );
        printf( "(NOTE: Do NOT use option -mercator with UTM projection.)\n\n" );

    }
    
    // check pixel aspect ratio and size of map extent
    check_aspect( xmin, xmax, ymin, ymax, xdim, ydim, proj_type );
    
    if (detail <= 0.0 || detail > 2.0) {
        fprintf( stderr, "*** WARNING: " );
        fprintf( stderr, "Unusual value for detail exponent. Is this correct?\n" );
    }
    
    printf(
        "Processing %d column x %d row array using detail = %f...\n",
        ncols, nrows, detail );
    fflush( stdout );

    error = terrain_filter(
        data, detail, nrows, ncols, xdim, ydim, coord_type, center_lat, &progress );

    if (error) {
        assert( error == TERRAIN_FILTER_MALLOC_ERROR );
        prefix_error();
        fprintf( stderr, "Memory allocation error occurred during processing of data.\n" );
        exit( EXIT_FAILURE );
    }
    
    if (lat1 != lat2) {
        fix_mercator( data, detail, nrows, ncols, lat1, lat2 );
    }

    // Write .flt and .hdr files:

    printf( "Writing output files...\n" );
    fflush( stdout );

    write_flt_hdr_files(
        out_dat_file, out_hdr_file, nrows, ncols, xmin, xmax, ymin, ymax, data, software );
    
    fclose( out_dat_file );
    fclose( out_hdr_file );

    free( data );
    free( software );
    
    // Copy optional .prj file:

    in_prj_file = fopen( in_prj_name, "rb" );   // use binary mode for compatibility
    if (in_prj_file) {
        out_prj_file = fopen( out_prj_name, "wb" ); // use binary mode for compatibility
        if (!out_prj_file) {
            fprintf( stderr, "*** WARNING: " );
            fprintf( stderr, "Could not open output file '%s'.\n", out_prj_name );
        } else {
            // copy file and change any "ZUNITS" line to "ZUNITS NO"
            copy_prj_file( in_prj_file, out_prj_file );

            fclose( out_prj_file );
        }
        fclose( in_prj_file );
    }

    free( in_prj_name );
    free( out_prj_name );

    printf( "DONE.\n" );

    return EXIT_SUCCESS;
}
예제 #13
0
파일: filebrowser.c 프로젝트: lkjcalc/nTxt
int filebrowser(void* scrbuf, char* file, char* title)
{
    char currentdir[FILENAME_MAX + 1];
    char* filenames[1024];
    char filenameinput[FILENAME_MAX + 1] = "";
    char blockc = '\0';
    int focus_filenameinput = 1;
    int num_files;
    int filescroll = 0;
    int fileselected = 0;
    int i;
    int inputpause = 0;
    if (get_last_doc(currentdir) != 0) {
        getcwd(currentdir, FILENAME_MAX + 1);
    }
    else {
        *(strrchr(currentdir, '/') + 1) = '\0';
    }

    num_files = get_filenames(currentdir, filenames);
    if (num_files == -1)
        return 1;

    wait_no_key_pressed();
    while (1) {
        //disp:
        clearScreen(scrbuf);
        filledRect(scrbuf, 0, TITLE_Y, SCREEN_WIDTH, TITLE_HEIGHT, 0);
        dispStringColor(scrbuf, 4, (TITLE_HEIGHT - CHAR_HEIGHT) / 2, title, WHITE_COLOR, 0);
        dispHorizLine(scrbuf, 0, DIR_Y + DIR_HEIGHT - 1, 320, 0);
        dispString(scrbuf, 4, DIR_Y + (DIR_HEIGHT - CHAR_HEIGHT) / 2, currentdir);
        dispHorizLine(scrbuf, 0, FILENAMEINPUT_Y, 320, 0);
        dispString(scrbuf, 4, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, "Filename:");
        dispString(scrbuf, 4 + 10 * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, filenameinput);
        if (focus_filenameinput)//if cursor is in the file name input field, disp an underline to show it
            putChar(scrbuf, 4 + (10 + strlen(filenameinput)) * CHAR_WIDTH, FILENAMEINPUT_Y + (FILENAMEINPUT_HEIGHT - CHAR_HEIGHT) / 2, '_');
        for (i = filescroll; i < filescroll + FILES_SHOWN && i < num_files; i++) {
            //disp file symbol
            if (is_dir(filenames[i]) && strcmp(filenames[i], ".") && strcmp(filenames[i], ".."))
                putChar(scrbuf, CHAR_WIDTH * 2, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, '\\');
            //disp filename, filesize and selection
            if (i != fileselected || focus_filenameinput) {
                dispString(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i]);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispString(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size);
                }
            }
            else {
                filledRect(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT - 1, SCREEN_WIDTH - CHAR_WIDTH * 4, CHAR_HEIGHT + 2, MENU_SELECTION_COLOR);
                dispStringColor(scrbuf, CHAR_WIDTH * 3, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, filenames[i], WHITE_COLOR, MENU_SELECTION_COLOR);
                if (!is_dir(filenames[i])) {
                    char size[16];
                    get_filesize(filenames[i], size);
                    dispStringColor(scrbuf, FILENAME_WIDTH, DIRLIST_Y + (i - filescroll) * CHAR_HEIGHT, size, WHITE_COLOR, MENU_SELECTION_COLOR);
                }
            }
        }
        showBuffer(scrbuf);


        //input
        if (!any_key_pressed())
            inputpause = 0;
        else
            inputpause--;

        if (isKeyPressed(KEY_NSPIRE_ESC))
            break;
        if (isKeyPressed(KEY_NSPIRE_TAB)) {
            focus_filenameinput = !focus_filenameinput;
            wait_no_key_pressed();
        }

        if (!focus_filenameinput) {
            if (isKeyPressed(KEY_NSPIRE_ENTER) && (blockc != '\n' || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = '\n';
                if (is_dir(filenames[fileselected])) {
                    chdir(filenames[fileselected]);
                    filescroll = 0;
                    fileselected = 0;
                    free_filenames(filenames);
                    getcwd(currentdir, FILENAME_MAX + 1);
                    num_files = get_filenames(currentdir, filenames);
                }
                else {
                    strcpy(file, currentdir);
                    strcat(file, filenames[fileselected]);
                    free_filenames(filenames);
                    printf("%s\n", file);
                    return 0;
                }
            }
            else if (isKeyPressed(KEY_NSPIRE_UP) && (blockc != 0x1 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x1;
                fileselected--;
                if (fileselected < 0) {
                    fileselected = num_files - 1;
                    filescroll = num_files - FILES_SHOWN;
                    if (filescroll < 0)
                        filescroll = 0;
                }
                else if (fileselected - filescroll < 0)
                    filescroll--;
                strcpy(filenameinput, filenames[fileselected]);
            }
            else if (isKeyPressed(KEY_NSPIRE_DOWN) && (blockc != 0x2 || inputpause <= 0)) {
                inputpause = INPUTPAUSE;
                blockc = 0x2;
                fileselected++;
                if (fileselected >= num_files) {
                    fileselected = 0;
                    filescroll = 0;
                }
                else if (fileselected - filescroll >= FILES_SHOWN)
                    ++filescroll;
                strcpy(filenameinput, filenames[fileselected]);
            }
        }
        else { //focus_filenameinput
            char c = readc();
            if (c == blockc && inputpause > 0)
                continue;
            if (c != '\0' && c != '\t' && c != '\n') {
                inputpause = INPUTPAUSE;
                blockc = c;
                if (c == '\b') {
                    if (filenameinput[0] != '\0')
                        filenameinput[strlen(filenameinput) - 1] = '\0';
                }
                else {
                    filenameinput[strlen(filenameinput)] = c;
                    filenameinput[strlen(filenameinput) + 1] = '\0';
                }
            }
            if (isKeyPressed(KEY_NSPIRE_UP) || isKeyPressed(KEY_NSPIRE_TAB)) {
                inputpause = INPUTPAUSE;
                focus_filenameinput = 0;
            }
            if (isKeyPressed(KEY_NSPIRE_ENTER)) {
                strcpy(file, currentdir);
                strcat(file, filenameinput);
                free_filenames(filenames);
                printf("%s\n", file);
                return 0;
            }
        }
        sleep(10);
    }

    free_filenames(filenames);
    return 1;
}