1 /*****************************************************************************
2    Major portions of this software are copyrighted by the Medical College
3    of Wisconsin, 1994-2000, and are released under the Gnu General Public
4    License, Version 2.  See the file README.Copyright for details.
5 ******************************************************************************/
6 
7 #include "mrilib.h"
8 
Syntax(void)9 void Syntax(void)
10 {
11    printf(
12     "Usage: 3dnvals [-all] [-verbose] dataset [dataset dataset ...]\n"
13     "* Prints (to stdout) the number of sub-bricks in a 3D dataset.\n"
14     "* If -all is specified, prints out all 4 dimensions:\n"
15     "    Nx, Ny, Nz, Nvals\n"
16     "* If -verbose is used then the header name of the dataset is printed first.\n"
17     "* The function of this simple program is to help in scripting.\n"
18    ) ;
19    PRINT_COMPILE_DATE ; exit(0) ;
20 }
21 
22 /*---------------------------------------------------------------------------*/
23 
main(int argc,char * argv[])24 int main( int argc , char * argv[] )
25 {
26    THD_3dim_dataset * dset ;
27    int iarg , all = 0, verbose = 0, cnt = 0;
28    int rval = -1;  /* exit(1) if all datasets fail   7 Apr 2015 [rickr] */
29 
30    if( argc < 2 || strncmp(argv[1],"-help",4) == 0 ) Syntax() ;
31 
32    iarg = 1 ;
33    cnt = 1;
34    while (cnt < argc) {
35       if( strncmp(argv[iarg],"-all",4) == 0 ){ all = 1 ; iarg++ ; }
36       else if( strncmp(argv[iarg],"-verbose",5) == 0 ){ verbose = 1 ; iarg++ ; }
37       ++cnt;
38    }
39    for( ; iarg < argc ; iarg++ ){
40       dset = THD_open_dataset( argv[iarg] ) ;
41       if( dset == NULL ){
42          if ( rval == -1 ) rval = 1; /* if unset, set bad exit code */
43          printf("-1\n") ;
44          continue ;
45       }
46       rval = 0; /* set good exit code */
47       if (!all) {
48          if (verbose) {
49             printf("%s: %d\n",
50                      DSET_HEADNAME(dset),
51                      DSET_NVALS(dset)) ;
52          } else {
53             printf("%d\n",DSET_NVALS(dset)) ;
54          }
55       } else {
56          if (verbose) {
57             printf("%s: %d %d %d %d\n",
58                      DSET_HEADNAME(dset),
59                      DSET_NX(dset), DSET_NY(dset), DSET_NZ(dset),
60                      DSET_NVALS(dset)) ;
61          } else {
62             printf("%d %d %d %d\n",
63                      DSET_NX(dset), DSET_NY(dset), DSET_NZ(dset),
64                      DSET_NVALS(dset)) ;
65          }
66       }
67       THD_delete_3dim_dataset( dset , False ) ;
68    }
69 
70    if( rval == -1 ) exit(0) ; /* unset rval is okay */
71    exit(rval) ;
72 }
73