Beispiel #1
0
void boundry_segs(long int offset, int npts, char *bndtbl, int col1, int col2, 
			int ltype, int lwidth)
{
FILE *fp;
int iret;
int nsegs,i,j,k;
float mxlat,mnlat,mxlon,mnlon;
float *X,*Y;
float lt[4],ln[4];
char buf[256];
static char bounddir[]="bounds";

fp = (FILE *)cfl_tbop(bndtbl,bounddir,&iret);
if(iret == 0)
   cfl_seek(fp,offset,SEEK_SET,&iret);
else
   {
   printf("open failed %d\n",iret);
   return;
   }

if(iret == 0)
   {
   X = (float *)malloc(npts*sizeof(float));
   Y = (float *)malloc(npts*sizeof(float));
   cfl_rdln(fp,255,buf,&iret);
   /*printf("look cfl_rdln %d %s\n",iret,buf);*/
   i = 0;
   if(iret == 0)
      {
      sscanf(buf,"%d %f %f %f %f %f %f",&nsegs,&mxlat,&mnlat,&mxlon,&mnlon,X,Y);
      i++;
      while((i < nsegs/2)&&(iret == 0))
         {
         cfl_rdln(fp,255,buf,&iret);
         if(iret == 0)
            {
            j = sscanf(buf,"%f %f %f %f %f %f %f %f",
               lt,ln,lt+1,ln+1,lt+2,ln+2,lt+3,ln+3);
            for(k=0;k<j;k+=2)
               {
               X[i] = lt[k/2]; Y[i] = ln[k/2]; i++;
               } 
            }
         }
      }
   bounds_fill(X,Y,nsegs/2,col1);

   bounds_line(X, Y, nsegs/2, col2, ltype, lwidth);
   free(X); free(Y);
   }
cfl_clos(fp,&iret);

}
Beispiel #2
0
void gb_ges ( int *iret )
/************************************************************************
 * gb_ges								*
 *									*
 * This function gets the GRIB information from GB_ENDS and passes	*
 * that information back to a function as independent variables.	*
 *									*
 * gb_ges ( iret )							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					-19 = error on message		*
 **									*
 * Log:									*
 * J. Chou/EAI		 7/93						*
 * S. Jacobs/EAI	 1/94	Clean up; Rename variables		*
 * L. Williams/EAI	 7/94	Reformat header				*
 * L. Sager		 8/95	Fix memory allocation error		*
 * S. Jacobs/NCEP	 1/96	Changed DA_READ to CFL_READ		*
 * D.W.Plummer/NCEP	 3/96	Changed cfl_ call sequence		*
 * M. Linda/GSC		10/97	Corrected the prologue format		*
 ***********************************************************************/
{
	int		offset, ret, nbytes;
	unsigned char	*buffer;

/*---------------------------------------------------------------------*/
	*iret = 0;

	offset = cursor + ISLENGTH + pdslength + gdslength +
			  bmslength + bdslength;
	buffer = (unsigned char *)
                 malloc ( 4       * sizeof(unsigned char) );
	cfl_seek ( gbfile.fptr, offset, SEEK_SET, &ret );
	cfl_read ( gbfile.fptr, 4, buffer, &nbytes, &ret );
	if ( ret != 0 ) {
	    *iret = -19;
	    return;
	}

	gb_ends ( buffer );

	free ( buffer );
}
Beispiel #3
0
void cvg_rdele ( VG_DBStruct *el, int el_start, int el_size, 
						FILE *fp, int *iret )
/************************************************************************
 * cvg_rdele								*
 *									*
 * This function reads a VG element from an open VG file. 		*
 *									*
 *  Note:  It is assumed that the *el contains a loaded header.		*
 *									*
 * cvg_rdele ( el, el_start, el_size, fp, iret )			*
 *									*
 * Input parameters:							*
 *	*el		VG_DBStruct	element structure		*
 *	el_start	int		File offset to start of element	*
 *	el_size		int		size of element to read in Bytes*
 *	*fp		FILE		Handle to open file		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  3 = VG element too large	*
 *					 -3 = seek to a bad location	*
 *					 -8 = no VG file is open	*
 *					-24 = no VG header loaded	*
 *									*
 **									*
 * Log:									*
 * E. Wehner/EAi	10/96	Created					*
 * D. Keiser/GSC	 1/97	Clean up and rename			*
 * D.W.Plummer/NCEP	 9/97	Changes for new vgstruct header file	*
 * C. Lin/EAI	        12/97	text element alignment remapping	*
 * G. Krueger/EAI	 1/98	Truncate too long elements.		*
 * G. Krueger/EAI	 4/98	Truncate too long elements to MAXPTS-1.	*
 * S. Jacobs/NCEP	 6/98	Added check for small front pips	*
 * A. Hardy/GSC         12/98   Added CLASS_CIRCLE                      *
 * E. Safford/GSC	04/99	fix no return value compiler warning	*
 * D.W.Plummer/NCEP     12/99   add call to cvg_rdwbx                   *
 * M. Li/GSC		12/99	Added cvg_swap and mv_swp4		*
 * F. J. Yen/NCEP	08/00	Added call to cvg_rdsig			*
 * R. Curtis/EAI	10/00	Added CCF check to Sigmet class check   *
 * J. Wu/GSC		11/00	Removed cvd_rdsym, cvd_rdwnd, cvg_rdcir *
 * E. Safford/GSC	12/00	rename params, clean up duplicate reads *
 * J. Wu/GSC		02/01	Replaced cvg_rdwbx & cvg_rdsig with new *
 *                              cvg_rdoldele() and added version control*
 * J. Wu/GSC		02/01	Modified 'unused2' to 'version' in VG   *
 * S. Jacobs/NCEP	 2/01	Added machine type MTLNUX		*
 * D.W.Plummer/NCEP	06/03	chgs for ASHCLD_ELM and VOLC_ELM	*
 * J. Wu/GSC		09/03	add LIST_ELM & JET_ELM			*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 * J. Wu/GSC		01/04	add cvg_rdgfa for new GFA_ELM		*
 * B. Yin/SAIC		02/04	added cvg_rdtca for TCA_ELM             *
 * B. Yin/SAIC		05/04	redefined MAX_TCA_SZ	                *
 * B. Yin/SAIC		08/04	removed MAX_TCA_SZ for water and islands*
 * J. Wu/SAIC		10/04	remove MAX_GFA_SZ			*
 * S. Danz/AWC          03/06   Add check for placement information     *
 * m.gamazaychikov/SAIC	04/07	add cvg_rdtce, cvg_rdtct and cvg_rdtcb	*
 * L. Hinson/AWC        01/12   Add SGWX_ELM                            *
 ***********************************************************************/
{
    int 	  *pnpts, ier, nbin, nbinfo, itrunc, max_version;
    int 	  info_pos, lon_pos, ierr;
    int		  one = 1;
    int		  tmp;
    int		  max_sz, info_sz;
    unsigned char *pinfo, *el_lon;
/*---------------------------------------------------------------------*/

    *iret = 0;
    info_pos = el_start + HDR_SZ;
    
    
    /*
     *  Determine the latest version # for VG elements.
     */
    max_version = 0; /* Latest version # for most VG element types */
    
    if ( el->hdr.vg_class == CLASS_WATCHES )  max_version = CUR_WBX_VER;
    if ( ( el->hdr.vg_class == CLASS_SIGMETS ) &&
         el->hdr.vg_type != SIGCCF_ELM &&
	 el->hdr.vg_type != VOLC_ELM &&
	 el->hdr.vg_type != ASHCLD_ELM )      max_version = CUR_SIG_VER;

    
    /*
     *  Read old versions VG elements (only WATCHES & SIGMETS have old
     *  versions currently). 
     */
    if ( (int)el->hdr.version < max_version ) { 
	cvg_rdoldele( el, el_start, el->hdr.recsz, fp, iret );    
    }
    
    else { 
        /*
         * Read current version of VG elements.  
         */
	pnpts  = NULL;
	itrunc = G_FALSE;
        pinfo  = (void *) &(el->elem);

	nbinfo = el_size - HDR_SZ;

	/*
	 *  Lines and fronts may have more than MAXPTS in their latlon array
	 *  if they were created through the vg driver.  If they do, they will
	 *  be truncated to MAXPTS, and an iret of +3 returned.
	 *
	 *  All other types will be checked against their maximum size, and
	 *  an error reported if they exceed this.
	 */
	switch ( el->hdr.vg_class ) {
	
	    case CLASS_LINES:

	        if (el->hdr.vg_type == LINE_ELM) {
		    max_sz  = MAX_LINE_SZ;
		    pnpts   = &(el->elem.lin.info.numpts);
		    info_sz = sizeof(LineInfo);
		    el_lon  = (void *)el->elem.lin.latlon;
		}
		else {
		    max_sz  = MAX_SPLINE_SZ;
		    pnpts   = &(el->elem.spl.info.numpts);
		    info_sz = sizeof(SpLineInfo);
		    el_lon  = (void *)el->elem.spl.latlon;
		}

		if (el_size > max_sz) {
		    itrunc  = G_TRUE;
		    el_lon  += MAX_PTS_SZ;	
  		    nbinfo  =  info_sz + MAX_PTS_SZ; 
		    el->hdr.recsz = max_sz;
		}

		break;

	    case CLASS_FRONTS:

		if (el_size > MAX_FRONT_SZ) {
		    itrunc = G_TRUE;
		    pnpts  = &(el->elem.frt.info.numpts);
		    el_lon = (void *)el->elem.frt.latlon; 
		    el_lon += MAX_PTS_SZ;
		    nbinfo = MAX_FRONT_SZ - HDR_SZ;
		    el->hdr.recsz = MAX_FRONT_SZ;
		}

  		pnpts  = &(el->elem.frt.info.numpts);
		break;

	
	    case CLASS_SYMBOLS:
	        if (el->hdr.recsz > MAX_SYM_SZ) {
		    *iret = -11;
		}
		break;

	    case CLASS_WINDS:
	        if (el->hdr.recsz > MAX_WIND_SZ) {
		    *iret = -11;
		}
		break;

	    case CLASS_TEXT:
		if (el->hdr.recsz > MAX_SPTEXT_SZ) {
		    *iret = -11;
		}
		break;
	 
	    case CLASS_CIRCLE:
		if (el->hdr.recsz > MAX_CIRCLE_SZ) {
		    *iret = -11;
		}
		break;
 
            case CLASS_SIGMETS:
		if ( ( ( el->hdr.vg_type != SIGCCF_ELM &&
			 el->hdr.vg_type != ASHCLD_ELM &&
			 el->hdr.vg_type != VOLC_ELM ) &&
		       el->hdr.recsz > MAX_SIGMET_SZ )  ||
        ( el->hdr.vg_type == SIGCCF_ELM && el->hdr.recsz > MAX_CCF_SZ ) ||
	( el->hdr.vg_type == ASHCLD_ELM && el->hdr.recsz > MAX_ASH_SZ ) ||
	( el->hdr.vg_type ==   VOLC_ELM && el->hdr.recsz > MAX_VOL_SZ ) ) {
		    *iret = -11;
		}
		break;
 
            case CLASS_TRACKS:
		if (el->hdr.recsz > MAX_TRACK_SZ) {
		    *iret = -11;
		}
		break;

            case CLASS_WATCHES:
		if (el->hdr.recsz > MAX_WATCHBOX_SZ) {
		    *iret = -11;
		}
		break;

            case CLASS_LIST:
		if (el->hdr.recsz > MAX_LIST_SZ) {
		    *iret = -11;
		}
		break;

            case CLASS_MET:
		if (el->hdr.vg_type == JET_ELM &&
		    el->hdr.recsz > MAX_JET_SZ) {
		    *iret = -11;
		} else if (el->hdr.vg_type == SGWX_ELM &&
                    el->hdr.recsz > MAX_SGWX_SZ) {
                    *iret = -11;
                }
		break;

	    default:
	        break;

        }   /* end of switch */

	if ( *iret < 0 ) {  
	    return;
   	}

	/*
	 *  Read the element data.  This read will not include the lon
	 *  array if the element has > MAXPTS.  The lons will be read using
	 *  the "if ( itrunc )" condition statements below.
	 */
	if ( el->hdr.vg_type == GFA_ELM ) {
	    cvg_rdgfa ( fp, (long)info_pos, el, &ier );
	}
	else if ( el->hdr.vg_type == TCA_ELM ) {
	    cvg_rdtca ( fp, (long)info_pos, el, &ier );
	}
	else if ( el->hdr.vg_type == TCERR_ELM ) {
	    cvg_rdtce ( fp, (long)info_pos, el, &ier );
	}
	else if ( el->hdr.vg_type == TCTRK_ELM ) {
	    cvg_rdtct ( fp, (long)info_pos, el, &ier );
	}
	else if ( el->hdr.vg_type == TCBKL_ELM ) {
	    cvg_rdtcb ( fp, (long)info_pos, el, &ier );
	}
	else {	
	    cfl_seek( fp, (long)info_pos, 0, &ier );
	    cfl_read( fp, nbinfo, (void *)( pinfo ), &nbin, &ier );
        }

	/*
	 *  Read the lons for truncated elements.
	 */
  	if ( itrunc ) {

	    /*
	     *  Set element characteristics to reasonable values, considering
	     *  that the line is truncated.  Set iret = 3 to signal truncation.
	     */
	    *iret   = 3;
	    *pnpts  = MAXPTS;
	    el->hdr.closed = 0;
	    el->hdr.filled = 0;

	    lon_pos  = info_pos + info_sz + 
    			( (el_size - HDR_SZ - info_sz) / 2 );

	    cfl_seek ( fp, (long)lon_pos, 0, &ier );
	    cfl_read ( fp, MAX_PTS_SZ, (void *)(el_lon), &nbin, &ier); 
	}
  

	if ( MTMACH == MTULTX ||
	     MTMACH == MTALPH ||
	     MTMACH == MTLNUX ) {
	    if ( itrunc ) {
  	        mv_swp4 (&one, pnpts, &tmp );
	        *pnpts = tmp;
	    }

	    cvg_swap( SWPINF, G_TRUE, *el, el, &ierr );
	}

    }

    /*
     * If the object is in the set of placed data, adjust the coordinates
     */
    cvg_eladj(el_start, el, &ierr);
}
Beispiel #4
0
void na_gtbl ( const char *cpyfil, char *name, char *proj, int *nxgd,
               int *nygd, float *garea, float *rnvblk, float *anlblk,
	       int *iret )
/************************************************************************
 * na_gtbl								*
 *									*
 * This subroutine finds grid INNAME (a numerical or character          *
 * identifier prefaced by '#') in a grid navigation table, then makes 	*
 * the navigation and analysis blocks.  The grid navigation is set up	*
 * in GEMPLT in order to check its validity.				*
 *									*
 * na_gtbl ( cpyfil, name, proj, nxgd, nygd, garea, rnvblk, anlblk,	*
 *           iret )							*
 *									*
 * Input parameters:							*
 *	*cpyfil		const char	Input for CPYFIL		*
 *									*
 * Output parameters:							*
 *	*name		char		Name of selected grid		*
 *	*proj		char		Grid projection			*
 *	*nxgd		int		Number of points in x dir	*
 *	*nygd		int		Number of points in y dir	*
 *	*garea		float		Grid corners			*
 *	*rnvblk		float		Grid navigation block		*
 *	*anlblk		float		Grid analysis block		*
 *	*iret		int		Return code			*
 *					 +1 = EXIT entered		*
 *					  0 = normal return		*
 *					 -4 = invalid navigation	*
 *					 -9 = grid not found in table	*
 **									*
 * Log:									*
 * S. Jacobs/EAI	 7/93		Copied from GDCTBL		*
 * D. Keiser/GSC	12/95		Changed FL_TOPN to FL_TBOP	*
 * R. Tian/SAIC		 7/06		Recoded from Fortran		*
 * S. Gilbert/NCEP      10/06   Added call to GR_VNAV                   *
 ************************************************************************/
{
    char gntrec[81], namgd[5], c2name[9], buffer[LLMXLN];
    float angl1, angl2, angl3, dbnds[4], deln;
    int angflg, found, valid;
    int iebnds[4], ingrdn, numgd, extnd, ier, ier1, iernum, navsz, i;
    FILE *lungrd;
/*----------------------------------------------------------------------*/
    *iret = 0;
    name[0] = '\0';

    /*
     * Get the grid number (INGRDN) out of NAME; a conversion error
     * sets IERNUM .ne. 0 and it is assumed that NAME is a type.
     */
    cst_lcuc ( (char *)cpyfil, c2name, &ier );
    strcpy ( name, &c2name[1] );
    cst_numb ( name, &ingrdn, &iernum );

    /*
     * Open the table of valid grid types.
     */
    lungrd = cfl_tbop ( "grdnav.tbl", "grid", &ier );
    if ( ier != 0 ) {
	er_wmsg ( "CFL", &ier, "grdnav.tbl", &ier1,
	          strlen("CFL"), strlen("grdnav.tbl") );
	*iret = -9;
	return;
    }

    /*
     * List the table contents for the user, if requested.
     */
    if ( strcmp ( name, "LIST" ) == 0 ) {
	while ( ! feof ( lungrd) ) {
	    cfl_trln ( lungrd, sizeof(gntrec), gntrec, &ier );
	    if ( ier != 0 ) break;

	    printf ( "%-79.79s\n", gntrec );
	}

	/*
	 * Rewind the table file.
	 */
	cfl_seek ( lungrd, 0, SEEK_SET, &ier );

	/*
	 * Prompt user for grid choice.
	 */
	printf ( "Enter grid id or number or type EXIT: " );
	scanf ( " %s", name );
	if ( name[0] == 'e' || name[0] == 'E' ) {
	    *iret = +1;
	    return;
	}
	cst_lcuc ( name, name, &ier );
	cst_numb ( name, &ingrdn, &iernum );
    }

    /*
     * Read through the list of valid grid types/numbers to get 
     * navigation/analysis information.
     */
    found = G_FALSE;
    while ( ! feof ( lungrd ) ) {
    	cfl_trln ( lungrd, sizeof(buffer), buffer, &ier );
	if ( ier != 0 ) break;

	sscanf ( buffer, "%s %d %s %f %f %f %f %f %f %f %d %d %f %d",
                 namgd, &numgd, proj, &angl1, &angl2, &angl3,
		 &garea[0], &garea[1], &garea[2], &garea[3],
		 nxgd, nygd, &deln, &extnd );
	if ( strcmp ( name, namgd ) == 0 || ingrdn == numgd ) {
	    found = G_TRUE;
	    break;
	}
    }
    cfl_clos ( lungrd, &ier );

    /*
     * Bail out if NAME wasn't found in the table.
     */
    if ( found == G_FALSE ) {
	*iret = -9;
	return;
    }

    /*
     * Fill navigation block.
     */
    angflg = G_TRUE;
    gr_vnav  ( proj, nxgd, nygd, &garea[0], &garea[1],
                &garea[2], &garea[3], &angl1, &angl2, &angl3,
		&angflg, &valid, &ier, strlen(proj) );

    if ( ier == 0 )
       grc_mnav  ( proj, nxgd, nygd, &garea[0], &garea[1],
                   &garea[2], &garea[3], &angl1, &angl2, &angl3,
                   &angflg, rnvblk, &ier );
    else {
       *iret = -2;
       return;
    }

    /*
     * Set up navigation in GEMPLT to check validity.
     */
    navsz = 13;
    grc_snav  ( &navsz, rnvblk, &ier );
    if ( ier != 0 ) {
	*iret = -4;
	return;
    }

    /*
     * Make an analysis block.
     */
    for ( i = 0; i < 4; i++ ) {
	iebnds[i] = extnd;
	dbnds [i] = RMISSD;
    }
    grc_mbn2 ( &deln, iebnds, dbnds, rnvblk, anlblk, &ier );

    return;
}
Beispiel #5
0
void shp_rdbh ( FILE *fp, dbf_header *dbfhdr, int *iret )
/************************************************************************
 * shp_rdbh                                                             *
 *                                                                      *
 * This function reads information from the database header.          	*
 *                                                                      *
 * shp_rdbh ( fp, dbfhdr, iret )					*
 *                                                                      *
 * Input parameters:                                                    *
 *      *fp             FILE            Database file pointer           *
 *                                                                      *
 * Output parameters:                                                   *
 *	*dbfhdr		dbf_header    	Database header sturcture  	*
 *      *iret           int             Return code                     *
 *                                        0 = Normal                    *
 **                                                                     *
 * Log:                                                                 *
 * R. Tian/SAIC         12/03	Initial coding				*
 * S. Jacobs/NCEP	 3/11	Enhance error messages			*
 * S. Jacobs/NCEP	 6/14	Added debug prints and field type char	*
 ***********************************************************************/
 {
    dbf_hdrmap hdrmap;
    dbf_fldmap fldmap;
    int numflds, nbin, ier, ifld;
/*---------------------------------------------------------------------*/
    *iret = 0;

    /*
     * Position to the beginning of the database file.
     */
    cfl_seek ( fp, 0, SEEK_SET, &ier );

    /*
     * Map the database header to the header map structure, and extract
     * those corresponding fields.
     */
    cfl_read ( fp, DBF_HEADER_SIZE, (unsigned char *)&hdrmap, 
               &nbin, &ier );

    if ( debug_flag ) {
	printf ( "DBF_HEADER_SIZE   = %ld\n", DBF_HEADER_SIZE );
	printf ( "DBF Version #     = 0x%02x\n", hdrmap.dbf_vers );
	printf ( "File Date         = %04d %02d %02d\n",
	       		hdrmap.dbf_date[0]+1900, hdrmap.dbf_date[1],
			hdrmap.dbf_date[2] );
	/* Extra debug for checking the header */
	/*
	int jj;
	for ( jj = 0; jj < (int)sizeof(hdrmap.dbf_stub); jj++ ) {
	    printf ( "Reserved %02d = 0x%02x\n", jj, hdrmap.dbf_stub[jj]);
	}
	*/
    }

    dbfhdr->nrec = (int)( shp_get_llong  ( hdrmap.dbf_nrec ) );
    dbfhdr->hlen = (int)( shp_get_lshort ( hdrmap.dbf_hlen ) );
    dbfhdr->rlen = (int)( shp_get_lshort ( hdrmap.dbf_rlen ) );
    numflds  = (int)((dbfhdr->hlen - DBF_HEADER_SIZE)/DBF_FIELD_SIZE);
    dbfhdr->nfld = numflds;

    if ( debug_flag ) {
	printf ( "Number of records = %d\n", dbfhdr->nrec );
	printf ( "Header length     = %d\n", dbfhdr->hlen );
	printf ( "Record length     = %d\n", dbfhdr->rlen );
	printf ( "Number of fields  = %d\n", dbfhdr->nfld );
    }

    if ( numflds > MAXFLD ) {
        fprintf ( stderr, "Number of fields (%d) exceeds MAXFLD. "
                          "Increase MAXFLD in shpprm.h\n", numflds );
        exit (-1);
    }
    if ( dbfhdr->rlen > MAXRECLEN ) {
        fprintf ( stderr, "Record length (%d) exceeds MAXRECLEN. "
                          "Increase MAXRECLEN in shpprm.h\n", dbfhdr->rlen );
        exit (-1);
    }

    /*
     * Map each database field to the field map structure, and extract
     * those corresponding fields.
     */
    for ( ifld = 0; ifld < numflds; ifld++ ) {
        cfl_read ( fp, DBF_FIELD_SIZE, (unsigned char *)&fldmap, 
	           &nbin, &ier );
	
	strncpy ( dbfhdr->dbflds[ifld].name, (char *)fldmap.fld_name, 
	          FLD_NAMELEN );
	dbfhdr->dbflds[ifld].name[FLD_NAMELEN-1] = CHNULL;
	dbfhdr->dbflds[ifld].type = fldmap.fld_type;
	dbfhdr->dbflds[ifld].lens = fldmap.fld_lens;
	dbfhdr->dbflds[ifld].decs = fldmap.fld_decs;
    }

    if ( debug_flag ) {
	printf ( "  Field name   type code  length  decimal_count\n" );
	for ( ifld = 0; ifld < numflds; ifld++ ) {
	    printf ( "  %-11.11s  %4d  %c   %6d  %6d\n",
		     dbfhdr->dbflds[ifld].name,
		     dbfhdr->dbflds[ifld].type,
		     dbfhdr->dbflds[ifld].type,
		     dbfhdr->dbflds[ifld].lens,
		     dbfhdr->dbflds[ifld].decs );
	}
    }

}
void nexr_list_lev ( char *filnam, int *lenfnam,
		char *radparm, int *lenparm, int *ier)

{

int i, nbin, iret;
long    flen, lofset = 20;
char cfil[LLPATH], cprm[LLMXLN];
char stid[]="KFTG", callid[5];

Radar *radar=NULL;
FILE *fp;


*ier = 0;

strncpy(cfil, filnam, *lenfnam);
strncpy(cprm, radparm, *lenparm);
cfil[*lenfnam] = '\0';
cprm[*lenparm] = '\0';

/* get actual file name to use in rsl call */
cfl_inqr ( cfil, NULL, &flen, cfil, &iret);

RSL_select_fields(cprm, NULL);

/*
if ( cprm[0] == 'd' )
        VINDEX = DZ_INDEX;
else if ( cprm[0] == 's' )
        VINDEX = SW_INDEX;
else if ( cprm[0] == 'v' )
        VINDEX = VR_INDEX;
*/

/*
 * see if we can get the station ID from bytes 21-24, otherwise, just use any ID
 */

fp = cfl_ropn ( cfil, NULL, &iret );
if  ( iret != 0 )  {
    printf("failed to open %s\n",cfil);
    *ier = -1;
    return;
    }
else {
    cfl_seek ( fp, lofset, SEEK_SET, &iret );
    if  ( iret != 0 )  {
        *ier = -1;
        cfl_clos ( fp, &iret );
        return;
        }
    }

cfl_read ( fp, 4, (unsigned char *)callid, &nbin, &iret );
cfl_clos ( fp, &iret );

if (( nbin < 4 )||(callid[0] < 'A')||(callid[0] > 'Z')) /* use a safe station ID....we aren't plotting lat/lon anyhow */
   strcpy(callid,stid);
else
   callid[4] = '\0';


/*RSL_radar_verbose_on();*/
RSL_read_these_sweeps("all", NULL);
radar = RSL_wsr88d_to_radar(cfil, callid);
/*RSL_radar_verbose_off();*/

if ( radar == NULL )
   {
   printf("failed to open %s\n",cfil);
   *ier = -1;
   return;
   }

for (i=0; i<radar->h.nvolumes; i++) {
   if (radar->v[i]) {
        printf("Volume %s: Sweeps available %d\n", cprm, radar->v[i]->h.nsweeps);
        print_header_for_volume(radar->v[i]);
      }
   }

RSL_free_radar(radar);


}
Beispiel #7
0
void crarea ( char *imgnam, int *iret )
/************************************************************************
 * crarea								*
 *									*
 * This subroutine reads the image data from a MCIDAS AREA file.	*
 * The full image is placed in memory pointed to by imgData.		*
 *									*
 * crarea ( imgnam, iret )						*
 *									*
 * Input parameters:							*
 *	*imgnam		char		Name of image file		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					G_NORMAL = normal return	*
 *					G_NIDSIZ = invalid image depth	*
 *					G_NIMGFL = cannot open/read img	*
 *					G_NMEMRY = memory alloc failure	*
 **									*
 * Log:									*
 * J. Cowie/COMET	 3/95						*
 * J. Cowie/COMET	 5/95	Modified to work with NAWIPS 5.2.1	*
 * S. Jacobs/NCEP	 1/97	Copied from XRAREA			*
 * J. Cowie/COMET	 1/97	Changed common variable names		*
 * J. Cowie/COMET	12/97	Added cfl_clos if error on cfl_seek	*
 * S. Chiswell/Unidata	 8/06	Added multibyte image check		*
 ***********************************************************************/
{
	FILE		*fp;
	char		defdir[12];
	long		lofset;
	unsigned int	iboff;
	int		lstrt, ii, jj, kk, nbin, ier;
	unsigned char	*rwdptr, *imdptr, buf[8];
	int		isPNG = 0;
/*---------------------------------------------------------------------*/

    if ( imdpth <= 0 ) {
	*iret = G_NIDSIZ;
	return;
    }
/*
 *  Open the file and seek to data offset.
 */
    defdir[0] = CHNULL;
    fp = cfl_ropn ( imgnam, defdir, &ier );
    if  ( ier != 0 )  {
	*iret = G_NIMGFL;
	return;
    }
    else {
	lofset = (long) imdoff;
	cfl_seek ( fp, lofset, SEEK_SET, &ier );
	if  ( ier != 0 )  {
	    cfl_clos ( fp, &ier );
	    *iret = G_NIMGFL;
	    return;
	}
	/* See if this is a png compressed AREA file */
	cfl_read ( fp, 8, buf, &nbin, &ier);
	if ( ( *iret == 0 ) && ( nbin == 8 ) ) {
            /*
            ** Check PNG magic word (8 first bytes):
            ** http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html
            ** decimal     -  137 80 78 71 13 10   26 10
            ** hexadecimal -   89 50 4e 47 0d 0a   1a 0a
            ** ASCII       - \211  P  N  G \r \n \032 \n
            */

            if ( buf[0] == (unsigned char)137 && buf[1] == (unsigned char) 80 &&
                buf[2] == (unsigned char) 78 && buf[3] == (unsigned char) 71 &&
                buf[4] == (unsigned char) 13 && buf[5] == (unsigned char) 10 &&
                buf[6] == (unsigned char) 26 && buf[7] == (unsigned char) 10     ) {
		isPNG = 1;
	    }
	}
	cfl_seek ( fp, lofset, SEEK_SET, &ier );
    }
    *iret = G_NORMAL;
/*
 *  If this file contains only one channel (band) and no line
 *  prefix data, read the raw data directly into imgData and exit.
 */
    if ( imprsz == 0 && imnchl == 1 ) {
	if ( isPNG )
	   png_read ( fp, imnpix, imnlin, imgData, &ier );
	else
	   cfl_read ( fp, imldat, imgData, &nbin, &ier );
	cfl_clos ( fp, &ier );
	crarea_pixel ( imgData );
	return;
    }
    else {
/*
 *  Allocate space for the raw image data.
 */
	if  ( ( rawData == (unsigned char *) NULL ) ||
		( imldat > (int)last_rawsize) ) {
	    if  ( rawData != (unsigned char *) NULL) {
		free(rawData);
	    }
	    rawData = (unsigned char *) calloc ( imldat,
			sizeof(unsigned char) );
	    if  ( rawData == (unsigned char *) NULL ) {
		*iret = G_NMEMRY;
		return;
	    }
	    last_rawsize = imldat;
	}
/*
 *  Read the raw image data.
 */
	if ( isPNG )
	   png_read ( fp, imnpix, imnlin, imgData, &ier );
	else
	   cfl_read ( fp, imldat, rawData, &nbin, &ier );
	cfl_clos ( fp, &ier );

    }
/*
 *  Process the prefix bytes and move data for the
 *  image channel into the imgData array.
 *
 *  NOTE: This has been tested for images with prefix bytes.
 *	  Have not tested any image files with multiple channels
 *	  in the file.
 */
    imdptr = imgData;

    for ( ii = 0; ii < imnlin; ii++ ) {
/*
 *  Calculate the starting byte in rawData for this line.
 */
	lstrt = ii * (imnpix * imdpth * imnchl + imprsz);
	rwdptr = &rawData[lstrt];
/*
 *  Process prefix data to each line, if any.
 *  iboff = band offset in each element.
 */
	iboff = 0; 
	if  ( imprsz != 0 ) {
/*
 *  Skip 4 bytes of validity code.
 */
	    if  ( imvald != 0 )  rwdptr += 4;
/*
 *  Skip documentation and calibration code.
 */
	    rwdptr += imdcsz + imclsz;
/*
 *  Process level map to get the band for each element,
 *  if necessary.
 */
	    if  ( imnchl > 1) {
/*
 *  Get the band offset.
 */
		for ( kk = 0; kk < imlvsz; kk ++ ) {
		    if  ( *rawData == 8 ) {
			iboff = kk;
			rwdptr += imlvsz - kk;
			break;
		    }
		    else {
			rwdptr ++;
		    }
		}
	    }
	    else {
/*
 *  Skip the level map.
 */
		rwdptr += imlvsz;
	    }
	}  /* End of "if  ( imprsz != 0 )"  */
/*
 *  Get the image data.
 */
	for ( jj = 0; jj < imnpix; jj++ ) {
	    for ( kk = 0; kk < imdpth; kk++ ) {
		*imdptr++ = *(rwdptr + iboff);
		rwdptr ++;
	    }
	}
    }  /* End of loop over imnlin  */
    crarea_pixel ( imgData );
}
Beispiel #8
0
void cvg_writeD ( VG_DBStruct *el, int start, int numbytes, 
						FILE *fp, int *iret )
/************************************************************************
 * cvg_writeD								*
 *									*
 * This function writes an element record to an opened VG file.		*
 * *WITHOUT* consideration of placement.  This gives the option of using*
 * VG files without needing device transformations (which placement     *
 * will need to get the meta data populated).                           *
 * NOTE: This is actually the original cvg_write, so the log has been   *
 * kept from that version.                                              *
 *									*
 * cvg_writeD  ( el, start, numbytes, fp, iret )			*
 *									*
 * Input parameters:							*
 *	*el		VG_DBStruct 	Pointer toVG record structure	*
 *	start		int		Offset to start VG record	*
 *	numbytes	int		Number of bytes to be written	*
 *	*fp		FILE		file pointer to VG file		*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					 -3 = seek to a bad location	*
 *					-17 = error writing to VG file	*
 *					-30 = invalid color(s)   	*
 *					-47 = no proper file specified	*
 *									*
 **									*
 * Log:									*
 * J. Wu/GSC		02/01	Created based on cvg_writelm()		*
 * S. Jacobs/NCEP	 2/01	Added machine type MTLNUX		*
 * E. Safford/GSC	07/01	add frees for all error returns		*
 * J. Wu/SAIC		10/02	use memcpy() to speed up performance	*
 * T. Piper/SAIC	12/02	Only use tmp_el when necessary		*
 * T. Piper/SAIC	12/02	Added -2 option for start		*
 * T. Lee/SAIC		11/03	used cvgcmn.h				*
 * J. Wu/SAIC		01/04	add cvg_writgfa for GFA_ELM		*
 * B. Yin/SAIC		02/04	added cvg_writtca for TCA_ELM		*
 * B. Yin/SAIC		05/04	copy entire el to tmp_el      	 	*
 * B. Yin/SAIC		07/04	Fixed a bug when grouping TCA  	 	*
 * E. Safford/SAIC	06/07	pass lower level cvg error code upward	*
 ***********************************************************************/
{
    int		ier;
    VG_DBStruct	*tmp_el;
    Boolean	cflError = False;
/*---------------------------------------------------------------------*/
/*
 *  Verify the file pointer.
 */         
    if ( fp == NULL )
    {
        *iret = -47;
	return;
    }

/*
 *  Check the proper color settings.
 */
    if ( el->hdr.maj_col < 0 || el->hdr.maj_col > 32 || 
	 el->hdr.maj_col < 0 || el->hdr.min_col > 32 )  {
	*iret = -30;	
	return; 
    } 

/* 
 *  Seek to the specified location.
 */
    if ( start == -2 ) { 
	ier = 0;
    }
    else if ( start == -1 ) { 
        cfl_seek( fp, 0, SEEK_END, &ier ); 
    }
    else {
       cfl_seek( fp, (long)start, SEEK_SET, &ier );
    }

    if ( ier != 0 )  {
        *iret = -3;
	return; 
    }
    *iret = G_NORMAL;

/*
 *  Swap bit order of VG elements if necessary.
 *  Use tmp_el to avoid actually changing data in el when swapping.
 */
    if ( MTMACH == MTULTX ||
    	 MTMACH == MTALPH ||
	 MTMACH == MTLNUX ) {
        tmp_el = (VG_DBStruct *) malloc ( sizeof(VG_DBStruct) );
        memcpy ( tmp_el, el, sizeof(VG_DBStruct) );
	if ( numbytes == sizeof( VG_HdrStruct ) ) {
 	    cvg_swap( SWPHDR, G_FALSE, *tmp_el, tmp_el, &ier );  
	} 
 	else {
	    cvg_swap( SWPALL, G_FALSE, *tmp_el, tmp_el, &ier );  
	} 

	if ( el->hdr.vg_type == GFA_ELM ) {
	    cvg_writgfa ( fp, tmp_el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCA_ELM ) 
		 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtca ( fp, tmp_el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCERR_ELM ) 
		 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtce ( fp, tmp_el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCTRK_ELM ) 
		 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtct ( fp, tmp_el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCBKL_ELM ) 
		 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtcb ( fp, tmp_el, &ier );
	}
	else {
	    cfl_writ( fp, numbytes, (unsigned char *)tmp_el, &ier);
	    if( ier < 0 ) {
		cflError = True;
	    }
	}

	free(tmp_el);
    }	
    else {
	if ( el->hdr.vg_type == GFA_ELM ) {
	    cvg_writgfa ( fp, el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCA_ELM )
                 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtca ( fp, el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCERR_ELM )
                 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtce ( fp, el, &ier );
        }
	else if (   ( el->hdr.vg_type == TCTRK_ELM )
                 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtct ( fp, el, &ier );
	}
	else if (   ( el->hdr.vg_type == TCBKL_ELM )
                 && ( numbytes != sizeof( VG_HdrStruct ) ) ) {
	    cvg_writtcb ( fp, el, &ier );
	}
	else {
	    cfl_writ( fp, numbytes, (unsigned char *)el, &ier);
	    if( ier < 0 ) {
                cflError = True;
            }
	}
    }
    if ( ier < 0 ) {
        if( !cflError ) {
            *iret = ier;
        }
        else {
            *iret = -17;
        }
    }
}