Ejemplo n.º 1
0
void clo_ddenc ( char *type, int format, float lat, float lon, char *str,
                 int *iret )
/************************************************************************
 * clo_ddenc                                                    	*
 *                                                                      *
 * This function returns gets the string for the seek and location      *
 * structure indicating which entry matches the input CLO name for the  *
 * given latitude and longitude. The format code is in a 4-5 digit      *
 * format (Eg. 5212 or 10212).  The columns are formatted as follows : 	*
 *					       				*
 *									*
 *   ROUNDING        UNITS        DIRECTION     DISPLAY			*
 *                                              			*
 *  5 - nearest 5    0 - omit     0 - omit      0 - degrees		*
 * 10 - nearest 10   1 - NM       1 - 16 point  1 - decimal/minutes   	*
 *                   2 - SM       2 - degrees   2 - 1st column		*
 *                   3 - KM             	4 - 3rd column		*
 *									*
 * For DISPLAY, the 1st column is usually the station id and the 3rd    *
 * column is the name of the station, city or county.			*
 *                                                                      *
 * clo_ddenc ( type, format, lat, lon, str, iret)                       *
 *                                                                      *
 * Input parameters:                                                    *
 *	*type		char		Name of CLO parameter		*
 *	format		int		Indicator of format to use      *
 *      lat            float            Latitude point                  *
 *      lon            float            Longitude point                 *
 *									*
 * Output parameters:                                                   *
 *	*str		char		Character string location       *
 *	*iret		int		Return value			*
 *					=  < 0 - String not created	*
 *									*
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC		01/00	Create					*
 * A. Hardy/GSC		01/00	Added new format display option         *
 * A. Hardy/GSC		01/00	Added length chk of str;changed rounding*
 * A. Hardy/GSC		02/00	modified for all variations of formats  *
 * A. Hardy/GSC		02/00	reworked string display; city locations *
 * D.W.Plummer/NCEP	 8/00	changes for clo_ redesign		*
 * A. Hardy/GSC		 8/00   renamed from clo_format			*
 * T. Piper/GSC		 3/01	Fixed IRIX6 compiler warnings		*
 * D.W.Plummer/NCEP	 8/01	Repl clo_bqinfo w/ cst_gtag		*
 * D.W.Plummer/NCEP	 6/05	Tens digit sets # decimals for lat,lon	*
 ***********************************************************************/
{
    int		idist, icmp, nh, ier;
    int		ilat, ilon, imnt, imnn, isit, isin;
    char	stn[80], idx[80], *pidx, sdir[4];
    float	dist, dir;
    int         ione, itens, ihund, irnd, which, inlen;
    int         isln, iwidth, ilftovr;
    char        sdirc[5], sdist[5];
    char	info[128], fmt[20];
    /*---------------------------------------------------------------------*/
    *iret = 0;
    strcpy ( str, "NULL" );
    iwidth = 16;

    /*
     * Parse out format into it's components.
     */

    ione  = format % 10;
    itens = (int) (format/10) % 10;
    ihund = (int) (format/100) % 10;
    irnd  = format / 1000;

    /*
     * Check one's place for lat-lon or deg-min.
     */

    if ( ione == 0 ) {	/* show lat/lon */
        /*
         * Tens digit controls the number of decimal digits for the
         * lat,lon display. The default is 2 digits.
         */
        if ( itens == 0 )  itens = 2;
        sprintf(fmt,"%%.%df, %%.%df", itens, itens );
        sprintf(str, fmt, lat, lon);
    }
    else if ( ione == 1 ) {   /* show lat/lon as deg-min */
        isit = ( lat < 0.0F ) ? '-' : ' ';
        ilat = (int) G_ABS ( lat );
        imnt = G_NINT ( ( G_ABS(lat) - (float)ilat ) * 60.0F );
        if  ( imnt >= 60 )  {
            imnt = imnt % 60;
            ilat += 1;
        }

        isin = ( lon < 0.0F ) ? '-' : ' ';
        ilon = (int) G_ABS ( lon );
        imnn = G_NINT ( ( G_ABS(lon) - (float)ilon ) * 60.0F );
        if  ( imnn >= 60 )  {
            imnn = imnn % 60;
            ilon += 1;
        }

        sprintf ( str, "%c%3d:%02d, %c%3d:%02d",
                  isit, ilat, imnt, isin, ilon, imnn );
    }

    else {   /* show city/county/stn  */
        which = clo_which ( type );

        if ( clo.loc[which].format == 1 ) { 		/* show bound */

            clo_tqbnd ( type, lat, lon, idx, &ier);
            pidx = idx;

            /*
             *   Find and save the county FIPS id.
            */

            if ( ione == 2) {

                if (strcmp ( pidx,"-") != 0 ) {
                    clo_bginfo ( type, 0, info, &ier );
                    cst_gtag ( "FIPS", info, "?", str, &ier );
                }
                else {
                    cst_split (pidx, ' ', 14, str, &ier);
                }
            }
            if ( ione == 4) {  /* Save the bound name */
                cst_split (pidx, ' ', 14, str, &ier);
            }
        }


        else {
            if ( clo.loc[which].format == 0 ) { 	/* show station */

                /*
                 *  get station ID, distance and direction.
                 */
                clo_tdirect ( type, lat, lon, stn, &dist, &dir, &ier );

                if ( ione == 4 ) {
                    /*
                     *  Replace station ID w/ station name.
                     */
                    clo_tgnm ( type, 1, sizeof(stn), &nh, stn, &ier );
                }
            }

            if ( ihund == 0 ) {
                strcpy ( sdirc, "" );
            }
            else {
                if ( ihund == 1 ) {           /* get nautical miles */
                    dist *= M2NM;
                }
                else if ( ihund == 2 ) {      /* get statute miles */
                    dist *= M2SM;
                }
                else if ( ihund == 3 ) {      /* get kilometers */
                    dist /= 1000.0F;
                }

                if ( irnd > 0 ) {
                    idist = G_NINT ( dist / (float)irnd ) * irnd;
                    sprintf ( sdirc, "%i ", idist);
                }
                else if ( irnd < 0 ) {
                    irnd = 1;
                    idist = G_NINT ( dist / (float)irnd ) * irnd;
                    sprintf ( sdirc, "%i ", idist);
                }
                else if ( irnd == 0 ) {
                    strcpy ( sdirc, "" );
                }

            }

            if ( itens == 0 ) {  /* omit the direction */
                strcpy ( sdist, "" );
            }
            else {
                if ( itens == 1 ) {      /* use 16 point dir. */
                    clo_compass ( &dir, sdir, &icmp, &ier );
                    sprintf ( sdist, "%s", sdir );
                }
                else if  ( itens == 2 ) {      /* use degrees  */
                    sprintf ( sdist, "%.0f", dir );
                }
            }

            sprintf(str, "%s %s",sdirc, sdist);

            /*
             * If the stn name is longer than 4 chars, print
             */

            inlen = (int)strlen(stn);
            isln = (int)strlen(str);
            ilftovr = iwidth - isln;

            if (inlen > 4 )  {
                sprintf ( str, "%*s %.*s", isln, str, ilftovr, stn );
            }
            else {
                sprintf ( str, "%s %3s", str, stn );
            }

            if ( (ihund == 0 ) && ( itens == 0 ) ) {
                sprintf ( str, "%.*s", ilftovr, stn );
            }
        }
    }
    if ( strcmp ( str, "NULL") != 0 ) *iret = -1;
}
Ejemplo n.º 2
0
void shn_dfhr ( int *idst, float *rlat, float *rlon, int *idiff, int *iret )
/************************************************************************
 * shn_dfhr								*
 *									*
 * Given a location defined by a latitude/longitude pair, this function	*
 * determines the offset (in hours) between GMT and the local time at	*
 * that location.							*
 *									*
 * shn_dfhr ( *idst, *rlat, *rlon, *idiff, *iret )			*
 *									*
 * Input parameters:                                                    *
 *	*idst		int		Flag denoting whether the	*
 *					current	report date-time occurs	*
 *					during Daylight	Savings Time:	*
 *					   0 = No			*
 *					   1 = Yes			*
 *	*rlat		float		Latitude of location		*
 *	*rlon		float		Longitude of location		*
 *                                                                      *
 * Output parameters:                                                   *
 *	*idiff		int		Difference (in hours) determined*
 *					by subtracting GMT from the	*
 *					local time at the given location*
 *	*iret		int		Return code:			*
 *					   0 = normal return		*
 *					  -1 = a problem occurred	*
 **                                                                     *
 *  Log:                                                                *
 *  J. Ator/NCEP         04/05                                          *
 ***********************************************************************/
{
	char cbndtp[8] = "TZ_BNDS";
	char cwrkst[80];
	char info[128];

	int ier;

	*iret = -1;

	clo_tqbnd ( cbndtp, *rlat, *rlon, cwrkst, &ier );
	if ( ier != 0 ) {
	    LOG_ERROR(clo_tqbnd);
	    return;
	}

	clo_bginfo ( cbndtp, 0, info, &ier ); 
	if ( ier != 0 ) {
	    LOG_ERROR(clo_bginfo);
	    return;
	}

	if ( *idst ) {
	    cst_gtag ( "GMT_DST_OFFSET", (const char *) info, " ", cwrkst, &ier );
	}
	else {
	    cst_gtag ( "GMT_OFFSET"    , (const char *) info, " ", cwrkst, &ier );
	}
	if ( ier != 0 ) {
	    LOG_ERROR(cst_gtag);
	    return;
	}

	cst_numb ( cwrkst, idiff, &ier );
	if ( ier != 0 ) {
	    LOG_ERROR(cst_numb);
	    return;
	}

	*iret = 0;
	return;
}
Ejemplo n.º 3
0
int main ( int argc, char **argv )
/************************************************************************
 * mdp									*
 *                                                                      *
 * This program generates the mesoscale discussion latlon pairings.	*
 * Pairings will be written to a file whose filename is based on the	*
 * input filename (filename extension, if exists, is replaced w/ "mdp").*
 *                                                                      *
 * Example:								*
 * mdp input_vgf_file.vgf						*
 * Produces latlon pairings in the ASCII file				*
 * output_vgf_file.mdp							*
 *                                                                      *
 * main(argc, argv)                                                     *
 *                                                                      *
 * Input parameters:                                                    *
 *  argc   int      number of parameters of command line                *
 *  argv   char**   parameter array of command line                     *
 *                                                                      *
 * Output parameters:                                                   *
 * Return parameters:                                                   *
 *                      NONE                                            *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * D.W.Plummer/NCEP	 6/02						*
 * D.W.Plummer/NCEP	 8/02	Bug fix for lons > 99.995 and < 100.0	*
 * G. Grosshans/SPC	11/02	Updated to decode multi-scalloped lines *
 * G. Grosshans/SPC	12/02	Updated to compute WFO/State		*
 * S. Jacobs/NCEP	 5/03	Clean up unused variables and headers	*
 * G. Grosshans/SPC     10/03   Updated for precision                   *
 * T. Piper/SAIC	12/05	Updated cst_wrap for CSC		*
 * J. Wu/SAIC		04/06	Added parameter in cst_wrap 		*
 * G. Grosshans/SPC	08/08	Updated for SCN 08-45 to add LAT...LON  *
 * 				and list first point as last point      *
 * 				to indicate a closed polygon.  Add      *
 *				word wrapping for ATTN...WFO...		*
 ***********************************************************************/
{
int		ii, ix, iy, ixfirst, iyfirst, pagflg, ne, ilen,
	        npts, ier, iret, nitems, more, curpos;

long		ifilesize;

float		x, y, flat[MAXLISTITEMS], flon[MAXLISTITEMS];

char		vg_class, vg_type, buffer[2048], bufferfinal[2048],
		bufferfinalwfo[2048],str[20], *cptr, errgrp[12], infile[128],
		ifname[128], outfile[128], info[2048], stpo[4],
		cstl_list[1000], cstl_liststate[1000],
		newLineStr[13]="            "; /* 13 spaces */

char		blank[2]={' '}, device[13], dfilnam[73], pro[80];
int		mode, istat, iunit, itype;
float		xsize, ysize, lllat, lllon, urlat, urlon,
		prjang1, prjang2, prjang3;

VG_DBStruct	el;

FILE		*ifptr, *ofptr;

const int line_len = 66;

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

    /* 
     * Set defaults for gsdeva and gsmprj
     */
    mode = 1;
    strcpy ( device, "GN" );
    iunit = 1;
    strcpy ( dfilnam, "MDPSPC" );
    itype = 1;
    xsize = 500.0F;
    ysize = 500.0F;
    lllat = 10.0F;
    lllon = -120.0F;
    urlat = 50.0F;
    urlon = -50.0F;
    strcpy ( pro, "str" );
    prjang1 =   90.0F;
    prjang2 = -105.0F;
    prjang3 =    0.0F;
    cstl_list[0] = '\0';
    cstl_liststate[0] = '\0';

    in_bdta ( &ier );
    ginitp ( &mode, &istat, &ier);
    gsdeva (device, &iunit, dfilnam, &itype, &xsize, &ysize, &iret,
	    strlen(device), strlen(dfilnam));
    gsmprj ( pro, &prjang1, &prjang2, &prjang3, 
	     &lllat, &lllon, &urlat, &urlon, &iret, strlen(pro));
    clo_init ( &ier );

    /*
     *  Check if number of input arguments is correct.
     */
    if ( argc < 2 )  {
	pagflg = G_FALSE;
	strcpy ( errgrp, "MDPSPC" );
        ip_help ( errgrp, &pagflg, &ier,
                  strlen(errgrp) );
	gendp (&mode, &ier);
	exit (0);
    }

    /*
     *  First input on command line is input vgf file name.
     */
    strcpy ( infile, argv[1] );
    cfl_inqr ( infile, NULL, &ifilesize, ifname, &ier );
    ifptr = (FILE *) cfl_ropn(ifname, "", &ier);
    if ( ier != 0 )  {
	printf("Error opening VGF file %s\n", infile );
	gendp (&mode, &ier);
	exit (0);
    }

    /*
     *  Output filename is input filename w/ "mdp" filename extension.
     */
    strcpy ( outfile, infile );
    cptr = strrchr( outfile, '.' );
    if ( cptr != (char *)NULL )  {
	cptr[0] = '\0';
    }
    strcat( outfile, ".mdp" );
    
    /*
     *  Loop through all the elements until a line is found.
     */
    ne = 0;
    more = G_TRUE;
    curpos = 0;
    buffer[0] = '\0';
    bufferfinal[0] = '\0';
    bufferfinalwfo[0] = '\0';
    strcat ( buffer, "LAT...LON   " );
    while ( ne < MAX_EDITABLE_ELEMS && more == G_TRUE )  {
	cvg_rdrecnoc( ifname, ifptr, curpos, &el, &ier );

	if ( ier < 0 )  {
	    more = G_FALSE;
	}
	else  {

	    curpos += el.hdr.recsz;

	    vg_class = el.hdr.vg_class;
	    vg_type  = el.hdr.vg_type;

            if ( ( (int)vg_class == CLASS_LINES ) &&
	    	 ( el.hdr.vg_type == SPLN_ELM ) &&
		 ( (int)el.elem.spl.info.spltyp == 3 ) )  {

		/*
		 *  Open output file.
		 */
		ofptr = (FILE *)cfl_wopn ( outfile, &ier );
		if ( ier != 0 )  {
		    printf("Error opening/creating output file %s\n",
		    	    outfile );
	            gendp (&mode, &ier);
		    exit (0);
    		}

	       /*
		* Find FIPS bounded by the closed line
		*/

		npts = el.elem.spl.info.numpts;

		/*  FIND WHAT STATES ARE IN MD AREA */

		clo_binpoly ( "CNTY_BNDS", npts, el.elem.spl.latlon,
                              &(el.elem.spl.latlon[npts]), &ier );
		clo_tgltln ( "CNTY_BNDS", MAXLISTITEMS, &nitems,
			      flat, flon, &ier);

		for ( ii = 0; ii < nitems; ii++ )  {
		  clo_bginfo( "CNTY_BNDS", ii, info, &ier );
		  cst_gtag( "STATE", info, "?", stpo, &ier);
		  
		  if (strstr(cstl_liststate, stpo)==NULL) {
		    strcat(cstl_liststate, stpo);
		    strcat(cstl_liststate, " ");		  
		  }
		}


		/*  FIND WHAT WFOs ARE IN MD AREA */
		clo_binpoly ( "CWA_BNDS", npts, el.elem.spl.latlon,
                              &(el.elem.spl.latlon[el.elem.spl.info.numpts]),
			      &ier );
		clo_tgltln ( "CWA_BNDS", MAXLISTITEMS, &nitems,
			      flat, flon, &ier);

		for ( ii = 0; ii < nitems; ii++ )  {
		  clo_bginfo( "CWA_BNDS", ii, info, &ier );
		  cst_gtag( "WFO", info, "?", stpo, &ier);
		  strcat(cstl_list, stpo);
		  strcat(cstl_list, "...");		  
		}

		/*
		 *  Format lats and lons into buffer.
		 */
		if ( (int)vg_type == LINE_ELM )  {
		    npts = el.elem.lin.info.numpts;
		}
		else if ( (int)vg_type == SPLN_ELM )  {
		    npts = el.elem.spl.info.numpts;
		}
		for ( ii = 0; ii < npts; ii++ )  {
		    if ( (int)vg_type == LINE_ELM )  {
		        x = el.elem.lin.latlon[ii];
		        y = -el.elem.lin.latlon[ii+npts];
		    }
		    else if ( (int)vg_type == SPLN_ELM )  {
		        x = el.elem.spl.latlon[ii];
		        y = -el.elem.spl.latlon[ii+npts];
		    }
		    /*
		     * Make sure lats and lons are rounded
		     * to 100ths of deg.
		     */
		    x = ((int)(x*100.0F)) / 100.0F;
		    y = ((int)(y*100.0F)) / 100.0F;
		    if ( y >= 100.0F )  y -= 100.0F;
		    ix = G_NINT(x*100.0F);
		    iy = G_NINT(y*100.0F);
		    sprintf( str, "%04d%04d ", ix, iy );
		    strcat ( buffer, str );
		    if ( ii == 0 ) {
                        ixfirst = ix;
			iyfirst = iy;
                    }
		}
		/*
		 *   Repeat first lat/lon point as last lat/lon point 
		 *   to indicate a closed polygon.
		 */


		sprintf( str, "%04d%04d ", ixfirst, iyfirst);
		strcat ( buffer, str );

		sprintf( str, "\n\n" );
		strcat ( buffer, str );

		/*
		 *  Wrap buffer such that only 6 pairs of lat,lons 
		 *  on one line.
		 *  ilen = 55;
		 *  cst_wrap( buffer, blank, &ilen, "\n", (char *)NULL, buffer, &ier );
		 */
		ilen = 66;
		cst_wrap( buffer, blank, &ilen, "\n", newLineStr, buffer, &ier );

	    }

	}
	ne++;
    }

    /*
     * wrap the ATTN...WFO... line
     */
    strcat ( bufferfinalwfo, "ATTN...WFO..." );
    strcat ( bufferfinalwfo, cstl_list );
    cst_wrap( bufferfinalwfo, "...", &line_len, "\n", (char *)NULL, bufferfinalwfo, &ier );

    /*
     * build the output file string and add the ATTN...WFO... string
     */
    strcat ( bufferfinal,"STATES=" );
    strcat ( bufferfinal, cstl_liststate );
    strcat ( bufferfinal, "\n\n" );
    strcat ( bufferfinal, bufferfinalwfo );
/*
    strcat ( bufferfinal,"ATTN...WFO..." );
    strcat ( bufferfinal, cstl_list );
*/
    strcat ( bufferfinal, "\n\n" );
    strcat ( bufferfinal, buffer );

    /*
     *  Write to output file.
     */
    cfl_writ ( ofptr, (int)strlen(bufferfinal),
    	       (unsigned char *)bufferfinal, &ier );

    /*
     *  close files and exit.
     */
    cfl_clos ( ifptr, &ier );
    cfl_clos ( ofptr, &ier );
    gendp (&mode, &ier);
    return(0);

}