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  

1dsum.c File Reference

#include "mrilib.h"

Go to the source code of this file.


Defines

#define MAXIM   1024

Functions

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

Define Documentation

#define MAXIM   1024
 

Definition at line 3 of file 1dsum.c.


Function Documentation

int main int    argc,
char *    argv[]
 

convert three sub-briks to a raw dataset with consecutive triplets

Definition at line 7 of file 1dsum.c.

References argc, far, machdep(), malloc, MRI_FLOAT_PTR, mri_read_1D(), ncol, MRI_IMAGE::nx, MRI_IMAGE::ny, and strtod().

00008 {
00009    int nim , ii , jj , kk , nx ;
00010    MRI_IMAGE ** inim ;
00011    float * far ;
00012    int ncol , ic ;
00013    float * csum ;
00014    int nn_ignore=0 , mm_use=0 , iarg=1 ;
00015 
00016    /*-- help? --*/
00017 
00018    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00019      printf("Usage: 1dsum [options] a.1D b.1D ...\n"
00020             "where each file a.1D, b.1D, etc. is an ASCII file of numbers arranged\n"
00021             "in rows and columns. The sum of each column is written to stdout.\n"
00022             "\n"
00023             "Options:\n"
00024             "  -ignore nn = skip the first nn rows of each file\n"
00025             "  -use    mm = use only mm rows from each file\n"
00026            ) ;
00027       exit(0) ;
00028    }
00029 
00030    machdep() ;
00031 
00032    /* parse options */
00033 
00034    while( iarg < argc && argv[iarg][0] == '-' ){
00035 
00036       if( strncmp(argv[iarg],"-ignore",4) == 0 ){
00037          nn_ignore = (int) strtod(argv[++iarg],NULL) ;
00038          if( nn_ignore < 0 ){fprintf(stderr,"** Illegal -ignore value!\n");exit(1);}
00039          iarg++ ; continue ;
00040       }
00041 
00042       if( strncmp(argv[iarg],"-use",4) == 0 ){
00043          mm_use = (int) strtod(argv[++iarg],NULL) ;
00044          if( mm_use < 0 ){fprintf(stderr,"** Illegal -use value!\n");exit(1);}
00045          iarg++ ; continue ;
00046       }
00047 
00048       fprintf(stderr,"** Unknown option: %s\n",argv[iarg]) ; exit(1) ;
00049    }
00050 
00051    /* read input files */
00052 
00053    nim = argc-iarg ;
00054    inim = (MRI_IMAGE **) malloc( sizeof(MRI_IMAGE *) * nim ) ;
00055    ncol = 0 ;
00056    for( jj=0 ; jj < nim ; jj++ ){
00057       inim[jj] = mri_read_1D( argv[jj+iarg] ) ;
00058       if( inim[jj] == NULL ){
00059          fprintf(stderr,"** Can't read input file %s\n",argv[jj+iarg]) ;
00060          exit(1) ;
00061       }
00062       if( jj > 0 && inim[jj]->nx != inim[0]->nx ){
00063          fprintf(stderr,
00064                  "** Input file %s doesn't match first file %s in length!\n",
00065                  argv[jj+iarg],argv[iarg]) ;
00066          exit(1) ;
00067       }
00068       ncol += inim[jj]->ny ;
00069    }
00070 
00071    if( mm_use == 0 ){
00072       mm_use = inim[0]->nx - nn_ignore ;
00073       if( mm_use < 0 ){fprintf(stderr,"** -ignore is too big for these files!\n");exit(1);}
00074    }
00075    if( nn_ignore + mm_use > inim[0]->nx ){
00076       fprintf(stderr,"** -ignore + -use is too big for these files!\n");exit(1);
00077    }
00078 
00079    csum = (float *) malloc(sizeof(float)*ncol) ;
00080    for( ic=0 ; ic < ncol ; ic++ ) csum[ic] = 0.0 ;
00081 
00082    nx = inim[0]->nx ;
00083    for( ii=nn_ignore ; ii < nn_ignore+mm_use ; ii++ ){
00084       for( ic=jj=0 ; jj < nim ; jj++ ){
00085          far = MRI_FLOAT_PTR(inim[jj]) ;
00086          for( kk=0 ; kk < inim[jj]->ny ; kk++ ) csum[ic++] += far[ii+kk*nx] ;
00087       }
00088    }
00089 
00090    for( ic=0 ; ic < ncol ; ic++ ) printf("%g ",csum[ic]) ;
00091    printf("\n");
00092    exit(0) ;
00093 }
 

Powered by Plone

This site conforms to the following standards: