int main(int argc,const char* argv[]) {
  PgOptions* opts;

  // this needs to be called to init the File5 library.
  // (In turn it calls the HDF5 init function.)
  affx::File5_open();

  // throw our errors for testing.
  Err::setThrowStatus(true);

  // Create our option parser, define the options and parse.
  opts = new PgOptions;
  define_options(opts);
  opts->parseArgv(argv);

  // Print our help message if necessary.
  if (opts->getBool("help")) {
    opts->usage();
  }
  // figure out what the user wanted...
  else if (opts->get("create-file")!="") {
    example_create_file(opts->get("create-file"));
  }
  else if (opts->get("open-file")!="") {
    example_open_file(opts->get("open-file"));
  }
  else if (opts->get("write-tsv")!="") {
    example_write_tsv(opts->get("write-tsv"),opts->getInt("num-rows"));
  }
  else if (opts->get("read-tsv")!="") {
    example_read_tsv(opts->get("read-tsv"),opts->getInt("num-rows"));
  }
  else if (opts->get("read-tsv-vec")!="") {
    example_read_tsv_vec(opts->get("read-tsv-vec"));
  }
  else {
    opts->usage();
  }

  // delete the opts so valgrind doenst report them.
  delete opts;

  // for debugging with valgrind calling _exit will exit the program without
  // letting HDF5 clean up its memory.  This can help id memory leaks.
  // _exit(0);

  // Programs which use HDF5 should call this before exiting.
  // this cleans up resources it has allocated.
  affx::File5_close();

  return 0;
}
示例#2
0
文件: main.cpp 项目: rkrug/grass-ci
int main(int argc, char *argv[])
{
    struct Options opts;
    struct ScaleRange iscale;	/* input file's data is scaled to this interval */
    struct ScaleRange oscale;	/* output file's scale */
    int iimg_fd;		/* input image's file descriptor */
    int oimg_fd;		/* output image's file descriptor */
    int ialt_fd = -1;		/* input elevation map's file descriptor */
    int ivis_fd = -1;		/* input visibility map's file descriptor */
    struct History hist;
    struct Cell_head orig_window;

    /* Define module */
    define_module();

    /* Define the different input options */
    opts = define_options();

    /**** Start ****/
    G_gisinit(argv[0]);
    if (G_parser(argc, argv) < 0)
	exit(EXIT_FAILURE);

    G_get_set_window(&orig_window);
    adjust_region(opts.iimg->answer);

    /* open input raster */
    if ((iimg_fd = Rast_open_old(opts.iimg->answer, "")) < 0)
	G_fatal_error(_("Unable to open raster map <%s>"), opts.iimg->answer);

    if (opts.ialt->answer) {
	if ((ialt_fd = Rast_open_old(opts.ialt->answer, "")) < 0)
	    G_fatal_error(_("Unable to open raster map <%s>"),
			  opts.ialt->answer);
    }

    if (opts.ivis->answer) {
	if ((ivis_fd = Rast_open_old(opts.ivis->answer, "")) < 0)
	    G_fatal_error(_("Unable to open raster map <%s>"),
			  opts.ivis->answer);
    }

    /* open a floating point raster or not? */
    if (opts.oint->answer) {
	if ((oimg_fd = Rast_open_new(opts.oimg->answer, CELL_TYPE)) < 0)
	    G_fatal_error(_("Unable to create raster map <%s>"),
			  opts.oimg->answer);
    }
    else {
	if ((oimg_fd = Rast_open_fp_new(opts.oimg->answer)) < 0)
	    G_fatal_error(_("Unable to create raster map <%s>"),
			  opts.oimg->answer);
    }

    /* read the scale parameters */
    read_scale(opts.iscl, iscale);
    read_scale(opts.oscl, oscale);

    /* initialize this 6s computation and parse the input conditions file */
    init_6S(opts.icnd->answer);

    InputMask imask = RADIANCE;	/* the input mask tells us what transformations if any
				   needs to be done to make our input values, reflectance
				   values scaled between 0 and 1 */
    if (opts.irad->answer)
	imask = REFLECTANCE;
    if (opts.etmbefore->answer)
	imask = (InputMask) (imask | ETM_BEFORE);
    if (opts.etmafter->answer)
	imask = (InputMask) (imask | ETM_AFTER);

    /* process the input raster and produce our atmospheric corrected output raster. */
    G_message(_("Atmospheric correction..."));
    process_raster(iimg_fd, imask, iscale, ialt_fd, ivis_fd,
		   oimg_fd, opts.oint->answer, oscale);


    /* Close the input and output file descriptors */
    Rast_short_history(opts.oimg->answer, "raster", &hist);
    Rast_close(iimg_fd);
    if (opts.ialt->answer)
	Rast_close(ialt_fd);
    if (opts.ivis->answer)
	Rast_close(ivis_fd);
    Rast_close(oimg_fd);

    Rast_command_history(&hist);
    Rast_write_history(opts.oimg->answer, &hist);

    /* Copy the colors of the input raster to the output raster.
       Scaling is ignored and color ranges might not be correct. */
    copy_colors(opts.iimg->answer, opts.oimg->answer);

    Rast_set_window(&orig_window);
    G_message(_("Atmospheric correction complete."));

    exit(EXIT_SUCCESS);
}