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  

SUMA_ProgramTemplate.c

Go to the documentation of this file.
00001 /*USE This sample to start writing standalone programs.
00002 Change PROGRAM_NAME to the program name of your choosing.
00003 */
00004 #include "SUMA_suma.h"
00005 
00006 SUMA_SurfaceViewer *SUMAg_cSV = NULL; /*!< Global pointer to current Surface Viewer structure*/
00007 SUMA_SurfaceViewer *SUMAg_SVv = NULL; /*!< Global pointer to the vector containing the various Surface Viewer Structures 
00008                                     SUMAg_SVv contains SUMA_MAX_SURF_VIEWERS structures */
00009 int SUMAg_N_SVv = 0; /*!< Number of SVs realized by X */
00010 SUMA_DO *SUMAg_DOv = NULL;   /*!< Global pointer to Displayable Object structure vector*/
00011 int SUMAg_N_DOv = 0; /*!< Number of DOs stored in DOv */
00012 SUMA_CommonFields *SUMAg_CF = NULL; /*!< Global pointer to structure containing info common to all viewers */
00013 
00014 void usage_PROGRAM_NAME (SUMA_GENERIC_ARGV_PARSE *ps)
00015 {
00016       static char FuncName[]={"usage_PROGRAM_NAME"};
00017       char * s = NULL, *sio=NULL, *st = NULL, *sts = NULL;
00018       int i;
00019       s = SUMA_help_basics();
00020       sio  = SUMA_help_IO_Args(ps);
00021       printf ( "\n"
00022                "Usage: A template code for writing SUMA programs.\n"
00023                " \n"
00024                "%s"
00025                "%s"
00026                "\n", sio,  s);
00027       SUMA_free(s); s = NULL; SUMA_free(st); st = NULL; SUMA_free(sio); sio = NULL;       
00028       s = SUMA_New_Additions(0, 1); printf("%s\n", s);SUMA_free(s); s = NULL;
00029       printf("       Ziad S. Saad SSCC/NIMH/NIH ziad@nih.gov     \n");
00030       exit(0);
00031 }
00032 
00033 SUMA_GENERIC_PROG_OPTIONS_STRUCT *SUMA_PROGRAM_NAME_ParseInput(char *argv[], int argc, SUMA_GENERIC_ARGV_PARSE *ps)
00034 {
00035    static char FuncName[]={"SUMA_BrainWrap_ParseInput"}; 
00036    SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt=NULL;
00037    int kar;
00038    SUMA_Boolean brk;
00039    SUMA_Boolean LocalHead = NOPE;
00040 
00041    SUMA_ENTRY;
00042    
00043    Opt = SUMA_Alloc_Generic_Prog_Options_Struct();
00044    kar = 1;
00045    brk = NOPE;
00046         while (kar < argc) { /* loop accross command ine options */
00047                 /*fprintf(stdout, "%s verbose: Parsing command line...\n", FuncName);*/
00048                 if (strcmp(argv[kar], "-h") == 0 || strcmp(argv[kar], "-help") == 0) {
00049                          usage_PROGRAM_NAME(ps);
00050           exit (0);
00051                 }
00052                 
00053                 SUMA_SKIP_COMMON_OPTIONS(brk, kar);
00054       
00055       if (!brk && (strcmp(argv[kar], "-debug") == 0))
00056       {
00057          if (kar+1 >= argc)
00058          {
00059             fprintf (SUMA_STDERR, "need a number after -debug \n");
00060             exit (1);
00061          }
00062          
00063          Opt->debug = atoi(argv[++kar]);
00064          brk = YUP;
00065       }
00066       
00067       if (!brk && !ps->arg_checked[kar]) {
00068                         fprintf (SUMA_STDERR,"Error %s:\nOption %s not understood. Try -help for usage\n", FuncName, argv[kar]);
00069                         exit (1);
00070                 } else {        
00071                         brk = NOPE;
00072                         kar ++;
00073                 }
00074    }
00075    
00076    SUMA_RETURN(Opt);
00077 }
00078 
00079 int main (int argc,char *argv[])
00080 {/* Main */    
00081    static char FuncName[]={"PROGRAM_NAME"}; 
00082    SUMA_GENERIC_PROG_OPTIONS_STRUCT *Opt;  
00083    SUMA_GENERIC_ARGV_PARSE *ps=NULL;
00084    SUMA_Boolean LocalHead = NOPE;
00085 
00086         SUMA_mainENTRY;
00087    SUMA_STANDALONE_INIT;
00088 
00089    /* Allocate space for DO structure */
00090         SUMAg_DOv = SUMA_Alloc_DisplayObject_Struct (SUMA_MAX_DISPLAYABLE_OBJECTS);
00091    ps = SUMA_Parse_IO_Args(argc, argv, "-o;-talk;");
00092    
00093    if (argc < 2) {
00094       usage_PROGRAM_NAME(ps);
00095       exit (1);
00096    }
00097    
00098    Opt = SUMA_PROGRAM_NAME_ParseInput (argv, argc, ps);
00099 
00100    if (Opt->debug > 2) LocalHead = YUP;
00101 
00102    if (ps) SUMA_FreeGenericArgParse(ps); ps = NULL;
00103    if (Opt) Opt = SUMA_Free_Generic_Prog_Options_Struct(Opt);
00104    if (!SUMA_Free_CommonFields(SUMAg_CF)) SUMA_error_message(FuncName,"SUMAg_CF Cleanup Failed!",1);
00105    exit(0);
00106    
00107 } 
 

Powered by Plone

This site conforms to the following standards: