⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int_expr.c

📁 LastWave
💻 C
📖 第 1 页 / 共 5 页
字号:
        Clean(*resVC);        DeleteFSIList(list);        return(0);      }           (*left)=(*left)+1;      begin = *left;      answer = ExpandFSIList(list, resFlt, resVC, AnyType);     }         /* Set Default range/sig/im */    if (answer == SignalType) {      if (ds) {ForceNoDefaultSig(defParam);}      else SetDefaultSig(defParam,(SIGNAL) *resVC,NO);    }    if (answer == ImageType) {      if (di) {ForceNoDefaultIm(defParam);}      else SetDefaultIm(defParam,(IMAGE) *resVC,NO);    }  }  /************************************   *   * Test the constants (signals)   *   ************************************/  /* X */     else if (!strncmp(begin,"X",1) && !IsValidSymbolChar1(begin[1])) {    if (DefaultX(defParam) == NULL) {      if (NoDefaultSig(defParam)) {        SetErrorf("Cannot infer what 'X' refers to");        Clean(*resVC);        return(0);      }      rg = TNewRange();      rg->step = DefaultSigDx(defParam);      rg->first = DefaultSigX0(defParam);      rg->size = DefaultSigSize(defParam);      *resVC = (VALUE) rg;      answer = RangeType;      *left = begin+1;     }    else {      type = GetTypeValue(DefaultX(defParam));      if (type == rangeType) {        if (!(flagType & RangeType)) {          SetErrorf("I am not expecting a range");          Clean(*resVC);          return(0);        }        *resVC = DefaultX(defParam);        (*resVC)->nRef++;        TempValue(*resVC);        answer = RangeType;        *left = begin+1;       }      else if (flagType & SignalType) {        *resVC = DefaultX(defParam);        (*resVC)->nRef++;        TempValue(*resVC);        answer = SignalType;        *left = begin+1;       }      else {        SetErrorf("I am not expecting a signal");        Clean(*resVC);        return(0);      }    }  }  /************************************   *   * Test an expression ()   *   ************************************/    else if (begin[0] == '(') {    begin1 = begin;    begin++;    oldFlagSpace = defParam->flagSpace;    defParam->flagSpace = YES;    r = TTExpr1(begin, left,resFlt,resVC,flagType,defParam);    defParam->flagSpace = oldFlagSpace;    if (r==NO) return(0);    if ((**left)!=')') {      if (**left == '\0') SetErrorf("Expecting a parenthesis ')'");       else SetErrorf("Syntax error");      Clean(*resVC);      return(0);    }    (*left)=(*left)+1;    begin = *left;    while (**left == ' ') (*left)++;    answer = r;  }  /************************************   *   * Case of the range ':'   *   ************************************/    else if (begin[0] == ':') {    if (!(flagType & RangeType)) {      SetErrorf("Not expecting a range");       Clean(*resVC);      return(0);    }    if (NoDefaultVector(defParam)) {      SetErrorf("Cannot infer what ':' refers to");       Clean(*resVC);      return(0);    }        *left = begin+1;    rg = ((RANGE) *resVC);    rg = TNewRange();    rg->size = (int) ((DefaultVMax(defParam)-DefaultVMin(defParam))/DefaultVDx(defParam)+1);    rg->step = DefaultVDx(defParam);    rg->first = DefaultVMin(defParam);        answer = RangeType;   }    /************************************   *   * A variable   *   ************************************/    else {    answer = TGetVariableContentLevelExpr(DefaultLevel(defParam),begin,left,resFlt,resVC,flagType,NO,defParam);    if (answer == SignalType) {SetDefaultSig(defParam,(SIGNAL) *resVC,NO);}    else if (answer == ImageType) {SetDefaultIm(defParam,(IMAGE) *resVC,NO);}    else if (answer == RangeType && ((RANGE) *resVC)->step > 0) SetDefaultSizeX0Dx(defParam,((RANGE) *resVC)->size,((RANGE) *resVC)->first,((RANGE) *resVC)->step,NO);        return(answer);  }      /************************************   *   * If there is a . (i.e., field) or a () (extraction)   * we must go on...   *   ************************************/  if ((**left == '.' || **left == '[') && *resVC != NULL) {    value = *resVC;    *resVC = NULL;    oldFlagEmptySI = defParam->flagEmptySI;    defParam->flagEmptySI = YES;    answer = TGetFieldOrExtractContentExpr(DefaultLevel(defParam), value, *left,left, resFlt,resVC, flagType, defParam);    defParam->flagEmptySI =  oldFlagEmptySI;    if (answer == SignalType) {      if (!defParam->flagEmptySI && ((SIGNAL) *resVC)->size == 0) {        SetErrorf("Do not expect empty signal");        *left = begin;        Clean(*resVC);        return(0);      }      SetDefaultSig(defParam,(SIGNAL) *resVC,NO);    }    else if (answer == ImageType) {      if (!defParam->flagEmptySI && (((IMAGE) *resVC)->nrow == 0 || ((IMAGE) *resVC)->ncol == 0)) {        SetErrorf("Do not expect empty image");        *left = begin;        Clean(*resVC);        return(0);      }      SetDefaultIm(defParam,(IMAGE) *resVC,NO);    }    else if (answer == RangeType && ((RANGE) *resVC)->step > 0) SetDefaultSizeX0Dx(defParam,((RANGE) *resVC)->size,((RANGE) *resVC)->first,((RANGE) *resVC)->step,NO);        return(answer);  }  ParamSkipSpace(*left);  /* Just return */  return(answer);}/* * Generic macro that performs unary operations */#define Apply1(out,in,rg,op) \  if (in!=NULL) {\    for (j=0;j<size;j++) out[j] = op(in[j]);\  }\  else {\    for (j=0;j<size;j++) out[j] = op(RangeVal(rg,j));\  }/* * Generic function that Sets the output of a unary operator on images and signals * * This function is called below by the TTExpr8 function which deal with unary operator * * If the argument of the operator is different from an image or a signal then this function is not called. * * The arguments are :  * *    - r1, vc1 : correspond to the argument of the unary operator (r1 is the type *                and vc1 the corresponding variable content).  * * The function returns the type of the result and assign vc3 so that the result will be stored in it. * (allocation wil be performed only if necessary). *       *  */static char TTSetOutput1(unsigned char r1, VALUE vc1, VALUE *vc3) {   SIGNAL s3,s1;   RANGE rg1;   IMAGE i3,i1;   char flagTemp1;      if (r1 == SignalType) s1 = (SIGNAL) vc1;   else if (r1 == ImageType) i1 = (IMAGE) vc1;   else if (r1 == RangeType) rg1 = (RANGE) vc1;   else Errorf("TTSetOutput1() : Weird error");      if(vc1->nRef == 1) flagTemp1 = YES;   else flagTemp1 = NO;      s3 = NULL;   i3 = NULL;   if (flagTemp1) {     if (r1 == SignalType) {*vc3 = (VALUE) s1; return(1);}     if (r1 == ImageType) {*vc3 = (VALUE) i1; return(1);}   }      if (r1 == SignalType) {     s3 = TNewSignal();     SizeSignal(s3,s1->size,s1->type);     CopyFieldsSig(s1,s3);     if (s1->type == XYSIG) memcpy(s3->X,s1->X,s1->size*sizeof(LWFLOAT));     *vc3 = (VALUE) s3;     return(1);   }   if (r1 == RangeType) {     s3 = TNewSignal();     SizeSignal(s3,rg1->size,YSIG);     *vc3 = (VALUE) s3;     return(1);   }   if (r1 == ImageType) {     i3 = TNewImage();     SizeImage(i3,i1->ncol,i1->nrow);     CopyFieldsImage(i1,i3);     *vc3 = (VALUE) i3;     return(1);   }          Errorf("SetOutput1() : Weired Error");      return(0); } /* * expr9 -> most of the unary operators and some special binary ones * */static unsigned char TTExpr9(char* begin, char** left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, ExprDefParam *defParam){  /* The operators 'op term' or 'op(expr0)' */  static char *opArray1[] = {"!", "+", "-", "~", NULL};  static int opSizeArray1[] = {1,1,1,1,0};  /* The operators 'op(expr0)' */  static char *opArray2[] = {"sinh","sin","cosh","cos","tanh","tan","acos","asin","atan",\                             "log2","log","ln","sqrt","abs","exp","ceil","floor","round","frac","int", NULL};  static int opSizeArray2[] = {4,3,4,3,4,3,4,4,4,4,3,2,4,3,3,4,5,5,4,3,0};  /* The operators 'op' 'op(expr0_Num)' 'op(expr0_Num,expr0,Num)' */  static char *opArray3[] = {"Zero","One","Id","I","J","Grand","Urand", NULL};  static int opSizeArray3[] = {4,3,2,1,1,5,5,0};  /* The operators 'op(expr0_Sig,expr0_Sig)' */  static char *opArray4[] = {"XY", NULL};  static int opSizeArray4[] = {2,0};  /* The operators 'op(expr0_Sig)' */  static char *opArray5[] = {"X","der","prim", "diag", NULL};  static int opSizeArray5[] = {1,3,4,4,0};  /* The operator 'op(expression)' */  static char *opArray6[] = {"type","btype", NULL};  static int opSizeArray6[] = {4,5,0};  /* The operator 'op(expression)' or 'op(expression,expression)' that returns a LWFLOAT/images/signal */  static char *opArray7[] = {"min","max", "sum", "any", "all", "mean", NULL};  static int opSizeArray7[] = {3,3,3,3,3,4,0};  /* The operator 'op(expression)' that returns a listv */  static char *opArray8[] = {"find", NULL};  static int opSizeArray8[] = {4,0};  char **op;  int *opSize;  char opIndex;  char arrayIndex;  char oldFlagSpace,oldFlagEmptySI;  SIGNAL s,s1,s2,s3;  RANGE rg1,rg2,rg3,rg;  IMAGE i,i1,i2,i3;  unsigned char r,r1,r2,r3;  char flagTemp;  LWFLOAT f1,f2;  LWFLOAT *array,*array3,temp,temp1;  int size,size1,size2,size3;  int j,j1,n;  char *begin1,*begin2;   VALUE vc1,vc2,vc3;   STRVALUE sc;    /***********************************************************   *    * If it starts with a number just call Term   *   ***********************************************************/      if (isdigit(*begin)) {      r = TermExpr(begin,left,resFlt,resVC,flagType,defParam);     if (r==NO) return(0);     return(r);   }       /***********************************************************   *    * Operators !,+,- and sin, sinh...   *    * 'op term' or 'op(expr0)'   * 'op(expr0)'   *   ***********************************************************/  /* First array */  arrayIndex = 1;  for (op = opArray1, opSize = opSizeArray1 ;;op++,opSize++) {                                                             if (*op == NULL) break;     if (!strncmp(begin,*op,*opSize)) break;   }  opIndex = op-opArray1+1;  /* Second array */  if (*op == NULL) {    arrayIndex = 2;    for (op = opArray2, opSize = opSizeArray2 ;;op++,opSize++) {                                                               if (*op == NULL) break;       if (!strncmp(begin,*op,*opSize) && !IsValidSymbolChar(begin[*opSize])) break;     }    opIndex = op-opArray2+1;  }      if (*op != NULL) {        /* Skip operator */     begin  += *opSize;     ParamSkipSpace(begin);    *left = begin;        /* Case (expr0) */    if (*begin == '(') {      begin1 = begin;      begin++;      *left = begin;      oldFlagSpace = defParam->flagSpace;      defParam->flagSpace = YES;      oldFlagEmptySI = defParam->flagEmptySI;      defParam->flagEmptySI = NO;      r = TTExpr1(begin,left,resFlt,resVC,flagType & ~(ListvType | OtherType | StringType),defParam);      defParam->flagEmptySI = oldFlagEmptySI;      defParam->flagSpace = oldFlagSpace;      if (r==NO) return(0);      if (**left != ')') {        SetErrorf("Expecting a parenthesis ')'");         Clean(*resVC);        return(0);      }      (*left)++;      begin = (*left);          }        /* Case term (first array only) */    else if (arrayIndex == 1) {      oldFlagEmptySI = defParam->flagEmptySI;      defParam->flagEmptySI = NO;      r = TermExpr(begin,left,resFlt,resVC,flagType & ~(ListvType | OtherType | StringType),defParam);      defParam->flagEmptySI = oldFlagEmptySI;      if (r==NO) return(0);      begin = (*left);                }    else {      Clean(*resVC);      return(0);    }    s = NULL;    i = NULL;    rg = NULL;    if (r == SignalType) s = (SIGNAL) *resVC;    else if (r == RangeType) rg = (RANGE) *resVC;    else if (r == ImageType) i = (IMAGE) *resVC;    else if (r != FloatType) Errorf("TTExpr9() : Weird Error");    if (r != FloatType && (*resVC)->nRef == 1) flagTemp = YES;    else flagTemp = NO;        /* If '+' : Nothing to do ! */    if (arrayIndex == 1 && opIndex == 2) return(r);    /* If '-' of a range : almost Nothing to do ! */    if (arrayIndex == 1 && opIndex == 3 && rg != NULL && rg->nRef == 1) {      rg->first = -rg->first;      rg->step = -rg->step;      return(RangeType);    }    /* If '~' */    if (arrayIndex == 1 && opIndex == 4) {      if (r == FloatType) return(r);      if (r == ImageType) {        if (i->ncol != 1) {          *resVC = (VALUE) TNewImage();          TranspImage(i,(IMAGE) *resVC);        }        else {          *resVC = (VALUE) TNewSignal();          SizeSignal((SIGNAL) *resVC,i->nrow,YSIG);          for(j=0;j<i->nrow;j++) ((SIGNAL) *resVC)->Y[j] = i->pixels[j];          r = SignalType;        }        return(r);      }      if (r == SignalType) {        *resVC = (VALUE) TNewImage();        SizeImage((IMAGE) *resVC,1,s->size);        memcpy(((IMAGE) *resVC)->pixels,s->Y,sizeof(LWFLOAT)*s->size);        return(ImageType);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -