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  

jp_afni.h File Reference

#include "iochan.h"

Go to the source code of this file.


Defines

#define AFNI_SIGNA_KECK
#define AFNI_CONTROL_PORT   7954
#define AFNI_TCP_PORT   7953
#define AFNI_OPEN_CONTROL_MODE   1
#define AFNI_WAIT_CONTROL_MODE   2
#define AFNI_OPEN_DATA_MODE   3
#define AFNI_CATCHUP_MODE   4
#define AFNI_CONTINUE_MODE   5
#define RSH   "rsh"

Functions

int read_Signa_cvs ()
void AFNI_start_io (int)
void AFNI_send_image (int)
void AFNI_exit (void)

Variables

int AFNI_mode
int AFNI_use_tcp
char AFNI_host []
char AFNI_iochan []
IOCHANAFNI_ioc
char AFNI_buf []
int AFNI_atexit_setup
char AFNI_infocom []
int AFNI_verbose

Define Documentation

#define AFNI_CATCHUP_MODE   4
 

Definition at line 26 of file jp_afni.h.

#define AFNI_CONTINUE_MODE   5
 

Definition at line 27 of file jp_afni.h.

#define AFNI_CONTROL_PORT   7954
 

Definition at line 20 of file jp_afni.h.

#define AFNI_OPEN_CONTROL_MODE   1
 

Definition at line 23 of file jp_afni.h.

#define AFNI_OPEN_DATA_MODE   3
 

Definition at line 25 of file jp_afni.h.

#define AFNI_SIGNA_KECK
 

Definition at line 14 of file jp_afni.h.

#define AFNI_TCP_PORT   7953
 

Definition at line 21 of file jp_afni.h.

#define AFNI_WAIT_CONTROL_MODE   2
 

Definition at line 24 of file jp_afni.h.

#define RSH   "rsh"
 

Definition at line 92 of file jp_afni.h.


Function Documentation

void AFNI_exit void   
 

Definition at line 14 of file ep_afni.c.

References iochan_close(), iochan_sleep(), pid_fork, and use_fork.

00015 {                                      /* the AFNI data channels get closed. */
00016    iochan_close(AFNI_ioc) ;
00017    return ;
00018 }

void AFNI_send_image int    nim
 

send image in imX[nim] to AFNI *

Definition at line 174 of file ep_afni.c.

References AFNI_infobuf, imX, IOCHAN_CLOSE, iochan_sendall(), iochan_sleep(), iochan_writecheck(), SHM_IOCHAN, and use_fork.

Referenced by AFNI_start_io().

00175 {
00176    int lx = imX[nim].x , ly = imX[nim].y , nbytes = 2*lx*ly , soff , jj ;
00177 
00178    if( AFNI_mode != AFNI_CONTINUE_MODE ) return ;
00179 
00180    if ( (lx*ly) == 65536 ) soff = OFFSET;  /* for Signa */
00181    else                    soff = 0;
00182 
00183    /** before very 1st image, send data type and matrix size **/
00184 
00185    if( nim == 0 ){
00186       if( AFNI_verbose ) fprintf(stderr,"Sending 1st info+image to AFNI.\n") ;
00187       sprintf( AFNI_buf , "DATUM short\nXYMATRIX %d %d\n" , lx,ly ) ;
00188       iochan_sendall( AFNI_ioc , AFNI_buf , strlen(AFNI_buf)+1 ) ;
00189    } else if( AFNI_verbose ){
00190       fprintf(stderr,"Sending image %d to AFNI.\n",nim+1) ;
00191    }
00192 
00193    jj = iochan_sendall( AFNI_ioc , imX[nim].arr + soff , nbytes ) ;
00194 
00195    /** if the data channel failed, stop **/
00196 
00197    if( jj < 0 ){
00198       fprintf(stderr,"Image transmission to AFNI fails at #%d.\a\n",nim) ;
00199       IOCHAN_CLOSE(AFNI_ioc) ;
00200       AFNI_mode = 0 ;
00201    }
00202 
00203    return ;
00204 }

void AFNI_start_io int   
 

Definition at line 41 of file ep_afni.c.

References AFNI_send_image(), iochan_clearcheck(), IOCHAN_CLOSE, iochan_init(), iochan_sendall(), iochan_sleep(), and iochan_writecheck().

00042 {
00043    int ii , jj ;
00044 
00045    /***** Check for illegal conditions *****/
00046 
00047    if( AFNI_mode <= 0 || AFNI_mode == AFNI_CONTINUE_MODE ) return ;
00048 
00049    /***** If we are at the first time in,
00050           try to open a control socket to talk to AFNI *****/
00051 
00052    if( AFNI_mode == AFNI_OPEN_CONTROL_MODE ){
00053 
00054       sprintf( AFNI_iochan , "tcp:%s:%d" , AFNI_host , AFNI_CONTROL_PORT ) ;
00055 
00056       if( AFNI_verbose )
00057          fprintf(stderr,"Opening control channel %s to AFNI.\n",AFNI_iochan) ;
00058 
00059       AFNI_ioc = iochan_init( AFNI_iochan , "w" ) ;
00060 
00061       if( AFNI_ioc == NULL ){
00062          fprintf(stderr,"Can't open control channel %s to AFNI!\a\n",AFNI_iochan) ;
00063          AFNI_mode = 0 ;                       /* disable AFNI */
00064          return ;
00065       } else {
00066          if( AFNI_verbose ) fprintf(stderr,"Entering AFNI_WAIT_CONTROL_MODE.\n") ;
00067          AFNI_mode = AFNI_WAIT_CONTROL_MODE ;  /* begin waiting for AFNI connection */
00068       }
00069    }
00070 
00071    /***** Check if the control socket is connected to AFNI *****/
00072 
00073    if( AFNI_mode == AFNI_WAIT_CONTROL_MODE ){
00074 
00075       ii = iochan_writecheck( AFNI_ioc , 1 ) ;  /* Check; wait at most 1 msec */
00076 
00077       /** if ii == 0, then the channel is still pending,
00078           so do nothing; otherwise, take some action.    **/
00079 
00080       if( ii < 0 ){
00081          fprintf(stderr,"Control channel to AFNI failed!\a\n") ;
00082          IOCHAN_CLOSE(AFNI_ioc) ;
00083          AFNI_mode = 0 ;                    /* disable AFNI */
00084          return ;
00085       } else if( ii > 0 ){
00086          if( AFNI_verbose ) fprintf(stderr,"Control channel connected to AFNI."
00087                                            "  Entering AFNI_OPEN_DATA_MODE.\n") ;
00088          AFNI_mode = AFNI_OPEN_DATA_MODE ;  /* prepare to send data to AFNI */
00089       }
00090    }
00091 
00092    /***** Send the control information, which says
00093           how we will talk to AFNI in the future (shmem or TCP/IP),
00094           then close the control channel and open this new data channel *****/
00095 
00096    if( AFNI_mode == AFNI_OPEN_DATA_MODE ){
00097 
00098       /* decide name of data channel: it can be TCP/IP or shared memory */
00099 
00100       if( AFNI_use_tcp ) sprintf(AFNI_iochan,"tcp:%s:%d",AFNI_host,AFNI_TCP_PORT) ;
00101       else               strcpy(AFNI_iochan,"shm:eps:1M") ;
00102 
00103       strcpy(AFNI_buf,AFNI_iochan) ;     /* tell AFNI where to read data */
00104       if( AFNI_infocom[0] != '\0' ){
00105          strcat(AFNI_buf,"\n") ;
00106          strcat(AFNI_buf,AFNI_infocom) ; /* tell it where to get 3T info */
00107       }
00108 
00109       if( AFNI_verbose )
00110          fprintf(stderr,"Sending control information to AFNI:\n%s\n",AFNI_buf) ;
00111 
00112       ii = iochan_sendall( AFNI_ioc , AFNI_buf , strlen(AFNI_buf)+1 ) ;
00113 
00114       /** A negative return is bad news **/
00115 
00116       if( ii < 0 ){
00117          fprintf(stderr,"Transmission of control data to AFNI failed!\a\n") ;
00118          IOCHAN_CLOSE(AFNI_ioc) ;
00119          AFNI_mode = 0 ;
00120          return ;
00121       } else {
00122          while( ! iochan_clearcheck(AFNI_ioc,2) ) /* wait for control data to clear */
00123             iochan_sleep(2) ;
00124          IOCHAN_CLOSE(AFNI_ioc) ;                 /* close control channel */
00125 
00126          if( AFNI_verbose )
00127             fprintf(stderr,"Opening data channel %s to AFNI.\n",AFNI_iochan) ;
00128 
00129          AFNI_ioc = iochan_init( AFNI_iochan , "w" ) ; /* open data channel */
00130          if( AFNI_ioc == NULL ){
00131             fprintf(stderr,"Can't open data channel %s to AFNI!\a\n",AFNI_iochan) ;
00132             AFNI_mode = 0 ;
00133             return ;
00134          } else {
00135             if( AFNI_verbose ) fprintf(stderr,"Entering AFNI_CATCHUP_MODE.\n") ;
00136             AFNI_mode = AFNI_CATCHUP_MODE ;
00137          }
00138       }
00139    }
00140 
00141    /***** Wait for the data channel to be connected to AFNI,
00142           and then send any images that are reconstructed and ready to go *****/
00143 
00144    if( AFNI_mode == AFNI_CATCHUP_MODE ){
00145 
00146       ii = iochan_writecheck( AFNI_ioc , 1 ) ;  /* wait at most 1 msec */
00147       if( ii < 0 ){
00148          fprintf(stderr,"AFNI data channel aborted before any data was sent!\a\n") ;
00149          IOCHAN_CLOSE( AFNI_ioc ) ;
00150          AFNI_mode = 0 ;
00151          return ;
00152       } else if( ii > 0 ){                      /* can now send data to AFNI! */
00153          if( AFNI_verbose )
00154             fprintf(stderr,"AFNI data channel %s is connected.\n"
00155                            "Entering AFNI_CONTINUE_MODE.\n" , AFNI_iochan) ;
00156          AFNI_mode = AFNI_CONTINUE_MODE ;
00157 
00158          /* if there are any images already accumulated, send them now! */
00159 
00160          if( nim > 0 && AFNI_verbose )
00161             fprintf(stderr,"Playing AFNI catchup with %d images.\n",nim) ;
00162 
00163          for( ii=0 ; ii < nim ; ii++ ) AFNI_send_image( ii ) ;
00164       }
00165    }
00166 
00167    return ;
00168 }

int read_Signa_cvs  
 

Referenced by AFNI_start_io().


Variable Documentation

int AFNI_atexit_setup
 

Definition at line 54 of file jp_afni.h.

char AFNI_buf[]
 

Definition at line 53 of file jp_afni.h.

Referenced by AFNI_start_io().

char AFNI_host[]
 

Definition at line 50 of file jp_afni.h.

Referenced by AFNI_start_io(), and main().

char AFNI_infocom[]
 

Definition at line 55 of file jp_afni.h.

Referenced by AFNI_start_io().

IOCHAN* AFNI_ioc
 

Definition at line 52 of file jp_afni.h.

char AFNI_iochan[]
 

Definition at line 51 of file jp_afni.h.

Referenced by AFNI_start_io().

int AFNI_mode
 

Definition at line 48 of file jp_afni.h.

Referenced by AFNI_start_io(), and main().

int AFNI_use_tcp
 

Definition at line 49 of file jp_afni.h.

Referenced by main().

int AFNI_verbose
 

Definition at line 56 of file jp_afni.h.

Referenced by main().

 

Powered by Plone

This site conforms to the following standards: