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  

im2niml.c

Go to the documentation of this file.
00001 #include "mrilib.h"
00002 
00003 int main( int argc , char *argv[] )
00004 {
00005    MRI_IMARR *iar ;
00006    MRI_IMAGE *im ;
00007    NI_stream ns=NULL ;
00008    NI_element *nel ;
00009    int ii , iarg=1 ;
00010    int nb=0 ;
00011 
00012    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00013      printf("Usage: im2niml imagefile [imagefile ...]\n"
00014             "Converts the input image(s) to a text-based NIML element\n"
00015             "and writes the result to stdout.  Sample usage:\n"
00016             " aiv -p 4444 &\n"
00017             " im2niml zork.jpg | nicat tcp:localhost:4444\n"
00018             "-- Author: RW Cox.\n"
00019            ) ;
00020      exit(0) ;
00021    }
00022 
00023    ns = NI_stream_open( "stdout:" , "w" ) ;
00024    if( ns == NULL ) ERROR_exit("Can't open stdout?!") ;
00025    for( ; iarg < argc ; iarg++ ){
00026      iar = mri_read_file( argv[iarg] ) ;
00027      if( iar == NULL ){
00028        ERROR_message("Can't read file %s",argv[iarg]); continue;
00029      }
00030      for( ii=0 ; ii < IMARR_COUNT(iar) ; ii++ ){
00031        im = IMARR_SUBIM(iar,ii) ; nel = mri_to_niml(im) ; mri_free(im) ;
00032        if( nel == NULL ){
00033          ERROR_message("Can't process %s[%d]",argv[iarg],ii); continue;
00034        }
00035        nb += NI_write_element( ns , nel , NI_TEXT_MODE ) ;
00036        NI_free_element(nel) ;
00037      }
00038      FREE_IMARR(iar) ;
00039    }
00040    NI_stream_closenow(ns) ;
00041    INFO_message("Wrote %d bytes to stdout",nb) ;
00042    exit(0) ;
00043 }
 

Powered by Plone

This site conforms to the following standards: