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  

plug_extract.c File Reference

#include "afni.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

Go to the source code of this file.


Data Structures

struct  extract_data
struct  fXYZ

Defines

#define NUM_YN_STRINGS   (sizeof(yn_strings)/sizeof(char *))
#define NUM_FORMAT_STRINGS   (sizeof(yn_strings)/sizeof(char *))
#define YUP   1
#define NOPE   0
#define ERROR_NOSUCHVOXEL   1
#define ERROR_FILEREAD   2
#define ERROR_FILEWRITE   2
#define ERROR_OPTIONS   17
#define ERROR_OUTCONFLICT   19

Functions

char * EXTRACT_main (PLUGIN_interface *)
void EXTRACT_tsfunc (double T0, double TR, int npts, float ts[], double ts_mean, double ts_slope, void *udp, float *dumb)
void show_ud (extract_data *ud)
void write_ud (extract_data *ud)
void indexTOxyz (extract_data *ud, int ncall, int *xpos, int *ypos, int *zpos)
void error_report (extract_data *ud, int ncall)
void writets (extract_data *ud, float *ts, int ncall)
float * extract_index (char *fname, int ind_col_loc, int ncols, int *nrows, int *Err)
fXYZextract_xyz (char *fname, int x_col_loc, int y_col_loc, int z_col_loc, int ncols, int *nrows, int *Err)
void disp_vect (float *v, int l)
int filexists (char *f_name)
int f_file_size (char *f_name)
DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface * PLUGIN_init (int ncall)

Variables

char helpstring []
char * yn_strings [] = { "n" , "y" }
char * format_strings [] = { "i x y z ts[1] ..." , "ts[1] ts[2] ..." }
PLUGIN_interface * global_plint = NULL

Define Documentation

#define ERROR_FILEREAD   2
 

Definition at line 138 of file plug_extract.c.

#define ERROR_FILEWRITE   2
 

Definition at line 139 of file plug_extract.c.

Referenced by EXTRACT_main().

#define ERROR_NOSUCHVOXEL   1
 

Definition at line 137 of file plug_extract.c.

#define ERROR_OPTIONS   17
 

Definition at line 140 of file plug_extract.c.

#define ERROR_OUTCONFLICT   19
 

Definition at line 141 of file plug_extract.c.

#define NOPE   0
 

Definition at line 135 of file plug_extract.c.

#define NUM_FORMAT_STRINGS   (sizeof(yn_strings)/sizeof(char *))
 

Definition at line 131 of file plug_extract.c.

Referenced by EXTRACT_main().

#define NUM_YN_STRINGS   (sizeof(yn_strings)/sizeof(char *))
 

Definition at line 130 of file plug_extract.c.

Referenced by EXTRACT_main().

#define YUP   1
 

Definition at line 134 of file plug_extract.c.


Function Documentation

void disp_vect float *    v,
int    l
[static]
 

Definition at line 1090 of file plug_extract.c.

References i, l, and v.

Referenced by show_ud().

01091         {
01092                 int i;
01093 
01094                 printf ("\n");
01095                 if ((l-1) == 0)
01096                         {
01097                                 printf ("V = %f\n",*v);
01098                         }
01099                 else 
01100                 {
01101                         for (i=0;i<l;++i)
01102                         {
01103                                 printf ("V[%d] = %f\t",i,v[i]);
01104                         }
01105                         printf ("\n");
01106                 }
01107                 return;
01108 
01109         }

void error_report extract_data   ud,
int    ncall
[static]
 

Definition at line 796 of file plug_extract.c.

References extract_data::errcode, indexTOxyz(), and extract_data::outlogfile.

Referenced by calculate_results(), and DELAY_tsfuncV2().

00797         {
00798                 int xpos,ypos,zpos;
00799                 
00800                 indexTOxyz (ud, ncall, &xpos , &ypos , &zpos); 
00801                 
00802                 switch (ud->errcode)
00803                         {
00804                                 
00805                                 default:
00806                                         fprintf (ud->outlogfile,"De Fault, De Fault (%d), the two sweetest words in the english langage ! ",ud->errcode);
00807                                         break;
00808                         }       
00809                 fprintf (ud->outlogfile,"%d\t%d\t%d\t%d\t\n", ncall , xpos , ypos , zpos  );
00810                 return;
00811         }

float * extract_index char *    fname,
int    ind_col_loc,
int    ncols,
int *    nrows,
int *    Err
[static]
 

Definition at line 953 of file plug_extract.c.

References calloc, f_file_size(), and i.

Referenced by EXTRACT_main().

00954 {/*extract_index*/
00955         
00956         float tmp, *indxvect=NULL;
00957         int sz,i;
00958         div_t divstuff,temp;
00959         FILE * INFILE;
00960         
00961         /* ncols must be > 0 */
00962         if (ncols <= 0)
00963                 
00964                 {
00965                         *Err = 4;
00966                         return (indxvect); /* ncols <= 0 !*/
00967                 }
00968                 
00969         
00970         /* ind_col_loc must be > 0  (1st column is 1, and it must be less than ncols) */
00971         if (ind_col_loc <= 0 || ind_col_loc > ncols)
00972                 {
00973                         *Err = 1;
00974                         return (indxvect); /* ind_col_loc should be >0 and <ncols*/
00975                 }
00976         
00977         /* if the number of rows is given, compute required size */
00978         if (*nrows > 0)
00979                 {
00980                         sz = *nrows * ncols;
00981                 }
00982         else
00983                 { /* dtermine the size and compute the number of rows, check if it's an integer*/
00984                         sz = f_file_size (fname);
00985                         if (sz == -1)
00986             {
00987                *Err = 3;
00988               return (indxvect);      
00989             }
00990                         divstuff = div (sz,ncols);
00991                         if (divstuff.rem != 0)
00992                                 {
00993                                         *Err = 2;
00994                                         return (indxvect); /* size of file and number of columns don't match */
00995                                 }
00996                         else 
00997                                 {
00998                                         *nrows = divstuff.quot;
00999                                 }
01000                 }
01001         
01002         /* Allocate and check for necessary space */
01003         indxvect = (float *) calloc (sz+2,sizeof(float));
01004         
01005          if (indxvect == NULL)
01006                                 {
01007                                         printf ("\nFatal Error : Failed to Allocate memory\a\n");
01008                                         printf ("Abandon Lab Immediately !\n\n");
01009                                         return NULL ;
01010                                 };
01011         
01012         INFILE = fopen (fname,"r");
01013         if (INFILE == NULL)
01014                 {
01015                         *Err = 3; /* can't find file */
01016                         return (indxvect);
01017                 }
01018 
01019         temp = div (ind_col_loc,ncols);
01020         
01021         for (i=0;i<sz;++i)
01022                 {
01023                         fscanf (INFILE,"%f",&tmp);
01024                         divstuff = div ((i+1),ncols);
01025                         if (divstuff.rem == temp.rem)
01026                                 {
01027                                         if (divstuff.rem != 0) indxvect[divstuff.quot] = tmp;
01028                                                 else indxvect[divstuff.quot-1] = tmp;
01029                                 }
01030                 }
01031 
01032         
01033         *Err = 0;
01034         return (indxvect);
01035         
01036 }/*extract_index*/

char * EXTRACT_main PLUGIN_interface *    [static]
 

Definition at line 351 of file plug_extract.c.

References calloc, THD_3dim_dataset::daxes, DSET_FILECODE, DSET_PREFIX, extract_data::dsetname, extract_data::dtrnd, extract_data::errcode, ERROR_FILEWRITE, extract_index(), EXTRACT_tsfunc(), extract_xyz(), extract_data::fail, filexists(), extract_data::format, format_strings, free, extract_data::ignore, extract_data::iloc, extract_data::indvect, itmp, extract_data::ncols, extract_data::new_prefix, extract_data::nrows, NUM_FORMAT_STRINGS, NUM_YN_STRINGS, THD_dataxes::nxx, extract_data::nxx, THD_dataxes::nyy, extract_data::nyy, THD_dataxes::nzz, extract_data::nzz, extract_data::outlogfile, extract_data::outwritets, extract_data::pass, PLUTO_4D_to_typed_fim(), PLUTO_add_dset(), PLUTO_find_dset(), PLUTO_prefix_ok(), PLUTO_string_index(), extract_data::strin, extract_data::strout, vec, write_ud(), extract_data::xloc, extract_data::xyzvect, extract_data::yloc, yn_strings, and extract_data::zloc.

Referenced by PLUGIN_init().

00352 {
00353    extract_data uda,*ud;
00354    MRI_IMAGE * tsim;
00355    MCW_idcode * idc ;                          /* input dataset idcode */
00356    THD_3dim_dataset * old_dset , * new_dset ;  /* input and output datasets */
00357    char *tmpstr , * str , *nprfxstr;                 
00358    int   ntime, nvec ,nprfx, Err , itmp;
00359         float * vec , fs , T ;
00360         char * tag;                     /* plugin option tag */ 
00361         
00362         /* Allocate as much character space as Bob specifies in afni.h + a bit more */
00363         
00364         tmpstr = (char *) calloc (PLUGIN_MAX_STRING_RANGE+10,sizeof(char));
00365         nprfxstr = (char *) calloc (PLUGIN_MAX_STRING_RANGE+10,sizeof(char));
00366         
00367         if (tmpstr == NULL || nprfxstr == NULL) 
00368                                                                           return "********************\n"
00369                                                                                                 "Could not Allocate\n"
00370                                                                                                 "a teeni weeni bit of\n"
00371                                                                                                 "Memory ! Go complain\n"
00372                                                                                                 "to yer Mamma ! \n"
00373                                                                                                 "********************\n";
00374                                                                                                 
00375         ud = &uda;              /* ud now points to an allocated space */
00376         ud->errcode = 0;        /*reset error flag */
00377         
00378    /*--------------------------------------------------------------------*/
00379    /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/
00380 
00381    /*--------- go to first input line ---------*/
00382                 
00383    tag = PLUTO_get_optiontag(plint) ;
00384    
00385    if (tag == NULL)
00386         {
00387                 return "************************\n"
00388              "Bad 1st line option \n"
00389              "************************"  ;
00390         }       
00391 
00392    idc      = PLUTO_get_idcode(plint) ;   /* get dataset item */
00393    old_dset = PLUTO_find_dset(idc) ;      /* get ptr to dataset */
00394    if( old_dset == NULL )
00395       return "*************************\n"
00396              "Cannot find Input Dataset\n"
00397              "*************************"  ;
00398    
00399    ud->dsetname = DSET_FILECODE (old_dset);
00400         
00401         ud->ignore = PLUTO_get_number(plint) ;    /* get number item */
00402         
00403         str = PLUTO_get_string(plint) ;                                 
00404         ud->dtrnd = (int)PLUTO_string_index( str , NUM_YN_STRINGS , yn_strings );
00405         
00406         
00407         
00408         /*--------- loop over ramining options ---------*/
00409         
00410                 
00411         ud->iloc = -1;
00412         ud->xloc = -1;
00413         ud->yloc = -1;
00414         ud->zloc = -1;
00415         do
00416                 {
00417                         tag = PLUTO_get_optiontag(plint) ;
00418                         if (tag == NULL) break;
00419                         if (strcmp (tag, "Mask") == 0)
00420                                 {
00421                                         ud->strin = PLUTO_get_string(plint) ; 
00422                                         ud->ncols = PLUTO_get_number(plint) ;
00423                                         ud->pass = PLUTO_get_number(plint) ;
00424                                         ud->fail = 0;  /* Set voxels that don't make it to 0 */
00425                                         continue;
00426                                 }
00427                         
00428                         if (strcmp (tag, "Index") == 0)
00429                                 {
00430                                         ud->iloc = PLUTO_get_number(plint) ;    /* get number item */
00431                                         continue;
00432                                 }
00433                 
00434                         if (strcmp (tag, "XYZ") == 0)
00435                                 {
00436                                                 ud->xloc = PLUTO_get_number(plint) ;    /* get number item */
00437                                                 ud->yloc = PLUTO_get_number(plint) ;    /* get number item */
00438                                                 ud->zloc = PLUTO_get_number(plint) ;    /* get number item */
00439                                                 continue;
00440                                 }
00441 
00442                         if (strcmp (tag, "Output") == 0)
00443                                         {
00444                                                 ud->new_prefix = PLUTO_get_string(plint) ;   /* get string item (the output prefix) */
00445                                                         /* check to see if the field is empty */
00446                                                         if (ud->new_prefix == NULL)
00447                                                                         nprfx = 0;
00448                                                                 else
00449                                                                         nprfx = 1;
00450                                                         /* check if the size is larger than 0. I did not want to check for this unless it's allocated */
00451                                                         if (nprfx == 1 && (int)strlen (ud->new_prefix) == 0)
00452                                                                 nprfx = 0;
00453 
00454                                                         if (nprfx == 0)         /* now create the new name and make new_prefix point to it */
00455                                                                 {
00456                                                                         sprintf (nprfxstr,"%s.XTRCT",DSET_PREFIX (old_dset));
00457                                                                         ud->new_prefix = nprfxstr;
00458                                                                         /*printf ("New prefix is set to be : %s\n\a",ud->new_prefix);*/
00459                                                                 }
00460 
00461                                         
00462                                                 if( ! PLUTO_prefix_ok(ud->new_prefix) )      /* check if it is OK */
00463                                         return "************************\n"
00464                                                  "Output Prefix is illegal\n"
00465                                                  "************************"  ;
00466 
00467                                         ud->strout = PLUTO_get_string(plint) ; 
00468 
00469                                         str = PLUTO_get_string(plint) ;                                 
00470                                                 ud->format = (int)PLUTO_string_index( str , NUM_FORMAT_STRINGS , format_strings );
00471                                                 continue;
00472                                         }
00473                         
00474                 } while (1);
00475         /* ------------------ Check for some errorsor inconsistencies ------------- */
00476                 
00477         if (ud->iloc == -1 && ud->xloc == -1)
00478                 {
00479                         return "**************************\n"
00480                                          "At least iloc or x/y/zloc\n"
00481                                          "must be specified\n"
00482                                          "**************************\n"
00483                                          ;
00484                 }
00485         
00486         if (ud->iloc != -1 && ud->xloc != -1)
00487                 {
00488                         return "***************************\n"
00489                                          "iloc AND x/y/zloc can not\n"
00490                                          "be simultaneously specified\n"
00491                                          "***************************\n"
00492                                          ;
00493                 }
00494         
00495         
00496         /* ------------------Done with user parameters ---------------------------- */
00497         
00498         /* Now loadup that index list or the xyz list */
00499         if (ud->iloc != -1)
00500                 {       
00501                         itmp = 0;  /* might want to give option of setting it to number of rows if*/ 
00502                     /* the users know it, otherwise, it is automatically determined*/    
00503                         ud->indvect = extract_index (ud->strin, ud->iloc, ud->ncols, &itmp, &Err);
00504                 }
00505         else            /* assuming the only other case is that x y z are specified */
00506                 {
00507                         itmp = 0; 
00508                         ud->xyzvect = extract_xyz (ud->strin , ud->xloc , ud->yloc , ud->zloc , ud->ncols, &itmp, &Err);
00509                 }
00510         
00511                 
00512         ud->nrows = itmp;
00513         
00514         switch (Err)
00515         {
00516                 case (0):
00517                         break;
00518                 case (1):
00519                         return "****************************************\n"
00520                                "index location should be > 0 and < ncols\n"
00521                                "****************************************\n";
00522                 case (2):
00523                         return "********************************************\n"
00524                 "file size and number of columns do not match\n"
00525                                "********************************************\n";
00526                 case (3):
00527                         return "**********************\n"
00528                 "Can't find matrix file\n"
00529                                "**********************\n";
00530                 case (4):
00531                         return "*****************\n"
00532                 "ncols must be > 0\n"
00533                                "*****************\n";
00534                 case (5):
00535                         return "****************************************\n"
00536                 "x/y/z column numbers can NOT be the same\n"
00537                                "****************************************\n";
00538                 default:
00539                         return "****************************************\n"
00540                 "Should not have gotten here .....\n"
00541                                "****************************************\n";
00542                 
00543         }
00544         
00545         
00546         if (strcmp (ud->strout,"") == 0)   /* no output file is specified */ 
00547                 {
00548                         sprintf ( tmpstr , "%s" , ud->new_prefix);
00549                         ud->strout = tmpstr;
00550                 }
00551         
00552         if (filexists(ud->strout) == 1)
00553                 {
00554                         return "*******************************\n"
00555                                          "Outfile exists, won't overwrite\n"
00556                                          "*******************************\n";   
00557                 }
00558         ud->outwritets = fopen (ud->strout ,"w");       
00559         
00560         sprintf ( tmpstr , "%s.log" , ud->strout);
00561         if (filexists(tmpstr) == 1)
00562                 {
00563                         return "*******************************\n"
00564                                          "Outfile.log exists, won't overwrite\n"
00565                                          "*******************************\n";   
00566                 }
00567         
00568         ud->outlogfile = fopen (tmpstr ,"w"); 
00569                 
00570         if ((ud->outwritets == NULL) || (ud->outlogfile == NULL) )
00571                                                 {
00572                                                         ud->errcode = ERROR_FILEWRITE; 
00573                                                         
00574                                                         return "***********************\n"
00575                                                                          "Could Not Write Outfile\n"
00576                                                                          "***********************\n";
00577                                                 }                               
00578         
00579         
00580         ud->nxx = (int)old_dset->daxes->nxx;                            /* get data set dimensions */
00581         ud->nyy = (int)old_dset->daxes->nyy;
00582         ud->nzz = (int)old_dset->daxes->nzz;
00583         
00584    /* ready to dump the log file */
00585    write_ud (ud);
00586    
00587    /*------------- ready to compute new dataset -----------*/
00588   
00589    new_dset = PLUTO_4D_to_typed_fim( old_dset ,             /* input dataset */
00590                                ud->new_prefix ,           /* output prefix */
00591                                -1,                                                      /* negative value indicating data type is like original brick */
00592                                ud->ignore ,               /* ignore count */
00593                                ud->dtrnd ,                    /* detrend */
00594                                EXTRACT_tsfunc ,         /* timeseries processor */
00595                                (void *)ud          /* data for tsfunc */
00596                              ) ;
00597    
00598    PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ;
00599 
00600         fclose (ud->outlogfile);
00601         fclose (ud->outwritets);
00602         
00603         free (tmpstr);          
00604         free (nprfxstr);
00605         
00606    return NULL ;  /* null string returned means all was OK */
00607 }

void EXTRACT_tsfunc double    T0,
double    TR,
int    npts,
float    ts[],
double    ts_mean,
double    ts_slope,
void *    udp,
float *    dumb
[static]
 

Definition at line 613 of file plug_extract.c.

References extract_data::errcode, extract_data::fail, global_plint, i, extract_data::iloc, indexTOxyz(), extract_data::indvect, extract_data::ln, extract_data::nrows, extract_data::pass, PLUTO_popup_meter(), PLUTO_set_meter(), TR, writets(), and extract_data::xyzvect.

Referenced by EXTRACT_main().

00616 {
00617    static int nvox , ncall ;
00618         extract_data uda,*ud;
00619         float xcor=0.0 ,  tmp=0.0 , tmp2 = 0.0 ,  dtx = 0.0 ,\
00620                          slp = 0.0 , vts = 0.0 , vrvec = 0.0 , rxcorCoef = 0.0;
00621         int i , is_ts_null , status , opt , actv , zpos , ypos , xpos , hit;
00622         
00623         ud = &uda;
00624         ud = (extract_data *) udp;
00625         
00626         
00627    /** is this a "notification"? **/
00628 
00629         
00630    if( dumb == NULL ){
00631                 
00632       if( npts > 0 ){  /* the "start notification" */
00633 
00634          PLUTO_popup_meter( global_plint ) ;  /* progress meter  */
00635          nvox  = npts ;                       /* keep track of   */
00636          ncall = 0 ;                          /* number of calls */
00637                         
00638       } else {  /* the "end notification" */
00639                         
00640          PLUTO_set_meter( global_plint , 100 ) ; /* set meter to 100% */
00641 
00642       }
00643       return ;
00644    }
00645 
00646         
00647         hit = 0;
00648         ud->ln = npts;
00649         
00650         
00651         if (ud->iloc != -1)                     /* for each ncall, find out if this index is wanted*/
00652                 {
00653                         *dumb = ud->fail;
00654                         for (i=0;i<ud->nrows;++i)
00655                                 {
00656                                         if (ud->indvect[i] == (float)ncall) 
00657                                                 {
00658                                                         hit = 1;
00659                                                    *dumb = ud->pass;
00660                                                         writets (ud,ts,ncall); 
00661                                                         i = ud->nrows;
00662                                                 }
00663                                 }
00664                 }
00665         else
00666                 {
00667                         *dumb = ud->fail;
00668                         indexTOxyz (ud, ncall, &xpos , &ypos , &zpos);
00669                         for (i=0;i<ud->nrows;++i)
00670                                 {
00671                                         if (ud->xyzvect[i].x == (float)xpos)
00672                                                 {
00673                                                         if (ud->xyzvect[i].y == (float)ypos)
00674                                                                 {
00675                                                                         if (ud->xyzvect[i].z == (float)zpos)
00676                                                                                 {
00677                                                                                         hit = 1;
00678                                                                                         *dumb = ud->pass;
00679                                                                                         writets (ud,ts,ncall); 
00680                                                                                         i = ud->nrows;
00681                                                                                 }
00682                                                                 }
00683                                                 }               
00684                                 }
00685                         
00686                 }
00687         
00688         
00689         /* the output brick generated here is practically useless, it has 1 at the voxels 
00690         whos time courses were used and 0 where nothing was extracted */
00691 
00692         
00693    
00694    if (ud->errcode == 0)                                /* if there are no errors, proceed */   
00695                 {/*                                             */
00696         }/* ud->errcode == 0 outer loop */
00697    
00698    /** set the progress meter to the % of completion **/
00699    ncall++ ;
00700    
00701    PLUTO_set_meter( global_plint , (100*ncall)/nvox ) ;
00702    
00703    ud->errcode = 0;     /* Rest error to nothing */
00704    
00705    return ;
00706 }

fXYZ * extract_xyz char *    fname,
int    x_col_loc,
int    y_col_loc,
int    z_col_loc,
int    ncols,
int *    nrows,
int *    Err
[static]
 

Definition at line 844 of file plug_extract.c.

References calloc, f_file_size(), i, fXYZ::x, fXYZ::y, and fXYZ::z.

Referenced by EXTRACT_main().

00845 {/*extract_xyz*/
00846         
00847         float tmp, *tmpX;
00848         int sz,i,indx,tst;
00849         div_t divstuff,tempx,tempy,tempz;
00850         FILE * INFILE;
00851         fXYZ * xyzvect=NULL;
00852         
00853         /* ncols must be > 0 */
00854         if (ncols <= 0)
00855                 
00856                 {
00857                         *Err = 4;
00858                         return (xyzvect); /* ncols <= 0 !*/
00859                 }
00860                 
00861                 
00862         /* ind_col_loc must be > 0  (1st column is 1, and it must be less than ncols) */
00863         if (x_col_loc <= 0 || x_col_loc > ncols || y_col_loc <= 0 || y_col_loc > ncols || z_col_loc <= 0 || z_col_loc > ncols )
00864                 {
00865                         *Err = 1;
00866                         return (xyzvect); /* ?_col_loc should be >0 and <ncols*/
00867                 }
00868         
00869         /* if the number of rows is given, compute required size */
00870         if (*nrows > 0)
00871                 {
00872                         sz = *nrows * ncols;
00873                 }
00874         else
00875                 { /* dtermine the size and compute the number of rows, check if it's an integer*/
00876                         sz = f_file_size (fname);
00877                         if (sz == -1)
00878            {
00879                    *Err = 3;
00880                    return (xyzvect);
00881             }
00882                         divstuff = div (sz,ncols);
00883                         if (divstuff.rem != 0)
00884                                 {
00885                                         *Err = 2;
00886                                         return (xyzvect); /* size of file and number of columns don't match */
00887                                 }
00888                         else 
00889                                 {
00890                                         *nrows = divstuff.quot;
00891                                 }
00892                 }
00893         
00894         tst = (x_col_loc - y_col_loc) * (x_col_loc - z_col_loc) * (y_col_loc - z_col_loc);
00895         if (tst == 0)
00896                 {
00897                         *Err = 5;
00898                         return (xyzvect); /* columns specified are the same */
00899                 } 
00900         
00901         /* Allocate and check for necessary space */
00902         xyzvect = (fXYZ *) calloc (sz+2,sizeof(fXYZ));
00903         
00904          if (xyzvect == NULL)
00905                                 {
00906                                         printf ("\nFatal Error : Failed to Allocate memory\a\n");
00907                                         printf ("Abandon Lab Immediately !\n\n");
00908                                         return NULL;
00909                                 };
00910         
00911         INFILE = fopen (fname,"r");
00912         if (INFILE == NULL)
00913                 {
00914                         *Err = 3; /* can't find file */
00915                         return (xyzvect);
00916                 }
00917 
00918         tempx = div (x_col_loc,ncols);
00919         tempy = div (y_col_loc,ncols);
00920         tempz = div (z_col_loc,ncols);
00921         
00922         for (i=0;i<sz;++i)
00923                 {
00924                         fscanf (INFILE,"%f",&tmp);
00925                         divstuff = div ((i+1),ncols);
00926                         if (divstuff.rem != 0)
00927                                 indx = divstuff.quot;
00928                         else 
00929                                 indx = divstuff.quot - 1;
00930                         
00931                         if (divstuff.rem == tempx.rem)
00932                                         xyzvect[indx].x = tmp;
00933                                 
00934                                 else if (divstuff.rem == tempy.rem)
00935                                                 xyzvect[indx].y = tmp;
00936                                         
00937                                         else if (divstuff.rem == tempz.rem)
00938                                                         xyzvect[indx].z = tmp;
00939                 }
00940 
00941         
00942         *Err = 0;
00943         return (xyzvect);
00944         
00945 }/*extract_xyz*/

int f_file_size char *    f_name [static]
 

Definition at line 1042 of file plug_extract.c.

Referenced by extract_index(), and extract_xyz().

01044     { 
01045       
01046 
01047      int cnt=0,ex;
01048      float buf;
01049      
01050      FILE*internal_file;
01051      
01052      internal_file = fopen (f_name,"r");
01053      if (internal_file == NULL) {
01054                                                                 return (-1);
01055                                                         }
01056      ex = fscanf (internal_file,"%f",&buf);                                             
01057      while (ex != EOF)
01058       {
01059         ++cnt;
01060         ex = fscanf (internal_file,"%f",&buf);
01061       }
01062       
01063       
01064       fclose (internal_file);
01065       return (cnt);                                                          
01066    }

int filexists char *    f_name [static]
 

Definition at line 1072 of file plug_extract.c.

Referenced by DUMP_main(), and EXTRACT_main().

01073 {/*filexists*/
01074         FILE *outfile;
01075         
01076         outfile = fopen (f_name,"r");
01077         if (outfile == NULL)
01078                 return (0);
01079         else 
01080                 fclose (outfile);
01081                 return (1);
01082                 
01083 }/*filexists*/

void indexTOxyz extract_data   ud,
int    ncall,
int *    xpos,
int *    ypos,
int *    zpos
[static]
 

Definition at line 781 of file plug_extract.c.

References extract_data::nxx, and extract_data::nyy.

Referenced by calculate_results(), DELAY_tsfuncV2(), error_report(), EXTRACT_tsfunc(), and writets().

00782         {
00783                 *zpos = (int)ncall / (int)(ud->nxx*ud->nyy);
00784                 *ypos = (int)(ncall - *zpos * ud->nxx * ud->nyy) / (int)ud->nxx;
00785                 *xpos = ncall - ( *ypos * ud->nxx ) - ( *zpos * ud->nxx * ud->nyy ) ;
00786                 return;
00787         }

DEFINE_PLUGIN_PROTOTYPE PLUGIN_interface* PLUGIN_init int    ncall
 

Definition at line 191 of file plug_extract.c.

References ANAT_ALL_MASK, EXTRACT_main(), format_strings, FUNC_ALL_MASK, global_plint, helpstring, and yn_strings.

00192 {
00193    PLUGIN_interface * plint ;     /* will be the output of this routine */
00194 
00195    if( ncall > 0 ) return NULL ;  /* only one interface */
00196 
00197    /*---------------- set titles and call point ----------------*/
00198 
00199    plint = PLUTO_new_interface( "3D+t Extract" ,
00200                                 "Extract voxel time courses given their index or XYZ coordinates" ,
00201                                 helpstring ,
00202                                 PLUGIN_CALL_VIA_MENU , EXTRACT_main  ) ;
00203 
00204    global_plint = plint ;  /* make global copy */
00205 
00206    /*--------- 1st line: Input dataset and mask files ---------*/
00207 
00208    PLUTO_add_option( plint ,
00209                      "Data" ,  /* label at left of input line */
00210                      "Data" ,  /* tag to return to plugin */
00211                      TRUE       /* is this mandatory? */
00212                    ) ;
00213 
00214    PLUTO_add_dataset(  plint ,
00215                        "3D+time" ,        /* label next to button   */
00216                        ANAT_ALL_MASK ,    /* take only EPI datasets */
00217                        FUNC_ALL_MASK ,    /*  No fim funcs   */
00218                        DIMEN_4D_MASK |    /* need 3D+time datasets  */
00219                        BRICK_ALLREAL_MASK /* need real-valued datasets */
00220                     ) ;
00221   
00222    PLUTO_add_number( plint ,
00223                     "Ignore" ,  /* label next to chooser */
00224                     0 ,         /* smallest possible value */
00225                     50 ,        /* largest possible value (inactivated for now)*/
00226                     0 ,         /* decimal shift (none in this case) */
00227                     0 ,         /* default value */
00228                     FALSE       /* allow user to edit value? */
00229                   ) ;
00230         PLUTO_add_string( plint ,
00231                      "Dtrnd" ,  /* label next to textfield */
00232                      2,yn_strings,    /* strings to choose among */
00233                      1         /* Default option */
00234                    ) ;
00235         
00236         /*---------- 2nd line: Mask file info  ----------*/
00237    PLUTO_add_option( plint ,
00238                      "Mask file" ,  /* label at left of input line */
00239                      "Mask" ,  /* tag to return to plugin */
00240                      TRUE       /* is this mandatory? */
00241                    ) ;
00242    
00243    PLUTO_add_string( plint , "Mask File" , 0 , NULL , 19 ) ;
00244    
00245    PLUTO_add_number( plint ,
00246                     "N Columns" ,  /* label next to chooser */
00247                     1 ,         /* smallest possible value */
00248                     1000 ,        /* largest possible value (inactivated for now)*/
00249                     0 ,         /* decimal shift (none in this case) */
00250                     3 ,         /* default value */
00251                     TRUE       /* allow user to edit value? */
00252                   ) ;
00253                                                 
00254         PLUTO_add_number( plint ,
00255                     "Pass Value" ,  /* label next to chooser */
00256                     -10000 ,         /* smallest possible value */
00257                     10000 ,        /* largest possible value (inactivated for now)*/
00258                     0 ,         /* decimal shift (none in this case) */
00259                     1 ,         /* default value */
00260                     TRUE       /* allow user to edit value? */
00261                   ) ;
00262         
00263    
00264 
00265    /*---------- 3rd line: index mask location ----------*/
00266    
00267    PLUTO_add_option( plint ,
00268                      "Index Mask ?" ,  /* label at left of input line */
00269                      "Index" ,  /* tag to return to plugin */
00270                      FALSE       /* is this mandatory? */
00271                    ) ;
00272    
00273    PLUTO_add_number( plint ,
00274                     "i col." ,  /* label next to chooser */
00275                     1 ,         /* smallest possible value */
00276                     1000 ,        /* largest possible value (inactivated for now)*/
00277                     0 ,         /* decimal shift (none in this case) */
00278                     1 ,         /* default value */
00279                     TRUE       /* allow user to edit value? */
00280                   ) ;
00281         
00282                    
00283    /*---------- 4th line: xyz mask location ----------*/
00284 
00285    PLUTO_add_option( plint ,
00286                      "XYZ Mask ?" ,  /* label at left of input line */
00287                      "XYZ" ,  /* tag to return to plugin */
00288                      FALSE       /* is this mandatory? */
00289                    ) ;
00290 
00291    PLUTO_add_number( plint ,
00292                     "x col." ,  /* label next to chooser */
00293                     1 ,         /* smallest possible value */
00294                     1000 ,        /* largest possible value */
00295                     0 ,         /* decimal shift (none in this case) */
00296                     2 ,         /* default value */
00297                     TRUE       /* allow user to edit value? */
00298                   ) ;
00299         
00300         PLUTO_add_number( plint ,
00301                     "y col." ,  /* label next to chooser */
00302                     1 ,         /* smallest possible value */
00303                     1000 ,        /* largest possible value */
00304                     0 ,         /* decimal shift (none in this case) */
00305                     3 ,         /* default value */
00306                     TRUE       /* allow user to edit value? */
00307                   ) ;
00308                   
00309 
00310         PLUTO_add_number( plint ,
00311                     "z col." ,  /* label next to chooser */
00312                     1 ,         /* smallest possible value */
00313                     1000 ,      /* largest possible value */
00314                     0 ,         /* decimal shift (none in this case) */
00315                     4 ,         /* default value */
00316                     TRUE       /* allow user to edit value? */
00317                   ) ;
00318                   
00319    /*---------- 5th line: output stuff ----------*/
00320 
00321    PLUTO_add_option( plint ,
00322                      "Output" ,  /* label at left of input line */
00323                      "Output" ,  /* tag to return to plugin */
00324                      TRUE        /* is this mandatory? */
00325                    ) ;
00326 
00327    PLUTO_add_string( plint ,
00328                      "AFNI Prfx" ,  /* label next to textfield */
00329                      0,NULL ,    /* no fixed strings to choose among */
00330                      19          /* 19 spaces for typing in value */
00331                    ) ;
00332    
00333    
00334    PLUTO_add_string( plint , "Filename" , 0 , NULL , 19 ) ;
00335               
00336    PLUTO_add_string( plint ,
00337                      "Format" ,  /* label next to textfield */
00338                      2,format_strings,    /* strings to choose among */
00339                      0          /* Default option */
00340                    ) ;
00341    
00342    return plint ;
00343 }

void show_ud extract_data   ud [static]
 

set the progress meter to the % of completion *

Definition at line 712 of file plug_extract.c.

References extract_data::dsetname, extract_data::dtrnd, extract_data::format, extract_data::ignore, extract_data::iloc, extract_data::ln, extract_data::ncols, extract_data::new_prefix, extract_data::nrows, extract_data::nxx, extract_data::nyy, extract_data::nzz, extract_data::strin, extract_data::strout, extract_data::xloc, extract_data::yloc, and extract_data::zloc.

Referenced by check_for_valid_inputs().

00713         {
00714                 printf ("\n\nUser Data Values at location :\n");
00715                 printf ("ud->dsetname= %s\n",ud->dsetname);
00716                 printf ("ud->strin= %s\n",ud->strin);
00717                 printf ("ud->strout= %s\n",ud->strout);
00718                 printf ("ud->nxx= %d\n",ud->nxx);
00719                 printf ("ud->nyy= %d\n",ud->nyy);
00720                 printf ("ud->nzz= %d\n",ud->nzz);
00721                 printf ("ud->iloc= %d\n",ud->iloc);
00722                 printf ("ud->xloc= %d\n",ud->xloc);
00723                 printf ("ud->yloc= %d\n",ud->yloc);
00724                 printf ("ud->zloc= %d\n",ud->zloc);
00725                 printf ("ud->ncols= %d\n",ud->ncols);
00726                 printf ("ud->nrows= %d\n",ud->nrows);
00727                 printf ("ud->ignore= %d\n",ud->ignore);
00728                 printf ("ud->dtrnd= %d\n",ud->dtrnd);
00729                 printf ("ud->ln= %d\n",ud->ln);
00730                 printf ("ud->new_prefix= %s\n",ud->new_prefix);
00731                 printf ("ud->format= %d\n",ud->format);
00732                 printf ("Hit enter to continue\a\n\n");
00733                 getchar ();
00734                 return;
00735         }

void write_ud extract_data   ud [static]
 

Definition at line 741 of file plug_extract.c.

References extract_data::dsetname, extract_data::dtrnd, extract_data::fail, extract_data::format, extract_data::ignore, extract_data::iloc, extract_data::ncols, extract_data::new_prefix, extract_data::nrows, extract_data::nxx, extract_data::nyy, extract_data::nzz, extract_data::outlogfile, extract_data::pass, extract_data::strin, extract_data::strout, extract_data::xloc, extract_data::yloc, and extract_data::zloc.

Referenced by check_for_valid_inputs(), DELAY_main(), and EXTRACT_main().

00742         {
00743                 fprintf (ud->outlogfile,"\n\nUser Data Values \n");
00744                 fprintf (ud->outlogfile,"ud->dsetname= %s\n",ud->dsetname);
00745                 fprintf (ud->outlogfile,"ud->strin= %s\n",ud->strin);
00746                 fprintf (ud->outlogfile,"ud->strout= %s\n",ud->strout);
00747                 fprintf (ud->outlogfile,"ud->nxx= %d\n",ud->nxx);
00748                 fprintf (ud->outlogfile,"ud->nyy= %d\n",ud->nyy);
00749                 fprintf (ud->outlogfile,"ud->nzz= %d\n",ud->nzz);
00750                 fprintf (ud->outlogfile,"ud->iloc= %d\n",ud->iloc);
00751                 fprintf (ud->outlogfile,"ud->xloc= %d\n",ud->xloc);
00752                 fprintf (ud->outlogfile,"ud->yloc= %d\n",ud->yloc);
00753                 fprintf (ud->outlogfile,"ud->zloc= %d\n",ud->zloc);
00754                 fprintf (ud->outlogfile,"ud->ncols= %d\n",ud->ncols);
00755                 fprintf (ud->outlogfile,"ud->nrows= %d\n",ud->nrows);
00756                 fprintf (ud->outlogfile,"ud->ignore= %d\n",ud->ignore);
00757                 fprintf (ud->outlogfile,"ud->dtrnd= %d\n",ud->dtrnd);
00758                 fprintf (ud->outlogfile,"ud->pass= %f\n",ud->pass);
00759                 fprintf (ud->outlogfile,"ud->fail= %f\n",ud->fail);
00760                 fprintf (ud->outlogfile,"ud->new_prefix= %s\n",ud->new_prefix);
00761                 fprintf (ud->outlogfile,"ud->format= %d\n",ud->format);
00762                 fprintf (ud->outlogfile,"\nThe format for the output file is the following:\n");
00763                 switch (ud->format)
00764                         {
00765                                 case (0):
00766                                         fprintf (ud->outlogfile,"ncall\txpos\typos\tzpos\tts[0]\tts[1]\t...\n");
00767                                         break;
00768                                 case (1):
00769                                         fprintf (ud->outlogfile,"ts[0]\tts[1]\t...\n");
00770                                         break;
00771                                         
00772                         }
00773                 
00774                 return;
00775         }

void writets extract_data   ud,
float *    ts,
int    ncall
[static]
 

Definition at line 817 of file plug_extract.c.

References extract_data::format, i, indexTOxyz(), extract_data::ln, and extract_data::outwritets.

Referenced by calculate_results(), DELAY_tsfuncV2(), and EXTRACT_tsfunc().

00819         {       
00820                 int i,xpos,ypos,zpos;
00821                 
00822                 switch (ud->format)
00823                         {
00824                                 case (0):
00825                                         indexTOxyz (ud,ncall,&xpos , &ypos , &zpos); 
00826                                         fprintf (ud->outwritets, "%d\t%d\t%d\t%d\t",ncall,xpos, ypos,zpos);
00827                                         break;
00828                                 case (1):
00829                                         break;
00830                                 default:
00831                                         break;
00832                         }
00833                 
00834                 for (i=0;i<ud->ln;++i)
00835                         {
00836                                 fprintf (ud->outwritets, "%f\t",ts[i]);
00837                         }
00838                 fprintf (ud->outwritets,"\n");
00839         }

Variable Documentation

char* format_strings[] = { "i x y z ts[1] ..." , "ts[1] ts[2] ..." } [static]
 

Definition at line 128 of file plug_extract.c.

Referenced by EXTRACT_main(), and PLUGIN_init().

PLUGIN_interface* global_plint = NULL [static]
 

Definition at line 173 of file plug_extract.c.

Referenced by EXTRACT_tsfunc(), and PLUGIN_init().

char helpstring[] [static]
 

Definition at line 68 of file plug_extract.c.

Referenced by PLUGIN_init().

char* yn_strings[] = { "n" , "y" } [static]
 

Definition at line 127 of file plug_extract.c.

Referenced by EXTRACT_main(), and PLUGIN_init().

 

Powered by Plone

This site conforms to the following standards: