void chksid (void) { gaint *f1,*f4; gaint i,j; gadouble x,y; f1 = flgh; f4 = flgv; for (j=1; j<=jmax; j++) { for (i=1; i<=imax; i++) { if (i<imax) { if (*f1==1) gxcolr(1); else if (*f1==7) gxcolr(3); else if (*f1==8) gxcolr(8); else if (*f1==9) gxcolr(4); else if (*f1==0) gxcolr(15); else gxcolr(2); gxconv((gadouble)i,(gadouble)j,&x,&y,3); gxplot(x,y,3); gxconv((gadouble)(i+1),(gadouble)j,&x,&y,3); gxplot(x,y,2); } if (j<jmax) { if (*f4==1) gxcolr(1); else if (*f4==7) gxcolr(3); else if (*f4==8) gxcolr(8); else if (*f4==9) gxcolr(4); else if (*f4==0) gxcolr(15); else gxcolr(2); gxconv((gadouble)i,(gadouble)j,&x,&y,3); gxplot(x,y,3); gxconv((gadouble)i,(gadouble)(j+1),&x,&y,3); gxplot(x,y,2); } f1++; f4++; } } gxfrme (0); }
void gxshad (gadouble *r, gaint is, gaint js, gadouble *vs, gaint *clrs, gaint lvs, char *u) { gadouble *p1,*p2,*p3,*p4; gadouble x,y,rmin,rmax; gaint i, j, k, rc; gaint *f1,*f2,*f3,*f4; char *p1u,*p2u,*p3u,*p4u; /* Make some stuff global within this file */ imax = is; jmax = js; gr = r; gru = u; /* Initialize xy coord buffer and stack buffer setup. */ stkcnt = 0; for (i=0; i<XYBMAX; i++) xystk[i] = NULL; grsize = is*js; xybuf = (gadouble *)malloc(sizeof(gadouble)*grsize*2); if (xybuf==NULL) { printf ("Error in gxshad: Unable to allocate xy coord buffer\n"); return; } xycnt = 0; /* Alocate flag work area. */ flgh = (gaint *)malloc(grsize*sizeof(gaint)); flgv = (gaint *)malloc(grsize*sizeof(gaint)); if (flgh==NULL || flgv==NULL) { printf ("Error in gxshad: Unable to allocate flags buffer\n"); return; } /* Loop through bands of the grid. Each band is three grid boxes wide, which avoids any problems with imbedded max's within min's or with imbedded complex undefined regions. */ imn = 1; imx = imax; for (jmn=1; jmn<jmax; jmn+=3) { jmx = jmn+3; if (jmx>jmax) jmx=jmax; rmin = 9.99e33; rmax = -9.99e33; for (j=jmn; j<=jmx; j++) { p1 = gr + ((j-1)*imax+imn-1); p1u = gru + ((j-1)*imax+imn-1); for (i=imn; i<=imx; i++) { if (*p1u!=0) { if (*p1>rmax) rmax = *p1; if (*p1<rmin) rmin = *p1; } p1++; p1u++; } } /* Loop through shade levels. */ prvclr = 0; for (k=0; k<lvs; k++) { val = vs[k]; color = clrs[k]; if (k<lvs-1 && vs[k+1]<rmin) { prvclr = color; continue; } if (val>rmax) continue; /* Set up flags to indicate which grid boxes contain missing data values and where the grid boundries are. Flag values are: 0 - nothing yet 1 - contour has been drawn through this side 7 - contour drawn through missing data box side 8 - boundry between missing data value box and non-missing data value box 9 - missing data value box side */ f1 = flgh + ((jmn-1)*imax); f4 = flgv + ((jmn-1)*imax); for (j=jmn; j<=jmx; j++) { for (i=1; i<=imax; i++) { *f1 = 0; *f4 = 0; f1++; f4++; } } for (j=jmn; j<jmx; j++) { p1 = gr + ((j-1)*imax+imn-1); p2 = p1+1; p3 = p2+imax; p4 = p1+imax; p1u = gru + ((j-1)*imax+imn-1); p2u = p1u+1; p3u = p2u+imax; p4u = p1u+imax; f1 = flgh + ((j-1)*imax+imn-1); f2 = flgv + ((j-1)*imax+imn); f3 = f1 + imax; f4 = f2 - 1; for (i=imn; i<imx; i++) { if (*p1u==0 || *p2u==0 || *p3u==0 || *p4u==0) { *f1=9; *f2=9; *f3=9; *f4=9; } p1++; p2++; p3++; p4++; p1u++; p2u++; p3u++; p4u++; f1++; f2++; f3++; f4++; } } for (j=jmn; j<jmx; j++) { p1 = gr + ((j-1)*imax+imn-1); p2 = p1+1; p3 = p2+imax; p4 = p1+imax; p1u = gru + ((j-1)*imax+imn-1); p2u = p1u+1; p3u = p2u+imax; p4u = p1u+imax; f1 = flgh + ((j-1)*imax+imn-1); f2 = flgv + ((j-1)*imax+imn); f3 = f1 + imax; f4 = f2 - 1; for (i=imn; i<imx; i++) { if (*p1u!=0 && *p2u!=0 && *p3u!=0 && *p4u!=0) { if (*f1==9) *f1=8; if (*f2==9) *f2=8; if (*f3==9) *f3=8; if (*f4==9) *f4=8; } p1++; p2++; p3++; p4++; p1u++; p2u++; p3u++; p4u++; f1++; f2++; f3++; f4++; } } /* Loop through grid, finding starting locations for a contour line. Once found, call gxsflw to follow the contour until it is closed. The contour is closed by following the grid boundry (and missing-data-value boundries) if necessary. */ for (j=jmn; j<=jmx; j++) { p1 = r + ((j-1)*imax+imn-1); p2 = p1+1; p4 = p1+imax; f1 = flgh + ((j-1)*imax+imn-1); f4 = flgv + ((j-1)*imax+imn-1); for (i=imn; i<=imx; i++) { if (i<imx && (*f1==0 || *f1==8) && ( (*p1<=val && *p2>val) || (*p1>val && *p2<=val) ) ) { if (j==jmx) rc = gxsflw(i,j-1,3); else rc = gxsflw(i,j,1); if (rc) goto err; } if (j<jmx && (*f4==0 || *f4==8) && ( (*p1<=val && *p4>val) || (*p1>val && *p4<=val) ) ) { if (i==imx) rc = gxsflw(i-1,j,2); else rc = gxsflw(i,j,4); if (rc) goto err; } p1++; p2++; p4++; f1++; f4++; } } /* Check for any unfilled regions by looking for any unfollowed boundry or missing-data-value sides that have point values that are both greater than the current shade value. This indicates a possible closed region (closed by missing data value boundries) that we have not yet picked up. We will bound that region and fill it. */ for (j=jmn; j<=jmx; j++) { p1 = r + ((j-1)*imax+imn-1); p2 = p1+1; p4 = p1+imax; f1 = flgh + ((j-1)*imax+imn-1); f4 = flgv + ((j-1)*imax+imn-1); for (i=imn; i<=imx; i++) { rc = 0; if (i<imx) { if (j==jmn && *f1==0 && *p1>val && *p2>val) rc = gxsflw(i,j,5); if (j==jmx && *f1==0 && *p1>val && *p2>val) rc = gxsflw(i,j,6); if (*f1==8 && *p1>val && *p2>val) rc = gxsflw(i+1,j,9); } if (j<jmx) { if (i==imn && *f4==0 && *p1>val && *p4>val) rc = gxsflw(i,j,7); if (i==imx && *f4==0 && *p1>val && *p4>val) rc = gxsflw(i,j,8); if (*f4==8 && *p1>val && *p4>val) rc = gxsflw(i,j+1,10); } if (rc) goto err; f1++; f4++; p1++; p2++; p4++; } } prvclr = color; } /* All closed maximas have been filled, and all closed minimas have been stacked. Fill minimas in reverse order. */ /* Note: to insure the various bands 'fit' together properly, the boundry points are adjusted outward slightly. This due to the Xserver not filling out to the boundry in poly fills. */ for (i=stkcnt-1; i>=0; i--) { xypnt = xystk[i]; xycnt = (gaint)(*xypnt); color = (gaint)(*(xypnt+1)); xypnt+=2; for (j=0; j<xycnt; j++) { gxconv(*(xypnt+(j*2)),*(xypnt+(j*2+1)),&x,&y,3); *(xypnt+(j*2)) = x; *(xypnt+(j*2+1)) = y; } gxcolr (color); gxfill (xypnt, xycnt); free(xystk[i]); } stkcnt = 0; xycnt = 0; } /* Free memory areas */ free(xybuf); free(flgh); free(flgv); return; err: printf ("Error in gxshad\n"); for (i=0; i<stkcnt; i++) free(xystk[i]); free(xybuf); free(flgh); free(flgv); return; }
gaint gxsflw (gaint i, gaint j, gaint iside) { /* Follow a shaded outline to the end. Close it if necessary by following around undef areas and around the grid border. */ /* The grid box: (f3) p4 side 3 p3 x ------------ x | | side 4 | | side 2 (f4) | | (f2) | | x ------------ x p1 side 1 p2 (f1) */ gaint *f1,*f2,*f3,*f4,*ff,*fu,*fd,*fl,*fr; gaint cnt,rc,isave,jsave,uflag,ucflg,bflag,k; gadouble *p1,*p2,*p3,*p4; gadouble x,y; isave = i; jsave = j; uflag = 0; bndflg = 0; bflag = 0; if (iside==1) goto side1; /* Jump in based on side */ if (iside==2) goto side2; if (iside==3) goto side3; if (iside==4) goto side4; bflag = 1; if (iside==5) goto br; if (iside==6) goto tr; if (iside==7) goto lu; if (iside==8) goto ru; if (iside==9) goto ur; if (iside==10) goto uu; printf ("Logic error 40 in gxshad\n"); return (1); /* Calculate entry point in the current grid box, then move to the next grid box based on the exit side. */ side1: /* Enter side 1 */ if (i<imn || i>(imx-1) || j<jmn || j>jmx) { printf ("logic error 12 in gxshad\n"); printf (" side1, %i %i \n",i,j); return(1); } p1 = gr + (imax*(j-1)+i-1); p2 = p1+1; x = (gadouble)i + (val-*p1)/(*p2-*p1); /* Calculate entry point */ y = (gadouble)j; rc = putxy(x,y); /* Put points in buffer */ if (rc) return(rc); f1 = flgh + (imax*(j-1)+i-1); if (*f1==1 || *f1==7) goto done; /* We may be done */ if (*f1>5 && !uflag) { /* Entered an undef box? */ if (*f1==9) { printf ("Logic error 4 in gxshad: %i %i\n",i,j); return(1); } *f1 = 7; /* Indicate we were here */ if (*p1>val) { rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uleft; } else { i++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uright; } } if (*f1==8) *f1 = 7; /* Indicate we were here */ else *f1 = 1; uflag = 0; if (j+1>jmx) { /* At top boundry? */ if (*p1>val) { rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto tleft; } else { i++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto tright; } } /* Check for exit side. Also check for col. */ p3 = p2+imax; p4 = p3-1; if ( (*p2<=val && *p3>val) || (*p2>val && *p3<=val) ) { if ( (*p3<=val && *p4>val) || (*p3>val && *p4<=val) ) { if (!spathl(*p1, *p2, *p3, *p4)) { i--; goto side2; /* Exiting 4, go enter 2 */ } } i++; goto side4; /* Exiting 2, go enter 4 */ } if ( (*p3<=val && *p4>val) || (*p3>val && *p4<=val) ) { j++; goto side1; /* Exiting 3, go enter 1 */ } if ( (*p4<=val && *p1>val) || (*p4>val && *p1<=val) ) { i--; goto side2; /* Exiting 4, go enter 2 */ } printf ("Logic error 8 in gxshad\n"); return(1); side2: /* Enter side 2 */ if (i<(imn-1) || i>(imx-1) || j<jmn || j>(jmx-1)) { printf ("logic error 12 in gxshad\n"); printf (" side2, %i %i \n",i,j); return(1); } p2 = gr + (imax*(j-1)+i); p3 = p2+imax; x = (gadouble)(i+1); y = (gadouble)j + (val-*p2)/(*p3-*p2); /* Calculate entry point */ rc = putxy(x,y); /* Put points in buffer */ if (rc) return(rc); f2 = flgv + (imax*(j-1)+i); if (*f2==1 || *f2==7) goto done; /* We may be done */ if (*f2>5 && !uflag) { /* Entered an undef box? */ if (*f2==9) { printf ("Logic error 4 in gxshad: %i %i\n",i,j); printf ("Side 2, entered %i \n",iside); return(1); } *f2 = 7; /* Indicate we were here */ if (*p2>val) { i++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto udown; } else { i++; j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uup; } } if (*f2==8) *f2 = 7; /* Indicate we were here */ else *f2 = 1; uflag = 0; if (i<imn) { /* At left boundry? */ if (*p2>val) { i++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto ldown; } else { i++; j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto lup; } } /* Check for exit side. Also check for col. */ p1 = p2-1; p4 = p3-1; if ( (*p3<=val && *p4>val) || (*p3>val && *p4<=val) ) { if ( (*p4<=val && *p1>val) || (*p4>val && *p1<=val) ) { if (spathl(*p1, *p2, *p3, *p4)) { j--; goto side3; /* Exiting 1, go enter 3 */ } } j++; goto side1; /* Exiting 3, go enter 1 */ } if ( (*p4<=val && *p1>val) || (*p4>val && *p1<=val) ) { i--; goto side2; /* Exiting 4, go enter 2 */ } if ( (*p1<=val && *p2>val) || (*p1>val && *p2<=val) ) { j--; goto side3; /* Exiting 1, go enter 3 */ } printf ("Logic error 8 in gxshad\n"); return(1); side3: /* Enter side 3 */ if (i<imn || i>(imx-1) || j<(jmn-1) || j>(jmx-1)) { printf ("logic error 12 in gxshad\n"); printf (" side3, %i %i \n",i,j); return(1); } p3 = gr + (imax*(j)+i); p4 = p3-1; x = (gadouble)i + (val-*p4)/(*p3-*p4); /* Calculate entry point */ y = (gadouble)(j+1); rc = putxy(x,y); /* Put points in buffer */ if (rc) return(rc); f3 = flgh + (imax*(j)+i-1); if (*f3==1 || *f3==7) goto done; /* We may be done */ if (*f3>5 && !uflag) { /* Entered an undef box? */ if (*f3==9) { printf ("Logic error 4 in gxshad: %i %i\n",i,j); printf ("Side 3, entered %i \n",iside); return(1); } *f3 = 7; /* Indicate we were here */ if (*p3>val) { i++; j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uright; } else { j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uleft; } } if (*f3==8) *f3 = 7; /* Indicate we were here */ else *f3 = 1; uflag = 0; if (j<jmn) { /* At bottom boundry? */ if (*p3>val) { i++; j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto bright; } else { j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto bleft; } } /* Check for exit side. Also check for col. */ p1 = p4-imax; p2 = p1+1; if ( (*p1<=val && *p4>val) || (*p1>val && *p4<=val) ) { if ( (*p1<=val && *p2>val) || (*p1>val && *p2<=val) ) { if (!spathl(*p1, *p2, *p3, *p4)) { i++; goto side4; /* Exiting 2, go enter 4 */ } } i--; goto side2; /* Exiting 4, go enter 2 */ } if ( (*p1<=val && *p2>val) || (*p1>val && *p2<=val) ) { j--; goto side3; /* Exiting 1, go enter 3 */ } if ( (*p2<=val && *p3>val) || (*p2>val && *p3<=val) ) { i++; goto side4; /* Exiting 2, go enter 4 */ } printf ("Logic error 8 in gxshad\n"); return(1); side4: /* Enter side 4 */ if (i<1 || i>imax || j<1 || j>(jmax-1)) { printf ("logic error 12 in gxshad\n"); printf (" side4, %i %i \n",i,j); printf (" imax, jmax = %i %i \n",imax,jmax); return(1); } p1 = gr + (imax*(j-1)+i-1); p4 = p1+imax; x = (gadouble)i; y = (gadouble)j + (val-*p1)/(*p4-*p1); /* Calculate entry point */ rc = putxy(x,y); /* Put points in buffer */ if (rc) return(rc); f4 = flgv + ((j-1)*imax+i-1); if (*f4==1 || *f4==7) goto done; /* We may be done */ if (*f4>5 && !uflag) { /* Entered an undef box? */ if (*f4==9) { printf ("Logic error 4 in gxshad: %i %i\n",i,j); printf ("Side 4, entered %i \n",iside); return(1); } *f4 = 7; /* Indicate we were here */ if (*p1>val) { rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto udown; } else { j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uup; } } if (*f4==8) *f4 = 7; /* Indicate we were here */ else *f4 = 1; uflag = 0; if (i+1>imx) { /* At right boundry? */ if (*p1>val) { rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto rdown; } else { j++; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto rup; } } /* Check for exit side. Also check for col. */ p2 = p1+1; p3 = p4+1; if ( (*p1<=val && *p2>val) || (*p1>val && *p2<=val) ) { if ( (*p2<=val && *p3>val) || (*p2>val && *p3<=val) ) { if (spathl(*p1, *p2, *p3, *p4)) { j++; goto side1; /* Exiting 3, go enter 1 */ } } j--; goto side3; /* Exiting 1, go enter 3 */ } if ( (*p2<=val && *p3>val) || (*p2>val && *p3<=val) ) { i++; goto side4; /* Exiting 2, go enter 4 */ } if ( (*p3<=val && *p4>val) || (*p3>val && *p4<=val) ) { j++; goto side1; /* Exiting 3, go enter 1 */ } printf ("Logic error 8 in gxshad\n"); return(1); /* At an undefined boundry and last moved towards the left. */ uleft: bndflg = 1; if (bflag && i==isave && j==jsave) goto done; if (j<(jmn+1)||j>jmx-1) { printf ("Logic error 16 in gxshad\n"); return (1); } fu = flgv + ((j-1)*imax+i-1); fd = fu-imax; if (i==imn) { if ((*fu>5 && *fd>5) || (*fu<5 && *fd<5)) { printf ("Logic error 20 in gxshad\n"); return (1); } if (*fu>5) goto ldown; else goto lup; } ff = flgh + ((j-1)*imax+i-2); cnt=0; if (*ff==7 || *ff==8) cnt++; if (*fu==7 || *fu==8) cnt++; if (*fd==7 || *fd==8) cnt++; if (cnt==2 || cnt==0) { printf ("Logic error 24 in gxshad\n"); return (1); } ucflg = 0; if (cnt==3) ucflg = undcol(i,j); if (ucflg==9) return(1); if (!ucflg && (*ff==7 || *ff==8)) { i--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (*fu>5) { j--; goto side3; } else goto side1; } *ff = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uleft; } if (ucflg!=2 && (*fd==7 || *fd==8)) { j--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fu==9) { goto side4; } else { i--; goto side2; } } *fd = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto udown; } if (ucflg!=1 && (*fu==7 || *fu==8)) { j++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fd==9) { j--; goto side4; } else { i--; j--; goto side2; } } *fu = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uup; } printf ("Logic error 28 in gxshad\n"); return(1); /* At an undefined boundry and last moved towards the right. */ uright: if (bflag && i==isave && j==jsave) goto done; ur: bndflg = 1; if (j<(jmn+1)||j>jmx-1) { printf ("Logic error 16 in gxshad\n"); return (1); } fu = flgv + ((j-1)*imax+i-1); fd = fu-imax; if (i==imx) { if ((*fu>5 && *fd>5) || (*fu<5 && *fd<5)) { printf ("Logic error 20 in gxshad\n"); return (1); } if (*fu>5) goto rdown; else goto rup; } ff = flgh + ((j-1)*imax+i-1); cnt=0; if (*ff==7 || *ff==8) cnt++; if (*fd==7 || *fd==8) cnt++; if (*fu==7 || *fu==8) cnt++; if (cnt==2 || cnt==0) { printf ("Logic error 24 in gxshad\n"); return (1); } ucflg = 0; if (cnt==3) ucflg = undcol(i,j); if (ucflg==9) return(1); if (!ucflg && (*ff==7 || *ff==8)) { i++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; i--; if (*fu>5) { j--; goto side3; } else goto side1; } *ff = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uright; } if (ucflg!=1 && (*fd==7 || *fd==8)) { j--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fu==9) { i--; goto side2; } else { goto side4; } } *fd = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto udown; } if (ucflg!=2 && (*fu==7 || *fu==8)) { j++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fd==9) { i--; j--; goto side2; } else { j--; goto side4; } } *fu = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uup; } printf ("Logic error 28 in gxshad\n"); return(1); /* At an undefined boundry and last moved towards the top. */ uup: if (bflag && i==isave && j==jsave) goto done; uu: bndflg = 1; if (i<(imn+1)||i>imx-1) { printf ("Logic error 16 in gxshad\n"); return (1); } fr = flgh + ((j-1)*imax+i-1); fl = fr-1; if (j==jmx) { if ((*fr>5 && *fl>5) || (*fr<5 && *fl<5)) { printf ("Logic error 20 in gxshad\n"); return (1); } if (*fr>5) goto tleft; else goto tright; } ff = flgv + ((j-1)*imax+i-1); cnt=0; if (*ff==7 || *ff==8) cnt++; if (*fr==7 || *fr==8) cnt++; if (*fl==7 || *fl==8) cnt++; if (cnt==2 || cnt==0) { printf ("Logic error 24 in gxshad\n"); return (1); } ucflg = 0; if (cnt==3) ucflg = undcol(i,j); if (ucflg==9) return(1); if (!ucflg && (*ff==7 || *ff==8)) { j++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { j--; uflag = 1; if (*fr>5) { i--; goto side2; } else goto side4; } *ff = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uup; } if (ucflg!=2 && (*fr==7 || *fr==8)) { i++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fl==9) { i--; j--; goto side3; } else { i--; goto side1; } } *fr = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uright; } if (ucflg!=1 && (*fl==7 || *fl==8)) { i--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fr==9) { j--; goto side3; } else { goto side1; } } *fl = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uleft; } printf ("Logic error 28 in gxshad\n"); return(1); /* At an undefined boundry and last moved towards the bottom. */ udown: bndflg = 1; if (bflag && i==isave && j==jsave) goto done; if (i<(imn+1)||i>imx-1) { printf ("Logic error 16 in gxshad\n"); return (1); } fr = flgh + ((j-1)*imax+i-1); fl = fr-1; if (j==jmn) { if ((*fr>5 && *fl>5) || (*fr<5 && *fl<5)) { printf ("Logic error 20 in gxshad\n"); return (1); } if (*fr>5) goto bleft; else goto bright; } ff = flgv + ((j-2)*imax+i-1); cnt=0; if (*ff==7 || *ff==8) cnt++; if (*fr==7 || *fr==8) cnt++; if (*fl==7 || *fl==8) cnt++; if (cnt==2 || cnt==0) { printf ("Logic error 24 in gxshad\n"); return (1); } ucflg = 0; if (cnt==3) ucflg = undcol(i,j); if (ucflg==9) return(1); if (!ucflg && (*ff==7 || *ff==8)) { j--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (*fr>5) { i--; goto side2; } else goto side4; } *ff = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto udown; } if (ucflg!=1 && (*fr==7 || *fr==8)) { i++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fl==9) { i--; goto side1; } else { i--; j--; goto side3; } } *fr = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uright; } if (ucflg!=2 && (*fl==7 || *fl==8)) { i--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { uflag = 1; if (ucflg || *fr==9) { goto side1; } else { j--; goto side3; } } *fl = 7; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto uleft; } printf ("Logic error 28 in gxshad\n"); return(1); /* Follow grid boundry until we hit a missing data area, or until we hit the restart of the contour line. */ tright: if (bflag && i==isave && j==jsave) goto done; tr: bndflg = 1; if (i==imx) goto rdown; ff = flgh + ((j-1)*imax+i-1); if (*ff>5) goto udown; i++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { j--; i--; goto side3; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto tright; tleft: bndflg = 1; if (bflag && i==isave && j==jsave) goto done; if (i==imn) goto ldown; ff = flgh + ((j-1)*imax+i-2); if (*ff>5) goto udown; i--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { j--; goto side3; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto tleft; bright: if (bflag && i==isave && j==jsave) goto done; br: bndflg = 1; if (i==imx) goto rup; ff = flgh + ((j-1)*imax+i-1); if (*ff>5) goto uup; i++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { i--; goto side1; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto bright; bleft: bndflg = 1; if (bflag && i==isave && j==jsave) goto done; if (i==imn) goto lup; ff = flgh + ((j-1)*imax+i-2); if (*ff>5) goto uup; i--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { goto side1; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto bleft; rup: if (bflag && i==isave && j==jsave) goto done; ru: bndflg = 1; if (j==jmx) goto tleft; ff = flgv + ((j-1)*imax+i-1); if (*ff>5) goto uleft; j++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { j--; i--; goto side2; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto rup; rdown: bndflg = 1; if (bflag && i==isave && j==jsave) goto done; if (j==jmn) goto bleft; ff = flgv + ((j-2)*imax+i-1); if (*ff>5) goto uleft; j--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { i--; goto side2; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto rdown; lup: if (bflag && i==isave && j==jsave) goto done; lu: bndflg = 1; if (j==jmx) goto tright; ff = flgv + ((j-1)*imax+i-1); if (*ff>5) goto uright; j++; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { j--; goto side4; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto lup; ldown: bndflg = 1; if (bflag && i==isave && j==jsave) goto done; if (j==jmn) goto bright; ff = flgv + ((j-2)*imax+i-1); if (*ff>5) goto uright; j--; p1 = gr + ((j-1)*imax+i-1); if (*p1<=val) { goto side4; } *ff = 1; rc = putxy((gadouble)i,(gadouble)j); if (rc) return(rc); goto ldown; done: shdcmp(); if (xycnt<4) goto cont; if (shdmax()) { for (k=0; k<xycnt; k++) { gxconv(*(xybuf+(k*2)),*(xybuf+(k*2+1)),&x,&y,3); *(xybuf+(k*2)) = x; *(xybuf+(k*2+1)) = y; } gxcolr (color); gxfill (xybuf, xycnt); } else { xystk[stkcnt] = (gadouble *)malloc(sizeof(gadouble)*(xycnt+1)*2); if (xystk[stkcnt]==NULL) { printf ("Memory allocation error in gxshad: stack buffer\n"); return (1); } xypnt = xystk[stkcnt]; *xypnt = (gadouble)(xycnt)+0.1; *(xypnt+1) = (gadouble)(prvclr)+0.1; xypnt+=2; for (k=0; k<xycnt; k++) { *(xypnt+(k*2)) = *(xybuf+(k*2)); *(xypnt+(k*2+1)) = *(xybuf+(k*2+1)); } stkcnt++; if (stkcnt>=XYBMAX) { printf ("Buffer stack limit exceeded in gxshad\n"); return(1); } } cont: xycnt = 0; return (0); }
void gxstrm (gadouble *u, gadouble *v, gadouble *c, gaint is, gaint js, char *umask, char *vmask, char *cmask, gaint flag, gadouble *shdlvs, gaint *shdcls, gaint shdcnt, gaint den) { gadouble x,y,xx,yy; gadouble *up, *vp, *cp, cv1,cv2,cv; gadouble uv1,uv2,uv,vv1,vv2,vv,auv,avv,xsav,ysav,xold=0.0,yold=0.0; gadouble fact,rscl,xxsv,yysv; gaint i,ii,jj,ii1,ij1,i2,j2,ipt,acnt,icol,scol,dis; gaint *it,siz,iacc,iisav,iscl,imn,imx,jmn,jmx,iz,jz,iss,jss,bflg; char *upmask,*vpmask,*cpmask; scol = -9; icol = 1; /* Figure out the interval for the flag grid */ i = is; if (js>i) i = js; iscl = 200/i; iscl = iscl + den - 5; if (iscl<1) iscl=1; if (iscl>10) iscl=10; fact = 0.5/((gadouble)iscl); rscl = (gadouble)iscl; /* Allocate memory for the flag grid */ iss = is*iscl; jss = js*iscl; siz = iss*jss; it = (gaint *)malloc(sizeof(gaint) * siz); if (it==NULL) { printf ("Cannot allocate memory for streamline function\n"); return; } for (i=0; i<siz; i++) *(it+i) = 0; /* Loop through flag grid to look for start of streamlines. To start requires no streams drawn within surrounding flag boxes. */ i2 = 0; j2 = 0; for (i=0; i<siz; i++) { dis = 2; if (den<5) dis = 3; if (den>5) dis = 1; imn = i2-dis; imx = i2+dis+1; jmn = j2-dis; jmx = j2+dis+1; if (imn<0) imn = 0; if (imx>iss) imx = iss; if (jmn<0) jmn = 0; if (jmx>jss) jmx = jss; iacc = 0; for (jz=jmn; jz<jmx; jz++) { ipt = jz*iss+imn; for (iz=imn; iz<imx; iz++) { iacc = iacc + *(it+ipt); ipt++; } } if (iacc==0) { x = ((gadouble)i2)/rscl; y = ((gadouble)j2)/rscl; xsav = x; ysav = y; gxconv (x+1.0,y+1.0,&xx,&yy,3); gxplot (xx,yy,3); xxsv = xx; yysv = yy; iisav = -999; iacc = 0; acnt = 0; bflg = 0; while (x>=0.0 && x<(gadouble)(is-1) && y>=0.0 && y<(gadouble)(js-1)) { ii = (gaint)x; jj = (gaint)y; xx = x - (gadouble)ii; yy = y - (gadouble)jj; up = u + jj*is+ii; upmask = umask + jj*is+ii; vp = v + jj*is+ii; vpmask = vmask + jj*is+ii; if (*upmask==0 || *(upmask+1)==0 || *(upmask+is)==0 || *(upmask+is+1)==0) break; if (*vpmask==0 || *(vpmask+1)==0 || *(vpmask+is)==0 || *(vpmask+is+1)==0) break; if (flag) { cp = c + jj*is+ii; cpmask = cmask + jj*is+ii; if (*cpmask==0 || *(cpmask+1)==0 || *(cpmask+is)==0 || *(cpmask+is+1)==0) icol = 15; else { cv1 = *cp + (*(cp+1)-*cp)*xx; cv2 = *(cp+is) + (*(cp+is+1)-*(cp+is))*xx; cv = cv1 + (cv2-cv1)*yy; icol = gxshdc(shdlvs,shdcls,shdcnt,cv); } if (icol!=scol && icol>-1) gxcolr(icol); scol = icol; } uv1 = *up + (*(up+1)-*up)*xx; uv2 = *(up+is) + (*(up+is+1)-*(up+is))*xx; uv = uv1 + (uv2-uv1)*yy; vv1 = *vp + (*(vp+1)-*vp)*xx; vv2 = *(vp+is) + (*(vp+is+1)-*(vp+is))*xx; vv = vv1 + (vv2-vv1)*yy; auv = fabs(uv); avv=fabs(vv); if (auv<0.1 && avv<0.1) break; if (auv>avv) { vv = vv*fact/auv; uv = uv*fact/auv; } else { uv = uv*fact/avv; vv = vv*fact/avv; } x = x + uv; y = y + vv; ii1 = (gaint)(x*rscl); ij1 = (gaint)(y*rscl); ii1 = ij1*iss + ii1; if (ii1<0 || ii1>=siz) break; if (*(it+ii1)==1) break; if (ii1!=iisav && iisav>-1) *(it+iisav) = 1; if (ii1==iisav) iacc++; else iacc = 0; if (iacc>10) break; iisav = ii1; gxconv (x+1.0,y+1.0,&xx,&yy,3); if (icol>-1) { if (bflg) { gxplot(xold,yold,3); bflg=0; } gxplot (xx,yy,2); } else bflg = 1; xold = xx; yold = yy; acnt++; if (acnt>20) { if (icol>-1) strmar (xxsv,yysv,xx,yy); acnt = 0; } xxsv = xx; yysv = yy; } bflg = 0; x = xsav; y = ysav; gxconv (x+1.0,y+1.0,&xx,&yy,3); gxplot (xx,yy,3); xxsv = xx; yysv = yy; iisav = -999; iacc = 0; acnt = 19; while (x>=0.0 && x<(gadouble)(is-1) && y>=0.0 && y<(gadouble)(js-1)) { ii = (gaint)x; jj = (gaint)y; xx = x - (gadouble)ii; yy = y - (gadouble)jj; up = u + jj*is+ii; upmask = umask + jj*is+ii; vp = v + jj*is+ii; vpmask = vmask + jj*is+ii; if (*upmask==0 || *(upmask+1)==0 || *(upmask+is)==0 || *(upmask+is+1)==0) break; if (*vpmask==0 || *(vpmask+1)==0 || *(vpmask+is)==0 || *(vpmask+is+1)==0) break; if (flag) { cp = c + jj*is+ii; cpmask = cmask + jj*is+ii; if (*cpmask==0 || *(cpmask+1)==0 || *(cpmask+is)==0 || *(cpmask+is+1)==0) icol = 15; else { cv1 = *cp + (*(cp+1)-*cp)*xx; cv2 = *(cp+is) + (*(cp+is+1)-*(cp+is))*xx; cv = cv1 + (cv2-cv1)*yy; icol = gxshdc(shdlvs,shdcls,shdcnt,cv); } if (icol!=scol && icol>-1) gxcolr(icol); scol = icol; } uv1 = *up + (*(up+1)-*up)*xx; uv2 = *(up+is) + (*(up+is+1)-*(up+is))*xx; uv = uv1 + (uv2-uv1)*yy; vv1 = *vp + (*(vp+1)-*vp)*xx; vv2 = *(vp+is) + (*(vp+is+1)-*(vp+is))*xx; vv = vv1 + (vv2-vv1)*yy; auv = fabs(uv); avv=fabs(vv); if (auv<0.1 && avv<0.1) break; if (auv>avv) { vv = vv*fact/auv; uv = uv*fact/auv; } else { uv = uv*fact/avv; vv = vv*fact/avv; } x = x - uv; y = y - vv; ii1 = (gaint)(x*rscl); ij1 = (gaint)(y*rscl); ii1 = ij1*iss + ii1; if (ii1<0 || ii1>=siz) break; if (*(it+ii1)==1) break; if (ii1!=iisav && iisav>-1) *(it+iisav) = 1; if (ii1==iisav) iacc++; else iacc = 0; if (iacc>10) break; iisav = ii1; gxconv (x+1.0,y+1.0,&xx,&yy,3); if (icol>-1) { if (bflg) { gxplot(xold,yold,3); bflg=0; } gxplot (xx,yy,2); } else bflg = 1; xold = xx; yold = yy; acnt++; if (acnt>20) { if (icol>-1) strmar(xx,yy,xxsv,yysv); acnt = 0; } xxsv = xx; yysv = yy; } } i2++; if (i2==iss) { i2 = 0; j2++; } } free (it); }