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  

Ifile.c File Reference

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <math.h>
#include <sys/param.h>
#include <dirent.h>
#include "machdep.h"

Go to the source code of this file.


Data Structures

struct  ge_header_info
struct  glob_t

Defines

#define GLOB_APPEND   0x001
#define GLOB_DOOFFS   0x002
#define GLOB_ERR   0x004
#define GLOB_MAGCHAR   0x008
#define GLOB_MARK   0x010
#define GLOB_NOCHECK   0x020
#define GLOB_NOSORT   0x040
#define GLOB_QUOTE   0x080
#define GLOB_NOMAGIC   0x100
#define GLOB_ALTNOT   0x200
#define GLOB_NOSPACE   (-1)
#define GLOB_ABEND   (-2)
#define __P(a)   a
#define xfree   free
#define xmalloc   malloc
#define xrealloc   realloc
#define S_ISDIR(a)   (((a) & S_IFMT) == S_IFDIR)
#define lstat   stat
#define DOLLAR   '$'
#define DOT   '.'
#define EOS   '\0'
#define LBRACKET   '['
#define NOT   '!'
#define ALTNOT   '^'
#define QUESTION   '?'
#define QUOTE   '\\'
#define RANGE   '-'
#define RBRACKET   ']'
#define SEP   '/'
#define STAR   '*'
#define TILDE   '~'
#define UNDERSCORE   '_'
#define M_META   0x8000
#define M_PROTECT   0x4000
#define M_MASK   0xffff
#define M_ASCII   0x00ff
#define CHAR(c)   ((c)&M_ASCII)
#define META(c)   ((c)|M_META)
#define M_ALL   META('*')
#define M_END   META(']')
#define M_NOT   META('!')
#define M_ALTNOT   META('^')
#define M_ONE   META('?')
#define M_RNG   META('-')
#define M_SET   META('[')
#define ismeta(c)   (((c)&M_META) != 0)
#define Lstat   Stat

Typedefs

typedef void * ptr_t
typedef unsigned short Char

Functions

time_t THD_file_mtime (char *pathname)
int THD_is_file (char *pathname)
int THD_is_symlink (char *pathname)
long THD_filesize (char *pathname)
int THD_is_directory (char *pathname)
int THD_is_executable (char *pathname)
void MCW_file_expand (int nin, char **fin, int *nout, char ***fout)
void MCW_free_expand (int gnum, char **gout)
void MCW_warn_expand (int www)
void NIH_glob (char *fn, int *nout, char ***fout)
void NIH_glob_free (int gnum, char **gout)
void ge_header (char *pathname, ge_header_info *hi)
void Ifile_help ()
int main (int argc, char *argv[])
int glob (const char *, int, int(*)(char *, int), glob_t *)
void globfree (glob_t *)
int glob1 __P ((Char *, glob_t *, int))
int glob2 __P ((Char *, Char *, Char *, glob_t *, int))
int glob3 __P ((Char *, Char *, Char *, Char *, glob_t *, int))
int globextend __P ((Char *, glob_t *))
int match __P ((Char *, Char *, Char *, int))
int compare __P ((const ptr_t, const ptr_t))
DIR *Opendir __P ((Char *))
Char *Strchr __P ((Char *, int))
DIR * Opendir (str) register Char *str
int errfunc __P ((char *, int))
void swap_4 (void *ppp)
void swap_8 (void *ppp)
void swap_2 (void *ppp)

Variables

stat * sb
int ch
 q
int flags
glob_tpglob
int no_match
pathend
pattern
restpattern
pat
patend
int m_not

Define Documentation

#define __P a       a
 

the following were in "sh.h", but I put them here to get rid of the need for that file -- RWCox *

Definition at line 621 of file Ifile.c.

Referenced by glob().

#define ALTNOT   '^'
 

Definition at line 689 of file Ifile.c.

#define CHAR c       ((c)&M_ASCII)
 

Definition at line 704 of file Ifile.c.

Referenced by glob().

#define DOLLAR   '$'
 

Definition at line 684 of file Ifile.c.

#define DOT   '.'
 

Definition at line 685 of file Ifile.c.

#define EOS   '\0'
 

Definition at line 686 of file Ifile.c.

#define GLOB_ABEND   (-2)
 

Definition at line 592 of file Ifile.c.

#define GLOB_ALTNOT   0x200
 

Definition at line 589 of file Ifile.c.

#define GLOB_APPEND   0x001
 

Definition at line 579 of file Ifile.c.

#define GLOB_DOOFFS   0x002
 

Definition at line 580 of file Ifile.c.

#define GLOB_ERR   0x004
 

Definition at line 581 of file Ifile.c.

#define GLOB_MAGCHAR   0x008
 

Definition at line 582 of file Ifile.c.

#define GLOB_MARK   0x010
 

Definition at line 583 of file Ifile.c.

#define GLOB_NOCHECK   0x020
 

Definition at line 584 of file Ifile.c.

#define GLOB_NOMAGIC   0x100
 

Definition at line 587 of file Ifile.c.

#define GLOB_NOSORT   0x040
 

Definition at line 585 of file Ifile.c.

#define GLOB_NOSPACE   (-1)
 

Definition at line 591 of file Ifile.c.

#define GLOB_QUOTE   0x080
 

Definition at line 586 of file Ifile.c.

#define ismeta c       (((c)&M_META) != 0)
 

Definition at line 713 of file Ifile.c.

Referenced by glob2().

#define LBRACKET   '['
 

Definition at line 687 of file Ifile.c.

#define Lstat   Stat
 

#define lstat   stat
 

Definition at line 661 of file Ifile.c.

#define M_ALL   META('*')
 

Definition at line 706 of file Ifile.c.

#define M_ALTNOT   META('^')
 

Definition at line 709 of file Ifile.c.

#define M_ASCII   0x00ff
 

Definition at line 702 of file Ifile.c.

#define M_END   META(']')
 

Definition at line 707 of file Ifile.c.

#define M_MASK   0xffff
 

Definition at line 701 of file Ifile.c.

#define M_META   0x8000
 

Definition at line 699 of file Ifile.c.

#define M_NOT   META('!')
 

Definition at line 708 of file Ifile.c.

#define M_ONE   META('?')
 

Definition at line 710 of file Ifile.c.

#define M_PROTECT   0x4000
 

Definition at line 700 of file Ifile.c.

#define M_RNG   META('-')
 

Definition at line 711 of file Ifile.c.

#define M_SET   META('[')
 

Definition at line 712 of file Ifile.c.

#define META c       ((c)|M_META)
 

Definition at line 705 of file Ifile.c.

#define NOT   '!'
 

Definition at line 688 of file Ifile.c.

#define QUESTION   '?'
 

Definition at line 690 of file Ifile.c.

#define QUOTE   '\\'
 

Definition at line 691 of file Ifile.c.

#define RANGE   '-'
 

Definition at line 692 of file Ifile.c.

Referenced by GenerateGrafFunc(), GRAF_drawing_EV(), RCREND_cutout_blobs(), RCREND_reload_dataset(), RCREND_reload_func_dset(), REND_cutout_blobs(), REND_reload_dataset(), and vector_angle().

#define RBRACKET   ']'
 

Definition at line 693 of file Ifile.c.

#define S_ISDIR a       (((a) & S_IFMT) == S_IFDIR)
 

don't use sh.h any more *

Definition at line 653 of file Ifile.c.

Referenced by f__canseek(), f__isdev(), glob2(), ListDirectory(), Stat(), UTL_IsDirectory(), and UTL_VerifyCreatePath().

#define SEP   '/'
 

Definition at line 694 of file Ifile.c.

#define STAR   '*'
 

Definition at line 695 of file Ifile.c.

#define TILDE   '~'
 

Definition at line 696 of file Ifile.c.

#define UNDERSCORE   '_'
 

Definition at line 697 of file Ifile.c.

#define xfree   free
 

Definition at line 623 of file Ifile.c.

#define xmalloc   malloc
 

Definition at line 624 of file Ifile.c.

#define xrealloc   realloc
 

Definition at line 625 of file Ifile.c.


Typedef Documentation

typedef unsigned short Char
 

Definition at line 664 of file Ifile.c.

typedef void* ptr_t
 

Definition at line 636 of file Ifile.c.


Function Documentation

int errfunc __P (char *, int)   
 

Char* Strchr __P (Char *, int)    [static]
 

DIR* Opendir __P (Char *)    [static]
 

int compare __P (const ptr_t, const ptr_t   [static]
 

int match __P (Char *, Char *, Char *, int)    [static]
 

int globextend __P (Char *, glob_t *)    [static]
 

int glob3 __P (Char *, Char *, Char *, Char *, glob_t *, int)    [static]
 

int glob2 __P (Char *, Char *, Char *, glob_t *, int)    [static]
 

int glob1 __P (Char *, glob_t *, int)    [static]
 

void ge_header char *    pathname,
ge_header_info   hi
 

Definition at line 1492 of file Ifile.c.

References abs, ge_header_info::dx, ge_header_info::dy, ge_header_info::dz, ge_header_info::good, L, ge_header_info::nx, ge_header_info::ny, ge_header_info::orients, skip, swap, swap_4(), ge_header_info::te, THD_filesize(), ge_header_info::tr, ge_header_info::uv17, and ge_header_info::zoff.

Referenced by main().

01493 {
01494    FILE *imfile ;
01495    int  length , skip , swap=0 , gg ;
01496    char orients[8] , str[8] ;
01497    int nx , ny , bpp , cflag , hdroff , stamp=0 , iarg=1 ;
01498    float uv17 = -1.0;
01499    
01500    if( hi == NULL ) return ;            /* bad */
01501    hi->good = 0 ;                       /* not good yet */
01502    if( pathname    == NULL ||
01503        pathname[0] == '\0'   ) return ; /* bad */
01504 
01505    length = THD_filesize( pathname ) ;
01506    if( length < 1024 ) return ;         /* bad */
01507 
01508    imfile = fopen( pathname , "r" ) ;
01509    if( imfile == NULL ) return ;        /* bad */
01510 
01511    strcpy(str,"JUNK") ;     /* initialize string */
01512    fread(str,1,4,imfile) ;  /* check for "IMGF" at start of file */
01513 
01514    if( str[0]!='I' || str[1]!='M' || str[2]!='G' || str[3]!='F' ){ /* bad */
01515       fclose(imfile) ; return ;
01516    }
01517 
01518    /*-- read next 5 ints (after the "IMGF" string) --*/
01519 
01520    fread( &skip , 4,1, imfile ) ; /* offset into file of image data */
01521    fread( &nx   , 4,1, imfile ) ; /* x-size */
01522    fread( &ny   , 4,1, imfile ) ; /* y-size */
01523    fread( &bpp  , 4,1, imfile ) ; /* bits per pixel (should be 16) */
01524    fread( &cflag, 4,1, imfile ) ; /* compression flag (1=uncompressed)*/
01525 
01526    /*-- check if nx is funny --*/
01527 
01528    if( nx < 0 || nx > 8192 ){      /* have to byte swap these 5 ints */
01529      swap = 1 ;                    /* flag to swap data, too */
01530      swap_4(&skip); swap_4(&nx); swap_4(&ny); swap_4(&bpp); swap_4(&cflag);
01531    } else {
01532      swap = 0 ;  /* data is ordered for this CPU */
01533    }
01534    if( nx < 0 || nx > 8192 || ny < 0 || ny > 8192 ){  /* bad */
01535       fclose(imfile) ; return ;
01536    }
01537 
01538    hi->nx = nx ;
01539    hi->ny = ny ;
01540 
01541    if( skip+2*nx*ny >  length ||               /* file is too short */
01542        skip         <= 0      ||               /* bizarre  */
01543        cflag        != 1      ||               /* data is compressed */
01544        bpp          != 16        ) return ;    /* data is not shorts */
01545 
01546    /*-- try to read image header data as well --*/
01547 
01548    fseek( imfile , 148L , SEEK_SET ) ; /* magic GEMS offset */
01549    fread( &hdroff , 4,1 , imfile ) ;   /* location of image header */
01550    if( swap ) swap_4(&hdroff) ;
01551 
01552    if( hdroff > 0 && hdroff+256 < length ){   /* can read from image header */
01553        float dx,dy,dz, xyz[9], zz, tr ; int itr, ii,jj,kk ;
01554 
01555        /*-- get voxel grid sizes --*/
01556 
01557        fseek( imfile , hdroff+26 , SEEK_SET ) ;    /* dz */
01558        fread( &dz , 4,1 , imfile ) ;
01559 
01560        fseek( imfile , hdroff+50 , SEEK_SET ) ;    /* dx and dy */
01561        fread( &dx , 4,1 , imfile ) ;
01562        fread( &dy , 4,1 , imfile ) ;
01563 
01564        if( swap ){ swap_4(&dx); swap_4(&dy); swap_4(&dz); }
01565 
01566        hi->dx = dx ; hi->dy = dy ; hi->dz = dz ;
01567 
01568        /* grid orientation: from 3 sets of LPI corner coordinates: */
01569        /*   xyz[0..2] = top left hand corner of image     (TLHC)   */
01570        /*   xyz[3..5] = top right hand corner of image    (TRHC)   */
01571        /*   xyz[6..8] = bottom right hand corner of image (BRHC)   */
01572        /* GEMS coordinate orientation here is LPI                  */
01573 
01574        fseek( imfile , hdroff+154 , SEEK_SET ) ;  /* another magic number */
01575        fread( xyz , 4,9 , imfile ) ;
01576        if( swap ){
01577           swap_4(xyz+0); swap_4(xyz+1); swap_4(xyz+2);
01578           swap_4(xyz+3); swap_4(xyz+4); swap_4(xyz+5);
01579           swap_4(xyz+6); swap_4(xyz+7); swap_4(xyz+8);
01580        }
01581 
01582        /* x-axis orientation */
01583        /* ii determines which spatial direction is x-axis  */
01584        /* and is the direction that has the biggest change */
01585        /* between the TLHC and TRHC                        */
01586 
01587        dx = fabs(xyz[3]-xyz[0]) ; ii = 1 ;
01588        dy = fabs(xyz[4]-xyz[1]) ; if( dy > dx ){ ii=2; dx=dy; }
01589        dz = fabs(xyz[5]-xyz[2]) ; if( dz > dx ){ ii=3;        }
01590        dx = xyz[ii+2]-xyz[ii-1] ; if( dx < 0. ){ ii = -ii;    }
01591        switch( ii ){
01592         case  1: orients[0]= 'L'; orients[1]= 'R'; break; /* Left      to Right     */
01593         case -1: orients[0]= 'R'; orients[1]= 'L'; break; /* Right     to Left      */
01594         case  2: orients[0]= 'P'; orients[1]= 'A'; break; /* Posterior to Anterior  */
01595         case -2: orients[0]= 'A'; orients[1]= 'P'; break; /* Anterior  to Posterior */
01596         case  3: orients[0]= 'I'; orients[1]= 'S'; break; /* Inferior  to Superior  */
01597         case -3: orients[0]= 'S'; orients[1]= 'I'; break; /* Superior  to Inferior  */
01598         default: orients[0]='\0'; orients[1]='\0'; break; /* should never happen    */
01599        }
01600 
01601        /* y-axis orientation */
01602        /* jj determines which spatial direction is y-axis  */
01603        /* and is the direction that has the biggest change */
01604        /* between the BRHC and TRHC                        */
01605 
01606        dx = fabs(xyz[6]-xyz[3]) ; jj = 1 ;
01607        dy = fabs(xyz[7]-xyz[4]) ; if( dy > dx ){ jj=2; dx=dy; }
01608        dz = fabs(xyz[8]-xyz[5]) ; if( dz > dx ){ jj=3;        }
01609        dx = xyz[jj+5]-xyz[jj+2] ; if( dx < 0. ){ jj = -jj;    }
01610        switch( jj ){
01611          case  1: orients[2] = 'L'; orients[3] = 'R'; break;
01612          case -1: orients[2] = 'R'; orients[3] = 'L'; break;
01613          case  2: orients[2] = 'P'; orients[3] = 'A'; break;
01614          case -2: orients[2] = 'A'; orients[3] = 'P'; break;
01615          case  3: orients[2] = 'I'; orients[3] = 'S'; break;
01616          case -3: orients[2] = 'S'; orients[3] = 'I'; break;
01617          default: orients[2] ='\0'; orients[3] ='\0'; break;
01618        }
01619 
01620        orients[4] = '\0' ;   /* terminate orientation string */
01621 
01622        kk = 6 - abs(ii)-abs(jj) ;   /* which spatial direction is z-axis   */
01623                                     /* where 1=LR, 2=PA, 3=IS               */
01624                                     /* (can't tell orientation from 1 slice) */
01625 
01626        zz = xyz[kk-1] ;             /* z-coordinate of this slice */
01627 
01628        hi->zoff = zz ;
01629        strcpy(hi->orients,orients) ;
01630 
01631        /*-- get TR in seconds --*/
01632 
01633        fseek( imfile , hdroff+194 , SEEK_SET ) ;
01634        fread( &itr , 4,1 , imfile ) ; /* note itr is an int */
01635        if( swap ) swap_4(&itr) ;
01636        hi->tr = 1.0e-6 * itr ;        /* itr is in microsec */
01637 
01638        /*-- get TE in milliseconds --*/
01639 
01640        fseek( imfile , hdroff+202 , SEEK_SET ) ;
01641        fread( &itr , 4,1 , imfile ) ; /* itr is an int, in microsec */
01642        if( swap ) swap_4(&itr) ;
01643        hi->te = 1.0e-6 * itr ;
01644 
01645        /* zmodify: get User Variable 17, a likely indicator of a new scan, info by S.Marrett, location from S. Inati's matlab function GE_readHeaderImage.m*/
01646          
01647       /* printf ("\nuv17 = \n"); */
01648       fseek ( imfile , hdroff+272+202, SEEK_SET ) ;
01649       fread( &uv17 , 4, 1 , imfile ) ;
01650       if( swap ) swap_4(&uv17) ;
01651       /* printf ("%d ", (int)uv17);  */
01652       hi->uv17 = (int)uv17; 
01653       /* printf ("\n"); */
01654       
01655        hi->good = 1 ;                 /* this is a good file */
01656 
01657    } /* end of actually reading image header */
01658 
01659    fclose(imfile) ; return ;
01660 }

int glob const char *   ,
int   ,
int(*   )(char *, int),
glob_t  
 

Definition at line 295 of file mcw_glob.c.

00296 {
00297     int     err, oldpathc;
00298     Char *bufnext, *bufend, *compilebuf, m_not;
00299     const unsigned char *compilepat, *patnext;
00300     int     c, nnot;
00301     Char patbuf[MAXPATHLEN + 1], *qpatnext;
00302     int     no_match;
00303 
00304     patnext = (unsigned char *) pattern;
00305     if (!(flags & GLOB_APPEND)) {
00306         pglob->gl_pathc = 0;
00307         pglob->gl_pathv = NULL;
00308         if (!(flags & GLOB_DOOFFS))
00309             pglob->gl_offs = 0;
00310     }
00311     pglob->gl_flags = flags & ~GLOB_MAGCHAR;
00312     pglob->gl_errfunc = errfunc;
00313     oldpathc = pglob->gl_pathc;
00314     pglob->gl_matchc = 0;
00315 
00316     if (pglob->gl_flags & GLOB_ALTNOT) {
00317         nnot = ALTNOT;
00318         m_not = M_ALTNOT;
00319     }
00320     else {
00321         nnot = NOT;
00322         m_not = M_NOT;
00323     }
00324 
00325     bufnext = patbuf;
00326     bufend = bufnext + MAXPATHLEN;
00327     compilebuf = bufnext;
00328     compilepat = patnext;
00329 
00330     no_match = *patnext == nnot;
00331     if (no_match)
00332         patnext++;
00333 
00334     if (flags & GLOB_QUOTE) {
00335         /* Protect the quoted characters */
00336         while (bufnext < bufend && (c = *patnext++) != EOS)
00337             if (c == QUOTE) {
00338                 if ((c = *patnext++) == EOS) {
00339                     c = QUOTE;
00340                     --patnext;
00341                 }
00342                 *bufnext++ = (Char) (c | M_PROTECT);
00343             }
00344             else
00345                 *bufnext++ = (Char) c;
00346     }
00347     else
00348         while (bufnext < bufend && (c = *patnext++) != EOS)
00349             *bufnext++ = (Char) c;
00350     *bufnext = EOS;
00351 
00352     bufnext = patbuf;
00353     qpatnext = patbuf;
00354     /* we don't need to check for buffer overflow any more */
00355     while ((c = *qpatnext++) != EOS) {
00356         switch (c) {
00357         case LBRACKET:
00358             c = *qpatnext;
00359             if (c == nnot)
00360                 ++qpatnext;
00361             if (*qpatnext == EOS ||
00362                 Strchr(qpatnext + 1, RBRACKET) == NULL) {
00363                 *bufnext++ = LBRACKET;
00364                 if (c == nnot)
00365                     --qpatnext;
00366                 break;
00367             }
00368             pglob->gl_flags |= GLOB_MAGCHAR;
00369             *bufnext++ = M_SET;
00370             if (c == nnot)
00371                 *bufnext++ = m_not;
00372             c = *qpatnext++;
00373             do {
00374                 *bufnext++ = CHAR(c);
00375                 if (*qpatnext == RANGE &&
00376                     (c = qpatnext[1]) != RBRACKET) {
00377                     *bufnext++ = M_RNG;
00378                     *bufnext++ = CHAR(c);
00379                     qpatnext += 2;
00380                 }
00381             } while ((c = *qpatnext++) != RBRACKET);
00382             *bufnext++ = M_END;
00383             break;
00384         case QUESTION:
00385             pglob->gl_flags |= GLOB_MAGCHAR;
00386             *bufnext++ = M_ONE;
00387             break;
00388         case STAR:
00389             pglob->gl_flags |= GLOB_MAGCHAR;
00390             /* collapse adjacent stars to one, to avoid
00391              * exponential behavior
00392              */
00393             if (bufnext == patbuf || bufnext[-1] != M_ALL)
00394                 *bufnext++ = M_ALL;
00395             break;
00396         default:
00397             *bufnext++ = CHAR(c);
00398             break;
00399         }
00400     }
00401     *bufnext = EOS;
00402 #ifdef DEBUG
00403     qprintf(patbuf);
00404 #endif
00405 
00406     if ((err = glob1(patbuf, pglob, no_match)) != 0)
00407         return (err);
00408 
00409     /*
00410      * If there was no match we are going to append the pattern
00411      * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified
00412      * and the pattern did not contain any magic characters
00413      * GLOB_NOMAGIC is there just for compatibility with csh.
00414      */
00415     if (pglob->gl_pathc == oldpathc &&
00416         ((flags & GLOB_NOCHECK) ||
00417          ((flags & GLOB_NOMAGIC) && !(pglob->gl_flags & GLOB_MAGCHAR)))) {
00418         if (!(flags & GLOB_QUOTE)) {
00419             Char *dp = compilebuf;
00420             const unsigned char *sp = compilepat;
00421 
00422             while ((*dp++ = *sp++) != '\0')
00423                 continue;
00424         }
00425         else {
00426             /*
00427              * copy pattern, interpreting quotes; this is slightly different
00428              * than the interpretation of quotes above -- which should prevail?
00429              */
00430             while (*compilepat != EOS) {
00431                 if (*compilepat == QUOTE) {
00432                     if (*++compilepat == EOS)
00433                         --compilepat;
00434                 }
00435                 *compilebuf++ = (unsigned char) *compilepat++;
00436             }
00437             *compilebuf = EOS;
00438         }
00439         return (globextend(patbuf, pglob));
00440     }
00441     else if (!(flags & GLOB_NOSORT))
00442         qsort((char *) (pglob->gl_pathv + pglob->gl_offs + oldpathc),
00443               pglob->gl_pathc - oldpathc, sizeof(char *),
00444               (int (*) __P((const void *, const void *))) compare);
00445     return (0);
00446 }

void globfree glob_t  
 

Definition at line 719 of file mcw_glob.c.

00720 {
00721     register int i;
00722     register char **pp;
00723 
00724     if (pglob->gl_pathv != NULL) {
00725         pp = pglob->gl_pathv + pglob->gl_offs;
00726         for (i = pglob->gl_pathc; i--; ++pp)
00727             if (*pp)
00728                 xfree((ptr_t) *pp), *pp = NULL;
00729         xfree((ptr_t) pglob->gl_pathv), pglob->gl_pathv = NULL;
00730     }
00731 }

void Ifile_help  
 

Definition at line 413 of file Ifile.c.

Referenced by main().

00414    {
00415       fprintf(stdout,"\nUsage: Ifile [Options] <File List> \n");
00416       
00417       fprintf(stdout,"\n\t[-nt]: Do not use time stamp to identify complete scans.\n");
00418       fprintf(stdout,"\t       Complete scans are identified from 'User Variable 17'\n"
00419                      "\t       in the image header.\n");
00420       fprintf(stdout,"\t[-sp Pattern]: Slice acquisition pattern.\n"          
00421                      "\t               Sets the slice acquisition pattern.\n"
00422                      "\t               The default option is alt+z.\n"
00423                      "\t               See to3d -help for acceptable options.\n"); 
00424       fprintf(stdout,"\t[-od Output_Directory]: Set the output directory in @RenamePanga.\n"
00425                      "\t                        The default is afni .\n"); 
00426       fprintf(stdout,"\n\t<File List>: Strings of wildcards defining series of\n");
00427       fprintf(stdout,"\t              GE-Real Time (GERT) images to be assembled\n");
00428       fprintf(stdout,"\t              as an afni brick. Example:\n");
00429       fprintf(stdout,"\t              Ifile '*/I.*'\n");
00430       fprintf(stdout,"\t          or  Ifile '083/I.*' '103/I.*' '123/I.*' '143/I.*'\n\n"); 
00431       fprintf(stdout,"\tThe program attempts to identify complete scans from the list\n");
00432       fprintf(stdout,"\tof images supplied on command line and generates the commands\n");
00433       fprintf(stdout,"\tnecessary to turn them into AFNI bricks using the script @RenamePanga.\n");
00434       fprintf(stdout,"\tIf at least one complete scan is identified, a script file named GERT_Reco\n");
00435       fprintf(stdout,"\tis created and executing it creates the afni bricks placed in the afni directory.\n");
00436       fprintf(stdout,"\nHow does it work?\n");
00437       fprintf(stdout,"\tWith the -nt option: Ifile uses the variable 'User Variable 17' in the \n");
00438       fprintf(stdout,"\tI file's header. This option appears to be augmented each time a new\n");
00439       fprintf(stdout,"\tscan is started. (Thanks to S. Marrett for discovering the elusive variable.)\n");
00440       fprintf(stdout,"\tWithout -nt option: Ifile first examines the modification time for each image and \n");
00441       fprintf(stdout,"\tinfers from that which images form a single scan. Consecutive images that are less \n");
00442       fprintf(stdout,"\tthan T seconds apart belong to the same scan. T is set based on the mean\n");
00443       fprintf(stdout,"\ttime delay difference between successive images. The threshold currently\n");
00444       fprintf(stdout,"\tused works for the test data that we have. If it fails for your data, let us\n");
00445       fprintf(stdout,"\tknow and supply us with the data. Once a set of images is grouped into a \n");
00446       fprintf(stdout,"\tscan the sequence of slice location is analysed and duplicate, missing slices,\n");
00447       fprintf(stdout,"\tand incomplete volumes are detected. Sets of images that do not pass these tests\n");
00448       fprintf(stdout,"\tare ignored.\n");
00449       fprintf(stdout,"\nPreserving Time Info: (not necessary with -nt option but does not hurt to preserve anyway)\n");
00450       fprintf(stdout,"\tIt is important to preserve the file modification time info as you copy or untar\n");
00451       fprintf(stdout,"\tthe data. If you neglect to do so and fail to write down where each scan ends\n");
00452       fprintf(stdout,"\tand/or begins, you might have a hell of a time reconstructing your data.\n");
00453       fprintf(stdout,"\tWhen copying image directories, use \33[1m cp -rp ???/* \33[0m and when untaring \n");
00454       fprintf(stdout,"\tthe archive, use \33[1m tar --atime-preserve -xf Archive.tar \33[0m on linux.\n");
00455       fprintf(stdout,"\tOn Sun and SGI, tar -xf Archive.tar preserves the time info.\n"); 
00456       fprintf(stdout,"\nFuture Improvements:\n");
00457       fprintf(stdout,"\tOut of justifiable laziness, and for other less convincing reasons, I have left \n");
00458       fprintf(stdout,"\tIfile and @RenamePanga separate. They can be combined into one program but it's usage\n");
00459       fprintf(stdout,"\twould become more complicated. At any rate, the user should not notice any difference\n");
00460       fprintf(stdout,"\tsince all they have to do is run the script GERT_reco that is created by Ifile.\n\n"); 
00461       fprintf(stdout,"\t   Dec. 12/01 (Last modified July 24/02) SSCC/NIMH \n\tRobert W. Cox(rwcox@nih.gov) and Ziad S. Saad (ziad@nih.gov)\n\n");
00462       
00463    }

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 54 of file Ifile.c.

References argc, calloc, free, ge_header(), ge_header_info::good, i, Ifile_help(), lmax(), malloc, MCW_file_expand(), MCW_free_expand(), Ni, THD_file_mtime(), ge_header_info::tr, ge_header_info::uv17, and ge_header_info::zoff.

00055 {
00056    int num_I , ii,jj , ngood , nrun , i, UseUv17 = 0;
00057    char **nam_I  ;
00058    char **gnam_I , *PatOpt=NULL, *OutDir = NULL;
00059    int   *time_I , *uv17, lmax=0 , ll , thresh , ibot,itop ;
00060    float *zoff_I , tr , zth1,zth2 , zd ;
00061    ge_header_info geh ;
00062    int Ni, CurVolInd, *New_Vol_Loc, *VolSize, N_Vols, *TroubVolume, iTroub, 
00063       MultiSliceVol, *DupSlice, iDup, BadRun, AllGood = 1, GoodRun, kar = -1,
00064       brk = 0, StrtFiles = 0;
00065    float *Dzv, fact;
00066    char fmt[128] ;
00067    FILE * fout_dbg, *fout_panga;
00068 
00069    if (argc == 1) { Ifile_help(); exit(1); }
00070    kar = 1;
00071         brk = 0;
00072    StrtFiles = 0;
00073         UseUv17 = 0;
00074    while (kar < argc && !StrtFiles) { /* loop accross command ine options */
00075       if (strcmp (argv[kar],"-h") == 0 || strcmp (argv[kar],"-help") == 0) { Ifile_help(); exit(1); }
00076       
00077       if (!brk && (strcmp(argv[kar], "-nt") == 0)) {
00078          UseUv17 = 1;
00079                         brk = 1;
00080          ++kar;
00081                 }
00082       
00083       if (!brk && (strcmp(argv[kar], "-od") == 0)) {
00084          kar ++;
00085                         if (kar >= argc)  {
00086                                 fprintf (stderr, "Error: Need argument after -od.\n");
00087                                 exit (1);
00088                         }
00089          OutDir =  (char *)malloc((strlen(argv[kar])+1)*sizeof(char));
00090          
00091          sprintf(OutDir,"%s",argv[kar]);
00092          brk = 1;
00093          ++kar;
00094       }
00095       
00096       if (!brk && (strcmp(argv[kar], "-sp") == 0)) {
00097          kar ++;
00098                         if (kar >= argc)  {
00099                                 fprintf (stderr, "Error: Need argument after -sp.\n");
00100                                 exit (1);
00101                         }
00102          PatOpt =  (char *)malloc((strlen(argv[kar])+1)*sizeof(char));
00103          
00104          sprintf(PatOpt,"%s",argv[kar]);
00105          brk = 1;
00106          ++kar;
00107       }
00108       
00109       /* nothing found, save location and get out */
00110       if (!brk) {
00111          /* Done with options */
00112          StrtFiles = kar;
00113       } else {
00114          brk = 0;
00115       }
00116    }
00117    
00118    if (UseUv17) { 
00119       fprintf(stderr,"++ using User Variable 17.\n"); } 
00120    else { 
00121       fprintf(stderr,"++ using time stamp.\n");} 
00122    
00123    if (!PatOpt) { 
00124       PatOpt = (char *)malloc(sizeof(char)*10);
00125       sprintf(PatOpt,"alt+z");
00126    }
00127    
00128    if (!OutDir) {
00129       OutDir = (char *)malloc(sizeof(char)*10);
00130       sprintf(OutDir,"afni");
00131    }
00132    
00133    fprintf(stderr,"++ using slice pattern %s\n", PatOpt);
00134    fprintf(stderr,"++ using output directory %s\n", OutDir);
00135    
00136    /*
00137    for (i = 1; i < argc; ++i) {
00138    fprintf(stdout, "%s\n", argv[i]);}
00139    */
00140    fout_panga = fopen("GERT_Reco","w");
00141    if (fout_panga == NULL) { 
00142       fprintf(stderr,"Could not open AutoPanga for writing. Check write permissions.\n");
00143       exit(1);
00144    }
00145    fprintf(fout_panga, "#!/bin/csh -f\n");
00146    fprintf(fout_panga, "#This script was automatically generated by Ifile.\n");
00147    fprintf(fout_panga, "#Change the following options to your liking (see @RenamePanga -help for more info):\n\n");
00148    fprintf(fout_panga, "set OutlierCheck = '-oc' #set to '-oc' to check for outliers, '' to skip checking.\n");
00149    fprintf(fout_panga, "set OutPrefix = 'OutBrick' #Output brick prefix.\n\n");
00150    
00151    /*-- get the list of files */
00152    fprintf(stderr,"++ Expanding file list ...\n") ;
00153    MCW_file_expand( argc - StrtFiles, argv + StrtFiles  , &num_I , &nam_I );
00154 
00155    fprintf(stderr,"++ found %d '*/I.*' files\n",num_I) ;
00156 
00157    if( num_I <= 0 ) exit(1) ;
00158 
00159    /*-- get time and z-offset of each good image --*/
00160 
00161    time_I = (int *)   calloc( sizeof(int)    , num_I ) ;
00162    zoff_I = (float *) calloc( sizeof(float)  , num_I ) ;
00163    gnam_I = (char **) calloc( sizeof(char *) , num_I ) ;
00164    uv17 = (int *) calloc( sizeof(int)    , num_I ) ;
00165    ngood  = 0 ;
00166 
00167    fprintf(stderr,"++ Scanning GE headers") ;
00168    #ifdef DBG_FILE   
00169       fout_dbg = fopen("DBG_IfileOut.txt","w");
00170    #endif
00171    
00172    for( ii=0 ; ii < num_I ; ii++ ){
00173       ge_header( nam_I[ii] , &geh ) ;    /* read GE header */
00174 
00175       if( ii%1000==999 ) fprintf(stderr,".") ;
00176 
00177       if( geh.good ){                    /* is good image file */
00178          zoff_I[ngood] = geh.zoff ;
00179          time_I[ngood] = (int) THD_file_mtime( nam_I[ii] ) ;
00180          gnam_I[ngood] = strdup( nam_I[ii] ) ;
00181          uv17[ngood] = geh.uv17;
00182          
00183          ngood++ ;
00184 
00185          ll = strlen(nam_I[ii]) ; if( ll > lmax ) lmax = ll ;
00186 
00187          tr += geh.tr ;
00188       }
00189       else {
00190       fprintf(stderr,"\tFile %s: !geh.good.\t", nam_I[ii] ) ;
00191       }
00192       #ifdef DBG_FILE   
00193          fprintf(fout_dbg,"%s %d\n", nam_I[ii], time_I[ii]);
00194       #endif
00195    }
00196    
00197   
00198    fprintf(stderr,"\n++ %d files are good images\n",ngood) ;
00199 
00200    MCW_free_expand(  num_I, nam_I ) ;/* don't need nam_I any more */
00201 
00202 
00203    if( ngood < 3 ) exit(1) ;
00204 
00205    /*-- convert to time difference from previous image --*/
00206 
00207    for( ii=ngood-1 ; ii > 0 ; ii-- ) {
00208         time_I[ii] -= time_I[ii-1] ;
00209       
00210       }
00211    time_I[0] = 0 ;
00212 
00213    /*-- set threshold for time, to find distinct imaging runs --*/
00214 
00215    tr    /= ngood ;                 /* average TR reported */
00216    thresh = (int)( 3.0*tr+10.5 ) ;  /* threshold (may need some work) */
00217 
00218    if (UseUv17 == 0) {
00219       /* Just suppress time threshold output, time calculations are not trimmed since they are performed very quickly*/
00220       fprintf(stderr,"++ File time threshold = %d s\n",thresh) ;
00221    }
00222    
00223    /*-- find time steps longer than thresh:
00224         these are starts of new imaging runs 
00225         or with -nt option, use User Variable 17--*/
00226    GoodRun = 0;
00227    nrun = 0 ;
00228    ibot = 0 ;
00229    while( ibot < ngood ){  /* scan forward from ibot */
00230 
00231       /* scan itop until end, or until time step is too big */
00232 
00233       if (UseUv17) {
00234          for( itop=ibot+1; itop<ngood && uv17[itop]==uv17[ibot]; itop++ ) {/* printf("%d ", uv17[itop]); */}; 
00235       } else { /* use time stamp */
00236          for( itop=ibot+1; itop<ngood && time_I[itop]<thresh; itop++ ) ; /* nada */
00237       }
00238       
00239       
00240       /* this run is from ibot to itop-1 */
00241       
00242       
00243       if( ibot == itop-1 ){                    /* skip single files */
00244 
00245          printf("skip:   %s\n",gnam_I[ibot]) ;
00246 
00247       } else {                                 /* more than 1 file */
00248                
00249          nrun++ ;
00250          BadRun = 0; /* Initialize with good faith */
00251          printf("\nRUN %02d:\t  %s .. %s\t",nrun,gnam_I[ibot],gnam_I[itop-1]) ;
00252          /* check for skipped slices [assume 1st 2 slices are OK] */
00253          
00254          if (0) /* intial method */
00255             {/* [[ this algorithm could use some thought!  ]] */
00256             /* [[ maybe compute median delta-zoff?        ]] */
00257             /* [[ what about 1 or 2 slice imaging runs?   ]] */
00258             /* [[ what about slice missing at top or bot? ]] */
00259 
00260             zth1 = fabs( zoff_I[ibot+1] - zoff_I[ibot] ) * 1.01 + 0.01 ;
00261             zth2 = 3.01*zth1 ;
00262 
00263             for( jj=ibot ; jj < itop-1 ; jj++ ){
00264                zd = fabs( zoff_I[jj+1] - zoff_I[jj] ) ;
00265                if( zd > zth1 && zd < zth2 )
00266                   printf("  image %s seems out of place\n",gnam_I[jj+1]) ;
00267             }
00268             }
00269          else
00270             {
00271                               
00272                Ni = itop - ibot; /*Number of images in run, itop is not included*/
00273                Dzv = (float *) calloc( sizeof(float)  , Ni) ;
00274                New_Vol_Loc = (int *) calloc(sizeof(int), Ni); /* could not be bigger than Ni */
00275                VolSize = (int *) calloc(sizeof(int), Ni); 
00276                TroubVolume = (int *) calloc(sizeof(int), Ni); 
00277                DupSlice = (int *) calloc(sizeof(int), Ni); 
00278                
00279                Dzv[0] = 0; /* derivative of volume */
00280                Dzv[1] = zoff_I[ibot+1] - zoff_I[ibot]; 
00281                if (Dzv[1] < 0) 
00282                   {
00283                      fact = -1; 
00284                      Dzv[1] *= fact;
00285                   }
00286                else fact = 1;
00287                if (Dzv[1] != 0) 
00288                   MultiSliceVol = 1; 
00289                else
00290                   MultiSliceVol = 0;
00291                   
00292                
00293                /* find total number of volumes */
00294                iDup = 0;
00295                iTroub = 0;
00296                CurVolInd = 0; /* Current Volume Index */
00297                New_Vol_Loc[CurVolInd] = ibot; /* New Volume Location in series */
00298                for (jj = ibot+2 ; jj < itop ; jj++ ){
00299                   Dzv[jj-ibot] = fact * (zoff_I[jj] - zoff_I[jj - 1]);
00300                   #ifdef DBG_FILE
00301                      fprintf(fout_dbg,"Dzv %f \n", Dzv[jj-ibot]);
00302                    #endif
00303                   if (MultiSliceVol && !Dzv[jj-ibot]) {
00304                      DupSlice[iDup] = jj;
00305                      ++iDup;
00306                   }
00307                   
00308                   if (Dzv[jj-ibot] < 0) { /* New Volume, coming Up */
00309                      ++CurVolInd;
00310                      New_Vol_Loc[CurVolInd] = jj;
00311                      VolSize[CurVolInd-1] = New_Vol_Loc[CurVolInd] - New_Vol_Loc[CurVolInd-1]; 
00312                      if (CurVolInd > 1) { /* compare to first volume */
00313                         if (VolSize[CurVolInd-1] != VolSize[0]) { /* trouble volume */
00314                            TroubVolume[iTroub] = CurVolInd - 1;
00315                            ++iTroub;
00316                         }
00317                      }
00318                   }
00319                } /* jj */
00320                VolSize[CurVolInd] = itop - New_Vol_Loc[CurVolInd]; /* last volume size */
00321                if (VolSize[CurVolInd] != VolSize[0]) { 
00322                   TroubVolume[iTroub] = CurVolInd;
00323                   ++iTroub;
00324                }
00325                N_Vols = CurVolInd+1;
00326                printf("%d images %d Volume(s) \n", Ni, N_Vols);
00327                /* DoppelChecker */
00328                if (N_Vols > 1) {
00329                   /*
00330                   for (i=0; i< N_Vols -1; i++) {
00331                   fprintf(stderr, "Vol %d %d slices Begin %s End %s\n", i, VolSize[i], gnam_I[New_Vol_Loc[i]], gnam_I[New_Vol_Loc[i+1]-1]);
00332                   }
00333                   fprintf(stderr, "Vol %d %d slices Begin %s End %s\n", N_Vols-1, VolSize[N_Vols-1], gnam_I[New_Vol_Loc[N_Vols-1]],gnam_I[itop-1]); 
00334                   */
00335                }
00336                else {                     
00337                   /* fprintf(stderr, "One volume found: %d slices, Begin %s End %s\n", VolSize[0], gnam_I[New_Vol_Loc[0]],gnam_I[itop-1]); */
00338                }
00339                if (iTroub > 0) { /* Trouble volumes found */
00340                   BadRun = 1;
00341                   fprintf(stderr, "\t\33[1m***************** PANGA! Trouble volumes found. *****************\33[0m\n");
00342                   fprintf(stderr, "\tVol %d %s--%s (%d slices) has a different size from the first volume (%d slices) in the series.\n", \
00343                      TroubVolume[0], gnam_I[New_Vol_Loc[TroubVolume[0]]], gnam_I[New_Vol_Loc[TroubVolume[0]]+VolSize[TroubVolume[0]]-1], VolSize[TroubVolume[0]], VolSize[0]);
00344                   if (iTroub > 1)
00345                      fprintf(stderr, "\t%d other volumes suffer of similar ailments! Think of the children!\n", iTroub - 1);
00346                   /* Too much info
00347                   for (i=0; i < iTroub; i++) {
00348                      fprintf(stderr, "Vol %d (%d slices) has a different size from the first volume (%d slices) in the series.\n", TroubVolume[i], VolSize[TroubVolume[i]], VolSize[0]);
00349                   }
00350                   */
00351                }
00352                if (iDup > 0) { /* Duplicate slices found */
00353                   BadRun = 1;
00354                   fprintf(stderr, "\t\33[1m***************** PANGA! Dupilcated slices found. *****************\33[0m\n");
00355                   for (i=0; i < iDup; i++) {
00356                      fprintf(stderr, "\tSlice %s appears to be a duplicate of slice %s.\n", gnam_I[DupSlice[i]], gnam_I[DupSlice[i]-1]);
00357                   }                  
00358                } /* iDup > 0 */
00359             }/* New Method */
00360             
00361             if (!BadRun) { /* write out results as a command line for @RenamePanga */
00362                ++ GoodRun;
00363                fprintf(fout_panga,"@RenamePanga %s ", strtok(gnam_I[ibot],"/"));
00364                if (MultiSliceVol)
00365                   fprintf(fout_panga,"%s %d %d $OutPrefix -sp %s $OutlierCheck -od %s\n", 
00366                      strtok(NULL,"/I."), (int)Ni/N_Vols, N_Vols, PatOpt, OutDir);
00367                else
00368                   fprintf(fout_panga,"%s %d %d $OutPrefix -sp %s $OutlierCheck -od %s\n", 
00369                      strtok(NULL,"/I."), N_Vols, (int)Ni/N_Vols, PatOpt, OutDir);
00370             }
00371             else
00372             {
00373                AllGood = 0;
00374             }
00375             free(Dzv);
00376             free(New_Vol_Loc);
00377             free(VolSize);
00378             free(TroubVolume);
00379             free(DupSlice);
00380       }
00381 
00382       ibot = itop ;  /* start scan here */
00383    }
00384    
00385    free(PatOpt);
00386    free(OutDir);
00387    
00388    #ifdef DBG_FILE
00389       fclose (fout_dbg);
00390    #endif
00391    fprintf(fout_panga, "\n");
00392    fclose (fout_panga);
00393    system ("chmod u+x GERT_Reco");
00394 #if 0
00395    /* old code to print out stuff to check if program was working */
00396    sprintf(fmt,"%%-%d.%ds: dt=%%d  zoff=%%g\n",lmax,lmax) ;
00397    for( ii=0 ; ii < ngood ; ii++ )
00398       printf(fmt,gnam_I[ii],time_I[ii],zoff_I[ii]) ;
00399 #endif
00400 
00401    if (!GoodRun) 
00402       system ("rm -f GERT_Reco"); 
00403    else
00404       fprintf(stdout,"\nFound %d complete scans.\nRun\33[1m GERT_Reco \33[0mto create AFNI bricks.\n\n", GoodRun);
00405       
00406    if (AllGood)
00407       exit(0) ;
00408    else
00409       exit(1);
00410 }

void MCW_file_expand int    nin,
char **    fin,
int *    nout,
char ***    fout
 

Routines that allows filename wildcarding to be handled inside to3d. The advantage: limitations of shell command line lengths.

  • 29 July 1996: Incorporated "glob" functions from tcsh-6.05, rather than rely on system supplying a library.
  • 30 July 1996: Extended routine to allow for 3D: type prefixes.
  • 10 Feb 2000: and for 3A: prefixes. --------------------------------------------------------------------------

Definition at line 1326 of file Ifile.c.

References fout, glob_t::gl_pathc, glob_t::gl_pathv, glob(), globfree(), ilen, malloc, and realloc.

01327 {
01328    glob_t gl ;
01329    int    ii , gnum, gold , ilen ;
01330    char ** gout ;
01331    char *  fn ;
01332    char prefix[4] , fpre[128] , fname[256] ;
01333    int  b1,b2,b3,b4,b5 , ib,ig , lpre ;
01334 
01335    if( nin <= 0 ){ *nout = 0 ; return ; }
01336 
01337    gnum = 0 ;
01338    gout = NULL ;
01339 
01340    for( ii=0 ; ii < nin ; ii++ ){
01341       fn = fin[ii] ;
01342 
01343       ig = 0 ;
01344 
01345       /** look for 3D: prefix **/
01346 
01347       if( strlen(fn) > 9 && fn[0] == '3' && fn[1] == 'D' ){
01348          ib = 0 ;
01349          prefix[ib++] = '3' ;
01350          prefix[ib++] = 'D' ;
01351          if( fn[2] == ':' ){ prefix[ib++] = '\0' ; }
01352          else              { prefix[ib++] = fn[2] ; prefix[ib++] = '\0' ; }
01353 
01354          ig = sscanf( fn+ib , "%d:%d:%d:%d:%d:%s" ,     /* must scan all */
01355                       &b1,&b2,&b3,&b4,&b5 , fname ) ;   /* six items OK  */
01356 
01357          /** if have all 6 3D: items, then make a 3D: prefix for output **/
01358 
01359          if( ig == 6 ){
01360             sprintf(fpre , "%s:%d:%d:%d:%d:%d:" , prefix,b1,b2,b3,b4,b5) ;
01361             lpre = strlen(fpre) ;
01362          } else {
01363             ig = 0 ;
01364          }
01365       }
01366 
01367       if( strlen(fn) > 9 && fn[0] == '3' && fn[1] == 'A' && fn[3] == ':' ){
01368          ib = 0 ;
01369          prefix[ib++] = '3' ;
01370          prefix[ib++] = 'A' ;
01371          prefix[ib++] = fn[2] ;
01372          prefix[ib++] = '\0' ;
01373 
01374          ig = sscanf( fn+ib , "%d:%d:%d:%s" ,  /* must scan all */
01375                       &b1,&b2,&b3, fname ) ;   /* four items OK */
01376 
01377          /** if have all 4 3A: items, then make a 3A: prefix for output **/
01378 
01379          if( ig == 4 ){
01380             sprintf(fpre , "%s:%d:%d:%d:" , prefix,b1,b2,b3) ;
01381             lpre = strlen(fpre) ;
01382          } else {
01383             ig = 0 ;
01384          }
01385       }
01386 
01387       if( ig > 0 ) (void) glob( fname , 0 , NULL ,  &gl ) ;  /* 3D: was OK */
01388       else         (void) glob( fn    , 0 , NULL ,  &gl ) ;  /*     not OK */
01389 
01390       /** put each matched string into the output array **/
01391 
01392       if( gl.gl_pathc > 0 ){
01393 
01394          /** make space for output now **/
01395          gold  = gnum ;
01396          gnum += gl.gl_pathc ;
01397          if( gout == NULL ) gout = (char **) malloc (      sizeof(char *)*gnum);
01398          else               gout = (char **) realloc(gout, sizeof(char *)*gnum);
01399 
01400          for( ib=0 ; ib < gl.gl_pathc ; ib++ ){
01401             ilen = strlen( gl.gl_pathv[ib] ) + 1 ;  /* length of this name */
01402             if( ig > 0 ) ilen += lpre ;             /* plus 3D: prefix?    */
01403 
01404             gout[ib+gold] = (char *) malloc( sizeof(char) * ilen ) ; /* output! */
01405 
01406             if( ig > 0 ){
01407                strcpy( gout[ib+gold] , fpre ) ;             /* 3D: prefix */
01408                strcat( gout[ib+gold] , gl.gl_pathv[ib] ) ;  /* then name  */
01409             }
01410             else {
01411                strcpy( gout[ib+gold] , gl.gl_pathv[ib] ) ;  /* just name */
01412             }
01413          }
01414 
01415       } else if( ig == 6 && strcmp(fname,"ALLZERO") == 0 ){ /* 06 Mar 2001 */
01416 
01417          gold = gnum ; gnum++ ;
01418          if( gout == NULL ) gout = (char **) malloc (      sizeof(char *)*gnum);
01419          else               gout = (char **) realloc(gout, sizeof(char *)*gnum);
01420 
01421          ilen = lpre + strlen(fname) + 1 ;
01422          gout[gold] = (char *) malloc( sizeof(char) * ilen ) ; /* output! */
01423          strcpy( gout[gold] , fpre ) ;
01424          strcat( gout[gold] , fname ) ;
01425 
01426       } else {  /* 30 Apr 2001 */
01427 
01428          if( warn )  /* 13 Jul 2001 - print only if told to do so */
01429            fprintf(stderr,"** Can't find file %s\n", (ig>0) ? fname : fn ) ;
01430       }
01431 
01432       globfree( &gl ) ;
01433    }
01434 
01435    *nout = gnum ; *fout = gout ; return ;
01436 }

void MCW_free_expand int    gnum,
char **    gout
 

make space for output now *

Definition at line 1438 of file Ifile.c.

References free.

01439 {
01440    int ii ;
01441 
01442    if( gout == NULL ) return ;
01443 
01444    for( ii=0 ; ii < gnum ; ii++ ) free( gout[ii] ) ;
01445    free( gout ) ;
01446    return ;
01447 }

void MCW_warn_expand int    www
 

Definition at line 1303 of file Ifile.c.

01303 { warn = www; return; }

void NIH_glob char *    fn,
int *    nout,
char ***    fout
 

Definition at line 1314 of file Ifile.c.

References fout, and MCW_file_expand().

01315 {
01316    MCW_file_expand( 1 , &fn , nout , fout ) ;
01317 }

void NIH_glob_free int    gnum,
char **    gout
 

Definition at line 1319 of file Ifile.c.

References MCW_free_expand().

01320 {
01321    MCW_free_expand( gnum , gout ) ;
01322 }

DIR* Opendir str    [static]
 

void swap_2 void *    ppp [static]
 

Swap the 2 bytes pointed to by ppp: ab -> ba.

Definition at line 1480 of file Ifile.c.

01481 {
01482    unsigned char *pntr = (unsigned char *) ppp ;
01483    unsigned char b0, b1;
01484 
01485    b0 = *pntr; b1 = *(pntr+1);
01486    *pntr = b1; *(pntr+1) = b0;
01487 }

void swap_4 void *    ppp [static]
 

Swap the 4 bytes pointed to by ppp: abcd -> dcba.

Definition at line 1454 of file Ifile.c.

01455 {
01456    unsigned char *pntr = (unsigned char *) ppp ;
01457    unsigned char b0, b1, b2, b3;
01458 
01459    b0 = *pntr; b1 = *(pntr+1); b2 = *(pntr+2); b3 = *(pntr+3);
01460    *pntr = b3; *(pntr+1) = b2; *(pntr+2) = b1; *(pntr+3) = b0;
01461 }

void swap_8 void *    ppp [static]
 

Swap the 8 bytes pointed to by ppp: abcdefgh -> hgfedcba.

Definition at line 1465 of file Ifile.c.

01466 {
01467    unsigned char *pntr = (unsigned char *) ppp ;
01468    unsigned char b0, b1, b2, b3;
01469    unsigned char b4, b5, b6, b7;
01470 
01471    b0 = *pntr    ; b1 = *(pntr+1); b2 = *(pntr+2); b3 = *(pntr+3);
01472    b4 = *(pntr+4); b5 = *(pntr+5); b6 = *(pntr+6); b7 = *(pntr+7);
01473 
01474    *pntr     = b7; *(pntr+1) = b6; *(pntr+2) = b5; *(pntr+3) = b4;
01475    *(pntr+4) = b3; *(pntr+5) = b2; *(pntr+6) = b1; *(pntr+7) = b0;
01476 }

time_t THD_file_mtime char *    pathname
 

Return the time at which the file was last modified.

Definition at line 467 of file Ifile.c.

Referenced by main().

00468 {
00469    static struct stat buf ; int ii ;
00470 
00471    if( pathname == NULL ) return 0 ;
00472    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00473    return buf.st_mtime ;
00474 }

long THD_filesize char *    pathname
 

Return the file length (0 if file not found).

Definition at line 499 of file Ifile.c.

00500 {
00501    static struct stat buf ; int ii ;
00502 
00503    if( pathname == NULL ) return -1 ;
00504    ii = stat( pathname , &buf ) ; if( ii != 0 ) return -1 ;
00505    return buf.st_size ;
00506 }

int THD_is_directory char *    pathname
 

Determine if this is really a directory or not.

Definition at line 510 of file Ifile.c.

Referenced by adwarp_refashion_dataset(), AFNI_finalize_read_palette_CB(), AFNI_finalize_read_sess_CB(), AFNI_read_inputs(), AFNI_refashion_dataset(), main(), mpeg_setup(), mri_imcount_mpeg(), mri_read_mpeg(), NLFIT_get_all_MODELs(), NLFIT_get_many_MODELs(), PLUG_get_all_plugins(), PLUG_get_many_plugins(), T3D_check_data(), THD_extract_directories(), THD_get_all_filenames(), THD_get_many_timeseries(), THD_getpathprogs(), THD_init_session(), THD_mkdir(), and THD_write_datablock().

00511 {
00512    static struct stat buf ; int ii ;
00513 
00514    if( pathname == NULL ) return 0 ;
00515    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00516    ii = (buf.st_mode & S_IFDIR) != 0 ; return ii ;
00517 }

int THD_is_executable char *    pathname
 

Determine if this is really an executable file or not.

Definition at line 521 of file Ifile.c.

Referenced by THD_get_all_executables().

00522 {
00523    static struct stat buf ; int ii ;
00524 
00525    if( pathname == NULL ) return 0 ;
00526    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00527    ii = (buf.st_mode & S_IXOTH) != 0 ; return ii ;
00528 }

int THD_is_file char *    pathname
 

Determine if this is really a regular file or not.

Definition at line 478 of file Ifile.c.

00479 {
00480    static struct stat buf ; int ii ;
00481 
00482    if( pathname == NULL ) return 0 ;
00483    ii = stat( pathname , &buf ) ; if( ii != 0 ) return 0 ;
00484    ii = (buf.st_mode & S_IFREG) != 0 ; return ii ;
00485 }

int THD_is_symlink char *    pathname
 

Determine if this is really a symbolic link or not.

Definition at line 489 of file Ifile.c.

00490 {
00491    char buf[32] ; int ii ;
00492 
00493    ii = readlink( pathname , buf , 32 ) ;
00494    return (ii > 0) ;
00495 }

Variable Documentation

int ch
 

Definition at line 806 of file Ifile.c.

int flags
 

Definition at line 857 of file Ifile.c.

Referenced by AFNI_register_nD_function(), calculate_long_min_match(), Clp_AddStringListType(), Clp_AddStringListTypeVec(), Clp_AddType(), convert_start(), demux(), finish_string_list(), Gif_FullCompressImage(), Gif_FullWriteFile(), glob(), glutInit(), main(), mpeg2_header_slice_start(), my_fgets(), NI_read_columns(), nullslice_start(), picture_coding_ext(), sequence_display_ext(), sequence_ext(), THD_subbrick_to_niml(), and THD_write_minc().

int m_not
 

Definition at line 1237 of file Ifile.c.

Referenced by glob(), glob3(), and match().

int no_match
 

Definition at line 1097 of file Ifile.c.

Referenced by glob(), glob1(), glob2(), and glob3().

* pat
 

Definition at line 1236 of file Ifile.c.

Referenced by match(), THD_get_all_timeseries(), and THD_get_wildcard_filenames().

* patend
 

Definition at line 1236 of file Ifile.c.

Referenced by match().

* pathend
 

Definition at line 1095 of file Ifile.c.

Referenced by glob2(), and glob3().

* pattern
 

Definition at line 1095 of file Ifile.c.

glob_t * pglob
 

Definition at line 1192 of file Ifile.c.

Referenced by glob(), glob1(), glob2(), glob3(), globextend(), and globfree().

q
 

Definition at line 836 of file Ifile.c.

Referenced by _dl_search_paths(), aawalk(), AFNI_niml_redisplay_CB(), AFNI_niml_viewpoint_CB(), afwalk(), allocate_memory(), argsort(), autovar(), axis_to_quat(), bad_dimtype(), basis_block4(), basis_block5(), basis_cos(), basis_expr(), basis_gam(), basis_legendre(), basis_one(), basis_sin(), basis_spmg1(), basis_spmg2(), basis_tent(), beta_p2t(), beta_t2p(), betadf(), bgrat(), binomial_p2t(), binomial_t2p(), bisect_(), bqr_(), calc_freg(), calculate_results(), cdfbet(), cdfbin(), cdfchi(), cdfchn(), cdff(), cdffnc(), cdfgam(), cdfnbn(), cdfnor(), cdfpoi(), cdft(), changedtype(), check_for_valid_inputs(), chisq_p2t(), chisq_t2p(), cl1_fort(), cl1_solve(), cl1_solve_res(), compare(), copyData(), count_args(), csfft_nextup(), cumnor(), DC_IRF(), DCM_GetElementValue(), DCM_GetElementValueOffset(), dim_check(), dim_finish(), dinvnr(), dobss(), docommon(), doentry(), doiolist(), donmlist(), dt1(), dtree_insert_at_node(), dtree_unlink_node(), duparg(), E0001(), entrypt(), erf1(), erfc1(), exassign(), fixargs(), fixexpr(), fold(), frdata(), free(), freetemps(), frexpr(), fstat_p2t(), fstat_t2p(), fstat_t2pp(), gam1(), gaminv(), gamma_p2t(), gamma_t2p(), getcds(), glob2(), glt_analysis(), grat1(), hidden_NI_realloc(), hqr2_(), hqr_(), iarrlen(), identify_repeats(), imagpart(), incbeta(), incbeta_inverse(), init_delay(), init_indep_var_matrix(), init_regression_analysis(), initialize(), initialize_filters(), Inline(), intraddr(), intrcall(), iochan_enable_perror(), lnbeta(), make_param(), mallkey(), malloc(), mkconv(), mkfunct(), mkpower(), mktmpn(), namelist(), nextdata(), normal_p2t(), normal_t2p(), normalize_quat(), nsubs(), opconv(), out_call(), output_results(), permute_dfvec3(), permute_dmat33(), pmodel_cdf(), pmodel_pdf(), poisson_p2t(), poisson_t2p(), prolog(), putch1(), putconst(), putct1(), putcx1(), putcxcmp(), putio(), putiocall(), qmedmad_float(), qzvec_(), ratqr_(), RCREND_cutout_blobs(), RCREND_rotmatrix(), RCREND_rotmatrix_to_angles(), read_input_data(), realloc(), realpart(), regression_analysis(), REND_cutout_blobs(), REND_rotmatrix(), REND_rotmatrix_to_angles(), report_results(), rot_matrix(), rot_to_matrix(), rot_to_shear(), rot_to_shear_matvec(), rotmatrix(), setbound(), shear_arb(), shear_best(), shear_xzyx(), stfcall(), SUMA_build_rotmatrix(), SUMA_Chung_Smooth_Weights(), SUMA_dPoint_At_Distance(), SUMA_mattoquat(), SUMA_Point_At_Distance(), SUMA_THD_handedness(), tcp_connect(), tcp_listen(), teapot(), THD_handedness(), THD_matrix_to_orientation(), threshold_data(), tinvit_(), trackball(), trackball_Phi(), tridib_(), trn32s_(), tross_Dont_Encode_Slash(), tsturm_(), unamstring(), warper_affine_for(), warper_affine_inv(), warper_bilinear_for(), warper_bilinear_inv(), warper_shift_for(), warper_shift_inv(), wavelet_analysis(), write_bucket_data(), and Xgamm().

* restpattern
 

Definition at line 1095 of file Ifile.c.

Referenced by glob3().

struct stat* sb
 

Definition at line 782 of file Ifile.c.

Referenced by addto_Dtable(), AFNI_hintize_pbar(), blksize(), DC_init_im_col(), DC_spectrum_AJJ(), DRAW_fillin_CB(), DRAW_into_dataset(), DRAW_redo_CB(), DRAW_undo_CB(), fgrow(), ISQ_plot_label(), ISQ_set_barhint(), listize_Dtable(), process_args(), PV2S_check_surfaces(), r_INT_cb_fill(), RCREND_rotmatrix_to_angles(), REND_rotmatrix_to_angles(), scroll_topbot(), sortIt(), Stat(), and SUMA_usage().

 

Powered by Plone

This site conforms to the following standards: