Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

mcrawl.c File Reference

#include "mrilib.h"

Go to the source code of this file.


Functions

int main (int argc, char *argv[])

Function Documentation

int main int    argc,
char *    argv[]
 

\** File : SUMA.c

Author:
: Ziad Saad Date : Thu Dec 27 16:21:01 EST 2001
Purpose :

Input paramters :

Parameters:
param  Usage : SUMA ( )
Returns :
Returns:
Support :
See also:
OpenGL prog. Guide 3rd edition , varray.c from book's sample code
Side effects :

Definition at line 3 of file mcrawl.c.

References argc, DSET_ARRAY, DSET_BRICK_TYPE, DSET_load, DSET_LOADED, DSET_NVOX, DSET_unload, ISVALID_DSET, strtod(), and THD_open_dataset().

00004 {
00005    float mfrac=0.50 ;
00006    double dsum ;
00007    int nvox , iarg=1 , hist[32768] , ii,npos=0 , ncut,nmed,kk,ib , qq,nold ;
00008    THD_3dim_dataset * dset ;
00009    short * sar ;
00010 
00011    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00012       printf("Usage: mcrawl [-mfrac x] dataset\n"); exit(0);
00013    }
00014 
00015    if( strcmp(argv[iarg],"-mfrac") == 0 ){
00016       mfrac = strtod( argv[++iarg] , NULL ) ;
00017       if( mfrac <= 0.0 ){ fprintf(stderr,"ILLEGAL -mfrac\n");exit(1);}
00018       if( mfrac >= 1.0 ) mfrac *= 0.01 ;
00019       iarg++ ;
00020    }
00021 
00022    dset = THD_open_dataset(argv[iarg]) ;
00023    if( !ISVALID_DSET(dset) ){ fprintf(stderr,"CAN'T open dataset\n");exit(1);}
00024    if( DSET_BRICK_TYPE(dset,0) != MRI_short ){ fprintf(stderr,"ILLEGAL dataset type\n");exit(1); }
00025    DSET_load(dset) ;
00026    if( !DSET_LOADED(dset) ){ fprintf(stderr,"CAN'T load dataset\n");exit(1);}
00027    sar = DSET_ARRAY(dset,0) ;
00028 
00029    nvox = DSET_NVOX(dset) ;
00030    memset( hist , 0 , sizeof(int)*32768 ) ;
00031 
00032    dsum = 0.0 ;
00033    for( ii=0 ; ii < nvox ; ii++ ){
00034       if( sar[ii] > 0 ){
00035          hist[sar[ii]]++ ; dsum += (double)(sar[ii])*(double)(sar[ii]) ; npos++ ;
00036       }
00037    }
00038 
00039    DSET_unload(dset) ;
00040 
00041    printf("npos = %d\n",npos) ; if( npos <= 99 ) exit(1) ;
00042 
00043    qq = 0.65 * npos ; ib = rint(0.5*sqrt(dsum/npos)) ;
00044    for( kk=0,ii=32767 ; ii >= ib && kk < qq ; ii-- ) kk += hist[ii] ;
00045 
00046    ncut = ii ; qq = 0 ;
00047    do{
00048       for( npos=0,ii=ncut ; ii < 32768 ; ii++ ) npos += hist[ii] ;
00049       npos /= 2 ;  /* find median */
00050       for( kk=0,ii=ncut ; ii < 32768 && kk < npos ; ii++ ) kk += hist[ii] ;
00051       printf("ncut=%d ii=%d kk=%d\n",ncut,ii,kk) ;
00052       nold = ncut ;
00053       ncut = mfrac * ii ;
00054       qq++ ;
00055    } while( qq < 20 && ncut != nold ) ;
00056 
00057    exit(0) ;
00058 }
 

Powered by Plone

This site conforms to the following standards: