#include "niml.h" static NI_stream nsafni ; /******************* Dial up AFNI on the local system. ********************/ void talk_to_afni_init( void ) { nsafni = NI_stream_open( "tcp:localhost:53211" , "w" ) ; } /****** Check if connection to AFNI is good. Returns: -1 means it is irrevocably dead. 0 means it isn't good yet, but we're still waiting. 1 means it is alive and well. Will wait up to 5 ms to see if AFNI has accepted connection. ******/ int talk_to_afni_checkup( void ) { return NI_stream_goodcheck( nsafni , 5 ) ; } /********** Send a data element to AFNI. Returns: -1 means connection to AFNI has died. 0 means connection to AFNI didn't connect yet. > 0 means this many bytes were sent to AFNI. **********/ int send_to_afni( NI_element *nel ) { int nn ; nn = NI_stream_writecheck( nsafni , 5 ) ; /* check if stream is */ if( nn <= 0 ) return nn ; /* OK for writing */ nn = NI_write_element( nsafni , nel , NI_TEXT_MODE ) ; /* write! */ return nn ; }