Example #1
0
File: mi.c Project: cran/rsgcc
coord_t mutual_information(mi_t* const m, const coord_t* const xs, const coord_t* const ys) {
  const coord_t* pxs;
  const coord_t* pys;
  make_grid(&m->grid, xs, ys, m->n, m->k);
  ordered_points(&m->grid, &pxs, &pys);

  sort_coords(pxs, m->sxs, m->xiis, m->n);
  sort_coords(pys, m->sys, m->yiis, m->n);

  int i;
  coord_t accum = 0;
  for (i = 0; i < m->n; i++) {
    int kis[m->k];
    search_knn(&m->grid, pxs[i], pys[i], kis);

    const dist_t mdx = find_range(pxs, i, kis, m->k);
    const int nx = region_count(m->sxs, m->n, m->xiis[i], mdx);

    const dist_t mdy = find_range(pys, i, kis, m->k);
    const int ny = region_count(m->sys, m->n, m->yiis[i], mdy);

    accum += get_psi(m, nx) + get_psi(m, ny);
  }

  destroy_grid(&m->grid);

  return get_psi(m, m->k) + get_psi(m, m->n) - (1.0/m->k) - (accum/m->n);
}
Example #2
0
grid_t *grid_clone(grid_t *grid) {
	if (grid == NULL)
		return NULL;
	grid_t *out = make_grid(grid->width, grid->height, grid->padding);
	grid_copy(grid, out);
	return out;
}
Example #3
0
grid_t *grid_from_image(image_t *image, int chan) {
	grid_t *grid = NULL;
	if (image == NULL)
		goto err;
	if (chan > CHAN_ALPHA)
		goto err;

	int i, j;
	int width, height;

	width = image->width;
	height = image->height;

	grid = make_grid(width, height, 0);
	if (grid == NULL)
		goto err;

	int div = UCHAR_MAX * UCHAR_MAX;
	for (j = 0; j < height; j++) {
		png_byte *row = image->rows[j];
		for (i = 0; i < width; i++) {
			png_byte *pix = &(row[i * 4]);
			int index = j * width + i;
			grid->dbl[index] = ((float) (pix[chan] * pix[CHAN_ALPHA])) / div;
		}
	}

	done: return grid;
	err:
	FREE(grid);
	grid = NULL;
	goto done;
}
Example #4
0
/* read an image and generate a result */
int main(int argc, char **argv) {
    int rows=0;
    int cols=0;
    int iterations=0;
    int i;
    int **grid = NULL;
    int **neighbors = NULL;

    if (argc<2 || !(grid=read_grid(stdin,&rows,&cols))
            || (iterations=atoi(argv[1]))<0) {
        fprintf(stderr,"life usage:  life iterations <inputfile\n");
        exit(1);
    }
#ifdef DEBUG
    printf("input:\n");
    print_grid(stdout,grid,rows,cols);
#endif /* DEBUG */
    neighbors = make_grid(rows,cols);
    for (i=0; i<iterations; i++) {
        next(grid, neighbors, rows, cols);
#ifdef DEBUG
        printf("next\n");
        print_grid(stdout,grid,rows,cols);
#endif /* DEBUG */
    }
    print_grid(stdout,grid,rows,cols);
    free_grid(grid,rows);
    free_grid(neighbors,rows);
}
Example #5
0
File: mi.c Project: cran/rsgcc
//for pearson correlation
coord_t c_pcc(mi_t* const m, const coord_t* const xs, const coord_t* const ys) {
  
  int i;
  make_grid(&m->grid, xs, ys, m->n, m->k);

  coord_t meanx = 0.0;
  coord_t meany = 0.0;
  coord_t sum1 = 0.0;
  coord_t sum2 = 0.0;
  coord_t sum3 = 0.0;
 
  const int len = m->n;
  for( i = 0; i < len; i++ ) {
      meanx += xs[i];
      meany += ys[i];
   }
   meanx = 1.0*meanx/len;
   meany = 1.0*meany/len;

   for( i = 0; i < len; i++ ) {
       sum1 += (xs[i] - meanx)*(ys[i] - meany);
       sum2 += (xs[i] - meanx)*(xs[i] - meanx);
       sum3 += (ys[i] - meany)*(ys[i] - meany);
    }
    
  destroy_grid(&m->grid);

   if( sum2 == 0.0 || sum3 == 0.0 ) return(0.0);
   else                             return( 1.0*sum1/(sqrt(sum2)*sqrt(sum3)) );

}
Example #6
0
int main() {
  int i = 0;

  struct tms before, after;

  int start = (950 / sizeof(int))  * 1000;
  int end = (1050 / sizeof(int)) * 1000;
  int step = (end - start) / 50;

  FILE *fp;
  fp = fopen("datas", "w");
  for (i = start; i < end; i += step) {
	int a, b, k, j, runtime, overall;
	int** testgrid;
	int** neighbor;
	

	a = b = (int) sqrt(i);

	testgrid = make_grid(a, b);
	neighbor = make_grid(a, b);

	for(k = 0; k < 10; k++) {
	  randomize_grid(testgrid, &a, &b);
	  zero_grid(neighbor, a, b);
	  
	  times(&before);
	  for(j = 0; j < 30; j++) {
		next(testgrid, neighbor, a, b);
	  }
	  times(&after);
	  
	  runtime = (int)  (after.tms_utime + after.tms_stime) -
		(before.tms_utime + before.tms_stime);
	  overall += runtime; 
	}
	
	free_grid(testgrid, a);
	free_grid(neighbor, a);
	
	fprintf(fp, "%d \t %d \n", i, overall);
	fflush(fp);
  }

  return 0;
}
Example #7
0
KuhnMunkres::Indexes KuhnMunkres::calculate(const Grid &grid)
{
    grid_ = grid;
    const Dimensions dimensions = ensure_grid_is_square();
    size = static_cast<int>(grid_.size());
#ifdef USE_STL
    row_covered.resize(size, false);
    column_covered.resize(size, false);
#else
    row_covered.fill(false, size);
    column_covered.fill(false, size);
#endif
    z0_row = 0;
    z0_column = 0;
    path = make_grid(size * 2, static_cast<int>(ZERO));
    marked = make_grid(size, static_cast<int>(ZERO));

    int step = 1;
    while (step) {
        switch (step) {
            case 1: step = step1(); break;
            case 2: step = step2(); break;
            case 3: step = step3(); break;
            case 4: step = step4(); break;
            case 5: step = step5(); break;
            case 6: step = step6(); break;
            default: break;
        }
    }

    Indexes indexes;
    for (int row = 0; row < size; ++row) {
        for (int column = 0; column < size; ++column) {
            if ((row < dimensions.first) &&
                (column < dimensions.second) &&
                marked.at(row).at(column) == STAR)
#ifdef USE_STL
                indexes.push_back(std::make_pair(row, column));
#else
                indexes.push_back(qMakePair(row, column));
#endif
        }
    }
    return indexes;
}
Example #8
0
grid_t *grid_padding(grid_t *grid, int padding) {
	if (grid == NULL)
		return NULL;

	grid_t *new_grid = make_grid(grid->width, grid->height, padding);
	if (new_grid == NULL)
		return NULL;
	grid_copy(grid, new_grid);
	return new_grid;
}
Example #9
0
pos_t *build_pos_list(void)
{
  pos_list = (pos_t*)malloc(sizeof(pos_t) * num_nodes);
  
  if(!strcmp(shape_name, "random")) return make_random();
  if(!strcmp(shape_name, "wave")) return make_wave();
  if(!strcmp(shape_name, "grid")) return make_grid();
  printf("Unknown shape: %s!\n", shape_name);
  exit(3);
}
int main(void)
{
    make_grid(.5, 10, 10);
    percolate();
    show_grid();

    int cnt, i, p;

    puts("\nrunning 10x10 grids 10000 times for each p:");
    for (p = 1; p < 10; p++) {
        for (cnt = i = 0; i < 10000; i++) {
            make_grid(p / 10., 10, 10);
            cnt += percolate();
            //show_grid(); // don't
        }
        printf("p = %3g: %.4f\n", p / 10., (double)cnt / i);
    }

    free(start);
    return 0;
}
Example #11
0
int ImportMapDataFromFile(char *FileName) {
	int i, j, value;
	FILE *fp = 0;
	fopen_s(fp, FileName, "rt");
	fscanf_s(fp, "Width %u\n", &BINARY_MAP_WIDTH);
	fscanf_s(fp, "Height %u\n", &BINARY_MAP_HEIGHT);

	MapData = make_grid(MapData);
	BinaryCollisionArray = make_grid(BinaryCollisionArray);

	for(j = BINARY_MAP_HEIGHT - 1; j >= 0; --j)
		for(i = 0; i < BINARY_MAP_WIDTH; ++i) {
			fscanf_s(fp, "%i ", &value);
			MapData[i][j] = value;
			BinaryCollisionArray[i][j] = ((value == 1) ? 1 : 0);
		}

	fclose(fp);

	return 1;
}
Example #12
0
File: mi.c Project: cran/rsgcc
//for spearman correlation
coord_t c_scc(mi_t* const m, const coord_t* const xs, const coord_t* const ys, const int* const xsix, const int* const ysix ) {
   make_grid(&m->grid, xs, ys, m->n, m->k);
  
  const int len = m->n;
  int i, j;
  
  //sort y by the rank of x
  int xorder, yorder;
  coord_t vecx_x[len], vecix_x[len], vecy_x[len], vecixy_x[len];
  for(i = 0; i < len; i++ ) {
     xorder = xsix[i];
     vecx_x[xorder-1] = xs[i];
     vecix_x[xorder-1] = xorder;
     vecy_x[xorder-1] = ys[i];
     vecixy_x[xorder-1] = ysix[i];
  }
  //mask the rank of x
  maskrankforSCC( vecx_x, vecix_x, len );
/*
  for( i = 0; i < len; i++ ) {
     printf("%f, %f, %f, %f\n", vecx_x[i], vecix_x[i], vecy_x[i], vecixy_x[i] );
  }
  printf("\n\n");
*/
  //sort x by the rank of y
  coord_t vecy_y[len], vecixy_y[len], vecixx_y[len];
  for( i = 0; i < len; i++ ) {
     yorder = vecixy_x[i];
     vecy_y[yorder-1] = vecy_x[i];
     vecixy_y[yorder-1] = yorder;
     vecixx_y[yorder-1] = vecix_x[i];
  }
  //mask the rank of y
  maskrankforSCC( vecy_y, vecixy_y, len );
/*
   for( i = 0; i < len; i++ ) {
     printf("%f, %f, %f\n", vecy_y[i], vecixy_y[i], vecixx_y[i] );
  }
  printf("\n\n");
*/
  coord_t tmp = 0;
  for( i = 0; i < len; i++ ) {
     tmp += (vecixy_y[i] - vecixx_y[i])*(vecixy_y[i] - vecixx_y[i]);
  }
//  printf("%d, %f\n", len, 1.0 - 6.0*tmp/(len*len*len - len) );
 
  destroy_grid(&m->grid);

  return( 1.0 - 6.0*tmp/(len*len*len - len) );
}
Example #13
0
File: mi.c Project: cran/rsgcc
//for euclidean distance
coord_t c_eudist( mi_t* const m, const coord_t* const xs, const coord_t* const ys) {
  int i;
  make_grid(&m->grid, xs, ys, m->n, m->k);

  coord_t sum1 = 0.0;
  coord_t t_tmp = 0.0;
  const int len = m->n;
  for( i = 0; i < len; i++ ) {
      t_tmp = xs[i] - ys[i];
      sum1 += t_tmp*t_tmp;
   }
    
  destroy_grid(&m->grid);

   if( sum1 == 0.0 ) return(0.0);
   else              return( sqrt(sum1) );
}
Example #14
0
File: mi.c Project: cran/rsgcc
//for spearman correlation
coord_t c_kcc(mi_t* const m, const coord_t* const xs, const coord_t* const ys ) {
   make_grid(&m->grid, xs, ys, m->n, m->k);
  
  const int len = m->n;
  int i, j, num;
  num = 0;
  for( i = 1; i < len; i++ ) {
     for( j = 0; j < i; j++ ) {
         num += (xs[i] - xs[j])*(ys[i] - ys[j]) > 0 ? 1 : -1;
     }//end for j
  }//end for i

 
  destroy_grid(&m->grid);

  return( 2.0*num/(len*len - len) );
}
Example #15
0
File: mi.c Project: cran/rsgcc
//for gini correlation
coord_t c_gcc(mi_t* const m, const coord_t* const xs, const coord_t* const ys, const int* const xsix, const int* const ysix ) {
  
  make_grid(&m->grid, xs, ys, m->n, m->k);
  
  const int len = m->n;
  int xorder, yorder;
  coord_t vecx_x[len], vecx_y[len], vecy_y[len], vecy_x[len];
  for (int i = 0; i < len; i++ ) {
  	xorder = xsix[i];
  	vecx_x[xorder-1] = xs[i];
  	vecy_x[xorder-1] = ys[i];
  	
  	yorder = ysix[i];
  	vecy_y[yorder-1] = ys[i];
  	vecx_y[yorder-1] = xs[i];
  }
  	

  coord_t accumx_x = 0;
  coord_t accumx_y = 0;
  coord_t accumy_y = 0;
  coord_t accumy_x = 0;
  for (int i = 0; i < len; i++) {
     //for order x
     coord_t weight = 2.0*(i+1)- m->n -1.0;
     accumx_x += weight*vecx_x[i];
     accumx_y += weight*vecx_y[i];
     
     accumy_y += weight*vecy_y[i];
     accumy_x += weight*vecy_x[i];
  }//for i

  coord_t gccx_y = accumx_y/accumx_x;
  coord_t gccy_x = accumy_x/accumy_y;
  coord_t final_gcc = gccx_y*gccx_y > gccy_x*gccy_x ? gccx_y : gccy_x;

  destroy_grid(&m->grid);

  return final_gcc;

}
Example #16
0
void place_overlap_find_least_placement(const Rect* client_rects,
                                        int n_client_rects,
                                        const Rect *monitor,
                                        const Size* req_size,
                                        Point* result)
{
    POINT_SET(*result, monitor->x, monitor->y);
    int overlap = G_MAXINT;
    int max_edges = 2 * (n_client_rects + 1);

    int x_edges[max_edges];
    int y_edges[max_edges];
    make_grid(client_rects, n_client_rects, monitor,
            x_edges, y_edges, max_edges);
    int i;
    for (i = 0; i < max_edges; ++i) {
        if (x_edges[i] == G_MAXINT)
            break;
        int j;
        for (j = 0; j < max_edges; ++j) {
            if (y_edges[j] == G_MAXINT)
                break;
            Point grid_point = {.x = x_edges[i], .y = y_edges[j]};
            Point best_top_left;
            int this_overlap =
                best_direction(&grid_point, client_rects, n_client_rects,
                        monitor, req_size, &best_top_left);
            if (this_overlap < overlap) {
                overlap = this_overlap;
                *result = best_top_left;
            }
            if (overlap == 0)
                break;
        }
        if (overlap == 0)
            break;
    }
}
Example #17
0
File: main.c Project: gozac/ZAC-42
int		main(int argc, char **argv)
{
	int		fd;
	t_list	*grid;
	void	*mlx;
	void	*win;

	if (argc < 2)
	{
		ft_putstr("usage : ./fdf file1\n");
		return (-1);
	}
	if ((fd = open(argv[1], O_RDONLY)) == -1)
	{
		perror(argv[1]);
		return (-1);
	}
	mlx = mlx_init();
	win = mlx_new_window(mlx, 1920, 1020, "42");
	grid = make_grid(fd);
	rely_point(mlx, win, grid);
	mlx_loop(mlx);
	return (0);
}
Example #18
0
int	main(int argc, char **argv)
{
  float Rf;
  if (argc!=7) {
    std::cout<<"Usage: recon <data-file> <random-file> <random-file>"
             <<" <bias> <f-growth> <R-filter>"<<std::endl;
    myexit(1);
  }
  bias = atof(argv[4]);		// Sets global variable.
  beta = atof(argv[5])/bias;	// Sets global variable.
  Rf   = atof(argv[6]);
  LCDM lcdm(0.30);		// Change OmegaM here if necessary.

#ifdef	TESTMG
  // Make a cosine wave (only in x-direction) and solve for it with
  // beta=0.  Used to test the MG solver convergence on a simple problem.
  box.L=1.25;  box.ctr[0]=box.ctr[1]=box.ctr[2]=0.6;
  const float dt=2*M_PI/Ng;
  std::vector<float> src(Ng*Ng*Ng);
  for (int ix=0; ix<Ng; ++ix)
    for (int iy=0; iy<Ng; ++iy)
      for (int iz=0; iz<Ng; ++iz)
        src[Ng*Ng*ix+Ng*iy+iz] = cos(ix*dt);
  bias = 1; beta = 0;
  std::vector<float> ans = MultiGrid::fmg(src,Ng);
  for (int ix=0; ix<Ng; ++ix)
    std::cout<<std::fixed<<std::setprecision(6)
             <<ix<<" "<<cos(ix*dt)/(2*M_PI*2*M_PI)
             <<" "<<ans[Ng*Ng*ix+Ng*0   +Ng/4]
             <<" "<<ans[Ng*Ng*ix+Ng*Ng/2+0]
             <<" "<<ans[Ng*Ng*ix+Ng*0   +Ng/2]<<std::endl;
  return(0);
#endif

  // Read the data and figure out the 3D positions and enclosing box.
  std::vector<struct particle> D = read_data(argv[1],lcdm);
  std::vector<struct particle> R1= read_data(argv[2],lcdm);
  std::vector<struct particle> R2= read_data(argv[3],lcdm);
  std::cout<<"# Read "<<std::setw(10)<<D.size()
           <<" objects from "<<argv[1]<<std::endl;
  std::cout<<"# Read "<<std::setw(10)<<R1.size()
           <<" randoms from "<<argv[2]<<std::endl;
  std::cout<<"# Read "<<std::setw(10)<<R2.size()
           <<" randoms from "<<argv[3]<<std::endl;
  remap_pos(D,R1,R2);
  std::cout<<"# Enclosing survey in a box of side "<<box.L<<" Mpc/h."
           <<std::endl;
  std::cout<<"# Grid/mesh size is "<<box.L/Ng<<" Mpc/h"
           <<" and filter scale is "<<Rf<<" Mpc/h."
           <<std::endl;

#ifndef	SKIPRAW
  write_data(D ,"data_raw.xyzw");
  write_data(R2,"rand_raw.xyzw");
#endif
  
  // Make the density (contrast) grid and solve for the
  // displacement potential, phi.
  std::vector<float> delta = make_grid(D,R1,Rf);
  std::vector<float> phi   = MultiGrid::fmg(delta,Ng);

  // Shift the particles and randoms back -- if you want to not enhance
  // the line-of-sight shift for the randoms you need to change beta before
  // calling shift_obj.
  shift_obj(D ,phi);
  shift_obj(R2,phi);

  write_data(D ,"data_rec.xyzw");
  write_data(R2,"rand_rec.xyzw");

  return(0);
}
Example #19
0
/*
 * Read a text file, formatted like this:
 *
 *         4      <- 1st line: width as decimal integer
 *         3      <- 2nd line: height as decimal integer
 *         ....   <- rows (. = dead cell, # = living cell)
 *         .##.
 *         ....		
 *                <- final row ending with a linefeed '\n'
 *
 *	If successful, returns SUCCESS and stores the grid in
 *  the location given by result. Otherwise returns INVALID_GRID_FILE
 *  and does not change result.
 *
 */
int read_grid_file(char* filename, struct grid_t ** result) {
    int row, cell, width, height;
    FILE * file;
    int read_result;
	struct grid_t * grid;

    file = fopen(filename, "r");
	if (file == NULL) {
		printf("Error: Cannot open file\n");
		return INVALID_GRID_FILE;
	}
	

	// read first line as width
    read_result = fscanf(file, "%d ", &width);
	
	// check for errors during read 
	// (positive result = number of bytes read, negative = error code)
	if (read_result <= 0) {
		printf("Error: Cannot read width from file\n");
		
		// close file in case of error!
		fclose(file);
		return INVALID_GRID_FILE;
	}
	
	// read second line as height
	read_result = fscanf(file, "%d ", &height);
	if (read_result <= 0) {
		printf("Error: Cannot read height from file\n");
		fclose(file);
		return INVALID_GRID_FILE;
	}
	
	// allocate grid with the given dimensions
	
    make_grid(width, height, &grid);
	
	// read rows
    for (row = 0; row < height; ++row) {
		
		// for each row, read cells
        for (cell = 0; cell < width; ++cell) {
			
			// read character from file
            read_result = fgetc(file);
			
			// if there are not enough characters
			// write error message and release all resources used so far
			if (read_result == EOF) {
				free_grid(grid);
				fclose(file);
				printf("Error: Unexpected end of file\n");
				return INVALID_GRID_FILE;
			}
			
			// translate . and # to dead and living cells
			switch ((char)read_result) {
				case '.':
					grid->cells[row][cell] = CELL_DEAD;
					break;
				case '#':
					grid->cells[row][cell] = CELL_ALIVE;
					break;
					
				// other characters lead to an error
				// and we need to release/free file and memory again
				default:
					free_grid(grid);
					fclose(file);
					printf("Error: Unexpected character in grid cell: %c\n", (char)read_result);
					return INVALID_GRID_FILE;
			}
        }
		
        // read the newline character at the end of each row
		read_result = fgetc(file);
		
		// if that was'nt a newline, there is something wrong:
		if ((char)read_result != '\n') {
			free_grid(grid);
			fclose(file);
			printf("Error: Expected new line, but found character or end of file\n");
			return INVALID_GRID_FILE;
		}
    }
	
    fclose(file);
	*result = grid;	// write the grid pointer behind the given result pointer
	return SUCCESS;
}
Example #20
0
int
main (void)
{
  spline = NULL;
  acc = NULL;
  int i, status;
  double r, r1, y[2];
  // bounds for making grid of m(R) vs. rho(0)
  const double rho_min = 1.0e+13, rho_max = 9.0e+14;
  const int MAX = 100;
  // pressure/density arrays from tabulated EOS data
  int n_eos_pts;
  FILE *fp = NULL;
  double (*pres) (double, void *);	// EOS pressure pointer
  double (*rho) (double, void *);	// EOS density pointer
  double tmp;
  // pointers to tabulated EOS data
  double *eos_tab_pres = NULL, *eos_tab_dens = NULL;

  /* this is the "third arm" of the EOS inversion routine. GSL calls
     the function whose root is being found several times during
     initialization and if we leave the pressure here uninitialized,
     it might be 0 or something crazy, which will be out of bounds of
     the "forward" EOS, and since the forward EOS uses interpolation,
     an out-of-bounds value of pressure will make it crash. */
  tmp_pres = 1.0e+25;

  pres = &eos_pres;
  rho = &eos_rho;

  //  fp = fopen("bck.eos", "r");
  //  fp = fopen("eosC", "r");
  //  fp = fopen("timmes.eos", "r");
  fp = fopen ("../EOS/helmholtz.eos", "r");

  if (fp == NULL)
    {
      fprintf (stderr, "Can't open file!\n");
      exit (1);
    }

  // read in # of EOS data points
  fscanf (fp, "%i", &n_eos_pts);

  eos_tab_dens = (double *) malloc (n_eos_pts * sizeof (double));
  eos_tab_pres = (double *) malloc (n_eos_pts * sizeof (double));

  // read in density and pressure data
  for (i = 0; i < n_eos_pts; i++)
    {
      fscanf (fp, "%le %le", &eos_tab_dens[i], &eos_tab_pres[i]);
    }
  fclose (fp);

  // set up interpolation machinery for EOS
  acc = gsl_interp_accel_alloc ();
  spline = gsl_spline_alloc (gsl_interp_cspline, n_eos_pts);
  gsl_spline_init (spline, eos_tab_dens, eos_tab_pres, n_eos_pts);

  // now make grid
  r = 1.0;			// the integrator will go nuts if we start right at r=0
  r1 = 1.0e+10;			// some final 'radius' (much larger than actual radius)

  printf ("%12s %12s %12s\n", "R", "M(r=R)", "rho(r=0)");

  params.single_star = 1;
  for (i = 0; i < MAX; i++)
    {
      // rho(0) evenly spaced in log
      params.rho_init = log10 (rho_min) +
	(double) i *((log10 (rho_max) - log10 (rho_min)) / (double) MAX);
      params.rho_init = pow (10.0, params.rho_init);

      y[1] = pres (params.rho_init, &params);
      y[0] = (4.0 / 3.0) * M_PI * pow (r, 3.0) * rho (y[1], &params);

      params.pinit = y[1];
      // This function is useful if you want to plot, e.g., central
      // pressure vs. total mass. You can also hang onto the run of
      // pressure with radius, which can be interesting when compared to
      // the Newtonian case.
      status = make_grid (params, r, r1, y);
    }

/*
  params.single_star = 0;
  printf("\nnow for a single star!\n");
  printf("%12s %12s %12s %12s\n", "r", "M(r)", "P(r)", "rho(r)");
  // print P and M vs r for Chandrasekhar-mass star
  params.rho_init = 1.0e+13;

  y[1] = pres(params.rho_init, &params); // rho(0) (roughly) for maximum mass
  y[0] = (4.0/3.0) * M_PI * pow(r, 3.0) * rho(y[1], &params);

  params.pinit = y[1];
  status = make_grid(params, r, r1, y);
*/

  gsl_spline_free (spline);
  gsl_interp_accel_free (acc);

  free (eos_tab_pres);
  free (eos_tab_dens);

  eos_tab_dens = NULL;
  eos_tab_pres = NULL;
  fp = NULL;
  pres = NULL;
  rho = NULL;
  return 0;
}
Example #21
0
 void print(std::ostream& os, const range<RangeIter>& xrange, const Values&... values) {
     print(os, make_grid(xrange), values...);
 }
Example #22
0
int main()
{

    gnd::debug_allocator<gnd::stack_allocator> alloc{"def", 1024};
    Foo * f1 = GND_NEW(Foo,alloc);
    GND_DELETE(f1,alloc);



    window.create(1280, 720, "Plant");

    window.on_left_drag.connect([](double x, double y){
        handle_middle_drag(x, y);
        return false;
    });

    window.on_cursor_move.connect([](double x, double y){
        mouse_x = x;
        mouse_y = y;
        return false;
    });

    glClearColor(0.82,0.86,0.91,1.0);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


    VAO grid = make_grid(100);

    shader = gnd::load_shader("../data/basic3d.vs", "../data/basic3d.fs");
    glUseProgram(shader);

    cam_pos = point_on_sphere(cam_radius, cam_theta, cam_phi);

    glm::mat4 mmodel{1.0f};
    glm::mat4 mview{glm::lookAt(cam_pos, glm::vec3{0,0,0}, glm::vec3{0,1,0})};
    glm::mat4 mproj{glm::perspective(0.785398f, 1280.0f/720.0f, 0.1f, 100.0f)};

    glUniformMatrix4fv(glGetUniformLocation(shader, "u_projection"), 1, GL_FALSE, &mproj[0][0]);
    glUniformMatrix4fv(glGetUniformLocation(shader, "u_view"), 1, GL_FALSE, &mview[0][0]);
    glUniformMatrix4fv(glGetUniformLocation(shader, "u_model"), 1, GL_FALSE, &mmodel[0][0]);

    std::vector<IndexedVAO> model = load_model("../data/model.blend");

    double last_measure = glfwGetTime();
    double time_now = last_measure;
    size_t frames_rendered = 0;
    char title_buf[64];

    glfwSwapInterval(0);

    glProvokingVertex(GL_FIRST_VERTEX_CONVENTION);

    glfwGetCursorPos(window.handle(), &mouse_x, &mouse_y);

    while(!window.should_close())
    {
        time_now = glfwGetTime();

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glBindVertexArray(grid.handle);
        glDrawArrays(grid.mode, 0, grid.count);

        draw_indexed_vaos(&model.front(), &model.back()+1);


        window.swap_buffers();
        glfwPollEvents();

        ++frames_rendered;
        if(time_now - last_measure >= 1.0)
        {
            snprintf(title_buf, 64, "%.2lf FPS", (double)frames_rendered/(time_now-last_measure));
            window.set_title(title_buf);
            last_measure = time_now;
            frames_rendered = 0;
        }
    }
    return 0;
}
Example #23
0
vector<double> unfoldE(const vector<double> &x, int mesh){
	vector<double> energy_grid=make_grid(x,mesh);
	vector<double> integrated_DOS=make_DOS(x,energy_grid);
	return make_S(x,energy_grid,integrated_DOS);

}
Example #24
0
int main(int argc,char *argv[]) {



#ifdef _XLIB_
  int xdf=0;
  int xd=0;
  struct XwinDisplay *dp;
  struct XwinWindow *win;
  char *display_name=NULL;
  char *wname="fov_plot";
  int xdoff=-1;
  int ydoff=-1;
#endif

  struct FrameBuffer *img=NULL;
  struct PostScript *psdata=NULL;
  FILE *fontfp=NULL;
  char *fntdbfname=NULL;
  struct FrameBufferFontDB *fontdb=NULL;
  unsigned int bgcol;
  unsigned int txtcol;

  int arg;

  char *envstr=NULL;
  char *cfname=NULL;
  FILE *fp;



  float wdt=540,hgt=540;
  float pad=0;

  char *fontname=NULL;
  float fontsize=10.0;
  char *dfontname="Helvetica";

  float width=0.5;

  struct Plot *plot=NULL;
  struct Splot *splot=NULL;

  float xpoff=40,ypoff=40;
  unsigned char psflg=0;
  unsigned char xmlflg=0;
  unsigned char ppmflg=0;
  unsigned char ppmxflg=0;
  unsigned char pngflg=0;

  unsigned char gflg=0;
  unsigned char pflg=0;


  unsigned char help=0; 
  unsigned char option=0; 

  char *bgcol_txt=NULL;
  char *txtcol_txt=NULL;


  unsigned char sqflg=0;
  MapTFunction  tfunc;

  unsigned char flip=0;
  unsigned char gvp=0;
  unsigned char ortho=0;
  unsigned char stereo=0;
  unsigned char cylind=0;

  float lat=90,lon=0;
  float latmin=50.0;
  float sf=1.0;
  float alt=0.0; 

  unsigned char magflg=0;
  unsigned char rotflg=0;

  unsigned char mapflg=0;
  unsigned char fmapflg=0;
  unsigned char bndflg=0;
  unsigned char grdflg=0;
  unsigned char tmkflg=0;
  unsigned char tlblflg=0;
  unsigned char ofovflg=0;
  unsigned char fofovflg=0;

  unsigned char cfovflg=0;
  unsigned char fcfovflg=0;

  unsigned char fovflg=0;
  unsigned char ffovflg=0;

  unsigned char grdontop=0;

  unsigned char dotflg=0;

  int tmtick=3;

  unsigned char lstflg=0;
  unsigned char trmflg=0;
  unsigned char ftrmflg=0;

  char *grdcol_txt=NULL;
  char *cstcol_txt=NULL;
  char *bndcol_txt=NULL;
  char *lndcol_txt=NULL;
  char *seacol_txt=NULL;
  char *trmcol_txt=NULL;
  char *ftrmcol_txt=NULL;
  char *tmkcol_txt=NULL;
  char *ofovcol_txt=NULL;
  char *fofovcol_txt=NULL;
  char *fovcol_txt=NULL;
  char *ffovcol_txt=NULL;

  char *cfovcol_txt=NULL;
  char *fcfovcol_txt=NULL;


  unsigned int grdcol;
  unsigned int cstcol;
  unsigned int bndcol;
  unsigned int lndcol;
  unsigned int seacol;
  unsigned int trmcol;
  unsigned int ftrmcol;
  unsigned int tmkcol;
  unsigned int ofovcol;
  unsigned int fofovcol;
  unsigned int fovcol;
  unsigned int ffovcol;

  unsigned int cfovcol;
  unsigned int fcfovcol;
  

  FILE *mapfp;
  float marg[4];
  int i;

  char *tmetxt=NULL;
  char *dtetxt=NULL;

  double tval=-1;
  double dval=-1;

  int yr,mo,dy,hr,mt;
  double sc;
  int yrsec;
  float tme_shft;



  double LsoT,LT,Hangle,dec,eqt;
  
  float dotr=2; 
 
  int stid=-1;
  char *ststr=NULL;
  int stnum=0;

  char tsfx[16];


  envstr=getenv("MAPDATA");

  mapfp=fopen(envstr,"r");
  map=MapFread(mapfp);
  fclose(mapfp);   

  envstr=getenv("BNDDATA");
  mapfp=fopen(envstr,"r");
  bnd=MapBndFread(mapfp);
  fclose(mapfp);

 envstr=getenv("SD_RADAR");
  if (envstr==NULL) {
    fprintf(stderr,"Environment variable 'SD_RADAR' must be defined.\n");
    exit(-1);
  }

  fp=fopen(envstr,"r");

  if (fp==NULL) {
    fprintf(stderr,"Could not locate radar information file.\n");
    exit(-1);
  }

  network=RadarLoad(fp);
  fclose(fp); 
  if (network==NULL) {
    fprintf(stderr,"Failed to read radar information.\n");
    exit(-1);
  }

  envstr=getenv("SD_HDWPATH");
  if (envstr==NULL) {
    fprintf(stderr,"Environment variable 'SD_HDWPATH' must be defined.\n");
    exit(-1);
  }

  RadarLoadHardware(envstr,network);


  bgcol=PlotColor(0xff,0xff,0xff,0xff);
  txtcol=PlotColor(0x00,0x00,0x00,0xff);

  grdcol=PlotColor(0x20,0x40,0x60,0xff);
  cstcol=PlotColor(0xa0,0xa0,0xa0,0xff);
  bndcol=PlotColor(0x80,0x80,0x80,0xff);
  lndcol=PlotColor(0xff,0xff,0xf0,0xff);
  seacol=PlotColor(0xe0,0xf0,0xff,0xff);
  tmkcol=PlotColor(0x00,0x00,0x00,0xff);
  ofovcol=PlotColor(0x00,0x00,0x00,0xff);
  fofovcol=PlotColor(0xff,0xff,0xff,0xff);
  fovcol=PlotColor(0x00,0x00,0x00,0xff);
  ffovcol=PlotColor(0xc0,0x00,0x00,0xff);
  trmcol=PlotColor(0x80,0x80,0x80,0xff);
  ftrmcol=PlotColor(0x80,0x80,0x80,0xff);

  cfovcol=PlotColor(0x00,0x00,0x00,0xff);
  fcfovcol=PlotColor(0xff,0xff,0xff,0xff);
 
  OptionAdd(&opt,"-help",'x',&help);
  OptionAdd(&opt,"-option",'x',&option);

  OptionAdd(&opt,"cf",'t',&cfname);


#ifdef _XLIB_ 
  OptionAdd(&opt,"x",'x',&xd);
  OptionAdd(&opt,"display",'t',&display_name);
  OptionAdd(&opt,"xoff",'i',&xdoff);
  OptionAdd(&opt,"yoff",'i',&ydoff);
#endif

  OptionAdd(&opt,"ppm",'x',&ppmflg);
  OptionAdd(&opt,"ppmx",'x',&ppmxflg);
  OptionAdd(&opt,"xml",'x',&xmlflg);
  OptionAdd(&opt,"png",'x',&pngflg);
  OptionAdd(&opt,"ps",'x',&psflg); 

  OptionAdd(&opt,"xp",'f',&xpoff);
  OptionAdd(&opt,"yp",'f',&ypoff);
  OptionAdd(&opt,"wdt",'f',&wdt);
  OptionAdd(&opt,"hgt",'f',&hgt);
  OptionAdd(&opt,"pad",'f',&pad);

  OptionAdd(&opt,"bgcol",'t',&bgcol_txt);
  OptionAdd(&opt,"txtcol",'t',&txtcol_txt);

  OptionAdd(&opt,"square",'x',&sqflg);

  OptionAdd(&opt,"ortho",'x',&ortho);
  OptionAdd(&opt,"stereo",'x',&stereo);
  OptionAdd(&opt,"gvp",'x',&gvp);

  OptionAdd(&opt,"lat",'f',&lat);
  OptionAdd(&opt,"lon",'f',&lon);
  OptionAdd(&opt,"latmin",'f',&latmin);
  OptionAdd(&opt,"sf",'f',&sf);
  OptionAdd(&opt,"mag",'x',&magflg);
  OptionAdd(&opt,"rotate",'x',&rotflg);
  OptionAdd(&opt,"alt",'f',&alt);
  OptionAdd(&opt,"flip",'x',&flip);

  OptionAdd(&opt,"coast",'x',&mapflg);
  OptionAdd(&opt,"fcoast",'x',&fmapflg);
  OptionAdd(&opt,"bnd",'x',&bndflg);
  OptionAdd(&opt,"grd",'x',&grdflg);
  OptionAdd(&opt,"tmk",'x',&tmkflg);

 OptionAdd(&opt,"grdontop",'x',&grdontop);


  OptionAdd(&opt,"fov",'x',&fovflg);
  OptionAdd(&opt,"ffov",'x',&ffovflg);

  OptionAdd(&opt,"ofov",'x',&ofovflg);
  OptionAdd(&opt,"fofov",'x',&fofovflg);

  OptionAdd(&opt,"cfov",'x',&cfovflg);
  OptionAdd(&opt,"fcfov",'x',&fcfovflg);

  OptionAdd(&opt,"tmtick",'i',&tmtick);
  OptionAdd(&opt,"lst",'x',&lstflg);
  OptionAdd(&opt,"term",'x',&trmflg);
  OptionAdd(&opt,"fterm",'x',&ftrmflg);

  OptionAdd(&opt,"grdcol",'t',&grdcol_txt);
  OptionAdd(&opt,"cstcol",'t',&cstcol_txt);
  OptionAdd(&opt,"bndcol",'t',&bndcol_txt);
  OptionAdd(&opt,"lndcol",'t',&lndcol_txt);
  OptionAdd(&opt,"seacol",'t',&seacol_txt);
  OptionAdd(&opt,"trmcol",'t',&trmcol_txt);
  OptionAdd(&opt,"tmkcol",'t',&tmkcol_txt);
 
  OptionAdd(&opt,"fovcol",'t',&fovcol_txt);
  OptionAdd(&opt,"ffovcol",'t',&ffovcol_txt);
  OptionAdd(&opt,"ofovcol",'t',&ofovcol_txt);
  OptionAdd(&opt,"fofovcol",'t',&fofovcol_txt);

  OptionAdd(&opt,"cfovcol",'t',&cfovcol_txt);
  OptionAdd(&opt,"fcfovcol",'t',&fcfovcol_txt);

  OptionAdd(&opt,"st",'t',&ststr);

  OptionAdd(&opt,"t",'t',&tmetxt);
  OptionAdd(&opt,"d",'t',&dtetxt);
  
  OptionAdd(&opt,"tmlbl",'x',&tlblflg);

  OptionAdd(&opt,"fontname",'t',&fontname);
  OptionAdd(&opt,"fontsize",'f',&fontsize);
  OptionAdd(&opt,"lnewdt",'f',&width);

  OptionAdd(&opt,"dotr",'f',&dotr);
  OptionAdd(&opt,"dot",'x',&dotflg);


  arg=OptionProcess(1,argc,argv,&opt,NULL);  

  if (cfname !=NULL) { /* load the configuration file */
    int farg;
    do {
      fp=fopen(cfname,"r");
      if (fp==NULL) break;
      free(cfname);
      cfname=NULL;
      optf=OptionProcessFile(fp);
      if (optf !=NULL) {
        farg=OptionProcess(0,optf->argc,optf->argv,&opt,NULL);
        OptionFreeFile(optf);
       }   
       fclose(fp);
    } while (cfname !=NULL);
  }

  if (help==1) {
    OptionPrintInfo(stdout,hlpstr);
    exit(0);
  }

  if (option==1) {
    OptionDump(stdout,&opt);
    exit(0);
  }


  if (tmetxt !=NULL) tval=strtime(tmetxt);
  if (dtetxt !=NULL) dval=strdate(dtetxt);

  tval+=dval;
  TimeEpochToYMDHMS(tval,&yr,&mo,&dy,&hr,&mt,&sc);
  yrsec=TimeYMDHMSToYrsec(yr,mo,dy,hr,mt,sc);

  if (magflg) {
    MapModify(map,AACGMtransform,NULL);
    MapModify(bnd,AACGMtransform,NULL);
  }

  fov=make_fov(tval,network,alt); 

  if (magflg) MapModify(fov,AACGMtransform,NULL);


  if (tmtick<1) tmtick=1;
  if (tmtick>6) tmtick=6;

  if ((ortho==0) && (stereo==0)) cylind=1;

  if (grdflg) grd=make_grid(15,10,cylind);   
 
  if (tmkflg) tmk=make_grid(30*tmtick,10,cylind);

  if ((lat<0) && (latmin>0)) latmin=-latmin;
  if ((lat>0) && (latmin<0)) latmin=-latmin;

  if (trmflg || ftrmflg) {
    if ((cylind) || (ortho) | (gvp))
       trm=SZATerminator(yr,mo,dy,hr,mt,sc,0,magflg,
                           1.0,90.0);
     else if (lat>0) trm=SZATerminator(yr,mo,dy,hr,mt,sc,1,magflg,
                                     1.0,90.0);
     else trm=SZATerminator(yr,mo,dy,hr,mt,sc,-1,magflg,1.0,90.0);
  }
 
  marg[0]=lat;
  marg[1]=lon;

  tfunc=MapCylindrical;
  if (ortho) tfunc=MapOrthographic;
  if (stereo) tfunc=MapStereographic;
  if (gvp) tfunc=MapGeneralVerticalPerspective;

  if ((ortho) || (gvp)) marg[2]=sf;
  else if (stereo) marg[2]=1.25*0.5*sf*90.0/(90-fabs(latmin));
  else marg[2]=1;
  marg[3]=flip;

  strcpy(tsfx,"LT");
  if (magflg) strcpy(tsfx,"MLT");
  else if (lstflg) strcpy(tsfx,"LST");

  dec=SZASolarDec(yr,mo,dy,hr,mt,sc);
  eqt=SZAEqOfTime(yr,mo,dy,hr,mt,sc);

  if (magflg) tme_shft=-MLTConvertYrsec(yr,yrsec,0.0)*15.0; 
    else {
      if (lstflg) {
        LsoT=(hr*3600+mt*60+sc)+eqt;
        Hangle=15*(LsoT/3600);
        tme_shft=-Hangle;
      } else {
        LT=(hr*3600+mt*60+sc);
        Hangle=15*(LT/3600);
        tme_shft=-Hangle;
      }
    }
  if (lat<0) tme_shft+=180.0;

  if (rotflg)  marg[1]=lon+tme_shft;
  
  if ((cylind) || (sqflg)) clip=MapSquareClip(); 
  else clip=MapCircleClip(10); 

  if (mapflg || fmapflg) {
     nmap=MapTransform(map,2*sizeof(float),PolygonXYbbox,
                           tfunc,marg);
     if (cylind) nmap=wrap(nmap);
     pmap=PolygonClip(clip,nmap); 
  }
  if (bndflg) {
     nbnd=MapTransform(bnd,2*sizeof(float),PolygonXYbbox,
                      tfunc,marg);
     if (cylind) nbnd=wrap(nbnd);
     pbnd=PolygonClip(clip,nbnd);
  }
  if (grdflg) {
     ngrd=MapTransform(grd,2*sizeof(float),PolygonXYbbox,
                      tfunc,marg);
     if (cylind) ngrd=wrap(ngrd);
     pgrd=PolygonClip(clip,ngrd);
  }
  if (trmflg || ftrmflg) {
     ntrm=MapTransform(trm,2*sizeof(float),PolygonXYbbox,
                           tfunc,marg);
     if (cylind) ntrm=wrap(ntrm);
     ptrm=PolygonClip(clip,ntrm); 
  }

  nfov=MapTransform(fov,2*sizeof(float),PolygonXYbbox,
                     tfunc,marg);
  if (cylind) nfov=wrap(nfov);
  pfov=PolygonClip(clip,nfov);

  if (tmkflg) {
     float tmp;
     tmp=marg[1];
     if (rotflg) marg[1]=0;
     else marg[1]=lon-tme_shft;
     ntmk=MapTransform(tmk,2*sizeof(float),PolygonXYbbox,
                        tfunc,marg);
     ptmk=PolygonClip(clip,ntmk);
     marg[1]=tmp;
  }


  if (bgcol_txt !=NULL) bgcol=PlotColorStringRGBA(bgcol_txt);
  if (txtcol_txt !=NULL) txtcol=PlotColorStringRGBA(txtcol_txt);

  if (grdcol_txt !=NULL) grdcol=PlotColorStringRGBA(grdcol_txt);
  if (cstcol_txt !=NULL) cstcol=PlotColorStringRGBA(cstcol_txt);
  if (bndcol_txt !=NULL) bndcol=PlotColorStringRGBA(bndcol_txt);
  if (lndcol_txt !=NULL) lndcol=PlotColorStringRGBA(lndcol_txt);
  if (seacol_txt !=NULL) seacol=PlotColorStringRGBA(seacol_txt);
  if (trmcol_txt !=NULL) trmcol=PlotColorStringRGBA(trmcol_txt);
  if (ftrmcol_txt !=NULL) ftrmcol=PlotColorStringRGBA(ftrmcol_txt);

  if (tmkcol_txt !=NULL) tmkcol=PlotColorStringRGBA(tmkcol_txt);

  if (fovcol_txt !=NULL) fovcol=PlotColorStringRGBA(fovcol_txt);
  if (ofovcol_txt !=NULL) ofovcol=PlotColorStringRGBA(ofovcol_txt);
  if (cfovcol_txt !=NULL) cfovcol=PlotColorStringRGBA(cfovcol_txt);
 
  if (ffovcol_txt !=NULL) ffovcol=PlotColorStringRGBA(ffovcol_txt);
  if (fofovcol_txt !=NULL) fofovcol=PlotColorStringRGBA(fofovcol_txt);
  if (fcfovcol_txt !=NULL) fcfovcol=PlotColorStringRGBA(fcfovcol_txt);


  if ((wdt==0) || (hgt==0)) {
    fprintf(stderr,"invalid plot size.\n");
    exit(-1);
  }


  if (tlblflg) pad=10+fontsize;
  
  if (fontname==NULL) fontname=dfontname;

  fntdbfname=getenv("FONTDB");
  fontfp=fopen(fntdbfname,"r");
  if (fontfp !=NULL) {
   fontdb=FrameBufferFontDBLoad(fontfp);
   fclose(fontfp);
  }
 
  if (fontdb==NULL) {
   fprintf(stderr,"Could not load fonts.\n");
   exit(-1);
  }


  if (ststr !=NULL) stid=RadarGetID(network,ststr);
  for (stnum=0;stnum<network->rnum;stnum++) 
     if (stid==network->radar[stnum].id) break;  
  if (stnum==network->rnum) stnum=0;



  /* now determine our output type */

  if (psflg) pflg=1;
  if (xmlflg) gflg=1;
  if (ppmflg) gflg=1;
  if (ppmxflg) gflg=1;
  if (pngflg) gflg=1;

#ifdef _XLIB_ 
   if (xd !=0) {
     pflg=0; 
     gflg=1;
   }
#endif

  if (pflg) gflg=0;
  if ((!gflg) && (!pflg)) pflg=1;

  plot=PlotMake();
  splot=SplotMake();
  SplotSetPlot(plot,splot);

  if (gflg) SplotSetFrameBuffer(splot,&img,fontdb,NULL,NULL);
  if (pflg) {
    psdata=PostScriptMake();
    PostScriptSetText(psdata,stream,stdout);
    SplotSetPostScript(splot,psdata,0,xpoff,ypoff);
  }



  PlotDocumentStart(plot,"fov_plot",NULL,wdt,hgt,24);
  PlotPlotStart(plot,"fov_plot",wdt,hgt,24);

  PlotRectangle(plot,NULL,0,0,wdt,hgt,1,bgcol,0x0f,0,NULL);
     
  if (fmapflg) {
      if ((cylind) || (sqflg)) PlotRectangle(plot,NULL,pad,pad,
                               wdt-2*pad,hgt-2*pad,  
                             1,seacol,0x0f,0,NULL);
      PlotEllipse(plot,NULL,wdt/2,hgt/2,wdt/2-pad,hgt/2-pad,
                   1,seacol,0x0f,0,NULL);
  }

  if ((grdflg) && (!grdontop)) {
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                                grdcol,0x0f,width,NULL,
                                pgrd,1);
  }

  if (fmapflg) {
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                   lndcol,0x0f,0,NULL,pmap,1);
  
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                   lndcol,0x0f,0,NULL,pmap,3);
  
    MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                   seacol,0x0f,0,NULL,pmap,0);
  }

  if (ftrmflg) MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
                             1,ftrmcol,0x0f,0,NULL,ptrm,1);

  
  if (fofovflg) {
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status !=1) continue;
      MapPlotPolygon(plot,NULL,pad,pad,
                   wdt-2*pad,hgt-2*pad,1,fofovcol,0x0f,0,NULL,pfov,i); 
    }
  }

  if (fcfovflg) {
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status!=0) continue;
      MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,1,
                       fcfovcol,0x0f,0,NULL,pfov,i); 
    }
  }


   if (ffovflg) {
    MapPlotPolygon(plot,NULL,pad,pad,
                 wdt-2*pad,hgt-2*pad,1,ffovcol,0x0f,0,NULL,pfov,stnum); 
   }
  

  if (mapflg) {
     MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,cstcol,0x0f,
                    width,NULL,
                    pmap,1);
  
     MapPlotOpenPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,cstcol,0x0f,
                    width,NULL,
                    pmap,2);
  
     MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,cstcol,0x0f,
                    width,NULL,
                    pmap,0);
  }

  if (ofovflg)  {
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status !=1) continue;
      MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                    ofovcol,0x0f,width,NULL,
                    pfov,i);
    } 
  }

 if (cfovflg)  {
   
    for (i=0;i<network->rnum;i++) {
      if (network->radar[i].id==stid) continue;
      if (network->radar[i].status !=0) continue;
      MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                    cfovcol,0x0f,width,NULL,
                    pfov,i);
    } 
  }

 if (dotflg) {
   int s=0;
   struct RadarSite *site; 
   float pnt[2]; 
   if (cfovflg | fcfovflg)  {
     for (i=0;i<network->rnum;i++) {
       if (network->radar[i].id==stid) continue;
       if (network->radar[i].status !=0) continue;
       site=RadarYMDHMSGetSite(&(network->radar[i]),yr,mo,dy,hr,mt,sc);
       pnt[0]=site->geolat;
       pnt[1]=site->geolon; 
       s=(*tfunc)(sizeof(float)*2,pnt,2*sizeof(float),pnt,marg);
       if (s==0) PlotEllipse(plot,NULL,pad+pnt[0]*(wdt-2*pad),
                    pad+pnt[1]*(hgt-2*pad),dotr,dotr,
                    1,fcfovcol,0x0f,0,NULL);
           
     } 
   }
   if (ofovflg | fofovflg)  {
     for (i=0;i<network->rnum;i++) {
       if (network->radar[i].id==stid) continue;
       if (network->radar[i].status !=1) continue;
       site=RadarYMDHMSGetSite(&(network->radar[i]),yr,mo,dy,hr,mt,sc);
       pnt[0]=site->geolat;
       pnt[1]=site->geolon; 
       s=(*tfunc)(sizeof(float)*2,pnt,2*sizeof(float),pnt,marg);
       if (s==0) PlotEllipse(plot,NULL,pad+pnt[0]*(wdt-2*pad),
                    pad+pnt[1]*(hgt-2*pad),dotr,dotr,
                    1,fofovcol,0x0f,0,NULL);
           
     } 
   }

   if (fovflg) {
     
     site=RadarYMDHMSGetSite(&(network->radar[stnum]),yr,mo,dy,hr,mt,sc);
     pnt[0]=site->geolat;
     pnt[1]=site->geolon; 
     s=(*tfunc)(sizeof(float)*2,pnt,2*sizeof(float),pnt,marg);
     if (s==0) PlotEllipse(plot,NULL,pad+pnt[0]*(wdt-2*pad),
                    pad+pnt[1]*(hgt-2*pad),dotr,dotr,
                    1,ffovcol,0x0f,0,NULL);
   }


 }

  if (fovflg) MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                    fovcol,0x0f,width,NULL,
                    pfov,stnum);

  if (bndflg) MapPlotOpenPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
                                bndcol,0x0f,width,NULL,
                                pbnd,-1);

  if (trmflg) MapPlotOpenPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
                                trmcol,0x0f,width,NULL,
                                ptrm,1);

  if (tmkflg) MapPlotPolygon(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,0,
                                tmkcol,0x0f,width,NULL,
                                ptmk,1);

  if ((grdflg) && (grdontop)) {
    MapPlotPolygon(plot,NULL,0,0,wdt-2*pad,hgt-2*pad,0,
                                grdcol,0x0f,width,NULL,
                                pgrd,1);
  }


  if ((cylind) || (sqflg)) 
     PlotRectangle(plot,NULL,pad,pad,wdt-2*pad,hgt-2*pad,
               0,grdcol,0x0f,width,NULL);
  else PlotEllipse(plot,NULL,wdt/2,hgt/2,wdt/2-pad,hgt/2-pad,
               0,grdcol,0x0f,width,NULL);

  if (tlblflg){
      if (lat>0) plot_time_label(plot,pad,pad,wdt-2*pad,hgt-2*pad,
				 90,flip,tsfx,
                                 lon-tme_shft*(! rotflg),
                                 (wdt/2)-pad,6,
                                 txtcol,0x0f,fontname,fontsize,fontdb);
      else plot_time_label(plot,pad,pad,wdt-2*pad,hgt-2*pad,
			   -90,flip,tsfx,
                           lon-tme_shft*(! rotflg),
                           (wdt/2)-pad,6,
                           txtcol,0x0f,fontname,fontsize,fontdb);
  }

  PlotPlotEnd(plot);  
  PlotDocumentEnd(plot);

  if (!gflg) exit(0);
  if (img==NULL) {
    fprintf(stderr,"Nothing to plot.\n");
    exit(-1);
  }

#ifdef _XLIB_
  if (xd !=0) {
    dp=XwinOpenDisplay(display_name,&xdf);
 
    if (dp==NULL) {
      fprintf(stderr,"Could not open display.\n");
      exit(-1);
    }

    if (xdoff==-1) xdoff=(dp->wdt-img->wdt)/2;
    if (ydoff==-1) ydoff=(dp->hgt-img->hgt)/2;


    win=XwinMakeWindow(xdoff,ydoff,img->wdt,img->hgt,0,
                       dp,wname,
                       wname,argv[0],wname,argc,argv,&xdf);
    if (win==NULL) {
      fprintf(stderr,"Could not create window.\n");
      exit(-1);
    }

    XwinFrameBufferWindow(img,win);

    XwinShowWindow(win);

    XwinDisplayEvent(dp,1,&win,1,NULL);

    XwinFreeWindow(win);
    XwinCloseDisplay(dp);
  } else {
    if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
    else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
    else if (ppmxflg==1)  FrameBufferSavePPMX(img,stdout);
    else FrameBufferSavePNG(img,stdout);
  }
  #else 
    if (xmlflg==1) FrameBufferSaveXML(img,stream,stdout);
    else if (ppmflg==1) FrameBufferSavePPM(img,stdout);
    else if (ppmxflg==1) FrameBufferSavePPMX(img,stdout);
    else FrameBufferSavePNG(img,stdout); 
  #endif
    return 0;
}