1 #include "mrilib.h"
2 
3 /*-----------------------------------------------------------------*/
4 /*! Convert this dataset to float format, in place.                */
5 /*  Scale factors will always be applied, even for floats.         */
6 
EDIT_floatize_dataset(THD_3dim_dataset * dset)7 void EDIT_floatize_dataset( THD_3dim_dataset *dset )
8 {
9    int nvals , iv ;
10    MRI_IMAGE *bim , *qim ;
11    float      bfac, *qar ;
12 
13 ENTRY("EDIT_floatize_dataset") ;
14 
15    if( !ISVALID_DSET(dset) ) EXRETURN ;
16 
17    DSET_mallocize(dset) ;
18    DSET_load(dset) ;
19    if( !DSET_LOADED(dset) ){
20      ERROR_message("Can't load dataset '%s' for floatize",DSET_BRIKNAME(dset));
21      EXRETURN ;
22    }
23 
24    nvals = DSET_NVALS(dset) ;
25    for( iv=0 ; iv < nvals ; iv++ ){
26      bim  = DSET_BRICK(dset,iv) ;
27      bfac = DSET_BRICK_FACTOR(dset,iv) ;
28      /* still "scale" a float dataset if there are factors to apply
29         (as they are cleared after the loop)   11 Sep, 2015 [rickr] */
30      if( bim->kind == MRI_float && (bfac == 1.0 || bfac == 0.0) )
31         continue ; /* already floatized */
32      qim  = mri_scale_to_float( bfac , bim ) ;
33      qar  = MRI_FLOAT_PTR(qim) ;
34      EDIT_substitute_brick( dset , iv , MRI_float , qar ) ;
35      mri_clear_data_pointer(qim); mri_free(qim) ;
36    }
37    EDIT_dset_items( dset , ADN_brick_fac,NULL , ADN_none ) ;
38 
39    EXRETURN ;
40 }
41 
42 /*-----------------------------------------------------------------*/
43 /*! Return type of all bricks, if they are the same, or -1 if not. */
44 
DSET_pure_type(THD_3dim_dataset * dset)45 int DSET_pure_type( THD_3dim_dataset *dset )
46 {
47    int nvals , iv , typ ;
48 
49 ENTRY("DSET_pure_type") ;
50 
51    if( !ISVALID_DSET(dset) ) RETURN(-1) ;
52 
53    nvals = DSET_NVALS(dset) ;
54    typ   = (int)DSET_BRICK_TYPE(dset,0) ;
55    for( iv=1 ; iv < nvals ; iv++ )
56      if( (int)DSET_BRICK_TYPE(dset,iv) != typ ) RETURN(-1) ;
57 
58    RETURN(typ) ;
59 }
60