Back to index

wims  3.65+svn20090927
Functions
levelcurve.c File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static int _lcomp (const void *l1, const void *l2)
static double lc_scalex (leveldata *ld, int x)
static double lc_scaley (leveldata *ld, int y)
static int _getlevel (leveldata *ld, int x, int y)
static void lc_replacexy (leveldata *ld)
int levelcurve (leveldata *ld)

Function Documentation

static int _getlevel ( leveldata ld,
int  x,
int  y 
) [static]

Definition at line 40 of file levelcurve.c.

{
    double dd;
    int i;
    
    eval_setval(ld->xevpos,lc_scalex(ld,x));
    eval_setval(ld->yevpos,lc_scaley(ld,y));
    set_evalue_error(0); set_evalue_pointer(ld->fn); dd=_evalue(10);
    for(i=0;i<ld->levelcnt && dd>ld->levels[i];i++);
    return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int _lcomp ( const void *  l1,
const void *  l2 
) [static]

Definition at line 18 of file levelcurve.c.

{
    const double *d1, *d2;
    double d;
    d1=(const double *) l1; d2=(const double *) l2;
    d=*d1-*d2;
    if(d<0) return -1; if(d>0) return 1;
    return 0;
}

Here is the caller graph for this function:

static void lc_replacexy ( leveldata ld) [static]

Definition at line 52 of file levelcurve.c.

{
    char *pp;
    for(pp=varchr(ld->fn,ld->xname);pp!=NULL;pp=varchr(pp,ld->xname)) {
       string_modify(ld->fn,pp,pp+strlen(ld->xname),EV_X);
       pp+=strlen(EV_X);
    }
    for(pp=varchr(ld->fn,ld->yname);pp!=NULL;pp=varchr(pp,ld->yname)) {
       string_modify(ld->fn,pp,pp+strlen(ld->yname),EV_Y);
       pp+=strlen(EV_Y);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static double lc_scalex ( leveldata ld,
int  x 
) [static]

Definition at line 28 of file levelcurve.c.

{
    if(x<0) x=0; if(x>=ld->xsize) x=ld->xsize-1;
    return ld->xspan*((double) x - 0.40127)/ld->xsize+ld->xrange[0];
}

Here is the caller graph for this function:

static double lc_scaley ( leveldata ld,
int  y 
) [static]

Definition at line 34 of file levelcurve.c.

{
    if(y<0) y=0; if(y>=ld->ysize) y=ld->ysize-1;
    return -ld->yspan*((double) y - 0.40127)/ld->ysize+ld->yrange[1];
}

Here is the caller graph for this function:

int levelcurve ( leveldata ld)

Definition at line 66 of file levelcurve.c.

{
    int xx,yy,xi,yi,xsteps,ysteps;
    int i,x,y,xt,yt;
    short int l1[LEVELSIZE_LIM+16], l2[LEVELSIZE_LIM+16];
    short int l3[LEVELGRAIN_LIM+2][LEVELGRAIN_LIM+2];
    char f[MAX_LINELEN+1];
    
    ld->datacnt=0;
    if(ld->fn==NULL || *(ld->fn)==0 || ld->levelcnt<1) return 1;
    if(ld->grain<1) ld->grain=4;
    if(ld->grain>LEVELGRAIN_LIM) ld->grain=LEVELGRAIN_LIM;
    if(ld->levelcnt>LEVEL_LIM) ld->levelcnt=LEVEL_LIM;
    if(ld->xsize<10 || ld->xsize>LEVELSIZE_LIM) return 2;
    if(ld->ysize<10 || ld->ysize>LEVELSIZE_LIM) return 2;
    if(check_parentheses(ld->fn,0)) return 3;
    ld->xspan=ld->xrange[1]-ld->xrange[0];
    ld->yspan=ld->yrange[1]-ld->yrange[0];
    if(ld->levelcnt>1) qsort(ld->levels,ld->levelcnt,sizeof(double),_lcomp);
    if(ld->xname==NULL || *(ld->xname)==0) ld->xname="x";
    if(ld->yname==NULL || *(ld->yname)==0) ld->yname="y";
    snprintf(f,sizeof(f),"%s",ld->fn); substitute(f); ld->fn=f;
    ld->xevpos=eval_getpos(EV_X); ld->yevpos=eval_getpos(EV_Y);
    if(ld->xevpos<0 || ld->yevpos<0) return 4;
    lc_replacexy(ld); evalue_compile(f);
    xsteps=(ld->xsize+ld->grain-1)/ld->grain+1;
    ysteps=(ld->ysize+ld->grain-1)/ld->grain+1;
    for(yy=yi=0;yi<ysteps;yy+=ld->grain,yi++) l2[yi]=_getlevel(ld,0,yy);
    l2[ysteps]=l2[ysteps-1];
    for(xi=1,xx=ld->grain;xi<xsteps && ld->datacnt<LEVELPOINT_LIM;xx+=ld->grain,xi++) {
       memmove(l1,l2,(ysteps+1)*sizeof(short int));
       for(yi=yy=0;yi<ysteps;yy+=ld->grain,yi++) l2[yi]=_getlevel(ld,xx,yy);
       l2[ysteps]=l2[ysteps-1];
       for(yi=0;yi<ysteps && ld->datacnt<LEVELPOINT_LIM;yi++)
         if(l1[yi]!=l1[yi+1] || l1[yi]!=l2[yi] || l1[yi]!=l2[yi+1]) {
             for(x=0,xt=(xi-1)*ld->grain;x<=ld->grain;x++,xt++)
              for(y=0,yt=yi*ld->grain;y<=ld->grain;y++,yt++) {
                  if(x==0 && y==0) {l3[x][y]=l1[yi]; continue;}
                  if(x==0 && y==ld->grain) {l3[x][y]=l1[yi+1]; continue;}
                  if(x==ld->grain && y==0) {l3[x][y]=l2[yi]; continue;}
                  if(x==ld->grain && y==ld->grain) {l3[x][y]=l2[yi+1]; continue;}
                  l3[x][y]=_getlevel(ld,xt,yt);
              }
             for(x=0,xt=(xi-1)*ld->grain;x<ld->grain;x++,xt++)
              for(y=0,yt=yi*ld->grain;y<ld->grain;y++,yt++) {
                  i=l3[x][y];
                  if((i!=l3[x][y+1] || i!=l3[x+1][y]) && 
                     ld->datacnt<LEVELPOINT_LIM && 
                     (i!=l3[x][y+1] || ld->datacnt==0 ||
                     l3[x+1][y+1]==l3[x+1][y] ||
                     ld->xdata[ld->datacnt-1]!=xt ||
                     ld->ydata[ld->datacnt-1]!=yt-1)) {
                     ld->xdata[ld->datacnt]=xt;
                     ld->ydata[ld->datacnt++]=yt;
                  }
              }
         }
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: