src/conv/vdicom/i2o_dcm.cpp
//
// try to read an integer value from a dicom data field
//
try to read an integer value from a dicom data field
try to read an integer value from a dicom data field
int
GetValue(char* b, char* vr, int len)
{
  if( vr[0] == '\0' ) 
    {
      bool  isAscii = true;
      short  digits = 0;
      for( int i=0; i < len && b[i] != ' '; i++ )
	if( b[i] < '0' || b[i] > '9' )
	  {
	    isAscii = false;
	    break;
	  }
	else
	  digits++;
      if( isAscii )
	if( digits )
	  return atoi( b );
	else
	  {
	    cerr << "INTERNAL ERROR ! GetValue() empty string: len=" << len << ", VR=\"" << vr << "\"" << endl;
	    exit(1);
	  }
      else
	{
	  if( len == 1 )
	    return *(int8_t*)b;
	  if( len == 2 )
	    return *(int16_t*)b;
	  if (len == 4)
	    return *(int32_t*)b;
	}
    }
  else 
    { 
      if( vr[0] == 'S' && vr[1] == 'L' ) 
	return *(int32_t*)b;
      if( vr[0] == 'S' && vr[1] == 'S' ) 
	return *(int16_t*)b;
      if( vr[0] == 'U' && vr[1] == 'L' ) 
	return *(u_int32_t*)b;
      if( vr[0] == 'U' && vr[1] == 'S' ) 
	return *(u_int16_t*)b;
      return atoi( b );
    }
  cerr << "INTERNAL ERROR ! GetValue() unhandled case: len=" << len << ", VR=\"" << vr << "\"" << endl;
  exit(1);
}
int GetValue ( char * b , char * vr , int len ) { if ( vr [ 0 ] == ' \0 ' ) { bool isAscii = true ; short digits = 0 ; for ( int i = 0 ; i < len && b [ i ] != ' ' ; i ++ ) if ( b [ i ] < ' ' || b [ i ] > ' ' ) { isAscii = false ; break ; } else digits ++ ; if ( isAscii ) if ( digits ) return atoi ( b ) ; else { cerr << " " << len << " \" " << vr << " \" " << endl ; exit ( 1 ) ; } else { if ( len == 1 ) return * ( int8_t * ) b ; if ( len == 2 ) return * ( int16_t * ) b ; if ( len == 4 ) return * ( int32_t * ) b ; } } else { if ( vr [ 0 ] == ' ' && vr [ 1 ] == ' ' ) return * ( int32_t * ) b ; if ( vr [ 0 ] == ' ' && vr [ 1 ] == ' ' ) return * ( int16_t * ) b ; if ( vr [ 0 ] == ' ' && vr [ 1 ] == ' ' ) return * ( u_int32_t * ) b ; if ( vr [ 0 ] == ' ' && vr [ 1 ] == ' ' ) return * ( u_int16_t * ) b ; return atoi ( b ) ; } cerr << " " << len << " \" " << vr << " \" " << endl ; exit ( 1 ) ; }
try to read an integer value from a dicom data field
try to read an integer value from a dicom data field
// implicit VR, might be binary or ascii // explicit VR, use it // signed long // signed short // unsigned long // unsigned short