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  

afni_driver.c

Go to the documentation of this file.
00001 #include "afni.h"
00002 #include <X11/keysym.h>
00003 
00004 /*******************************************************************
00005   Functions to drive AFNI user-interface stuff from plugouts, etc.
00006   These routines take as input strings, and then call the
00007   appropriate callbacks to simulate what happens when the user
00008   presses various buttons.
00009 ********************************************************************/
00010 
00011 static int AFNI_drive_rescan_controller( char *code ) ;
00012 static int AFNI_drive_switch_session( char *cmd ) ;
00013 static int AFNI_drive_switch_anatomy( char *cmd ) ;
00014 static int AFNI_drive_switch_function( char *cmd ) ;
00015 static int AFNI_drive_open_window( char *cmd ) ;
00016 static int AFNI_drive_close_window( char *cmd ) ;
00017 static int AFNI_drive_quit( char *cmd ) ;
00018 
00019 static int AFNI_drive_save_jpeg( char *cmd ) ;      /* 28 Jul 2005 */
00020 static int AFNI_drive_set_view( char *cmd ) ;       /* 28 Jul 2005 */
00021 static int AFNI_drive_set_dicom_xyz( char *cmd ) ;  /* 28 Jul 2005 */
00022 static int AFNI_drive_set_spm_xyz( char *cmd ) ;    /* 28 Jul 2005 */
00023 static int AFNI_drive_set_ijk( char *cmd ) ;        /* 28 Jul 2005 */
00024 static int AFNI_drive_set_xhairs( char *cmd ) ;     /* 28 Jul 2005 */
00025 
00026 static int AFNI_drive_system( char *cmd ) ;         /* 19 Dec 2002 */
00027 static int AFNI_drive_chdir ( char *cmd ) ;         /* 19 Dec 2002 */
00028 
00029 #ifdef ALLOW_PLUGINS
00030 static int AFNI_drive_open_plugin( char *cmd ) ;    /* 13 Nov 2001 */
00031 #endif
00032 
00033 static int AFNI_drive_open_graph_xy ( char *cmd ) ; /* 14 Nov 2001 */
00034 static int AFNI_drive_close_graph_xy( char *cmd ) ;
00035 static int AFNI_drive_clear_graph_xy( char *cmd ) ;
00036 static int AFNI_drive_addto_graph_xy( char *cmd ) ;
00037 
00038 static int AFNI_drive_open_graph_1D ( char *cmd ) ; /* 15 Nov 2001 */
00039 static int AFNI_drive_close_graph_1D( char *cmd ) ;
00040 static int AFNI_drive_clear_graph_1D( char *cmd ) ;
00041 static int AFNI_drive_addto_graph_1D( char *cmd ) ;
00042 
00043 static int AFNI_drive_geom_graph    ( char *cmd ) ; /* 16 Nov 2001 */
00044 
00045 static int AFNI_drive_add_overlay_color( char *cmd ) ; /* 16 Jan 2003 */
00046 static int AFNI_drive_set_threshold    ( char *cmd ) ; /* 16 Jan 2003 */
00047 static int AFNI_drive_set_threshnew    ( char *cmd ) ; /* 06 Feb 2004 */
00048 static int AFNI_drive_set_pbar_number  ( char *cmd ) ; /* 16 Jan 2003 */
00049 static int AFNI_drive_set_pbar_sign    ( char *cmd ) ; /* 17 Jan 2003 */
00050 static int AFNI_drive_set_pbar_all     ( char *cmd ) ; /* 17 Jan 2003 */
00051 static int AFNI_drive_pbar_rotate      ( char *cmd ) ; /* 17 Jan 2003 */
00052 static int AFNI_set_func_autorange     ( char *cmd ) ; /* 17 Jan 2003 */
00053 static int AFNI_set_func_range         ( char *cmd ) ; /* 21 Jan 2003 */
00054 static int AFNI_set_func_visible       ( char *cmd ) ; /* 21 Jan 2003 */
00055 static int AFNI_set_func_resam         ( char *cmd ) ; /* 21 Jan 2003 */
00056 static int AFNI_sleeper                ( char *cmd ) ; /* 22 Jan 2003 */
00057 static int AFNI_define_colorscale      ( char *cmd ) ; /* 03 Feb 2003 */
00058 static int AFNI_open_panel             ( char *cmd ) ; /* 05 Feb 2003 */
00059 static int AFNI_drive_purge_memory     ( char *cmd ) ; /* 09 Dec 2004 */
00060 static int AFNI_redisplay              ( char *cmd ) ;
00061 
00062 /*-----------------------------------------------------------------
00063   Drive AFNI in various (incomplete) ways.
00064   Return value is 0 if good, -1 if bad.
00065 -------------------------------------------------------------------*/
00066 
00067 typedef int dfunc(char *) ;
00068 
00069   /* function label from plugout, function pointer inside AFNI */
00070 
00071 typedef struct { char *nam; dfunc *fun; } AFNI_driver_pair ;
00072 
00073 static AFNI_driver_pair dpair[] = {
00074  { "RESCAN_THIS"      , AFNI_drive_rescan_controller } ,
00075 
00076  { "SET_SESSION"      , AFNI_drive_switch_session    } ,
00077  { "SWITCH_SESSION"   , AFNI_drive_switch_session    } ,
00078  { "SWITCH_DIRECTORY" , AFNI_drive_switch_session    } ,
00079 
00080  { "SET_ANATOMY"      , AFNI_drive_switch_anatomy    } ,
00081  { "SWITCH_ANATOMY"   , AFNI_drive_switch_anatomy    } ,
00082  { "SWITCH_UNDERLAY"  , AFNI_drive_switch_anatomy    } ,
00083  { "SET_UNDERLAY"     , AFNI_drive_switch_anatomy    } ,
00084 
00085  { "SET_FUNCTION"     , AFNI_drive_switch_function   } ,
00086  { "SWITCH_FUNCTION"  , AFNI_drive_switch_function   } ,
00087  { "SWITCH_OVERLAY"   , AFNI_drive_switch_function   } ,
00088  { "SET_OVERLAY"      , AFNI_drive_switch_function   } ,
00089 
00090  { "PURGE_MEMORY"     , AFNI_drive_purge_memory      } ,
00091 
00092  { "OPEN_WINDOW"      , AFNI_drive_open_window       } ,
00093  { "ALTER_WINDOW"     , AFNI_drive_open_window       } ,
00094  { "CLOSE_WINDOW"     , AFNI_drive_close_window      } ,
00095 
00096  { "SAVE_JPEG"        , AFNI_drive_save_jpeg         } ,
00097  { "SET_VIEW"         , AFNI_drive_set_view          } ,
00098  { "SET_DICOM_XYZ"    , AFNI_drive_set_dicom_xyz     } ,
00099  { "SET_SPM_XYZ"      , AFNI_drive_set_spm_xyz       } ,
00100  { "SET_IJK"          , AFNI_drive_set_ijk           } ,
00101  { "SET_XHAIRS"       , AFNI_drive_set_xhairs        } ,
00102  { "SET_CROSSHAIRS"   , AFNI_drive_set_xhairs        } ,
00103 
00104  { "OPEN_GRAPH_XY"    , AFNI_drive_open_graph_xy     } ,
00105  { "CLOSE_GRAPH_XY"   , AFNI_drive_close_graph_xy    } ,
00106  { "CLEAR_GRAPH_XY"   , AFNI_drive_clear_graph_xy    } ,
00107  { "ADDTO_GRAPH_XY"   , AFNI_drive_addto_graph_xy    } ,
00108 
00109  { "OPEN_GRAPH_1D"    , AFNI_drive_open_graph_1D     } ,
00110  { "CLOSE_GRAPH_1D"   , AFNI_drive_close_graph_1D    } ,
00111  { "CLEAR_GRAPH_1D"   , AFNI_drive_clear_graph_1D    } ,
00112  { "ADDTO_GRAPH_1D"   , AFNI_drive_addto_graph_1D    } ,
00113 
00114  { "SET_GRAPH_GEOM"   , AFNI_drive_geom_graph        } ,
00115 
00116  { "QUIT"             , AFNI_drive_quit              } ,
00117 
00118  { "SYSTEM"           , AFNI_drive_system            } ,
00119  { "CHDIR"            , AFNI_drive_chdir             } ,
00120 
00121  { "ADD_OVERLAY_COLOR"  , AFNI_drive_add_overlay_color } ,
00122  { "SET_THRESHOLD"      , AFNI_drive_set_threshold     } ,
00123  { "SET_THRESHNEW"      , AFNI_drive_set_threshnew     } ,
00124  { "SET_FUNC_THRESH"    , AFNI_drive_set_threshold     } ,
00125  { "SET_PBAR_NUMBER"    , AFNI_drive_set_pbar_number   } ,
00126  { "SET_PBAR_SIGN"      , AFNI_drive_set_pbar_sign     } ,
00127  { "SET_PBAR_ALL"       , AFNI_drive_set_pbar_all      } ,
00128  { "PBAR_ROTATE"        , AFNI_drive_pbar_rotate       } ,
00129  { "SET_FUNC_AUTORANGE" , AFNI_set_func_autorange      } ,
00130  { "SET_FUNC_RANGE"     , AFNI_set_func_range          } ,
00131  { "SET_FUNC_VISIBLE"   , AFNI_set_func_visible        } ,
00132  { "SEE_OVERLAY"        , AFNI_set_func_visible        } ,
00133  { "SET_FUNC_RESAM"     , AFNI_set_func_resam          } ,
00134  { "SLEEP"              , AFNI_sleeper                 } ,
00135  { "SETENV"             , AFNI_setenv                  } ,  /* external */
00136  { "DEFINE_COLORSCALE"  , AFNI_define_colorscale       } ,
00137  { "DEFINE_COLOR_SCALE" , AFNI_define_colorscale       } ,
00138  { "OPEN_PANEL"         , AFNI_open_panel              } ,
00139 
00140  { "REDISPLAY"          , AFNI_redisplay               } ,
00141  { "REDRAW"             , AFNI_redisplay               } ,
00142 
00143  { NULL , NULL } } ;
00144 
00145 /*----------------------------------------------------------------------*/
00146 
00147 int AFNI_driver( char *cmdd )
00148 {
00149    int clen , rval , ii , dd , dlen ;
00150    char *cmd , *dmd ;
00151 
00152 ENTRY("AFNI_driver") ;
00153 
00154    if( cmdd == NULL || *cmdd == '\0' ) RETURN(-1) ;  /* bad */
00155 
00156    dmd = cmd = strdup(cmdd) ; clen = strlen(cmd) ;
00157 
00158    /* skip leading blanks */
00159 
00160    for( ii=0 ; ii < clen ; ii++ )
00161       if( !isspace(cmd[ii]) ) break ;
00162 
00163    if( ii == clen ){ free(dmd); RETURN(-1); }  /* all blanks? */
00164 
00165    cmd += ii ; clen = strlen(cmd) ;
00166 
00167    /* 19 Dec 2002: trim trailing blanks */
00168 
00169    for( ii=clen-1 ; ii > 0 && isspace(cmd[ii]) ; ii-- )
00170      cmd[ii] = '\0' ;
00171 
00172    clen = strlen(cmd) ;
00173 
00174    /* scan dpair list for command */
00175 
00176    for( dd=0 ; dpair[dd].nam != NULL ; dd++ ){
00177 
00178       dlen = strlen(dpair[dd].nam) ;
00179       if( clen >= dlen                         &&
00180           strncmp(cmd,dpair[dd].nam,dlen) == 0   ){  /* found it */
00181 
00182          for( ii=dlen ; ii < clen ; ii++ )      /* skip blanks */
00183             if( !isspace(cmd[ii]) ) break ;     /* after command name */
00184 
00185          rval = dpair[dd].fun( cmd+ii ) ;       /* execute command */
00186          free(dmd) ; RETURN(rval) ;
00187       }
00188    }
00189 
00190    free(dmd) ; RETURN(-1) ;  /* not in the list */
00191 }
00192 
00193 /*---------------------------------------------------------------*/
00194 /*! Purge named dataset or all datasets from memory. */
00195 
00196 int AFNI_drive_purge_memory( char *cmd )  /* 09 Dec 2004 */
00197 {
00198    char dname[THD_MAX_NAME] ;
00199    THD_slist_find slf ;
00200    int ic ;
00201 
00202 ENTRY("AFNI_drive_purge_memory") ;
00203 
00204    if( *cmd == '\0' ){ AFNI_purge_dsets(1); RETURN(0); }
00205 
00206    /* get dataset name, truncate trailing blanks */
00207 
00208    MCW_strncpy( dname , cmd , THD_MAX_NAME ) ;
00209    for( ic=strlen(dname)-1 ; ic >= 0 ; ic-- )
00210      if( isspace(dname[ic]) || iscntrl(dname[ic]) ) dname[ic] = '\0' ;
00211      else break ;
00212 
00213    if( strlen(dname) == 0 ) RETURN(-1) ;
00214 
00215    /* find this dataset in current session of this controller */
00216 
00217    slf = THD_dset_in_sessionlist( FIND_PREFIX, dname, GLOBAL_library.sslist,-1 );
00218 
00219    if( slf.dset_index < 0 ){   /* 18 Mar 2005 */
00220      MCW_idcode idcode ;
00221      MCW_strncpy( idcode.str , dname , MCW_IDSIZE ) ;
00222      slf = THD_dset_in_sessionlist( FIND_IDCODE, &idcode,
00223                                     GLOBAL_library.sslist,-1 );
00224    }
00225 
00226    if( slf.sess_index >= 0 && slf.dset_index >= 0 ){
00227      THD_3dim_dataset **dss =
00228        GLOBAL_library.sslist->ssar[slf.sess_index]->dsset[slf.dset_index] ;
00229      for( ic=0 ; ic <= LAST_VIEW_TYPE ; ic++ ) PURGE_DSET( dss[ic] ) ;
00230      RETURN(0) ;
00231    }
00232 
00233    RETURN(-1) ;
00234 }
00235 
00236 /*---------------------------------------------------------------*/
00237 /*! Run a system() command. */
00238 
00239 int AFNI_drive_system( char *cmd )  /* 19 Dec 2002 */
00240 {
00241    return system( cmd ) ;
00242 }
00243 
00244 /*---------------------------------------------------------------*/
00245 /*! Change working directory. */
00246 
00247 int AFNI_drive_chdir( char *cmd )   /* 19 Dec 2002 */
00248 {
00249    return chdir( cmd ) ;
00250 }
00251 
00252 /*-----------------------------------------------------------------
00253   Convert a controller code ("A", etc.) to an index.
00254   * Returns -1 if the index is illegal.
00255   * Returns -1 if the next character in the code string is NOT
00256      a NUL or a '.' or a blank.
00257   * Note that a legal index might not have an active controller.
00258   * Controller #i is pointed to by GLOBAL_library.controllers[i],
00259     for i=0..MAX_CONTROLLERS-1; cf. AFNI_rescan_controller().
00260 -------------------------------------------------------------------*/
00261 
00262 int AFNI_controller_code_to_index( char *code )
00263 {
00264    int ic ;
00265 ENTRY("AFNI_controller_code_to_index") ;
00266    if( code    == NULL || *code   == '\0' ) RETURN(-1) ;
00267    if( code[1] != '\0' && code[1] != '.' && code[1] != ' ' ) RETURN(-1) ;
00268    ic = *code - 'A' ;
00269    if( ic < 0 || ic >= MAX_CONTROLLERS ) ic = -1 ;
00270    RETURN(ic) ;
00271 }
00272 
00273 /*-----------------------------------------------------------------
00274   Rescan a controller's current session for new datasets.
00275   Return value is 0 if good, -1 if bad.
00276 -------------------------------------------------------------------*/
00277 
00278 static int AFNI_drive_rescan_controller( char *code )
00279 {
00280    int ic ;
00281    Three_D_View *im3d ;
00282 
00283 ENTRY("AFNI_rescan_controller") ;
00284 
00285    ic = AFNI_controller_code_to_index( code ) ;
00286    if( ic < 0 ) ic = 0 ;                       /* default = A */
00287 
00288    im3d = GLOBAL_library.controllers[ic] ;
00289    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
00290 
00291    /* same callback as Rescan This */
00292 
00293    AFNI_rescan_CB( NULL , (XtPointer)im3d , NULL ) ;
00294    RETURN(0) ;
00295 }
00296 
00297 /*-----------------------------------------------------------------
00298   Switch to a new directory in a controller.
00299   Input is of the form "A.directoryname".
00300   Return value is 0 if good, -1 if bad.
00301 -------------------------------------------------------------------*/
00302 
00303 static int AFNI_drive_switch_session( char *cmd )
00304 {
00305    int ic , dadd=2 ;
00306    Three_D_View *im3d ;
00307    char dname[THD_MAX_NAME] ;
00308    MCW_choose_cbs cbs ;
00309 
00310 ENTRY("AFNI_switch_session") ;
00311 
00312    if( cmd == NULL || strlen(cmd) < 3 ) RETURN(-1) ;
00313 
00314    ic = AFNI_controller_code_to_index( cmd ) ;
00315    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
00316 
00317    im3d = GLOBAL_library.controllers[ic] ;
00318    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
00319 
00320    /* get session name, truncate trailing blanks */
00321 
00322    MCW_strncpy( dname , cmd+dadd , THD_MAX_NAME ) ;
00323    for( ic=strlen(dname)-1 ; ic >= 0 ; ic-- )
00324       if( isspace(dname[ic]) || iscntrl(dname[ic]) ) dname[ic] = '\0' ;
00325       else break ;
00326 
00327    if( strlen(dname) == 0 ) RETURN(-1) ;
00328 
00329    /* find session name in list of sessions (sloppy compare) */
00330 
00331    for( ic=0 ; ic < GLOBAL_library.sslist->num_sess ; ic++ )
00332       if( strstr(GLOBAL_library.sslist->ssar[ic]->sessname,dname) != NULL ) break;
00333 
00334    if( ic == GLOBAL_library.sslist->num_sess ) RETURN(-1) ;
00335 
00336    /* do the switcheroo: same callback as Switch Session */
00337 
00338    cbs.ival = ic ;
00339 
00340    AFNI_finalize_dataset_CB( im3d->vwid->view->choose_sess_pb ,
00341                              (XtPointer)im3d ,  &cbs          ) ;
00342 
00343    RETURN(0) ;
00344 }
00345 
00346 /*----------------------------------------------------------------------
00347   Set the anatomical dataset.  Input is of the form "A.prefix".
00348   Return value is 0 if good, -1 if bad.
00349 -------------------------------------------------------------------*/
00350 
00351 static int AFNI_drive_switch_anatomy( char *cmd )
00352 {
00353    int ic , dadd=2 ;
00354    Three_D_View *im3d ;
00355    char dname[THD_MAX_NAME] ;
00356    MCW_choose_cbs cbs ;
00357    THD_slist_find slf ;
00358 
00359 ENTRY("AFNI_switch_anatomy") ;
00360 
00361    if( cmd == NULL || strlen(cmd) < 3 ) RETURN(-1) ;
00362 
00363    ic = AFNI_controller_code_to_index( cmd ) ;
00364    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
00365 
00366    im3d = GLOBAL_library.controllers[ic] ;
00367    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
00368 
00369    /* get dataset name, truncate trailing blanks */
00370 
00371    MCW_strncpy( dname , cmd+dadd , THD_MAX_NAME ) ;
00372    for( ic=strlen(dname)-1 ; ic >= 0 ; ic-- )
00373      if( isspace(dname[ic]) || iscntrl(dname[ic]) ) dname[ic] = '\0' ;
00374      else break ;
00375 
00376    if( strlen(dname) == 0 ) RETURN(-1) ;
00377 
00378    /* find this dataset in current session of this controller */
00379 
00380    slf = THD_dset_in_session( FIND_PREFIX , dname , im3d->ss_now ) ;
00381 
00382    if( slf.dset_index < 0 ){   /* 18 Mar 2005 */
00383      MCW_idcode idcode ;
00384      MCW_strncpy( idcode.str , dname , MCW_IDSIZE ) ;
00385      slf = THD_dset_in_session( FIND_IDCODE , &idcode , im3d->ss_now ) ;
00386    }
00387 
00388    if( slf.dset_index < 0 ) RETURN(-1) ;
00389 
00390    cbs.ival = slf.dset_index ;
00391 
00392    /* same callback as Switch Anatomy */
00393 
00394    AFNI_finalize_dataset_CB( im3d->vwid->view->choose_anat_pb ,
00395                              (XtPointer)im3d ,  &cbs          ) ;
00396 
00397    RETURN(0) ;
00398 }
00399 
00400 /*----------------------------------------------------------------------
00401   Set the functional dataset.  Input is of the form "A.prefix".
00402   Return value is 0 if good, -1 if bad.
00403 -------------------------------------------------------------------*/
00404 
00405 static int AFNI_drive_switch_function( char *cmd )
00406 {
00407    int ic , dadd=2 ;
00408    Three_D_View *im3d ;
00409    char dname[THD_MAX_NAME] ;
00410    MCW_choose_cbs cbs ;
00411    THD_slist_find slf ;
00412 
00413 ENTRY("AFNI_switch_function") ;
00414 
00415    if( cmd == NULL || strlen(cmd) < 3 ) RETURN(-1) ;
00416 
00417    ic = AFNI_controller_code_to_index( cmd ) ;
00418    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
00419 
00420    im3d = GLOBAL_library.controllers[ic] ;
00421    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
00422 
00423    /* get dataset name, truncate trailing blanks */
00424 
00425    MCW_strncpy( dname , cmd+dadd , THD_MAX_NAME ) ;
00426    for( ic=strlen(dname)-1 ; ic >= 0 ; ic-- )
00427       if( isspace(dname[ic]) || iscntrl(dname[ic]) ) dname[ic] = '\0' ;
00428       else break ;
00429 
00430    if( strlen(dname) == 0 ) RETURN(-1) ;
00431 
00432    /* find this dataset in current session of this controller */
00433 
00434    slf = THD_dset_in_session( FIND_PREFIX , dname , im3d->ss_now ) ;
00435 
00436    if( slf.dset_index < 0 ){   /* 18 Mar 2005 */
00437      MCW_idcode idcode ;
00438      MCW_strncpy( idcode.str , dname , MCW_IDSIZE ) ;
00439      slf = THD_dset_in_session( FIND_IDCODE , &idcode , im3d->ss_now ) ;
00440    }
00441 
00442    if( slf.dset_index < 0 ) RETURN(-1) ;
00443 
00444    cbs.ival = slf.dset_index ;
00445 
00446    /* same callback as Switch Function */
00447 
00448    AFNI_finalize_dataset_CB( im3d->vwid->view->choose_func_pb ,
00449                              (XtPointer)im3d ,  &cbs          ) ;
00450 
00451    RETURN(0) ;
00452 }
00453 
00454 /*--------------------------------------------------------------------
00455   Open a window in the controller.
00456   Input is a string of the form A.sagittalimage, etc.
00457   Return value is 0 if good, -1 if bad.
00458 -------------------------------------------------------------------*/
00459 
00460 static int AFNI_drive_open_window( char *cmd )
00461 {
00462    int ic ;
00463    Three_D_View *im3d ;
00464    char *cpt ;
00465    int gww=-1,ghh=-1,gxx=-1,gyy=-1 ;
00466    MCW_imseq   *isq=NULL ;
00467    MCW_grapher *gra=NULL ;
00468 
00469 ENTRY("AFNI_drive_open_window") ;
00470 
00471    /* make sure the controller itself is open */
00472 
00473    ic = AFNI_controller_code_to_index( cmd ) ;
00474    if( ic < 0 ) ic = 0 ;
00475 
00476    im3d = GLOBAL_library.controllers[ic] ;
00477    if( !IM3D_VALID(im3d) ){                  /* try to create it */
00478       AFNI_make_controller( ic ) ;
00479       im3d = GLOBAL_library.controllers[ic] ;
00480       if( !IM3D_VALID(im3d) ) RETURN(-1) ;   /* should never happen */
00481    }
00482 
00483    if( !IM3D_OPEN(im3d) ){                   /* make sure is visible */
00484       OPEN_CONTROLLER(im3d) ;
00485       AFNI_initialize_controller( im3d ) ;   /* decide what to see */
00486       AFNI_initialize_view( NULL , im3d ) ;  /* set up to see it */
00487       AFNI_controller_clonify() ;
00488    }
00489 
00490    if( strlen(cmd) < 3 ) RETURN(0) ;         /* no commands? */
00491 
00492    /* 13 Nov 2001: plugins are done in a separate function */
00493 
00494 #ifdef ALLOW_PLUGINS
00495    if( strstr(cmd,"plugin.") != NULL ){
00496       ic = AFNI_drive_open_plugin( cmd ) ;
00497       RETURN(ic) ;
00498    }
00499 #endif
00500 
00501    /* open a graph or image window */
00502 
00503         if( strstr(cmd,"axialimage") != NULL ){
00504           AFNI_view_xyz_CB( im3d->vwid->imag->image_xyz_pb, im3d, NULL ) ;
00505           isq = im3d->s123 ;
00506 
00507    } else if( strstr(cmd,"sagittalimage") != NULL ){
00508           AFNI_view_xyz_CB( im3d->vwid->imag->image_yzx_pb, im3d, NULL ) ;
00509           isq = im3d->s231 ;
00510 
00511    } else if( strstr(cmd,"coronalimage") != NULL ){
00512           AFNI_view_xyz_CB( im3d->vwid->imag->image_zxy_pb, im3d, NULL ) ;
00513           isq = im3d->s312 ;
00514 
00515    } else if( strstr(cmd,"axialgraph") != NULL ){
00516           AFNI_view_xyz_CB( im3d->vwid->imag->graph_xyz_pb, im3d, NULL ) ;
00517           gra = im3d->g123 ;
00518 
00519    } else if( strstr(cmd,"sagittalgraph") != NULL ){
00520           AFNI_view_xyz_CB( im3d->vwid->imag->graph_yzx_pb, im3d, NULL ) ;
00521           gra = im3d->g231 ;
00522 
00523    } else if( strstr(cmd,"coronalgraph") != NULL ){
00524           AFNI_view_xyz_CB( im3d->vwid->imag->graph_zxy_pb, im3d, NULL ) ;
00525           gra = im3d->g312 ;
00526    }
00527    XmUpdateDisplay( im3d->vwid->top_shell ) ;
00528 
00529    /* find geom=..., if present */
00530 
00531    cpt = strstr(cmd,"geom=") ;
00532    if( cpt == NULL ) cpt = strstr(cmd,"geom:") ;
00533    if( cpt != NULL )
00534      AFNI_decode_geom( cpt+5 , &gww,&ghh,&gxx,&gyy ) ;
00535 
00536    /*--- opened an image viewer: maybe modify it ---*/
00537 
00538    if( isq != NULL ){
00539 
00540       /* geometry */
00541 
00542       if( gxx >= 0 && gyy >= 0 )
00543         XtVaSetValues( isq->wtop, XmNx, gxx, XmNy, gyy, NULL ) ;
00544       if( gww > 0 && ghh > 0 )
00545         XtVaSetValues( isq->wtop, XmNwidth, gww, XmNheight, ghh, NULL ) ;
00546 
00547       /* image fraction */
00548 
00549       cpt = strstr(cmd,"ifrac=") ;
00550       if( cpt == NULL ) cpt = strstr(cmd,"ifrac:") ;
00551       if( cpt != NULL ){
00552         float ifrac = strtod( cpt+6 , NULL ) ;
00553         if( ifrac >= FRAC_MIN && ifrac <= 1.0 )
00554           drive_MCW_imseq( isq, isqDR_setifrac, (XtPointer)(&ifrac) ) ;
00555       }
00556 
00557       /* montage */
00558 
00559       cpt = strstr(cmd,"mont=") ;
00560       if( cpt == NULL ) cpt = strstr(cmd,"mont:") ;
00561       if( cpt != NULL ){
00562         int mww=-1 , mhh=-1 , msp=-1 , mgap=-1 , nn ;
00563         char mcol[128] = "\0" ;
00564 
00565         nn = sscanf( cpt+5 , "%dx%d:%d:%d:%s" , &mww,&mhh,&msp,&mgap,mcol );
00566 
00567         if( nn >= 2 && mww >= 1 && mww <= MONT_NMAX && mhh >= 1 && mhh <= MONT_NMAX ){
00568           int mp[5] ;
00569           mp[0] = mww ; mp[1] = mhh ; mp[2] = msp ; mp[3] = mgap ;
00570           mp[4] = DC_find_overlay_color(im3d->dc,mcol);
00571           drive_MCW_imseq( isq , isqDR_setmontage , (XtPointer)mp ) ;
00572         }
00573       }
00574 
00575       /* iconify [06 Aug 2002] */
00576 
00577       cpt = strstr(cmd,"iconi") ;
00578       if( cpt != NULL ){
00579         XIconifyWindow( XtDisplay(isq->wtop) ,
00580                          XtWindow(isq->wtop)  ,
00581                          isq->dc->screen_num   ) ;
00582       }
00583 
00584       /* opacity [21 Jan 2003] */
00585 
00586       cpt = strstr(cmd,"opacity=") ;
00587       if( cpt == NULL ) cpt = strstr(cmd,"opacity:") ;
00588       if( cpt != NULL ){
00589         int opaval = -1 ;
00590         sscanf( cpt+8 , "%d" , &opaval ) ;
00591         drive_MCW_imseq( isq , isqDR_setopacity , (XtPointer)opaval ) ;
00592       }
00593 
00594       /* keypress [18 Feb 2005] */
00595 
00596       cpt = strstr(cmd,"keypress=") ;
00597       if( cpt == NULL ) cpt = strstr(cmd,"keypress:") ;
00598       if( cpt != NULL ){
00599         unsigned long key ;
00600         cpt += 9 ;
00601         if( *cpt == '\'' || *cpt == '\"' ) cpt++ ;
00602              if( strncmp(cpt,"XK_Left"     , 7) == 0 ) key = XK_Left     ;
00603         else if( strncmp(cpt,"XK_Right"    , 8) == 0 ) key = XK_Right    ;
00604         else if( strncmp(cpt,"XK_Down"     , 7) == 0 ) key = XK_Down     ;
00605         else if( strncmp(cpt,"XK_Up"       , 5) == 0 ) key = XK_Up       ;
00606         else if( strncmp(cpt,"XK_Page_Up"  ,10) == 0 ) key = XK_Page_Up  ;
00607         else if( strncmp(cpt,"XK_Page_Down",12) == 0 ) key = XK_Page_Down;
00608         else if( strncmp(cpt,"XK_Delete"   , 9) == 0 ) key = XK_Delete   ;
00609         else if( strncmp(cpt,"XK_Home"     , 7) == 0 ) key = XK_Home     ;
00610         else if( strncmp(cpt,"XK_F2"       , 5) == 0 ) key = XK_F2       ;
00611         else if( strncmp(cpt,"XK_F3"       , 5) == 0 ) key = XK_F3       ;
00612         else if( strncmp(cpt,"XK_F4"       , 5) == 0 ) key = XK_F4       ;
00613         else if( strncmp(cpt,"XK_F5"       , 5) == 0 ) key = XK_F5       ;
00614         else if( strncmp(cpt,"XK_F6"       , 5) == 0 ) key = XK_F6       ;
00615         else if( strncmp(cpt,"XK_F7"       , 5) == 0 ) key = XK_F7       ;
00616         else if( strncmp(cpt,"XK_F8"       , 5) == 0 ) key = XK_F8       ;
00617         else if( strncmp(cpt,"XK_F9"       , 5) == 0 ) key = XK_F9       ;
00618         else if( strncmp(cpt,"XK_F10"      , 6) == 0 ) key = XK_F10      ;
00619         else if( strncmp(cpt,"XK_F11"      , 6) == 0 ) key = XK_F11      ;
00620         else if( strncmp(cpt,"XK_F12"      , 6) == 0 ) key = XK_F12      ;
00621         else                                           key = *cpt        ;
00622         ISQ_handle_keypress( isq , key ) ;
00623       }
00624 
00625    /*--- opened a graph viewer: maybe modify it ---*/
00626 
00627    } else if( gra != NULL ){
00628 
00629       /* geometry */
00630 
00631       if( gxx >= 0 && gyy >= 0 )
00632         XtVaSetValues( gra->fdw_graph, XmNx, gxx, XmNy, gyy, NULL ) ;
00633       if( gww > 0 && ghh > 0 )
00634         XtVaSetValues( gra->fdw_graph, XmNwidth, gww, XmNheight, ghh, NULL ) ;
00635 
00636       /* matrix */
00637 
00638       cpt = strstr(cmd,"matrix=") ;
00639       if( cpt == NULL ) cpt = strstr(cmd,"matrix:") ;
00640       if( cpt != NULL ){
00641         int mat = (int) strtod( cpt+7 , NULL ) ;
00642         if( mat > 0 )
00643           drive_MCW_grapher( gra , graDR_setmatrix , (XtPointer)mat ) ;
00644       }
00645 
00646       /* pinnum OR pintop */
00647 
00648       cpt = strstr(cmd,"pinnum=") ;
00649       if( cpt == NULL ) cpt = strstr(cmd,"pinnum:") ;
00650       if( cpt == NULL ) cpt = strstr(cmd,"pintop=") ;
00651       if( cpt == NULL ) cpt = strstr(cmd,"pintop:") ;
00652       if( cpt != NULL ){
00653         int pn = (int) strtod( cpt+7 , NULL ) ;
00654         if( pn >= MIN_PIN )
00655           drive_MCW_grapher( gra, graDR_setpinnum, (XtPointer)pn ) ;
00656       }
00657 
00658       /* pinbot [19 Mar 2004] */
00659 
00660       cpt = strstr(cmd,"pinbot=") ;
00661       if( cpt == NULL ) cpt = strstr(cmd,"pinbot:") ;
00662       if( cpt != NULL ){
00663         int pn = (int) strtod( cpt+7 , NULL ) ;
00664         if( pn > 0 )
00665           drive_MCW_grapher( gra, graDR_setpinbot, (XtPointer)pn ) ;
00666       }
00667 
00668       /* iconify [06 Aug 2002] */
00669 
00670       cpt = strstr(cmd,"iconi") ;
00671       if( cpt != NULL ){
00672         XIconifyWindow( XtDisplay(gra->fdw_graph) ,
00673                          XtWindow(gra->fdw_graph)  ,
00674                          gra->dc->screen_num   ) ;
00675       }
00676 
00677       /* keypress [18 Feb 2005] */
00678 
00679       cpt = strstr(cmd,"keypress=") ;
00680       if( cpt == NULL ) cpt = strstr(cmd,"keypress:") ;
00681       if( cpt != NULL ){
00682         char buf[2] ;
00683         cpt += 9 ;
00684         if( *cpt == '\'' || *cpt == '\"' ) cpt++ ;
00685              if( strncmp(cpt,"XK_Left" ,7) == 0 ) buf[0] = '<'  ;
00686         else if( strncmp(cpt,"XK_Right",8) == 0 ) buf[0] = '>'  ;
00687         else if( strncmp(cpt,"XK_Down" ,7) == 0 ) buf[0] = 'Z'  ;
00688         else if( strncmp(cpt,"XK_Up"   ,5) == 0 ) buf[0] = 'z'  ;
00689         else                                      buf[0] = *cpt ;
00690         if( buf[0] == 'N' ) buf[0] = '\0' ;  /* bad key for this */
00691         buf[1] = '\0' ;
00692         GRA_timer_stop( gra ) ;
00693         GRA_handle_keypress( gra , buf , NULL ) ;
00694       }
00695 
00696 
00697    /*--- opened the controller itself: maybe move it ---*/
00698 
00699    } else {
00700 
00701       /* geometry */
00702 
00703       if( gxx >= 0 && gyy >= 0 )
00704         XtVaSetValues( im3d->vwid->top_shell, XmNx, gxx, XmNy, gyy, NULL ) ;
00705 
00706       /* iconify [06 Aug 2002] */
00707 
00708       cpt = strstr(cmd,"iconi") ;
00709       if( cpt != NULL ){
00710         XIconifyWindow( XtDisplay(im3d->vwid->top_shell) ,
00711                          XtWindow(im3d->vwid->top_shell)  ,
00712                          im3d->dc->screen_num   ) ;
00713       }
00714 
00715    }
00716 
00717    /*-- finito --*/
00718 
00719    XmUpdateDisplay( im3d->vwid->top_shell ) ;
00720    RETURN(0) ;
00721 }
00722 
00723 /*--------------------------------------------------------------------
00724   Close a window in the controller.
00725   Input is a string of the form A.sagittalimage, etc.
00726   Return value is 0 if good, -1 if bad.
00727   You can't close a plugin window this way.
00728 -------------------------------------------------------------------*/
00729 
00730 static int AFNI_drive_close_window( char *cmd )
00731 {
00732    int ic ;
00733    Three_D_View *im3d ;
00734 
00735 ENTRY("AFNI_drive_close_window") ;
00736 
00737    /* make sure the controller itself is open */
00738 
00739    ic = AFNI_controller_code_to_index( cmd ) ;
00740    if( ic < 0 ) ic = 0 ;
00741 
00742    im3d = GLOBAL_library.controllers[ic] ;
00743    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;       /* that was easy */
00744 
00745    if( strlen(cmd) < 3 ){                    /* close the controller */
00746       if( AFNI_count_controllers() > 1 ){    /* but only if there is */
00747          CLOSE_CONTROLLER(im3d); RETURN(0);  /* at least 1 more open */
00748       }
00749       RETURN(-1) ;                           /* can't close last controller */
00750    }
00751 
00752    /* close a graph or image window */
00753 
00754         if( strstr(cmd,"axialimage") != NULL )
00755           drive_MCW_imseq( im3d->s123 , isqDR_destroy , NULL ) ;
00756 
00757    else if( strstr(cmd,"sagittalimage") != NULL )
00758           drive_MCW_imseq( im3d->s231 , isqDR_destroy , NULL ) ;
00759 
00760    else if( strstr(cmd,"coronalimage") != NULL )
00761           drive_MCW_imseq( im3d->s312 , isqDR_destroy , NULL ) ;
00762 
00763    else if( strstr(cmd,"axialgraph") != NULL )
00764           drive_MCW_grapher( im3d->g123 , graDR_destroy , NULL ) ;
00765 
00766    else if( strstr(cmd,"sagittalgraph") != NULL )
00767           drive_MCW_grapher( im3d->g231 , graDR_destroy , NULL ) ;
00768 
00769    else if( strstr(cmd,"coronalgraph") != NULL )
00770           drive_MCW_grapher( im3d->g312 , graDR_destroy , NULL ) ;
00771 
00772    else
00773           RETURN(-1) ;
00774 
00775    XmUpdateDisplay( im3d->vwid->top_shell ) ;
00776    RETURN(0) ;
00777 }
00778 
00779 /*---------------------------------------------------------------
00780    Open a plugin window -- 13 Nov 2001
00781 -----------------------------------------------------------------*/
00782 
00783 #ifdef ALLOW_PLUGINS
00784 static int AFNI_drive_open_plugin( char *cmd )
00785 {
00786    int ic , ipl , ll , pl , qq ;
00787    Three_D_View *im3d ;
00788    char *cpt ;
00789    int gww=-1,ghh=-1,gxx=-1,gyy=-1 ;
00790 
00791    int      npbut              ;       /* how many plugins */
00792    char **  pluglab            ;       /* their labels     */
00793    PLUGIN_interface ** plugint ;       /* their interfaces */
00794 
00795 ENTRY("AFNI_drive_open_plugin") ;
00796 
00797    /* the controller is always good,
00798       since we are called from a place that just made sure of that */
00799 
00800    ic = AFNI_controller_code_to_index( cmd ) ;
00801    if( ic < 0 ) ic = 0 ;
00802    im3d = GLOBAL_library.controllers[ic] ;
00803 
00804    cpt = strstr(cmd,"plugin.") ;
00805    if( cpt == NULL || strlen(cpt) < 9 ) RETURN(-1) ;
00806    cpt += 7 ;  /* start of plugin name */
00807    pl   = strlen(cpt) ;
00808 
00809    /* get list of plugins */
00810 
00811    npbut   = im3d->vwid->nplugbut; if( npbut < 1 ) RETURN(-1) ;
00812    pluglab = im3d->vwid->pluglab ;
00813    plugint = im3d->vwid->plugint ;
00814 
00815    /* check name after plugin. vs. list */
00816 
00817    for( ipl=0 ; ipl < npbut ; ipl++ ){
00818       for( ll=strlen(pluglab[ipl]) ;   /* truncate trailing blanks */
00819            ll >= 0 && isspace(pluglab[ipl][ll]) ; ll-- ) ; /* nada */
00820       if( ll < 0 ) continue ;                        /* all blanks?! ERROR */
00821       if( pl < ll ) continue ;                       /* too short to match */
00822       for( qq=0 ; qq < ll ; qq++ )                   /* match each nonblank */
00823          if( !isspace(pluglab[ipl][qq]) && cpt[qq]!=pluglab[ipl][qq] ) break ;
00824       if( qq == ll ) break ;  /* found a match */
00825    }
00826 
00827    if( ipl >= npbut ) RETURN(-1) ;  /* no plugin found with this name */
00828 
00829    /* try to start the plugin (same callback as pressing the plugin's button) */
00830 
00831    PLUG_startup_plugin_CB( im3d->vwid->plugbut[ipl] , plugint[ipl] , NULL ) ;
00832 
00833    /* find geom=..., if present */
00834 
00835    cpt = strstr(cmd,"geom=") ;
00836    if( cpt == NULL ) cpt = strstr(cmd,"geom:") ;
00837    if( cpt != NULL )
00838       AFNI_decode_geom( cpt+5 , &gww,&ghh,&gxx,&gyy ) ;
00839 
00840    if( gxx >= 0                         &&
00841        gyy >= 0                         &&
00842        plugint[ipl]->wid        != NULL &&
00843        plugint[ipl]->wid->shell != NULL   ){
00844 
00845        XtVaSetValues( plugint[ipl]->wid->shell,
00846                       XmNx , gxx , XmNy , gyy , NULL ) ;
00847    }
00848 
00849    XmUpdateDisplay( im3d->vwid->top_shell ) ;
00850    RETURN(0) ;
00851 }
00852 #endif
00853 
00854 /*---------------------------------------------------------------*/
00855 
00856 static int AFNI_drive_quit( char *cmd )
00857 {
00858   int ii ;
00859   fprintf(stderr,"\n******* AFNI is commanded to quit! ") ; fflush(stderr) ;
00860   for( ii=0 ; ii < 7 ; ii++ ){ RWC_sleep(100); fprintf(stderr,"*"); fflush(stderr); }
00861   fprintf(stderr,"\n\n") ;
00862   exit(0) ;
00863 }
00864 
00865 /*===============================================================
00866   14 Nov 2001: Draw graphs from plugout-supplied data
00867 =================================================================*/
00868 
00869 /*-------------------------------------------------------------------------
00870   Define type to hold graphing information; also see coxplot/ stuff.
00871 ---------------------------------------------------------------------------*/
00872 
00873 #include "coxplot.h"
00874 
00875 typedef struct {
00876    char gname[THD_MAX_NAME] ;  /* graph name */
00877    int ny ;                    /* number of sub-graphs */
00878    float xbot,xtop ,           /* graph ranges */
00879          ybot,ytop  ;
00880 
00881    int num_pt ;                /* number points now graphed */
00882    int num_mpinit ;            /* number lines used when initializing graph */
00883 
00884    MEM_topshell_data *mp ; /* the plotting/display data structure */
00885 
00886    float last_x ;          /* last plotted points (if num_pt > 0) */
00887    float *last_y ;
00888 } Graph_xy ;
00889 
00890 /*-------- storage to hold active graphs controlled by plugouts --------*/
00891 
00892 static int        num_Graph_xy  = 0 ;     /* how many graphs now have */
00893 static Graph_xy **Graph_xy_list = NULL ;  /* array of existing graphs */
00894 
00895 /*--------------------------------------------------------------------------
00896   Find a graph in the list, and return its index; if not present, return -1.
00897 ----------------------------------------------------------------------------*/
00898 
00899 static int find_graph_xy_name( char *name )
00900 {
00901    int ii ;
00902 
00903    if( name == NULL || name[0] == '\0' ) return -1 ;
00904 
00905    for( ii=0 ; ii < num_Graph_xy ; ii++ )
00906       if( Graph_xy_list[ii] != NULL                  &&
00907           strcmp(Graph_xy_list[ii]->gname,name) == 0   ) return ii ;
00908 
00909    return -1 ;
00910 }
00911 
00912 /*--------------------------------------------------------------------------
00913   Find an empty slot in the graph list, or make one (always succeeds).
00914   Return the index in the graph list.
00915 ----------------------------------------------------------------------------*/
00916 
00917 static int find_empty_graph_xy(void)
00918 {
00919    int ii ;
00920 
00921    /* nothing in list ==> make a new list */
00922 
00923    if( Graph_xy_list == NULL ){
00924       Graph_xy_list    = (Graph_xy **) malloc(sizeof(Graph_xy *)) ;
00925       Graph_xy_list[0] = NULL ;
00926       num_Graph_xy     = 1 ;
00927       return 0 ;
00928    }
00929 
00930    /* search list for an empty element */
00931 
00932    for( ii=0 ; ii < num_Graph_xy ; ii++ )
00933       if( Graph_xy_list[ii] == NULL ) return ii ;
00934 
00935    /* add empty element to list */
00936 
00937    Graph_xy_list = (Graph_xy **) realloc( Graph_xy_list ,
00938                                           sizeof(Graph_xy *)*(num_Graph_xy+1) ) ;
00939    Graph_xy_list[num_Graph_xy] = NULL ;
00940    num_Graph_xy++ ;
00941    return (num_Graph_xy-1) ;
00942 }
00943 
00944 /*--------------------------------------------------------------------------
00945   If the user kills a graph, do this (free up stuff)
00946 ----------------------------------------------------------------------------*/
00947 
00948 static void kill_graph_xy( MEM_topshell_data * mp )
00949 {
00950    int ii ;
00951 
00952    if( mp == NULL || Graph_xy_list == NULL ) return ;
00953 
00954    /* find this graph in the list */
00955 
00956    for( ii=0 ; ii < num_Graph_xy ; ii++ )
00957       if( Graph_xy_list[ii]     != NULL &&
00958           Graph_xy_list[ii]->mp == mp     ) break ;
00959 
00960    if( ii >= num_Graph_xy ) return ;  /* should not happen */
00961 
00962    /* free data from this graph */
00963 
00964    if( Graph_xy_list[ii]->last_y != NULL )
00965       free( Graph_xy_list[ii]->last_y ) ;
00966 
00967    if( mp->userdata != NULL ) free(mp->userdata) ;
00968 
00969    free( Graph_xy_list[ii] ) ; Graph_xy_list[ii] = NULL ; return ;
00970 }
00971 
00972 /*--------------------------------------------------------------------------
00973   SET_GRAPH_GEOM gname geom=something
00974 ----------------------------------------------------------------------------*/
00975 
00976 static int AFNI_drive_geom_graph( char *cmd )
00977 {
00978    int ntok , ig ;
00979    char **stok=NULL ;
00980    char *gname , *cpt ;
00981    Graph_xy *gxy ;
00982    int gww=-1,ghh=-1,gxx=-1,gyy=-1 ;
00983 
00984 ENTRY("AFNI_drive_geom_graph") ;
00985 
00986    /* tokenize the command string */
00987 
00988    ntok = breakup_string( cmd , &stok ) ;
00989    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
00990 
00991    /* check if this graph name is already in use */
00992 
00993    ig = find_graph_xy_name( stok[0] ) ;
00994    freeup_strings(ntok,stok) ;
00995    if( ig < 0 || Graph_xy_list[ig]->mp == NULL ) RETURN(-1) ;
00996    gxy = Graph_xy_list[ig] ;
00997 
00998    cpt = strstr(cmd,"geom=") ;
00999    if( cpt == NULL ) cpt = strstr(cmd,"geom:") ;
01000    if( cpt == NULL || strlen(cpt) < 7 ) RETURN(-1) ;
01001 
01002    AFNI_decode_geom( cpt+5 , &gww,&ghh,&gxx,&gyy ) ;
01003 
01004    ig = -1 ;
01005    if( gxx >= 0 && gyy >= 0 ){
01006      XtVaSetValues( gxy->mp->top , XmNx,gxx    , XmNy,gyy     , NULL ); ig=0;
01007    }
01008    if( gww > 0 && ghh > 0 ){
01009      XtVaSetValues( gxy->mp->top , XmNwidth,gww, XmNheight,ghh, NULL ); ig=0;
01010    }
01011 
01012    RETURN(ig) ;
01013 }
01014 
01015 /*--------------------------------------------------------------------------
01016   OPEN_GRAPH_XY gname toplabel xbot xtop xlabel
01017                             ny ybot ytop ylabel yname_1 ... yname_ny
01018 ----------------------------------------------------------------------------*/
01019 
01020 static int AFNI_drive_open_graph_xy( char *cmd )
01021 {
01022    int ntok , ig ;
01023    char **stok=NULL ;
01024 
01025    char *gname , *toplabel=NULL , *xlabel=NULL , *ylabel=NULL ;
01026    int   ny=1 ;
01027    float xbot=0.0,xtop=1.0 , ybot=0.0,ytop=1.0 ;
01028    char **yname=NULL ;
01029 
01030    Graph_xy *gxy ;
01031 
01032 ENTRY("AFNI_drive_open_graph_xy") ;
01033 
01034    /* tokenize the command string */
01035 
01036    ntok = breakup_string( cmd , &stok ) ;
01037    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01038 
01039    /* check if this graph name is already in use */
01040 
01041    gname = stok[0] ;
01042    ig = find_graph_xy_name( gname ) ;
01043    if( ig >= 0 ){
01044       freeup_strings(ntok,stok) ; RETURN(-1) ;   /* already used = bad */
01045    }
01046 
01047    /* create a graph */
01048 
01049    ig = find_empty_graph_xy() ;
01050 
01051    Graph_xy_list[ig] = gxy = (Graph_xy *) calloc(1,sizeof(Graph_xy)) ;
01052 
01053    MCW_strncpy( gxy->gname , gname , THD_MAX_NAME ) ;
01054 
01055 #if 0
01056 { int qq ;
01057   fprintf(stderr,"AFNI_drive_open_graph_xy tokens:\n") ;
01058   for( qq=0 ; qq < ntok ; qq++ ) fprintf(stderr," %2d:%s\n",qq,stok[qq]); }
01059 #endif
01060 
01061    /* parse values out of the tokens */
01062 
01063    if( ntok > 1 ) toplabel = stok[1] ;
01064 
01065    if( ntok > 2 ) xbot = strtod(stok[2],NULL) ;
01066    if( ntok > 3 ) xtop = strtod(stok[3],NULL) ;
01067    if( xbot == xtop )    { xtop = xbot+1.0 ; }
01068    else if( xbot > xtop ){ float qq = xbot; xbot = xtop; xtop = qq ; }
01069 
01070    if( ntok > 4 ) xlabel = stok[4] ;
01071 
01072    if( ntok > 5 ){
01073       int qq = strtol(stok[5],NULL,10) ;
01074       if( qq > 1 ) ny = qq ;
01075    }
01076 
01077    if( ntok > 6 ) ybot = strtod(stok[6],NULL) ;
01078    if( ntok > 7 ) ytop = strtod(stok[7],NULL) ;
01079    if( ybot == ytop )    { ytop = ybot+1.0 ; }
01080    else if( ybot > ytop ){ float qq = ybot; ybot = ytop; ytop = qq ; }
01081 
01082    if( ntok > 8 ) ylabel = stok[8] ;
01083 
01084    if( ntok > 9 ){
01085       int qq ;
01086       yname = (char **) calloc( ny , sizeof(char *) ) ;
01087       for( qq=0 ; qq < ny && qq+9 < ntok ; qq++ ) yname[qq] = stok[qq+9] ;
01088    }
01089 
01090    /* put values into graph struct */
01091 
01092    gxy->xbot = xbot ; gxy->xtop = xtop ;
01093    gxy->ybot = ybot ; gxy->ytop = ytop ; gxy->ny = ny ;
01094 
01095    gxy->num_pt = 0 ;  /* number of points plotted thus far */
01096 
01097    /* create the actual graph */
01098 
01099    gxy->mp = plot_ts_init( GLOBAL_library.dc->display ,
01100                            xbot , xtop ,
01101                            -ny , ybot , ytop ,
01102                            xlabel , ylabel ,
01103                            toplabel , yname , kill_graph_xy ) ;
01104 
01105    freeup_strings(ntok,stok) ;
01106    if( yname != NULL ) free(yname) ;
01107 
01108    if( gxy->mp == NULL ){         /* should not happen */
01109       free(Graph_xy_list[ig]) ; Graph_xy_list[ig] = NULL ;
01110       RETURN(-1) ;
01111    }
01112 
01113    /* number of lines plotted so far (labels, etc.) */
01114 
01115    gxy->num_mpinit = MEMPLOT_NLINE(gxy->mp->mp) ;
01116 
01117    /* place to store last location plotted */
01118 
01119    gxy->last_y = (float *) calloc(ny,sizeof(float)) ;
01120 
01121    RETURN(0) ;
01122 }
01123 
01124 /*--------------------------------------------------------------------------
01125   CLOSE_GRAPH_XY gname
01126 ----------------------------------------------------------------------------*/
01127 
01128 static int AFNI_drive_close_graph_xy( char *cmd )
01129 {
01130    int ig , ntok ;
01131    char **stok = NULL ;
01132 
01133 ENTRY("AFNI_drive_close_graph_xy") ;
01134 
01135    /* tokenize the command string */
01136 
01137    ntok = breakup_string( cmd , &stok ) ;
01138    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01139 
01140    /* check if this graph name is already in use */
01141 
01142    ig = find_graph_xy_name( stok[0] ) ;
01143    freeup_strings(ntok,stok) ;
01144    if( ig < 0 || Graph_xy_list[ig]->mp == NULL ) RETURN(-1) ;
01145 
01146    plotkill_topshell( Graph_xy_list[ig]->mp ) ; /* will call kill_graph_xy */
01147    RETURN(0) ;
01148 }
01149 
01150 /*--------------------------------------------------------------------------
01151   CLEAR_GRAPH_XY gname
01152 ----------------------------------------------------------------------------*/
01153 
01154 static int AFNI_drive_clear_graph_xy( char *cmd )
01155 {
01156    int ig , ntok ;
01157    char **stok = NULL ;
01158 
01159 ENTRY("AFNI_drive_clear_graph_xy") ;
01160 
01161    /* tokenize the command string */
01162 
01163    ntok = breakup_string( cmd , &stok ) ;
01164    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01165 
01166    /* check if this graph name is already in use */
01167 
01168    ig = find_graph_xy_name( stok[0] ) ;
01169    freeup_strings(ntok,stok) ;
01170    if( ig < 0 || Graph_xy_list[ig]->mp == NULL ) RETURN(-1) ;
01171 
01172    /* cut off the graph lines since the initial stuff */
01173 
01174    TRUNC_MEMPLOT( Graph_xy_list[ig]->mp->mp ,
01175                   Graph_xy_list[ig]->num_mpinit ) ;
01176 
01177    /* show it again, Sam (but the data part will be gone) */
01178 
01179    redraw_topshell( Graph_xy_list[ig]->mp ) ;
01180    Graph_xy_list[ig]->num_pt = 0 ;  /* number of points plotted thus far */
01181    RETURN(0) ;
01182 }
01183 
01184 /*--------------------------------------------------------------------------
01185   ADDTO_GRAPH_XY gname x y_1 y_2 .. y_ny [repeat]
01186 ----------------------------------------------------------------------------*/
01187 
01188 static int AFNI_drive_addto_graph_xy( char *cmd )
01189 {
01190    int ig , ntok , nx , ny , ii,jj , tt , num_pt , ibot ;
01191    char **stok = NULL ;
01192    Graph_xy *gxy ;
01193    float *x , **y ;
01194 
01195 ENTRY("AFNI_drive_addto_graph_xy") ;
01196 
01197    /* tokenize the command string */
01198 
01199    ntok = breakup_string( cmd , &stok ) ;
01200    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01201 
01202    /* check if this graph name is already in use */
01203 
01204    ig = find_graph_xy_name( stok[0] ) ;
01205    if( ig < 0 || Graph_xy_list[ig]->mp == NULL ){
01206       freeup_strings(ntok,stok) ; RETURN(-1) ;
01207    }
01208    gxy = Graph_xy_list[ig] ;
01209 
01210    /* number of sub-graphs */
01211 
01212    ny = gxy->ny ;
01213 
01214    /* number of points to add to each sub-graph */
01215 
01216    nx = (ntok-1)/(ny+1) ;
01217    if( nx < 1 ){ freeup_strings(ntok,stok); RETURN(-1); }
01218 
01219    /* attach to last_x and last_y? */
01220 
01221    num_pt = gxy->num_pt ;
01222    if( num_pt > 0 ) nx++ ;  /* need 1 extra place for last_x and last_y */
01223 
01224    x = (float *) calloc(nx,sizeof(float)) ;
01225    y = (float **) malloc( sizeof(float *)*ny ) ;
01226    for( jj=0 ; jj < ny ; jj++ )
01227       y[jj] = (float *) calloc(nx,sizeof(float)) ;
01228 
01229    /* put last_x and last_y into graphing data, if needed */
01230 
01231    if( num_pt > 0 ){
01232       x[0] = gxy->last_x ;
01233       for( jj=0 ; jj < ny ; jj++ ) y[jj][0] = gxy->last_y[jj] ;
01234       ibot = 1 ;
01235    } else {
01236       ibot = 0 ;
01237    }
01238 
01239    /* parse tokens into numbers for graphing */
01240 
01241    tt = 1 ;                            /* token index */
01242    for( ii=ibot ; ii < nx ; ii++ ){
01243       x[ii] = strtod( stok[tt++] , NULL ) ;
01244       for( jj=0 ; jj < ny ; jj++ )
01245          y[jj][ii] = strtod( stok[tt++] , NULL ) ;
01246    }
01247 
01248    /* save new last_x and last_y */
01249 
01250    gxy->last_x = x[nx-1] ;
01251    for( jj=0 ; jj < ny ; jj++ ) gxy->last_y[jj] = y[jj][nx-1] ;
01252 
01253    /**** graphing! ****/
01254 
01255    plot_ts_addto( gxy->mp , nx , x , -ny , y ) ;
01256 
01257    /* cleanup */
01258 
01259    gxy->num_pt += nx ;  /* number of points in each sub-graph so far */
01260 
01261    for( jj=0 ; jj < ny ; jj++ ) free(y[jj]) ;
01262    free(y) ; free(x) ; freeup_strings(ntok,stok) ;
01263 
01264    RETURN(0) ;
01265 }
01266 
01267 /*-------------------------------------------------------------------------
01268   CLOSE_GRAPH_1D gname
01269 ---------------------------------------------------------------------------*/
01270 
01271 static int AFNI_drive_close_graph_1D( char *cmd )
01272 {
01273   return AFNI_drive_close_graph_xy( cmd ) ;
01274 }
01275 
01276 /*-------------------------------------------------------------------------
01277   OPEN_GRAPH_1D gname toplab nx dx xlab
01278                              ny ybot ytop ylab yname_1 ... yname_ny
01279 ---------------------------------------------------------------------------*/
01280 
01281 static int AFNI_drive_open_graph_1D( char *cmd )
01282 {
01283    int ntok , ig , ii ;
01284    char **stok=NULL ;
01285 
01286    char *gname , *toplabel=NULL , *xlabel=NULL , *ylabel=NULL ;
01287    int   ny=1 , nx=500 ;
01288    float dx=1.0 , ybot=0.0,ytop=1.0 ;
01289    char **yname=NULL ;
01290 
01291    Graph_xy *gxy ;
01292 
01293 ENTRY("AFNI_drive_open_graph_1D") ;
01294 
01295    /* tokenize the command string */
01296 
01297    ntok = breakup_string( cmd , &stok ) ;
01298    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01299 
01300    /* check if this graph name is already in use */
01301 
01302    gname = stok[0] ;
01303    ig = find_graph_xy_name( gname ) ;
01304    if( ig >= 0 ){
01305       freeup_strings(ntok,stok) ; RETURN(-1) ;   /* already used = bad */
01306    }
01307 
01308 #if 0
01309 { int qq ;
01310   fprintf(stderr,"AFNI_drive_open_graph_1D tokens:\n") ;
01311   for( qq=0 ; qq < ntok ; qq++ ) fprintf(stderr," %2d:%s\n",qq,stok[qq]); }
01312 #endif
01313 
01314    /* create a graph */
01315 
01316    ig = find_empty_graph_xy() ;
01317 
01318    Graph_xy_list[ig] = gxy = (Graph_xy *) malloc(sizeof(Graph_xy)) ;
01319 
01320    MCW_strncpy( gxy->gname , gname , THD_MAX_NAME ) ;
01321 
01322    /* parse values out of the tokens */
01323 
01324    if( ntok > 1 ) toplabel = stok[1] ;
01325 
01326    if( ntok > 2 ){
01327       int qq = strtol(stok[2],NULL,10) ;
01328       if( qq >= 10 ) nx = qq ;
01329    }
01330 
01331    if( ntok > 3 ){
01332       float qq = strtod(stok[3],NULL) ;
01333       if( qq > 0.0 ) dx = qq ;
01334    }
01335 
01336    if( ntok > 4 ) xlabel = stok[4] ;
01337 
01338    if( ntok > 5 ){
01339       int qq = strtol(stok[5],NULL,10) ;
01340       if( qq > 1 ) ny = qq ;
01341    }
01342 
01343    if( ntok > 6 ) ybot = strtod(stok[6],NULL) ;
01344    if( ntok > 7 ) ytop = strtod(stok[7],NULL) ;
01345    if( ybot == ytop )    { ytop = ybot+1.0 ; }
01346    else if( ybot > ytop ){ float qq = ybot; ybot = ytop; ytop = qq ; }
01347 
01348    if( ntok > 8 ) ylabel = stok[8] ;
01349 
01350    if( ntok > 9 ){
01351       int qq ;
01352       yname = (char **) calloc( ny , sizeof(char *) ) ;
01353       for( qq=0 ; qq < ny && qq+9 < ntok ; qq++ ) yname[qq] = stok[qq+9] ;
01354    }
01355 
01356    /* put values into graph struct */
01357 
01358    gxy->xbot = 0.0  ; gxy->xtop = nx*dx ;
01359    gxy->ybot = ybot ; gxy->ytop = ytop  ; gxy->ny = ny ;
01360 
01361    gxy->num_pt = 0.0 ;
01362 
01363    /* create the actual graph */
01364 
01365    gxy->mp = plot_strip_init( GLOBAL_library.dc->display ,
01366                               nx , dx ,
01367                               -ny , ybot , ytop ,
01368                               xlabel , ylabel ,
01369                               toplabel , yname , kill_graph_xy ) ;
01370 
01371    freeup_strings(ntok,stok) ;
01372    if( yname != NULL ) free(yname) ;
01373 
01374    if( gxy->mp == NULL ){         /* should not happen */
01375       free(Graph_xy_list[ig]) ; Graph_xy_list[ig] = NULL ;
01376       RETURN(-1) ;
01377    }
01378 
01379    gxy->last_y = NULL ;  /* not used for this graph type */
01380 
01381    RETURN(0) ;
01382 }
01383 
01384 /*-------------------------------------------------------------------------
01385   CLEAR_GRAPH_1D gname
01386 ---------------------------------------------------------------------------*/
01387 
01388 static int AFNI_drive_clear_graph_1D( char *cmd )
01389 {
01390    int ig , ntok , ii ;
01391    char **stok = NULL ;
01392 
01393 ENTRY("AFNI_drive_clear_graph_1D") ;
01394 
01395    /* tokenize the command string */
01396 
01397    ntok = breakup_string( cmd , &stok ) ;
01398    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01399 
01400    /* check if this graph name is already in use */
01401 
01402    ig = find_graph_xy_name( stok[0] ) ;
01403    freeup_strings(ntok,stok) ;
01404    if( ig < 0 || Graph_xy_list[ig]->mp == NULL ) RETURN(-1) ;
01405 
01406    /* do the clearance work */
01407 
01408    plot_strip_clear( Graph_xy_list[ig]->mp ) ;  /* coxplot/plot_strip.c */
01409 
01410    RETURN(0) ;
01411 }
01412 
01413 /*-------------------------------------------------------------------------
01414   ADDTO_GRAPH_1D gname y_1 y_2 .. y_ny [repeat]
01415 ---------------------------------------------------------------------------*/
01416 
01417 static int AFNI_drive_addto_graph_1D( char *cmd )
01418 {
01419    int ig, ntok, nx, ny, ii,jj, tt, num_pt, ibot, nadd ;
01420    char **stok = NULL ;
01421    Graph_xy *gxy ;
01422    float **y ;
01423 
01424 ENTRY("AFNI_drive_addto_graph_1D") ;
01425 
01426    /* tokenize the command string */
01427 
01428    ntok = breakup_string( cmd , &stok ) ;
01429    if( ntok <= 0 || stok == NULL ) RETURN(-1) ;
01430 
01431    /* check if this graph name is already in use */
01432 
01433    ig = find_graph_xy_name( stok[0] ) ;
01434    if( ig < 0 || Graph_xy_list[ig]->mp == NULL ){
01435       freeup_strings(ntok,stok) ; RETURN(-1) ;
01436    }
01437    gxy = Graph_xy_list[ig] ;
01438 
01439    /* number of sub-graphs */
01440 
01441    ny = gxy->ny ;
01442 
01443    /* number of points to add to each sub-graph */
01444 
01445    nadd = (ntok-1)/ny ;
01446    if( nadd < 1 ){ freeup_strings(ntok,stok); RETURN(-1); }
01447 
01448    /* make space for incoming data */
01449 
01450    y = (float **) malloc( sizeof(float *)*ny ) ;
01451    for( jj=0 ; jj < ny ; jj++ )
01452       y[jj] = (float *) calloc(nadd,sizeof(float)) ;
01453 
01454    /* convert incoming tokens to numbers */
01455 
01456    tt = 1 ;                            /* token index */
01457    for( ii=0 ; ii < nadd ; ii++ ){
01458       for( jj=0 ; jj < ny ; jj++ )
01459          y[jj][ii] = strtod( stok[tt++] , NULL ) ;
01460    }
01461 
01462    /***** graphing! *****/
01463 
01464    plot_strip_addto( gxy->mp , nadd , y ) ;
01465 
01466    /* cleanup */
01467 
01468    for( jj=0 ; jj < ny ; jj++ ) free(y[jj]) ;
01469    free(y) ; freeup_strings(ntok,stok) ;
01470 
01471    RETURN(0) ;
01472 }
01473 
01474 /*------------------------------------------------------------------------*/
01475 /*! ADD_OVERLAY_COLOR colordef colorlab -- 16 Jan 2003
01476 --------------------------------------------------------------------------*/
01477 
01478 static int AFNI_drive_add_overlay_color( char *cmd )
01479 {
01480    char cdef[256]="\0" , clab[256]="\0" ;
01481    int ii ;
01482 
01483 ENTRY("AFNI_drive_add_overlay_color") ;
01484 
01485    sscanf( cmd , "%255s %255s" , cdef,clab ) ;
01486    if( cdef[0] == '\0' || clab[0] == '\0' ) RETURN(-1) ;
01487 
01488    if( GLOBAL_library.dc == NULL ){           /* before X11 started */
01489      if( INIT_ncolovr < MAX_NCOLOVR ){
01490        ii = INIT_ncolovr++ ;
01491        INIT_labovr[ii] = XtNewString(cdef) ;
01492        INIT_colovr[ii] = XtNewString(clab) ;
01493      } else
01494        RETURN(-1) ;
01495    } else {                                   /* after X11 started */
01496      ii = DC_add_overlay_color( GLOBAL_library.dc , cdef , clab ) ;
01497      if( ii < 0 ) RETURN(-1) ;
01498      OVC_mostest( GLOBAL_library.dc->ovc ) ;
01499    }
01500    RETURN(0) ;
01501 }
01502 
01503 /*------------------------------------------------------------------------*/
01504 /*! SET_THRESHOLD [c].val [dec] -- 16 Jan 2003
01505     as in "SET_THRESHOLD A.3327 2" or
01506           "SET_THRESHOLD .9932 2"
01507 --------------------------------------------------------------------------*/
01508 
01509 static int AFNI_drive_set_threshold( char *cmd )
01510 {
01511    int ic , dadd=1 , dec=-1 , ival , smax ;
01512    Three_D_View *im3d ;
01513    float val ;
01514    char *cpt ;
01515    static float tval[9] = { 1.0 , 10.0 , 100.0 , 1000.0 , 10000.0 ,
01516                             100000.0 , 1000000.0 , 10000000.0 , 100000000.0 } ;
01517 
01518 ENTRY("AFNI_drive_set_threshold") ;
01519 
01520    if( cmd == NULL || strlen(cmd) < 3 ) RETURN(-1) ;
01521 
01522    ic = AFNI_controller_code_to_index( cmd ) ;
01523    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01524 
01525    im3d = GLOBAL_library.controllers[ic] ;
01526    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01527 
01528    /* get val and set scale */
01529 
01530    if( cmd[dadd] != '.' ) RETURN(-1) ;
01531    val = strtod( cmd+dadd , &cpt ) ;
01532    ival = rint(val/THR_FACTOR) ;
01533    smax = (int)( pow(10.0,THR_TOP_EXPON) + 0.001 ) - 1 ;
01534    if( ival < 0 || ival > smax ) RETURN(-1) ;
01535    XmScaleSetValue( im3d->vwid->func->thr_scale , ival ) ;
01536 
01537    /* get dec, if present, and apply it */
01538 
01539    sscanf(cpt,"%d",&dec) ;
01540 
01541    if( dec >= 0 && dec <= THR_TOP_EXPON )
01542      AFNI_set_thresh_top( im3d , tval[dec] ) ;
01543 
01544    AFNI_thr_scale_CB( im3d->vwid->func->thr_scale, (XtPointer)im3d, NULL ) ;
01545    RETURN(0) ;
01546 }
01547 
01548 /*------------------------------------------------------------------------*/
01549 /*! SET_THRESHNEW [c].val [**] -- 06 Feb 2004
01550     as in "SET_THRESHNEW A.0.372" or
01551           "SET_THRESHNEW 0.372 **"   (the "**" means to set the range too)
01552 --------------------------------------------------------------------------*/
01553 
01554 static int AFNI_drive_set_threshnew( char *cmd )
01555 {
01556    int ic,dadd , olddec,newdec , ival,smax,id,stop , dopval,dostar;
01557    Three_D_View *im3d ;
01558    float val , pval ;
01559    char *cpt ;
01560    static float tval[9] = { 1.0 , 10.0 , 100.0 , 1000.0 , 10000.0 ,
01561                             100000.0 , 1000000.0 , 10000000.0 , 100000000.0 } ;
01562 
01563 ENTRY("AFNI_drive_set_threshnew") ;
01564 
01565    if( cmd == NULL || *cmd == '\0' ) RETURN(-1) ;
01566 
01567    ic = AFNI_controller_code_to_index( cmd ) ;
01568    if( ic < 0 ){
01569      ic = 0 ; dadd = 0 ;
01570    } else {
01571      if( cmd[1] == '\0' ) RETURN(-1) ;   /* no value following? */
01572      dadd = 2 ;                          /* skip period following controller */
01573    }
01574 
01575    im3d = GLOBAL_library.controllers[ic] ;
01576    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;   /* stupid user */
01577 
01578    /* get val from command line */
01579 
01580    val = strtod( cmd+dadd , &cpt ) ;
01581    if( val < 0.0 || val > THR_TOP_VALUE ) RETURN(-1) ; /* stupid user */
01582 
01583    /* get current scale decimal setting */
01584 
01585    olddec = (int)rint( log10(im3d->vinfo->func_thresh_top) ) ;
01586         if( olddec < 0             ) olddec = 0 ;
01587    else if( olddec > THR_TOP_EXPON ) olddec = THR_TOP_EXPON ;
01588    newdec = olddec ;
01589 
01590    smax  = (int)rint( pow(10.0,THR_TOP_EXPON) ) ;
01591    stop  = smax - 1 ;                             /* max slider value */
01592 
01593    dopval = (val >= 0.0) && (val <= 1.0) && (strchr(cpt,'p') != NULL) &&
01594             (DSET_BRICK_STATCODE(im3d->fim_now,im3d->vinfo->thr_index) > 0) ;
01595 
01596    dostar = (val > 0.0) && (strchr(cpt,'*') != NULL) ;
01597 
01598    if( dopval ){
01599      pval = THD_pval_to_stat( val ,
01600               DSET_BRICK_STATCODE(im3d->fim_now,im3d->vinfo->thr_index) ,
01601               DSET_BRICK_STATAUX (im3d->fim_now,im3d->vinfo->thr_index)  ) ;
01602      if( pval >= 0.0 ) val = pval ;
01603    }
01604 
01605    if( val >= im3d->vinfo->func_thresh_top || dostar ){ /* reset scale range */
01606 
01607      newdec = (int)( log10(val) + 1.0 ) ;
01608           if( newdec < 0             ) newdec = 0 ;
01609      else if( newdec > THR_TOP_EXPON ) newdec = THR_TOP_EXPON ;
01610    }
01611 
01612    if( newdec != olddec )
01613      AFNI_set_thresh_top( im3d , tval[newdec] ) ;
01614 
01615    ival = rint( val/(THR_FACTOR*tval[newdec]) ) ;
01616         if( ival < 0    ) ival = 0    ;
01617    else if( ival > stop ) ival = stop ;
01618 
01619    XmScaleSetValue( im3d->vwid->func->thr_scale , ival ) ;
01620 
01621    AFNI_thr_scale_CB( im3d->vwid->func->thr_scale, (XtPointer)im3d, NULL ) ;
01622    RETURN(0) ;
01623 }
01624 
01625 /*------------------------------------------------------------------------*/
01626 /*! SET_PBAR_NUMBER [c.]num
01627     as in "SET_PBAR_NUMBER A.3"
01628     use a large number (99, say) to turn on colorscale mode
01629 --------------------------------------------------------------------------*/
01630 
01631 static int AFNI_drive_set_pbar_number( char *cmd )
01632 {
01633    int ic , dadd=2 , num=-1 ;
01634    Three_D_View *im3d ;
01635    MCW_pbar *pbar ;
01636 
01637 ENTRY("AFNI_drive_set_pbar_number") ;
01638 
01639    if( cmd == NULL || strlen(cmd) < 1 ) RETURN(-1) ;
01640 
01641    ic = AFNI_controller_code_to_index( cmd ) ;
01642    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01643    if( !isdigit(cmd[dadd]) ) RETURN(-1) ;
01644 
01645    im3d = GLOBAL_library.controllers[ic] ;
01646    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01647 
01648    pbar = im3d->vwid->func->inten_pbar ;
01649 
01650    num = (int) strtod( cmd+dadd , NULL ) ;
01651    if( num < NPANE_MIN ) RETURN(-1) ;
01652    if( num > NPANE_MAX ) num = NPANE_MAX+1 ;
01653    AV_assign_ival( im3d->vwid->func->inten_av , num ) ;
01654 
01655    HIDE_SCALE(im3d) ;
01656    if( num <= NPANE_MAX ){
01657      pbar->bigmode = 0 ;
01658      alter_MCW_pbar( pbar , num , NULL ) ;
01659      NORMAL_cursorize( pbar->panew ) ;  /* 08 Apr 2005 */
01660    } else {
01661      int npane=pbar->num_panes , jm=pbar->mode ;
01662      float pmax=pbar->pval_save[npane][0][jm] ,
01663            pmin=pbar->pval_save[npane][npane][jm] ;
01664      PBAR_set_bigmode( pbar , 1 , pmin,pmax ) ;
01665      AFNI_inten_pbar_CB( pbar , im3d , 0 ) ;
01666      POPUP_cursorize( pbar->panew ) ;  /* 08 Apr 2005 */
01667    }
01668    FIX_SCALE_SIZE(im3d) ;
01669 
01670    RETURN(0) ;
01671 }
01672 
01673 /*------------------------------------------------------------------------*/
01674 /*! SET_PBAR_SIGN [c.]+ OR [c.]-
01675     as in "SET_PBAR_SIGN A.+"
01676 --------------------------------------------------------------------------*/
01677 
01678 static int AFNI_drive_set_pbar_sign( char *cmd )
01679 {
01680    int ic , dadd=2 , val ;
01681    Three_D_View *im3d ;
01682 
01683 ENTRY("AFNI_drive_set_pbar_sign") ;
01684 
01685    if( cmd == NULL || strlen(cmd) < 1 ) RETURN(-1) ;
01686 
01687    ic = AFNI_controller_code_to_index( cmd ) ;
01688    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01689 
01690    im3d = GLOBAL_library.controllers[ic] ;
01691    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01692 
01693    switch( cmd[dadd] ){
01694      default: RETURN(-1) ;
01695 
01696      case 'p':
01697      case 'P':
01698      case '+': val = 1 ; break ;
01699 
01700      case 's':
01701      case 'S':
01702      case '-': val = 0 ; break ;
01703    }
01704 
01705    MCW_set_bbox( im3d->vwid->func->inten_bbox , val ) ;
01706 
01707    AFNI_inten_bbox_CB( im3d->vwid->func->inten_bbox->wbut[PBAR_MODEBUT] ,
01708                        (XtPointer)im3d , NULL ) ;
01709    RETURN(0) ;
01710 }
01711 
01712 /*-------------------------------------------------------------------------*/
01713 /*! SET_PBAR_ALL [c.]{+|-}num val=color val=color ...
01714    "SET_PBAR_ALL A.+5 1.0=yellow 0.5=red 0.05=none -0.05=blue -0.50=cyan"
01715    "SET_PBAR_ALL A.+99 topval colorscale_name FLIP ROTA=n"
01716 ---------------------------------------------------------------------------*/
01717 
01718 static int AFNI_drive_set_pbar_all( char *cmd )
01719 {
01720    int ic , dadd=2 , npan=0 , pos , nn , ii,jj ;
01721    float pval[NPANE_MAX+1] , val ;
01722    int   pcol[NPANE_MAX]   , col , flip=0 , rota=0 ;
01723    char  str[256] , *cpt ;
01724    MCW_pbar *pbar ;
01725    Three_D_View *im3d ;
01726 
01727 ENTRY("AFNI_drive_set_pbar_all") ;
01728 
01729    if( cmd == NULL || strlen(cmd) < 4 ) RETURN(-1) ;
01730 
01731    ic = AFNI_controller_code_to_index( cmd ) ;
01732    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01733 
01734    im3d = GLOBAL_library.controllers[ic] ;
01735    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01736 
01737    /* get sign */
01738 
01739    switch( cmd[dadd] ){
01740      default: RETURN(-1) ;
01741      case '+': pos = 1 ; break ;
01742      case '-': pos = 0 ; break ;
01743    }
01744    dadd++ ;
01745 
01746    /* get number of panes */
01747 
01748    sscanf( cmd+dadd , "%d%n" , &npan , &nn ) ;
01749    if( npan < NPANE_MIN ) RETURN(-1) ;
01750    if( npan > NPANE_MAX ) npan = NPANE_MAX+1 ;
01751    dadd += nn ;
01752 
01753    pbar = im3d->vwid->func->inten_pbar ;
01754 
01755    if( npan <= NPANE_MAX ){ /* discrete panes: get value=colorname array */
01756 
01757      for( ii=0 ; ii < npan ; ii++ ){
01758        str[0] = '\0' ; nn = 0 ;
01759        sscanf( cmd+dadd , "%f=%255s%n" , &val,str,&nn ) ;
01760        if( str[0] == '\0' || nn == 0 ) RETURN(-1) ;  /* can't parse */
01761 
01762        col = DC_find_overlay_color( GLOBAL_library.dc , str ) ;
01763        if( col < 0 )                   RETURN(-1) ;  /* bad color name */
01764 
01765        for( jj=0 ; jj < ii ; jj++ )                  /* check ordering */
01766          if( pval[jj] <= val )         RETURN(-1) ;
01767 
01768        if( ii > 0 ){                                 /* check size */
01769          if( fabs(val) >= pval[0] )    RETURN(-1) ;
01770          if( pos && val <= 0.0 )       RETURN(-1) ;
01771        } else {
01772          if( val <= 0.0 )              RETURN(-1) ;
01773        }
01774 
01775        pval[ii] = val ; pcol[ii] = col ;
01776        dadd += nn ;
01777      }
01778      if( pos ) pval[npan] = 0.0 ;        /* set bottom level */
01779      else      pval[npan] = -pval[0] ;
01780 
01781    } else {     /* 03 Feb 2003: get topval and colorscale_name */
01782 
01783      str[0] = '\0' ; val = 0.0 ;
01784      sscanf( cmd+dadd , "%f %s" , &val, str ) ;
01785      if( val <= 0.0 ) RETURN(-1) ;
01786 
01787      flip = ( strstr(cmd+dadd,"FLIP") != NULL ) ;
01788 
01789      cpt = strstr(cmd+dadd,"ROTA=") ;
01790      if( cpt == NULL ) cpt = strstr(cmd+dadd,"ROTA:") ;
01791      if( cpt != NULL ) sscanf(cpt+5,"%d",&rota) ;
01792    }
01793 
01794    /* now set pbar values (and other widgets) */
01795 
01796    im3d->vinfo->use_posfunc = pbar->mode = pos ;
01797    MCW_set_bbox( im3d->vwid->func->inten_bbox , pos ) ;
01798    AV_assign_ival( im3d->vwid->func->inten_av , npan ) ;
01799 
01800    HIDE_SCALE(im3d) ;
01801    if( npan <= NPANE_MAX ){         /* set discrete panels */
01802      for( ii=0 ; ii < npan ; ii++ ){
01803        pbar->ov_index[ii] = pbar->ovin_save[npan][ii][pos] = pcol[ii] ;
01804        PBAR_set_panecolor( pbar , ii , pcol[ii] ) ;
01805      }
01806      pbar->bigmode = 0 ;
01807      alter_MCW_pbar( pbar , npan , pval ) ;
01808      AFNI_hintize_pbar( pbar , (im3d->vinfo->fim_range != 0.0)
01809                                 ? im3d->vinfo->fim_range
01810                                 : im3d->vinfo->fim_autorange ) ;
01811      NORMAL_cursorize( pbar->panew ) ;  /* 08 Apr 2005 */
01812    } else {    /* set the colorscale */
01813      float pmax, pmin ;
01814      pbar->bigset = 0 ;
01815      pmax = val ; pmin = (pbar->mode) ? 0.0 : -pmax ;
01816      PBAR_set_bigmode( pbar , 1 , pmin,pmax ) ;
01817      PBAR_set_bigmap( pbar , str ) ;
01818      rotate_MCW_pbar( pbar , rota ) ;  /* 07 Feb 2004 */
01819      if( flip ) PBAR_flip( pbar ) ;    /* 07 Feb 2004 */
01820      AFNI_inten_pbar_CB( pbar , im3d , 0 ) ;
01821      POPUP_cursorize( pbar->panew ) ;  /* 08 Apr 2005 */
01822    }
01823    FIX_SCALE_SIZE(im3d) ;
01824 
01825    RETURN(0) ;
01826 }
01827 
01828 /*-------------------------------------------------------------------------*/
01829 /*! PBAR_ROTATE [c.]{+|-}
01830    "PBAR_ROTATE A.+"
01831 ---------------------------------------------------------------------------*/
01832 
01833 static int AFNI_drive_pbar_rotate( char *cmd )
01834 {
01835    int ic , dadd=2 , nn ;
01836    MCW_pbar *pbar ;
01837    Three_D_View *im3d ;
01838 
01839 ENTRY("AFNI_drive_pbar_rotate") ;
01840 
01841    if( cmd == NULL || strlen(cmd) < 1 ) RETURN(-1) ;
01842 
01843    ic = AFNI_controller_code_to_index( cmd ) ;
01844    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01845 
01846    im3d = GLOBAL_library.controllers[ic] ;
01847    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01848 
01849    /* get sign */
01850 
01851    switch( cmd[dadd] ){
01852      default: RETURN(-1) ;
01853      case '+': nn =  1 ; break ;
01854      case '-': nn = -1 ; break ;
01855    }
01856 
01857    rotate_MCW_pbar( im3d->vwid->func->inten_pbar , nn ) ;
01858    RETURN(0) ;
01859 }
01860 
01861 /*-------------------------------------------------------------------------*/
01862 /*! SET_FUNC_AUTORANGE [c.]{+|-}
01863    "SET_FUNC_AUTORANGE A.+"
01864 ---------------------------------------------------------------------------*/
01865 
01866 static int AFNI_set_func_autorange( char *cmd )
01867 {
01868    int ic , dadd=2 , nn ;
01869    Three_D_View *im3d ;
01870 
01871 ENTRY("AFNI_set_func_autorange") ;
01872 
01873    if( cmd == NULL || strlen(cmd) < 1 ) RETURN(-1) ;
01874 
01875    ic = AFNI_controller_code_to_index( cmd ) ;
01876    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01877 
01878    im3d = GLOBAL_library.controllers[ic] ;
01879    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01880 
01881    switch( cmd[dadd] ){
01882      default: RETURN(-1) ;
01883      case '+': nn = 1 ; break ;
01884      case '-': nn = 0 ; break ;
01885    }
01886 
01887    MCW_set_bbox( im3d->vwid->func->range_bbox , nn ) ;
01888    AFNI_range_bbox_CB( im3d->vwid->func->range_bbox->wbut[RANGE_AUTOBUT] ,
01889                        im3d , NULL ) ;
01890    RETURN(0) ;
01891 }
01892 
01893 /*-------------------------------------------------------------------------*/
01894 /*! SET_FUNC_RANGE [c.]value
01895    "SET_FUNC_RANGE A.0.3333"
01896 ---------------------------------------------------------------------------*/
01897 
01898 static int AFNI_set_func_range( char *cmd )
01899 {
01900    int ic , dadd=2 ;
01901    Three_D_View *im3d ;
01902    float val ;
01903 
01904 ENTRY("AFNI_set_func_range") ;
01905 
01906    if( cmd == NULL || strlen(cmd) < 1 ) RETURN(-1) ;
01907 
01908    ic = AFNI_controller_code_to_index( cmd ) ;
01909    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01910 
01911    im3d = GLOBAL_library.controllers[ic] ;
01912    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01913 
01914    val = strtod( cmd+dadd , NULL ) ;
01915    if( val <  0.0 ) RETURN(-1) ;
01916 
01917    if( val == 0.0 ){
01918      char clabel[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
01919      char str[8] ;
01920      sprintf(str,"%c.+",clabel[ic]) ;
01921      RETURN( AFNI_set_func_autorange(str) ) ;
01922    }
01923 
01924    MCW_set_bbox( im3d->vwid->func->range_bbox , 0 ) ;   /* autoRange box off */
01925    im3d->vinfo->use_autorange = 0 ;
01926 
01927    AV_SENSITIZE( im3d->vwid->func->range_av , 1 ) ;
01928    AV_assign_fval( im3d->vwid->func->range_av , val ) ;
01929    AFNI_range_av_CB( im3d->vwid->func->range_av , im3d ) ;
01930    RETURN(0) ;
01931 }
01932 
01933 /*-------------------------------------------------------------------------*/
01934 /*! SET_FUNC_VISIBLE [c.]{+|-}
01935    "SET_FUNC_VISIBLE A.+"
01936 ---------------------------------------------------------------------------*/
01937 
01938 static int AFNI_set_func_visible( char *cmd )
01939 {
01940    int ic , dadd=2 , nn ;
01941    Three_D_View *im3d ;
01942 
01943 ENTRY("AFNI_set_func_visible") ;
01944 
01945    if( cmd == NULL || strlen(cmd) < 1 ) RETURN(-1) ;
01946 
01947    ic = AFNI_controller_code_to_index( cmd ) ;
01948    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01949 
01950    im3d = GLOBAL_library.controllers[ic] ;
01951    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01952 
01953    switch( cmd[dadd] ){
01954      default: RETURN(-1) ;
01955      case '+': nn = 1 ; break ;
01956      case '-': nn = 0 ; break ;
01957    }
01958 
01959    MCW_set_bbox( im3d->vwid->view->see_func_bbox , nn ) ;
01960    AFNI_see_func_CB( NULL , im3d , NULL ) ;
01961    RETURN(0) ;
01962 }
01963 
01964 /*-------------------------------------------------------------------------*/
01965 /*! SET_FUNC_RESAM [c.]{NN|Li|Cu|Bk}.{NN|Li|Cu|Bk}
01966    "SET_FUNC_RESAM A.Li.Li"
01967 ---------------------------------------------------------------------------*/
01968 
01969 static int AFNI_set_func_resam( char *cmd )
01970 {
01971    int ic , dadd=2 , fr=-1 , tr=-1 ;
01972    Three_D_View *im3d ;
01973 
01974 ENTRY("AFNI_set_func_resam") ;
01975 
01976    if( cmd == NULL || strlen(cmd) < 2 ) RETURN(-1) ;
01977 
01978    ic = AFNI_controller_code_to_index( cmd ) ;
01979    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
01980 
01981    im3d = GLOBAL_library.controllers[ic] ;
01982    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
01983 
01984         if( cmd[dadd] == 'N' && cmd[dadd+1] == 'N' ) fr = 0 ;
01985    else if( cmd[dadd] == 'L' && cmd[dadd+1] == 'i' ) fr = 1 ;
01986    else if( cmd[dadd] == 'C' && cmd[dadd+1] == 'u' ) fr = 2 ;
01987    else if( cmd[dadd] == 'B' && cmd[dadd+1] == 'k' ) fr = 2 ;
01988    else                                              RETURN(-1);
01989 
01990    if( cmd[dadd+2] == '.' ){
01991      dadd += 3 ;
01992           if( cmd[dadd] == 'N' && cmd[dadd+1] == 'N' ) tr = 0 ;
01993      else if( cmd[dadd] == 'L' && cmd[dadd+1] == 'i' ) tr = 1 ;
01994      else if( cmd[dadd] == 'C' && cmd[dadd+1] == 'u' ) tr = 2 ;
01995      else if( cmd[dadd] == 'B' && cmd[dadd+1] == 'k' ) tr = 2 ;
01996      else                                              RETURN(-1);
01997    }
01998 
01999    AV_assign_ival( im3d->vwid->dmode->func_resam_av , fr ) ;
02000    im3d->vinfo->func_resam_mode = fr ;
02001    if( im3d->b123_fim != NULL )
02002      im3d->b123_fim->resam_code =
02003       im3d->b231_fim->resam_code =
02004        im3d->b312_fim->resam_code = im3d->vinfo->func_resam_mode ;
02005 
02006    if( tr >= 0 ){
02007      AV_assign_ival( im3d->vwid->dmode->thr_resam_av , fr ) ;
02008      im3d->vinfo->thr_resam_mode = tr ;
02009      if( im3d->b123_fim != NULL )
02010        im3d->b123_fim->thr_resam_code =
02011         im3d->b231_fim->thr_resam_code =
02012          im3d->b312_fim->thr_resam_code = im3d->vinfo->thr_resam_mode ;
02013    }
02014 
02015    AFNI_resam_av_CB( NULL , im3d ) ;
02016    RETURN(0) ;
02017 }
02018 
02019 /*------------------------------------------------------------------*/
02020 /*! SLEEP msec */
02021 
02022 static int AFNI_sleeper( char *cmd )
02023 {
02024    int ms=-1 ;
02025    if( cmd == NULL || strlen(cmd) < 1 ) return(-1) ;
02026    sscanf( cmd , "%d" , &ms ) ;
02027    if( ms > 0 ) RWC_sleep( ms ) ;
02028    return(0) ;
02029 }
02030 
02031 #if 0   /** code removed to afni_environ.c on 03 Jun 2005 **/
02032 /*------------------------------------------------------------------*/
02033 /*! SETENV name value */
02034 
02035 int AFNI_setenv( char *cmd )
02036 {
02037    char nam[256]="\0" , val[1024]="\0" , eqn[1280] , *eee ;
02038 
02039    if( cmd == NULL || strlen(cmd) < 3 ) return(-1) ;
02040 
02041    sscanf( cmd , "%255s %1023s" , nam , val ) ;
02042    if( nam[0] == '\0' || val[0] == '\0' && strchr(cmd,'=') != NULL ){
02043      char *ccc = strdup(cmd) ;
02044      eee = strchr(ccc,'=') ; *eee = ' ' ;
02045      sscanf( ccc , "%255s %1023s" , nam , val ) ;
02046      free((void *)ccc) ;
02047    }
02048    if( nam[0] == '\0' || val[0] == '\0' ) return(-1) ;
02049 
02050    sprintf(eqn,"%s=%s",nam,val) ;
02051    eee = strdup(eqn) ; putenv(eee) ;
02052    return(0) ;
02053 }
02054 #endif
02055 
02056 /*------------------------------------------------------------------*/
02057 /*! REDISPLAY */
02058 
02059 static int AFNI_redisplay( char *cmd )
02060 {
02061    int cc ;
02062    Three_D_View *qq3d ;
02063 
02064    for( cc=0 ; cc < MAX_CONTROLLERS ; cc++ ){
02065       qq3d = GLOBAL_library.controllers[cc] ;
02066       if( ! IM3D_OPEN(qq3d) ) continue ;
02067       AFNI_set_viewpoint( qq3d , -1,-1,-1 , REDISPLAY_OVERLAY ) ;
02068    }
02069    return(0) ;
02070 }
02071 
02072 /*--------------------------------------------------------------------*/
02073 /*! DEFINE_COLORSCALE name num=color num=color ... */
02074 
02075 static int AFNI_define_colorscale( char *cmd )
02076 {
02077   return PBAR_define_bigmap( cmd ) ;
02078 }
02079 
02080 /*---------------------------------------------------------------------*/
02081 /*! OPEN_PANEL [c.]Define_Function, etc. */
02082 
02083 static int AFNI_open_panel( char *cmd )
02084 {
02085    int ic , dadd=2 , fr=-1 , tr=-1 ;
02086    Three_D_View *im3d ;
02087 
02088 ENTRY("AFNI_open_panel") ;
02089 
02090    if( cmd == NULL || strlen(cmd) < 2 ) RETURN(-1) ;
02091 
02092    ic = AFNI_controller_code_to_index( cmd ) ;
02093    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
02094 
02095    im3d = GLOBAL_library.controllers[ic] ;
02096    if( !IM3D_OPEN(im3d) ) RETURN(-1) ;
02097 
02098    /* do the right thing (simulate a button press) */
02099 
02100    if( strcmp(cmd+dadd,"Define_Function") == 0 || strcmp(cmd+dadd,"Define_Overlay") == 0 ){
02101      if( !XtIsManaged(im3d->vwid->func->frame) )
02102        AFNI_define_CB( im3d->vwid->view->define_func_pb, im3d, NULL ) ;
02103    } else if( strcmp(cmd+dadd,"Define_Datamode") == 0 ){
02104      if( !XtIsManaged(im3d->vwid->dmode->frame) )
02105        AFNI_define_CB( im3d->vwid->view->define_dmode_pb, im3d, NULL ) ;
02106    } else if( strcmp(cmd+dadd,"Define_Markers")  == 0 ){
02107      if( !XtIsManaged(im3d->vwid->marks->frame) )
02108        AFNI_define_CB( im3d->vwid->view->define_marks_pb, im3d, NULL ) ;
02109    } else {
02110      RETURN(-1) ;
02111    }
02112    RETURN(0) ;
02113 }
02114 
02115 /*--------------------------------------------------------------------*/
02116 /*! SAVE_JPEG [c.]imagewindowname fname */
02117 
02118 static int AFNI_drive_save_jpeg( char *cmd )
02119 {
02120    int ic , dadd=2 ;
02121    Three_D_View *im3d ;
02122    char junk[256] , fname[288] ;
02123    MCW_imseq   *isq=NULL ;
02124    MCW_grapher *gra=NULL ;
02125 
02126 ENTRY("AFNI_drive_save_jpeg") ;
02127 
02128    /* make sure the controller itself is open */
02129 
02130    if( strlen(cmd) < 3 ) RETURN(-1) ;
02131 
02132    ic = AFNI_controller_code_to_index( cmd ) ;
02133    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
02134 
02135    im3d = GLOBAL_library.controllers[ic] ;
02136    if( !IM3D_OPEN(im3d) ){
02137      ERROR_message("SAVE_JPEG %s: controller not open",cmd); RETURN(-1);
02138    }
02139 
02140    /* extract the filename to save into */
02141 
02142    junk[0] = fname[0] = '\0' ;
02143    sscanf( cmd+dadd , "%255s%255s" , junk , fname ) ;
02144    if( junk[0] == '\0' || fname[0] == '\0' ){
02145      ERROR_message("SAVE_JPEG %s: something is missing",cmd); RETURN(-1);
02146      RETURN(-1) ;
02147    }
02148 
02149    if( !STRING_HAS_SUFFIX(fname,".jpg") && !STRING_HAS_SUFFIX(fname,".JPG") )
02150      strcat(fname,".jpg") ;
02151 
02152    /* find graph or image window */
02153 
02154         if( strstr(cmd+dadd,"axialimage")    != NULL ) isq = im3d->s123 ;
02155    else if( strstr(cmd+dadd,"sagittalimage") != NULL ) isq = im3d->s231 ;
02156    else if( strstr(cmd+dadd,"coronalimage")  != NULL ) isq = im3d->s312 ;
02157    else if( strstr(cmd+dadd,"axialgraph")    != NULL ) gra = im3d->g123 ;
02158    else if( strstr(cmd+dadd,"sagittalgraph") != NULL ) gra = im3d->g231 ;
02159    else if( strstr(cmd+dadd,"coronalgraph")  != NULL ) gra = im3d->g312 ;
02160 
02161    XmUpdateDisplay( im3d->vwid->top_shell ) ;
02162 
02163    if( isq != NULL ){
02164      drive_MCW_imseq( isq, isqDR_save_jpeg , (XtPointer)fname ) ;
02165    } else if( gra != NULL ){
02166      GRA_file_pixmap( gra , fname ) ;
02167    } else {
02168      ERROR_message("SAVE_JPEG %s: don't understand windowname",cmd) ;
02169      RETURN(-1) ;
02170    }
02171 
02172    RETURN(0) ;
02173 }
02174 
02175 /*--------------------------------------------------------------------*/
02176 /*! SET_VIEW [c.]viewname */
02177 
02178 static int AFNI_drive_set_view( char *cmd )
02179 {
02180    int ic , vv=-1 ;
02181    Three_D_View *im3d ;
02182 
02183    if( strlen(cmd) < 3 ) return -1;
02184 
02185    ic = AFNI_controller_code_to_index( cmd ) ;
02186    if( ic < 0 ) ic = 0 ;
02187    im3d = GLOBAL_library.controllers[ic] ;
02188    if( !IM3D_OPEN(im3d) ) return -1 ;
02189 
02190         if( strstr(cmd,"orig") != NULL ) vv = VIEW_ORIGINAL_TYPE ;
02191    else if( strstr(cmd,"acpc") != NULL ) vv = VIEW_ACPCALIGNED_TYPE ;
02192    else if( strstr(cmd,"tlrc") != NULL ) vv = VIEW_TALAIRACH_TYPE ;
02193    else                                  return -1 ;
02194 
02195    if( vv == im3d->vinfo->view_type ) return 0 ;  /* nothing to do */
02196    if( !XtIsSensitive(im3d->vwid->view->view_bbox->wbut[vv]) ) return -1 ;
02197 
02198    MCW_set_bbox( im3d->vwid->view->view_bbox , 1 << vv ) ;
02199    AFNI_switchview_CB( NULL , (XtPointer)im3d , NULL ) ;
02200    return 0 ;
02201 }
02202 
02203 /*--------------------------------------------------------------------*/
02204 /*! SET_DICOM_XYZ [c.] x y z */
02205 
02206 static int AFNI_drive_set_dicom_xyz( char *cmd )
02207 {
02208    int ic , dadd=2 ;
02209    Three_D_View *im3d ;
02210    float x,y,z ;
02211 
02212    if( strlen(cmd) < 3 ) return -1;
02213 
02214    ic = AFNI_controller_code_to_index( cmd ) ;
02215    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
02216    im3d = GLOBAL_library.controllers[ic] ;
02217    if( !IM3D_OPEN(im3d) ) return -1 ;
02218 
02219    ic = sscanf( cmd+dadd , "%f%f%f" , &x,&y,&z ) ;
02220    if( ic < 3 ) return -1 ;
02221    AFNI_jumpto_dicom( im3d , x,y,z ) ;
02222    return 0 ;
02223 }
02224 
02225 /*--------------------------------------------------------------------*/
02226 /*! SET_SPM_XYZ [c.] x y z */
02227 
02228 static int AFNI_drive_set_spm_xyz( char *cmd )
02229 {
02230    int ic , dadd=2 ;
02231    Three_D_View *im3d ;
02232    float x,y,z ;
02233 
02234    if( strlen(cmd) < 3 ) return -1;
02235 
02236    ic = AFNI_controller_code_to_index( cmd ) ;
02237    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
02238    im3d = GLOBAL_library.controllers[ic] ;
02239    if( !IM3D_OPEN(im3d) ) return -1 ;
02240 
02241    ic = sscanf( cmd+dadd , "%f%f%f" , &x,&y,&z ) ;
02242    if( ic < 3 ) return -1 ;
02243    AFNI_jumpto_dicom( im3d , -x,-y,z ) ;
02244    return 0 ;
02245 }
02246 
02247 /*--------------------------------------------------------------------*/
02248 /*! SET_IJK [c.] i j k */
02249 
02250 static int AFNI_drive_set_ijk( char *cmd )
02251 {
02252    int ic , dadd=2 ;
02253    Three_D_View *im3d ;
02254    int i,j,k ;
02255 
02256    if( strlen(cmd) < 3 ) return -1;
02257 
02258    ic = AFNI_controller_code_to_index( cmd ) ;
02259    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
02260    im3d = GLOBAL_library.controllers[ic] ;
02261    if( !IM3D_OPEN(im3d) ) return -1 ;
02262 
02263    ic = sscanf( cmd+dadd , "%d%d%d" , &i,&j,&k ) ;
02264    if( ic < 3 ) return -1 ;
02265    AFNI_set_viewpoint( im3d , i,j,k , REDISPLAY_ALL ) ;
02266    return 0 ;
02267 }
02268 
02269 /*--------------------------------------------------------------------*/
02270 /*! SET_XHAIRS [c.]code */
02271 
02272 static int AFNI_drive_set_xhairs( char *cmd )
02273 {
02274    int ic , dadd=2 , hh=-1 ;
02275    Three_D_View *im3d ;
02276    int i,j,k ;
02277 
02278    if( strlen(cmd) < 3 ) return -1;
02279 
02280    ic = AFNI_controller_code_to_index( cmd ) ;
02281    if( ic < 0 ){ ic = 0 ; dadd = 0 ; }
02282    im3d = GLOBAL_library.controllers[ic] ;
02283    if( !IM3D_OPEN(im3d) ) return -1 ;
02284 
02285         if( strstr(cmd,"OFF")    != NULL ) hh = 0 ;
02286    else if( strstr(cmd,"SINGLE") != NULL ) hh = 1 ;
02287    else if( strstr(cmd,"MULTI")  != NULL ) hh = 2 ;
02288    else if( strstr(cmd,"LR_AP")  != NULL ) hh = 3 ;
02289    else if( strstr(cmd,"LR_IS")  != NULL ) hh = 4 ;
02290    else if( strstr(cmd,"AP_IS")  != NULL ) hh = 5 ;
02291    else if( strstr(cmd,"LR")     != NULL ) hh = 6 ;
02292    else if( strstr(cmd,"AP")     != NULL ) hh = 7 ;
02293    else if( strstr(cmd,"IS")     != NULL ) hh = 8 ;
02294    else                                    return -1 ;
02295 
02296    AV_assign_ival( im3d->vwid->imag->crosshair_av, hh ) ;
02297    AFNI_crosshair_visible_CB( im3d->vwid->imag->crosshair_av, (XtPointer)im3d );
02298    return 0 ;
02299 }
 

Powered by Plone

This site conforms to the following standards: