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

📄 int_fsilist.c

📁 LastWave
💻 C
📖 第 1 页 / 共 2 页
字号:
/*..........................................................................*//*                                                                          *//*      L a s t W a v e   K e r n e l   3 . 0                               *//*                                                                          *//*      Copyright (C) 1998-2002 Emmanuel Bacry.                             *//*      email : lastwave@cmap.polytechnique.fr                              *//*                                                                          *//*..........................................................................*//*                                                                          *//*      This program is a free software, you can redistribute it and/or     *//*      modify it under the terms of the GNU General Public License as      *//*      published by the Free Software Foundation; either version 2 of the  *//*      License, or (at your option) any later version                      *//*                                                                          *//*      This program is distributed in the hope that it will be useful,     *//*      but WITHOUT ANY WARRANTY; without even the implied warranty of      *//*      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *//*      GNU General Public License for more details.                        *//*                                                                          *//*      You should have received a copy of the GNU General Public License   *//*      along with this program (in a file named COPYRIGHT);                *//*      if not, write to the Free Software Foundation, Inc.,                *//*      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA             *//*                                                                          *//*..........................................................................*/#include "lastwave.h"#include "signals.h"#include "images.h"#include "int_fsilist.h"extern unsigned char TTExpr1(char* begin, char** left, LWFLOAT *resFlt, VALUE *resVC, unsigned char flagType, ExprDefParam *defParam) ;#define Clean(val)  if ((val) != NULL) {(val) = NULL;}/* Variable used in the BPER,BMIR,... macros */long __borderTempLong__;/****************************************************************************//*                                                                          *//*  int_listfsi.c                 *//*                                                                          *//****************************************************************************//*   * Some static variables to avoid dynamic allocation  */ #define NFSILISTS 10static FSIList theSFIList[NFSILISTS];static int nSFIList = -1;/* * Init the static SFI list  */static void InitSFIList(void){  int j;    for (j=0;j<NFSILISTS;j++) theSFIList[j].size = 0;  nSFIList = 0;}/*  * Returns an SFIList that is available (from the static list) */  static int yyy=0;FSIList *NewSFIList(void){  int j;  FSIList *list;    if (nSFIList == -1) InitSFIList();  if (theSFIList[nSFIList].size == 0) j = nSFIList;  else {    for (j=0;j<NFSILISTS;j++) if (theSFIList[j].size == 0) break;    if (j == NFSILISTS) {      for (j=0;j<NFSILISTS;j++) DeleteFSIList(theSFIList+j);      Errorf("NewSFIList() : Sorry, too many lists are used (maximum is %d)",NFSILISTS);    }  }  list = &(theSFIList[j]);  nSFIList = (j+1)%NFSILISTS;  list->nSep = 0;  list->flagImage = NO;    yyy++;  return(list);    }/*  * Delete an SFIList */ void DeleteFSIList(FSIList *list){  if (list-theSFIList >= NFSILISTS) Errorf("DeleteFSIList() : Weird");  nSFIList = list-theSFIList;  list->size = 0;  yyy--;}/* * Read the options of an FSI List */char  FSIReadExtractOption(char *begin, char **left, char **options, unsigned long *optionFlag){  char *begin1;  char **options1;  char flagNoOption;    if (options == NULL) return(0);    SkipSpace(begin);  if (*begin != '*') return(0);  *optionFlag = 0;  flagNoOption = NO;  while (*begin == '*') {        /* Get next option */    begin1 = begin+1;    while (*begin1 != '*' && *begin1 != ',' && *begin1 != FSISEPARATOR && *begin1 != ')' && *begin1 != '\0') begin1++;        /* No Option *- ? */    if (begin1-begin == 2 && *(begin1-1) == '-') {      flagNoOption = YES;      begin = begin1;      SkipSpace(begin);      if (*begin == '\0' || *begin == FSISEPARATOR) break;      if (*begin == ',') begin++;      SkipSpace(begin);      continue;    }        /* Compare it */    options1 = options;    while (*options1) {      if (begin1-begin <= strlen(*options1) && !strncmp(begin,*options1,begin1-begin)) break;      options1++;    }    if (*options1 == NULL) {      SetErrorf("Bad extracting option");      *left = begin;      return(NO);    }    *optionFlag |= (1<<(options1-options));     begin = begin1;    SkipSpace(begin);    if (*begin == '\0') break;    if (*begin == FSISEPARATOR) {begin++;SkipSpace(begin);break;}    if (*begin == ',') begin++;    SkipSpace(begin);  }      *left = begin;    if (flagNoOption) *optionFlag = 0;    return(YES);}           /* * Macro to test the validity of indexes for extraction  */#define ValidIndexBound(index) \((index) >= min && (index) <= max ? 1 : (ei->flags & EIErrorBound ? SetErrorf("Indexes are out of range"), -1 : 0))#define ValidIndexInt(index) \((index) != (int) index ? SetErrorf("Expecting integer indexes"), -1 : 1)/* * Read a list of content. * * The arguments are : *   *    begin, left : as usual *    ei : the information needed about the indexes to extract (if no extraction then it is NULL) * */ FSIList *SFIListExpr(char* begin, char** left, ExtractInfo *ei, ExprDefParam *defParam) {  FSIList *list;    int j,kk;  VALUE val;  LWFLOAT f;  char flagError;  SIGNAL s;  RANGE rg;  int size;  IMAGE i;  LWFLOAT min,max,dx,dy;  int *nValid,nVal;  LISTV lv;  int nlv;  char *type;    unsigned char r;    int jsep,row1NCol,row2NCol;  int nvblock,nhblock;  int nrowCur,ncolCur;  int nrow,ncol;  char *begin1;  char flagExtract;  DefaultVectVar;    ParamSkipSpace(begin);    /*   * Case of an empty []       */  if (*begin == ']') {    list = NewSFIList();    list->nx = list->ny = list->nx1 = list->ny1 = 0;    *left = begin;    return(list);  }    /*    * Some inits    */  flagExtract = (ei != NULL);   if (ei && ei->nSignals<=0) Errorf("SFIListExpr() : Weird : bad extractInfo->nSignals<=0");  list = NewSFIList();  j = 0;  flagError = NO;  /* Set the min max for the first signal in case of extraction and a pointer to what will be the number of indexes in range */    if (flagExtract) {    min = ei->xmin;    dx = ei->dx;    if (dx<=0) s = ei->xsignal;    else s = NULL;    max = ei->xmax;    nValid = &(list->nx1);    *nValid = 0;    list->ny1 = 0;    if (min <= max) {      SaveDefaultVector(defParam);      SetDefaultVector(defParam,min,dx,max,s,YES);    }  }      nrow = 0;    /* The total number of rows */  ncol = 0;    /* The total number of cols */  ncolCur = 0; /* The current number of cols */  nrowCur = 0; /* The current number of rows */  nvblock = 1; /* The current vertical block number */  nhblock = 1; /* The current horizontal block number */  jsep = -1;   /* The index where the first separator ',' is found (used only in the case of extractIm) */   row1NCol = row2NCol = -1; /* The number of columns of the first and second rows (used only in the case of flagExtract) */     lv = NULL;    while(1) {    /* Treat the next element in the listv  if there is any */    if (lv != NULL) {      if (lv->length != nlv) {        type = GetListvNth(lv,nlv,&val,&f);        if (type == rangeType) r = RangeType;        else if (type == numType) r = FloatType;        else if (type == signaliType) r = SignalType;        else if (type == imageiType) r = ImageType;        else if (type == imageType || type == signalType) {nlv++; continue;}        else {          SetErrorf("Bad '%s' element type in listv for extraction (should be one of '%s', '%s, '%s' or '%s')",type,floatType,rangeType,signaliType,imageiType);          *left = begin;          flagError = YES;          break;        }      }      nlv++;      if (lv->length == nlv) lv = NULL;    }            /* Otherwise just parse the line */    else {      begin1 = begin;      val = NULL;      r = TTExpr1(begin, left,&f,&val,FloatType | SignalType | ImageType | RangeType | ListvType,defParam);      if (r == 0) {        flagError = YES;        break;      }      /* case of a listv */      if (r==ListvType) {        lv = (LISTV) val;        if (lv->length == 0) {          lv = NULL;          goto jumpEmptyListv;        }        nlv = 0;        continue;      }    }    if (j == NFSI) { /* Too many elements */      flagError = YES;      *left = begin1;      SetErrorf("Sorry, too many elements (Maximum is %d)",NFSI);      break;     }    /* Get the type of the next content */    switch(r) {      case FloatType :  list->fsi[j].type = FSIFloat; break;      case SignalType :  list->fsi[j].type = FSISignal; break;      case RangeType :  list->fsi[j].type = FSIRange; break;      case ImageType :  list->fsi[j].type = FSIImage; break;    }    /* Case it is a signal or a range */            if (r == SignalType || r == RangeType) {      if (r == SignalType) {        s = (SIGNAL) val;        size = s->size;      }      else {        rg = (RANGE) val;        size = rg->size;      }      if (nhblock == 1) {nrowCur = 1; nrow += nrowCur;}      else if (nrowCur != 1) { /* a signal is on the same row as an image */        flagError = YES;        *left = begin1;        SetErrorf("Expect an image with %d rows (not a signal or a range!)",nrowCur);        break;       }      if (nvblock == 1) ncol += size;      else {        ncolCur += size;        if (!flagExtract && ncolCur > ncol) { /* One row has too many columns */          flagError = YES;          *left = begin1;          SetErrorf("Row with an exceeding number of columns %d (>%d)",ncolCur,ncol);          break;         }       }            /* Some checkings with ExtractInfo if necessary */      if (flagExtract) {         /* Case of Ranges */        if (r==RangeType) {           /* Checking min, max */          if (min > max) *nValid += size;          else {            if ((ei->flags & EIErrorBound) && ((rg->step > 0 && (rg->first < min || rg->first+rg->step*(size-1) > max)) || (rg->step < 0 && (rg->first > max || rg->first+rg->step*(size-1) < min)))) {              flagError = YES;              SetErrorf("Indexes out of range");              break;            }            else {              if (rg->step > 0) nVal = (int) ((MIN(rg->first+rg->step*(size-1),max) - MAX(rg->first,min))/rg->step+1.1);              else nVal = (int) ((MIN(rg->first,max) - MAX(rg->first+rg->step*(size-1),min))/(-rg->step)+1.1);              if (nVal > 0) *nValid += nVal;            }          }          /* Checking int */          if (ei->flags & EIIntIndex) {            if (rg->first != (int) rg->first || (rg->step != (int) rg->step && size != 1)) {              flagError = YES;              SetErrorf("Expect integer indexes");              break;            }          }        }        /* Case of signals */                  else {          if (min > max) {            *nValid += s->size;            if (ei->flags & EIIntIndex) {              for(kk=0;kk<s->size;kk++) {                if (ValidIndexInt(s->Y[kk]) == -1) break;              }            }          }          else {            for(kk=0;kk<s->size;kk++) {              if ((ei->flags & EIIntIndex) && ValidIndexInt(s->Y[kk]) == -1) break;              nVal = ValidIndexBound(s->Y[kk]);              if (nVal == -1) break;              *nValid += nVal;            }          }          if (kk != s->size) {            flagError = YES;            break;          }        }      }                      /* Setting the new element in the list */      if (r==SignalType) {list->fsi[j].val.s = s; list->fsi[j].array = s->Y;}      else {list->fsi[j].val.r = rg; list->fsi[j].array = NULL;}      list->fsi[j].size = size;      s = NULL;      val = NULL;      j++;      list->size++;    }    /* Case it is an image */    else if (r == ImageType) {      i = (IMAGE) val;      if (flagExtract && i->nrow != 1) {        if (ei->nSignals == 1) {          SetErrorf("Can't use image for extraction indexes");          flagError = YES;          break;        }        if (list->size != 0 || i->nrow != 2) {          SetErrorf("Can't use more than 1 image with 2 rows for extraction indexes");          flagError = YES;          break;        }      }      if (nhblock == 1) {nrowCur = i->nrow; nrow += nrowCur;}      else if (nrowCur != i->nrow) { /* an image has the wrong number of rows */        flagError = YES;        *left = begin1;        SetErrorf("Bad number of rows %d (expect %d rows)",i->nrow,nrowCur);        break;       }       if (nvblock == 1) ncol += i->ncol;      else {        ncolCur += i->ncol;        if (!flagExtract && ncolCur > ncol) { /* One row has too many columns */          flagError = YES;

⌨️ 快捷键说明

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