Пример #1
0
Файл: geo.c Проект: mmase/wgrib2
int closest_init(unsigned char **sec) {

    int i, nnpts;
    double s, c;
    int grid_type;


    if (use_gctpc && output_order == wesn && nx > 0 && ny > 0) {
       if (gctpc_ll2xy_init(sec, lon, lat) == 0) return 0;
    }

    grid_type = code_table_3_1(sec);

    if  (!GDS_Scan_staggered(scan) && nx > 0 && ny > 0) {
        /* if grids with (lat,lon) -> (i,j) insert code here */
        if (grid_type == 0 && output_order == wesn) return latlon_init(sec, nx, ny);
        if (grid_type == 90 && output_order == wesn) return space_view_init(sec);
    }

    nnpts = (int) GB2_Sec3_npts(sec);
    if (x) {
        free(x);
        free(y);
        free(z);
        x = y = z = NULL;
    }
    if (lat && lon) {
        x = (double *) malloc(nnpts * sizeof(double));
        y = (double *) malloc(nnpts * sizeof(double));
        z = (double *) malloc(nnpts * sizeof(double));
        if (x == NULL || y == NULL || z == NULL) fatal_error("memory allocation closest_init","");

#pragma omp parallel for private(i,s,c) schedule(static)
        for (i = 0; i < nnpts; i++) {
	    if (lat[i] >= 999.0 || lon[i] >= 999.0) {
		/* x[i] = sin() .. cannot be bigger than 1 */
		x[i] = y[i] = z[i] = 999.0;
	    }
            else {
                s = sin(lat[i] * (M_PI / 180.0));
                c = sqrt(1.0 - s * s);
                z[i] = s;
                x[i] = c * cos(lon[i] * (M_PI / 180.0));
                y[i] = c * sin(lon[i] * (M_PI / 180.0));
	    }
        }

    }
    return 0;
}
Пример #2
0
/*
 * HEADER:100:ll2i:inv:2:x=lon y=lat, converts to (i)
 */
int f_ll2i(ARG2) {

    double to_lat[1], to_lon[1];
    int i, iptr;

    if (mode == -1) {
        latlon = 1;
    }
    if (mode >= 0) {
        if (output_order != wesn) return 1;
        to_lon[0] = atof(arg1);
        to_lat[0] = atof(arg2);
        i = gctpc_ll2xy_init(sec, lon, lat);
        if (i == 0)  {
            i = gctpc_ll2i(1, to_lon, to_lat, &iptr);
            sprintf(inv_out,"%lf %lf -> (%d)",to_lon[0], to_lat[0], iptr);
        }
    }
    return 0;
}
Пример #3
0
/*
 * HEADER:100:ll2ij:inv:2:x=lon y=lat, converts lon-lat (i,j) 
 */
int f_ll2ij(ARG2) {

    double x[1], y[1], to_lat[1], to_lon[1];
    int i;

    if (mode == -1) {
	latlon = 1;
    }
    if (mode >= 0) {
	if (output_order != wesn)  return 1;
	to_lon[0] = atof(arg1);
	to_lat[0] = atof(arg2);
        i = gctpc_ll2xy_init(sec, lon, lat);
	if (i == 0)  {
            i = gctpc_ll2xy(1, to_lon, to_lat, x , y);
	    sprintf(inv_out,"%lf %lf -> (%lf,%lf)",to_lon[0], to_lat[0], x[0]+1.0, y[0]+1.0);
	}
    }
    return 0;
}