Example #1
0
static void _pgmvcp_gfaCalc ( VG_DBStruct *el, float dx, float dy, Boolean grp )
/************************************************************************
 * _pgmvcp_gfaCalc                                                      *
 *                                                                      *
 * Internal function for MOVE/COPY GFA's atribute box location.		*
 *                                                                      *
 * static void _pgmvcp_gfaCalc ()                 			*
 *      *el               VG_DBStruct	Pointer to gfa element		*
 *       dx               float		Increment on X axis		*
 *       dy               float		Increment on Y axis		*
 *       grp              Boolean	Group mode or not		*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * J. Wu/SAIC		02/04	initial coding				*
 * J. Wu/SAIC		10/04	Access GFA attr with cvg_getFld()	*
 ***********************************************************************/
{
    int		np, ier;
    float	delx, dely, xx, yy, nlat, nlon;
    char	value[32];
/*---------------------------------------------------------------------*/
/*
 * For group drag/drop, use the given dx, dy as the "delta" increment.
 */    
    delx = dx;
    dely = dy;
    
/*
 * For single element drag/drop, recalculate the "delta" increment. 
 */    
    if ( !grp && _dcN > 0 ) {
        delx = *(_dcX + _nearPt) - _origX;
        dely = *(_dcY + _nearPt) - _origY;
    }
    
/*
 * Adjust attribute text box location.
 */
    np = 1;
    cvg_getFld ( el, TAG_GFA_LAT, value, &ier );
    nlat = atof ( value );
    cvg_getFld ( el, TAG_GFA_LON, value, &ier );
    nlon = atof ( value );
    
    gtrans ( sys_M, sys_D, &np, &nlat, &nlon,
		 &xx, &yy, &ier, strlen(sys_M), strlen(sys_D) );
    xx += delx;
    yy += dely;
    gtrans ( sys_D, sys_M, &np, &xx, &yy, &nlat,&nlon,
		 &ier, strlen(sys_D), strlen(sys_M) );    
    
    sprintf ( value, "%7.2f", nlat );
    cvg_setFld ( el, TAG_GFA_LAT, value, &ier );

    sprintf ( value, "%7.2f", nlon );
    cvg_setFld ( el, TAG_GFA_LON, value, &ier );
}
Example #2
0
static void
hcl2rgb(double h, double c, double l, double *R, double *G, double *B)
{
    double L, U, V;
    double u, v;
    double X, Y, Z;

    /* Step 1 : Convert to CIE-LUV */

    h = DEG2RAD * h;
    L = l;
    U = c * cos(h);
    V = c * sin(h);

    /* Step 2 : Convert to CIE-XYZ */

    if (L <= 0 && U == 0 && V == 0) {
        X = 0; Y = 0; Z = 0;
    }
    else {
        Y = WHITE_Y * ((L > 7.999592) ? pow((L + 16)/116, 3) : L / 903.3);
        u = U / (13 * L) + WHITE_u;
        v = V / (13 * L) + WHITE_v;
        X =  9.0 * Y * u / (4 * v);
        Z =  - X / 3 - 5 * Y + 3 * Y / v;
    }

    /* Step 4 : CIE-XYZ to sRGB */

    *R = gtrans(( 3.240479 * X - 1.537150 * Y - 0.498535 * Z) / WHITE_Y);
    *G = gtrans((-0.969256 * X + 1.875992 * Y + 0.041556 * Z) / WHITE_Y);
    *B = gtrans(( 0.055648 * X - 0.204043 * Y + 1.057311 * Z) / WHITE_Y);
}
Example #3
0
static void _pgmvcp_wboxCalc ( void )
/************************************************************************
 * _pgmvcp_wboxCalc                                                     *
 *                                                                      *
 * Internal function for MOVE/COPY watch box point/anchor calculation	*
 *                                                                      *
 * static void _pgmvcp_wboxCalc ()                 			*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 *  D.W.Plummer/NCEP	11/00						*
 *  A. Hardy/GSC        11/00   renamed coordinate system declarations  *
 *  H. Zeng/XTRIA	01/03   modified arguments to pgwbxw_getAttr	*
 *  H.Zeng/SAIC		10/04	added two para. to pgwbxw_getAttr	*
 ***********************************************************************/
{
    int           ii, np, cnty_colr, ier;
    signed char	  cnty_fill;
    int           nearest, wcolr, wstyle, wshape, mtype, mwidth;
    float	  rx[8], ry[8], rx2[8], ry2[8], tlat[8], tlon[8], msize;
/*---------------------------------------------------------------------*/
/*
 * get the new corner points (by calculating anchor points)
 */
        pgwbxw_getAttr(&wcolr, &wstyle, &wshape, 
		       &mtype, &msize,  &mwidth,
		       &cnty_fill, &cnty_colr    );

        np = 8;

	for ( ii = 0; ii < np; ii++ )  {
	    rx[ii] = *(_dcX +ii);
	    ry[ii] = *(_dcY +ii);
	}
        gtrans (sys_D, sys_M, &np, rx, ry, tlat, tlon, &ier,
                strlen(sys_D), strlen(sys_M));
	nearest = 0;
        pgwpts_get(nearest, wshape, tlat, tlon, tlat, tlon, &ier);
        gtrans (sys_M, sys_D, &np, tlat, tlon, rx2, ry2, &ier,
                strlen(sys_M), strlen(sys_D));

/*
 * assign the new values
 */
        for (ii = 0; ii < np; ii++) {
            _dcX[ii] = rx2[ii];
            _dcY[ii] = ry2[ii];
            pgactv_modPt( ii, _dcX[ii], _dcY[ii] );
        }
        _dcX[np+1] = _dcX[0];
        _dcY[np+1] = _dcY[0];
        _dcX[np+2] = ( _dcX[2] + _dcX[6] ) / 2.0F;
        _dcY[np+2] = ( _dcY[2] + _dcY[6] ) / 2.0F;
        _dcX[np+3] = _dcX[4];
        _dcY[np+3] = _dcY[4];

}
Example #4
0
void clo_clipget ( int *which, int *npts, float *xo, float *yo, int *iret )
/************************************************************************
 * clo_clipget	                                                        *
 *                                                                      *
 * This routine obtains x and y coordinates of points of a contour.	*
 *                                                                      *
 * void clo_clipget ( which, npts, xo, yo, iret )			*
 *                                                                      *
 * Input parameters:                                                    *
 *      *which		int             Which contour to retrieve	*
 *                                                                      *
 * Output parameters:                                                   *
 *      *npts		int             Number of the contour points	*
 *      *xo		float		X array of contour points	*
 *      *yo		float		Y array of contour points       *
 *      *iret           int             Return code                     *
 *                                      =  0: normal                    *
 *                                      = -1: no such contour 	        *
 **                                                                     *
 * Log:                                                                 *
 * B. Yin/SAIC           9/04   	Created                         *
 ***********************************************************************/
{
    int		ii, ier;
    float	*xnormal, *ynormal; 
/*---------------------------------------------------------------------*/

    if ( *which >= gpc_poly_results.num_contours || *which < 0 ) {
       *iret = -1;
       return;
    }

    /*
     * Allocated memory for points in sys_N coordinates.
     */ 
    *npts  = gpc_poly_results.contour [ *which ].num_vertices;

    G_MALLOC ( xnormal, float, *npts, "CLO_CLIPGET: xnormal" );
    G_MALLOC ( ynormal, float, *npts, "CLO_CLIPGET: ynormal" );

    /*
     * Get (x, y) of the contour
     */
    for ( ii = 0; ii < *npts; ii++ ) {
	xnormal [ ii ] = gpc_poly_results.contour [ *which ].vertex [ ii ].x;
	ynormal [ ii ] = gpc_poly_results.contour [ *which ].vertex [ ii ].y;
    }

    /*
     * Convert sys_N to the incoming coordinate system 
     */
    gtrans ( sys_N, sysin, npts, xnormal, ynormal, xo, yo,
             &ier, strlen(sys_N), strlen(sysin) );

    G_FREE ( xnormal, float );
    G_FREE ( ynormal, float );

    *iret = 0;
    
}
Example #5
0
void wgem_gtrans( char *sysin, char *sysout, int *np, float *xin, float *yin,
                  float *xout, float *yout, int *iret )
/************************************************************************
 * wgem_gtrans              						*
 *									*
 * This function is a wrapper for gtrans.				*
 *									*
 * void wgem_gtrans( sysin, sysout, np, xin, yin, xout, yout, iret )	*
 *									*
 * Input parameters:							*
 *	*sysin		char	input coordinate system			*
 *	*sysout		char	output coordinate system		*
 *	*np		int	number of points			*
 *	*xin		float	input X coordinates / lats		*
 *	*yin		float	input Y coordinates / lons		*
 *									*
 * Output parameters:							*
 *	*xout		float	output X coordinates / lats		*
 *	*yout		float	output Y coordinates / lons		*
 *	*iret		int	return code				*
 **									*
 * E. Safford/SAIC	12/07	initial coding                          *
 ***********************************************************************/
{
    gtrans( sysin, sysout, np, xin, yin, xout, yout, iret,
            strlen( sysin ), strlen( sysout ) );
}
Example #6
0
void crg_rngpt ( float mx, float my, float *llx, float *lly, 
					float *urx, float *ury, int *iret ) 
/************************************************************************
 * crg_rngpt                                                            *
 *                                                                      *
 * This function returns the range for a single point (in map coords).	*
 * This does not write anything to the range record array -- it just    *
 * returns the range coordinates.					*
 *                                                                      *
 * crg_rngpt ( mx, my, llx, lly, urx, ury, iret ) 			*
 *                                                                      *
 * Input parameters:                                                    *
 *	mx		float		x coordinate of point		*
 *	my		float		y coordinate of point		*
 *                                                                      *
 * Output parameters:                                                   *
 * 	*llx		float		lower left x range coordinate 	*
 * 	*lly		float		lower left y range coordinate 	*
 * 	*urx		float		lower right x range coordinate	*
 * 	*ury		float		lower right y range coordinate	*
 *      *iret           int             Return code                     *
 **                                                                     *
 * Log:                                                                 *
 * E. Safford/GSC	10/98	initial coding                        	*
 * A. Hardy/GSC         11/00   renamed coordinate system declarations	*
 * J. Wu/GSC            03/01   Standardized extra space EXTRA/EXTRA_SM	*
 ***********************************************************************/
{
    float	rx, ry;
    float	srx, sry;
    int 	ier, np;
/*---------------------------------------------------------------------*/

    *iret = 0;

    /*
     *  Convert point in element to device...
     */
    np = 1;
    rx = mx;
    ry = my;
    gtrans(sys_M, sys_D, &np, &rx, &ry, &srx, &sry, &ier,
                        strlen(sys_M), strlen(sys_D));
   
    if (ier < 0) {
        *iret = -1;
    }
    else {
        *lly = sry - (float)EXTRA;
        *llx = srx - (float)EXTRA;
        *urx = srx + (float)EXTRA;
        *ury = sry + (float)EXTRA;
    }
}
Example #7
0
/*=====================================================================*/
static void _pgmvcp_ccfCalc ( VG_DBStruct *el, float dx, float dy, Boolean grp )
/******************************************************************************
  _pgmvcp_ccfCalc
  
  Internal function for MOVE/COPY CCF's attribute box location
  
  static void _pgmvcp_ccfCalc ()
    Input parameters:
      *el    VG_DBStruct Pointer to ccf element
      dx     float Increment on X axis
      dy     float Increment on Y axis
      grp    Boolean Group mode or not
**
  Log:
  L. Hinson  07/09  initial coding
*******************************************************************************/      
{
    int		np, ier;
    float	delx, dely, xx, yy, nlat, nlon;
    char	value[32];
    delx = dx;
    dely = dy;
    if ( !grp && _dcN > 0 ) {
        delx = *(_dcX + _nearPt) - _origX;
        dely = *(_dcY + _nearPt) - _origY;
    }
    np = 1;
    nlat = el->elem.ccf.info.textlat;
    nlon = el->elem.ccf.info.textlon;
    gtrans ( sys_M, sys_D, &np, &nlat, &nlon,
		 &xx, &yy, &ier, strlen(sys_M), strlen(sys_D) );
    xx += delx;
    yy += dely;
    gtrans ( sys_D, sys_M, &np, &xx, &yy, &nlat,&nlon,
		 &ier, strlen(sys_D), strlen(sys_M) );
    el->elem.ccf.info.textlat = nlat;
    el->elem.ccf.info.textlon = nlon;
}
Example #8
0
void radar_bounds(int *kx, int *ky, int *iret)
{
int i,j, ier;
int np;

*iret = 0;

np = 0;
for(i=1;i<=*kx;i++)
   for(j=1;j<=*ky;j++)
   {
   xin[np] = i; yin[np] = j;
   np++;
   }

gtrans(sys_G, sys_D, &np, xin, yin, xout, yout, &ier, strlen(sys_G), strlen(sys_D));

}
Example #9
0
void radar_ij ( float *i, float *j )
{
int np=1, ier;
float xin[1], yin[1], xout[1], yout[1];
static char sysg[]="G", sysm[]="M";

xin[0]=radar_clat;
yin[0]=radar_clon;
gtrans ( sysm, sysg, &np, xin, yin, xout, yout, &ier,
	strlen(sysm), strlen(sysg) );
if ( ier == 0 )
   {
   *i = xout[0];
   *j = yout[0];
   }
else
   {
   printf("look ier %d\n",ier);
   *i = RMISSD;
   *j = RMISSD;
   }
}
Example #10
0
int convertcoords ( 	char *incoords,
			char *outcoords,
			float *xin,
			float *yin,
			float *xout,
			float *yout )
{

	int		np = 1;
	int		iret;

	if ( strlen (incoords) != 1 || strlen (outcoords) != 1 ) return (0);
/*
 *	Call GEMPAK GTRANS to convert coords
 */	
	gtrans ( incoords, outcoords, &np, xin, yin, xout, yout, &iret,
	         strlen(incoords), strlen(outcoords) );

	if ( iret == 0 && *xout != RMISSD && *yout != RMISSD )
	    return (1);
	else
	    return (0);
	    
}
Example #11
0
void uka_jtin ( int njp, float jlat[], float jlon[], int nwp,
                float wlat[], float wlon[], float wspd [],
                float wlvl[], float wlvla[], float wlvlb[], int wtyp[], 
		int *nop, float olat[], float olon[], float ospd[], 
		float olvl[], float olvla[], float olvlb[], int *iret )
/************************************************************************
 * uka_jtin								*
 *                                                                      *
 * This function puts the core points, the wind barb points and the 	*
 * hash points in the correct order, and gets the wind speed values 	*
 * for the hash marks.							* 
 *                                                                      *
 * uka_jtin ( njp, jlat, jlon, nwp, wlat, wlon, wspd, wlvl, wlvla, 	*
 *            wlvlb, wtyp, nop,	olat, olon, ospd, olvl, olvla, olvlb, 	*
 *            iret )							*
 *                                                                      *
 * Input parameters:                                                    *
 *      njp             int             Number of jet core points	*
 *      jlat[]          float           Latitudes of core points	*
 *      jlon[]          float           Longitudes of core points	*
 *      nwp             int             No. of wind (barb & hash) pts	*
 *      wlat[]          float           Latitudes of wind points        *
 *      wlon[]          float           Longitudes of wind points  	*
 *      wspd[]          float           Speed of wind points (m/sec)	*
 *      wlvl[]          float           Flight level of wind pts (m)	*
 *	wlvla[]		float		Flight level above jet (m)	*
 *	wlvlb[]		float		Flight level below jet (m)	*
 *      wtyp[]          int             Wind point types		*
 *                                         1 = wind barb point		*
 *                                         2 = hash point		*
 *									*
 * Output parameters:							*
 *      *nop            int             Total number of points		*
 *      olat[]          float           Latitudes of points		*
 *      olon[]          float           Longitudes of points		*
 *      ospd[]          float           Speed of points (m/sec)		*
 *      olvl[]          float           Flight levels of points (m)	*
 *	olvla[]		float		Flight level above jet (m)	*
 *	olvlb[]		float		Flight level below jet (m)	*
 *      *iret           int             Return code			*
 *                                         0 = normal return		*
 *                                        15 = curve fit problem	*
 **                                                                     *
 * Log:                                                                 *
 * M. Li/SAIC		02/04	Extracted from sig_jets			*
 * M. Li/SAIC		04/04	Added flight level above/below jet	*
 * M. Li/SAIC		05/04	Copied from sig_jtin			*
 * M. Li/SAIC		07/04	Added olvl to UKA_JTSP			*
 * M. Li/SAIC		01/06	Added CED projection  			*
 ***********************************************************************/
{
    int 	ii, ier;
    char	proj[8];
    float 	minlat, maxlat, lllat, lllon, urlat, urlon;
    float 	angle1, angle2, angle3;
    float	dens, crvscl;
    float 	px[MAXPTS], py[MAXPTS], qx[MAXPTS], qy[MAXPTS],
          	tx[MAXPTS], ty[MAXPTS];
    int    	otyp[MAXPTS];
    int		widx[MAXPTS];
/*---------------------------------------------------------------------*/
    *iret   = 0;

    dens = 5.0F;
    crvscl = 30.0F;
    *nop = MAXPTS;
    minlat = 9999.0F;
    maxlat = -9999.0F;
    for ( ii = 0; ii < njp; ii++ ) {
    	minlat = G_MIN ( minlat, jlat[ii] );
    	maxlat = G_MAX ( maxlat, jlat[ii] );

    }

    if ( minlat >= 0.0F ) {
    	/*
    	 * Use North STR projection.
    	 */
    	strcpy ( proj, "STR" );
    	angle1 = 90.0F;
    	angle2 = -90.0F;
    	angle3 = 0.0F;
    	lllat = -15.0F;
    	lllon = -135.0F;
    	urlat = -15.0F;
    	urlon = -135.0F;
    }
    else if (maxlat < 0.0F ) {
    	/*
    	 * Use South STR projection.
    	 */
    	strcpy ( proj, "STR" );
    	angle1 = -90.0F;
    	angle2 = -90.0F;
    	angle3 = 0.0F;
    	lllat = 15.0F;
    	lllon = -135.0F;
    	urlat = 15.0F;
    	urlon = -135.0F;
    }
    else {
	/*
         * Use CED projection.
         */
	strcpy ( proj, "CED" );
        angle1 = 0.0F;
        angle2 = 0.0F;
        angle3 = 0.0F;
        lllat = -90.0F;
        lllon = -180.0F;
        urlat = 90.0F;
        urlon = 180.0F;
    }
    gsmprj ( proj, &angle1, &angle2, &angle3,
     	     &lllat, &lllon, &urlat, &urlon, &ier, strlen(proj) );
    gtrans ( sys_M, sys_D, &njp, jlat, jlon, px, py, &ier,
     	     strlen(sys_M), strlen(sys_D) );
    gtrans ( sys_M, sys_D, &nwp, wlat, wlon, qx, qy, &ier,
     	     strlen(sys_M), strlen(sys_D) );
    cgr_insert ( px, py, njp, qx, qy, nwp, dens, crvscl,
                 tx, ty, nop, widx, &ier );

    if ( ier != 0 ) {
        *iret = 15;
    }
    else {
    	gtrans ( sys_D, sys_M, nop, tx, ty, olat, olon, &ier,
     		 strlen(sys_D), strlen(sys_M) );

    	for ( ii = 0; ii < *nop; ii++) {
	    olvl[ii]  = SIGRLMS;
	    olvla[ii] = SIGRLMS;
	    olvlb[ii] = SIGRLMS;
	    ospd[ii]  = SIGRLMS;
	    otyp[ii]  = ILINE;
      	}
    	for ( ii = 0; ii < nwp; ii++ ) {
	    ospd[widx[ii]] = wspd[ii];
	    olvl[widx[ii]] = wlvl[ii];
	    olvla[widx[ii]] = wlvla[ii];
	    olvlb[widx[ii]] = wlvlb[ii];
	    otyp[widx[ii]] = wtyp[ii]; 
    	}

    	/*
     	 * Calculate wind speed for hash marks.
     	 */

    	uka_jtsp ( *nop, otyp, ospd, olvl, &ier );
    }

}
Example #12
0
static void pgconn_smear ( int loc1,  int loc2, VG_DBStruct *elOut,
			  int *nout, float *outX, float *outY )
/************************************************************************
 * pgconn_smear	                                          		*
 *                                                                      *
 * This function smears two selected GFA elements.  If the two GFAs	*
 * intersect, they are combined using "union";  otherwise, they are	*
 * combined using "shrink-wrap" algorithm.				*
 *									*
 * static void pgconn_smear ( loc1, loc2, elOut, nout, outX, outY )	*
 *                                                                      *
 * Input parameters:                                                    *
 *	loc1		int		Location of first GFA element	*
 *	loc2		int		Location of second GFA element	*
 *									*
 * Output parameters:                                             	*
 *      *elOut		VG_DBStruct	GFA element			*
 *	*nout		int		number of smear points		*
 *	outX[]		float		x of smear points in sys_D	*
 *	outY[]		float		y of smear points in sys_D	*
 *									*
 * Return parameters:                                             	*
 *    			None			       		 	*
 **                                                                     *
 * Log:                                                                 *
 * J. Wu/SAIC		06/07	initial coding				*
 * J. Wu/SAIC		09/07	add "unionOnly" into pgsmear_smear	*
 ***********************************************************************/
{
    int		ii, jj, npts, ier, GFA_loc[2], ntmp;
    char	value[10];
    float	*xtmp, *ytmp, *lat, *lon;
    Boolean	repeat;
/*---------------------------------------------------------------------*/
/*
 *  Set computational projection
 */
    ncw_set ( );
    ncw_sproj ( "PREFS" );
    
/*
 *  Smear
 *  Note: pgsmear_smear() needs following options for "join" GFAs:
 *        "skipFzlvl"	- False: closed FZLVL could be joined.
 *        "useAllShapShots"	- True:  snapshots' status doesn't matter.
 *        "reducePts"	- False: no point reduction performed.
 */
    GFA_loc[ 0 ] = loc1;	    
    GFA_loc[ 1 ] = loc2;	    
    pgsmear_smear ( 2, GFA_loc, False, _primaryEl.hdr.maj_col, 0, 
		    NULL, False, False, True, False, True,		  
		    elOut, nout, outX, outY );
    
/*
 *  Remove repeated points
 */
    ntmp = *nout;
    G_MALLOC ( xtmp, float, ntmp, "pgsmear_doSnap xtmp" );
    G_MALLOC ( ytmp, float, ntmp, "pgsmear_doSnap ytmp" );
    G_MALLOC ( lat, float, ntmp, "pgconn_select: lat" );
    G_MALLOC ( lon, float, ntmp, "pgconn_select: lon" );
    
    npts = 0;
    for ( ii = 0; ii < *nout; ii++ ) {

	repeat = False;

	for ( jj = ii + 1; jj < ntmp; jj++ ) {

	    if ( ( fabs ( outX[ ii ] - outX[ jj ] ) < .0001 ) &&

	         ( fabs ( outY[ ii ] - outY[ jj ] ) < .0001 ) ) {

	       repeat = True;
	       break;

	    }
	}

	if ( !repeat ) {

	   xtmp[ npts ] = outX[ ii ];
	   ytmp[ npts ] = outY[ ii ];
	   npts++;
	}
    }
    
/*
 *  Convert device (x,y) to (lat,lon) and put into el. 
 */
    gtrans ( sys_D, sys_M, &npts, xtmp, ytmp, lat, lon, &ier,
    	     strlen(sys_D), strlen(sys_M) );

    if ( npts > 0 ) {

       elOut->elem.gfa.info.npts = npts;

       for ( ii = 0; ii < npts; ii++ ) {

           elOut->elem.gfa.latlon[ ii ] 	 = lat[ ii ];
           elOut->elem.gfa.latlon[ ii + npts ]   = lon[ ii ];

       }
    }
   
/*
 *  Unset computational projection and back to current projection
 */
    ncw_unset ( );
    
/*
 *  Snap if the first polygon is an airmet or outlook.
 */		                         
    cvg_getFld ( &_primaryEl, TAG_GFA_FCSTHR, value, &ier );
    		    
    if ( strchr ( value, '-' ) ) {                                              
	pgsmear_snapEl ( True, elOut, &ier );			
    }
    
/*
 *  Convert into device for ghosting in current projection.
 */		                         
    *nout = elOut->elem.gfa.info.npts;
		        
    gtrans ( sys_M, sys_D, nout, elOut->elem.gfa.latlon,
	     &(elOut->elem.gfa.latlon[*nout]), outX, outY,
	     &ier, strlen(sys_M), strlen(sys_D) );
		    
    
    G_MALLOC ( xtmp, float, ntmp, "pgconn_smear xtmp" );
    G_MALLOC ( ytmp, float, ntmp, "pgconn_smear ytmp" );
    G_MALLOC ( lat, float, ntmp, "pgconn_smear lat" );
    G_MALLOC ( lon, float, ntmp, "pgconn_smear lon" );

/*
 *  Adopt the first selected GFA's attributes.
 */
    cvg_getFld ( &_primaryEl, TAG_GFA_FCSTHR, value, &ier );
    cvg_setFld ( elOut, TAG_GFA_FCSTHR, value, &ier );
                    
    cvg_getFld ( &_primaryEl, TAG_GFA_SUBTYPE, value, &ier );
    cvg_setFld ( elOut, TAG_GFA_SUBTYPE, value, &ier );		    
    ces_get( atoi( value ), elOut, &ier );
		    
    elOut->hdr.maj_col = _primaryEl.hdr.maj_col;
    elOut->hdr.min_col = _primaryEl.hdr.min_col;
}
Example #13
0
void cvg_todev ( VG_DBStruct *el, int *np, float *dx, float *dy, int *iret )
/************************************************************************
 * cvg_todev								*
 *									*
 * This function converts the map based coordinates that are used in	*
 * the VGF file to a device based coordinate equivalent to the current	*
 * display.								*
 *									*
 * cvg_todev ( el, np, dx, dy, iret )					*
 *									*
 * Input parameters:							*
 *	*el		VG_DBStruct	Pointer to VG record structure	*
 *									*
 * Output parameters:							*
 *	*np		int		Number of points		*
 *	*dx		float		Array of device coordinates	*
 *	*dy		float		Array of device coordinates	*
 *	*iret		int		Return code			*
 *					 -4 = unknown VG record type	*
 *									*
 **									*
 * Log:									*
 * E. Wehner/EAi	11/96	Created					*
 * D. Keiser/GSC	 1/97	Clean up				*
 * D. Keiser/GSC	 3/97	Added contour type			*
 * D. Keiser/GSC	 4/97	Added special line			*
 * E. Safford/GSC        4/97   Added text type                 	*
 * E. Wehner/EAi	 5/97	Added symbols/lines			*
 * E. Wehner/EAi	 5/97	Added wind barbs			*
 * E. Safford/GSC	 6/97	Added special text			*
 * D.W.Plummer/NCEP	 9/97	Changes for new vgstruct header file	*
 * E. Wehner/EAi	 9/97	REmoved xwdrawcmn.h and unused comments	*
 * W. Li/EAI		04/98	Add DARR_ELM, HASH_ELM			*
 * I. Durham/GSC	 5/98	Changed underscore decl. to an include	*
 * A. Hardy/GSC         10/98   Added CMBSY_ELM                         *
 * T. Piper/GSC		10/98	Prolog update				*
 * A. Hardy/GSC         11/98   Modified CIRCLE_ELM case statements     *
 * S. Law/GSC		05/99	Added TRKSTORM_ELM			*
 * G. Krueger/EAI	05/99	Modified circles for latlon array	*
 * S. Law/GSC		07/99	Added SIGINTL_ELM			*
 * S. Law/GSC		08/99	Added remaining SIGMETs			*
 * S. Law/GSC		02/00	Added SIGCCF_ELM			*
 * J. Wu/GSC		11/00	Removed unused CONTOUR_ELM case	        *
 * A. Hardy/GSC         11/00   renamed coordinate system declarations  *
 * J. Wu/SAIC		11/02	add LIST_ELM	        		*
 * H. Zeng/XTRIA	07/03   added VOLC_ELM				*
 * J. Wu/SAIC		10/03	add JET_ELM	        		*
 * H. Zeng/XTRIA	10/03   added ASHCLD_ELM			*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 * J. Wu/SAIC		02/04	add GFA_ELM	        		*
 * B. Yin/SAIC		04/04	add TCA_ELM	        		*
 * B. Yin/SAIC		05/04	Modified TCA_ELM case statement.	*
 * B. Yin/SAIC		07/04	Modified TCA case for water and islands	*
 * S. Gilbert/NCEP	11/05	Added Zero WW case for TCA_ELM          *
 * L. Hinson/AWC        01/12   Add SGWX_ELM                            *
 ***********************************************************************/
{
    int		ier;
    char	grp[4];
    int		ier1;
    int		loglev, counter, ibkpts;
    float	lat[ MAXPTS ], lon[ MAXPTS ];
/*---------------------------------------------------------------------*/
    strcpy(grp, "CVG");
    loglev = 0;

    *iret = 0;

    switch ( el->hdr.vg_type)
    {
	case FRONT_ELM:

	    *np = el->elem.frt.info.numpts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, el->elem.frt.latlon, 
		   &(el->elem.frt.latlon[*np]),
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case CIRCLE_ELM:

	    *np = el->elem.cir.info.numpts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, el->elem.cir.data.latlon, 
		   &(el->elem.cir.data.latlon[*np]),
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case SPLN_ELM:

	    *np = el->elem.spl.info.numpts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, el->elem.spl.latlon, 
		   &(el->elem.spl.latlon[*np]),
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case LINE_ELM:

            *np = el->elem.lin.info.numpts;
/*
 *          Convert all points in element to device...
 */
            gtrans(sys_M, sys_D, np, el->elem.lin.latlon, 
		   &(el->elem.lin.latlon[*np]),
		   dx, dy, &ier,
                   strlen(sys_M), strlen(sys_D));
            break;

	case WBOX_ELM:

	    *np = el->elem.wbx.info.numpts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, el->elem.wbx.latlon, 
		   &(el->elem.wbx.latlon[*np]),
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

        case TEXT_ELM:
        case TEXTC_ELM:

            *np = 1;
            gtrans(sys_M, sys_D, np, 
		   &el->elem.txt.info.lat, &el->elem.txt.info.lon,
		   dx, dy, &ier,
                   strlen(sys_M), strlen(sys_D));
            break;

	case SPTX_ELM:
            *np = 1;
            gtrans(sys_M, sys_D, np, 
		   &el->elem.spt.info.lat, &el->elem.spt.info.lon,
		   dx, dy, &ier,
                   strlen(sys_M), strlen(sys_D));
	    break;

        case MARK_ELM:
        case WXSYM_ELM:
        case CTSYM_ELM:
        case ICSYM_ELM:
        case PTSYM_ELM:
        case PWSYM_ELM:
        case SKSYM_ELM:
        case SPSYM_ELM:
        case TBSYM_ELM:
        case CMBSY_ELM:
/*
 *          Convert the point in the element to device coordinates.
 */
            *np = 1;
            gtrans(sys_M, sys_D, np, 
		   &el->elem.sym.data.latlon[0], &el->elem.sym.data.latlon[*np],
		   dx, dy, &ier,
                   strlen(sys_M), strlen(sys_D));
	    break;

	case BARB_ELM:
	case ARROW_ELM:
	case DARR_ELM:
	case HASH_ELM:
/*
 *          Convert the point in the element to device coordinates.
 */
            *np = 1;
            gtrans(sys_M, sys_D, np, 
		   &el->elem.wnd.data.latlon[0], &el->elem.wnd.data.latlon[*np],
		   dx, dy, &ier,
                   strlen(sys_M), strlen(sys_D));
            break;

	case TRKSTORM_ELM:

	    *np = el->elem.trk.info.npts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.trk.latlon[0], 
		   &el->elem.trk.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;


	case SIGAIRM_ELM:
	case SIGCONV_ELM:
	case SIGINTL_ELM:
	case SIGNCON_ELM:
	case SIGOUTL_ELM:

	    *np = el->elem.sig.info.npts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.sig.latlon[0], 
		   &el->elem.sig.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case SIGCCF_ELM:

	    *np = el->elem.ccf.info.npts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.ccf.latlon[0], 
		   &el->elem.ccf.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

        case VOLC_ELM:
/*
 *          Convert the point in the element to device coordinates.
 */
            *np = 1;
            gtrans(sys_M, sys_D, np, 
		   &el->elem.vol.latlon[0], &el->elem.vol.latlon[*np],
		   dx, dy, &ier,
                   strlen(sys_M), strlen(sys_D));
	    break;

	case ASHCLD_ELM:

	    *np = el->elem.ash.info.npts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.ash.latlon[0], 
		   &el->elem.ash.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case LIST_ELM:

	    *np = el->elem.lst.data.nitems;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.lst.data.lat[0], 
		   &el->elem.lst.data.lon[0],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case JET_ELM:

	    *np = el->elem.jet.line.spl.info.numpts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.jet.line.spl.latlon[0], 
		   &el->elem.jet.line.spl.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	case GFA_ELM:

	    *np = el->elem.gfa.info.npts;

	    gtrans(sys_M, sys_D, np, &el->elem.gfa.latlon[0], 
		   &el->elem.gfa.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

        case SGWX_ELM:
            *np = el->elem.sgwx.info.npts;
/*
 *	    Convert all points in element to device...
 */
	    gtrans(sys_M, sys_D, np, &el->elem.sgwx.latlon[0], 
		   &el->elem.sgwx.latlon[*np],
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break; 

	case TCA_ELM:

	    *np = 0;

            if ( el->elem.tca.info.wwNum == 0 ) {
               lat[0] = el->elem.tca.info.text_lat;
               lon[0] = el->elem.tca.info.text_lon;
               *np = 1;
            }
            else {
	        for ( counter = 0; counter < el->elem.tca.info.wwNum; counter++ ) {
		    for ( ibkpts = 0; ibkpts < el->elem.tca.info.tcaww[ counter ].numBreakPts; ibkpts++ ){
		        lat[ *np ] = el->elem.tca.info.tcaww[ counter ].breakPnt[ ibkpts ].lat;
		        lon[ *np ] = el->elem.tca.info.tcaww[ counter ].breakPnt[ ibkpts ].lon;
		        (*np)++;
		    }
	        }
	    }
	    gtrans(sys_M, sys_D, np, lat, lon, 
		   dx, dy, &ier,
		   strlen(sys_M), strlen(sys_D));
	    break;

	default:
	    *iret = -4;
            er_lmsg( &loglev, grp, iret, NULL, &ier1, strlen(grp));

	    break;
    }
}
Example #14
0
void clo_clip ( int *np, float *xp, float *yp, char *sysp, char *bounds,
		char *name, int *nclip, int *maxpts, int *iret )
/************************************************************************
 * clo_clip	                                                        *
 *                                                                      *
 * This routine performs clipping of a polygon against a specified      *
 * bounds area.                                                         *
 *                                                                      *
 * void clo_clip ( np, xp, yp, sysp, bounds, name, nclip, 		*
 *		   maxpts, iret )					*
 *                                                                      *
 * Input parameters:                                                    *
 *      *np		int             Number of polygon points        *
 *      *xp		float		X array of polygon points	*
 *      *yp		float		Y array of polygon points       *
 *	*sysp		char		Polygon points coordinate system*
 *	*bounds		char		Bounds name			*
 *	*name		char		Clipping area tag 		*
 *                                                                      *
 * Output parameters:                                                   *
 *      *nclip		int             Number of resulting contours    *
 *      *maxpts		int             Maximum number of points for any*
 *					contour in the resulting polygon*
 *      *iret           int             Return code                     *
 *                                      =  0: normal                    *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * B. Yin/SAIC           9/04   	Created                         *
 ***********************************************************************/
{
    int     		ier, ii;
    float   		*xnormal, *ynormal;
    gpc_polygon     	gpc_poly, gpc_poly_bnds, gpc_poly_tmp; 
    gpc_vertex_list 	verts;
/*---------------------------------------------------------------------*/

    strcpy ( sysin, sysp ); 

    /*
     * Convert incoming coordinate system to sys_N (normalized).
     */
    G_MALLOC ( xnormal, float, *np, "CLO_CLIP: xnormal" );
    G_MALLOC ( ynormal, float, *np, "CLO_CLIP: ynormal" );

    gtrans ( sysp, sys_N, np, xp, yp, xnormal, ynormal,
             &ier, strlen(sysp), strlen(sys_N) );

    /*
     * Fill GPC polygon structure with incoming points.
     */
    gpc_poly.num_contours = 0;
    gpc_poly.hole         = (int*)NULL;
    gpc_poly.contour      = (gpc_vertex_list*)NULL;

    verts.vertex          = (gpc_vertex*)NULL;
    verts.num_vertices    = 0;

    gpc_cvlist ( *np, xnormal, ynormal, &verts, &ier );
    gpc_add_contour ( &gpc_poly, &verts, G_FALSE );

    /*
     * Create a GPC polygon for the bounds.
     */
    clo_clipbnds ( bounds, name, &gpc_poly_bnds, &ier );

    /*
     * Clip
     */
    gpc_polygon_clip ( GPC_INT, &gpc_poly, &gpc_poly_bnds, &gpc_poly_tmp );

    /*
     * Remove holes. Holes are ignored in this release.
     */
    gpc_poly_results.num_contours = 0;
    gpc_poly_results.hole         = (int*)NULL;
    gpc_poly_results.contour      = (gpc_vertex_list*)NULL;

    for ( ii = 0; ii < gpc_poly_tmp.num_contours; ii++ ) {
	if ( gpc_poly_tmp.hole [ ii ] == G_FALSE ) {
	   gpc_add_contour ( &gpc_poly_results, &gpc_poly_tmp.contour [ ii ], G_FALSE );
	}
    }

    /*
     * Get the number of contours in the resulting polygon
     * and the maximum number of pointers of any contour
     */
    *nclip  = gpc_poly_results.num_contours;
    *maxpts = 0;

    for ( ii = 0; ii < *nclip; ii++ ) {
        *maxpts = MAX ( *maxpts, gpc_poly_results.contour [ ii ].num_vertices );
    }

    /*
     * Release memory
     */
    gpc_free_polygon ( &gpc_poly_bnds );
    gpc_free_polygon ( &gpc_poly_tmp );
    gpc_free_polygon ( &gpc_poly );

    free ( verts.vertex );

    G_FREE ( xnormal, float );
    G_FREE ( ynormal, float );

    *iret = 0;

}
Example #15
0
static void clo_clipbnds ( char *bounds, char *name, gpc_polygon *polygon, 
		    int *iret )
/************************************************************************
 * clo_clipbnds		                                                *
 *                                                                      *
 * This routine puts all bound parts into a polygon.			*
 *                                                                      *
 * void clo_clipbnds ( bounds, name, polygon, iret )			*
 *                                                                      *
 * Input parameters:                                                    *
 *	*bounds		char		Bounds name			*
 *	*name		char		Clipping area tag		*
 *                                                                      *
 * Output parameters:                                                   *
 *	*polygon	gpc_polygon	Resulting polygon		*
 *      *iret           int             Return code                     *
 *                                      =  0: normal                    *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * B. Yin/SAIC           9/04   	Created                         *
 ***********************************************************************/
{
    int			minp, maxp, next, npts, ier;
    float		*xlat, *ylon, *xnormal, *ynormal;
    float		filter;
    gpc_vertex_list 	verts;
/*---------------------------------------------------------------------*/

    /*
     * Set bounds type and tag
     */
    clo_bstype ( bounds, &ier );
    clo_bstag  ( name, &ier );

    /*
     * Initialization
     */
    minp   = 0;
    maxp   = LLMXPT;
    filter = 0.0F;
    next   = 0;

    G_MALLOC ( xlat, float, maxp, "CLO_CLIPBNDS: xlat" );
    G_MALLOC ( ylon, float, maxp, "CLO_CLIPBNDS: ylon" );

    polygon->num_contours = 0;
    polygon->hole         = (int*)NULL;
    polygon->contour      = (gpc_vertex_list*)NULL;

    /*
     * Read each bounds part and put it in a gpc polygon
     */  
    clo_bgnext ( &minp, &maxp, &filter, &npts, xlat, ylon, &next );
 
    while ( next == 0 ) {
        /*
         * Convert bounds coordinate system to sys_N
         */
        G_MALLOC ( xnormal, float, npts, "CLO_CLIPBNDS: xnormal" );
        G_MALLOC ( ynormal, float, npts, "CLO_CLIPBNDS: ynormal" );

        gtrans ( sys_M, sys_N, &npts, xlat, ylon, xnormal, ynormal,
                 &ier, strlen(sys_M), strlen(sys_N) );

        /*
         * Create GPC polygon structures for bounds.
         */
        verts.vertex          = (gpc_vertex*)NULL;
        verts.num_vertices    = 0;

        gpc_cvlist ( npts, xnormal, ynormal, &verts, &ier );

	/*
	 * Holes are not considered 
	 */
        gpc_add_contour ( polygon, &verts, G_FALSE );

	/*
	 * Free memory
	 */
        free ( verts.vertex );
        G_FREE ( xnormal, float );
        G_FREE ( ynormal, float );

        clo_bgnext ( &minp, &maxp, &filter, &npts, xlat, ylon, &next );
    }
  
    G_FREE ( xlat, float );
    G_FREE ( ylon, float );

    *iret = 0;

}
Example #16
0
void dgc_subg ( const char *ijskip, int *maxgrid, int *imll, int *jmll, 
                int *imur, int *jmur, int *iret )
/************************************************************************
 * dgc_subg								*
 *									*
 * This subroutine sets the internal subset grid given the reference	*
 * grid navigation set in GPLT and the map projection set in GPLT.	*
 * If the reference grid is globe wrapping with the addition of an	*
 * extra grid column, then the navigation set in GPLT must be that for	*
 * the grid with the extra column.					*
 * 									*
 * The subset grid is larger by five grid points than that strictly	*
 * needed to cover the map projection area.  This extension permits	*
 * more accurate computation of derivatives.  The subset grid relative	*
 * coordinates of the region strictly needed for the map are returned.	*
 * 									*
 *									*
 * IJSKIP is parsed by IN_GSKP.  IJSKIP information is entered using	*
 * the following format, where items in square brackets are optional:	*
 *									*
 *	IJSKIP = Iskip[;Istart][;Iend][/Jskip[;Jstart][;Jend]],		*
 *									*
 *	IJSKIP=Y[ES], or IJSKIP=N[O]					*
 *									*
 * The following rules apply in using IJSKIP input:			*
 *									*
 * 1.  If only Iskip is entered, then I and J skips are Iskip.  The	*
 *     beginning points and ending points are determined by querying	*
 *     the display projection to find the area on the reference grid	*
 *     needed to cover it.						*
 *									*
 * 2.  If any bounding value is omitted, it is determined automatically *
 *     by querying the display projection as in 1 above.		*
 *									*
 * 3.  If IJSKIP is blank or NO, skipping is not used to determine the	*
 *     internal grid navigation.					*
 * 									*
 * 4.  If IJSKIP is YES, all skip parameters are determined		*
 *     automatically.							*
 * 									*
 * dgc_subg ( ijskip, maxgrid, imll, jmll, imur, jmru, iret )		*
 *									*
 * Input parameters:							*
 *	*ijskip		const char	User input for skip subsetting	*
 *	*maxgrid	int		Maximum grid size               *
 *									*
 * Output parameters:							*
 *	*IMLL		int		Lower left map I bound		*
 *	*JMLL		int		Lower left map J bound		*
 *	*IMUR		int		Upper right map I bound		*
 *	*JMUR		int		Upper right map J bound		*
 * 	*IRET		int		Return code			*
 *					  0 = normal return		*
 *					-37 = no ref grid navigation set*
 *					-38 = glb wrap grd inconsistency*
 *					-39 = map projection is not set *
 *					-40 = subset grd bound error	*
 *					-41 = subset grid is too big	*
 *					-43 = cannot rearrange grid	*
 *					-44 = error set subset grid nav	*
 *					-48 = both I bounds required	*
 **									*
 * Log:									*
 * K. Brill/HPC		08/02						*
 * K. Brill/HPC		 9/02	Also initialize gparmd () to blank	*
 * S. Jacobs/NCEP	11/02	Added check for current nav vs saved nav*
 * K. Brill/HPC		11/02	Eliminate use of the SUBA logical array	*
 * K. Brill/HPC		12/02	Use IJSKIP input for subset by skipping *
 * R. Tian/SAIC		 3/04	Add check for outflg			*
 * R. Tian/SAIC		 5/04	Added call to DG_CONE			*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 * S. Gilbert/NCEP	 5/07	Added maxgrid argument                  *
 ************************************************************************/
{
    char gprj[5], cnum[5];
    float aglt1, agln1, aglt2, agln2, ag1, ag2, ag3, rimn, rjmn, rimx,
        rjmx, rglt[2], rgln[2], tnav[LLNNAV];
    double a, b, c;
    int lmx, mx, my, imn, jmn, imx, jmx, nx, ny, ix1, ix2, nsx, iy1, iy2,
        nsy, n, idx, idy, ichk, iadlx, iadly, iadrx, iadry, kxsg, kysg,
	kxysg, nu, mxnu, imn2, jmn2, imx2, jmx2, iadd, navsz;
    int nc, tobig, autos, angflg, navflg, done, ishf, ier, ierr, iir, i, k;

   /*
    * timing vars
    */
    struct   timeb t_gsgprj1, t_gsgprj2, t_gsgprj3, t_gqgprj1, t_gqgprj2, 
             t_gsgprj4, t_setr, t_gqbnd, t_gskp, t_gtrans1, t_mnav, t_cnav, 
             t_cone, t_current;
/*----------------------------------------------------------------------*/
    *iret = 0;
    _dgsubg.dgsubg = G_TRUE;

    for ( i = 0; i < NGDFLS; i++ ) {
	if ( _nfile.outflg[i] == G_TRUE ) {
	    *iret = -63;
	    return;
	}
    }

    /*
     * Set LMX to maximum allowed threshold for ijskip=yes
     */
    lmx = LLMXTH;

    /*
     * Set the reference grid navigation in GPLT.
     */
    cst_itos ( (int *)(&_dgsubg.refnav[1]), 1, &nc, gprj, &ier );
    cst_rmbl ( gprj, gprj, &nc, &ier );
    mx = G_NINT ( _dgsubg.refnav[4] );
    my = G_NINT ( _dgsubg.refnav[5] );
    agln1 = _dgsubg.refnav[7];
    if ( _dgfile.addcol == G_TRUE ) {
	mx += 1;
	agln2 = _dgsubg.refnav[7];
    } else {
	agln2 = _dgsubg.refnav[9];
    }
    ftime(&t_gsgprj1);
    gsgprj ( gprj, &_dgsubg.refnav[10], &_dgsubg.refnav[11], 
             &_dgsubg.refnav[12], &mx, &my, &_dgsubg.refnav[6],
	     &_dgsubg.refnav[7], &_dgsubg.refnav[8], &agln2, &ier,
	     strlen(gprj) );
    ftime(&t_current);
    if ( ier != 0 ) {
	er_wmsg ( "GEMPLT", &ier, " ", &ierr, strlen("GEMPLT"), strlen(" ") );
	*iret = -37;
	return;
    } else if ( _dgsubg.gwrapg == G_TRUE &&
        ( ! COMPAR ( agln1, agln2 ) && ! COMPAR ( (agln1+360.), agln2 ) ) ) {
	*iret = -38;
	return;
    }

    /*
     * Get the shift for re-arranging any globe wrapping grid.
     * ISHIFT is stored in DGCMN.CMN.
     */
    ftime(&t_setr);
    grc_setr ( &mx, &my, &_dgsubg.ishift, &ier );
    ftime(&t_current);
    if ( ier == -22 ) {
	*iret = -39;
	return;
    } else if ( ier != 0 ) {
	*iret = -43;
	return;
    }
    ftime(&t_gqgprj1);
    gqgprj ( gprj, &ag1, &ag2, &ag3, &mx, &my, &aglt1, &agln1, &aglt2,
             &agln2, &ier, sizeof(gprj) );
    ftime(&t_current);
    gprj[4] = '\0';
    cst_lstr ( gprj, &nc, &ier );
    gprj[nc] = '\0';

    /*
     * Get the grid index bounds for the subset grid.
     */
    ftime(&t_gqbnd);
    gqbnd ( sys_G, &rimn, &rjmn, &rimx, &rjmx, &ier, strlen(sys_D) );
    ftime(&t_current);
    if ( ier != 0 ) {
	er_wmsg ( "GEMPLT", &ier, " ", &ierr, strlen("GEMPLT"), strlen(" ") );
	*iret = -40;
	return;
    }
    imn = (int)rimn;
    jmn = (int)rjmn;
    imx = G_NINT ( rimx + .5 );
    if ( G_DIFFT((float)((int)rimx), rimx, GDIFFD) ) imx = (int)rimx;
    jmx = G_NINT ( rjmx + .5 );
    if ( G_DIFFT((float)((int)rjmx), rjmx, GDIFFD) ) jmx = (int)rjmx;
    if ( imn < 1 ) imn = 1;
    if ( jmn < 1 ) jmn = 1;
    if ( imx > mx ) imx = mx;
    if ( jmx > my ) jmx = my;
    nx = imx - imn + 1;
    ny = jmx - jmn + 1;
    if ( nx * ny > lmx ) {
        tobig = G_TRUE;
    } else {
        tobig = G_FALSE;
    }

    /*
     * Check for subsetting by skipping.
     *
     * The bounds are returned from IN_GSKP as IMISSD if
     * not provided.  The skip value returned is converted
     * to a stride value by adding one, i.e. IDX=1 means
     * no skipping, IDX=2 means skip one point.
     *
     * The mathematical relationship stating that the
     * original number of grid points from IMN to IMX must
     * equal the number of points skipped plus the number
     * kept is this:
     *
     *	    (IMX - IMN + 1) = N + (N - 1) * nskip
     *
     * where N is the number of points remaining after
     * skipping and nskip is the number of points skipped
     * between the points that are kept.
     *
     * This equation appears a number of times in various
     * forms below.
     */
    ftime(&t_gskp);
    in_gskp ( ijskip, &ix1, &ix2, &nsx, &iy1, &iy2, &nsy, &autos, &ier );
    ftime(&t_current);
    if ( ier != 0 ) {
	er_wmsg ( "IN", &ier, " ", &iir, strlen("IN"), strlen(" ") );
	*iret = -40;
	return;
    }
    if ( ix2 > mx ) {
	ier = -49;
	er_wmsg ( "DG", &ier, "I", &iir, strlen("DG"), strlen("I") );
	*iret = -40;
	return;
    } else if ( iy2 > my ) {
	ier = -49;
	er_wmsg ( "DG", &ier, "J", &iir, strlen("DG"), strlen("J") );
	*iret = -40;
	return;
    }
    if ( autos == G_TRUE && tobig == G_TRUE ) {
	a = (double)( lmx - 1 );
	b = (double)( nx + ny - 2 * lmx );
	c = (double)( lmx - nx * ny );
	n = (int)( ( b + sqrt ( b * b - 4. * a * c ) ) / ( 2. * a ) );
	nsx = n + 1;
	nsy = nsx;
	cst_inch ( nsx, cnum, &ier );
	ier = 7;
	er_wmsg ( "DG", &ier, cnum, &iir, strlen("DG"), strlen(cnum) );
    }
    idx = nsx + 1;
    idy = nsy + 1;
    if ( nsx > 0 ) {
	ichk = nx / nsx;
	if ( ichk <= 4 ) {
	    ier = 6;
	    er_wmsg ( "DG", &ier, "I", &iir, strlen("DG"), strlen("I") );
	}
    }
    if ( nsy > 0 ) {
	ichk = ny / nsy;
	if ( ichk <= 4 ) {
	    ier = 6;
	    er_wmsg ( "DG", &ier, "J", &iir, strlen("DG"), strlen("J") );
	}
    }

    /*
     * Extend the grid bounds if possible.
     */
    iadlx = 0;
    iadly = 0;
    iadrx = 0;
    iadry = 0;
    imn2 = imn;
    jmn2 = jmn;
    imx2 = imx;
    jmx2 = jmx;
    iadd = 0;
    done = G_FALSE;
    while ( done == G_FALSE && iadd < 5 ) {
	iadd += 1;
	if ( imn2 > idx ) {
	    imn2 -= idx;
	    iadlx += idx;
	}
	if ( jmn2 > idy ) {
	    jmn2 -= idy;
	    iadly += idy;
	}
	if ( imx2 < ( mx - idx ) ) {
	    imx2 += idx;
	    iadrx += idx;
	}
	if ( jmx2 < ( my - idy ) ) {
	    jmx2 += idy;
	    iadry += idy;
	}
	kxsg = G_NINT ( (float)( imx2 - imn2 + 1 + nsx ) / (float)( 1 + nsx ) );
	kysg = G_NINT ( (float)( jmx2 - jmn2 + 1 + nsy ) / (float)( 1 + nsy ) );
	kxysg = kxsg * kysg;
	if ( (kxysg > *maxgrid) && (*maxgrid != IMISSD) ) {
	    done = G_TRUE;
	    if ( imn != imn2 ) {
		imn = imn2 + idx;
		iadlx -= idx;
	    }
	    if ( jmn != jmn2 ) {
		jmn = jmn2 + idy;
		iadly -= idy;
	    }
	    if ( imx != imx2 ) {
		imx = imx2 - idx;
		iadrx -= idx;
	    }
	    if ( jmx != jmx2 ) {
		jmx = jmx2 - idy;
		iadry -= idy;
	    }
	} else {
	    imn = imn2;
	    jmn = jmn2;
	    imx = imx2;
	    jmx = jmx2;
	}
    }

    /*
     * Adjust extend margins using the stride values.
     */
    iadlx = iadlx / idx;
    iadrx = iadrx / idx;
    iadly = iadly / idy;
    iadry = iadry / idy;

    /*
     * Set the I dimension extraction bounds.  No shifting
     * is done if the user provides these bounds.  No
     * extend region is allowed if user provides bounds.
     */
    ishf = _dgsubg.ishift;
    if ( ix1 > 0 ) {
	_dgsubg.ishift = 0;
	iadlx = 0;
	imn = ix1;
    }
    if ( ix2 > 0 ) {
	_dgsubg.ishift = 0;
	iadrx = 0;
	imx = ix2;
    }
    if ( ishf != _dgsubg.ishift ) {
	if ( ix1 < 0 || ix2 < 0 ) {
	    *iret = -48;
	    return;
	}

	/*
	 * Reset the grid projection in GPLT.
	 */
	mx = G_NINT ( _dgsubg.refnav[4] );
	my = G_NINT ( _dgsubg.refnav[5] );
	agln1 = _dgsubg.refnav[7];
	if ( _dgfile.addcol == G_TRUE ) {
	    mx += 1;
	    agln2 = _dgsubg.refnav[7];
	} else {
	    agln2 = _dgsubg.refnav[9];
	}
    ftime(&t_gsgprj2);
	gsgprj ( gprj, &_dgsubg.refnav[10], &_dgsubg.refnav[11], 
	    &_dgsubg.refnav[12], &mx, &my, &_dgsubg.refnav[6],
	    &_dgsubg.refnav[7], &_dgsubg.refnav[8], &agln2, &ier,
	    strlen(gprj) );
    ftime(&t_current);
    ftime(&t_gqgprj2);
	gqgprj ( gprj, &ag1, &ag2, &ag3, &mx, &my, &aglt1, &agln1, 
	    &aglt2, &agln2, &ier, sizeof(gprj) );
    ftime(&t_current);
    if ( diagClbkPtr != NULL )
	gprj[4] = '\0';
	cst_lstr ( gprj, &nc, &ier );
	gprj[nc] = '\0';
	ierr = 5;
	er_wmsg ( "DG", &ierr, " ", &ier, strlen("DG"), strlen(" ") );
    }

    /*
     * Adjust IMX and IMN for skipping.
     */
    if ( idx > 1 ) {
	nu = G_NINT ( (float)( imx - imn + 1 + nsx ) / (float)( 1 + nsx ) );
	mxnu = nu * ( 1 + nsx ) + imn - 1 - nsx;
	if ( mxnu > ( mx - idx ) && mxnu != ix2 ) {
	    mxnu = mx;
	    imn = mxnu - nu * ( 1 + nsx ) + 1 + nsx;
	    if ( imn < 1 ) {
		/*
		 * Start at 1 when full range is needed.
		 */
		imn = 1;
		nu = ( mxnu - imn + 1 + nsx ) / ( 1 + nsx );
		mxnu = nu * ( 1 + nsx ) + imn - 1 - nsx;
	    }
	}
	imx = mxnu;
	if ( ( ix2 > 0 && imx != ix2 ) || 
	     ( ix1 > 0 && imn != ix1 ) ) {
	    ierr = 4;
	    er_wmsg ( "DG", &ierr, "I", &ier, strlen("DG"), strlen("I") );
	}
    }

    /*
     * Set the J dimension extraction bounds. No extend
     * region is allowed if user provides bounds.
     */
    if ( iy1 > 0 ) {
	iadly = 0;
	jmn = iy1;
    }
    if ( iy2 > 0 ) {
	iadry = 0;
	jmx = iy2;
    }

    /*
     * Adjust JMX and JMN for skipping.
     */
    if ( idy > 1 ) { 
	nu = G_NINT ( (float)( jmx - jmn + 1 + nsy ) / (float)( 1 + nsy ) );
	mxnu = nu * ( 1 + nsy ) + jmn - 1 - nsy;
	if ( mxnu > ( my - idy ) && mxnu != iy2 ) {
	    mxnu = my;
	    jmn = mxnu - nu * ( 1 + nsy ) + 1 + nsy;
	    if ( jmn < 1 ) {
		/*
		 * Start at 1 when full range is needed.
		 */
		jmn = 1;
		nu = ( mxnu - jmn + 1 + nsy ) / ( 1 + nsy );
		mxnu = nu * ( 1 + nsy ) + jmn - 1 - nsy;
	    }
	}
	jmx = mxnu;
	if ( ( iy2 > 0 && jmx != iy2 ) || ( iy1 > 0 && jmn != iy1 ) ) {
	    ierr = 4;
	    er_wmsg ( "DG", &ierr, "J", &ier, strlen("DG"), strlen("J") );
	}
    }

    /*
     * Compute subset grid final dimensions.
     */
    kxsg = ( imx - imn + 1 + nsx ) / ( 1 + nsx );
    kysg = ( jmx - jmn + 1 + nsy ) / ( 1 + nsy );
    if ( kxsg <= 0 || kysg <= 0 ) {
	*iret = -40;
	return;
    }
    kxysg = kxsg * kysg;
	

    /*
     * Set common block subset coordinates on reference grid.
     */
    _dgsubg.jsgxmn = imn;
    _dgsubg.jsgymn = jmn;
    _dgsubg.jsgxmx = imx;
    _dgsubg.jsgymx = jmx;
    _dgsubg.jsgxsk = idx;
    _dgsubg.jsgysk = idy;

    /*
     * Set DG_HILO area bounds on subset grid.
     */
    _dgarea.kgxmin = iadlx + 1;
    _dgarea.kgymin = iadly + 1;
    _dgarea.kgxmax = kxsg - iadrx;
    _dgarea.kgymax = kysg - iadry;

    /*
     * Strict map bounds are same as above.
     */
    *imll = _dgarea.kgxmin;
    *jmll = _dgarea.kgymin;
    *imur = _dgarea.kgxmax;
    *jmur = _dgarea.kgymax;

    /*
     * Set the DGAREA common grid bounds calculation flag.
     */
    _dgarea.jgxmin = 1;
    _dgarea.jgxmax = kxsg;
    _dgarea.jgymin = 1;
    _dgarea.jgymax = kysg;
    _dgarea.ksub1 = 1;
    _dgarea.ksub2 = kxysg;

    /*
     * Compute grid size and maximum number of internal grids
     * for the common block.
     */
    if ( (kxysg > *maxgrid) && (*maxgrid != IMISSD) ) {
	/*
	 * Here is the future location to set up some other
	 * remapping.
	 */
	*iret = -41;
	return;
    }

    _dgfile.kxd = kxsg;
    _dgfile.kyd = kysg;
    _dgfile.kxyd = kxysg;
    _dggrid.maxdgg = NDGRD;

    /*
     * Compute the navigation of the internal (subset) grid.
     */
    strcpy ( _dgfile.cprj, gprj );
    rglt[0] = _dgsubg.jsgxmn;
    rgln[0] = _dgsubg.jsgymn;
    rglt[1] = _dgsubg.jsgxmx;
    rgln[1] = _dgsubg.jsgymx;
    nc = 2;
    ftime(&t_gtrans1);
    gtrans ( sys_G, sys_M, &nc, rglt, rgln, rglt, rgln, &ier,
        strlen(sys_G), strlen(sys_M) );
    ftime(&t_current);
    if ( G_ABS ( rgln[0] - 180. ) < .01 || G_ABS ( rgln[0] + 180. ) < .01 )
        rgln[0] = -180.;
    if ( G_ABS ( rgln[1] - 180. ) < .01 || G_ABS ( rgln[1] + 180. ) < .01 )
        rgln[0] = 180.;
    if ( G_ABS ( rgln[0] - rgln[1]) < 0.01 )
        rgln[1] = rgln[0];
    ftime(&t_gsgprj3);
    gsgprj ( _dgfile.cprj, &ag1, &ag2, &ag3, &_dgfile.kxd, &_dgfile.kyd, 
        &rglt[0], &rgln[0], &rglt[1], &rgln[1], &ier, strlen(_dgfile.cprj) );
    ftime(&t_current);
    if ( ier != 0 ) {
	if ( _dgsubg.gwrapg == G_TRUE) {
	    ag2 += 180.;
	    if ( ag2 >= 360. ) ag2 -= 360.;
    ftime(&t_gsgprj4);
	    gsgprj ( _dgfile.cprj, &ag1, &ag2, &ag3, &_dgfile.kxd, &_dgfile.kyd,
		&rglt[0], &rgln[0], &rglt[1], &rgln[1], &ier,
		strlen(_dgfile.cprj) ) ;
    ftime(&t_current);
	if ( ier != 0 ) {
		*iret = -44;
		return;
	    }
	} else {
	    *iret = -44;
	    return;
	}
    }
    angflg = G_TRUE;
    ftime(&t_mnav);
    grc_mnav ( _dgfile.cprj, &_dgfile.kxd, &_dgfile.kyd, &rglt[0], &rgln[0],
	&rglt[1], &rgln[1], &ag1, &ag2, &ag3, &angflg, tnav, &ier );
    ftime(&t_current);

    /*
     * Check the current navigation against the saved navigation.
     * If they are different, then set the navigation flag to False.
     */
    navsz = LLNNAV;
    ftime(&t_cnav);
    grc_cnav ( tnav, _dgfile.snav, &navsz, &navflg, &ier );
    ftime(&t_current);

    /*
     * Save the current navigation.
     */
    for ( k = 0; k < LLNNAV; k++ ) {
	_dgfile.snav[k] = tnav[k];
    }

    db_retsubgcrs (_dgfile.cprj, _dgfile.kxd, _dgfile.kyd, rglt[0], rgln[0],
                       rglt[1], rgln[1],ag1, ag2, ag3,&ier); 
    /*
     * Set the constant of the cone for various projections (code
     * duplicated from UPDCON.FOR in GEMPLT).
     */
    _dgfile.anglr1 = ag1 * DTR;
    _dgfile.anglr2 = ag2 * DTR;
    _dgfile.anglr3 = ag3 * DTR;
    ftime(&t_cone);
    dg_cone ( _dgfile.cprj, &_dgfile.anglr1, &_dgfile.anglr3,
    	      &_dgfile.concon, iret );
    ftime(&t_current);

    /*
     * Set lat/lon,  map scale factor, and rotation matrix
     * internal grid pointers to zero.
     */
    _dgfile.idglat = 0;
    _dgfile.idglon = 0;
    _mapscl.ixmscl = 0;
    _mapscl.iymscl = 0;
    _mapscl.ixmsdy = 0;
    _mapscl.iymsdx = 0;
    _dgrtwd.irtcos = 0;
    _dgrtwd.irtsin = 0;
    _dglndc.lndsea = 0;

    /*
     * Initialize orientation angle.
     */
    _dgovec.ornang = RMISSD;

    /*
     * Free all existing grids since navigation is changed.
     */
    if ( navflg == G_FALSE ) {
        dg_fall ( &ier );
    }

    /*
     * Initialize the origin for M calculation.
     */
    _dgorig.orglat = RMISSD;
    _dgorig.orglon = RMISSD;
    _dgorig.orgxpt = RMISSD;
    _dgorig.orgypt = RMISSD;

    /*
     * Since there were no errors, set flag saying dg package has
     * been initialized.
     */
    _dgfile.dgset = G_TRUE;

    /*
     * Initialize the pointer in the internal grid arrays.
     */
    _dggrid.idglst = 0;

    return;
}
Example #17
0
void dg_adcl ( int *iret )
/************************************************************************
 * dg_adcl                                                              *
 *                                                                      *
 * This subroutine adds a column to a grid.                             *
 *                                                                      *
 * dg_adcl ( iret )  				                        *
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret		int		Return code                     *
 *                                        0 = normal return             *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC         10/03                                           *
 * K. Brill/HPC		 2/04	Initialize gwrapg and addcol		*
 * R. Tian/SAIC		 5/04	Removed check for addcol		*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 * K. Brill/HPC         11/11   Remove check for exceeding LLMXTG	*
 ************************************************************************/
{
    float rgx[2], rgy[2];
    int np, ier, ier2;
/*----------------------------------------------------------------------*/
    *iret   = 0;

    _dgsubg.gwrapg = G_FALSE;
    _dgfile.addcol = G_FALSE;
    grc_rnav ( _dgsubg.refnav, _dgfile.cprj, &_dgfile.kxd, &_dgfile.kyd, &ier );
    if ( ( strcmp ( _dgfile.cprj, "MER" ) == 0 ) || 
         ( strcmp ( _dgfile.cprj, "CED" ) == 0 ) ) {
/*	if ( ( _dgfile.kyd * (_dgfile.kxd+1) ) > LLMXTG ) return; */
	rgx[0] = 1.;
	rgy[0] = 1.;
	rgx[1] = (float)( _dgfile.kxd + 1 );
	rgy[1] = 1.;
	np = 2;
	gtrans ( sys_G, sys_M, &np, rgx, rgy, rgx, rgy, &ier,
	    strlen(sys_G), strlen(sys_M) );
	if ( G_ABS ( rgy[0] - rgy[1] ) < 0.01 ||
	    ( G_ABS ( rgy[0] + 180. ) < 0.01 &&
	      G_ABS ( rgy[1] - 180. ) < 0.01 ) ) {
	    _dgfile.kxd += 1;
	    _dgfile.kxyd = _dgfile.kxd * _dgfile.kyd;
	    _dggrid.maxdgg = NDGRD;
	    gsgprj ( _dgfile.cprj, &_dgsubg.refnav[10], &_dgsubg.refnav[11], 
	        &_dgsubg.refnav[12], &_dgfile.kxd, &_dgfile.kyd,
		&_dgsubg.refnav[6], &_dgsubg.refnav[7], &_dgsubg.refnav[8],
		&_dgsubg.refnav[7], &ier, strlen(_dgfile.cprj) );
	    if ( ier != 0 ) {
		er_wmsg ( "GEMPLT", &ier, " ", &ier2,
		    strlen("GEMPLT"), strlen(" ") );
		*iret = -7;
	    }
	    _dgfile.addcol = G_TRUE;

	    /*
	     * Free all existing grids since grid size is changed.
	     */
	    dg_fall ( &ier );
	}
    } else {
	_dgfile.addcol = G_FALSE;
    }

    if ( ( strcmp ( _dgfile.cprj, "MER" ) == 0 ) ||
         ( strcmp ( _dgfile.cprj, "MCD" ) == 0 ) ||
    	 ( strcmp ( _dgfile.cprj, "CED" ) == 0 ) ) {
	/*
	 * Set GWRAPG flag for globe wrapping grid.
	 */
	rgx[0] = 1.;
	rgy[0] = 1.;
	rgx[1] = (float)_dgfile.kxd;
	rgy[1] = 1.;
	np = 2;
	gtrans ( sys_G, sys_M, &np, rgx, rgy, rgx, rgy, &ier,
	    strlen(sys_G), strlen(sys_M) );
	if ( G_ABS ( rgy[0] - rgy[1] ) < 0.01 ||
	    ( G_ABS ( rgy[0] + 180. ) < 0.01 &&
	      G_ABS ( rgy[1] - 180. ) < 0.01 ) ) {
	    _dgsubg.gwrapg = G_TRUE;
	}
    }

    return;
}
Example #18
0
void radar_bounds(int *istnm, int *kx, int *ky, int *iret)
{
char gsys[]="G";
int i;
char msys[]="L";
int np=4;
float xin[4], yin[4], xout[4], yout[4];
float mnx,mxx,mny,mxy;

*iret = 0;

/*
 * See if this station is already been used.
 */
for(i=0;i<numstats;i++)
   {
   if(*istnm == stnums[i])
      {
      if(gbounds[i][0] == RMISSD) *iret = -1;
      XL = gbounds[i][0]; YB = gbounds[i][1]; XR = gbounds[i][2]; YT = gbounds[i][3];
      return;
      }
   }

/*
 * Get the grid point locations of the 4 corners of the image.
 * If any portion of the image lies within the grid, store
 * the grid point boundaries.
 */
xin[0] = imleft; yin[0] = imbot;
xin[1] = imrght; yin[1] = imbot;
xin[2] = imleft; yin[2] = imtop;
xin[3] = imrght; yin[3] = imtop;
gtrans(msys, gsys, &np, xin, yin, xout, yout, iret, strlen(gsys), strlen(msys));

if(*iret == 0)
   {
   mnx = RMISSD; mny = RMISSD; mxy = RMISSD; mxx = RMISSD;
   for(i=0;i<np;i++)
      {
      if((xout[i] < mnx)||(mnx == RMISSD)) mnx = xout[i];
      if((xout[i] > mxx)||(mxx == RMISSD)) mxx = xout[i];
      if((yout[i] < mny)||(mny == RMISSD)) mny = yout[i];
      if((yout[i] > mxy)||(mxy == RMISSD)) mxy = yout[i];
      }

   if((mxx < 0)||(mnx > (*kx+1))||
      (mxy < 0)||(mny > (*ky+1)))
      {
      XL = XR = YB = YT = RMISSD;
      *iret = -1;
      }
   else
      {
      if(mnx < 1)
         XL = 1;
      else
         XL = floor(mnx);
      if(mxx > *kx)
         XR = *kx;
      else
         XR = ceil(mxx);
      if(mny < 1)
         YB = 1;
      else
         YB = floor(mny);
      if(mxy > *ky)
         YT = *ky;
      else
         YT = ceil(mxy);
      }
   }
else
   {
   /* *iret != 0 */
   XL = XR = YB = YT = RMISSD;
   }
   
gbounds[numstats][0] = XL;
gbounds[numstats][1] = YB;
gbounds[numstats][2] = XR;
gbounds[numstats][3] = YT;
   
stnums[numstats] = *istnm;
numstats++;

}
Example #19
0
void clip_line ( int npoly, float *px, float *py, int npts, float *plat,
                 float *plon, int closed, int maxpts,
                 int *ninout, float *xinout, float *yinout, int *inout,
                 int *iret )
/************************************************************************
 * clip_line								*
 *									*
 * This program clips a single line against a single polygon.		*
 *                                                                      *
 * clip_line( npoly, px, py, npts, plat, plon, closed, maxpts, ninout, 	*
 *				xinout, yinout, inout, iret )		*
 *                                                                      *
 * Input parameters:                                                    *
 *  npoly	int	number of points in clipping polygon		*
 *  *px		float	array of x-coords in clipping polygon		*
 *  *py		float	array of y-coords in clipping polygon		*
 *  npts	int	number of points in line to be clipped		*
 *  *plat	float	array of latitudes in line to be clipped        *
 *  *plon	float	array of longitudes in line to be clipped       *
 *  closed	int	flag indicating if line is closed or not	*
 *  maxpts	int	maximum number of points returned		*
 *                                                                      *
 * Output parameters:                                                   *
 *  *ninout	int	number of returned points			*
 *  *xinout	float	array of x points				*
 *  *yinout	float	array of y points				*
 *  *inout	int	array of indicators as to in or out		*
 *  *iret	int	Return code					*
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * D.W.Plummer/NCEP	 3/02						*
 * X.Guo/CWS		10/10 	Missed calculating some intersection pts*
 *                              between line and polygon                *
 ***********************************************************************/
{
    int	ii, jj, kk, ll, nint, ier;
    int	intrsct, tinout[LLMXPT];
    float	xint, yint, temp;
    float	fxint[LLMXPT], fyint[LLMXPT], dist[LLMXPT];
    float	Nplat[LLMXPT], Nplon[LLMXPT], Npx[LLMXPT], Npy[LLMXPT];
    float   x11[2], y11[2];
    /*---------------------------------------------------------------------*/

    *iret = 0;

    cgr_inpoly ( "M", &npts, plat, plon, "M", &npoly, px, py, tinout, &ier );

    gtrans ( sys_M, sys_N, &npts, plat, plon, Nplat, Nplon, &ier,
             strlen(sys_N), strlen(sys_N) );
    gtrans ( sys_M, sys_N, &npoly, px, px, Npx, Npy, &ier,
             strlen(sys_N), strlen(sys_N) );

    *ninout = 0;
    for ( ii = 0; ii < npts-1; ii++ )  {
        xinout[*ninout] = plat[ii];
        yinout[*ninout] = plon[ii];
        inout[*ninout] = tinout[ii];
        (*ninout)++;
        nint = 0;
        for ( jj = 0; jj < npoly; jj++ )  {
            if ( jj == npoly - 1 ) {
                x11[0] = px[jj];
                x11[1] = px[0];
                y11[0] = py[jj];
                y11[1] = py[0];
            }
            else {
                x11[0] = px[jj];
                x11[1] = px[jj+1];
                y11[0] = py[jj];
                y11[1] = py[jj+1];
            }
            cgr_segint ( sys_M, &(plat[ii%npts]), &(plon[ii%npts]),
                         sys_M, x11, y11,
                         sys_M, &xint, &yint, &intrsct, &ier );
            if ( intrsct == G_TRUE )  {
                fxint[nint] = xint;
                fyint[nint] = yint;
                nint++;
            }
        }
        if ( nint > 0 )  {
            clo_dist ( &(plat[ii]), &(plon[ii]), &nint, fxint, fyint,
                       dist, &ier );
            for ( kk = 0; kk < nint-1; kk++ )  {
                for ( ll = 0; ll < nint-kk-1; ll++ )  {
                    if ( dist[ll] > dist[ll+1] )  {
                        temp = fxint[ll];
                        fxint[ll] = fxint[ll+1];
                        fxint[ll+1] = temp;
                        temp = fyint[ll];
                        fyint[ll] = fyint[ll+1];
                        fyint[ll+1] = temp;
                        temp = dist[ll];
                        dist[ll] = dist[ll+1];
                        dist[ll+1] = temp;
                    }
                }
            }
            for ( kk = 0; kk < nint; kk++ )  {
                xinout[*ninout] = fxint[kk];
                yinout[*ninout] = fyint[kk];
                inout[*ninout] = inout[(*ninout)-1];
                (*ninout)++;
                xinout[*ninout] = fxint[kk];
                yinout[*ninout] = fyint[kk];
                if ( inout[(*ninout)-1] == 0 )  inout[*ninout] = 1;
                if ( inout[(*ninout)-1] == 1 )  inout[*ninout] = 0;
                (*ninout)++;
            }
        }
    }
    xinout[*ninout] = plat[npts-1];
    yinout[*ninout] = plon[npts-1];
    inout[*ninout] = tinout[npts-1];
    (*ninout)++;
}
Example #20
0
/* ARGSUSED */
static void _pgmvcp_elDropEh ( Widget w, XtPointer clnt, XEvent *event,
							Boolean *ctdr )
/************************************************************************
 * _pgmvcp_elDropEh                                                     *
 *                                                                      *
 * This function is the callback for a drop on a selected element.      *
 *                                                                      *
 * static void _pgmvcp_elDropEh (w, clnt, event, ctdr)			*
 *                                                                      *
 * Input parameters:                                                    *
 *      w               Widget          Parent widget                   *
 *      clnt		XtPointer       State information record        *
 *      *event          XEvent          Button press event record       *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * E. Safford/GSC       06/97   Modified to handle Special Text         *
 * E. Wehner/EAi        07/97   Remove offsets when replacing text.     *
 * E. Safford/GSC       07/97   Fixed drag with special text problem    *
 * E. Wehner/EAi        08/97   Remove watch box slide                  *
 * C. Lin/EAI            8/97   Add offsets for 'S' coord(roam)         *
 * D.W.Plummer/NCEP      9/97   Combine into NxmDraw for new vgstruct.h *
 * E. Wehner/EAi         9/97   Remove graphics info record             *
 * C. Lin/EAi           10/97   rename from NxmDrSlDropCb, cleanup      *
 * C. Lin/EAi           10/97   add WBOX_ELEM related functions         *
 * C. Lin/EAi           11/97   further cleanup                         *
 * E. Safford/GSC       02/98   add _storedEl for undo function         *
 * S. Law/GSC           04/98   added copy function                     *
 * E. Safford/GSC       04/98   added FUNC_SELECT to FUNC_MOVE ops      *
 * S. Law/GSC           05/98   cleaned up drag, added group box        *
 * E. Safford/GSC       05/98   mod for new undo routines               *
 * E. Safford/GSC       05/98   move to nmap_pgmvcp.c                   *
 * E. Safford/GSC       06/98   split from mvcpDrop.c                   *
 * G. Krueger/EAI       06/98   Uniform status hints                    *
 * E. Safford/GSC       07/98   reset _dcN for closed figures           *
 * C. Lin/EAI       	08/98   fix ghosting problem & reset _dragCount *
 * G. Krueger/EAI	09/98	Added ghost veiling			*
 * G. Krueger/EAI	10/98	Using table for hints			*
 * E. Safford/GSC	12/98	modify refresh to limit area affected	*
 * D.W.Plummer/NCEP	 4/99	remove call to pgwlst_update		*
 * E. Safford/GSC	11/00	wipe the county list for watches     	*
 * H. Zeng/EAI          11/00   changed for the new undo design         *
 * H. Zeng/EAI          11/00   changed cvg_rdrec() parameters          *
 * A. Hardy/GSC         11/00   renamed coordinate system declaration   *
 * H. Zeng/EAI          12/00   modified for multiple undo steps        *
 * J. Wu/SAIC		12/01	add layer in crg_set() call		*
 * J. Wu/SAIC		01/02	add layer in crg_get() call		*
 * T. Lee/SAIC          11/03   added user directory to work_file       *
 * T. Lee/SAIC		11/03	used cvg_getworkfile			*
 * J. Wu/SAIC		11/03	adjust jet barb/hash position		*
 * J. Wu/SAIC		02/04	adjust gfa attribute box position	*
 * J. Wu/SAIC		07/04	add filter param. to crg_get()		*
 * J. Wu/SAIC		07/04	free GFA block memory			*
 * B. Yin/SAIC		02/05	add a call to snap for GFA		*
 * E. Safford/SAIC	06/05	allow smear to get smaller on edit	*
 * S. Danz/AWC		07/06	Added new cvg_delet placement argument	*
 * S. Danz/AWC          08/06   New flag to pgvgf_saveNewElm to place el*
 * S. Danz/AWC          08/06   Updated to use cvg_checkplace to find   *
 * 				area impacted and call crg_rebuild()    *
 * S. Danz/AWC          02/07   Add logic to update GFA centroid 	*
 * L. Hinson/AWC        07/09   Add code to update CCF centroid         *
 ***********************************************************************/
{
int         location, ier, currfunc, new_location, num, layer, el_layer;
int         found, update_crg, one = 1;
float       llx, lly, urx, ury; 
float       x_cntr, y_cntr, c_lat, c_lon, area;
float       o_llx, o_lly, o_urx, o_ury, inf_bbox[4];
char	    value[32];
VG_DBStruct el, del_el;
filter_t    filter;
/*---------------------------------------------------------------------*/

    _dragCount = 0;
    mcanvw_disarmDrag();
    mcanvw_disarmDrop();

    if ( _wboxElm )  {
	pgwpts_setSnap (TRUE);
	_pgmvcp_wboxCalc ( );
    }

    pggst_clearGhost(TRUE);
    if (!_midDrag)
	return;

    _midDrag = FALSE;

    update_crg = 0;

    currfunc = pgpalw_getCurOperId();

    pgundo_newStep();
    location = pgactv_getElmLoc();
    cvg_rdrec(cvg_getworkfile(), location, &el, &ier);

    crg_getinx (location, &num, &ier);
    crg_get (num, &el_layer, filter, &o_llx, &o_lly, &o_urx, &o_ury, &ier);
    
    pghdlb_deselectEl (location, FALSE); 

    if ((currfunc == FUNC_MOVE) || (currfunc == FUNC_SELECT)) {

/*
 * Mark elements in placement that are effected by
 * the delete, and get the area of influence back
 */
        cvg_rdrec(cvg_getworkfile(), location, &del_el, &ier);
        cvg_checkplace(&del_el, 1, location, &found, inf_bbox, &ier);
        if (found > 0) {

/*
 * Update the refresh extent if the area impacted by
 * placement was bigger than the area passed in
 */
            o_llx = G_MIN(o_llx, inf_bbox[0]);
            o_lly = G_MIN(o_lly, inf_bbox[2]);
            o_urx = G_MAX(o_urx, inf_bbox[1]);
            o_ury = G_MAX(o_ury, inf_bbox[3]);
            update_crg = 1;
        }

/*
 * Free TCA/GFA memory
 */
        if ( del_el.hdr.vg_type == TCA_ELM ) {
            cvg_freeBkpts ( &del_el );
        }
        else if ( del_el.hdr.vg_type == GFA_ELM ) {
            cvg_freeElPtr ( &del_el );
        }

/* 
 *  delete old element
 */  
	cvg_delet (cvg_getworkfile(), location, TRUE, &ier);
	crg_clear (num, &ier);
        pgundo_storeThisLoc(location, UNDO_DEL, &ier);
    }

    if ( el.hdr.vg_type == WBOX_ELM )  {

        pgwbxw_getAnchor ( 0, el.elem.wbx.info.w_a0id,
                        &el.elem.wbx.info.w_a0lt, &el.elem.wbx.info.w_a0ln,
                        &el.elem.wbx.info.w_a0dis, el.elem.wbx.info.w_a0dir,
                        &ier );

        pgwbxw_getAnchor ( 1, el.elem.wbx.info.w_a1id,
                        &el.elem.wbx.info.w_a1lt, &el.elem.wbx.info.w_a1ln,
                        &el.elem.wbx.info.w_a1dis, el.elem.wbx.info.w_a1dir,
                        &ier );

/*
 *  Wipe the county list
 */
 	el.elem.wbx.info.numcnty = 0;
    }

/*
 *  adjust jet barb/hash position accordingly
 */ 
    if ( el.hdr.vg_type == JET_ELM )  {
        _pgmvcp_jetCalc ( &el, 0, 0, False );
    }
     
    if ( el.hdr.vg_type == SIGCCF_ELM ) {
      _pgmvcp_ccfCalc ( &el, 0, 0, False );
      gtrans ( sys_D, sys_M, &_dcN, _dcX, _dcY, 
		 &(el.elem.ccf.latlon[0]), &(el.elem.ccf.latlon[_dcN]), &ier,
		 strlen(sys_D), strlen(sys_M) );
      _dcN = el.elem.ccf.info.npts;
      cvg_todev ( &el, &_dcN, _dcX, _dcY, &ier );
      
      if ( el.hdr.closed ) {
        cgr_centroid ( _dcX, _dcY, &_dcN, &x_cntr, &y_cntr, &area, &ier );
      } else {
        x_cntr = _dcX[0] ;
        y_cntr = _dcY[0] ;
      }
      gtrans( sys_D, sys_M, &one, &x_cntr, &y_cntr, &c_lat, &c_lon, &ier, 
	    strlen(sys_D), strlen(sys_M) 
	    );
      el.elem.ccf.info.arrowlat = c_lat;
      el.elem.ccf.info.arrowlon = c_lon;
    }
/*
 *  adjust GFA attribute box position accordingly
 */ 
    if ( el.hdr.vg_type == GFA_ELM ) {

        _pgmvcp_gfaCalc ( &el, 0, 0, False );

	gtrans ( sys_D, sys_M, &_dcN, _dcX, _dcY, 
		 &(el.elem.gfa.latlon[0]), &(el.elem.gfa.latlon[_dcN]), &ier,
		 strlen(sys_D), strlen(sys_M) );

	pgsmear_snapEl ( FALSE, &el, &ier );

	_dcN = el.elem.gfa.info.npts;

	cvg_todev( &el, &_dcN, _dcX, _dcY, &ier );

	if ( pggfaw_isClosed() ) {
	    cgr_centroid( _dcX, _dcY, &_dcN, &x_cntr, &y_cntr, &area, &ier );
	} else {
	    x_cntr = _dcX[ 0 ];
	    y_cntr = _dcY[ 0 ];
	}
	gtrans( sys_D, sys_M, &one, &x_cntr, &y_cntr, &c_lat, &c_lon, &ier, 
	    strlen(sys_D), strlen(sys_M) 
	    );

	sprintf ( value, "%7.2f", c_lat );
	cvg_setFld ( &el, TAG_GFA_ARROW_LAT, value, &ier );
	sprintf ( value, "%7.2f", c_lon );
	cvg_setFld ( &el, TAG_GFA_ARROW_LON, value, &ier );
    }
    
/*
 *  save new element
 */
    pgvgf_saveNewElm(NULL, sys_D, &el, _dcN, _dcX, _dcY, FALSE, 
    		&new_location, &ier);
    pgundo_storeThisLoc (new_location, UNDO_ADD, &ier);
    pgundo_endStep();
    
/*
 * Free TCA/GFA memory
 */
    if ( el.hdr.vg_type == TCA_ELM ) {
            cvg_freeBkpts ( &el );
    }
    else if ( el.hdr.vg_type == GFA_ELM ) {
        cvg_freeElPtr ( &el );
    }

    cvg_rdrec(cvg_getworkfile(), new_location, &el, &ier);
    layer = pglayer_getCurLayer( );
    crg_set (&el, new_location, layer, &ier);
    pgactv_setActvElm (&el, new_location);

    crg_getinx (new_location, &num, &ier);
    crg_get(num, &el_layer, filter, &llx, &lly, &urx, &ury, &ier);

    if (o_llx < llx)
        llx = o_llx;
    if (o_lly < lly)
        lly = o_lly;
    if (o_urx > urx)
        urx = o_urx;
    if (o_ury > ury)
        ury = o_ury;

/*
 * Mark elements in placement that are effected by
 * the new element, and get the area of influence back
 */
    cvg_checkplace(&el, 0, new_location, &found, inf_bbox, &ier);
    if (found > 0) {

/*
 * Update the refresh extent if the area impacted by
 * placement was bigger than the area passed in
 */
        llx = G_MIN(llx, inf_bbox[0]);
        lly = G_MIN(lly, inf_bbox[2]);
        urx = G_MAX(urx, inf_bbox[1]);
        ury = G_MAX(ury, inf_bbox[3]);
        update_crg = 1;
    }

    xpgpaste (llx, lly, urx, ury, &ier);
    cvg_rfrsh (NULL, llx, lly, urx, ury, &ier);

/*
 * If we may have impacted other elements with placement
 * we will need to rebuild the range records
 */
    if (update_crg) {
        crg_rebuild();
    }

    pghdlb_select (&el, new_location);

/*
 * Free TCA/GFA memory
 */
    if ( el.hdr.vg_type == TCA_ELM ) {
            cvg_freeBkpts ( &el );
    }
    else if ( el.hdr.vg_type == GFA_ELM ) {
        cvg_freeElPtr ( &el );
    }

    mbotw_mouseSet(LMHINT_DRAG, MMHINT_DONE);
}
Example #21
0
void crg_setsigmet ( VG_DBStruct *el, int joffset, int elnum, int *iret )
/************************************************************************
 * crg_setsigmet                                                        *
 *                                                                      *
 * This function sets the range for a sigmet element.			*
 *                                                                      *
 * crg_setsigmet ( el, joffset, elnum, iret ) 				*
 *                                                                      *
 * Input parameters:                                                    *
 *	*el		VG_DBStruct	Element containing circle	*
 * 	joffset		int		File position of the element	*
 *	elnum		int		Element number			*
 *									*
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 **                                                                     *
 * Log:                                                                 *
 * H. Zeng/EAI          07/02   initial coding                          *
 * H. Zeng/EAI          07/02   modified for very large iso. SIGMET     *
 ***********************************************************************/
{
    float	llx, lly, urx, ury, ccx, ccy, dist, ang1, ang2;
    float       new_llx, new_lly, new_urx, new_ury, new_ccx, new_ccy;
    float	lat[MAX_SIGMET*2+3], lon[MAX_SIGMET*2+3];
    float	s1lat[2], s1lon[2], s2lat[2], s2lon[2];
    float	x1[2], y1[2], x2[2], y2[2];
    float	xint, yint, new_dist;
    float	dirs[]= { 0.0F, 180.0F, 90.0F, 270.0F };
    int 	ii, kk, ier, np, npx, vg_subtype, two, intrsct;
    SigmetType  *psig;
    /*---------------------------------------------------------------------*/

    *iret = 0;

    psig       = &(el->elem.sig);
    vg_subtype = psig->info.subtype;
    np         = psig->info.npts;
    dist       = psig->info.distance * NM2M;

    /*
     *  get bounds
     */
    crg_gbnd (sys_M, sys_D, np, &(psig->latlon[0]),
              &(psig->latlon[np]), &llx, &lly, &urx, &ury,
              &ccx, &ccy);


    /*
     * For line or isolated SIGMET, range should be expanded
     * because of the distance.
     */
    if ( vg_subtype == SIGTYP_ISOL && !G_DIFFT(dist, 0.0F, GDIFFD) ) {

        npx = 4;
        for ( ii = 0; ii < npx; ii++ ) {
            clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]),
                        &dist, &(dirs[ii]), &(lat[ii]), &(lon[ii]), &ier );

        }
        crg_gbnd (sys_M, sys_D, npx, &(lat[0]), &(lon[0]),
                  &new_llx, &new_lly, &new_urx, &new_ury,
                  &new_ccx, &new_ccy );

        /*
         * Calculate the distance between (new_ccx, new_ccy) and
         * (new_llx, new_lly).
         */
        new_dist = (float)sqrt( (double)((new_ccx - new_llx) * (new_ccx - new_llx)
                                         + (new_ccy - new_lly) * (new_ccy - new_lly) ) );

        /*
         * modify the range according to new_dist.
         */
        llx = new_ccx - new_dist;
        urx = new_ccx + new_dist;
        ury = new_ccy + new_dist;
        lly = new_ccy - new_dist;

    }
    else if ( vg_subtype == SIGTYP_LINE && !G_DIFFT(dist, 0.0F, GDIFFD) ) {

        switch ( psig->info.sol )  {

        case    SIGLINE_NOF:
        case    SIGLINE_SOF:
        case    SIGLINE_EOF:
        case    SIGLINE_WOF:

            npx = 0;
            for ( ii = 0; ii < np; ii++ )  {
                clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[ii+np]),
                            &dist, &(dirs[psig->info.sol-1]),
                            &(lat[npx]), &(lon[npx]), &ier );
                npx++;
            }
            crg_gbnd (sys_M, sys_D, npx, &(lat[0]), &(lon[0]),
                      &new_llx, &new_lly, &new_urx, &new_ury,
                      &new_ccx, &new_ccy );

            break;

        case    SIGLINE_ESOL:

            lat[0] = psig->latlon[0];
            lon[0] = psig->latlon[np];

            clo_direct ( &(psig->latlon[1]), &(psig->latlon[np+1]),
                         &(psig->latlon[0]), &(psig->latlon[np  ]),
                         &ang1, &ier );

            ang1 -= 90.0F;
            clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]), &dist,
                        &ang1, &(lat[2*np+1]), &(lon[2*np+1]), &ier );
            ang1 = ang1 - 180.0F;
            clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]), &dist,
                        &ang1, &(lat[1]), &(lon[1]), &ier );

            ang2 = ang1;

            two = 2;
            for ( ii = 1; ii < np-1; ii++ )  {

                clo_direct ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]),
                             &(psig->latlon[ii]), &(psig->latlon[np+ii]),
                             &ang1, &ier );
                ang1 = (float)fmod ( ((double)ang1+270.0), 360.0);
                clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]),
                            &dist, &ang1, &(s1lat[1]), &(s1lon[1]), &ier );
                clo_direct ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]),
                             &(psig->latlon[ii]), &(psig->latlon[np+ii]),
                             &ang2, &ier );
                ang2 = (float)fmod ( ((double)ang2+90.0), 360.0);
                clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]),
                            &dist, &ang2, &(s2lat[0]), &(s2lon[0]), &ier );

                if ( G_ABS(ang1-ang2) > 1.F )  {

                    clo_dltln ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]),
                                &dist, &ang1, &(s1lat[0]), &(s1lon[0]), &ier );
                    clo_dltln ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]),
                                &dist, &ang2, &(s2lat[1]), &(s2lon[1]), &ier );

                    gtrans ( sys_M, sys_N, &two, s1lat, s1lon, x1, y1,
                             &ier, strlen(sys_M), strlen(sys_N) );
                    gtrans ( sys_M, sys_N, &two, s2lat, s2lon, x2, y2,
                             &ier, strlen(sys_M), strlen(sys_N) );
                    cgr_segint( sys_N, x1, y1, sys_N, x2, y2,
                                sys_M, &xint, &yint, &intrsct, &ier );

                }
                else  {

                    xint = (s1lat[1] + s2lat[0]) / 2.0F;
                    yint = (s1lon[1] + s2lon[0]) / 2.0F;

                }

                kk = ii + 1;
                lat[kk] = xint;
                lon[kk] = yint;

                ang1 = (float)fmod ( ((double)ang1+180.0), 360.0 );
                ang2 = (float)fmod ( ((double)ang2+180.0), 360.0 );

                clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]),
                            &dist, &ang1, &(s1lat[1]), &(s1lon[1]), &ier );
                clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]),
                            &dist, &ang2, &(s2lat[0]), &(s2lon[0]), &ier );

                if ( G_ABS(ang1-ang2) > 1.F )  {

                    clo_dltln ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]),
                                &dist, &ang1, &(s1lat[0]), &(s1lon[0]), &ier );
                    clo_dltln ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]),
                                &dist, &ang2, &(s2lat[1]), &(s2lon[1]), &ier );

                    gtrans ( sys_M, sys_N, &two, s1lat, s1lon, x1, y1,
                             &ier, strlen(sys_M), strlen(sys_N) );
                    gtrans ( sys_M, sys_N, &two, s2lat, s2lon, x2, y2,
                             &ier, strlen(sys_M), strlen(sys_N) );
                    cgr_segint( sys_N, x1, y1, sys_N, x2, y2,
                                sys_M, &xint, &yint, &intrsct, &ier );

                }
                else  {

                    xint = (s1lat[1] + s2lat[0]) / 2.0F;
                    yint = (s1lon[1] + s2lon[0]) / 2.0F;

                }

                kk = 2*np - ii + 1;
                lat[kk] = xint;
                lon[kk] = yint;

                ang1 = (float)fmod ( ((double)ang1+180.0), 360.0 );
                ang2 = (float)fmod ( ((double)ang2+180.0), 360.0 );

                ang1 = ang2;

            } /* the end of for (... */

            clo_direct ( &(psig->latlon[np-2]), &(psig->latlon[2*np-2]),
                         &(psig->latlon[np-1]), &(psig->latlon[2*np-1]),
                         &ang2, &ier );

            ang2 -= 90.0F;
            clo_dltln ( &(psig->latlon[np-1]), &(psig->latlon[2*np-1]),
                        &dist, &ang2, &(lat[np]), &(lon[np]), &ier );

            ang2 = (float)fmod ( ((double)ang2+180.0), 360.0);
            clo_dltln ( &(psig->latlon[np-1]), &(psig->latlon[2*np-1]),
                        &dist, &ang2, &(lat[np+2]), &(lon[np+2]), &ier );

            lat[np+1] = psig->latlon[np-1];
            lon[np+1] = psig->latlon[2*np-1];

            lat[2*np+2] = lat[0];
            lon[2*np+2] = lon[0];

            npx = 2*np + 3;
            crg_gbnd (sys_M, sys_D, npx, &(lat[0]), &(lon[0]),
                      &new_llx, &new_lly, &new_urx, &new_ury,
                      &new_ccx, &new_ccy );

            break;

        } /* the end of switch ... */

        /*
         * compare two set of ranges and get the union of them.
         */
        llx = ( llx <= new_llx ) ? llx : new_llx;
        urx = ( urx >= new_urx ) ? urx : new_urx;
        ury = ( ury >= new_ury ) ? ury : new_ury;
        lly = ( lly <= new_lly ) ? lly : new_lly;

    } /* the end of else if ... */


    llx -= (float)EXTRA_SM;
    urx += (float)EXTRA_SM;
    ury += (float)EXTRA_SM;
    lly -= (float)EXTRA_SM;

    /*
     *  Store the device coordinates in the range array.
     */
    crg_save(elnum, joffset, llx, lly, urx, ury, &ier);


}
Example #22
0
void utf_ptext ( int offflg, int shift_x, int shift_y,
		 unsigned char *endof, int zm, unsigned char *ptr,
		 int *add, int *iret )
/************************************************************************
 * utf_ptext								*
 *									*
 * This function plots both regular and offset text records C5 and C8	*
 * from a UTF file.							*
 *									*
 * utf_ptext ( offflg, shift_x, shift_y, endof, zm, ptr, add, iret )	*
 *									*
 * Input parameters:							*
 *	offflg		int		Offset vs regular text flag	*
 *	shift_x		int		X shift factor			*
 *	shift_y		int		Y shift factor			*
 *	*endof		unsigned char	End of buffer			*
 *	zm		int		Zoom threshold (from user)	*
 *	*ptr		unsigned char	Position in buffer		*
 *									*
 * Output parameters:							*
 *	*add		int		Total number of bytes in record	*
 *	*iret		int		Return code			*
 *									*
 **									*
 * Log:									*
 * D. Keiser/GSC	12/96	Copied from utf_text			*
 * D. Keiser/GSC	 4/97	Corrected turbulence plot		*
 * S. Jacobs/NCEP	 4/97	Removed value from turb sym		*
 * D. Keiser/GSC	 6/97	Initialized txtwid			*
 * S. Jacobs/NCEP	 7/97	Changed font size calculation		*
 * D. Keiser/GSC	 7/97	Increased string sizes			*
 * S. Jacobs/NCEP	 8/97	Corrected PTND symbol numbers		*
 * M. Linda/GSC		10/97	Corrected the prologue format		*
 * S. Jacobs/NCEP	10/97	Changed the calling seq for gstext	*
 * I. Durham/GSC	 5/98	Changed underscore decl. to an include	*
 * S. Jacobs/NCEP	 7/98	Changed the font type and size		*
 * A. Hardy/GSC         11/00   renamed coordinate system declarations	*
 ***********************************************************************/
{
    int 		len, offset, sign, i, j, delx, dely, ixoff, g, b;
    int			iyoff, spcflg, np, ier, rb, ipnt, pltfil, bytadd;
    int			jpnt, zt, zf, chrsiz, txtwid, fntnum, txtflg, nc;
    int 		ipwwid, isktyp, iskwid, iptwid, iwtwid, ictwid;
    int			ispwid, icewid, nchr, textfg, ituwid, numpnt;
    int			idum;
    float 		sf, txtsiz, temp, rotat, rx, ry, szsky, szpwth;
    float		rcode, xl, yb, xr, yt, xl2, yb2, xr2;
    float		yt2, xrat, yrat, rdelx, rdely, szptnd, szwthr;
    float		szctyp, szspcl, szicng, szturb, xin[2], yin[2];
    float 		xout[2], yout[2];
    unsigned char 	string[200], *tmpbuf=NULL, outstr[200];
    char 		newstr[200];

    int gfunc[] = { 0000, GSKY, GSKY, GSKY, GSKY, GSKY, GSPC, GSPC,
   		    0000, 0000, 0000, 0000, 0000, 0000, GSKY, GSKY,
		    GSKY, 0000, 0000, GSKY, GSKY, GSKY, GPTN, GPTN, 
		    GPTN, GPTN, GPTN, GPTN, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GPWX, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GSPC, GSPC, GSPC, GSPC, GSPC, GWTH, GPWX, GWTH,
		    GSPC, GSPC, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH, GWTH,
		    GSPC, GSPC, GSPC, GWTH, GSPC, GSPC, GSPC, GSPC,
		    GWTH, GWTH, GSPC, GSPC, GSPC, GCTP, GCTP, GCTP,
		    GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, 
		    GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, 
		    GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP, GCTP,
		    GSPC, GSPC, GTRB, GTRB, GTRB, GICE, GICE, GICE };

    int gsym[] = { 0, 6, 7, 8, 9, 10, 0, 8,
    		   0, 0, 0, 0, 0, 0, 0, 1,
		   2, 0, 0, 3, 4, 5, 999, 1999,
		   5999, 6999, 3999, 8999, 4, 5, 6, 7,
		   8, 9, 10, 11, 12, 13, 14, 15,
		   16, 9, 18, 19, 50, 60, 70, 68,
		   30, 14, 16, 15, 4, 45, 8, 31,
		   18, 17, 34, 36, 37, 38, 39, 41,
		   44, 48, 49, 52, 56, 57, 66, 67,
		   47, 58, 76, 77, 78, 79, 81, 62,
		   4, 19, 20, 43, 21, 23, 22, 24,
		   97, 72, 12, 13, 29, 11, 12, 13, 
		   14, 15, 16, 17, 18, 19, 1, 2,
		   3, 4, 5, 6, 7, 8, 9, 21,
		   22, 23, 24, 25, 26, 27, 28, 29,
		   25, 26, 2, 4, 6, 3, 5, 8 };

/*---------------------------------------------------------------------*/
    *iret = 0;
    sf = 0.25F;
    temp = 0.8F;
    fntnum = 21;
    txtflg = 2;
    ixoff = 0;
    iyoff = 0;
    rotat = 0.0F;
    delx = 0;
    dely = 0;
    txtwid = 1;

/*
**  Decode the header of the C5 or C8 record.
*/
    utf_dtext( offflg, shift_x, shift_y, zm, endof, ptr, &g, &b, &rb,
	       &zt, &pltfil, &zf, &chrsiz, &ipnt, &jpnt, &len, &bytadd,
	       &ier );
    *add = bytadd;
    ptr += 6;

/*
**  If offset text record C8, decode delta X and delta Y.
*/
    if ( offflg ) {
     	for ( i = 0; i < 2; i++, ptr++ ) {
    	    sign = *ptr & 0x80;
      	    offset = *ptr & 0x7f;
      	    if ( sign != 0 )
            	offset -= 0x80;
      	    if ( i == 0 )
	    	delx = offset << shift_x;
      	    else
	     	dely = offset << shift_y;
    	}
    }

/*
**  Query MAP and DEVICE bounds and compute X and Y ratios that
**  will adjust delta X and delta Y for zooming. Add delta X and 
**  delta Y to I, J.
*/
    gqbnd( sys_M, &xl, &yb, &xr, &yt, &ier, strlen(sys_M) );
    xin[0] = xl;
    xin[1] = xr;
    yin[0] = yb;
    yin[1] = yt;
    numpnt = 2;
    gtrans( sys_M, sys_G, &numpnt, xin, yin, xout, yout, &ier, 
					strlen(sys_M),	strlen(sys_G) );
    gqbnd( sys_D, &xl2, &yb2, &xr2, &yt2, &ier, strlen(sys_D) );
    xrat = (xout[1] - xout[0]) / (xr2 - xl2) / 2.0F;
    yrat = (yout[1] - yout[0]) / (yb2 - yt2) / 2.0F;
    rx = (float) ipnt;
    ry = (float) jpnt; 
    rdelx = (float) delx;
    rdely = (float) dely;
    rx = rx + (rdelx + 3.0F) * xrat;
    ry = ry + (rdely + 15.0F) * yrat;

    spcflg = G_FALSE;
    textfg = G_FALSE;
    nchr = 0;

/*
**  Traverse string of characters, plotting only if plot filter is true.
*/
    while ( (*ptr < 128) && (ptr < endof) ) {
	if ( pltfil ) {

/*
**	    If a cursor moving character is encountered and textfg is
**	    TRUE, build string from buffer and pass into GTEXT to be
**	    plotted.
*/
	    if ( ( *ptr == 18 ) || (( *ptr >= 8 ) && ( *ptr <= 13 ) ) ) {
		if ( textfg ) {
		    j = 0;
		    for ( i = 0; i < nchr; i++, tmpbuf++) {
		    	if ( ( *tmpbuf >= 32 ) && ( *tmpbuf < 127 ) ) {
			    string[j] = *tmpbuf;
			    j++;
			}
		    }
		    string[j] = CHNULL;
		    if  ( chrsiz < 3 )  {
			txtsiz = 1.000F;
		    }
		    else  {
			txtsiz = 1.714F;
		    }
		    idum = 0;
		    gstext( &fntnum, &txtflg, &txtsiz, &txtwid,
			    &idum, &idum, &idum, &ier );
		    cst_unpr( (char *)string, (char *)outstr, &ier );
		    strcpy(newstr, (char *) outstr);
		    cst_lstr( newstr, &nc, &ier );
		    if ( nc > 0 ) {
			gtext( sys_G, &rx, &ry, newstr, &rotat, &ixoff,
			       &iyoff, &ier, strlen(sys_G), 
			       strlen(newstr) );
			ixoff = nc * 3;
		    }
		    textfg = G_FALSE;
		    nchr = 0;
		}

/*
**		Check for special characters and set appropriate GEMPAK
**		offsets.
*/
		switch(*ptr) {

/*
**		    Back space.
*/
		    case 8:
			ixoff -= 2;
			break;

/*
**		    Forward space. 
*/
		    case 9:
			ixoff += 2;
			break;

/*
**		    Down space. 
*/
		    case 10:
			iyoff -= 2;
			break;

/*
**		    Up space. 
*/
		    case 11:
			iyoff += 2; 
			break;

/*
**		    New Line (1.5). 
*/
		    case 12:
			ixoff = 0;
			iyoff -= 3;
			break;

/*
**		    New Line (1.0). 
*/
		    case 13:
			ixoff = 0;
			iyoff -= 2;
			break;

/*
**		    Set special character flag. 
*/
		    case 18:
			spcflg = G_TRUE;	
			break;
		}
	    }

/*
**	    If a reset to regular character mode character is
**	    encountered, set the special character flag back to FALSE.
*/
	    else if ( *ptr == 17 ) {
		spcflg = G_FALSE;
	    }

/*
**	    If a special character is encountered, check it against the
**	    symbol array, and plot it according to which symbol code it
** 	    represents.
*/
	    else {
		if ( spcflg ) {
		    np = 1;
		    switch (gfunc[*ptr]) {
/*
**			Sky cover. 
*/
			case GSKY:
			    isktyp = 0;
			    iskwid = 0;
			    szsky = temp + ((float) chrsiz*sf) - 0.05F;
			    rcode = (float) gsym[*ptr];
			    gssky( &szsky, &isktyp, &iskwid, &ier );
			    gsky( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				  &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Past weather. 
*/
			case GPWX:
			    ipwwid = 0;
			    szpwth = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
		    	    gspwth( &szpwth, &ipwwid, &ier );
		    	    gpwth( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
		    	    break;

/*
**			Pressure tendency. 
*/
			case GPTN:
			    iptwid = 0;
			    szptnd = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
			    gsptnd( &szptnd, &iptwid, &ier );
			    gptnd( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			WMO weather symbols. 
*/
			case GWTH:
			    iwtwid = 0;
			    if ( gsym[*ptr] == 70 || gsym[*ptr] == 72 ) 
				szwthr = temp + ((float) chrsiz*sf) +
								0.5F;
			    else
				szwthr = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
			    gswthr( &szwthr, &iwtwid, &ier );
			    gwthr( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Cloud type. 
*/
			case GCTP:
			    ictwid = 0;
			    szctyp = temp + ((float) chrsiz*sf);
		    	    rcode = (float) gsym[*ptr];
			    gsctyp( &szctyp, &ictwid, &ier );
			    gctyp( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Special symbols. 
*/
			case GSPC:
			    ispwid = 0;
			    if ( gsym[*ptr] == 12 || gsym[*ptr] == 13 )
				szspcl = temp + ((float) chrsiz*sf) -
								0.3F;
			    else if ( gsym[*ptr] == 0 ) 
				szspcl = temp + ((float) chrsiz*sf) -
								0.4F;
			    else
				szspcl = temp + ((float) chrsiz*sf);
			    rcode = (float) gsym[*ptr];
			    gsspcl( &szspcl, &ispwid, &ier );
			    gspcl( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Turbulence. 
*/
			case GTRB:
			    ituwid = 0;
			    szturb = temp + ((float) chrsiz*sf) - 0.5F;
		    	    rcode = (float) gsym[*ptr];
			    gsturb( &szturb, &ituwid, &ier );
			    gturb( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

/*
**			Icing. 
*/
			case GICE:
			    icewid = 0;
			    szicng = temp + ((float) chrsiz*sf) - 0.5F;
		    	    rcode = (float) gsym[*ptr];
			    gsicng( &szicng, &icewid, &ier );
			    gicng( sys_G, &np, &rcode, &rx, &ry, &ixoff,
				   &iyoff, &ier, strlen(sys_G) );
			    break;

		    }
		    ixoff += 2;
		}

/*
**		If textfg is FALSE, place character in buffer to be used
**		in later building the string to plot.
*/
		else {
		    if ( !textfg ) {
			tmpbuf = ptr;
			textfg = G_TRUE;
		    }
		    nchr++;
		}
	    }
	}
    ptr++;
    }

/*
**  Build string from buffer and pass into GTEXT to be plotted.
*/
    if ( textfg ) {
	if ( pltfil ) {
	j = 0;
	for ( i = 0; i < nchr; i++, tmpbuf++) {
	    if ( ( *tmpbuf >= 32 ) && ( *tmpbuf < 127 ) ) {
		string[j] = *tmpbuf;
		j++;
	    }
	}
	string[j] = CHNULL;
	if  ( chrsiz < 3 )  {
	    txtsiz = 1.000F;
	}
	else  {
	    txtsiz = 1.714F;
	}
	idum = 0;
       	gstext( &fntnum, &txtflg, &txtsiz, &txtwid, 
		&idum, &idum, &idum, &ier );
	    cst_unpr( (char *)string, (char *)outstr, &ier );
	    strcpy(newstr, (char *) outstr);
	    cst_lstr( newstr, &nc, &ier );
	    if  ( nc > 0 ) {
		gtext( sys_G, &rx, &ry, newstr, &rotat, &ixoff,
		       &iyoff, &ier, strlen(sys_G), strlen(newstr) );
		ixoff = nc * 3;
	    }
	    textfg = G_FALSE;
	    nchr = 0;
	}
    }
}
Example #23
0
static void _pgmvcp_jetCalc ( VG_DBStruct *el, float dx, float dy, Boolean grp )
/************************************************************************
 * _pgmvcp_wboxCalc                                                     *
 *                                                                      *
 * Internal function for MOVE/COPY jet's barbs/hashs			*
 *                                                                      *
 * static void _pgmvcp_jetCalc ()                  			*
 *      *el               VG_DBStruct	Pointer to jet element		*
 *       dx               float		Increment on X axis		*
 *       dy               float		Increment on Y axis		*
 *       grp              Boolean	Group mode or not		*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * J. Wu/SAIC		11/03	initial coding				*
 ***********************************************************************/
{
    int		ii, np, ier;
    float	delx, dely, xx, yy;
/*---------------------------------------------------------------------*/
/*
 * For group drag/drop, use the given dx, dy as the "delta" increment.
 */    
    delx = dx;
    dely = dy;
    
/*
 * For single element drag/drop, recalculate the "delta" increment. 
 */    
    if ( !grp && _dcN > 0 ) {
        delx = *(_dcX + _nearPt) - _origX;
        dely = *(_dcY + _nearPt) - _origY;
    }
    
/*
 * Adjust barb/hash locations.
 */
    np = 1;
    for ( ii = 0; ii < el->elem.jet.nbarb; ii++ ) {
	gtrans ( sys_M, sys_D, &np,
		 &el->elem.jet.barb[ii].wnd.data.latlon[0],
		 &el->elem.jet.barb[ii].wnd.data.latlon[1],
		 &xx, &yy, &ier, strlen(sys_M), strlen(sys_D) );
        xx += delx;
	yy += dely;
	gtrans ( sys_D, sys_M, &np, &xx, &yy,
		 &el->elem.jet.barb[ii].wnd.data.latlon[0],
		 &el->elem.jet.barb[ii].wnd.data.latlon[1],
		 &ier, strlen(sys_D), strlen(sys_M) );    
    }
    
    for ( ii = 0; ii < el->elem.jet.nhash; ii++ ) {
	gtrans ( sys_M, sys_D, &np,
		 &el->elem.jet.hash[ii].wnd.data.latlon[0],
		 &el->elem.jet.hash[ii].wnd.data.latlon[1],
		 &xx, &yy, &ier, strlen(sys_M), strlen(sys_D) );
        xx += delx;
	yy += dely;
	gtrans ( sys_D, sys_M, &np, &xx, &yy,
		 &el->elem.jet.hash[ii].wnd.data.latlon[0],
		 &el->elem.jet.hash[ii].wnd.data.latlon[1],
		 &ier, strlen(sys_D), strlen(sys_M) );    
    }    
}
Example #24
0
void dg_tadc ( int *iret )
/************************************************************************
 * dg_tadc                                                              *
 *                                                                      *
 * This subroutine determines if an added column is required for the	*
 * transfer navigation.							*
 *                                                                      *
 * This subroutine sets the adcltg and gwrptg flags in the HINTRP block *
 * of DGCMN.CMN								*
 *                                                                      *
 * The transfer navigation is assumed to be set in GPLT.		*
 *                                                                      *
 * dg_tadc ( iret ) 		 		                        *
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret		int		Return code                     *
 *                                        0 = normal return             *
 **                                                                     *
 * Log:                                                                 *
 * K. Brill/HPC		 3/04	Created from DG_ADCL			*
 * R. Tian/SAIC		 2/06	Recoded from Fortran			*
 * K. Brill/HPC         11/11   Remove check for exceeding LLMXTG	*
 ************************************************************************/
{
    char gprj[5];
    float rgx[2], rgy[2];
    int mx, my, two, ier, ier2;
/*----------------------------------------------------------------------*/
    *iret   = 0;
    two = 2;

    _hintrp.gwrptg = G_FALSE;
    _hintrp.adcltg = G_FALSE;
    grc_rnav ( _hintrp.tfrnav, gprj, &mx, &my, &ier );
    if ( strcmp ( gprj, "MER" ) == 0 || strcmp ( gprj, "CED" ) == 0 ) {
/*	if ( ( my * (mx+1) ) > LLMXTG ) return; */
	rgx[0] = 1.;
	rgy[0] = 1.;
	rgx[1] = (float)( mx + 1 );
	rgy[1] = 1.;
	gtrans ( sys_G, sys_M, &two, rgx, rgy, rgx, rgy, &ier,
	         strlen(sys_G), strlen(sys_M) );
	if ( G_ABS ( rgy[0] - rgy[1] ) < 0.005 ||
	    ( G_ABS ( rgy[0] + 180. ) < 0.005 &&
	      G_ABS ( rgy[1] - 180. ) < 0.005 ) ) {
	    mx += 1;
	    gsgprj ( gprj, &_hintrp.tfrnav[10], &_hintrp.tfrnav[11],
		&_hintrp.tfrnav[12], &mx, &my, &_hintrp.tfrnav[6],
		&_hintrp.tfrnav[7], &_hintrp.tfrnav[8], &_hintrp.tfrnav[7],
		&ier, strlen(gprj) );
	    if ( ier != 0 ) {
		er_wmsg ( "GEMPLT", &ier, " ", &ier2,
		    strlen("GEMPLT"), strlen(" " ) );
		*iret = -7;
	    }
	    _hintrp.adcltg = G_TRUE;
	    _hintrp.gwrptg = G_TRUE;
	    return;
	} else {
	    _hintrp.adcltg = G_FALSE;
	}
    }

    if ( ( strcmp ( gprj, "MER" ) == 0 ) || ( strcmp ( gprj, "MCD" ) == 0 ) ||
	 ( strcmp ( gprj, "CED" ) == 0 ) ) {
	/*
	 * Set GWRAPG flag for globe wrapping grid.
	 */
	rgx[0] = 1.;
	rgy[0] = 1.;
	rgx[1] = (float)mx;
	rgy[1] = 1.;
	gtrans ( sys_G, sys_M, &two, rgx, rgy, rgx, rgy, &ier,
	         strlen(sys_G), strlen(sys_M) );
	if ( G_ABS ( rgy[0] - rgy[1] ) < 0.005 ||
	    ( G_ABS ( rgy[0] + 180. ) < 0.005 &&
	      G_ABS ( rgy[1] - 180. ) < 0.005 ) )  _hintrp.gwrptg = G_TRUE;
    }

    return;
}
Example #25
0
void radar_grid(int *prodflg, int *kx, int *ky, float *fdata, float *rlev)
{
char *radarea;
int lens, ier, i, j, np, ip, x, y, it;

char fname[LLMXLN];
char gsys[]="G", msys[]="L";
float xl, yb, xr, yt, rval, rvalmx;
int xstart,xstop,ystart,ystop;
int imode=0, iarea=0, ipix;
static int xcsiz=0;
static float *xin=NULL,*xout=NULL,*yin=NULL, *yout=NULL;

// Allocate memory
if ( xin == NULL ) {
   xin = (float *)malloc(MAXNEX * sizeof(float));
   xout = (float *)malloc(MAXNEX * sizeof(float));
   yin = (float *)malloc(MAXNEX * sizeof(float));
   yout = (float *)malloc(MAXNEX * sizeof(float));
   if(xin == NULL) printf("failed to malloc xin\n");
   if(xout == NULL) printf("failed to malloc xout\n");
   if(yin == NULL) printf("failed to malloc yin\n");
   if(yout == NULL) printf("failed to malloc your\n");
   xcsiz = MAXNEX;
}

xstart = (int)XL; xstop = (int)XR;
ystart = (int)YB; ystop = (int)YT;

// Reallocate memory if new grid size exceeds MAXNEX
if ( ( ( xstop - xstart + 1 ) * ( ystop - ystart + 1 ) ) > xcsiz ) {
   xcsiz = (xstop - xstart + 1)*(ystop - ystart + 1);
   printf("increasing MAXNEX to %d [%d %d %d %d]\n",xcsiz,xstop,xstart,ystop,ystart);
   xin = (float *)realloc(xin, xcsiz*sizeof(float));
   xout = (float *)realloc(xout, xcsiz*sizeof(float));
   yin = (float *)realloc(yin, xcsiz*sizeof(float));
   yout = (float *)realloc(yout, xcsiz*sizeof(float));
   if(xin == NULL) printf("failed to realloc xin\n");
   if(xout == NULL) printf("failed to realloc xout\n");
   if(yin == NULL) printf("failed to realloc yin\n");
   if(yout == NULL) printf("failed to realloc your\n");
}


np = 0;
for ( i=xstart; i<=xstop; i++ )
   for ( j=ystart; j<=ystop; j++ ) {
      xin[np] = i; yin[np] = j;
      np++;
   }

// Convert grid from G to L
gtrans(gsys, msys, &np, xin, yin, xout, yout, &ier, strlen(gsys), strlen(msys));

np = 0;
rvalmx = RMISSD;
for ( i=xstart; i<=xstop; i++ )
   for ( j=ystart; j<=ystop; j++ ) {
      if ( ( xout[np] >= 1 ) && ( xout[np] <= imnpix ) &&
           ( yout[np] >= 1 ) && ( yout[np] <= imnlin ) ) {
         x = (int) rint(xout[np]);
         y = (int) rint(yout[np]);
         it = ((y - 1) * imnpix) + x - 1;
         ip = ((j - 1) * (*kx)) + i - 1;

         // If imgData is between min and max (0 and 16 for 4 bit 0 and 255 for HiRes 8 bit)

         if ( ( imgData[it] >= immnpx ) && ( imgData[it] <= immxpx ) ) {

            // assign rval to level specified by imgData number

            if ( *prodflg > 0) {
		rval = rlev[(int)imgData[it]];
            } else {
            	rval = (int)imgData[it];
            }
            	
	    if ( rval > rvalmx ) {
               rvalmx = rval;
            }

            // if rval is great than existing value, replace

            if ( rval > fdata[ip] ) {
                fdata[ip] = rval;
            }
         } else
            printf("%d %d %d   %d %d %d   %d [%d %d]\n", x,y,np, i,j,ip, imgData[it],immnpx, immxpx);
      }
      np++;
   }

}
Example #26
0
void radar_info(rad_struct RADARS[], int NEXSTNS)
{
int i,j,np=1,iret;
float x,y,sped,drct;
float rotat=0;
float rwmrk, rhmrk, rwtxt, rhtxt, rwbrb, rhbrb;
int ixoff=0,iyoff=0;
char plotstr[8];

float nx[1], ny[1], gx[1], gy[1]; 

char gcord[]="G", ncord[]="N";
char NEstr[] = "NE";
char OMstr[] = "OM";
char NAstr[] = "NA";
cntr_struct *next_cntr;
int *dataptr;

gqsysz ( &rwmrk, &rhmrk, &rwtxt, &rhtxt, &rwbrb, &rhbrb, &iret);

if(radinfo_col > 0) 
   {
   gscolr(&radinfo_col,&iret);
   for(i=0;i<NEXSTNS;i++)
      {
      get_xy(RADARS[i].stnlat,RADARS[i].stnlon,&x,&y);
      if(RADARS[i].mode == MDNE)
         gtext(gcord,&x,&y,NEstr,&rotat,&ixoff,&iyoff,&iret, strlen(gcord),strlen(NEstr));
      else if(RADARS[i].mode == MDOM)
         gtext(gcord,&x,&y,OMstr,&rotat,&ixoff,&iyoff,&iret, strlen(gcord),strlen(OMstr));
      else if(RADARS[i].mode == MDNA)
         gtext(gcord,&x,&y,NAstr,&rotat,&ixoff,&iyoff,&iret, strlen(gcord),strlen(NAstr));
      }
   }

if(cntr_col > 0)
   {
   gscolr(&cntr_col,&iret);
   gsbarb(&cntr_sz,&cntr_wid,&cntr_type,&iret);

   filter_init();

   for(i=0;i<NEXSTNS;i++)
      {
      for(j=0;j<RADARS[i].ncntr;j++)
         {
         get_xy4(RADARS[i].stnlat,RADARS[i].stnlon,RADARS[i].cntr[j].ggg,&x,&y);
         gx[0] = x + .125; gy[0] = y - .125;         
         gtrans ( gcord, ncord, &np, gx, gy, nx, ny, &iret,
            strlen(gcord),strlen(ncord));

	 if((nx[0] >= 0)&&(nx[0] <= 1)&&(ny[0] >= 0)&&(ny[0] <= 1))
	    n_filter (np, nx, ny, rhbrb, rwbrb, cntr_filter, &(RADARS[i].cntr[j]));

         } 
      }

   filter_set_head();
   while(filter_retrieve((void *)(&next_cntr), &x, &y))
      {
      sped = next_cntr->spd;
      drct = next_cntr->dir;
      gbarb(ncord,&np,&x,&y,&sped,&drct,&iret,strlen(ncord));
      } 
   }

if(maxtop_col > 0)
   {
   gscolr(&maxtop_col,&iret);

   filter_init();

   for(i=0;i<NEXSTNS;i++)
      {
      if(RADARS[i].maxtop > 0)
         {
         get_xy4(RADARS[i].stnlat,RADARS[i].stnlon,RADARS[i].maxtop_ggg,&x,&y);

	 gx[0] = x + .125; gy[0] = y - .125;
         gtrans ( gcord, ncord, &np, gx, gy, nx, ny, &iret,
            strlen(gcord),strlen(ncord));
         /* char string is 3 characters */
	 if((nx[0] >= 0)&&(nx[0] <= 1)&&(ny[0] >= 0)&&(ny[0] <= 1))
	    n_filter (np, nx, ny, rhtxt, rwtxt*2.7, maxtop_filter, &(RADARS[i].maxtop) );
         }
      }
   ixoff = 0; iyoff = 0; rotat = 0;
   filter_set_head();
   while(filter_retrieve((void *)(&dataptr), &x, &y))
      {
      sprintf(plotstr,"%03d\0",*dataptr);
      gtextc(ncord,&x,&y,plotstr,&rotat,&ixoff,&iyoff,&iret,
            strlen(ncord),strlen(plotstr));
      }
   }

if(meso_col > 0)
   {
   gscolr(&meso_col,&iret);
   gsmrkr(&meso_mark,&meso_hw,&meso_sz,&meso_wid,&iret);

   filter_init();

   for(i=0;i<NEXSTNS;i++)
      {
      for(j=0;j<RADARS[i].nmeso;j++)
         {
         get_xy4(RADARS[i].stnlat,RADARS[i].stnlon,RADARS[i].meso[j].ggg,&x,&y);

	 gx[0] = x + .125; gy[0] = y - .125;
         gtrans ( gcord, ncord, &np, gx, gy, nx, ny, &iret,
            strlen(gcord),strlen(ncord));
	 if((nx[0] >= 0)&&(nx[0] <= 1)&&(ny[0] >= 0)&&(ny[0] <= 1))
	    n_filter (np, nx, ny, rhmrk, rwmrk, meso_filter, NULL);
         RADARS[i].meso[j].nx = nx[0];
         RADARS[i].meso[j].ny = ny[0];
         }
      }
   filter_set_head();
   while(filter_retrieve((void *)(&dataptr), &x, &y))
      {
      gmark(ncord,&np,&x,&y,&iret,strlen(ncord));
      }
   }

if(tvs_col > 0)
   {
   gscolr(&tvs_col,&iret);
   gsmrkr(&tvs_mark,&tvs_hw,&tvs_sz,&tvs_wid,&iret);

   filter_init();

   for(i=0;i<NEXSTNS;i++)
      {
      for(j=0;j<RADARS[i].ntvs;j++)
         {
         get_xy4(RADARS[i].stnlat,RADARS[i].stnlon,RADARS[i].tvs[j].ggg,&x,&y);
         gx[0] = x + .125; gy[0] = y - .125;
         gtrans ( gcord, ncord, &np, gx, gy, nx, ny, &iret,
            strlen(gcord),strlen(ncord));
	 if((nx[0] >= 0)&&(nx[0] <= 1)&&(ny[0] >= 0)&&(ny[0] <= 1))
            n_filter (np, nx, ny, rhmrk, rwmrk, tvs_filter, NULL);
         RADARS[i].tvs[j].nx = nx[0];
         RADARS[i].tvs[j].ny = ny[0];
         }
      }
   filter_set_head();
   while(filter_retrieve((void *)(&dataptr), &x, &y))
      {
      gmark(ncord,&np,&x,&y,&iret,strlen(ncord));
      }
   }

}
Example #27
0
void cds_sig ( VG_DBStruct *el, int indx, int *iret )
/************************************************************************
 * cds_sig								*
 *									*
 * This function displays SIGMETs to the output device.			*
 *									*
 * cds_sig (el, indx, iret)						*
 *									*
 * Input parameters:							*
 * 	*el		VG_DBStruct	Pointer to VG record structure	*
 *	indx		int		Index into user attribute table *
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *									*
 **									*
 * Log:									*
 * D.W.Plummer/NCEP	 7/99	Copied from cds_line			*
 * D.W.Plummer/NCEP	 9/99	Compute circle from element distance;	*
 *				Compute line extension area		*
 * H. Zeng/EAI           9/99   Preserve plot attributes                *
 * F. J. Yen/NCEP 	10/99   Handled user attribute table            *
 * M. Li/GSC		10/99	Modified clo_direct and clo_dltln codes	*
 * D.W.Plummer/NCEP	12/99	Added plotting of sequence number	*
 * M. Li/GSC		 1/00	Used string variables in gtrans		*
 * S. Law/GSC		05/00	changed to use MAX_SIGMET for lat/lon	*
 * H. Zeng/EAI          06/00   increased the sizes of lat&lon arrays   *
 * A. Hardy/GSC         11/00   renamed coordinate system declarations	*
 * M. Li/SAIC           01/03   delete vgstruct.h                       *
 * T. Piper/SAIC        12/05   redone with new Setting_t structure     *
 ***********************************************************************/
{
    int		ii, kk, npts, np, intrsct, ier;
    int		mtype, color, width, lintyp, lthw, lwhw, mkhw, two;
    int         iltypx, ilthwx, iwidthx, iwhwx, icolrx, imarkx, imkhwx, imkwidx;
    char	str[4];
    float	lat[MAX_SIGMET*2+3], lon[MAX_SIGMET*2+3];
    float	size, dist, dir, ang1, ang2;
    float	dirs[]={ 0.0F, 180.0F, 90.0F, 270.0F };
    float	s1lat[2], s1lon[2], s2lat[2], s2lon[2];
    float	x1[2], y1[2], x2[2], y2[2];
    float	xint, yint;
    float       szmarkx;
    float	lbllat, lbllon, rotat=0.0F;
    int		ixoff=0, iyoff=2;
    int		itxfn_s, itxhw_s, itxwid_s, ibrdr_s, irrotn_s, ijust_s;
    float	sztext_s;
    int		itxfn, itxhw, itxwid, ibrdr, irrotn, ijust;
    float	sztext;
    SigmetType	*psig;
/*---------------------------------------------------------------------*/

    *iret = 0;

    /*
     *  Save plot attributes.
     */
    gqcolr ( &icolrx, &ier );
    gqline ( &iltypx, &ilthwx, &iwidthx, &iwhwx, &ier );
    gqmrkr ( &imarkx, &imkhwx, &szmarkx, &imkwidx, &ier );
   
    /*
     * setup basic information
     */
    psig  = &(el->elem.sig);
    width =  (int) (( (  cdsUattr[indx].info.sig->linwid == 0 ) ?
		(float)psig->info.linwid :
		(float)cdsUattr[indx].info.sig->linwid) * cdsLineWdth);
    lintyp = (  cdsUattr[indx].info.sig->lintyp == 0 ) ?
		psig->info.lintyp : cdsUattr[indx].info.sig->lintyp;

    lthw  = 0;
    lwhw  = 0;
    mtype = 1;
    mkhw  = 0;
    size  = 1.0F;
    np    = psig->info.npts;

    gsline (&lintyp, &lthw, &width, &lwhw, &ier);

    color = (cdsColor == 0) ? 
       	 ( ( cdsUattr[indx].maj_col == 0 ) ?
	     el->hdr.maj_col : cdsUattr[indx].maj_col ) : cdsColor;
    gscolr (&color, &ier);

    switch ( psig->info.subtype )  {

      case	SIGTYP_ISOL:		/* isolated	*/

	/*
	 *  Plot marker w/ surrounding circle
	 */

        lat[0] = psig->latlon[0];
        lon[0] = psig->latlon[np];
        gsmrkr ( &mtype, &mkhw, &size, &width, &ier );
        gmark ( sys_M, &np, lat, lon, &ier, strlen(sys_M) );

	if ( !G_DIFF(psig->info.distance, 0.0F ) )  {

            dir = ( lat[0] >= 0.F ) ? 180.F : 0.F;
	    dist = psig->info.distance * NM2M;
	    clo_dltln ( &lat[0], &lon[0], &dist, &dir, &(lat[1]), &(lon[1]), &ier );
            np = 18;
            gcircl ( sys_M, lat, lon, &(lat[1]), &(lon[1]), &np, 
		     &ier, strlen(sys_M) );

	}

	break;

      case	SIGTYP_LINE:		/* line		*/

	for ( ii = 0; ii < np; ii++ )  {
	    lat[ii] = psig->latlon[ii];
	    lon[ii] = psig->latlon[ii+np];
	}

	gline ( sys_M, &np, lat, lon, &ier, strlen(sys_M) );

	if ( !G_DIFF(psig->info.distance, 0.0F) )  {

	    lintyp = 2;
    	    gsline (&lintyp, &lthw, &width, &lwhw, &ier);

	    dist = psig->info.distance * NM2M;

	    switch ( psig->info.sol )  {

		case	SIGLINE_NOF:
		case	SIGLINE_SOF:
		case	SIGLINE_EOF:
		case	SIGLINE_WOF:

		    npts = 1;
		    for ( ii = 0; ii < np; ii++ )  {
			clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[ii+np]),
				    &dist, &(dirs[psig->info.sol-1]),
				    &(lat[npts]), &(lon[npts]), &ier );
			npts++;
		    }
		    lat[npts] = psig->latlon[np-1];
		    lon[npts] = psig->latlon[2*np-1];
		    npts++;

		    gline ( sys_M, &npts, lat, lon, &ier, strlen(sys_M) );

		break;

		case	SIGLINE_ESOL:

		    lat[0] = psig->latlon[0];
		    lon[0] = psig->latlon[np];

		    clo_direct ( &(psig->latlon[1]), &(psig->latlon[np+1]),
				 &(psig->latlon[0]), &(psig->latlon[np  ]),
				 &ang1, &ier );

		    ang1 -= 90.0F;
		    clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]), &dist, 
				&ang1, &(lat[2*np+1]), &(lon[2*np+1]), &ier );
		    ang1 = ang1 - 180.0F;
		    clo_dltln ( &(psig->latlon[0]), &(psig->latlon[np]), &dist, 
				&ang1, &(lat[1]), &(lon[1]), &ier );

		    ang2 = ang1;

		    two = 2;
		    for ( ii = 1; ii < np-1; ii++ )  {

		     clo_direct ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]),
				  &(psig->latlon[ii]), &(psig->latlon[np+ii]), 
				  &ang1, &ier );
		     ang1 = (float)fmod ( ((double)ang1+270.0), 360.0);
		     clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), 
				 &dist, &ang1, &(s1lat[1]), &(s1lon[1]), &ier );
		     clo_direct ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]),
				  &(psig->latlon[ii]), &(psig->latlon[np+ii]),
				  &ang2, &ier );
		     ang2 = (float)fmod ( ((double)ang2+90.0), 360.0);
		     clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), 
				 &dist, &ang2, &(s2lat[0]), &(s2lon[0]), &ier );

		     if ( G_ABS(ang1-ang2) > 1.F )  {

		       clo_dltln ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]), 
				   &dist, &ang1, &(s1lat[0]), &(s1lon[0]), &ier );
		       clo_dltln ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]), 
				   &dist, &ang2, &(s2lat[1]), &(s2lon[1]), &ier );

		       gtrans ( sys_M, sys_N, &two, s1lat, s1lon, x1, y1, 
		                &ier, strlen(sys_M), strlen(sys_N) );
		       gtrans ( sys_M, sys_N, &two, s2lat, s2lon, x2, y2, 
		                &ier, strlen(sys_M), strlen(sys_N) );
		       cgr_segint( sys_N, x1, y1, sys_N, x2, y2,
			           sys_M, &xint, &yint, &intrsct, &ier );

		     }
		     else  {

		       xint = (s1lat[1] + s2lat[0]) / 2.0F;
		       yint = (s1lon[1] + s2lon[0]) / 2.0F;

		     }

		     kk = ii + 1;
		     lat[kk] = xint;
		     lon[kk] = yint;

		     ang1 = (float)fmod ( ((double)ang1+180.0), 360.0 );
		     ang2 = (float)fmod ( ((double)ang2+180.0), 360.0 );

		     clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), 
				 &dist, &ang1, &(s1lat[1]), &(s1lon[1]), &ier );
		     clo_dltln ( &(psig->latlon[ii]), &(psig->latlon[np+ii]), 
				 &dist, &ang2, &(s2lat[0]), &(s2lon[0]), &ier );

		     if ( G_ABS(ang1-ang2) > 1.F )  {

		       clo_dltln ( &(psig->latlon[ii-1]), &(psig->latlon[np+ii-1]), 
				   &dist, &ang1, &(s1lat[0]), &(s1lon[0]), &ier );
		       clo_dltln ( &(psig->latlon[ii+1]), &(psig->latlon[np+ii+1]), 
				   &dist, &ang2, &(s2lat[1]), &(s2lon[1]), &ier );

		       gtrans ( sys_M, sys_N, &two, s1lat, s1lon, x1, y1, 
		                &ier, strlen(sys_M), strlen(sys_N) );
		       gtrans ( sys_M, sys_N, &two, s2lat, s2lon, x2, y2, 
		                &ier, strlen(sys_M), strlen(sys_N) );
		       cgr_segint( sys_N, x1, y1, sys_N, x2, y2,
			           sys_M, &xint, &yint, &intrsct, &ier );

		     }
		     else  {

		       xint = (s1lat[1] + s2lat[0]) / 2.0F;
		       yint = (s1lon[1] + s2lon[0]) / 2.0F;

		     }

		     kk = 2*np - ii + 1;
		     lat[kk] = xint;
		     lon[kk] = yint;

		     ang1 = (float)fmod ( ((double)ang1+180.0), 360.0 );
		     ang2 = (float)fmod ( ((double)ang2+180.0), 360.0 );

		     ang1 = ang2;

		    }

		    clo_direct ( &(psig->latlon[np-2]), &(psig->latlon[2*np-2]),
				 &(psig->latlon[np-1]), &(psig->latlon[2*np-1]),
				 &ang2, &ier );

		    ang2 -= 90.0F;
		    clo_dltln ( &(psig->latlon[np-1]), &(psig->latlon[2*np-1]), 
				&dist, &ang2, &(lat[np]), &(lon[np]), &ier );

		    ang2 = (float)fmod ( ((double)ang2+180.0), 360.0);
		    clo_dltln ( &(psig->latlon[np-1]), &(psig->latlon[2*np-1]), 
				&dist, &ang2, &(lat[np+2]), &(lon[np+2]), &ier );

		    lat[np+1] = psig->latlon[np-1];
		    lon[np+1] = psig->latlon[2*np-1];

		    lat[2*np+2] = lat[0];
		    lon[2*np+2] = lon[0];

		    npts = 2*np + 3;
		    gline ( sys_M, &npts, lat, lon, &ier, strlen(sys_M) );

		break;

	    }

	}

	break;

      case	SIGTYP_AREA:		/* area		*/

	for ( ii = 0; ii < np; ii++ )  {
	    lat[ii] = psig->latlon[ii];
	    lon[ii] = psig->latlon[ii+np];
	}
	lat[np] = psig->latlon[0];
	lon[np] = psig->latlon[np];
	np++;

	gline ( sys_M, &np, lat, lon, &ier, strlen(sys_M) );

	break;

    }

    if ( el->hdr.vg_type == SIGCONV_ELM || el->hdr.vg_type == SIGOUTL_ELM )  {

	if ( el->hdr.vg_type == SIGCONV_ELM ) 
	    sprintf( str, "%d%c", psig->info.seqnum, psig->info.msgid[0] );
	else if ( el->hdr.vg_type == SIGOUTL_ELM )
	    sprintf( str, "%d", psig->info.seqnum );

	np = psig->info.npts;
	lbllat = psig->latlon[0];
	lbllon = psig->latlon[np];
	for ( ii = 1; ii < np; ii++ )  {
	    if ( psig->latlon[ii] > lbllat )  {
	        lbllat = psig->latlon[ii];
	        lbllon = psig->latlon[ii+np];
	    }
	}

	gqtext( &itxfn_s, &itxhw_s, &sztext_s, &itxwid_s, &ibrdr_s, 
		&irrotn_s, &ijust_s, &ier );
	itxfn  = 0;
	itxhw  = 0;
	sztext = 1.5F;
	itxwid = 0;
	ibrdr  = 0;
	irrotn = 0;
	ijust  = 2;
	gstext( &itxfn, &itxhw, &sztext, &itxwid, &ibrdr, &irrotn, &ijust, &ier );
	gtext( sys_M, &lbllat, &lbllon, str, &rotat, &ixoff, &iyoff, &ier, 
	       strlen(sys_M), strlen(str) );
	gstext( &itxfn_s, &itxhw_s, &sztext_s, &itxwid_s, &ibrdr_s, 
		&irrotn_s, &ijust_s, &ier );

    }

    /*
     *  Restore the saved plot attribute values
     */
    gsmrkr ( &imarkx, &imkhwx, &szmarkx, &imkwidx, &ier );
    gsline ( &iltypx, &ilthwx, &iwidthx, &iwhwx, &ier );
    gscolr ( &icolrx, &ier );

}
Example #28
0
void crg_setwnd ( VG_DBStruct *el, int joffset, int elnum, int *iret )
/************************************************************************
 * crg_setwnd                                                           *
 *                                                                      *
 * This function sets the range for a wind element.			*
 *                                                                      *
 * crg_setwnd ( el, joffset, elnum, iret ) 				*
 *                                                                      *
 * Input parameters:                                                    *
 *	*el		VG_DBStruct	Element containing wind		*
 * 	joffset		int		File position of the element	*
 *	elnum		int		Element number			*
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 **                                                                     *
 * Log:                                                                 *
 * E. Wehner/EAi         8/97   Created					*
 * D.W.Plummer/NCEP	 9/97	Changes for new vgstruct header file	*
 * F.J.Yen/NCEP		 1/98	Rewrote crg_wndrng.  Cleaned up.	*
 * F.J.Yen/NCEP		 4/98	Increased range.			*
 * F.J.Yen/NCEP		 4/98	Added DARR_ELM and HASH_ELM.		*
 * F.J.Yen/NCEP		 4/98	Used base speed of 10 for DARR_ELM.	*
 * I. Durham/GSC	 5/98	Changed underscore decl. to an include	*
 * S. Law/GSC		03/99	Cleaned up range sizes			*
 * A. Hardy/GSC         11/00   renamed coordinate system declarations	*
 * J. Wu/GSC            03/01   Standardized extra space EXTRA/EXTRA_SM	*
 ***********************************************************************/
{
    float	rx[1], ry[1];
    float	srx[1], sry[1];
    float	llx, lly, urx, ury;
    float	mysize;
    int 	ier, np;
    float	szmk, sztx, szwb, szws, szab, szah;
    float	sizwba, adjhsiz, speed;

/*---------------------------------------------------------------------*/

    *iret = 0;

    /*
     *  Convert point in element to device...
     */

    np = 1;
    rx[0] = el->elem.wnd.data.latlon[0];
    ry[0] = el->elem.wnd.data.latlon[np];

    gtrans(sys_M, sys_D, &np, rx, ry, srx, sry, &ier, 
	   strlen(sys_M), strlen(sys_D));

    /*
     *  Get wind barb and wind arrow sizes...
     */

    gqsizd ( &szmk, &sztx, &szwb, &szws, &szab, &szah, &ier );

    /*
     *  calculate the size (mysize) of this barb in device coords x and y.
     */
    if (el->hdr.vg_type == BARB_ELM) {
        mysize = (el->elem.wnd.info.size * szwb) + (float)EXTRA;
    }
    else if (el->hdr.vg_type == ARROW_ELM || el->hdr.vg_type == DARR_ELM) {
	if (el->hdr.vg_type == DARR_ELM) {
	    speed = DARR_BASE_SPD;
	}
	else if (el->elem.wnd.data.spddir[0] < 1.0F) {
	    speed = 1.0F;
	}
	else {
	    speed = el->elem.wnd.data.spddir[0];
	}

	sizwba = (speed * el->elem.wnd.info.size * szab);
	adjhsiz = el->elem.wnd.info.hdsiz * szah * 0.85F;

	mysize = sizwba + adjhsiz + (float)EXTRA;
    }
    else {
        mysize = el->elem.wnd.info.size * szwb + (float)EXTRA;
    }

    /* 
     * set range points based on the dimension of the element 
     */

    lly = sry[0] - mysize;
    llx = srx[0] - mysize;
    urx = srx[0] + mysize;
    ury = sry[0] + mysize;

    /*
     *  Store the device coordinates in the range array.
     */
    crg_save(elnum, joffset, llx, lly, urx, ury, &ier);
}