Doxygen Source Code Documentation
mri_fromstring.c File Reference
#include "mrilib.h"Go to the source code of this file.
Functions | |
| MRI_IMAGE * | mri_1D_fromstring (char *str) |
Function Documentation
|
|
Produce a 1D (float) image from a string of the form "20@1,10@0,5@1". ------------------------------------------------------------------------------- Definition at line 7 of file mri_fromstring.c. References ENTRY, far, free, malloc, mri_fix_data_pointer(), mri_new_vol_empty(), NI_decode_string_list(), NI_delete_str_array, NI_str_array::num, realloc, RETURN, and NI_str_array::str. Referenced by mri_read_1D(), and mri_read_ascii().
00008 {
00009 int ii,nnn,count , ntot=0 ;
00010 float *far , value ;
00011 NI_str_array *sar ;
00012 char sep ;
00013 MRI_IMAGE *flim ;
00014
00015 ENTRY("mri_1D_fromstring") ;
00016
00017 sar = NI_decode_string_list( str , ",;" ) ;
00018 if( sar == NULL ) RETURN(NULL) ;
00019 if( sar->num == 0 ){ NI_delete_str_array(sar); RETURN(NULL); }
00020
00021 far = (float *) malloc(sizeof(float)) ;
00022 for( ii=0 ; ii < sar->num ; ii++ ){
00023
00024 if( strstr(sar->str[ii],"@") != NULL || /* if has one of the */
00025 strstr(sar->str[ii],"x") != NULL || /* allowed separator */
00026 strstr(sar->str[ii],"X") != NULL || /* characters, then */
00027 strstr(sar->str[ii],"*") != NULL ){ /* scan for count@value */
00028
00029 nnn = sscanf( sar->str[ii] , "%d%c%f" , &count , &sep , &value ) ;
00030 if( nnn != 3 || count < 1 ){ free(far); RETURN(NULL); }
00031
00032 } else { /* just scan for value */
00033 count = 1 ;
00034 nnn = sscanf( sar->str[ii] , "%f" , &value ) ;
00035 if( nnn != 1 ){ free(far); RETURN(NULL); }
00036 }
00037
00038 far = (float *) realloc( far , sizeof(float)*(ntot+count) ) ;
00039 for( nnn=0 ; nnn < count ; nnn++ ) far[nnn+ntot] = value ;
00040 ntot += count ;
00041
00042 }
00043
00044 NI_delete_str_array(sar) ;
00045 flim = mri_new_vol_empty( ntot,1,1 , MRI_float ) ;
00046 mri_fix_data_pointer( far , flim ) ;
00047 RETURN(flim) ;
00048 }
|