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  

ranks.c File Reference

Go to the source code of this file.


Data Structures

struct  node

Typedefs

typedef node node

Functions

void list_print (node *n, int *count)
void list_delete (node **n)
void node_insert (node **n, float r)
void node_addvalue (node **head, float r)
float node_get_rank (node *head, float r)
float node_get_value (node *head, int rank)
float node_get_median (node *head, int n)
float * rank_array (int n, float *xarray)
float * rank_darray (int n, double *darray)

Typedef Documentation

typedef struct node node
 


Function Documentation

void list_delete node **    n
 

Definition at line 56 of file ranks.c.

References free.

Referenced by calc_shift(), calc_stat(), rank_array(), and rank_darray().

00057 {
00058   if ((*n)->next != NULL)
00059     list_delete (&((*n)->next));
00060   free (*n);
00061   *n = NULL;
00062 }

void list_print node   n,
int *    count
 

Definition at line 34 of file ranks.c.

References node::d, node::fval, i, and node::next.

Referenced by calc_shift().

00035 {
00036   int i;
00037 
00038   for (i = 0;  i < n->d;  i++)
00039     {
00040       printf (" %6.1f", n->fval);
00041       *count += 1;
00042       if (*count % 10 == 0)
00043         printf ("\n");
00044     }
00045 
00046   if (n->next != NULL)
00047     list_print (n->next, count);
00048 }

void node_addvalue node **    head,
float    r
 

Definition at line 88 of file ranks.c.

References node::d, node::fval, node::next, node_insert(), and r.

Referenced by calc_shift(), calc_stat(), rank_array(), and rank_darray().

00089 {
00090   node ** lastptr;
00091   node * ptr;
00092 
00093 
00094   if (*head == NULL)  node_insert (head, r);
00095   else
00096     {
00097       lastptr = head;
00098       ptr = *head;
00099 
00100       while ( (ptr->fval < r) && (ptr->next != NULL) )
00101         {
00102           lastptr = &(ptr->next);
00103           ptr = ptr->next;
00104         }
00105       
00106       if (ptr->fval > r)
00107         node_insert (lastptr, r);
00108       else
00109         if (ptr->fval == r)
00110           ptr->d += 1;
00111         else
00112           node_insert (&(ptr->next), r);
00113     }
00114 }

float node_get_median node   head,
int    n
 

Definition at line 169 of file ranks.c.

References node_get_value().

Referenced by calc_shift().

00170 {
00171   float median;
00172 
00173 
00174   if (n % 2)
00175     median = node_get_value(head, n/2 + 1);
00176   else
00177     median = 0.5 * (node_get_value(head, n/2) + 
00178                     node_get_value(head, n/2 + 1));
00179 
00180   return (median);
00181 }

float node_get_rank node   head,
float    r
 

Definition at line 122 of file ranks.c.

References node::d, node::fval, node::next, and r.

Referenced by calc_stat(), rank_array(), and rank_darray().

00123 {
00124   node * ptr;
00125   float rank;
00126 
00127   ptr = head;
00128   rank = 0.0;
00129 
00130   while (ptr->fval != r)
00131     {
00132       rank += ptr->d;
00133       ptr = ptr->next;
00134     }
00135 
00136   rank += (ptr->d + 1) / 2.0;
00137   return (rank);
00138 }

float node_get_value node   head,
int    rank
 

Definition at line 146 of file ranks.c.

References node::d, node::fval, and node::next.

Referenced by node_get_median().

00147 {
00148   node * ptr;
00149   int k;
00150 
00151   ptr = head;
00152   k = 0;
00153 
00154   while (k + ptr->d < rank)
00155     {
00156       k += ptr->d;
00157       ptr = ptr->next;
00158     }
00159 
00160   return (ptr->fval);
00161 }

void node_insert node **    n,
float    r
 

Definition at line 70 of file ranks.c.

References malloc, and r.

Referenced by node_addvalue().

00071 {
00072   node * ptr;
00073 
00074   ptr = *n;
00075   *n = (node *) malloc (sizeof(node));
00076   (*n)->fval = r;
00077   (*n)->d = 1;
00078   (*n)->next = ptr;
00079 }

float* rank_array int    n,
float *    xarray
 

Definition at line 191 of file ranks.c.

References i, list_delete(), malloc, MTEST, node_addvalue(), and node_get_rank().

Referenced by calc_stat().

00196 {
00197   int i;                             /* array index */
00198   node * xhead = NULL;               /* pointer to list of sorted values */
00199   float * rarray = NULL;             /* array of ranks */
00200 
00201 
00202   /*----- Allocate memory for array of ranks -----*/
00203   rarray = (float *) malloc (sizeof(float) * n);    MTEST (rarray); 
00204 
00205 
00206   /*----- Enter and sort original data  -----*/
00207   for (i = 0;  i < n;  i++)
00208     node_addvalue (&xhead, xarray[i]); 
00209 
00210 
00211   /*----- Get ranks of data -----*/
00212   for (i = 0;  i < n;  i++)
00213     rarray[i] = node_get_rank (xhead, xarray[i]);
00214 
00215 
00216   /*----- Deallocate memory -----*/
00217   list_delete (&xhead);
00218 
00219 
00220   /*----- Return array of ranks -----*/
00221   return (rarray);
00222 }

float* rank_darray int    n,
double *    darray
 

Definition at line 232 of file ranks.c.

References i, list_delete(), malloc, MTEST, node_addvalue(), and node_get_rank().

Referenced by init_delay(), init_regression_analysis(), and regression_analysis().

00237 {
00238   int i;                             /* array index */
00239   node * xhead = NULL;               /* pointer to list of sorted values */
00240   float * rarray = NULL;             /* array of ranks */
00241 
00242 
00243   /*----- Allocate memory for array of ranks -----*/
00244   rarray = (float *) malloc (sizeof(float) * n);    MTEST (rarray); 
00245 
00246 
00247   /*----- Enter and sort original data  -----*/
00248   for (i = 0;  i < n;  i++)
00249     node_addvalue (&xhead, (float) darray[i]); 
00250 
00251 
00252   /*----- Get ranks of data -----*/
00253   for (i = 0;  i < n;  i++)
00254     rarray[i] = node_get_rank (xhead, (float) darray[i]);
00255 
00256 
00257   /*----- Deallocate memory -----*/
00258   list_delete (&xhead);
00259 
00260 
00261   /*----- Return array of ranks -----*/
00262   return (rarray);
00263 }
 

Powered by Plone

This site conforms to the following standards: