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 #include "thd.h"
9
10 /*****************************************************************
11 A datablock contains the information needed to access the
12 data in memory.
13 ******************************************************************/
14
15 /*---------------------------------------------------------------
16 Count the number of in-memory sub-bricks actually stored in
17 a datablock at this instant. Returns -1 if an error.
18 -----------------------------------------------------------------*/
19
THD_count_databricks(THD_datablock * dblk)20 int THD_count_databricks( THD_datablock * dblk )
21 {
22 int ibr , count ;
23
24 if( ! ISVALID_DATABLOCK(dblk) || dblk->brick == NULL ) return -1 ;
25
26 count = 0 ;
27 for( ibr=0 ; ibr < dblk->nvals ; ibr++ )
28 if( DBLK_BRICK(dblk,ibr) != NULL && DBLK_ARRAY(dblk,ibr) != NULL )
29 count++ ;
30
31 return count ;
32 }
33
34 /*---------------------------------------------------------------*/
35
THD_count_potential_databricks(THD_datablock * dblk)36 int THD_count_potential_databricks( THD_datablock * dblk )
37 {
38 int ibr , count ;
39
40 if( ! ISVALID_DATABLOCK(dblk) || dblk->brick == NULL ) return -1 ;
41
42 count = 0 ;
43 for( ibr=0 ; ibr < dblk->nvals ; ibr++ )
44 if( MRI_HAS_DATA(DBLK_BRICK(dblk,ibr)) ) count++ ;
45
46 return count ;
47 }
48
49 /*---------------------------------------------------------------*/
50
THD_subset_loaded(THD_3dim_dataset * dset,int nb,int * bb)51 int THD_subset_loaded( THD_3dim_dataset *dset , int nb , int *bb )
52 {
53 int ii,kk , nvals ;
54
55 if( !ISVALID_DSET(dset) || nb <= 0 || bb == NULL ) return 0 ;
56 nvals = DSET_NVALS(dset) ;
57
58 for( ii=0 ; ii < nb ; ii++ ){
59 kk = bb[ii] ; if( kk < 0 || kk >= nvals ) return 0 ;
60 if( !DSET_BRICK_LOADED(dset,kk) ) return 0 ;
61 }
62 return 1 ;
63 }
64