int main(int argc, char *argv[]) { BAR("first test"); BAR("second test: %s", "a string"); return 0; }
int main(void) { BAR("%s", "123456789"); BAR("%s", "hello"); BAR("%s", "world"); BAR("%s", "lenghui1012"); BAR("f**k you: %d", 100); printf("%s\n", json_data); printf("%d\n", strlen(json_data)); }
int main() { FOO(12, 20); BAR(1); XXPRINTF("my name is %s", "richard"); return 0; }
int main( void ) /***************/ { int i; bool noneyet; /*printf( "extern UINT8 IsArray[] = {\n" );*/ printf( "/*STRM_MAGIC*/ 0,\n" ); printf( "/*STRM_END */ 0" ); /* note: no ",\n" !! */ for( i = 0; i <= 255; i++ ) { noneyet = true; if( isprint( i ) ) { printf( ",\n/* '%c' */ ", i ); } else { printf( ",\n/* 0x%02x */ ", i ); } if( isws( i ) ) { BAR( IS_WS ); } if( isprt( i ) ) { BAR( IS_PRINT ); } if( isalpha( i ) ) { BAR( IS_ALPHA ); } if( isextc( i ) ) { BAR( IS_EXTC ); } if( isdirc( i ) ) { BAR( IS_DIRC ); } if( isfilec( i ) ) { BAR( IS_FILEC ); } if( ismacc( i ) ) { BAR( IS_MACC ); } if( isbarf( i ) ) { BAR( IS_BARF ); } if( noneyet ) { printf( "0" ); } } /*printf("\n};\n");*/ printf( "\n" ); return( 0 ); }
int main() { int a = 42; char *c = BAR( __LINE__ ) puts(c); puts(d); puts(__FILE__); puts(__func__); return __LINE__ + FOO ( 1 + a *, 2 ) + e; }
int main() { if (2 > 4) FOO(2) /* 这里 FOO(2) 后面一定不能添加分号,否则会报错 */ else FOO(4) /* 这里 FOO(4) 后面可加分号,也可不加,一般是不加 */ if (2 < 4) BAR(2); /* 这里 BAR(2) 后面一定要加分号,否则会报错 */ else BAR(4) /* 同时,这里的 BAR(4) 后面也一定要加分号! */ return 0; }
/* Check if there are any records in the dripback loop left. */ static bool DripBackCheckBusy(landing_dripback2_t *db2) { detref_t *first; /* check if dripback loop is still active */ while ((first = SNetFifoPeekFirst(&db2->detfifo)) != NULL) { BAR(); if (first->refcount > 0) { break; } SNetFifoGet(&db2->detfifo); SNetFifoDone(&first->recfifo); SNetDelete(first); } return first ? true : false; }
/* Process a stolen item. */ static void SNetWorkerLoot(worker_t *worker) { if (worker->loot.desc) { if (worker->loot.item) { if (worker->loot.count > 0) { AAF(&(worker->loot.item->count), worker->loot.count); } if (trylock_work_item(worker->loot.item, worker)) { if (worker->loot.item->count > 0) { SNetWorkerWorkItem(worker->loot.item, worker); } if (worker->loot.item->lock == worker->id) { unlock_work_item(worker->loot.item, worker); } } } else /* (worker->loot.item == NULL) */ { work_item_t *item = GetFreeWorkItem(worker); item->next_item = NULL; item->next_free = NULL; item->desc = worker->loot.desc; item->lock = worker->id; item->count = worker->loot.count; SNetHashPtrStore(worker->hash_ptab, item->desc, item); SNetWorkerWorkItem(item, worker); if (item->count == 0) { if (item->desc) { SNetHashPtrRemove(worker->hash_ptab, item->desc); } item->lock = worker->id; PutFreeWorkItem(worker, item); } else { item->lock = 0; item->next_item = worker->prev->next_item; BAR(); worker->prev->next_item = worker->iter = item; } } worker->loot.desc = NULL; worker->loot.count = 0; worker->loot.item = NULL; worker->has_work = (worker->todo.head.next_item != NULL); } }
/* Add a new unit of work to the worker's todo list. * At return iterator should point to the new item. */ void SNetWorkerTodo(worker_t *worker, snet_stream_desc_t *desc) { work_item_t *item = SNetHashPtrLookup(worker->hash_ptab, desc); if (item) { /* Item may be locked by a thief. */ AAF(&item->count, 1); } else { item = GetFreeWorkItem(worker); item->count = 1; item->desc = desc; item->lock = 0; item->next_free = NULL; item->next_item = worker->prev->next_item; BAR(); worker->prev->next_item = item; worker->prev = item; SNetHashPtrStore(worker->hash_ptab, desc, item); worker->has_work = true; } }
int dCollideBoxPlane (dxGeom *o1, dxGeom *o2, int flags, dContactGeom *contact, int skip) { dxBox *box = (dxBox*) o1; dxPlane *plane = (dxPlane*) o2; contact->g1 = o1; contact->g2 = o2; int ret = 0; //@@@ problem: using 4-vector (plane->p) as 3-vector (normal). const dReal *R = o1->final_posr->R; // rotation of box const dReal *n = plane->p; // normal vector // project sides lengths along normal vector, get absolute values dReal Q1 = dDOT14(n,R+0); dReal Q2 = dDOT14(n,R+1); dReal Q3 = dDOT14(n,R+2); dReal A1 = dMUL(box->side[0],Q1); dReal A2 = dMUL(box->side[1],Q2); dReal A3 = dMUL(box->side[2],Q3); dReal B1 = dFabs(A1); dReal B2 = dFabs(A2); dReal B3 = dFabs(A3); // early exit test dReal depth = plane->p[3] + dMUL(REAL(0.5),(B1+B2+B3)) - dDOT(n,o1->final_posr->pos); if (depth < 0) return 0; // find number of contacts requested int maxc = flags & NUMC_MASK; if (maxc < 1) maxc = 1; if (maxc > 3) maxc = 3; // no more than 3 contacts per box allowed // find deepest point dVector3 p; p[0] = o1->final_posr->pos[0]; p[1] = o1->final_posr->pos[1]; p[2] = o1->final_posr->pos[2]; #define FOO(i,op) \ p[0] op dMUL(REAL(0.5),dMUL(box->side[i],R[0+i])); \ p[1] op dMUL(REAL(0.5),dMUL(box->side[i],R[4+i])); \ p[2] op dMUL(REAL(0.5),dMUL(box->side[i],R[8+i])); #define BAR(i,iinc) if (A ## iinc > 0) { FOO(i,-=) } else { FOO(i,+=) } BAR(0,1); BAR(1,2); BAR(2,3); #undef FOO #undef BAR // the deepest point is the first contact point contact->pos[0] = p[0]; contact->pos[1] = p[1]; contact->pos[2] = p[2]; contact->normal[0] = n[0]; contact->normal[1] = n[1]; contact->normal[2] = n[2]; contact->depth = depth; ret = 1; // ret is number of contact points found so far if (maxc == 1) goto done; // get the second and third contact points by starting from `p' and going // along the two sides with the smallest projected length. #define FOO(i,j,op) \ CONTACT(contact,i*skip)->pos[0] = p[0] op dMUL(box->side[j],R[0+j]); \ CONTACT(contact,i*skip)->pos[1] = p[1] op dMUL(box->side[j],R[4+j]); \ CONTACT(contact,i*skip)->pos[2] = p[2] op dMUL(box->side[j],R[8+j]); #define BAR(ctact,side,sideinc) \ depth -= B ## sideinc; \ if (depth < 0) goto done; \ if (A ## sideinc > 0) { FOO(ctact,side,+) } else { FOO(ctact,side,-) } \ CONTACT(contact,ctact*skip)->depth = depth; \ ret++; CONTACT(contact,skip)->normal[0] = n[0]; CONTACT(contact,skip)->normal[1] = n[1]; CONTACT(contact,skip)->normal[2] = n[2]; if (maxc == 3) { CONTACT(contact,2*skip)->normal[0] = n[0]; CONTACT(contact,2*skip)->normal[1] = n[1]; CONTACT(contact,2*skip)->normal[2] = n[2]; } if (B1 < B2) { if (B3 < B1) goto use_side_3; else { BAR(1,0,1); // use side 1 if (maxc == 2) goto done; if (B2 < B3) goto contact2_2; else goto contact2_3; } } else { if (B3 < B2) { use_side_3: // use side 3 BAR(1,2,3); if (maxc == 2) goto done; if (B1 < B2) goto contact2_1; else goto contact2_2; } else { BAR(1,1,2); // use side 2 if (maxc == 2) goto done; if (B1 < B3) goto contact2_1; else goto contact2_3; } } contact2_1: BAR(2,0,1); goto done; contact2_2: BAR(2,1,2); goto done; contact2_3: BAR(2,2,3); goto done; #undef FOO #undef BAR done: for (int i=0; i<ret; i++) { CONTACT(contact,i*skip)->g1 = o1; CONTACT(contact,i*skip)->g2 = o2; } return ret; }
int dCollideBoxPlane (dxGeom *o1, dxGeom *o2, int flags, dContactGeom *contact, int skip) { dIASSERT (skip >= (int)sizeof(dContactGeom)); dIASSERT (o1->type == dBoxClass); dIASSERT (o2->type == dPlaneClass); dIASSERT ((flags & NUMC_MASK) >= 1); dxBox *box = (dxBox*) o1; dxPlane *plane = (dxPlane*) o2; contact->g1 = o1; contact->g2 = o2; contact->side1 = -1; contact->side2 = -1; int ret = 0; //@@@ problem: using 4-vector (plane->p) as 3-vector (normal). const dReal *R = o1->final_posr->R; // rotation of box const dReal *n = plane->p; // normal vector // project sides lengths along normal vector, get absolute values dReal Q1 = dCalcVectorDot3_14(n,R+0); dReal Q2 = dCalcVectorDot3_14(n,R+1); dReal Q3 = dCalcVectorDot3_14(n,R+2); dReal A1 = box->side[0] * Q1; dReal A2 = box->side[1] * Q2; dReal A3 = box->side[2] * Q3; dReal B1 = dFabs(A1); dReal B2 = dFabs(A2); dReal B3 = dFabs(A3); // early exit test dReal depth = plane->p[3] + REAL(0.5)*(B1+B2+B3) - dCalcVectorDot3(n,o1->final_posr->pos); if (depth < 0) return 0; // find number of contacts requested int maxc = flags & NUMC_MASK; // if (maxc < 1) maxc = 1; // an assertion is made on entry if (maxc > 4) maxc = 4; // not more than 4 contacts per box allowed // find deepest point dVector3 p; p[0] = o1->final_posr->pos[0]; p[1] = o1->final_posr->pos[1]; p[2] = o1->final_posr->pos[2]; #define FOO(i,op) \ p[0] op REAL(0.5)*box->side[i] * R[0+i]; \ p[1] op REAL(0.5)*box->side[i] * R[4+i]; \ p[2] op REAL(0.5)*box->side[i] * R[8+i]; #define BAR(i,iinc) if (A ## iinc > 0) { FOO(i,-=) } else { FOO(i,+=) } BAR(0,1); BAR(1,2); BAR(2,3); #undef FOO #undef BAR // the deepest point is the first contact point contact->pos[0] = p[0]; contact->pos[1] = p[1]; contact->pos[2] = p[2]; contact->depth = depth; ret = 1; // ret is number of contact points found so far if (maxc == 1) goto done; // get the second and third contact points by starting from `p' and going // along the two sides with the smallest projected length. #define FOO(i,j,op) \ CONTACT(contact,i*skip)->pos[0] = p[0] op box->side[j] * R[0+j]; \ CONTACT(contact,i*skip)->pos[1] = p[1] op box->side[j] * R[4+j]; \ CONTACT(contact,i*skip)->pos[2] = p[2] op box->side[j] * R[8+j]; #define BAR(ctact,side,sideinc) \ if (depth - B ## sideinc < 0) goto done; \ if (A ## sideinc > 0) { FOO(ctact,side,+); } else { FOO(ctact,side,-); } \ CONTACT(contact,ctact*skip)->depth = depth - B ## sideinc; \ ret++; if (B1 < B2) { if (B3 < B1) goto use_side_3; else { BAR(1,0,1); // use side 1 if (maxc == 2) goto done; if (B2 < B3) goto contact2_2; else goto contact2_3; } } else { if (B3 < B2) { use_side_3: // use side 3 BAR(1,2,3); if (maxc == 2) goto done; if (B1 < B2) goto contact2_1; else goto contact2_2; } else { BAR(1,1,2); // use side 2 if (maxc == 2) goto done; if (B1 < B3) goto contact2_1; else goto contact2_3; } } contact2_1: BAR(2,0,1); goto done; contact2_2: BAR(2,1,2); goto done; contact2_3: BAR(2,2,3); goto done; #undef FOO #undef BAR done: if (maxc == 4 && ret == 3) { // If user requested 4 contacts, and the first 3 were created... // Combine contacts 2 and 3 (vectorial sum) and get the fourth one // Result: if a box face is completely inside a plane, contacts are created for all the 4 vertices dReal d4 = CONTACT(contact,1*skip)->depth + CONTACT(contact,2*skip)->depth - depth; // depth is the depth for first contact if (d4 > 0) { CONTACT(contact,3*skip)->pos[0] = CONTACT(contact,1*skip)->pos[0] + CONTACT(contact,2*skip)->pos[0] - p[0]; // p is the position of first contact CONTACT(contact,3*skip)->pos[1] = CONTACT(contact,1*skip)->pos[1] + CONTACT(contact,2*skip)->pos[1] - p[1]; CONTACT(contact,3*skip)->pos[2] = CONTACT(contact,1*skip)->pos[2] + CONTACT(contact,2*skip)->pos[2] - p[2]; CONTACT(contact,3*skip)->depth = d4; ret++; } } for (int i=0; i<ret; i++) { dContactGeom *currContact = CONTACT(contact,i*skip); currContact->g1 = o1; currContact->g2 = o2; currContact->side1 = -1; currContact->side2 = -1; currContact->normal[0] = n[0]; currContact->normal[1] = n[1]; currContact->normal[2] = n[2]; } return ret; }
int main(int argc,char *argv[]) { ////////////////////////////////////////////////////////////// //PROGRAM VARIBALES ////////////////////////////////////////////////////////////// char datafile[FSIZE]="",derintfile[FSIZE]=""; int numcols=0,colx=0,coly=0; int i,ndata; ////////////////////////////////////////////////////////////// //INITIALIZE ////////////////////////////////////////////////////////////// TITLE(stdout,'*',"COMPUTE DERIVATIVES AND INTEGRAL OF DATA"); ////////////////////////////////////////////////////////////// //SET OPTIONS AND USAGE ////////////////////////////////////////////////////////////// SET_OPTIONS(":hvVf:d:n:x:y:"); SET_USAGE( "=======================================================================================\n" "Usage:\n\n" "\t./program -f <datafile> [-d <derint_file>] -n <numcols> -x <colx> -y <coly>\n" "\n" "Take columns <colx> and <coly> from <datafile> and computes the first\n" "and second derivative but also the integral in the interval. The\n" "results are stored in file <derint_file>\n" "=======================================================================================\n" ); ////////////////////////////////////////////////////////////// //READ OPTIONS ////////////////////////////////////////////////////////////// while(ITEROPTIONS){ switch(OPTION){ case 'f': strcpy(datafile,optarg); break; case 'd': strcpy(derintfile,optarg); break; case 'n': numcols=atoi(optarg); break; case 'x': colx=atoi(optarg); break; case 'y': coly=atoi(optarg); break; //======================================== //COMMON //======================================== case 'v': VERBOSITY=1; break; case 'V': VERBOSITY=2; break; //DETECT ERRORS OPTION_ERRORS; } } ////////////////////////////////////////////////////////////// //VALIDATE OPTIONS ////////////////////////////////////////////////////////////// if(isBlank(datafile)){ fprintf(stderr,"Error: No datafile was provided\n"); PRINT_USAGE; EXIT; } if(!fileExists(datafile)){ fprintf(stderr,"Error: Datafile '%s' does not exist\n",datafile); PRINT_USAGE; EXIT; } if(isBlank(derintfile)){ sprintf(derintfile,"%s.der",datafile); } if((ndata=countLines(datafile))==0){ fprintf(stderr,"Error: Datafile '%s' seems empty\n",datafile); PRINT_USAGE; EXIT; } if(numcols<1){ fprintf(stderr,"Error: The number of columns should be different from 0\n"); PRINT_USAGE; EXIT; } if(colx==0){ colx=0; } if(coly==0){ coly=1; } ////////////////////////////////////////////////////////////// //REPORT INPUT INFORMATION ////////////////////////////////////////////////////////////// if(VERBOSE(1)){ BAR(stdout,'O'); fprintf(stdout,"Datafile: %s\n",datafile); fprintf(stdout,"Der. Int. file: %s\n",derintfile); fprintf(stdout,"Number of columns: %d\n",numcols); fprintf(stdout,"Columns x,y: %d,%d\n",colx,coly); fprintf(stdout,"Number of points in datafile: %d\n",ndata); BAR(stdout,'O'); } ////////////////////////////////////////////////////////////// //PROGRAM ////////////////////////////////////////////////////////////// //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //READING DATA //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STPRINTF("Reading %d data points from datafile '%s'...\n",ndata,datafile); real *X=readColumns(datafile,ndata,numcols,colx); real *Y=readColumns(datafile,ndata,numcols,coly); //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //COMPUTING DERIVATIVES //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STPRINTF("Computing derivatives and integral...\n"); file fd=fileOpen(derintfile,"w"); fprintf(fd,"#Datafile: %s\n",datafile); fprintf(fd,"#NumberColumns: %d\n",numcols); fprintf(fd,"#ColX,ColY: %d %d\n",colx,coly); fprintf(fd,"%-14s %-14s %-14s %-14s %-14s\n", "#1:X","2:Y","3:dydx","4:d2ydx2","5:integ"); real dx,dydx,d2ydx2,integ=0; for(i=0;i<ndata;i++){ if(i==0){ dx=X[i+1]-X[i]; dydx=(Y[i+1]-Y[i])/dx; d2ydx2=(Y[2]-2*Y[1]+Y[0])/((X[2]-X[0])/2*(X[2]-X[0])/2); integ+=(Y[i]+Y[i+1])/2*dx; }else if(i==ndata-1){ dx=X[i]-X[i-1]; dydx=(Y[i]-Y[i-1])/dx; d2ydx2=(Y[ndata-1]-2*Y[ndata-2]+Y[ndata-3])/ ((X[ndata-1]-X[ndata-3])/2*(X[ndata-1]-X[ndata-3])/2); integ+=(Y[i]+Y[i-1])/2*dx; }else{ dx=X[i+1]-X[i-1]; dydx=(Y[i+1]-Y[i-1])/dx; d2ydx2=(Y[i+1]-2*Y[i]+Y[i-1])/(dx/2*dx/2); integ+=(Y[i+1]+Y[i-1])/2*(dx/2); } fprintf(fd,"%+14.7e %+14.7e %+14.7e %+14.7e %+14.7e\n", X[i],Y[i],dydx,d2ydx2,integ); } fclose(fd); STPRINTF("Done.\n"); return 0; }
int_triple THD_orient_guess( MRI_IMAGE *imm ) { int nvox , ii , nx,ny,nxy,nz , ix,jy,kz , icm,jcm,kcm , nbar ; byte *bar , bp,bm ; float xcm , ycm , zcm , ff , dx,dy,dz ; float xx,yy,zz ; int ni,nj,nk , itop,jtop,ktop , im,ip , jm,jp , km,kp ; float axx,ayy,azz , clip , qx,qy,qz , arr[3] ; int d_LR , d_AP , d_IS ; int_triple it = {-1,-1,-1} ; /*-- check for bad input --*/ if( imm == NULL || imm->nx < 5 || imm->ny < 5 || imm->nz < 5 ) return it ; nx = imm->nx; ny = imm->ny; nz = imm->nz; nxy = nx*ny; nvox = nx*ny*nz; dx = fabs(imm->dx) ; if( dx == 0.0 ) dx = 1.0 ; dy = fabs(imm->dy) ; if( dy == 0.0 ) dy = 1.0 ; dz = fabs(imm->dz) ; if( dz == 0.0 ) dz = 1.0 ; /*-- make mask of NPER levels --*/ bar = (byte *) malloc( sizeof(byte) * nvox ) ; clip = THD_cliplevel( imm , 0.5 ) ; /* start with a binary mask */ switch( imm->kind ){ case MRI_float:{ float *ar = MRI_FLOAT_PTR(imm) ; for( ii=0 ; ii < nvox ; ii++ ) bar[ii] = (ar[ii] >= clip); } break ; case MRI_short:{ short *ar = MRI_SHORT_PTR(imm) ; for( ii=0 ; ii < nvox ; ii++ ) bar[ii] = (ar[ii] >= clip); } break ; case MRI_byte:{ byte *ar = MRI_BYTE_PTR(imm) ; for( ii=0 ; ii < nvox ; ii++ ) bar[ii] = (ar[ii] >= clip); } break ; } nbar = THD_countmask(nvox,bar) ; printf("%d voxels in initial binary mask\n",nbar) ; if( nbar == 0 ){ free(bar); return it; } /* bad */ THD_mask_clust( nx,ny,nz , bar ) ; /* take biggest cluster */ nbar = THD_countmask(nvox,bar) ; printf("%d voxels in final binary mask\n",nbar) ; #ifdef NPER if( nper > 1 ){ float per[NPER+1] ; MRI_IMAGE *qim ; int jj ; qim = mri_new( nbar , 1 , imm->kind ) ; switch(imm->kind){ case MRI_float:{ float *ar=MRI_FLOAT_PTR(imm) , *qar=MRI_FLOAT_PTR(qim) ; for( jj=ii=0 ; ii < nvox ; ii++ ) if( bar[ii] ) qar[jj++] = ar[ii] ; } break ; case MRI_short:{ short *ar=MRI_SHORT_PTR(imm) , *qar=MRI_SHORT_PTR(qim) ; for( jj=ii=0 ; ii < nvox ; ii++ ) if( bar[ii] ) qar[jj++] = ar[ii] ; } break ; case MRI_byte:{ byte *ar=MRI_BYTE_PTR(imm) , *qar=MRI_BYTE_PTR(qim) ; for( jj=ii=0 ; ii < nvox ; ii++ ) if( bar[ii] ) qar[jj++] = ar[ii] ; } break ; } printf("call mri_percents\n") ; mri_percents( qim , nper , per ) ; /* compute nper break points */ mri_free(qim) ; printf("per:") ; for( ii=0 ; ii <= nper ; ii++ ) printf(" %g",per[ii]) ; printf("\n") ; switch( imm->kind ){ case MRI_float:{ float *ar = MRI_FLOAT_PTR(imm) , val ; for( ii=0 ; ii < nvox ; ii++ ){ if( bar[ii] ){ val = ar[ii] ; for( jj=1 ; jj <= nper && val >= per[jj] ; jj++ ) ; /*spin*/ bar[ii] = jj ; } } } break ; case MRI_short:{ short *ar = MRI_SHORT_PTR(imm) , val ; for( ii=0 ; ii < nvox ; ii++ ){ if( bar[ii] ){ val = ar[ii] ; for( jj=1 ; jj <= nper && val >= per[jj] ; jj++ ) ; /*spin*/ bar[ii] = jj ; } } } break ; case MRI_byte:{ byte *ar = MRI_BYTE_PTR(imm) , val ; for( ii=0 ; ii < nvox ; ii++ ){ if( bar[ii] ){ val = ar[ii] ; for( jj=1 ; jj <= nper && val >= per[jj] ; jj++ ) ; /*spin*/ bar[ii] = jj ; } } } break ; } } #endif /* NPER */ /* find center of mass of mask */ xcm = ycm = zcm = ff = 0.0 ; for( ii=0 ; ii < nvox ; ii++ ){ if( bar[ii] ){ ix = (ii % nx) ; xx = ix*dx ; xcm += xx*bar[ii] ; jy = (ii / nx) % ny ; yy = jy*dy ; ycm += yy*bar[ii] ; kz = (ii /nxy) ; zz = kz*dz ; zcm += zz*bar[ii] ; ff += bar[ii] ; } } xcm /= ff ; ycm /= ff ; zcm /= ff ; icm = rint(xcm/dx) ; itop = 2*icm ; if( itop >= nx ) itop = nx-1 ; ni = itop-icm ; jcm = rint(ycm/dy) ; jtop = 2*jcm ; if( jtop >= ny ) jtop = ny-1 ; nj = jtop-jcm ; kcm = rint(zcm/dz) ; ktop = 2*kcm ; if( ktop >= nz ) ktop = nz-1 ; nk = ktop-kcm ; printf("Mask count = %d\n" "icm = %d jcm = %d kcm = %d\n" "ni = %d nj = %d nk = %d\n", (int)ff , icm,jcm,kcm , ni,nj,nk ) ; /** compute asymmetry measures about CM voxel **/ #define BAR(i,j,k) bar[(i)+(j)*nx+(k)*nxy] axx = 0.0 ; for( ix=1 ; ix <= ni ; ix++ ){ im = icm-ix ; ip = icm+ix ; for( kz=kcm-nk ; kz <= kcm+nk ; kz++ ){ for( jy=jcm-nj ; jy <= jcm+nj ; jy++ ) axx += abs(BAR(ip,jy,kz) - BAR(im,jy,kz)) ; } } axx /= (ni*nj*nk) ; printf("axx = %g\n",axx) ; ayy = 0.0 ; for( jy=1 ; jy <= nj ; jy++ ){ jm = jcm-jy ; jp = jcm+jy ; for( kz=kcm-nk ; kz <= kcm+nk ; kz++ ){ for( ix=icm-ni ; ix <= icm+ni ; ix++ ) ayy += abs(BAR(ix,jp,kz) - BAR(ix,jm,kz)) ; } } ayy /= (ni*nj*nk) ; printf("ayy = %g\n",ayy) ; azz = 0.0 ; for( kz=1 ; kz <= nk ; kz++ ){ km = kcm-kz ; kp = kcm+kz ; for( jy=jcm-nj ; jy <= jcm+nj ; jy++ ){ for( ix=icm-ni ; ix <= icm+ni ; ix++ ) azz += abs(BAR(ix,jy,kp) - BAR(ix,jy,km)) ; } } azz /= (ni*nj*nk) ; printf("azz = %g\n",azz) ; /** least asymettric is L-R direction **/ if( axx < ayy ){ if( axx < azz ) d_LR = 1 ; else d_LR = 3 ; } else { if( ayy < azz ) d_LR = 2 ; else d_LR = 3 ; } printf("axis %d is L-R\n",d_LR) ; arr[0] = axx ; arr[1] = ayy ; arr[2] = azz ; ff = arr[d_LR-1] ; arr[0] /= ff ; arr[1] /= ff ; arr[2] /= ff ; printf("a ratios = %g %g %g\n",arr[0],arr[1],arr[2]) ; /** find asymmetry measures in 1/2 spaces perp to L-R **/ switch( d_LR ){ case 3:{ /* L-R is z-axis */ float axx_jp=0.0, axx_jm=0.0, ayy_ip=0.0, ayy_im=0.0 ; for( ix=1 ; ix <= ni ; ix++ ){ im = icm-ix ; ip = icm+ix ; for( kz=kcm-nk ; kz <= kcm+nk ; kz++ ){ for( jy=1 ; jy <= nj ; jy++ ){ axx_jp += abs(BAR(ip,jcm+jy,kz) - BAR(im,jcm+jy,kz)) ; axx_jm += abs(BAR(ip,jcm-jy,kz) - BAR(im,jcm-jy,kz)) ; } } } for( jy=1 ; jy <= nj ; jy++ ){ jm = jcm-jy ; jp = jcm+jy ; for( kz=kcm-nk ; kz <= kcm+nk ; kz++ ){ for( ix=1 ; ix <= ni ; ix++ ){ ayy_ip += abs(BAR(icm+ix,jp,kz) - BAR(icm+ix,jm,kz)) ; ayy_im += abs(BAR(icm-ix,jp,kz) - BAR(icm-ix,jm,kz)) ; } } } axx_jp /= (ni*nj*nk) ; axx_jm /= (ni*nj*nk) ; ayy_ip /= (ni*nj*nk) ; ayy_im /= (ni*nj*nk) ; printf("axx_jp=%g axx_jm=%g ayy_ip=%g ayy_im=%g\n", axx_jp,axx_jm , ayy_ip,ayy_im ) ; } /* end of case 3 */ break ; } return it ; }
int main(int argc, char **argv) { /* Declare vars. */ CDKSCREEN *cdkscreen = 0; CDKHISTOGRAM *volume = 0; CDKHISTOGRAM *bass = 0; CDKHISTOGRAM *treble = 0; WINDOW *cursesWin = 0; char *volumeTitle = "<C></5>Volume<!5>"; char *bassTitle = "<C></5>Bass <!5>"; char *trebleTitle = "<C></5>Treble<!5>"; CDK_PARAMS params; boolean Box; CDKparseParams(argc, argv, ¶ms, CDK_CLI_PARAMS); Box = CDKparamValue(¶ms, 'N', TRUE); /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Color. */ initCDKColor(); /* Create the histogram objects. */ volume = newCDKHistogram (cdkscreen, CDKparamValue(¶ms, 'X', 10), CDKparamValue(¶ms, 'Y', 10), CDKparamValue(¶ms, 'H', 1), CDKparamValue(¶ms, 'W', -2), HORIZONTAL, volumeTitle, Box, CDKparamValue(¶ms, 'S', FALSE)); if (volume == 0) { /* Exit CDK. */ destroyCDKScreen (cdkscreen); endCDK(); /* Print out a message and exit. */ printf ("Oops. Can not make volume histogram. Is the window big enough??\n"); ExitProgram (EXIT_FAILURE); } bass = newCDKHistogram (cdkscreen, CDKparamValue(¶ms, 'X', 10), CDKparamValue(¶ms, 'Y', 14), CDKparamValue(¶ms, 'H', 1), CDKparamValue(¶ms, 'W', -2), HORIZONTAL, bassTitle, Box, CDKparamValue(¶ms, 'S', FALSE)); if (bass == 0) { /* Exit CDK. */ destroyCDKHistogram (volume); destroyCDKScreen (cdkscreen); endCDK(); /* Print out a message and exit. */ printf ("Oops. Can not make bass histogram. Is the window big enough??\n"); ExitProgram (EXIT_FAILURE); } treble = newCDKHistogram (cdkscreen, CDKparamValue(¶ms, 'X', 10), CDKparamValue(¶ms, 'Y', 18), CDKparamValue(¶ms, 'H', 1), CDKparamValue(¶ms, 'W', -2), HORIZONTAL, trebleTitle, Box, CDKparamValue(¶ms, 'S', FALSE)); if (treble == 0) { /* Exit CDK. */ destroyCDKHistogram (volume); destroyCDKHistogram (bass); destroyCDKScreen (cdkscreen); endCDK(); /* Print out a message and exit. */ printf ("Oops. Can not make treble histogram. Is the window big enough??\n"); ExitProgram (EXIT_FAILURE); } #define BAR(a,b,c) A_BOLD, a, b, c, ' '|A_REVERSE|COLOR_PAIR(3), Box /* Set the histogram values. */ setCDKHistogram (volume, vPERCENT, CENTER, BAR(0, 10, 6)); setCDKHistogram (bass , vPERCENT, CENTER, BAR(0, 10, 3)); setCDKHistogram (treble, vPERCENT, CENTER, BAR(0, 10, 7)); refreshCDKScreen (cdkscreen); sleep (4); /* Set the histogram values. */ setCDKHistogram (volume, vPERCENT, CENTER, BAR(0, 10, 8)); setCDKHistogram (bass , vPERCENT, CENTER, BAR(0, 10, 1)); setCDKHistogram (treble, vPERCENT, CENTER, BAR(0, 10, 9)); refreshCDKScreen (cdkscreen); sleep (4); /* Set the histogram values. */ setCDKHistogram (volume, vPERCENT, CENTER, BAR(0, 10, 10)); setCDKHistogram (bass , vPERCENT, CENTER, BAR(0, 10, 7)); setCDKHistogram (treble, vPERCENT, CENTER, BAR(0, 10, 10)); refreshCDKScreen (cdkscreen); sleep (4); /* Set the histogram values. */ setCDKHistogram (volume, vPERCENT, CENTER, BAR(0, 10, 1)); setCDKHistogram (bass , vPERCENT, CENTER, BAR(0, 10, 8)); setCDKHistogram (treble, vPERCENT, CENTER, BAR(0, 10, 3)); refreshCDKScreen (cdkscreen); sleep (4); /* Set the histogram values. */ setCDKHistogram (volume, vPERCENT, CENTER, BAR(0, 10, 3)); setCDKHistogram (bass , vPERCENT, CENTER, BAR(0, 10, 3)); setCDKHistogram (treble, vPERCENT, CENTER, BAR(0, 10, 3)); refreshCDKScreen (cdkscreen); sleep (4); /* Set the histogram values. */ setCDKHistogram (volume, vPERCENT, CENTER, BAR(0, 10, 10)); setCDKHistogram (bass , vPERCENT, CENTER, BAR(0, 10, 10)); setCDKHistogram (treble, vPERCENT, CENTER, BAR(0, 10, 10)); refreshCDKScreen (cdkscreen); sleep (4); /* Clean up. */ destroyCDKHistogram (volume); destroyCDKHistogram (bass); destroyCDKHistogram (treble); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }
int main () { int i = 0; return BAR(i); }
int main(int argc,char *argv[]) { ////////////////////////////////////////////////////////////// //PROGRAM VARIBALES ////////////////////////////////////////////////////////////// char mapfile[FSIZE]="",distfile[FSIZE]="",type[2]=""; char ctype,coper='s'; int cx=0,cy=1; ////////////////////////////////////////////////////////////// //INITIALIZE ////////////////////////////////////////////////////////////// TITLE(stdout,'*',"COMPUTE A SCALAR MAP"); ////////////////////////////////////////////////////////////// //SET OPTIONS AND USAGE ////////////////////////////////////////////////////////////// SET_OPTIONS(":hvVm:d:t:o:x:y:"); SET_USAGE( "============================================================================\n" "Usage:\n" "\n" "\t./program -m <mapfile> [-d <distfile>] -t <type_dist> [-o <type_oper>]\n" "\t -x <direction_x> [-y <direction_y>]\n" /* Collapse the information in the <mapfile>. Collapsing a map means to produce a 2-D or a 1-D (<type_dist>: 1D or 2D) from a full 3-D map. What collapse do is to take a given direction in the grid and apply over all the cells in that direction an operation (<type_oper>: sum, average). You can indicate the directions that should be preserved (<direction_x> and/or <direction_y>). */ "\n" "=========================================================================\n" ); ////////////////////////////////////////////////////////////// //READ OPTIONS ////////////////////////////////////////////////////////////// while(ITEROPTIONS){ switch(OPTION){ case 'm': strcpy(mapfile,optarg); break; case 'd': strcpy(distfile,optarg); break; case 't': strcpy(type,optarg); break; case 'o': coper=optarg[0]; break; case 'x': cx=atoi(optarg); break; case 'y': cy=atoi(optarg); break; //======================================== //COMMON //======================================== case 'v': VERBOSITY=1; break; case 'V': VERBOSITY=2; break; //DETECT ERRORS OPTION_ERRORS; } } ////////////////////////////////////////////////////////////// //VALIDATE OPTIONS ////////////////////////////////////////////////////////////// if(isBlank(mapfile)){ fprintf(stderr,"Error: No mapfile was provided\n"); PRINT_USAGE; EXIT; } if(!fileExists(mapfile)){ fprintf(stderr,"Error: Mapfile '%s' does not exist\n",mapfile); PRINT_USAGE; EXIT; } if(isBlank(distfile)){ sprintf(distfile,"%s.dst",mapfile); } if(isBlank(type)){ strcpy(type,"1D"); } ctype=type[0]; if(ctype=='2'){ if(cx==cy){ fprintf(stderr,"Error: x(%d) and y(%d) cannot be equal\n",cx,cy,mapfile); PRINT_USAGE; EXIT; } }else{ cy=(cx+1)%3; } ////////////////////////////////////////////////////////////// //REPORT INPUT INFORMATION ////////////////////////////////////////////////////////////// if(VERBOSE(1)){ BAR(stdout,'O'); fprintf(stdout,"Map file: %s\n",mapfile); fprintf(stdout,"Distributuion file: %s\n",distfile); fprintf(stdout,"Type of distribution: %s\n",type); fprintf(stdout,"Type of operation: %c\n",coper); fprintf(stdout,"X column: %d\n",cx); if(ctype!='2') fprintf(stdout,"Y column: %d\n",cy); BAR(stdout,'O'); } ////////////////////////////////////////////////////////////// //PROGRAM ////////////////////////////////////////////////////////////// int i,j,k,n,p; char linea[LSIZE],ctmp[LSIZE]; int nx,ny,nz; real *fieldmap; real x,y,z; real C[3][MAXGRID]; int ix,iy,iz; int ndx,ndy,ndz; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //READ MAP FILE //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STPRINTF("Getting data from mapfile '%s'...\n",mapfile); file fm=fopen(mapfile,"r"); //Read header for(i=1;i<=6;i++) fgets(linea,sizeof linea,fm); //Get number of data points in the grid fgets(linea,sizeof linea,fm); sscanf(linea,"%s %d %d %d",ctmp,&nx,&ny,&nz); fieldmap=(real*)calloc(nx*ny*nz,sizeof(real)); //Read data points fgets(linea,sizeof linea,fm); n=0; for(k=0;k<nz;k++){ for(i=0;i<nx;i++){ for(j=0;j<ny;j++){ p=i+j*nx+k*nx*ny; fgets(linea,sizeof linea,fm);n++; //fprintf(stdout,"DATA LINEA %d: %s",n,linea); sscanf(linea,"%f %f %f %f", &x,&y,&z,&fieldmap[p]); //fprintf(stdout,"%d %d %d : %d = %g\n",i,j,k,p,fieldmap[p]); C[1][j]=y; } C[0][i]=x; //Blank line fgets(linea,sizeof linea,fm);n++; //fprintf(stdout,"LINEA %d: %s",n,linea); } C[2][k]=z; //Blank line fgets(linea,sizeof linea,fm);n++; //fprintf(stdout,"LINEA %d: %s",n,linea); } fclose(fm); /* fprintf(stdout,"X:"); arrayPrintf(stdout,"%.2e ",C[0],nx); fprintf(stdout,"\n"); fprintf(stdout,"Y:"); arrayPrintf(stdout,"%.2e ",C[1],ny); fprintf(stdout,"\n"); fprintf(stdout,"Z:"); arrayPrintf(stdout,"%.2e ",C[2],nz); fprintf(stdout,"\n"); */ //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //COLLAPSE DATA //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STPRINTF("Collapsing data...\n"); real XDIST[MAXGRID],YDIST[MAXGRID]; real distmap[MAXGRID][MAXGRID]; switch(cx){ case 0: ndx=nx;ix=0; switch(cy){ case 1: ndy=ny;iy=1; ndz=nz;iz=2; break; case 2: ndy=nz;iy=2; ndz=ny;iz=1; break; } break; case 1: ndx=ny;ix=1; switch(cy){ case 0: ndy=nx;iy=0; ndz=nz;iz=2; break; case 2: ndy=nz;iy=2; ndz=nx;iz=0; break; } break; case 2: ndx=nz;ix=2; switch(cy){ case 0: ndy=nx;iy=0; ndz=ny;iz=1; break; case 1: ndy=ny;iy=1; ndz=nx;iz=0; break; } break; } /* fprintf(stdout,"ix,iy,iz: %d,%d,%d\n",ix,iy,iz); fprintf(stdout,"nx,ny,nz: %d,%d,%d\n",ndx,ndy,ndz); */ /* i=1;j=3;k=2; p=positionDist(ix,iy,iz,i,j,k,nx,ny,nz); fprintf(stdout,"ENTRY (%d,%d,%d:%d): %e\n",i,j,k,p,fieldmap[p]); exit(0); //*/ switch(ctype){ case '1': for(i=0;i<ndx;i++){ XDIST[i]=C[ix][i]; //fprintf(stdout,"CONST %d: %g\n",i,XDIST[i]); distmap[i][0]=0; for(j=0;j<ndy;j++){ for(k=0;k<ndz;k++){ p=positionDist(ix,iy,iz,i,j,k,nx,ny,nz); /* fprintf(stdout,"\tSumming up %d:%d,%d:%d,%d:%d = %d: %g\n", ix,i,iy,j,iz,k,p,fieldmap[p]); */ distmap[i][0]+=fieldmap[p]; } } if(coper=='a') distmap[i][0]/=(ndy*ndz); } break; case '2': for(i=0;i<ndx;i++){ XDIST[i]=C[ix][i]; for(j=0;j<ndy;j++){ YDIST[j]=C[iy][j]; distmap[i][j]=0; for(k=0;k<ndz;k++){ p=positionDist(ix,iy,iz,i,j,k,nx,ny,nz); distmap[i][j]+=fieldmap[p]; } if(coper=='a') distmap[i][j]/=ndz; } } break; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //STORE DISTRIBUTION //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% STPRINTF("Storing distribution in file '%s'...\n",distfile); file fd=fileOpen(distfile,"w"); fprintf(fd,"#MapFile: %s\n",mapfile); fprintf(fd,"#TypeDist: %s\n",type); switch(ctype){ case '1': fprintf(fd,"#ColapseDirections: %d\n",cx); fprintf(fd,"%-14s %-14s\n","#1:X","2:DIST"); for(i=0;i<ndx;i++){ //fprintf(fd,"%+14.7e %+14.7e\n",XDIST[i],distmap[i][0]); fprintf(fd,"%+14.7e %g\n",XDIST[i],distmap[i][0]); } break; case '2': fprintf(fd,"#ColapseDirections: %d %d\n",cx,cy); fprintf(fd,"%-14s %-14s\t%-14s\n","#1:X","2:Y","3:DIST"); for(i=0;i<ndx;i++){ for(j=0;j<ndy;j++){ //fprintf(fd,"%+14.7e %+14.7e\t%+14.7e\n",XDIST[i],YDIST[j],distmap[i][j]); fprintf(fd,"%+14.7e %+14.7e\t%g\n",XDIST[i],YDIST[j],distmap[i][j]); } fprintf(fd,"\n"); } break; } return 0; }