Exemple #1
0
int closest(unsigned char **sec, double plat, double plon) {

    int i, nnpts;
    int grid_type, j;
    double t, xx, yy, zz, small;

    if (use_gctpc && output_order == wesn && nx > 0 && ny > 0) {
	if (gctpc_ll2i(1, &plon, &plat, &j) == 0) return j;
    }

    grid_type = code_table_3_1(sec);
    // if grid with (lat,lon) -> (i,j) /l.. insert code here
    if (grid_type == 0 && nx > 0 && ny > 0 && output_order == wesn) return latlon_closest(sec, plat, plon);
    if (grid_type == 90 && nx > 0 && ny > 0 && output_order == wesn) return space_view_closest(sec, plat, plon);

    nnpts = (int) GB2_Sec3_npts(sec);
    if (x == NULL || nnpts <= 0) return -1;

    zz = sin(plat * (M_PI / 180.0));
    t = sqrt(1.0 - zz*zz);
    xx = t * cos(plon * (M_PI / 180.0));
    yy = t * sin(plon * (M_PI / 180.0));

    small = 0.0;
    j = -1;
#pragma omp parallel private(i,t)
{
    double t_thread, small_thread;
    int j_thread;
    small_thread = 0.0;
    j_thread = -1;
   
#pragma omp for schedule(static) nowait
    for (i = 0; i < nnpts; i++) {
	if (x[i] >= 999.0) continue;
        t_thread = (x[i]-xx)*(x[i]-xx)+(y[i]-yy)*(y[i]-yy)+(z[i]-zz)*(z[i]-zz);
	if (j_thread == -1 || t_thread < small_thread) {
            small_thread = t_thread;
            j_thread = i;
        }
    }

#pragma omp critical
    {
	if (j == -1 || small_thread < small) {
            small = small_thread;
            j = j_thread;
        }
    }

}

    return j;
}
Exemple #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;
}