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  

1dnorm.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #include "mrilib.h"
00008 
00009 int main( int argc , char * argv[] )
00010 {
00011    MRI_IMAGE * inim ;
00012    int ii , jj , nx,ny , nopt;
00013    float * iar ;
00014    double sq ;
00015 
00016    /*-- help? --*/
00017 
00018    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00019      printf("Usage: 1dnorm infile outfile\n"
00020             "where infile is an AFNI *.1D file (ASCII list of numbers arranged\n"
00021             "in columns); outfile will be a similar file, with each column being\n"
00022             "L2 normalized.\n"
00023            ) ;
00024       exit(0) ;
00025    }
00026 
00027    machdep() ;
00028 
00029    nopt = 1 ;
00030    if( nopt+1 >= argc ){
00031       fprintf(stderr,"** Need input and output filenames!\n");exit(1);
00032    }
00033 
00034    if( argc > nopt+1 && !THD_filename_ok(argv[nopt+1]) ){
00035       fprintf(stderr,"** Illegal output filename!\n"); exit(1);
00036    }
00037    if( argc > nopt+1 && strcmp(argv[nopt+1],"-") != 0 && THD_is_file(argv[nopt+1]) ){
00038       fprintf(stderr,"** Output file already exists!\n"); exit(1);
00039    }
00040 
00041    /* read input file */
00042 
00043    inim = mri_read_1D( argv[nopt] ) ;
00044    if( inim == NULL ){
00045       fprintf(stderr,"** Can't read input file!\n"); exit(1);
00046    }
00047 
00048    nx = inim->nx ; ny = inim->ny ; iar = MRI_FLOAT_PTR(inim) ;
00049 
00050    for( jj=0 ; jj < ny ; jj++ ){
00051       sq = 0.0 ;
00052       for( ii=0 ; ii < nx ; ii++ ) sq += SQR(iar[ii+jj*nx]) ;
00053       if( sq > 0.0 ){
00054          sq = 1.0 / sq ;
00055          for( ii=0 ; ii < nx ; ii++ ) iar[ii+jj*nx] *= sq ;
00056       }
00057    }
00058 
00059    mri_write_1D( (argc > nopt+1) ? argv[nopt+1] : "-" , inim ) ;
00060    exit(0) ;
00061 }
 

Powered by Plone

This site conforms to the following standards: