示例#1
0
/* input solution data from stream ---------------------------------------------
* input solution data from stream
* args   : unsigned char data I stream data
*          gtime_t ts       I  start time (ts.time==0: from start)
*          gtime_t te       I  end time   (te.time==0: to end)
*          double tint      I  time interval (0: all)
*          int    qflag     I  quality flag  (0: all)
*          solbuf_t *solbuf IO solution buffer
* return : status (1:solution received,0:no solution,-1:disconnect received)
*-----------------------------------------------------------------------------*/
extern int inputsol(unsigned char data, gtime_t ts, gtime_t te, double tint,
                    int qflag, const solopt_t *opt, solbuf_t *solbuf)
{
    sol_t sol={{0}};
    int stat;
    
    trace(4,"inputsol: data=0x%02x\n",data);
    
    sol.time=solbuf->time;
    
    if (data=='$'||(!isprint(data)&&data!='\r'&&data!='\n')) { /* sync header */
        solbuf->nb=0;
    }
    solbuf->buff[solbuf->nb++]=data;
    if (data!='\n'&&solbuf->nb<MAXSOLMSG) return 0; /* sync trailer */
    
    solbuf->buff[solbuf->nb]='\0';
    solbuf->nb=0;
    
    /* check disconnect message */
    if (!strcmp((char *)solbuf->buff,MSG_DISCONN)) {
        trace(3,"disconnect received\n");
        return -1;
    }
    /* decode solution */
    if ((stat=decode_sol((char *)solbuf->buff,opt,&sol,solbuf->rb))>0) {
        solbuf->time=sol.time; /* update current time */
    }
    if (stat!=1||!screent(sol.time,ts,te,tint)||(qflag&&sol.stat!=qflag)) {
        return 0;
    }
    /* add solution to solution buffer */
    return addsol(solbuf,&sol);
}
示例#2
0
文件: sur980.c 项目: mildred/Varkon
     DBstatus    varkon_sur_order (

/*!------------- Argument declarations -----------------------------*/
/*                                                                  */
/* In:                                                              */
   DBVector *p_refpt,    /* Comparison point (R*3 or U,V)     (ptr) */
   EVALS    xyz_in[],    /* All input  (solution) points            */
   DBint    n_inpts,     /* Number of input  points                 */
   DBint    ocase_in,    /* Ordering case                           */
                         /* See below in program !!!!!              */
/* Out:                                                             */
   EVALS    xyz_out[],   /* All output (solution) points            */
   DBint   *p_n_outpts ) /* Number of output points           (ptr) */
/*                                                                  */
/*-----------------------------------------------------------------!*/

{ /* Start of function */

/*!--------------- Internal variables ------------------------------*/
/*                                                                  */
   DBint   ocase;        /* Ordering case                           */
   DBint   i_pt;         /* Loop index point                        */
   DBint   i_o;          /* Loop index outer                        */
   DBint   i_i;          /* Loop index inner                        */
   DBint   i_min;        /* Element number for min_dist             */
   DBfloat min_dist;     /* Minimum distance                        */
/*                                                                  */
/*-----------------------------------------------------------------!*/

   DBfloat ctol;         /* Coordinate tolerance                    */
   DBfloat idpoint;      /* Identical point criterion               */
   char    errbuf[80];   /* String for error message fctn erpush    */

/*--------------end-of-declarations---------------------------------*/

/*!                                                                 */
/* Algorithm                                                        */
/* =========                                                        */
/*                                                                 !*/

#ifdef DEBUG
if ( dbglev(SURPAC) == 1 )
{
fprintf(dbgfil(SURPAC),
  "sur980 Enter ocase_in %d n_inpts= %d\n",
       (int)ocase_in, (int)n_inpts);
  fprintf(dbgfil(SURPAC),
  "sur980 p_refpt %12.4f %12.4f %12.4f \n",
   p_refpt->x_gm,  p_refpt->y_gm,  p_refpt->z_gm);
for (i_pt=1; i_pt<=n_inpts;   i_pt= i_pt+1)
  {
  fprintf(dbgfil(SURPAC),
  "sur980 %d %12.4f %12.4f %12.4f \n",(int)i_pt,
   xyz_in[i_pt-1].r_x, xyz_in[i_pt-1].r_y,
   xyz_in[i_pt-1].r_z );
  }
  fflush(dbgfil(SURPAC)); 
}
#endif

/*!                                                                 */
/* 1. Check of input data and initializations                       */
/* ___________________________________________                      */
/*                                                                 !*/

  if ( n_inpts == 0 )
    {
    *p_n_outpts = 0;
    varkon_ini_evals  (&xyz_out[0]);         
    return(SUCCED);
    }

/* Check that n_inpts <= 1000 (array pflag dimension)               */

if ( n_inpts > 1000 || n_inpts < 0 )
   {
   sprintf(errbuf,"(pflag dimension) %%varkon_sur_order");
   return(varkon_erpush("SU2993",errbuf));
   }


/*!                                                                 */
/* Coordinate tolerances and infinite distance criterion.           */
/* Call of varkon_idpoint (sur741), varkon_ctol (sur751) and        */
/* varkon_infinitetol (sur754).                                     */
/* The coordinate tolerance used is idpoint for ocase_in= 1 or 2    */
/* and ctol if ocase_in= 10 or 20.                                  */
/*                                                                 !*/

#ifdef  DEBUG
   idpttol = F_UNDEF; 
   ocase   = I_UNDEF;
#endif

   ctol      = varkon_ctol();
   idpoint   = varkon_idpoint();
   itol      = varkon_infinitetol();

if         ( ocase_in == 1 )
   {
   ocase   = 1;
   idpttol = idpoint;
   }
else if    ( ocase_in == 2 )
   {
   ocase   = 2;
   idpttol = idpoint;
   }
else if    ( ocase_in == 10 )
   {
   ocase   = 1;
   idpttol = ctol;
   }
else if    ( ocase_in == 20 )
   {
   ocase   = 2;
   idpttol = ctol;
   }
else
   {
   sprintf(errbuf,"(ocase_in)%%sur980");
   return(varkon_erpush("SU2993",errbuf));
   }

/* Output number of points:                                         */
   *p_n_outpts = 0;

/* Initialize point flag Eq. +1: Point is not used (sorted)         */
for (i_pt=1; i_pt<=n_inpts;   i_pt= i_pt+1)
  {
  pflag[i_pt-1] = 1;
  }

/*!                                                                 */
/* 2.                                                               */
/* ______________________________                                   */
/*                                                                 !*/

for (i_o= 1; i_o<= n_inpts; i_o =i_o +1)  /* Start outer loop       */
  {                                       /*                        */
  min_dist = itol;                        /* Start value for        */
                                          /* the next point         */
  i_min    = -1;                          /* Flag = no pt found     */
  for (i_i= 1; i_i<= n_inpts; i_i= i_i+1) /* Start inner loop       */
    {                                     /*                        */
    if ( pflag[i_i-1] > 0 )               /* Compare only if point  */
      {                                   /* not is used            */
      if      ( ocase == 1 )              /* Calculate R*3 or U,V   */
      r3dist(p_refpt,xyz_in,i_i );        /* distance depending on  */
      else if ( ocase == 2 )              /* ordering case (ocase)  */
      uvdist(p_refpt,xyz_in,i_i );        /*                        */
      if ( dist < min_dist )              /* If "shorter distance"  */
         {                                /*                        */
         min_dist = dist;                 /*                        */
         i_min    = i_i;                  /*                        */
         }                                /* End if "shorter dist." */
      }                                   /* End if "pt is not used"*/
    }                                     /* End   inner loop       */
    if ( i_min > 0 )                      /* Distance is less       */
       {                                  /* pt will be added       */
                                          /* if not already         */
                                          /* existing               */
       pflag[i_min-1] = -1;               /* Pt is always "used"    */
       addsol(xyz_in,i_min,               /* Minimum distance to    */
             xyz_out,*p_n_outpts);        /* existing solutions     */
       if ( a_dist >= idpttol )           /* Add solution if min.   */
         {                                /* distance >= idpttol    */
         *p_n_outpts= *p_n_outpts + 1;    /* An additional point    */
         xyz_out[*p_n_outpts-1] =         /* R*3 and U,V data       */
            xyz_in[i_min-1];              /* to output array        */
         }                                /* End if a_dist< idpttol */
       }                                  /* End if i_min > 0       */
  }                                       /* End   outer loop       */


#ifdef DEBUG
if ( dbglev(SURPAC) == 1 )
  {
  fprintf(dbgfil(SURPAC),
  "sur980 Exit varkon_sur_order  No output pts %d Used tolerance %f\n",
     (int)*p_n_outpts , idpttol );
  fflush(dbgfil(SURPAC)); 
  }
#endif

    return(SUCCED);

} /* End of function                                                */