00001 
00011 #include "gdata.h"
00012 #include "jbxl_state.h"
00013 
00014 
00015 int     ZeroBase = 0;
00016 double  RZxy     = 1.0;     
00017 int     ChkRZxy  = OFF;     
00018 
00019 
00028 void  free_CmnHead(CmnHead* hd)
00029 {
00030     if (hd!=NULL) {
00031         if (hd->buf!=NULL)   free(hd->buf);
00032         if (hd->grptr!=NULL) free(hd->grptr);
00033         init_CmnHead(hd);
00034     }
00035 }
00036 
00037 
00038 
00046 void  init_CmnHead(CmnHead* hd)
00047 {
00048     if (hd!=NULL) {
00049         memset(hd, 0, sizeof(CmnHead));
00050         hd->kind = HEADER_NONE;
00051     }
00052 }
00053 
00054 
00055 
00069 BSGraph  make_BSGraph(int xs, int ys, int zs)
00070 {
00071     int  i;
00072     BSGraph  vp;
00073 
00074     memset(&vp, 0, sizeof(BSGraph));
00075     if (xs==0 || ys==0) {
00076         vp.state = JBXL_GRAPH_IVDARG_ERROR;
00077         return vp;
00078     }
00079 
00080     vp.xs = xs;
00081     vp.ys = ys;
00082     if (zs>0) vp.zs = zs;
00083     else      vp.zs = 1;
00084     vp.state = JBXL_NORMAL;
00085 
00086     vp.gp = (uByte*)malloc(vp.xs*vp.ys*vp.zs*sizeof(uByte));
00087     if (vp.gp==NULL) {
00088         memset(&vp, 0, sizeof(BSGraph));
00089         vp.state = JBXL_GRAPH_MEMORY_ERROR;
00090         return vp;
00091     }
00092 
00093     for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0;
00094 
00095     return vp;
00096 }
00097 
00098 
00099 
00113 WSGraph  make_WSGraph(int xs, int ys, int zs)
00114 {
00115     int  i;
00116     WSGraph  vp;
00117 
00118     memset(&vp, 0, sizeof(WSGraph));
00119     if (xs==0 || ys==0) {
00120         vp.state = JBXL_GRAPH_IVDARG_ERROR;
00121         return vp;
00122     }
00123 
00124     vp.xs = xs;
00125     vp.ys = ys;
00126     if (zs>0) vp.zs = zs;
00127     else      vp.zs = 1;
00128     vp.state = JBXL_NORMAL;
00129 
00130     vp.gp = (sWord*)malloc(vp.xs*vp.ys*vp.zs*sizeof(sWord));
00131     if (vp.gp==NULL) {
00132         memset(&vp, 0, sizeof(WSGraph));
00133         vp.state = JBXL_GRAPH_MEMORY_ERROR;
00134         return vp;
00135     }
00136 
00137     for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0;
00138 
00139     return vp;
00140 }
00141 
00142 
00143 
00157 FSGraph  make_FSGraph(int xs, int ys, int zs)
00158 {
00159     int  i;
00160     FSGraph  vp;
00161 
00162     memset(&vp, 0, sizeof(FSGraph));
00163     if (xs==0 || ys==0) {
00164         vp.state = JBXL_GRAPH_IVDARG_ERROR;
00165         return vp;
00166     }
00167 
00168     vp.xs = xs;
00169     vp.ys = ys;
00170     if (zs>0) vp.zs = zs;
00171     else      vp.zs = 1;
00172     vp.state = JBXL_NORMAL;
00173 
00174     vp.gp = (double*)malloc(vp.xs*vp.ys*vp.zs*sizeof(double));
00175     if (vp.gp==NULL) {
00176         memset(&vp, 0, sizeof(FSGraph));
00177         vp.state = JBXL_GRAPH_MEMORY_ERROR;
00178         return vp;
00179     }
00180 
00181     for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0.0;
00182 
00183     return vp;
00184 }
00185 
00186 
00187 
00201 ISGraph  make_ISGraph(int xs, int ys, int zs)
00202 {
00203     int  i;
00204     ISGraph  vp;
00205 
00206     memset(&vp, 0, sizeof(ISGraph));
00207     if (xs==0 || ys==0) {
00208         vp.state = JBXL_GRAPH_IVDARG_ERROR;
00209         return vp;
00210     }
00211 
00212     vp.xs = xs;
00213     vp.ys = ys;
00214     if (zs>0) vp.zs = zs;
00215     else      vp.zs = 1;
00216     vp.state = JBXL_NORMAL;
00217 
00218     vp.gp = (int*)malloc(vp.xs*vp.ys*vp.zs*sizeof(int));
00219     if (vp.gp==NULL) {
00220         memset(&vp, 0, sizeof(ISGraph));
00221         vp.state = JBXL_GRAPH_MEMORY_ERROR;
00222         return vp;
00223     }
00224 
00225     for (i=0; i<vp.xs*vp.ys*vp.zs; i++) vp.gp[i] = 0;
00226 
00227     return vp;
00228 }
00229 
00230 
00231 
00245 VSGraph  make_VSGraph(int xs, int ys, int zs)
00246 {
00247     int  i;
00248     VSGraph  vp;
00249 
00250     memset(&vp, 0, sizeof(VSGraph));
00251     if (xs==0 || ys==0) {
00252         vp.state = JBXL_GRAPH_IVDARG_ERROR;
00253         return vp;
00254     }
00255 
00256     vp.xs = xs;
00257     vp.ys = ys;
00258     if (zs>0) vp.zs = zs;
00259     else      vp.zs = 1;
00260     vp.state = JBXL_NORMAL;
00261 
00262     vp.gp = (vector*)malloc(xs*ys*zs*sizeof(vector));
00263     if (vp.gp==NULL) {
00264         memset(&vp, 0, sizeof(VSGraph));
00265         vp.state = JBXL_GRAPH_MEMORY_ERROR;
00266         return vp;
00267     }
00268 
00269     for (i=0; i<xs*ys*zs; i++) vp.gp[i] = set_vector(0.0, 0.0, 0.0);
00270 
00271     return vp;
00272 }
00273 
00274 
00275 
00290 MSGraph  make_MSGraph(int xs, int ys, int zs, int depth)
00291 {
00292     MSGraph  vp;
00293 
00294     memset(&vp, 0, sizeof(MSGraph));
00295     if (xs==0 || ys==0) {
00296         vp.state = JBXL_GRAPH_IVDARG_ERROR;
00297         return vp;
00298     }
00299 
00300     vp.xs = xs;
00301     vp.ys = ys;
00302     if (zs>0) vp.zs = zs;
00303     else      vp.zs = 1;
00304     if (depth>0) vp.depth = depth;
00305     else         vp.depth = 1;
00306     vp.state = JBXL_NORMAL;
00307 
00308     vp.gp = (unsigned char*)malloc(xs*ys*zs*((depth+7)/8));
00309     if (vp.gp==NULL) {
00310         memset(&vp, 0, sizeof(MSGraph));
00311         vp.state = JBXL_GRAPH_MEMORY_ERROR;
00312         return vp;
00313     }
00314 
00315     memset(vp.gp, 0, xs*ys*zs*((depth+7)/8));
00316     return vp;
00317 }
00318 
00319 
00320 
00334 BSGraph* new_BSGraph(int xs, int ys, int zs)
00335 {
00336     int  i;
00337     BSGraph* vp;
00338 
00339     vp = (BSGraph*)malloc(sizeof(BSGraph));
00340     if (vp==NULL) return NULL;
00341     memset(vp, 0, sizeof(BSGraph));
00342 
00343     if (xs==0 || ys==0) {
00344         vp->state = JBXL_GRAPH_IVDARG_ERROR;
00345         return vp;
00346     }
00347 
00348     vp->xs = xs;
00349     vp->ys = ys;
00350     if (zs>0) vp->zs = zs;
00351     else      vp->zs = 1;
00352     vp->state = JBXL_NORMAL;
00353 
00354     vp->gp = (uByte*)malloc(vp->xs*vp->ys*vp->zs*sizeof(uByte));
00355     if (vp->gp==NULL) {
00356         memset(vp, 0, sizeof(BSGraph));
00357         vp->state = JBXL_GRAPH_MEMORY_ERROR;
00358         return vp;
00359     }
00360 
00361     for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0;
00362 
00363     return vp;
00364 }
00365 
00366 
00367 
00381 WSGraph* new_WSGraph(int xs, int ys, int zs)
00382 {
00383     int  i;
00384     WSGraph* vp;
00385 
00386     vp = (WSGraph*)malloc(sizeof(WSGraph));
00387     if (vp==NULL) return NULL;
00388     memset(vp, 0, sizeof(WSGraph));
00389 
00390     if (xs==0 || ys==0) {
00391         vp->state = JBXL_GRAPH_IVDARG_ERROR;
00392         return vp;
00393     }
00394 
00395     vp->xs = xs;
00396     vp->ys = ys;
00397     if (zs>0) vp->zs = zs;
00398     else      vp->zs = 1;
00399     vp->state = JBXL_NORMAL;
00400 
00401     vp->gp = (sWord*)malloc(vp->xs*vp->ys*vp->zs*sizeof(sWord));
00402     if (vp->gp==NULL) {
00403         memset(vp, 0, sizeof(WSGraph));
00404         vp->state = JBXL_GRAPH_MEMORY_ERROR;
00405         return vp;
00406     }
00407 
00408     for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0;
00409 
00410     return vp;
00411 }
00412 
00413 
00414 
00428 FSGraph* new_FSGraph(int xs, int ys, int zs)
00429 {
00430     int  i;
00431     FSGraph* vp;
00432 
00433     vp = (FSGraph*)malloc(sizeof(FSGraph));
00434     if (vp==NULL) return NULL;
00435     memset(vp, 0, sizeof(FSGraph));
00436 
00437     if (xs==0 || ys==0) {
00438         vp->state = JBXL_GRAPH_IVDARG_ERROR;
00439         return vp;
00440     }
00441 
00442     vp->xs = xs;
00443     vp->ys = ys;
00444     if (zs>0) vp->zs = zs;
00445     else      vp->zs = 1;
00446     vp->state = JBXL_NORMAL;
00447 
00448     vp->gp = (double*)malloc(vp->xs*vp->ys*vp->zs*sizeof(double));
00449     if (vp->gp==NULL) {
00450         memset(vp, 0, sizeof(FSGraph));
00451         vp->state = JBXL_GRAPH_MEMORY_ERROR;
00452         return vp;
00453     }
00454 
00455     for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0.0;
00456 
00457     return vp;
00458 }
00459 
00460 
00461 
00475 ISGraph* new_ISGraph(int xs, int ys, int zs)
00476 {
00477     int  i;
00478     ISGraph* vp;
00479 
00480     vp = (ISGraph*)malloc(sizeof(ISGraph));
00481     if (vp==NULL) return NULL;
00482 
00483     memset(vp, 0, sizeof(ISGraph));
00484     if (xs==0 || ys==0) {
00485         vp->state = JBXL_GRAPH_IVDARG_ERROR;
00486         return vp;
00487     }
00488 
00489     vp->xs = xs;
00490     vp->ys = ys;
00491     if (zs>0) vp->zs = zs;
00492     else      vp->zs = 1;
00493     vp->state = JBXL_NORMAL;
00494 
00495     vp->gp = (int*)malloc(vp->xs*vp->ys*vp->zs*sizeof(int));
00496     if (vp->gp==NULL) {
00497         memset(vp, 0, sizeof(ISGraph));
00498         vp->state = JBXL_GRAPH_MEMORY_ERROR;
00499         return vp;
00500     }
00501 
00502     for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = 0;
00503 
00504     return vp;
00505 }
00506 
00507 
00508 
00522 VSGraph* new_VSGraph(int xs, int ys, int zs)
00523 {
00524     int  i;
00525     VSGraph* vp;
00526 
00527     vp = (VSGraph*)malloc(sizeof(VSGraph));
00528     if (vp==NULL) return NULL;
00529     memset(vp, 0, sizeof(VSGraph));
00530 
00531     if (xs==0 || ys==0) {
00532         vp->state = JBXL_GRAPH_IVDARG_ERROR;
00533         return vp;
00534     }
00535 
00536     vp->xs = xs;
00537     vp->ys = ys;
00538     if (zs>0) vp->zs = zs;
00539     else      vp->zs = 1;
00540     vp->state = JBXL_NORMAL;
00541 
00542     vp->gp = (vector*)malloc(vp->xs*vp->ys*vp->zs*sizeof(vector));
00543     if (vp->gp==NULL) {
00544         memset(vp, 0, sizeof(VSGraph));
00545         vp->state = JBXL_GRAPH_MEMORY_ERROR;
00546         return vp;
00547     }
00548 
00549     for (i=0; i<vp->xs*vp->ys*vp->zs; i++) vp->gp[i] = set_vector(0.0, 0.0, 0.0);
00550 
00551     return vp;
00552 }
00553 
00554 
00555 
00570 MSGraph* new_MSGraph(int xs, int ys, int zs, int depth)
00571 {
00572     MSGraph* vp;
00573 
00574     vp = (MSGraph*)malloc(sizeof(MSGraph));
00575     if (vp==NULL) return NULL;
00576     memset(vp, 0, sizeof(MSGraph));
00577 
00578     if (xs==0 || ys==0) {
00579         vp->state = JBXL_GRAPH_IVDARG_ERROR;
00580         return vp;
00581     }
00582 
00583     vp->xs = xs;
00584     vp->ys = ys;
00585     if (zs>0) vp->zs = zs;
00586     else      vp->zs = 1;
00587     if (depth>0) vp->depth = depth;
00588     else         vp->depth = 1;
00589     vp->state = JBXL_NORMAL;
00590 
00591     vp->gp = (unsigned char*)malloc(vp->xs*vp->ys*vp->zs*((depth+7)/8));
00592     if (vp->gp==NULL) {
00593         memset(vp, 0, sizeof(MSGraph));
00594         vp->state = JBXL_GRAPH_MEMORY_ERROR;
00595         return vp;
00596     }
00597 
00598     memset(vp->gp, 0, vp->xs*vp->ys*vp->zs*((depth+7)/8));
00599     return vp;
00600 }
00601 
00602 
00603 
00613 ISGraph  W2ISGraph(WSGraph vp)
00614 {
00615     int  i;
00616     ISGraph  ix;
00617 
00618     ix.xs = vp.xs;
00619     ix.ys = vp.ys;
00620     ix.zs = vp.zs;
00621     ix.state = vp.state;
00622 
00623     ix.gp = (int*)malloc(ix.xs*ix.ys*ix.zs*sizeof(int));
00624     if (ix.gp==NULL) {
00625         memset(&ix, 0, sizeof(ISGraph));
00626         ix.state = JBXL_GRAPH_MEMORY_ERROR;
00627         return ix;
00628     }
00629 
00630     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (int)vp.gp[i];
00631     return ix;
00632 }
00633 
00634 
00635 
00645 FSGraph  W2FSGraph(WSGraph vp)
00646 {
00647     int  i;
00648     FSGraph  ix;
00649 
00650     ix.xs = vp.xs;
00651     ix.ys = vp.ys;
00652     ix.zs = vp.zs;
00653     ix.state = vp.state;
00654 
00655     ix.gp = (double*)malloc(ix.xs*ix.ys*ix.zs*sizeof(double));
00656     if (ix.gp==NULL) {
00657         memset(&ix, 0, sizeof(FSGraph));
00658         ix.state = JBXL_GRAPH_MEMORY_ERROR;
00659         return ix;
00660     }
00661 
00662     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i]=(double)vp.gp[i];
00663     return ix;
00664 }
00665 
00666 
00667 
00677 WSGraph  B2WSGraph(BSGraph vp)
00678 {
00679     int  i;
00680     WSGraph  ix;
00681 
00682     ix.xs = vp.xs;
00683     ix.ys = vp.ys;
00684     ix.zs = vp.zs;
00685     ix.state = vp.state;
00686 
00687     ix.gp = (sWord*)malloc(ix.xs*ix.ys*ix.zs*sizeof(sWord));
00688     if (ix.gp==NULL) {
00689         memset(&ix, 0, sizeof(WSGraph));
00690         ix.state = JBXL_GRAPH_MEMORY_ERROR;
00691         return ix;
00692     }
00693 
00694     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i];
00695     return ix;
00696 }
00697 
00698 
00699 
00709 WSGraph  I2WSGraph(ISGraph vp)
00710 {
00711     int  i;
00712     WSGraph  ix;
00713 
00714     ix.xs = vp.xs;
00715     ix.ys = vp.ys;
00716     ix.zs = vp.zs;
00717     ix.state = vp.state;
00718 
00719     ix.gp = (sWord*)malloc(ix.xs*ix.ys*ix.zs*sizeof(sWord));
00720     if (ix.gp==NULL) {
00721         memset(&ix, 0, sizeof(WSGraph));
00722         ix.state = JBXL_GRAPH_MEMORY_ERROR;
00723         return ix;
00724     }
00725 
00726     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i];
00727     return ix;
00728 }
00729 
00730 
00731 
00741 WSGraph  F2WSGraph(FSGraph vp)
00742 {
00743     int  i;
00744     WSGraph ix;
00745 
00746     ix.xs = vp.xs;
00747     ix.ys = vp.ys;
00748     ix.zs = vp.zs;
00749     ix.state = vp.state;
00750 
00751     ix.gp = (sWord*)malloc(ix.xs*ix.ys*ix.zs*sizeof(sWord));
00752     if (ix.gp==NULL) {
00753         memset(&ix, 0, sizeof(WSGraph));
00754         ix.state = JBXL_GRAPH_MEMORY_ERROR;
00755         return ix;
00756     }
00757 
00758     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i];
00759     return ix;
00760 }
00761 
00762 
00763 
00773 FSGraph  V2FSGraph(VSGraph vp)
00774 {
00775     int  i;
00776     FSGraph ix;
00777 
00778     ix = make_FSGraph(vp.xs, vp.ys, vp.zs);
00779     if (ix.gp==NULL) return ix;
00780 
00781     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = vp.gp[i].n;
00782     ix.state = vp.state;
00783 
00784     return ix;
00785 }
00786 
00787 
00788 
00797 WSGraph  V2WSGraph(VSGraph vp)
00798 {
00799     int  i;
00800     WSGraph  ix;
00801 
00802     ix = make_WSGraph(vp.xs, vp.ys, vp.zs);
00803     if (ix.gp==NULL) return ix;
00804 
00805     for (i=0; i<ix.xs*ix.ys*ix.zs; i++) ix.gp[i] = (sWord)vp.gp[i].n;
00806     ix.state = vp.state;
00807 
00808     return ix;
00809 }
00810 
00811 
00812 
00820 void  init_IRBound(IRBound* rb)
00821 {
00822     rb->xmax = rb->ymax = rb->zmax = 0;
00823     rb->xmin = rb->ymin = rb->zmin = SINTMAX;
00824     rb->misc = OFF;
00825 }
00826 
00827 
00828 
00836 void  init_DRBound(DRBound* rb)
00837 {
00838     rb->xmax = rb->ymax = rb->zmax = 0.0;
00839     rb->xmin = rb->ymin = rb->zmin = DBL_MAX;
00840     rb->misc = OFF;
00841 }
00842 
00843 
00844 
00853 void  set_RZxy(double rzm)
00854 {
00855     ChkRZxy = ON;
00856     RZxy = rzm;
00857     
00858 }
00859 
00860 
00861 
00868 int  chk_RZxy(void)   
00869 {
00870     if (ChkRZxy==OFF) {
00871         DEBUG_MODE PRINT_MESG("CHK_RZXY: WARNING: undefined RZxy!!!\n");
00872         
00873         return FALSE;
00874     }
00875     return TRUE;
00876 }
00877 
00878