Esempio n. 1
0
/* ----------------------------------------------------------------
 * 功    能:将字符串解包为TLV格式数据
 * 输入参数:szBuf           输入字符串
 *           iBufLen         输入字符串长度
 * 输出参数:pTLV            TLV格式数据
 * 返 回 值:0  成功;    -1 失败
 * 作    者:fengwei
 * 日    期:2012-9-24
 * 调用说明:UnpackTLV(pTLV, szBuf, iLen)
 * 修改日志:修改日期    修改者      修改内容简述
 * ----------------------------------------------------------------
 */
int UnpackTLV(T_TLVStru *pTLV, char* szBuf, int iBufLen)
{
    int  i, iIndex, iLen;
    char szTagBuf[MAX_TAG_LEN+1];
    T_TLVData *pData;

    iIndex = 0;
    i = 0;

    while (iIndex < iBufLen)
    {
        pData = pTLV->tTLVData + i;
        
        iLen = _get_tag(szBuf+iIndex, pTLV->iTagType, pData->szTag);
        if (iLen == 0)
        {
            WriteLog(ERROR, "unpack tlv Tag error");
            return FAIL;
        }
        iIndex += iLen;

        iLen = _get_len(szBuf+iIndex, pTLV->iLenType, &(pData->iLen));
        if (iLen == 0)
        {
            WriteLog(ERROR, "unpack tlv len error");
            return FAIL;
        }
        iIndex += iLen;

        iLen = _get_value(szBuf+iIndex, pData->iLen, pTLV->iValueType, 
                          pData->szValue);
        if (iLen < 0)
        {
            WriteLog(ERROR, "unpack tlv value error");
            return FAIL;
        }
        iIndex += iLen;

        pData->iFlag = DATA_NOTNULL;

        i++;
    }

    return SUCC;
}
Esempio n. 2
0
int xs_trans::Construct(int num, double *x, double *y, double minb) {
  long int cur, ll, dyl;
  int line, num_int, num_prev_int, jj, rc;
  double len_now, len_prev, dy, c2, ccor;

  _num_pts = num;
  _record_into_int(_num_pts, &x[0], &(y[0]), UNIT);
  rc = _quick_check();
  if ( rc == -1 ) return (-1);

#ifdef DBGSPLINE
  printf("original values\n");
  for (int jj=0; jj<_num_pts; jj++) {
    printf("=1= %.4f %.4f\n", x[jj], y[jj]);
  }
  printf("converted to int\n");
  for (int jj=0; jj<_num_pts; jj++) {
    printf("=2= %ld %ld\n", _xxin[jj], _yyin[jj]);
  }
#endif

  _num_pts = _cmethod(ANG_THRESH);

#ifdef DBGSPLINE
  printf("after compression\n");
  for (int jj=0; jj<_num_pts; jj++) {
    printf("=3= %ld %ld\n", _rxx[jj], _ryy[jj]);
  }
#endif
  
  _find_min_max();
  _num_segs = _insert2segs();

  qsort(_segs, _num_segs, sizeof(segment), mycompare);
  
  // initialize the rest
  _init_internal();

  // find min y, if odd # of intersection, skip
  cur = _min_y;
  while (1) {
    num_int = _find_intersects(cur, &_working[0]);
    len_now = _get_len(num_int, &_working[0], UNIT);
    if ( num_int % 2 == 0 && len_now > minb ) break;  // another magic number
    //    if ( num_int % 2 == 0 || num_int == 1 ) break;

    cur += YGRID;
  }

  // first value
  line = 0;
  _my_yy[line] = (double)cur *UNIT;
  _my_aa[line] = 0.0;
  _my_pp[line] = 0.0;
  _my_cc[line] = 0.0;

  for (jj=0; jj<num_int; jj+=2) {
    _my_pp[line] += _working[jj+1]-_working[jj];
  }
  _my_pp[line] *= UNIT;
  _my_ll[line] = _my_pp[line];

  // store the previous
  for (jj=0; jj<num_int; jj++)  _prev[jj] = _working[jj];
  num_prev_int = num_int;

  // get ready
  line++;
  ll = cur;
  cur += YGRID;

  // work out the rest
  for (; cur < _max_y; cur+=YGRID) {
    num_int = _find_intersects(cur, &_working[0]);
    if (num_int % 2 == 1 ) continue;  // skip odd number of intersections

    len_now = _get_len(num_int, &_working[0],UNIT);
    len_prev = _get_len(num_prev_int, &_prev[0], UNIT);
    dyl = cur - ll;
    dy = (double)dyl*UNIT;

    c2 = len_prev*dy*dy/2.0 + (len_now-len_prev)*dy*dy/6.0;
    ccor = _my_aa[line-1]*dy;
    
    _my_yy[line ] = (double)cur* UNIT;

    _my_aa[line] = _my_aa[line-1] + dy*(len_now+len_prev)/2.0;
    _my_pp[line] = _my_pp[line-1] + _get_pp(num_int, &_working[0], num_prev_int, &_prev[0], dyl, UNIT);
    _my_ll[line] = len_now;
    _my_cc[line] = _my_cc[line-1] + ccor + c2;

    // get ready for the next one
    line++;
    ll = cur;
    for (jj=0; jj<num_int; jj++)  _prev[jj] = _working[jj];
    num_prev_int = num_int;
  }
  _num_samples = line;

#ifdef DBGSPLINE
  printf("sampling dense\n");
  for (int jj=0; jj<_num_samples; jj++) {
    printf("=4= %.4e %.4e %.4e %.4e %.4e\n", _my_aa[jj], _my_ll[jj],_my_pp[jj],_my_cc[jj],_my_yy[jj]);
  }
#endif
  // coarse sampling
  _final_samples=0;
  for (jj=0; jj<_num_samples; jj+=SGRID) {
    _aa[_final_samples] = _my_aa[jj];
    _ll[_final_samples] = _my_ll[jj];
    _pp[_final_samples] = _my_pp[jj];
    _cc[_final_samples] = _my_cc[jj];
    _yy[_final_samples] = _my_yy[jj];

    _final_samples++;
  }

  // add the last one, if it's not too close
  if ( jj - 2*SGRID/3 < _num_samples ) {
    _aa[_final_samples] = _my_aa[_num_samples-1];
    _ll[_final_samples] = _my_ll[_num_samples-1];
    _pp[_final_samples] = _my_pp[_num_samples-1];
    _cc[_final_samples] = _my_cc[_num_samples-1];
    _yy[_final_samples] = _my_yy[_num_samples-1];
    _final_samples++;
  }

#ifdef DBGSPLINE
  printf("sampling coarse\n");
  for (int jj=0; jj<_final_samples; jj++) {
    printf("=5= %.4e %.4e %.4e %.4e %.4e\n", _aa[jj], _ll[jj],_pp[jj],_cc[jj],_yy[jj]);
  }
#endif

  // scale y as depth
  for (jj=1; jj<_final_samples; jj++) _yy[jj] -= _yy[0];
  _yy[0] = 0.0;

  return 0;
}