Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_fromstring.c
Go to the documentation of this file.00001 #include "mrilib.h"
00002
00003
00004
00005
00006
00007 MRI_IMAGE * mri_1D_fromstring( char *str )
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 ||
00025 strstr(sar->str[ii],"x") != NULL ||
00026 strstr(sar->str[ii],"X") != NULL ||
00027 strstr(sar->str[ii],"*") != NULL ){
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 {
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 }