Exemplo n.º 1
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nfiles, npoly, npolys,i;
    polygon **poly;
    poly=poly_global;

    /* parse arguments */
    parse_args(argc, argv);

    /* at least two input and one output filename required as arguments */
    if (argc - optind < 3) {
	if (optind > 1 || argc - optind >= 1) {
	    fprintf(stderr, "%s requires at least 3 arguments: polygon_infile, azel_infile, and outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- polyid ----------------\n");

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 2 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
        npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &poly[npoly], 1);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
	msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
      msg("STOP\n");
      exit(0);
    }
    
    if (snapped==0) {
      msg("WARNING: 'snapped' keyword not found in all input files.\n");
      msg("Polygons should be snapped before performing other mangle operations.\n");
    }
    
    /* polygon id numbers */
    npolys = poly_ids(argv[argc - 2], argv[argc - 1], &fmt, npoly, poly);
    if (npolys == -1) exit(1);

  for(i=0;i<npoly;i++){
    free_poly(poly[i]);
  }
    return(0);
}
Exemplo n.º 2
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nfiles, npoly,i;
    long np;
    polygon **poly;
    poly=poly_global;

    /* parse arguments */
    parse_args(argc, argv);

    /* three input and one output filename required as arguments */
    nfiles = argc - optind;
    if (nfiles != 4) {
	if (optind > 1 || nfiles >= 1) {
	    fprintf(stderr, "%s requires 4 arguments: polygon_infile, azel_infile, th_infile, and dd_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- ddcount ----------------\n");

    /* advise data format */
    advise_fmt(&fmt);


    /* read polygons */
    ifile = optind;
    npoly = rdmask(argv[optind], &fmt, NPOLYSMAX, poly);
    if (npoly == -1) exit(1);
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }

    /* pair counts */
    np = ddcount(argv[optind + 1], argv[optind + 2], argv[optind + 3], &fmt, npoly, poly);
    if (np == -1) exit(1);
    
    for(i=0;i<npoly;i++){
      free_poly(poly[i]);
    }

    return(0);
}
Exemplo n.º 3
0
void  clear_whole_screen()
{
	if(which_high_res == RES_1024_768)
	{
		viewport(0,1023,0,767);
	}
	else
		viewport(0,1279,0,1023);


	wrmask(0xff);
	flood((short)((global_screen_color << 4) | global_screen_color));
	wrmask(io_masks[which_page]);
	rdmask(io_masks[which_page]);

	restore_graphics_viewport();
}
Exemplo n.º 4
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, ipoly, nfiles, npoly, npolys, i;
    polygon **polys;
    polys=polys_global;

    /* default output format */
    fmt.out = keywords[POLYGON];

    /* parse arguments */
    parse_args(argc, argv);
    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind == 1) {
	    fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- poly2poly ----------------\n");

    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale (&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale (&mtol, munit, 'r');
	munit = 'r';
    }

    /* weight limits */
    if (is_weight_min && is_weight_max) {
	/* min <= max */
	if (weight_min <= weight_max) {
	    msg("will keep only polygons with weights inside [%Lg, %Lg]\n", weight_min, weight_max);
	/* min > max */
	} else {
	    msg("will keep only polygons with weights >= %Lg or <= %Lg\n", weight_min, weight_max);
	    msg("         (only polygons with weights outside (%Lg, %Lg))\n", weight_max, weight_min);
	}
    } else if (is_weight_min) {
	msg("will keep only polygons with weights >= %Lg\n", weight_min);
    } else if (is_weight_max) {
	msg("will keep only polygons with weights <= %Lg\n", weight_max);
    }
    /* area limits */
    if (is_area_min && is_area_max) {
	/* min <= max */
	if (area_min < area_max) {
	    msg("will keep only polygons with areas inside [%Lg, %Lg]\n", area_min, area_max);
	/* min > max */
	} else {
	    msg("will keep only polygons with areas >= %Lg or <= %Lg\n", area_min, area_max);
	    msg("         (only polygons with areas outside (%Lg, %Lg))\n", area_max, area_min);
	}
    } else if (is_area_min) {
	msg("will keep only polygons with areas >= %Lg\n", area_min);
    } else if (is_area_max) {
	msg("will keep only polygons with areas <= %Lg\n", area_max);
    }
    /* id limits */
    if (is_id_min && is_id_max) {
	/* min <= max */
	if (id_min < id_max) {
	    msg("will keep only polygons with ids inside [%lld, %lld]\n", id_min, id_max);
	/* min > max */
	} else {
	    msg("will keep only polygons with ids >= %lld or <= %lld\n", id_min, id_max);
	    msg("         (only polygons with ids outside (%lld, %lld))\n", id_max, id_min);
	}
    } else if (is_id_min) {
	msg("will keep only polygons with areas >= %lld\n", id_min);
    } else if (is_id_max) {
	msg("will keep only polygons with areas <= %lld\n", id_max);
    }
    /* pixel limits */
    if (is_pixel_min && is_pixel_max) {
	/* min <= max */
	if (pixel_min < pixel_max) {
	    msg("will keep only polygons with pixel numbers inside [%d, %d]\n", pixel_min, pixel_max);
	/* min > max */
	} else {
	    msg("will keep only polygons with pixel numbers >= %d or <= %d\n", pixel_min, pixel_max);
	    msg("         (only polygons with pixel numbers outside (%d, %d))\n", pixel_max, pixel_min);
	}
    } else if (is_pixel_min) {
	msg("will keep only polygons with pixel numbers >= %d\n", pixel_min);
    } else if (is_pixel_max) {
	msg("will keep only polygons with pixel numbers <= %d\n", pixel_max);
    }

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
	npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
	if (npolys == -1) exit(1);
	/* intersect polygons of infile1 with those of subsequent infiles */
	if (ifile > optind && intersect) {
	    npoly = intersect_poly(npoly, polys, npolys, &polys[npoly], mtol);
	    if (npoly == -1) exit(1);
	/* increment number of polygons */
	} else {
	    npoly += npolys;
	}
    }
    if (nfiles >= 2 && !intersect) {
        msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }

    /* apply new id numbers to output polygons */
    if (fmt.newid == 'n') {
	for (ipoly = 0; ipoly < npoly; ipoly++) {
	  polys[ipoly]->id = (long long)ipoly+fmt.idstart;
	}
    }

    if (fmt.newid == 'p') {
      for (ipoly = 0; ipoly < npoly; ipoly++) {
	polys[ipoly]->id = (long long)polys[ipoly]->pixel;
      }
    }

    /* write polygons */
    ifile = argc - 1;
    npoly = wrmask(argv[ifile], &fmt, npoly, polys);
    if (npoly == -1) exit(1);

    for(i=0;i<npoly;i++){
      free_poly(polys[i]);
    }

    return(0);
}
Exemplo n.º 5
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nfiles, npoly, npolys,i;
    polygon **polys;
    polys=polys_global;

    /* default output format */
    fmt.out = keywords[POLYGON];

    /* parse arguments */
    parse_args(argc, argv);

    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind == 1) {
	    fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    /* survey must have been specified */
    if (!survey) {
	fprintf(stderr, "%s requires -z<survey> option to specify the name of a survey,\n", argv[0]);
	fprintf(stderr, "%*s or the name of a file containing a list of weights.\n", (int)strlen(argv[0]), "");
	fprintf(stderr, "Please look in weight_fn.c for the names of known surveys.\n");
	exit(1);
    }

    msg("---------------- weight ----------------\n");

    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale(&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale(&mtol, munit, 'r');
	munit = 'r';
    }

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
	npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
        msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }

    /* weight polygons */
    npoly = weight(npoly, polys, survey);

    ifile = argc - 1;
    npoly = wrmask(argv[ifile], &fmt, npoly, polys);
    if (npoly == -1) exit(1);

    for(i=0;i<npoly;i++){
      free_poly(polys[i]);
    }

    return(0);
}
Exemplo n.º 6
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
  int ifile, nfiles, npoly, npolys, i, res_max_temp;
  char scheme_temp;
  polygon **polys;
  polys=polys_global;

  //   mtrace();

  /* default output format */
  fmt.out = keywords[POLYGON];
  /* default is to renumber output polygons with old id numbers */
  fmt.newid = 'o';

  /* parse arguments */
  parse_args(argc, argv);
  
  /* at least one input and output filename required as arguments */
  if (argc - optind < 2) {
    if (optind > 1 || argc - optind == 1) {
      fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
      usage();
      exit(1);
    } else {
      usage();
      exit(0);
    }
  }
  
  msg("---------------- pixelize ----------------\n");
  
  // snap angles 
  scale(&axtol, axunit, 's');
  scale(&btol, bunit, 's');
  scale(&thtol, thunit, 's');
  axunit = 's';
  bunit = 's';
  thunit = 's';
  //  msg("snap angles: axis %Lg%c latitude %Lg%c edge %Lg%c\n", axtol, axunit, btol, bunit, thtol, thunit);
  scale(&axtol, axunit, 'r');
  scale(&btol, bunit, 'r');
  scale(&thtol, thunit, 'r');
  axunit = 'r';
  bunit = 'r';
  thunit = 'r';
  
  /* tolerance angle for multiple intersections */
  if (mtol != 0.) {
    scale(&mtol, munit, 's');
    munit = 's';
    msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
    scale(&mtol, munit, 'r');
    munit = 'r';
  }
  
  msg("pixelization scheme %c, maximum resolution %d\n", scheme, res_max);
  msg("maximum number of polygons allowed in each pixel: %d\n", polys_per_pixel);
  scheme_temp=scheme;
  res_max_temp=res_max;
  

  /* advise data format */
  advise_fmt(&fmt);
  
  /* read polygons */
  npoly = 0;
  nfiles = argc - 1 - optind;
  for (ifile = optind; ifile < optind + nfiles; ifile++) {
    npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
    if (npolys == -1) exit(1);
    npoly += npolys;
  }
  if (nfiles >= 2) {
    msg("total of %d polygons read\n", npoly);
  }
  if (npoly == 0) {
    msg("STOP\n");
    exit(0);
  }

  if(scheme!=scheme_temp || res_max!=res_max_temp){
    msg("warning: pixelization information in input file is being discarded\n");
    scheme=scheme_temp;
    res_max=res_max_temp;
  }

  /* pixelize polygons */
  npolys = pixelize(npoly, polys, NPOLYSMAX - npoly, &polys[npoly]);
  if (npolys == -1) exit(1);

  pixelized=1;
  if(polys_per_pixel>0) res_max=-1;

  /* write polygons */
  ifile = argc - 1;
  npolys = wrmask(argv[ifile], &fmt, npolys, &polys[npoly]);
  if (npolys == -1) exit(1);
  /* memmsg(); */

  for(i=0;i<npoly+npolys;i++){
    free_poly(polys[i]);
  }

  return(0);
}
Exemplo n.º 7
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nadj, nfiles, npoly, npolys, i;
    polygon **polys;
    polys=polys_global;

    /* default output format */
    fmt.out = keywords[POLYGON];
    /* default is to renumber output polygons with old id numbers */
    fmt.newid = 'o';

    /* parse arguments */
    parse_args(argc, argv);

    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind == 1) {
	    fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- snap ----------------\n");

    /* snap angles */
    scale(&axtol, axunit, 's');
    scale(&btol, bunit, 's');
    scale(&thtol, thunit, 's');
    axunit = 's';
    bunit = 's';
    thunit = 's';
    msg("snap angles: axis %Lg%c latitude %Lg%c edge %Lg%c\n", axtol, axunit, btol, bunit, thtol, thunit);
    scale(&axtol, axunit, 'r');
    scale(&btol, bunit, 'r');
    scale(&thtol, thunit, 'r');
    axunit = 'r';
    bunit = 'r';
    thunit = 'r';

    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale(&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale(&mtol, munit, 'r');
	munit = 'r';
    }

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
	npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
	msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }

    /* adjust boundaries of polygons */
    nadj = snap(npoly, polys);
    if(nadj==-1) exit(1);

    snapped=1;
    
    /* write polygons */
    ifile = argc - 1;
    npoly = wrmask(argv[ifile], &fmt, npoly, polys);
    if (npoly == -1) exit(1);
 
    for(i=0;i<npoly;i++){
      free_poly(polys[i]);
    }

    return(0);
}
Exemplo n.º 8
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    char *th_in_filename;
    int nfiles, np, npoly,i;
    polygon **poly;
    poly=poly_global;

    /* set angular unit for output DR angles to default */
    fmt.outunit = OUTUNIT;

    /* parse arguments */
    parse_args(argc, argv);

    /* two or three input and one output filename required as arguments */
    nfiles = argc - optind;
    if (!(nfiles == 3 || nfiles == 4)) {
	if (optind > 1 || nfiles >= 1) {
	    fprintf(stderr, "%s requires 3 arguments: polygon_infile, azel+th_infile, and dr_outfile\n", argv[0]);
	    fprintf(stderr, "%*s       or 4 arguments: polygon_infile, azel_infile, th_infile, and dr_outfile\n", (int)strlen(argv[0]), " ");
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    /* summary option only possible with 3 input and 1 output files */
    if (summary && nfiles != 4) {
	fprintf(stderr, "%s with summary option -h requires 3 input files and 1 output file:\n", argv[0]);
	fprintf(stderr, "%*s polygon_infile azel_infile th_infile dr_outfile\n", (int)strlen(argv[0]), " ");
	usage();
	exit(1);
    }

    msg("---------------- drangle ----------------\n");

    /* advise data format */
    advise_fmt(&fmt);


    /* read polygons */
    npoly = rdmask(argv[optind], &fmt, NPOLYSMAX, poly, 1);
    if (npoly == -1) exit(1);
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }
    if (snapped==0 || balkanized==0) {
      fprintf(stderr, "Error: input polygons must be snapped and balkanized before using drangle.\n");
      fprintf(stderr, "If your polygons are already snapped and balkanized, add the 'snapped' and\n'balkanized' keywords at the beginning of each of your input polygon files.\n");
      exit(1);
    }

    /* name of file containing angular radii th, if present */
    th_in_filename = (nfiles == 3)? 0x0 : argv[optind + 2];

    /* angles */
    np = drangle(argv[optind + 1], th_in_filename, argv[argc - 1], &fmt, npoly, poly);
    if (np == -1) exit(1);

    for(i=0;i<npoly;i++){
      free_poly(poly[i]);
    }

    return(0);
}
Exemplo n.º 9
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nfiles, np, npoly, npolys,i;
    polygon **poly;
    poly=poly_global;

    /* parse arguments */
    parse_args(argc, argv);

    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind >= 1) {
            fprintf(stderr, "%s requires at least 2 arguments: polygon_infile, and outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- ransack ----------------\n");

    /* advise data format */
    advise_fmt(&fmt);

    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale(&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale(&mtol, munit, 'r');
	munit = 'r';
    }

    /* warn about seed not being set */
    if (seed_read == 0) {
	msg("warning: seed was not set on command line: using default seed %d\n", seed);
    }

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
	npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &poly[npoly]);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
	msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }
 
   if (snapped==0 || balkanized==0) {
     msg("WARNING: 'snapped' and 'balkanized' keywords not found in all input files.\n");
     msg("Running ransack on polygons that are not snapped and balkanized may give misleading results.\n");
   }

    /* random points in polygons */
    ifile = argc - 1;
    np = ransack(argv[ifile], &fmt, npoly, NPOLYSMAX, poly);
    if (np == -1) exit(1);
 
    for(i=0;i<npoly;i++){
      free_poly(poly[i]);
    }

    return(0);
}
Exemplo n.º 10
0
/*--------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
  int ifile, nfiles, npoly, npolys, nhealpix_poly, nhealpix_polys, j, k, nweights, nweight;
  long double *weights;
  
  polygon **polys;
  polys=polys_global;

  /* default output format */
  //fmt.out = keywords[HEALPIX_WEIGHT];
  fmt.out = keywords[POLYGON];

  /* parse arguments */
  parse_args(argc, argv);

  /* at least two input and one output filenames required as arguments */
  if (argc - optind < 3) {
      if (optind > 1 || argc - optind == 1 || argc - optind == 2) {
         fprintf(stderr, "%s requires at least 3 arguments: polygon_infile1, polygon_infile2, and polygon_outfile\n", argv[0]);
         usage();
         exit(1);
     } else {
         usage();
         exit(0);
     }
  }

  msg("---------------- rasterize ----------------\n");

  /* snap angles */
  scale(&axtol, axunit, 's');
  scale(&btol, bunit, 's');
  scale(&thtol, thunit, 's');
  axunit = 's';
  bunit = 's';
  thunit = 's';
  msg("snap angles: axis %Lg%c latitude %Lg%c edge %Lg%c\n", axtol, axunit, btol, bunit, thtol, thunit);
  scale(&axtol, axunit, 'r');
  scale(&btol, bunit, 'r');
  scale(&thtol, thunit, 'r');
  axunit = 'r';
  bunit = 'r';
  thunit = 'r';
  
  /* tolerance angle for multiple intersections */
  if (mtol != 0.) {
     scale(&mtol, munit, 's');
     munit = 's';
     msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
     scale(&mtol, munit, 'r');
     munit = 'r';
  }

  /* advise data format */
  advise_fmt(&fmt);

  /* read polygons from polygon_infile1 (healpix pixels, or some other 'rasterizer' pixels) */
  /* the id numbers of these polygons should match the pixel numbers of this pixelization scheme;
     for example, if you are using HEALPix, the id numbers should match the HEALPix pixel numbers
     in the NESTED scheme */
  nhealpix_poly = 0;
  ifile = optind;
  nhealpix_polys = rdmask(argv[ifile], &fmt, NPOLYSMAX - nhealpix_poly, &polys[nhealpix_poly]);
  if (nhealpix_polys == -1) exit(1);
  nhealpix_poly += nhealpix_polys;

  if (nhealpix_poly == 0) {
     msg("STOP\n");
     exit(0);
  }

  /* Input rasterizer polygons need not be balkanized if they are non-overlapping by construction,
     which is the case for the HEALPix polygons.  This is a special case - all other mangle functions
     that require balkanization require all input files to be balkanized.  To avoid getting an error
     here, increment the 'balkanized' counter here if the rasterizer polygons are not balkanized. */
  if (balkanized == 0) {
    balkanized++;
  }

  /* set nweights equal to maximum id number in rasterizer file */
  nweights = 0;
  for (k = 0; k < nhealpix_poly; k++) {
    if (polys[k]->id > nweights) nweights = polys[k]->id;
  }

  /* read polygons from polygon_infile2, polygon_infile3, etc. */
  npoly = nhealpix_poly;
  nfiles = argc - 2 - optind;
  for (ifile = optind + 1; ifile < optind + 1 + nfiles; ifile++) {
      npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
      if (npolys == -1) exit(1);
      npoly += npolys;
  }
  if (nfiles >= 2) {
    msg("total of %d polygons read from mask files\n", npoly-nhealpix_poly);
  }
  if (npoly-nhealpix_poly == 0) {
    msg("STOP\n");
    exit(0);
  }

    if (snapped==0 || balkanized==0) {
      fprintf(stderr, "Error: input polygons must be snapped and balkanized before rasterization.\n");
      fprintf(stderr, "If your polygons are already snapped and balkanized, add the 'snapped' and\n'balkanized' keywords at the beginning of each of your input polygon files.\n");
      exit(1);
    }


  /* allocate memory for weights array */
  weights = (long double *) malloc(sizeof(long double) * (nweights));
  if (!weights) {
     fprintf(stderr, "rasterize: failed to allocate memory for %d long doubles\n", nweights);
     exit(1);
  }

  /* initialize weights array to 0 */
  for (k = 0; k < nweights; k++) weights[k] = 0.;

  /* rasterize */
  nweight = rasterize(nhealpix_poly, npoly, polys, nweights, weights);
  if (nweight == -1) exit(1);

  /* copy new weights to original rasterizer polygons */
  for (k = 0; k < nhealpix_poly; k++) {
    for (j = 0; j < nweights; j++) {
      if (polys[k]->id == j+1) {
	polys[k]->weight = weights[j];
	break;
      }
    }
  }


  ifile = argc - 1;
  if (strcmp(fmt.out, "healpix_weight") == 0) {
    nweight = wr_healpix_weight(argv[ifile], &fmt, nweights, weights);
    if (nweight == -1) exit(1);
  }
  else {
    nweight = wrmask(argv[ifile], &fmt, nhealpix_poly, polys);
    if (nweight == -1) exit(1);
  }

  /* free array */
  for(k = 0; k < npoly; k++){
    free_poly(polys[k]);
  }

  return(0);

}
Exemplo n.º 11
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nfiles, npoly, npolys,i;
    char key;
    polygon **polys;
    polys=polys_global;

    /* default output format */
    fmt.out = keywords[POLYGON];
    /* default is to renumber output polygons with new id numbers */
    fmt.newid = 'n';

    /* parse arguments */
    parse_args(argc, argv);

    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind == 1) {
	    fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- balkanize ----------------\n");
    
    // snap angles 
    scale(&axtol, axunit, 's');
    scale(&btol, bunit, 's');
    scale(&thtol, thunit, 's');
    axunit = 's';
    bunit = 's';
    thunit = 's';
    // msg("snap angles: axis %Lg%c latitude %Lg%c edge %Lg%c\n", axtol, axunit, btol, bunit, thtol, thunit);
    scale(&axtol, axunit, 'r');
    scale(&btol, bunit, 'r');
    scale(&thtol, thunit, 'r');
    axunit = 'r';
    bunit = 'r';
    thunit = 'r';
    
    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale(&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale(&mtol, munit, 'r');
	munit = 'r';
    }

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
	npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
	msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }

    if (snapped==0) {
      fprintf(stderr, "Error: input polygons must be snapped before balkanization.\n");
      fprintf(stderr, "If your polygons are already snapped, add the 'snapped' keyword\nat the beginning of each of your input polygon files.\n");
      exit(1);
    }

    /* balkanize polygons */
    npolys = balkanize(npoly, polys, NPOLYSMAX - npoly, &polys[npoly]);
    if (npolys == -1) exit(1);
 
    balkanized=1;

    /* write polygons */
    ifile = argc - 1;
    npolys = wrmask(argv[ifile], &fmt, npolys, &polys[npoly]);
    if (npolys == -1) exit(1);
    /* memmsg(); */
 
    for(i=0;i<npoly+npolys;i++){
      free_poly(polys[i]);
    }

    return(0);
}
Exemplo n.º 12
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nadj, nfiles, npoly, npolys, res_max_temp,i;
    char scheme_temp;
    polygon **polys;
    polys=polys_global;

    /* default output format */
    fmt.out = keywords[POLYGON];
    /* default is to renumber output polygons with pixel numbers as id numbers */
    fmt.newid = 'p';

    /* parse arguments */
    parse_args(argc, argv);

    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind == 1) {
	    fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- pixelmap ----------------\n");

    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale(&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale(&mtol, munit, 'r');
	munit = 'r';
    }

    /* save res_max as defined on command line rather than using value from file*/
    /* value of scheme in file will override scheme defined on command line */
    res_max_temp=res_max;
    scheme_temp=scheme;

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
	npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly]);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
        msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }
    
    res_max=res_max_temp;
    msg("pixelization scheme %c, making map at resolution %d\n", scheme, res_max);
    
    if (snapped==0 || balkanized==0) {
      fprintf(stderr, "Error: input polygons must be snapped and balkanized before using pixelmap.\n");
      fprintf(stderr, "If your polygons are already snapped and balkanized, add the 'snapped' and\n'balkanized' keywords at the beginning of each of your input polygon files.\n");
      exit(1);
    }

    /* pixelmap polygons */
    nadj = pixelmap(&npoly, polys);
    if (nadj == -1) exit(1);

    ifile = argc - 1;
    npoly = wrmask(argv[ifile], &fmt, npoly, polys);
    if (npoly == -1) exit(1);
 
    for(i=0;i<npoly;i++){
      free_poly(polys[i]);
    }

    return(0);
}
Exemplo n.º 13
0
/*------------------------------------------------------------------------------
  Main program.
*/
int main(int argc, char *argv[])
{
    int ifile, nfiles, npoly, npolys,i;
    polygon **polys;
    polys=polys_global;

    /* default output format */
    fmt.out = keywords[POLYGON];
    /* default is to renumber output polygons with old id numbers */
    fmt.newid = 'o';

    /* parse arguments */
    parse_args(argc, argv);

    /* tolerance angle for multiple intersections */
    if (mtol != 0.) {
	scale(&mtol, munit, 's');
	munit = 's';
	msg("multiple intersections closer than %Lg%c will be treated as coincident\n", mtol, munit);
	scale(&mtol, munit, 'r');
	munit = 'r';
    }

    /* at least one input and output filename required as arguments */
    if (argc - optind < 2) {
	if (optind > 1 || argc - optind == 1) {
	    fprintf(stderr, "%s requires at least 2 arguments: polygon_infile and polygon_outfile\n", argv[0]);
	    usage();
	    exit(1);
	} else {
	    usage();
	    exit(0);
	}
    }

    msg("---------------- grow ----------------\n");

    /*process grow angle */
    scale(&grow_angle, gunit, 's');
    gunit = 's';
    msg("Borders of %Lg%c will be grown around the input polygons.\n", grow_angle, gunit);
    scale(&grow_angle, gunit, 'r');
    gunit = 'r';
    
    /* check if input polygons are pixelized - for this routine we need them to *NOT* be pixelized */
    if (pixelized==1) {
      fprintf(stderr, "Error: input polygons are pixelized. The grow function can only be applied to non-pixelized polygons.");
      exit(1);
    }

    /* advise data format */
    advise_fmt(&fmt);

    /* read polygons */
    npoly = 0;
    nfiles = argc - 1 - optind;
    for (ifile = optind; ifile < optind + nfiles; ifile++) {
        npolys = rdmask(argv[ifile], &fmt, NPOLYSMAX - npoly, &polys[npoly], 1);
	if (npolys == -1) exit(1);
	npoly += npolys;
    }
    if (nfiles >= 2) {
        msg("total of %d polygons read\n", npoly);
    }
    if (npoly == 0) {
	msg("STOP\n");
	exit(0);
    }

    /* grow polygons */
    npolys=grow(npoly, polys, NPOLYSMAX-npoly, &polys[npoly], grow_angle);
    if (npolys == -1) exit(1);

    ifile = argc - 1;
    npolys = wrmask(argv[ifile], &fmt, npolys, polys);
    if (npolys == -1) exit(1);
 
    for(i=0;i<npolys;i++){
      free_poly(polys[i]);
    }

    return(0);
}