Exemplo n.º 1
0
void grdnav_init()
{
  int ier, iret, nitm;
  char buf[255], subst[255], *cpos;
  FILE *fp;
  nav_list *q;

  if ( ( fp = cfl_tbop ( "grdnav.tbl", "grid", &ier) ) != NULL ) {
    while ( ier == 0 ) {
      cfl_trln ( fp, sizeof(buf), buf, &ier);
      if  ( ( ier == 0 ) && ( ( q = (nav_list *)malloc( sizeof(nav_list) ) ) != NULL ) ) {

	cpos = cst_split( buf, ' ', sizeof(subst)-1, subst, &iret);
        if ( iret == 0 ) {
	  cst_ncpy(q->id,subst,sizeof(q->id)-1, &iret);
	  cst_ldsp(cpos, cpos, &nitm, &iret);
	}

	cpos = cst_split( cpos, ' ', sizeof(subst)-1, subst, &iret);
        if ( ( iret == 0 ) && ( cpos != NULL ) ) {
          iret = sscanf(subst,"%d",&(q->gnum));
	  cst_ldsp(cpos, cpos, &nitm, &iret);
	}
        else {
          free(q);
          continue;
        }

	cpos = cst_split( cpos, ' ', sizeof(subst)-1, subst, &iret);
        if ( ( iret == 0 ) && ( cpos != NULL ) ) {
	  cst_ncpy(q->proj,subst,sizeof(q->proj)-1, &iret);
	  cst_ldsp(cpos, cpos, &nitm, &iret);
	}
	else {
          free(q);
          continue;
        }

	iret = sscanf(cpos,"%f %f %f %f %f %f %f %d %d",
			&(q->angle[0]), &(q->angle[1]), &(q->angle[2]),
			&(q->llt), &(q->lln), &(q->ult), &(q->uln),
			&(q->kx), &(q->ky) );
        if ( iret == 9 ) {
	   q->next = nav_head;
	   nav_head = q;
        }
        else {
	   free(q);
	}
      }
    }
  }

  
}
Exemplo n.º 2
0
void mainw_setIconName ( char* iconName )
/************************************************************************
 * mainw_setIconName 							*
 *									*
 * This function sets the toplevel icon name.				*
 *									*
 * void mainw_setIconName(iconName)					*
 *									*
 * Input parameters:							*
 *  iconName	 char*          proposed icon name			*
 *									*
 * Output parameters:							*
 * Return parameters:							*
 *		 NONE							*
 *									*
 **									*
 * Log: 								*
 * H. Zeng/SAIC		09/04   initial coding				*
 * E. Safford/SAIC	07/07	use defined COMPONENT_LEN		*
 ***********************************************************************/
{
  static char  icon_name[ COMPONENT_LEN ];
  int	       ier;
/*---------------------------------------------------------------------*/

        if ( _topLevel != NULL ) {

          cst_ncpy ( icon_name, iconName, 120, &ier );
	  XtVaSetValues( _topLevel, XmNiconName, icon_name, NULL);
        }

}
Exemplo n.º 3
0
void utl_ctim ( int len, char *curtim, int *iret )
/************************************************************************
 * utl_ctim                                                             *
 *                                                                      *
 * This function retrieves the current system time and converts it to   *
 * a character string of the form DDHHMM.				*
 *                                                                      *
 * utl_ctim ( len, curtim, iret )  					*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 *	len		int		Max length of 'curtim'		*
 * Output parameters:                                                   *
 *	*curtim		char		Current time as DDHHMM		*
 *      *iret           int		Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/NCEP	5/03		From VFCTIM  			*
 * B. Yin/SAIC          3/04   changed css_date calling sequences       *
 ***********************************************************************/
{
    char    dattim[7], zone[4];
    int     itype, iyr, imon, idy, ihr, imin, isc, julian, ier;
/*-------------------------------------------------------------------*/
    *iret = 0;
    itype = 1;
    curtim[0] = '\0';

   /*
    * Get current system time for UTC issue time of cancel product.
    */

    css_date ( &itype, &iyr, &imon, &idy, &ihr, &imin, &isc, &julian, 
               zone, iret);

    if ( (idy >= 1) && (idy <= 9 ) ) {
	cst_ncpy( curtim, "0", 1, &ier);
    }
    cst_inch ( idy, dattim, iret);
    cst_ncat (curtim, dattim, &len, iret);

    if ( (ihr >= 0) && (ihr <= 9 ) ) {
	cst_ncat( curtim, "0", &len, iret);
    }
    cst_inch ( ihr, dattim, iret );
    cst_ncat (curtim, dattim, &len, iret);

    if ( (imin >= 0) && (imin <= 9 ) ) {
	cst_ncat( curtim, "0", &len, iret);
    }
    cst_inch ( imin, dattim, iret );
    cst_ncat (curtim, dattim, &len, iret);
}
Exemplo n.º 4
0
void wbc_mzrm ( char *states, char *ststr, int *len1, int *iret )
/************************************************************************
 * wbc_mzrm								*
 *                                                                      *
 * This function removes the specific marine zones listed above from	*
 * the state id string. 						*
 *                                                                      *
 * wbc_mzrm ( states, len1, len2, stzstr, sttstr, iret )		*
 *                                                                      *
 * Input parameters:                                                    *
 *	*states		char		String of state ids		*
 *                                                                      *
 * Output parameters:                                                   *
 *	*ststr		char		States id string; no Mar. Zones *
 *	*len1		int		Length of ststr			*
 *      *iret           int		Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/NCEP          5/03						*
 * A. Hardy/NCEP          9/04		Added "SL"			*
 * T. Piper/SAIC	02/05	Removed unused variable 'stnam'		*
 ***********************************************************************/
{
    int     ii, ier, ilen, ipos;
/*-------------------------------------------------------------------*/
    *iret = 0;
    ier   = 0;
    ststr[0] = '\0';

   /*
    * Remove unwanted marine zones listed above from state strings.
    */

    ii = 0;

    while ( ( ii <  NUM_ZNS ) ) {
	cst_rmst ( states, _mzones[ii], &ipos, states, &ier);
	if ( ipos > 0 ) {
            cst_rxbl ( states, states, &ilen, &ier);
	}
	ii++;
    }

    cst_lstr ( states, &ilen, &ier );
    cst_ncpy ( ststr, states, ilen, &ier );
}
Exemplo n.º 5
0
void gb2_ctim ( int time, char *param )
/************************************************************************
 * gb2_ctim								*
 *									*
 * This routine replaces the "--" characters in a GEMPAK parameter      *
 * string with the number specified in variable time.                   *
 *									*
 * gb2_ctim ( time, param )	                			*
 *									*
 * Input parameters:							*
 *	time  	        int             Integer time range              *
 *									*
 * Input/Output parameters:						*
 *      *param         char             GEMPAK parameter string         *
 **									*
 * Log:									*
 * S. Gilbert       12/04                                               *
 * T. Piper/SAIC	07/06	Replaced strncpy with cst_ncpy		*
 ***********************************************************************/
{
    int  ier, len;
    char ctim[12], dash[]="--", *cptr;

    /*
    **   Convert integer to character
    */
    if ( time != IMISSD ) 
       if ( time >= 0 && time < 10 )
          sprintf ( ctim, "%.2d", time);
       else
          cst_inch ( time, ctim, &ier);
    else 
	cst_ncpy(ctim, "XX", 2, &ier);

    /*
    **   replace "--" or append time character in parameter string.
    */
    cptr = strstr( param, dash);
    if ( cptr != 0 )
       cst_rpst( param, dash, ctim, param, &ier);
    else
       if ( time > 0 )  cst_ncat( param, ctim, &len, &ier);

}
Exemplo n.º 6
0
void utl_gmon ( int dtmonth, char *pmm, int *iret )
/************************************************************************
 * utl_gmon								*
 *									*
 * This function converts the numerical value of a month into the three	*
 * character abbreviation for the month.				*
 *									*
 * utl_gmon ( dtmonth, pmm, iret )					*
 *									*
 * Input parameters:							*
 *	dtmonth		int		Month				*
 *									*
 * Output parameters:							*
 *	*pmm		char		3-character month name		*
 *	*iret		int		Return code			*
 *					   -6 = Bad month number 	*
 **									*
 * Log:									*
 * A. Hardy/NCEP	 7/03						*
 * A. Hardy/NCEP	 8/03		Changed length check 4 -> 3	*
 ***********************************************************************/
{
        int	len1, lenp, ier;
	char	noname[12][4] = { "JAN", "FEB", "MAR", "APR", "MAY",
				 "JUN", "JUL", "AUG", "SEP", "OCT",
				 "NOV", "DEC" };
/*---------------------------------------------------------------------*/
	*iret   = 0;
	lenp    = 4;
	pmm[0]  = '\0';
   /*
    *	Retrieve the 3 character month.
    */
	if ( dtmonth >= 1 && dtmonth <= 12 ) {
	    len1 = G_MIN ( lenp, 3 );
	    cst_ncpy ( pmm, noname[dtmonth-1], len1, &ier);
	}
	else {
	    *iret = -6;
	    return;
	}
}
Exemplo n.º 7
0
void de_mbr1 ( const int *k, const char *infl, char *outfl, int *iret )
/************************************************************************
 * de_mbr1								*
 *									*
 * This subroutine parses a GDFILE entry to find and handle ensemble 	*
 * specifications.  It is called from DG_NFIL.  The routine turns an 	*
 * ensemble entry into a single entry that DG_NFIL can handle.  	*
 *									*
 * de_mbr1 ( k, infl, outfl, iret )					*
 *									*
 * Input parameters:							*
 *	*k		const int	GDFILE entry position number	*
 *	*infl		const char	Input file entry		*
 *									*
 * Output parameters:							*
 *	*outfl		char*		Output file replaces INFL	*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 *					 -2 = grid file or template not	*
 *						exist			*
 *									*
 * Log:									*
 * T. Lee/SAIC		12/04						*
 * T. Lee/SAIC		06/05	Parsed weight value			*
 * R. Tian/SAIC		12/05	Translated from Fortran			*
 * m.gamazaychikov/SAIC 04/06   Added idtmch flag to CTB_DTGET CS       *
 * T. Piper/SAIC	04/07	Modified for cfl_scnt CSC		*
 * F. J. Yen/NCEP	 4/08	Added bin mins & mstrct to CTB_DTGET CSC*
 * S. Jacobs/NCEP	12/11	Fixed check if there is no table entry	*
 * 				returned by ctb_dtget			*
 ***********************************************************************/
{
    int index, nfarr, ic, is, iff, ir, ii, ino, ihb, mnb, iha, mna,
	mstrct, idtmch, nfile, istar, last, len, ier;
    long lens;
    char lsv[MXFLSZ], newfil[MXFLSZ], filnam[MXFLSZ], cycle[DTTMSZ],
        path[MXFLSZ], tmplt[MXFLSZ], dum[DTTMSZ], rplc[DTTMSZ], membr[17];
    char *opnptr, *clsptr, *starp, *ptr, **farr, *def = " ";
    struct dirent **dnlist=NULL;
/*----------------------------------------------------------------------*/
    *iret = 0;
    outfl[0] = '\0';

/*
 * Check if INFL contains a curly-bracket enclosed ensemble spec.
 * If not, the first entry is not an ensemble grid.  Do nothing.
 */
    opnptr = strchr ( infl, '{' );
    if ( ! opnptr ) {
        strcpy ( outfl, infl );
	return;
    }

/*
 * Save the string between curly brackets to ensspc (k).  Get
 * the first element of the file(s). 
 */
    cst_opcl ( infl, opnptr, &clsptr, &ier );
    if ( ier != 0 ) {
        *iret = -2;
	return;
    }
    for ( index = 0, ptr = opnptr + 1; ptr < clsptr; index++, ptr++ ) {
        _ensdiag.ensspc[*k-1][index] = *ptr;
    }
    _ensdiag.ensspc[*k-1][index] = '\0';

    clsptr = strchr ( _ensdiag.ensspc[*k-1], ',' );
    if ( ! clsptr ) {
        strcpy ( lsv, _ensdiag.ensspc[*k-1] );
    } else {
        for ( index = 0, ptr = _ensdiag.ensspc[*k-1];
	      ptr < clsptr; index++, ptr++ ) {
	    lsv[index] = *ptr;
	}
	lsv[index] = '\0';
    }

/*
 * If file name is not an alias, do nothing.
 */
    cfl_inqr ( lsv, NULL, &lens, newfil, &ier );
    if ( ier == 0 ) {
        strcpy ( outfl, lsv );
	return;
    }

/*
 * Get the template.  If the template does not end with "*", 
 * do nothing.
 */
    farr = (char **)cmm_malloc2d ( 2, MXFLSZ, sizeof(char), &ier );
    if ( strchr ( lsv, '%' ) ) {
        cst_clst ( lsv, '%', def, 2, MXFLSZ, farr, &nfarr, &ier );
	strcpy ( lsv, farr[1] );
    }
    cst_clst ( lsv, '|', def, 2, MXFLSZ, farr, &nfarr, &ier );
    strcpy ( filnam, farr[0] );
    strcpy ( cycle, farr[1] );
    cmm_free2d ( (void **)farr, &ier );
    ctb_dtget ( filnam, path, tmplt, &ic, &is, &iff, &ir, &ii, &ino,
                &ihb, &mnb, &iha, &mna, &mstrct, &idtmch, &ier );
    if ( ier != 0 ) {
        strcpy ( outfl, lsv );
	return;
    }
    else {
	starp = strchr ( tmplt, '*' );
	istar = (int)( starp - tmplt );
	if ( ! starp ) {
	    strcpy ( outfl, lsv );
	    return;
	}
    }

/*
 * If the template contains an "*", then it is an ensemble with
 * multiple members.  The last member is the one sought.
 */
    if ( strcmp ( cycle, def ) != 0 ) {
	cti_stan ( cycle, "YYMMDD/HHNN", dum, &ier );
	if ( strstr ( tmplt, "YYYYMMDD" ) ) {
	    strcpy ( rplc, "YY" );
	    strncat ( rplc, dum, 6 );
	    rplc[8] = '\0';
	    cst_rpst ( tmplt, "YYYYMMDD", rplc,	tmplt, &ier );
	} else {
	    strncpy ( rplc, dum, 6 );
	    rplc[6] = '\0';
	    cst_rpst ( tmplt, "YYMMDD", rplc, tmplt, &ier );
	}
	strncpy ( rplc, &dum[7], 2 );
	rplc[2] = '\0';
	cst_rpst ( tmplt, "HH", rplc, tmplt, &ier );
    }

/*
 * Retrieve the last member of the ensemble alias.
 */
    cfl_scnt ( path, tmplt, -1, &dnlist, &nfile, &ier );
    if ( nfile == 0 ) {
	*iret = -2;
	er_wmsg ( "DE", iret, " ", &ier, strlen("DE"), strlen(" ") );
	return;
    }
    strcpy ( newfil, dnlist[0]->d_name );
    for (ii=0;ii<nfile;ii++){
	free(dnlist[ii]);
    }
    if ( dnlist != NULL ) free(dnlist);

/*
 * Replace "*" in the template with member names.  Note
 * that "*" may be embedded in the template.
 */
    if ( *(starp+1) == '\0' ) {
	last = G_TRUE;
    } else {
	last = G_FALSE;
    }
    if ( last == G_TRUE ) {
	strcpy ( membr, &newfil[istar] );
    } else {
	len = strlen ( newfil ) - strlen ( tmplt ) + 1;
	cst_ncpy ( membr, &newfil[istar], len, &ier );
    }

/*
 * Recombine the alias and last member with the cycle.
 */
    strcpy ( outfl, filnam );
    strcat ( outfl, ":" );
    strcat ( outfl, membr );
    if ( strcmp ( cycle, def ) != 0 ) {
        strcat ( outfl, "|" );
	strcat ( outfl, cycle );
    }

    return;
}
Exemplo n.º 8
0
void srchw_fosdMarkrep ( srchinfo_t *srch_info, char *text_rep, 
			char *srch_str, int called_from, int *iret )
/************************************************************************
 * srchw_fosdMarkrep							*
 *									*
 * This routine will search for the search string of each report and	*
 * the beginning position and save that position in a structure.        *
 *									*
 * srchw_fosdMarkrep (srch_info, text_rep, srch_str, called_from, iret) *
 *									*
 * Input parameters:                                                    *
 *      *srch_info	srchinfo_t	Search structure 		*
 *      *text_rep	char		file contents			*
 *      *srch_str	char		search string 			*
 *      called_from     int     	Indicate from where it is called*
 *                                	  1 - from user click           *
 *                                	  2 - from auto-update          *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret           int             Return code                     *
 **									*
 * Log:									*
 * D.Plummer/NCEP	12/95		Reorganize for fosd type W      *
 * L.Williams/EAI	6/96		Check for duplicate reports	*
 * R.Tian/SAIC  	1/02		Avoid possible overflow buf	*
 * R. Tian/SAIC		11/03		Added called_from arg		*
 * E. Safford/SAIC	12/07	rm direct access to textW widget	*
 ***********************************************************************/
{

char	*str, t_str[15];
char	buf[REPMAX];
int	ibeg, ipos;
int	flag;
int	replen;
int	index, ier;
char	notfound_msg[80];
char	exceeds_msg[80];

struct data_file_info *file_info;
struct directory_info *dir_info;

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

	ipos=0;
	flag=0;
	file_info = &(srch_info->file_info);
	dir_info  = &(srch_info->dir_info);

	ibeg = file_info->file_len - 1;

	_cache[0] = '\0';
        while ( ( ipos >= 0 ) && ( *iret == 0 ) ) {

/*
 *  Locate the starting position of each report
 */

		cst_srch( ibeg, 0, srch_str, text_rep,
			 &ipos, iret );	 
/*
 *  Copy report into a temporary buffer
 */

		replen = G_MIN((ibeg - ipos), (REPMAX - 1));
		strncpy(buf, &text_rep[ipos], (size_t)replen);
		buf[replen] = '\0';

/*
 *  Advance to the correct line
 */
		str = strtok(buf, DELMTR);
		if ( str != NULL ) {
			str = strtok(NULL, DELMTR);
			str = strtok(NULL, DELMTR);
		}

		if ( str ) {

		   str = strtok(str, " ");

/*
 *  Get the station and the WMO id 
 */
		   while ( str ) {
			if ( isalpha(str[0]) ) {

			    if ( flag == 0 ) {
				strcpy(t_str, str);
				flag = 1;
			    }
			    else {
				if ( repnum < MAX_REPORTS ) {

			           sprintf(reportInfo[repnum].stnid, " %s ", str);
				   index = srchw_binSrch( stnList.srchstr, stnList.nstn, 
					reportInfo[repnum].stnid );

				   if( index >= 0 ) {
                                       if( strncmp( _cache, &(text_rep[ipos+CACHE_POS]), 30 ) != 0 ) {

						reportInfo[repnum].stnindex = index;
				           	reportInfo[repnum].position = ipos;
				           	sprintf(reportInfo[repnum].fname, "%s/%s",
						    dir_info->dirpath, 
						    dir_info->filnam[srch_info->dir_info.cfilnum] );
	        		   		repnum++;
						cst_ncpy( _cache, &(text_rep[ipos+CACHE_POS]), 30, iret );
				       }
				   }
				   else {
                    			sprintf( notfound_msg, 
						"PRODUCT STATION \"%s\" not found in table.\n", 
						reportInfo[repnum].stnid );
					if ( called_from == 1 ) {
					    pdata_setReportText( notfound_msg, &ier );
					    txtw_dsplyReport( &ier );
					}
					reportInfo[repnum].stnid[0] = '\0';
				   }

				}	
				else {
				    sprintf( exceeds_msg, 
					     "Report limit reached (%d) -- "
					     "Reduce Time Covered.\n",
					     MAX_REPORTS );
				    if ( called_from == 1 ) {
					pdata_setReportText( exceeds_msg, &ier );
					txtw_dsplyReport( &ier );
				    }
				}
			    }
			}
			else {
			   flag = 0;
			   break;
			}
			str = strtok(NULL, " ");
		   }
		}
		ibeg = --ipos;
        }
	stnList.nreports = repnum;
}
Exemplo n.º 9
0
void nsf_gtim ( int index, dttms_t endtim, int mrange, int intrvl, 
		Boolean jflag, int *idelrt, int *ntime,
		dttms_t timarr[], int *iret )
/************************************************************************
 * nsf_gtim								*
 *									*
 * This routine returns an array of times for the requested SFC data.	*
 *									*
 * nsf_gtim ( index, endtim, mrange, intrvl, jflag, idelrt, ntime,	*
 *		timarr, iret )						*
 *									*
 * Input parameters:							*
 *	index		int		Index to attribute arrays	*
 *	endtim		dttms_t		End time of range		*
 *	mrange		int		Minutes in time range		*
 *	intrvl		int		Minutes in time interval	*
 *	jflag		Boolean		Reference time flag		*
 *									*
 * Input and output parameters:						*
 * 									*
 *	*idelrt		int		Minutes in delta reference time	*
 *									*
 * Output parameters:							*
 *	*ntime		int		Number of times in array	*
 *	timarr[ntime]	dttms_t		Array of times			*
 *	*iret		int		Return code			*
 *					   As for NIM_TLST		*
 *									*
 **									*
 * S. Jacobs/NCEP	 6/99	Created					*
 * S. Law/GSC		06/00	MAXSFC -> MAXTMPLT			*
 * R. Curtis/EAI	10/00   Changed MXTIME to MXNMFL		*
 * T. Lee/SAIC		08/03	Added time interval to calling sequence	*
 * T. Lee/SAIC		01/04	Added reference time flag		*
 * T. Lee/SAIC		04/04	Added delta reference time		*
 ***********************************************************************/
{

	int		iflag, nt, lenstr, ipos1, ipos2, ier, ierr;
	char		timstr[MXNMFL*20];

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

	*iret = 0;

/*
 *	Check for a valid index value.
 */
	if  ( index < 0 || index >= MAXTMPLT )  {
	    *iret = -1;
	    return;
	}

/*
 *	Clear the output string.
 */
	memset ( timstr, 0, sizeof(timstr) );

/*
 *	Given the image type and info, get a list of the MAXTIM latest
 *	times in a single string, separated by semi colons.
 */
	iflag = (int) jflag;
	nsf_tlst ( sfcdt[index].alias, sfcdt[index].cycle,
		   &(sfcdt[index].isbcat), endtim, &mrange, &intrvl,
		   &iflag, idelrt, timstr, &lenstr, &nt, iret,
		   strlen ( sfcdt[index].alias ),
		   strlen ( sfcdt[index].cycle ),
		   strlen ( endtim ), sizeof ( timstr ) );

/*
 *	If there is an error, set the number of times to 0 and return.
 */
	if  ( *iret != 0 )  {
	    *ntime = 0;
	    return;
	}

/*
 *	Add a NULL to the end of the string of times.
 */
	timstr[lenstr] = CHNULL;

/*
 *	Parse the string of times into an array of times.
 */
	ierr   = 0;
	*ntime = 1;
	ipos1  = 0;
	while ( ierr == 0 ) {

/*
 *	    Find the next semi colon.
 */
	    cst_nocc ( timstr, ';', *ntime, 1, &ipos2, &ierr );
	    if  ( ierr != 0 )  ipos2 = strlen(timstr) + 1;

/*
 *	    Copy the time into the array.
 */
	    cst_ncpy ( timarr[*ntime-1], &timstr[ipos1],
		       ipos2-ipos1, &ier );

/*
 *	    Update the string position counter.
 */
	    ipos1 = ipos2 + 1;

/*
 *	    If there is no error, increment the time counter.
 */
	    if  ( ierr == 0 )  (*ntime)++;

	}

}
Exemplo n.º 10
0
void gdmakewmo ( GDG2_input *input, GDG2_gemgrid *gemgrid, char *chdr, 
                 int *iret )
/************************************************************************
 * gdmakewmo                                                            *
 *                                                                      *
 * This routine generates a WMO Header from user input parameter WMOHDR *
 * and gempak grid date/time info, if necessary.                        *
 *                                                                      *
 *  Usage:                                                              *
 *      gdmakewmo( input, gemgrid, chdr, iret )                         *
 *                                                                      *
 *  Input Arguments:                                                    *
 *      *input            GDG2_input       input structure for GDGRIB2  *
 *      *gemgrid          GDG2_gemgrid     grid and Gempak info         *
 *                                                                      *
 *  Output Arguments:                                                   *
 *      *chdr              char            WMO Header                   *
 *      *iret              int             Error return code.           *
 *                                           0 = Normal                 *
 **                                                                     *
 * Log:                                                                 *
 * S. Gilbert/NCEP	 8/05	Orig					*
 * S. Gilbert/NCEP	 8/05	Changed string manipulations		*
 * S. Jacobs/NCEP	 2/11	Replaced strncpy with cst_ncpy		*
 ***********************************************************************/
{
    int    ret, num, j, ier2;
    int    numparts = 3;
    char   cparts[numparts][LLMXLN], *plist[numparts], *cdef="\0";


    /*
     *  Separate WMO Header parts from user input
     */
    for ( j=0; j<numparts; j++) plist[j] = cparts[j];
    cst_clst( input->wmohdr, '/', cdef, numparts, LLMXLN, plist, &num, &ret);

    /*
     *  Set first six characters of WMO Header
     */
    if ( strlen( plist[0] ) == (size_t)6 ) {
       cst_ncpy( chdr, plist[0], 6, &ret );
    }
    else {
       *iret = -9;
       strcpy( chdr, cdef );
       return;
    }

    /*
     *  Insert space after first six characters of WMO Header
     */
    strcat( chdr, " " );

    /*
     *  Set originating center identifier.
     */
    if ( strlen( plist[1] ) == (size_t)4 ) {
       strcat( chdr, plist[1] );
    }
    else {
       strcat( chdr, "KWBC" );
    }

    /*
     *  Insert space after originating center identifier.
     */
    strcat( chdr, " " );

    /*
     *  Set Date/Time group
     */
    if ( strlen( plist[2] ) == (size_t)6 ) {
       strcat( chdr, plist[2] );
    }
    else {
       cst_ncpy ( chdr+12, gemgrid->ctime[0]+4, 2, &ier2 );
       cst_ncpy ( chdr+14, gemgrid->ctime[0]+7, 4, &ier2 );
    }

    /*
     *  Add CR-CR-LF
     */
    chdr[18] = CHCR;
    chdr[19] = CHCR;
    chdr[20] = CHLF;
    chdr[21] = CHNULL;

    return;

}
Exemplo n.º 11
0
void vfwsaw ( int *iret )
/************************************************************************
 * vfwsaw                                                               *
 *                                                                      *
 * This program opens, creates and closes the Weather Watch SAW text    *
 * product file.							*
 *                                                                      *
 * vfwsaw ( iret )                                             		*
 *                                                                      *
 * Input parameters:                                                    *
 *                                                                      *
 * Output parameters:                                                   *
 *      *iret            int            Return Code                     *
 *                                                                      *
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/GSC          8/99   Created                                 *
 * M. Li/GSC		10/99	Modified output format			*
 * A. Hardy/GSC         11/99   Added replacement watch information     *
 * A. Hardy/GSC		 2/00   Extracted from SPCTXT                   *
 * A. Hardy/GSC		 3/00   Add check for listing replacement states*
 * A. Hardy/GSC		 5/00   Changed cfl_aopn to cfl_wopn; Use       *
 *				AWIPS/WMO header ids.; removed 'NNNN'	*
 * A. Hardy/GSC		10/00   Added ck for '0' dist. anchor/vor points*
 * A. Hardy/GSC		12/00   Removed '&' from iret			*
 * A. Hardy/SAIC	10/01   Added check for old/new WMO header flag *
 * R. Tian/SAIC		06/02	Modified to meet the SPC requirement	*
 * R. Tian/SAIC		04/03	Corrected if(iret == 0) syntax error	*
 * A. Hardy/NCEP	 6/03	Change hail size to string for decimals *
 * A. Hardy/NCEP	10/03	Modified to use utl/wbc libraries and   *
 * 				added 'TEST' if a test watch		*
 * A. Hardy/NCEP	 3/04	Added wbc_mzrm				*
 * G. Grosshans/SPC	10/04	Added ADD_WATCH_APPROX check		*
 * G. Grosshans/SPC	11/05	Added LATLON_SAW_FORMAT tag to turn     *
 *				off lat-lon info at bottom of product.	*
 * S. Jacobs/NCEP	11/05	Fixed array indices for ilat and ilon	*
 * T. Piper/SAIC	12/05	Updated for cst_wrap CSC		*
 * J. Wu/SAIC		04/06	Added parameter in cst_wrap 		*
 ***********************************************************************/
{
    FILE    *ifpsaw;
    char    blank[2]={' '}, ifname[256], wtch_type[20];
    char    cname1[32], cname2[32], sep[5], cpstates[256], states[256];
    char    newname[132], tmpsaw[500], hwmstr[500];
    char    prefs_tag[] = "LATLON_SAW_FORMAT";
    float   xx, yy;
    int     ii, jj, ier, len, ilat[4], ilon[4];
    Boolean useln;
/*-------------------------------------------------------------------*/
    ier = 0;

   /*
    *  Create output file for appending.
    */

    utl_gname ( spcinfo.ancrpt.stn1, spcinfo.ancrpt.stnnam1, 
		spcinfo.ancrpt.stateid1, &ier );
    utl_gname ( spcinfo.ancrpt.stn2, spcinfo.ancrpt.stnnam2, 
		spcinfo.ancrpt.stateid2, &ier );

    sprintf ( ifname, "WW%04d.SAW", spcinfo.wnum );
    ifpsaw = cfl_wopn ( ifname, &ier );

   /*
    * Set up header information.
    */
    if ( strcmp(spcinfo.wtype,"SEVERE THUNDERSTORM" ) == 0 ) 
                strcpy ( wtch_type, "SEVERE TSTM");
    if ( strcmp(spcinfo.wtype,"TORNADO" ) == 0 ) 
                strcpy ( wtch_type, "TORNADO");

    spcinfo.sssnum = spcinfo.wnum % 10;
    fprintf ( ifpsaw, "WWUS30 KWNS %02d%s\n", 
                      spcinfo.itime.day,spcinfo.itime.hour);
    fprintf ( ifpsaw, "SAW%d \n", spcinfo.sssnum);
    fprintf ( ifpsaw, "%cSPC AWW %02d%s\n", CHRS, 
                      spcinfo.itime.day,spcinfo.itime.hour);

   /*
    * Replace underscores in the county names with a space.
    */

    cst_rnan (  spcinfo.ancrpt.stnnam1, cname1, &ier );
    cst_rnan (  spcinfo.ancrpt.stnnam2, cname2, &ier );

   /*
    * Check if watch has been issued as a 'TEST'.
    */ 

    if ( strcmp (spcinfo.status, "TEST") == 0 ) {
        fprintf ( ifpsaw, "WW %d TEST ", spcinfo.wnum); 
    }
    else {
        fprintf ( ifpsaw, "WW %d ", spcinfo.wnum); 
    }

   /*
    * Check for the marine zones which aren't the Great Lakes or
    * coastal water (CW). Remove them, if found.
    */

    strcpy (cpstates, spcinfo.states);
    wbc_mzrm ( cpstates, states, &len, &ier );

   /*
    * Set up rest of section.
    */

    fprintf ( ifpsaw, "%s %s %02d%sZ - %02d%sZ\n",
              wtch_type, states, spcinfo.vtime.day, 
	      spcinfo.vtime.hour, spcinfo.etime.day, spcinfo.etime.hour );
    fprintf ( ifpsaw, "AXIS..%d STATUTE MILES %s OF LINE..\n",
              spcinfo.ancatt.dist, spcinfo.ancatt.dirc );

   /*
    *  Check for zero distance for anchor points.
    */
    if ( (spcinfo.ancrpt.dist1 != 0 ) && ( spcinfo.ancrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "%d%s %s/%s %s/ - %d%s %s/%s %s/\n",
                  spcinfo.ancrpt.dist1, spcinfo.ancrpt.dirct1, spcinfo.ancrpt.stn1,
                  cname1, spcinfo.ancrpt.stateid1,
                  spcinfo.ancrpt.dist2, spcinfo.ancrpt.dirct2, spcinfo.ancrpt.stn2,
                  cname2, spcinfo.ancrpt.stateid2);
    }
    else if  ( ( spcinfo.ancrpt.dist1 == 0 ) && ( spcinfo.ancrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "%s/%s %s/ - %d%s %s/%s %s/\n",
                  spcinfo.ancrpt.stn1, cname1, spcinfo.ancrpt.stateid1,
                  spcinfo.ancrpt.dist2, spcinfo.ancrpt.dirct2, spcinfo.ancrpt.stn2,
                  cname2, spcinfo.ancrpt.stateid2);
    }
    else if  ( ( spcinfo.ancrpt.dist1 != 0 ) && ( spcinfo.ancrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "%d%s %s/%s %s/ - %s/%s %s/\n",
                  spcinfo.ancrpt.dist1, spcinfo.ancrpt.dirct1, spcinfo.ancrpt.stn1,
                  cname1, spcinfo.ancrpt.stateid1, spcinfo.ancrpt.stn2,
                  cname2, spcinfo.ancrpt.stateid2);
    }
    else if  ( ( spcinfo.ancrpt.dist1 == 0 ) && ( spcinfo.ancrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "%s/%s %s/ - %s/%s %s/\n",
                  spcinfo.ancrpt.stn1, cname1, spcinfo.ancrpt.stateid1, 
		  spcinfo.ancrpt.stn2, cname2, spcinfo.ancrpt.stateid2);
    }
   /*
    * Check for zero distance for the vor points.
    */
    if ( (spcinfo.vorrpt.dist1 != 0 ) && ( spcinfo.vorrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%d%s %s - %d%s %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc,
                  spcinfo.vorrpt.dist1, spcinfo.vorrpt.dirct1, spcinfo.vorrpt.stn1,
                  spcinfo.vorrpt.dist2, spcinfo.vorrpt.dirct2, spcinfo.vorrpt.stn2);
    }
    else if ( (spcinfo.vorrpt.dist1 == 0 ) && ( spcinfo.vorrpt.dist2 != 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%s - %d%s %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc, spcinfo.vorrpt.stn1, 
		  spcinfo.vorrpt.dist2, spcinfo.vorrpt.dirct2, spcinfo.vorrpt.stn2);
    }
    else if ( (spcinfo.vorrpt.dist1 != 0 ) && ( spcinfo.vorrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%d%s %s - %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc, spcinfo.vorrpt.dist1, 
		  spcinfo.vorrpt.dirct1, spcinfo.vorrpt.stn1, spcinfo.vorrpt.stn2);
    }
    else if ( (spcinfo.vorrpt.dist1 == 0 ) && ( spcinfo.vorrpt.dist2 == 0 ) ) {
        fprintf ( ifpsaw, "..AVIATION COORDS.. %dNM %s /%s - %s/\n",
                  spcinfo.voratt.dist, spcinfo.voratt.dirc, 
		  spcinfo.vorrpt.stn1, spcinfo.vorrpt.stn2);
    }

   /*
    * Set up hail, wind gusts and lightning section.
    */

    tmpsaw[0] = '\0';
    cst_ncpy ( sep, "TO", 2, &ier );
    len = sizeof(hwmstr);
    wbc_dhwm ( sep, &(spcinfo.hailsz), &(spcinfo.maxgust), 
                &(spcinfo.maxtops), &(spcinfo.motion.deg), 
		&(spcinfo.motion.speed), len, hwmstr, &ier );
    tmpsaw[0] = '\0';
    strcat ( tmpsaw, hwmstr);
    strcat ( tmpsaw, EOL );
    cst_wrap ( tmpsaw, blank, &len, EOL, (char *)NULL, tmpsaw, &ier );
    fprintf ( ifpsaw, tmpsaw);

   /*
    *  If there are replacement watches listed, retrieve the lists of states
    *  for each replacement watch.
    */

    if ( strcmp ( spcinfo.replcnm[0], "NONE") != 0 ) {
	strcpy ( newname, "ww");
	strcat ( newname, spcinfo.replcnm[0] );
	strcat ( newname, ".txt" );
	strcpy ( newinfo.file_info.filnam,newname);
	vfrptxt (newname, iret); 
	if ( *iret == 0 ){
            wbc_mzrm ( newinfo.states, states, &len, &ier );
            fprintf ( ifpsaw, "\nREPLACES WW %d..%s \n",
	          atoi(spcinfo.replcnm[0]), states);
	}
	else {
	    fprintf ( ifpsaw, "         WW %d.. \n", 
	              atoi (spcinfo.replcnm[0]) );
        }
   /*
    *  If there are more that 1 replacement watches listed,
    *  proceed with the loop.
    */
        for(jj = 1; jj <= spcinfo.wwrepnm; jj++) {
	    strcpy ( newname, "ww");
	    strcat ( newname, spcinfo.replcnm[jj] );
	    strcat ( newname, ".txt" );
	    strcpy ( newinfo.file_info.filnam,newname);
  	    vfrptxt (newname, iret); 
	    if ( *iret == 0 ){
            wbc_mzrm ( newinfo.states, states, &len, &ier );
	    fprintf ( ifpsaw, "REPLACES WW %d..%s \n", 
	              atoi (spcinfo.replcnm[jj]), states);
	    }
	    else {
	      fprintf ( ifpsaw, "         WW %d.. \n", 
	              atoi (spcinfo.replcnm[jj]) );
	    }
        }
	fprintf ( ifpsaw, "\n");
    }
    else {
	    fprintf ( ifpsaw, "\n");
    }

    /*
     * Check if the LATLON_SAW_FORMAT flag is TRUE and then
     * add enhanced lat-lon data to the SAW text.
     * Make sure lats and lons are rounded to 
     * 100ths of deg.
     */

    tmpsaw[0] = '\0';
    ctb_pfbool (prefs_tag, &useln, &ier );
    if ( useln == TRUE ) {
	for ( ii = 0 ; ii < 4 ; ii++ ) {
            switch ( ii ) {
                case 0:
                    xx = ((int)(spcinfo.wcpnt1.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt1.lon*-100.0F)) / 100.0F;
                    break;
                case 1:
                    xx = ((int)(spcinfo.wcpnt2.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt2.lon*-100.0F)) / 100.0F;
                    break;
                case 2:
                    xx = ((int)(spcinfo.wcpnt3.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt3.lon*-100.0F)) / 100.0F;
                    break;
                case 3:
                    xx = ((int)(spcinfo.wcpnt4.lat*100.0F)) / 100.0F;
                    yy = ((int)(spcinfo.wcpnt4.lon*-100.0F)) / 100.0F;
                    break;
		default:
                    break;
            } 
            if ( yy >= 100.0F )  yy = yy - 100.0F;
            ilat[ii] = G_NINT(xx*100.0F);
	    ilon[ii] = G_NINT(yy*100.0F);
        }
        fprintf ( ifpsaw, "LAT...LON %4d%04d %4d%04d %4d%04d %4d%04d\n\n",
            ilat[0], ilon[0],
            ilat[1], ilon[1],
            ilat[2], ilon[2],
            ilat[3], ilon[3]);
    }

    /*
     * Check if the approximation verbage needs to be included
     * in the SAW text.
     */
    tmpsaw[0] = '\0';
    strcpy (prefs_tag, "ADD_WATCH_APPROX");
    ctb_pfbool (prefs_tag, &useln, &ier );

    if ( useln == TRUE ) {
       tmpsaw[0] = '\0';
       fprintf(ifpsaw, "THIS IS AN APPROXIMATION TO THE WATCH AREA.  FOR A\n");
       fprintf(ifpsaw, "COMPLETE DEPICTION OF THE WATCH SEE WOUS64 KWNS\n");
       fprintf(ifpsaw, "FOR WOU%d.\n", spcinfo.sssnum);
       fprintf(ifpsaw, "\n");
    }


   /*
    *  Close output file.
    */

    cfl_clos ( ifpsaw, &ier );
}
Exemplo n.º 12
0
void im_icmn ( int *hv, int *iret ) 	
/************************************************************************
 * im_icmn								*
 *									*
 * This subroutine sets some information in the image common header.	*
 *									*
 * im_icmn ( hv, iret )							*
 *									*
 * Input parameters:							*
 *	*hv		int		Pointer to first header variable*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *					  0 = normal return		*
 **									*
 * Log:									*
 * D.W.Plummer/NCEP      6/04   From xsicmn				*
 * T. Piper/SAIC	 09/07	Replaced strncpy with cst_ncpy.		*
 ***********************************************************************/
{
int	ier;
char	*cptr;
/*---------------------------------------------------------------------*/

	*iret = G_NORMAL;
/*
 *  Set variables - order is important here.
 *  Follow the order in the imgdef.h file.
 */
	imftyp = *hv++ ;
	imbank = *hv++ ;
	imdoff = *hv++ ;
	imldat = *hv++ ;
	imnpix = *hv++ ;
	imnlin = *hv++ ;
	imdpth = *hv++ ;
	rmxres = *(float *) hv++ ;
	rmyres = *(float *) hv++ ;
	imleft = *hv++ ;
	imtop  = *hv++ ;
	imrght = *hv++ ;
	imbot  = *hv++ ;
	rmxysc = *(float *) hv++ ;
	imbswp = *hv++ ;	
	imnchl = *hv++ ;
	imprsz = *hv++ ;
	imdcsz = *hv++ ;
	imclsz = *hv++ ;
	imlvsz = *hv++ ;
	imvald = *hv++ ;
	imrdfl = *hv++ ;
	immnpx = *hv++ ;
	immxpx = *hv++ ;
	imsorc = *hv++ ;
	imtype = *hv++ ;

	imradf = *hv++ ;
	rmbelv = *(float *) hv++ ;
	immode = *hv++ ;
	imdate = *hv++ ;
	imtime = *hv++ ;

	cptr = (char *)hv;

        cst_ncpy ( cmsorc, cptr, 20, &ier );
        cptr += 20;
        cst_ncpy ( cmtype, cptr, 8, &ier );
        cptr += 8;
        cst_ncpy ( cmstyp, cptr, 4, &ier );
        cptr += 4;
        cst_ncpy ( cmcalb, cptr, 4, &ier );
        cptr += 4;
	
}
Exemplo n.º 13
0
void ngd_gnms ( char *alias, int *nname, nmlst_t namarr[], int *iret )
/************************************************************************
 * ngd_gnms								*
 *									*
 * This routine returns an array of storm or volcano names for the	*
 * requested GRID data.							*
 *									*
 * ngd_gnms ( alias, nname, namarr, iret )				*
 *									*
 * Input parameters:							*
 *	*alias		char		Data type alias name		*
 *									*
 * Output parameters:							*
 *	*nname		int		Number of names in array	*
 *	namarr[nname]	nmlst_t		Array of names			*
 *	*iret		int		Return code			*
 *					   As for NGD_NLST		*
 *									*
 **									*
 * S. Jacobs/NCEP	 3/01	Created					*
 ***********************************************************************/
{

	int		lenstr, ipos1, ipos2, ier, ierr;

	char		namstr[MXNMFL*MXFLSZ];

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

	*iret  = 0;

/*
 *	Given the grid data type, get the list of names from the
 *	file names.
 */
 	ngd_nlst ( alias, namstr, &lenstr, iret,
		   strlen ( alias ), sizeof ( namstr ) );

/*
 *	If there is an error, set the number of names to 0 and return.
 */
 	if  ( *iret != 0 )  {
	    *nname = 0;
	    return;
	}

/*
 *	Add a NULL to the end of the string of names.
 */
	namstr[lenstr] = CHNULL;

/*
 *	Parse the string of names into an array of names.
 */
	ierr   = 0;
	*nname = 1;
	ipos1  = 0;
	while ( ierr == 0 ) {

/*
 *	    Find the next semi colon.
 */
	    cst_nocc ( namstr, ';', *nname, 1, &ipos2, &ierr );
	    if  ( ierr != 0 )  ipos2 = strlen(namstr) + 1;

/*
 *	    Copy the name into the array.
 */
	    cst_ncpy ( namarr[*nname-1], &namstr[ipos1],
		       ipos2-ipos1, &ier );

/*
 *	    Update the string position counter.
 */
	    ipos1 = ipos2 + 1;

/*
 *	    If there is no error, increment the name counter.
 */
	    if  ( ierr == 0 )  (*nname)++;

	}

}
Exemplo n.º 14
0
void css_envr ( const char *filnam, char *file, int *iret )
/************************************************************************
 * css_envr								*
 *									*
 * This routine checks filnam for an environment variable. If one is	*
 * found, it is replaced with the actual path name.  The new expanded	*
 * file name is returned.  Environment variables are identified by names*
 * beginning with $ and ending with a /.				*
 *									*
 * This routine only checks for environmental variables at the beginning*
 * of 'filnam', not embedded within the string.  Additionally, the 	*
 * environmental variable must be immediately followed by a '/' and	*
 * the remainder of the full path filename.  The environmental variable	*
 * may not be surrounded by braces, i.e., '{}'.  The old VAX syntax is	*
 * supported, in that the leading '$' may be omitted and the 		*
 * environmental variable followed by a colon ':' in which case the '/'	*
 * may be omitted.							*
 *									*
 * To summarize, if an environmental variable is used in a filename the	*
 * filname must be in one of the following formats:			*
 *									*
 * 	$ENV/dir1/dir2/.../dirN/file					*
 * 	ENV:dir1/dir2/.../dirN/file					*
 *									*
 * css_envr ( filnam, file, iret )					*
 *									*
 * Input parameters:							*
 *	*filnam		const char	User input file name		*
 *									*
 * Output parameters:							*
 *	*file		char		Expanded file name		*
 *	*iret		int		Return code			*
 *					  2 = Symbol not found		*
 **									*
 * Log:									*
 * S. Jacobs/NMC	 6/94						*
 * L. Williams/EAI	 7/94		Reformat header			*
 * S. Jacobs/NMC	 7/94		Fixed bug with getenv		*
 * G. Krueger/EAI	 3/96		ANSI, always return a file name	*
 * R. Tian/SAIC		10/04		Handle '~' in file name		*
 * D.W.Plummer/NCEP	10/06	Add colon processing (VAX syntax)	*
 * T. Piper/SAIC	03/07	Fixed '~/' case, put result in file	*
 ***********************************************************************/
{
	char	symbol[133], filtmp[73], usernm[73], *cptr;
	int	ipos, ier;
	size_t	ii, jj;
	struct passwd *pw;

/*---------------------------------------------------------------------*/
	*iret     = 0;
	file[0]   = '\0';
	symbol[0] = '\0';
	filtmp[0] = '\0';
	strcpy ( file, filnam );

/*
 *	Handle '~' in file name.
 */
 	if ( filnam[0] == '~' ) {
	    if ( filnam[1] == '/' ) {
/*
 *		'~/user'.
 */
	        cst_rpst ( filnam, "~", "$HOME", file, &ier );
	    } else {
/*
 *		'~user'.
 */
	        cst_nocc ( filnam, '/', 1, 0, &ipos, &ier );
		if ( ier == 0 ) {
		    cst_ncpy ( usernm, &filnam[1], ipos-1, &ier );
		} else if ( ier == -5 ) {
		    ipos = strlen ( filnam );
		    strcpy ( usernm, &filnam[1] );
		}
		pw = getpwnam ( usernm );
		if ( pw ) {
		    strcpy ( file, pw->pw_dir );
		    strcat ( file, &filnam[ipos] );
		} else {
		    *iret = 2;
		    return;
		}

	    }
	}
/*
 *	Find the part of the name which is an environmental variable.
 *	Translate the variable to a path name.
 */
	else if ( filnam[0] == '$' ) {
	    ii = 1;
	    while ( ( ii < strlen(filnam)+1 ) && ( filnam[ii] != '/' ) ) {
		symbol[ii-1] = filnam[ii];
		symbol[ii] = '\0';
		ii++;
	    }
	    jj = ii;
	    while ( jj < strlen(filnam)+1 ) {
		filtmp[jj-ii] = filnam[jj];
		jj++;
	    }
	    if  ( getenv ( symbol ) != NULL ) {
		strcpy ( file, getenv ( symbol ) );
		strcat ( file, filtmp );
	    } else {
		*iret = 2;
	    }
	}

/*
 * 	Search for a colon ':' and, if found, pull out and process.
 */
	else  {

	    cptr = strchr ( filnam, ':' );

	    if ( cptr != (char *)NULL )  {

		strncpy ( symbol, filnam, (size_t)(cptr-filnam) );
		symbol[(cptr-filnam)] = '\0';

	        if  ( getenv ( symbol ) != NULL ) {
		    strcpy ( file, getenv ( symbol ) );
		    strcat ( file, "/" );
		    strcat ( file, (cptr+1) );
	        } else {
		    *iret = 2;
	        }
	    }
	}
}
Exemplo n.º 15
0
void ctb_hfread ( int *iret )
/************************************************************************
 * ctb_pfread								*
 *									*
 * This function reads the info from the Hershey Fonts tables.		*
 * 									*
 * The Hershey Font coordinates are encoded using the ASCII characters.	*
 * Each character pair represents a coordinate in the drawing system	*
 * with 'R,R' as the origin. To get the coordinate values, subtract	*
 * 'R' from the given character. For example, the pair 'SB' corresponds	*
 * to (+1,-16).								*
 *									*
 * ctb_hfread ( iret )							*
 *									*
 * Input parameters:							*
 *									*
 * Output parameters:							*
 *	*iret		int		Return code			*
 *				  	  -1 = cannot open or read table*
 *				  	 -12 = cannot allocate memory	*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	10/07	Created					*
 * T. Piper/SAIC	03/08	Replaced cmm functions with Macros	*
 ***********************************************************************/
{
    FILE	*fp;
    char	buffer[256], av[6];
    int		ii, nr, ier, ifont, ier2, jj, kk, nf, one = 1;

    font_tbl_name_t   tbl[] = {	{"hfont03.tbl",  3},
				{"hfont23.tbl", 23},
				{"hfont04.tbl",  4},
				{"hfont14.tbl", 14},
				{"hfont24.tbl", 24},
				{"hfont34.tbl", 34} };
/*---------------------------------------------------------------------*/

  *iret = G_NORMAL;

/*
 * Allocate space for all of the font structures.
 */
  nf = sizeof(tbl)/sizeof(tbl[0]);
  G_MALLOC ( _hfontTbl, HF_font_t, nf, "ctb_hfread - _hfontTbl");
  if ( _hfontTbl == NULL ) {
    *iret = -12;
    return;
  }

  _nhfont = 0;
  for ( ifont = 0; ifont < nf; ifont++ )  {
/*
 *  Read the font table and add entries into the structure. 
 */
    nr = 0;
    fp = cfl_tbop ( tbl[ifont].table_name, "hershey", &ier );
    if ( ier == 0 ) { 
	cfl_tbnr ( fp, &nr, &ier);
    }
	    
    if ( nr == 0 ) {
	cfl_clos ( fp, &ier );
        *iret = -1;
        return;
    }
    _hfontTbl[ifont].font_code = tbl[ifont].font_num;

/*
 *  Allocate space for the characters.
 */
    G_MALLOC ( _hfontTbl[ifont].character, HF_char_t, nr, "ctb_hfread - _hfontTbl[ifont].character");
    if ( _hfontTbl[ifont].character == NULL ) {
	cfl_clos ( fp, &ier );
	*iret = -12;
	return;
    }
  
/*
 * Read table entries into the structure.
 */
    ii = 0;

/* Read the next line from the file */
    cfl_trln ( fp, 256, buffer, &ier );

/*
 * Process the file while there is no error and
 * the end of the file has not been reached.
 */
    while ( ier >= 0 && ier != 4 ) {

        if ( ier == 0 ) {

	    G_MALLOC ( _hfontTbl[ifont].character[ii].point_code, char,  
		    strlen(buffer)+1, " ctb_hfread - _hfontTbl[ifont].character[ii].point_code");
	    if ( _hfontTbl[ifont].character[ii].point_code == NULL ) {
		cfl_clos ( fp, &ier );
		*iret = -12;
		return;
	    }
	    strcpy ( _hfontTbl[ifont].character[ii].point_code, buffer );

/* Get the character ASCII code */
	    cst_ncpy ( av, &(buffer[0]), 5, &ier2 );
	    cst_numb ( av, &(_hfontTbl[ifont].character[ii].ascii_val),
		       &ier2 );

/*
 * Get the number of points for the character
 * (The number in the file includes the X min and max,
 *  so subtract one)
 */
	    cst_ncpy ( av, &(buffer[5]), 3, &ier2 );
	    cst_numb ( av, &(_hfontTbl[ifont].character[ii].npts),
			&ier2 );
	    (_hfontTbl[ifont].character[ii].npts)--;

/* Get the X min and max */
	    _hfontTbl[ifont].character[ii].xmin = buffer[8] - 'R';
	    _hfontTbl[ifont].character[ii].xmax = buffer[9] - 'R';

/* Get the coordinates, if the number of points is > 0 */
	    if ( _hfontTbl[ifont].character[ii].npts > 0 ) {
		G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t,
			_hfontTbl[ifont].character[ii].npts, 
			" ctb_hfread - _hfontTbl[ifont].character[ii].point");
                if ( _hfontTbl[ifont].character[ii].point == NULL ) {
		    cfl_clos ( fp, &ier );
		    *iret = -12;
		    return;
		}

/*
 * Check for " R", which denotes a "pen up".
 * If there is a pen up code, set the points to missing.
 * Otherwise, decode the coordinate values.
 */
		kk = 10;
		for ( jj = 0;
		      jj < _hfontTbl[ifont].character[ii].npts;
		      jj++ ) {
		    if ( strncmp ( &(buffer[kk]), " R", 2 ) == 0 ) {
			_hfontTbl[ifont].character[ii].point[jj].x = -99;
			_hfontTbl[ifont].character[ii].point[jj].y = -99;
			kk += 2;
		    }
		    else {
			_hfontTbl[ifont].character[ii].point[jj].x =
						buffer[kk] - 'R'; kk++;
			_hfontTbl[ifont].character[ii].point[jj].y =
						buffer[kk] - 'R'; kk++;
		    }
		}

	    }
/*
 * If there are no character codes,
 * set one point at the origin
 */
	    else {
		G_MALLOC ( _hfontTbl[ifont].character[ii].point, HF_point_t,
				one, " ctb_hfread - _hfontTbl[ifont].character[ii].point");
		if ( _hfontTbl[ifont].character[ii].point == NULL ) {
		    cfl_clos ( fp, &ier );
		    *iret = -12;
		    return;
		}
		_hfontTbl[ifont].character[ii].point[0].x = 0;
		_hfontTbl[ifont].character[ii].point[0].y = 0;
	    }
	    ii++;
        }

/* Read the next line from the file */
	cfl_trln ( fp, 256, buffer, &ier );

    }

/* Set the number of characters for the font */
    _hfontTbl[ifont].numchr = ii;

/* Close the font table */
    cfl_clos ( fp, &ier );

/* Increase the count for the number of fonts */
    _nhfont++;
  }  
Exemplo n.º 16
0
void nim_flnm ( const char *imgtyp, const char *imginf,
                char *basetm, char *endtim, int mrange,
                int intrvl, Boolean bflag, Boolean bauto, char *path,
                char ***namarr, char ***timarr, int *ntimes, int *iret )
/************************************************************************
 * nim_flnm								*
 *									*
 * This routine returns an array of file names given the image info.	*
 * The type of image, SAT or RAD, and the image info, which is the	*
 * directory of the data, are used to locate the image data files on 	*
 * disk. For satellite images, the info is the part of the directory	*
 * path that defines the source/geog_area/channel. For radar images,	*
 * the info is lcl_or_natl/area/type.					*
 *									*
 * void nim_flnm ( imgtyp, imginf, basetm, endtim, mrange, intrvl,	*
 *		   bflag, bauto, path, namarr, timarr, nfound, iret )	*
 *									*
 * Input parameters:							*
 *      *imgtyp         const char      Type of image                   *
 *      *imginf         const char      Directory information           *
 *	*basetm		char		Base time			*
 *	*endtim		char		End time of range		*
 *	mrange		int		Minutes in time range		*
 *	intrvl		int		Minutes in time interval	*
 *	bflag		Boolean		Reference time flag		*
 *	bauto		Boolean		Auto update flag		*
 *									*
 * Output parameters:							*
 *	*path		char		Full directory path		*
 *	***namarr	char		Array of all file names		*
 *	***timarr	char		Array of all file times		*
 *	*ntimes		int		Number of files/times returned	*
 *	*iret		int		Return code			*
 *					  -3 = no files found		*
 **									*
 * Log:									*
 * S. Jacobs/NCEP	 8/99	Created					*
 * S. Jacobs/NCEP	 2/00	Use the path and templ from datatype.tbl*
 * S. Jacobs/NCEP	 7/00	Moved error check to after FL_SCND call	*
 * S. Jacobs/NCEP	 8/00	Added check: len of tmpl = len of file	*
 * S. Jacobs/NCEP	 3/01	Increased file template to 48 chars	*
 * S. Jacobs/NCEP	 9/01	Ignore the non-date part of the template*
 * A. Hardy/SAIC         2/02   Changed call FL_SCND			*
 * T. Lee/SAIC		 6/02	Handled wild card template; return ipos	*
 * T. Lee/SAIC		 9/04	Replaced FL_TMPL with CTB_DTGET		*
 * A. Hardy/NCEP	11/04   Added calls to ST_RNUL			*
 * m.gamazaychikov/SAIC 12/04   Added ion flag to CTB_DTGET CS          *
 * m.gamazaychikov/SAIC 01/06   Changed ctmpl string length to MXTMPL   *
 * m.gamazaychikov/SAIC 04/06   Added idtmch flag to CTB_DTGET CS       *
 * T. Piper/SAIC	04/07	Re-wrote in 'C'; dynamic arrays		*
 * T. Piper/SAIC	10/07	Check value of nt before cti_tmln	*
 * F. J. Yen/NCEP	 4/08	Add bin mins and mstrct to CTB_DTGET CSC*
 ***********************************************************************/
{
    long istar;
    int ic, is, nf, ir, ii, kk, ion, ihb, iha, idtmch, iorder, lens;
    int imb, ima, mstrct;
    int ier, ier1, ier2, itarr[5], jtarr[5], lenf, lent, mdif, ndif, nt;
    int idir=-1, idelrt=-1, nfiles;
    size_t timlen=DTTMS_SIZE;
    /*
     *  The following dimensions are based upon the sizes in the datatype.tbl
     *  plus one for the null character; then rounded up to the neartest
     *  multiple of four.
     */
    char *pstar, **t_names=NULL, **t_times=NULL, **tarr=NULL;
    char cpath[28], ctmpl[MXTMPL], tmplt[MXTMPL];
    dattm_t strtim;
    nmlst_t tfil;
    struct dirent **dnlist=NULL;
    /*---------------------------------------------------------------------*/
    /*
     *  Construct the directory name from the image data attributes.
     */
    ctb_dtget ( (char*)imgtyp, cpath, ctmpl, &ic, &is, &nf, &ir, &ii,
                &ion, &ihb, &imb, &iha, &ima, &mstrct, &idtmch, &ier );
    strcpy ( path,  cpath );
    strcat ( path,   "/"  );
    strcat ( path, imginf );
    /*
     *  Scan the directory.
     */
    iorder = 1;
    cfl_scnt ( path, ctmpl, iorder, &dnlist, &nfiles, &ier );
    /*
     *  If there are no files, there is an error.
     */
    if ( nfiles > 0 ) {
        /*
         *  Construct the full file name template for this directory.
         */
        pstar = strchr(ctmpl, '*' );
        if ( pstar == NULL ) {
            /*  No '*' was found in the template.   */
            strcpy(tmplt, ctmpl);
        }
        else {
            /*  An '*' was found in the template.  */
            istar = ( pstar - ctmpl );
            if ( istar == 0 ) {
                /*  An '*' was found at the beginning of the template.  */
                strcpy(tmplt, (ctmpl+2));
            }
            else {
                cst_ncpy(tmplt, ctmpl, istar, &ier);
            }
        }
        /*
         *  Convert each file name to a time.
         */
        cst_lstr(tmplt, &lent, &ier );
        cst_lstr(dnlist[0]->d_name, &lenf, &ier );
        G_MALLOC(tarr, char*, nfiles, "nim_flnm:  tarr");
        for ( ii = 0; ii < nfiles; ii++ ) {
            G_CALLOC(tarr[ii], char, timlen, "nim_flnm:  tarr[ii]");
            if ( pstar == NULL ) {
                cfl_mdat(dnlist[ii]->d_name, tmplt, "YYMMDD/HHNN",
                         tarr[ii], &ier );
            }
            else {
                if ( istar == 0 ) {
                    strcpy(tfil, dnlist[ii]->d_name+(lenf-lent));
                }
                else {
                    cst_ncpy(tfil, dnlist[ii]->d_name, lent, &ier);
                }
                cfl_mdat(tfil, tmplt, "YYMMDD/HHNN", tarr[ii], &ier );
            }
        }

        /*
         *   Sort the times.
         */
        qsort( (void*)tarr, (size_t)nfiles, sizeof(char*), compare );
        cti_yyyy(nfiles, tarr, tarr, &ier);

        /*
         *  Compute the start time of the range from the end time
         *  and the number of minutes.
         */
        ti_ctoi ( endtim, itarr, &ier, strlen(endtim) );
        ti_subm ( itarr, &mrange, jtarr, &ier );
        ti_itoc ( jtarr, strtim, &ier, sizeof(strtim) );
        st_null ( strtim, strtim, &lens, &ier, sizeof(strtim), sizeof(strtim) );
        /*
         *  Find the number of times to return.
         */
        nt = 0;
        for ( ii = 0; ii < nfiles; ii++ ) {
            ti_diff ( strtim, tarr[ii], &mdif, &ier1, strlen(strtim), timlen-1 );
            ti_diff ( tarr[ii], endtim, &ndif, &ier2, timlen-1, strlen(endtim));
            if ( ( ier1 == 0 ) && ( ier2 == 0 ) ) {
                if ( ( mdif <= 0 ) && ( ndif <= 0 ) ) {
                    G_REALLOC(t_names, char*, nt+1, "nim_flnm:  t_names");
                    G_MALLOC(t_names[nt], char, (strlen(dnlist[ii]->d_name)+1),
                             "nim_flnm:  t_names[nt]");
                    strcpy(t_names[nt], dnlist[ii]->d_name);
                    G_REALLOC(t_times, char*, nt+1, "nim_flnm:  t_times");
                    G_MALLOC(t_times[nt], char, (strlen(tarr[ii])+1),
                             "nim_flnm:  t_times[nt]");
                    strcpy(t_times[nt], tarr[ii]);
                    nt++;
                }
            }
            G_FREE(tarr[ii], char);
            free (dnlist[ii]);
        }
Exemplo n.º 17
0
void mainw_setTitleName ( const char* spfName, const char *cycle )
/************************************************************************
 * mainw_setTitleName 							*
 *									*
 * This function adds the title addtion to the NMAP2 window title name.	*
 *									*
 * The nmap2 title format is:						*
 *									*
 *   "NMAP2 (Version) -- [spf file name ] -- [forecast day/cycle]"	*
 *									*
 * The spf file name is only used if an spf file has been loaded, and   *
 * the forecast day/cycle string will only be added if the prefs.tbl    *
 * file's USE_DAY_CYCLE switch is set to True and product generation is *
 * active.								*
 *									*
 * void mainw_setTitleName ( titleAdditon )				*
 *									*
 * Input parameters:							*
 *   spfName	 char*          spf file name				*
 *   cycle	 char*          forecast day/cycle time string 		*
 *									*
 * Output parameters:							*
 * Return parameters:							*
 *		 NONE							*
 *									*
 **									*
 * Log:                                                                 *
 * J. Wu/SAIC		03/05   initial coding				*
 * E. Safford/SAIC	07/07 	change input params to spfName & cycle	*
 ***********************************************************************/
{
    static char	*oldTitle, newTitle[256];

    int		nc, ier;
    Boolean	haveSpf = False, haveCycle = False;
/*---------------------------------------------------------------------*/

    if ( _topLevel != NULL ) {

	/*
	 *  Determine what inputs have been provided.
	 */
	if( spfName ) {
            cst_ncpy( _spfName, spfName, COMPONENT_LEN -1, &ier );
	    if( ier < 0 ) return;
        } 
	
	if( cycle ) {
            cst_ncpy( _dayCycle, cycle, COMPONENT_LEN -1, &ier );
	    if( ier < 0 ) return;
	}

	if( strlen( _spfName ) > 0 )  haveSpf = True;	
	if( strlen( _dayCycle ) > 0 )  haveCycle = True;	


	/*
	 *  Get the current title string.
	 */
        XtVaGetValues ( _topLevel, XmNtitle, &oldTitle, NULL );


	/*
	 *  Chop off the old title at the right ')' which is the end of
	 *  the version number in the title.
	 */
	cst_nocc ( oldTitle, ')', 1, 1, &nc, &ier );        	
	cst_ncpy ( newTitle, oldTitle, nc+1, &ier );
	       
	/*
	 *  Add the SPF file.
	 */ 
	if( haveSpf ) {
	    strcat ( newTitle, " -- " );
	    strcat ( newTitle, _spfName );
	}
	
	/*
	 *  Add the day/cycle string.
	 */	
	if( haveCycle ) {
	    strcat ( newTitle, " -- " );
	    strcat ( newTitle, _dayCycle );
	}

	/*
	 *  Display the new title.
	 */
	XtVaSetValues ( _topLevel, XmNtitle, newTitle, NULL );	
        
    }

}
Exemplo n.º 18
0
void wbc_area ( char *locnam, char *vorstr, int len, char *areastr, 
                int *iret )
/************************************************************************
 * wbc_area                                                    		*
 *                                                                      *
 * This function converts the VOR stations string to the VOR watch area *
 * string,containing distance, direction, county names and state ids.	*
 *                                                                      *
 * Input example:							*
 *   17 WNW DEC;26 E FAM;26 WNW FAM;55 SSE COU;22 NNW UIN;47 ENE UIN;	*
 *                                                                      *
 * Output example:							*
 *   17 WNW OF DECATUR, IL..TO 26 E OF FARMINGTON, MO..TO 26 WNW OF 	*
 *   FARMINGTON, MO..TO 55 SSE OF COLUMBIA, MO..TO 22 NNW OF QUINCY, 	*
 *   IL..TO 47 ENE OF QUINCY, IL.					*
 *                                                                      *
 * wbc_area ( locnam, vorstr, len, areastr, iret )   			*
 *                                                                      *
 * Input parameters:                                                    *
 *	*locnam		char	Locator type				*
 *	*vorstr		char	Polygon text string			*
 *	len		int	Max length of 'areastr'			*
 *									*
 * Output parameters:                                                   *
 *	*areastr	char	Polygon area text string		*
 *	*iret		int	Return value				*
 *			           -5 = VORSTR too big 			*
 *									*
 **                                                                     *
 * Log:                                                                 *
 * A. Hardy/NCEP	 5/03   From VF_AREA				*
 ************************************************************************/
{
	int	ii, nstn, maxlen, nstr, np, icnt, ier, exp, max, len1;
	char    tmpstr[420], holdstr[200], qstate[1], pstn[180]; 
	char    arrgrp[15], **aryvor, county[30], state[3];
/*---------------------------------------------------------------------*/
    *iret = 0;
    np = 1;
    icnt = 1;
    max  = 6;
    exp  = 4;
    qstate[0] = '\0';
    tmpstr[0] = '\0';
    maxlen = sizeof(pstn);

    if ( strcmp ( locnam, "VOR") != 0 ) {
        *iret = -2;
        return;
    }
    cst_lstr ( vorstr, &len1, &ier );
    if ( len1 >= 400 ) {
        *iret = -5;
        return;
    }

   /*
    * Set up the memory space to break up the VOR area string.
    */

    clo_init ( &ier );

    aryvor = (char **) malloc(sizeof(char *) * 4);
    for ( ii = 0; ii < 4; ii++ ) {
        aryvor[ii] = (char *) malloc(6) ;
    }

   /*
    *  Get the city and state of the VOR station.
    */

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

        vorstr = (char *) cst_split ( vorstr, ';', 12, arrgrp, &ier);

        cst_clst ( arrgrp, ' ', " ", exp, max, aryvor, &nstr, &ier);

	if ( nstr == 3 ) {

            clo_findstn ( locnam, aryvor[2], qstate, np, maxlen,
                      &nstn, pstn, &ier);

	}
	else if ( nstr == 2) {
            clo_findstn ( locnam, aryvor[1], qstate, np, maxlen,
                      &nstn, pstn, &ier);
	}

	cst_gtag ( "NAME", pstn, " ", county, &ier );
	cst_gtag ( "ST", pstn, " ", state, &ier );
	cst_rnan (county, county, &ier);

       /*
        * Create the watch area string.
        */

        holdstr[0] = '\0';

	if ( icnt < 6 ) {
	    if ( strcmp ( aryvor[0], "..") != 0 ) {
	        sprintf( holdstr," %s %s OF %s, %s..TO ",aryvor[0], 
	                 aryvor[1], county, state);
	    }
	    else {
		/*
		 * Print string for zero distance and no direction.
		 */
	        sprintf( holdstr," %s, %s..TO ", county, state);
	    }
	}
	else {
	    if ( strcmp ( aryvor[0], "..") != 0 ) {
	        sprintf( holdstr," %s %s OF %s, %s.",aryvor[0], aryvor[1],
	             county, state);
	    }
	    else {
		/*
		 * Print string for zero distance and no direction.
		 */
	        sprintf( holdstr," %s, %s.", county, state);
	    }
	}
	icnt++;
        cst_ncat ( tmpstr, holdstr, &len1, &ier);
    }

    len1 = G_MIN ( len, (int)strlen(tmpstr) );
    cst_ncpy( areastr, tmpstr, len1, &ier);

   /*
    * Free memory space.
    */

    for ( ii = 0; ii < 4; ii++ ) {
        free ( aryvor[ii] );
    }
    free ( aryvor);
}
Exemplo n.º 19
0
void ctb_rdprf ( char *tblnam, char *dirsym, char *tag, char *value, 
 		 int *iret )
/************************************************************************
 * ctb_rdprf								*
 *									*
 * This subroutine reads a prefs table and returns a single value 	*
 * associated with a single tage in the table.				* 
 *									*
 * ctb_rdprf ( tblnam, dirsym, tag, value, iret )			*
 *									*
 * Input parameters:							*
 *	*tblnam		char		Prefs table file name		*
 *	*dirsym 	char		Lowest level directory name	*
 *	*tag		char		Tags for prefs table definition	*
 *									*
 * Output parameters:							*
	*value		char		Value for prefs table tag	*
 *	*iret		int		Return code			*
 *					  -1 = table cannot be opened	*
 *					  -2 = entry not found		*
 **									*
 * Log:									*
 * M. Li/SAIC		10/04	Modified from ctb_rdwou			*
 ***********************************************************************/
{

	FILE   *ftbl;
	char   chname[25], label[120], buffer[180];
        int    ier, ilen2, lens;
	Boolean found;

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

/*
 *	Initialize output variables.
 */
	*iret     = -2;
	ilen2     = 0;
	chname[0] = '\0';
        label[0] = '\0';
        value[0] = '\0';
	found    = False;

/*
 *	Open the prefs table file.
 */
	ftbl = cfl_tbop ( tblnam, dirsym, &ier );
	if  ( ier != 0 )  {
	    *iret = -1;
	    return;
	}
	cst_lstr ( tag, &lens, &ier );

/*
 *	Read in the next record, check for a comment,
 *	and process valid table entries.
 */
	while ( ( fgets ( buffer, 180, ftbl ) != NULL ) && ( !found ) ) {
	    if  ( buffer[0] != '!' )  {
		if  ( sscanf ( buffer,"%s %s", chname, label) ) {
		    cst_rmbl ( chname, chname, &ilen2, &ier );
	            cst_lstr ( label, &lens, &ier );
		    if (strcmp ( chname, tag ) == 0 ) {
		        cst_ncpy ( value, label, lens, &ier );
			found    = True;
		        *iret    = 0;
	            }
		    else {
	                chname[0] = '\0';
                        label[0] = '\0';
		    }
		}
	    }
	}
	if ( !found ) {
	    *iret = -2;
	}

	cfl_clos ( ftbl, &ier );
}