| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include <assert.h> |
| 26 |
#include <ctype.h> |
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "../biosig.h" |
| 31 |
|
| 32 |
#ifdef _WIN32 |
| 33 |
|
| 34 |
#include <sys/types.h> |
| 35 |
struct stat { |
| 36 |
_dev_t st_dev; |
| 37 |
_ino_t st_ino; |
| 38 |
unsigned short st_mode; |
| 39 |
short st_nlink; |
| 40 |
short st_uid; |
| 41 |
short st_gid; |
| 42 |
_dev_t st_rdev; |
| 43 |
_off_t st_size; |
| 44 |
time_t st_atime; |
| 45 |
time_t st_mtime; |
| 46 |
time_t st_ctime; |
| 47 |
}; |
| 48 |
int __cdecl stat(const char *_Filename,struct stat *_Stat); |
| 49 |
#else |
| 50 |
#include <sys/stat.h> |
| 51 |
#endif |
| 52 |
|
| 53 |
#define min(a,b) (((a) < (b)) ? (a) : (b)) |
| 54 |
#define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
#ifdef WITH_DCMTK |
| 60 |
#undef WITH_DICOM // disable internal DICOM implementation |
| 61 |
#undef WITH_GDCM // disable interface to GDCM |
| 62 |
|
| 63 |
#ifdef __cplusplus |
| 64 |
extern "C" { |
| 65 |
#endif |
| 66 |
|
| 67 |
int sopen_dcmtk_read(HDRTYPE* hdr); |
| 68 |
|
| 69 |
int sopen_dicom_read(HDRTYPE* hdr) { |
| 70 |
return sopen_dcmtk_read(hdr); |
| 71 |
} |
| 72 |
|
| 73 |
#ifdef __cplusplus |
| 74 |
} |
| 75 |
#endif |
| 76 |
|
| 77 |
#endif |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
#ifdef WITH_GDCM |
| 84 |
#undef WITH_DICOM |
| 85 |
|
| 86 |
#include "gdcmReader.h" |
| 87 |
|
| 88 |
|
| 89 |
#include "gdcmDataSet.h" |
| 90 |
#include "gdcmAttribute.h" |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
#include "gdcmFile.h" |
| 95 |
#include "gdcmFileMetaInformation.h" |
| 96 |
#include "gdcmWaveform.h" |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
int sopen_dicom_read(HDRTYPE* hdr) { |
| 129 |
|
| 130 |
fprintf(stdout,"%s ( line %d): GDCM is used to read dicom files.\n",__func__,__LINE__); |
| 131 |
|
| 132 |
gdcm::Reader reader; |
| 133 |
const gdcm::DataElement *de; |
| 134 |
reader.SetFileName( hdr->FileName ); |
| 135 |
if ( !reader.Read() ) { |
| 136 |
fprintf(stdout,"%s (line %i) \n",__FILE__,__LINE__); |
| 137 |
return 1; |
| 138 |
} |
| 139 |
|
| 140 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i)\n",__FILE__,__LINE__); |
| 141 |
gdcm::File &file = reader.GetFile(); |
| 142 |
gdcm::FileMetaInformation &header = file.GetHeader(); |
| 143 |
|
| 144 |
if ( header.FindDataElement( gdcm::Tag(0x0002, 0x0013 ) ) ) |
| 145 |
const gdcm::DataElement &de = header.GetDataElement( gdcm::Tag(0x0002, 0x0013) ); |
| 146 |
|
| 147 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i)\n",__FILE__,__LINE__); |
| 148 |
gdcm::DataSet &ds = file.GetDataSet(); |
| 149 |
|
| 150 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i)\n",__FILE__,__LINE__); |
| 151 |
if ( header.FindDataElement( gdcm::Tag(0x0002, 0x0010 ) ) ) |
| 152 |
de = &header.GetDataElement( gdcm::Tag(0x0002, 0x0010) ); |
| 153 |
|
| 154 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x0002,0x0010> len=%i\n",__FILE__,__LINE__,de->GetByteValue() ); |
| 155 |
|
| 156 |
if (0) { |
| 157 |
gdcm::Attribute<0x28,0x100> at; |
| 158 |
at.SetFromDataElement( ds.GetDataElement( at.GetTag() ) ); |
| 159 |
if( at.GetValue() != 8 ) { |
| 160 |
|
| 161 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x0002,0x0010> GetValue\n",__FILE__,__LINE__ ); |
| 162 |
|
| 163 |
return 1; |
| 164 |
} |
| 165 |
at.SetValue( 32 ); |
| 166 |
ds.Replace( at.GetAsDataElement() ); |
| 167 |
} |
| 168 |
{ |
| 169 |
|
| 170 |
|
| 171 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x0008,0x002a>\n",__FILE__,__LINE__); |
| 172 |
gdcm::Attribute<0x0008,0x002a> at; |
| 173 |
ds.GetDataElement( at.GetTag() ); |
| 174 |
at.SetFromDataElement( ds.GetDataElement( at.GetTag() ) ); |
| 175 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x0008,0x002a>\n",__FILE__,__LINE__); |
| 176 |
|
| 177 |
|
| 178 |
} |
| 179 |
|
| 180 |
{ |
| 181 |
|
| 182 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x0008,0x0023>\n",__FILE__,__LINE__); |
| 183 |
gdcm::Attribute<0x0008,0x0023> at; |
| 184 |
ds.GetDataElement( at.GetTag() ); |
| 185 |
at.SetFromDataElement( ds.GetDataElement( at.GetTag() ) ); |
| 186 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x0008,0x0023>\n",__FILE__,__LINE__); |
| 187 |
} |
| 188 |
if (1) { |
| 189 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x003a,0x0005>\n",__FILE__,__LINE__); |
| 190 |
gdcm::Attribute<0x003a,0x0005> NumberOfWaveformChannels; |
| 191 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x003a,0x0005> %i\n",__FILE__,__LINE__, NumberOfWaveformChannels.GetValue()); |
| 192 |
|
| 193 |
|
| 194 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x003a,0x0005> %i\n",__FILE__,__LINE__, NumberOfWaveformChannels.GetValue()); |
| 195 |
} |
| 196 |
{ |
| 197 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x003a,0x0010>\n",__FILE__,__LINE__); |
| 198 |
gdcm::Attribute<0x003a,0x0010> NumberOfWaveformSamples; |
| 199 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x003a,0x0010> %i\n",__FILE__,__LINE__, NumberOfWaveformSamples.GetValue()); |
| 200 |
|
| 201 |
|
| 202 |
} |
| 203 |
|
| 204 |
gdcm::Attribute<0x003a,0x001a> SamplingFrequency; |
| 205 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i): attr <0x003a,0x001a> %f\n",__FILE__,__LINE__, SamplingFrequency.GetValue()); |
| 206 |
|
| 207 |
return 0; |
| 208 |
} |
| 209 |
#endif |
| 210 |
|
| 211 |
|
| 212 |
#ifdef __cplusplus |
| 213 |
extern "C" { |
| 214 |
#endif |
| 215 |
|
| 216 |
int sopen_unipro_read(HDRTYPE* hdr) { |
| 217 |
hdr->FILE.LittleEndian = (__BYTE_ORDER == __LITTLE_ENDIAN); |
| 218 |
char *Header1 = (char*)hdr->AS.Header; |
| 219 |
struct tm t0; |
| 220 |
char tmp[5]; |
| 221 |
memset(tmp,0,5); |
| 222 |
strncpy(tmp,Header1+0x9c,2); |
| 223 |
t0.tm_mon = atoi(tmp)-1; |
| 224 |
strncpy(tmp,Header1+0x9e,2); |
| 225 |
t0.tm_mday = atoi(tmp); |
| 226 |
strncpy(tmp,Header1+0xa1,2); |
| 227 |
t0.tm_hour = atoi(tmp); |
| 228 |
strncpy(tmp,Header1+0xa3,2); |
| 229 |
t0.tm_min = atoi(tmp); |
| 230 |
strncpy(tmp,Header1+0xa5,2); |
| 231 |
t0.tm_sec = atoi(tmp); |
| 232 |
strncpy(tmp,Header1+0x98,4); |
| 233 |
t0.tm_year = atoi(tmp)-1900; |
| 234 |
hdr->T0 = tm_time2gdf_time(&t0); |
| 235 |
|
| 236 |
memset(tmp,0,5); |
| 237 |
strncpy(tmp,Header1+0x85,2); |
| 238 |
t0.tm_mday = atoi(tmp); |
| 239 |
strncpy(tmp,Header1+0x83,2); |
| 240 |
t0.tm_mon = atoi(tmp)-1; |
| 241 |
strncpy(tmp,Header1+0x7f,4); |
| 242 |
t0.tm_year = atoi(tmp)-1900; |
| 243 |
hdr->Patient.Birthday = tm_time2gdf_time(&t0); |
| 244 |
|
| 245 |
|
| 246 |
biosigERROR(hdr, B4C_FORMAT_UNSUPPORTED, "UNIPRO not supported"); |
| 247 |
return(0); |
| 248 |
} |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
#ifdef WITH_DICOM |
| 255 |
int sopen_dicom_read(HDRTYPE* hdr) { |
| 256 |
|
| 257 |
fprintf(stdout,"home-made parser is used to read dicom files.\n"); |
| 258 |
|
| 259 |
char FLAG_implicite_VR = 0; |
| 260 |
int EndOfGroup2=-1; |
| 261 |
|
| 262 |
if (hdr->HeadLen<132) { |
| 263 |
hdr->AS.Header = (uint8_t*)realloc(hdr->AS.Header, 132); |
| 264 |
hdr->HeadLen += ifread(hdr->AS.Header+hdr->HeadLen, 1, 132-hdr->HeadLen, hdr); |
| 265 |
} |
| 266 |
size_t count = hdr->HeadLen; |
| 267 |
size_t pos = 128; |
| 268 |
while (!hdr->AS.Header[pos] && (pos<128)) pos++; |
| 269 |
if ((pos==128) && !memcmp(hdr->AS.Header+128,"DICM",4)) { |
| 270 |
|
| 271 |
pos = 132; |
| 272 |
} |
| 273 |
else |
| 274 |
pos = 0; |
| 275 |
|
| 276 |
size_t bufsiz = 16384; |
| 277 |
while (!ifeof(hdr)) { |
| 278 |
hdr->AS.Header = (uint8_t*)realloc(hdr->AS.Header, count+bufsiz+1); |
| 279 |
count += ifread(hdr->AS.Header+count, 1, bufsiz, hdr); |
| 280 |
bufsiz *= 2; |
| 281 |
} |
| 282 |
ifclose(hdr); |
| 283 |
hdr->AS.Header[count] = 0; |
| 284 |
|
| 285 |
uint16_t nextTag[2]; |
| 286 |
|
| 287 |
struct tm T0; |
| 288 |
char flag_t0=0; |
| 289 |
char flag_ignored; |
| 290 |
uint32_t Tag; |
| 291 |
uint32_t Len; |
| 292 |
nextTag[0] = *(uint16_t*)(hdr->AS.Header+pos); |
| 293 |
nextTag[1] = *(uint16_t*)(hdr->AS.Header+pos+2); |
| 294 |
while (pos < count) { |
| 295 |
|
| 296 |
if ((__BYTE_ORDER == __BIG_ENDIAN) ^ !hdr->FILE.LittleEndian) { |
| 297 |
|
| 298 |
Tag = (((uint32_t)bswap_16(nextTag[0])) << 16) + bswap_16(nextTag[1]); |
| 299 |
pos += 4; |
| 300 |
if (FLAG_implicite_VR) { |
| 301 |
Len = bswap_32(*(uint32_t*)(hdr->AS.Header+pos)); |
| 302 |
pos += 4; |
| 303 |
} |
| 304 |
else { |
| 305 |
|
| 306 |
if (pos+4 > count) break; |
| 307 |
|
| 308 |
if (memcmp(hdr->AS.Header+pos,"OB",2) |
| 309 |
&& memcmp(hdr->AS.Header+pos,"OW",2) |
| 310 |
&& memcmp(hdr->AS.Header+pos,"OF",2) |
| 311 |
&& memcmp(hdr->AS.Header+pos,"SQ",2) |
| 312 |
&& memcmp(hdr->AS.Header+pos,"UT",2) |
| 313 |
&& memcmp(hdr->AS.Header+pos,"UN",2) ) { |
| 314 |
Len = bswap_16(*(uint16_t*)(hdr->AS.Header+pos+2)); |
| 315 |
pos += 4; |
| 316 |
} |
| 317 |
else { |
| 318 |
Len = bswap_32(*(uint32_t*)(hdr->AS.Header+pos+4)); |
| 319 |
pos += 8; |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
else { |
| 324 |
|
| 325 |
Tag = (((uint32_t)nextTag[0]) << 16) + nextTag[1]; |
| 326 |
pos += 4; |
| 327 |
if (FLAG_implicite_VR) { |
| 328 |
Len = *(uint32_t*)(hdr->AS.Header+pos); |
| 329 |
pos += 4; |
| 330 |
} |
| 331 |
else { |
| 332 |
|
| 333 |
if (pos+4 > count) break; |
| 334 |
|
| 335 |
if (memcmp(hdr->AS.Header+pos,"OB",2) |
| 336 |
&& memcmp(hdr->AS.Header+pos,"OW",2) |
| 337 |
&& memcmp(hdr->AS.Header+pos,"OF",2) |
| 338 |
&& memcmp(hdr->AS.Header+pos,"SQ",2) |
| 339 |
&& memcmp(hdr->AS.Header+pos,"UT",2) |
| 340 |
&& memcmp(hdr->AS.Header+pos,"UN",2) ) { |
| 341 |
Len = *(uint16_t*)(hdr->AS.Header+pos+2); |
| 342 |
pos += 4; |
| 343 |
} |
| 344 |
else { |
| 345 |
Len = *(uint32_t*)(hdr->AS.Header+pos+4); |
| 346 |
pos += 8; |
| 347 |
} |
| 348 |
} |
| 349 |
} |
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
if (pos+Len < count) { |
| 355 |
nextTag[0] = *(uint16_t*)(hdr->AS.Header+pos+Len); |
| 356 |
nextTag[1] = *(uint16_t*)(hdr->AS.Header+pos+Len+2); |
| 357 |
hdr->AS.Header[pos+Len] = 0; |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
flag_ignored = 0; |
| 362 |
if (VERBOSE_LEVEL>8) |
| 363 |
fprintf(stdout," %6x: (%04x,%04x) %8d\t%s\n",pos,Tag>>16,Tag&0x0ffff,Len,(char*)hdr->AS.Header+pos); |
| 364 |
|
| 365 |
switch (Tag) { |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
case 0x00020000: { |
| 372 |
int c = 0; |
| 373 |
if (!memcmp(hdr->AS.Header+pos-4,"UL",2)) |
| 374 |
c = leu32p(hdr->AS.Header+pos); |
| 375 |
else if (!memcmp(hdr->AS.Header+pos-4,"SL",2)) |
| 376 |
c = lei32p(hdr->AS.Header+pos); |
| 377 |
else if (!memcmp(hdr->AS.Header+pos-4,"US",2)) |
| 378 |
c = leu16p(hdr->AS.Header+pos); |
| 379 |
else if (!memcmp(hdr->AS.Header+pos-4,"SS",2)) |
| 380 |
c = lei16p(hdr->AS.Header+pos); |
| 381 |
else { |
| 382 |
|
| 383 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i) %i<%i %i>\n",__FILE__,__LINE__,pos,hdr->AS.Header[pos-8],hdr->AS.Header[pos-7]); |
| 384 |
biosigERROR(hdr, B4C_FORMAT_UNSUPPORTED, "DICOM (0002,0000): unsupported"); |
| 385 |
} |
| 386 |
EndOfGroup2 = c + pos; |
| 387 |
break; |
| 388 |
} |
| 389 |
case 0x00020001: |
| 390 |
break; |
| 391 |
|
| 392 |
case 0x00020002: { |
| 393 |
hdr->NS = 1; |
| 394 |
char *t = (char*)hdr->AS.Header+pos; |
| 395 |
while (isspace(*t)) t++; |
| 396 |
char *ct[] = { "1.2.840.10008.5.1.4.1.1.9.1.1", |
| 397 |
"1.2.840.10008.5.1.4.1.1.9.1.2", |
| 398 |
"1.2.840.10008.5.1.4.1.1.9.1.3", |
| 399 |
"1.2.840.10008.5.1.4.1.1.9.2.1", |
| 400 |
"1.2.840.10008.5.1.4.1.1.9.3.1", |
| 401 |
"1.2.840.10008.5.1.4.1.1.9.4.1" |
| 402 |
}; |
| 403 |
if (!strcmp(t,*ct)) hdr->NS = 12; |
| 404 |
break; |
| 405 |
} |
| 406 |
|
| 407 |
case 0x00020003: |
| 408 |
break; |
| 409 |
|
| 410 |
case 0x00020010: { |
| 411 |
char *t = (char*)hdr->AS.Header+pos; |
| 412 |
while (isspace(*t)) t++; |
| 413 |
char *ct[] = { "1.2.840.10008.1.2", |
| 414 |
"1.2.840.10008.1.2.1", |
| 415 |
"1.2.840.10008.1.2.1.99", |
| 416 |
"1.2.840.10008.1.2.2" |
| 417 |
}; |
| 418 |
|
| 419 |
if (!strcmp(t,*ct)) FLAG_implicite_VR = 1; |
| 420 |
else if (!strcmp(t,*ct+1)) FLAG_implicite_VR = 0; |
| 421 |
else if (!strcmp(t,*ct+3)) FLAG_implicite_VR = 1; |
| 422 |
break; |
| 423 |
} |
| 424 |
|
| 425 |
case 0x00080020: |
| 426 |
case 0x00080023: |
| 427 |
{ |
| 428 |
hdr->AS.Header[pos+8]=0; |
| 429 |
T0.tm_mday = atoi((char*)hdr->AS.Header+pos+6); |
| 430 |
hdr->AS.Header[pos+6]=0; |
| 431 |
T0.tm_mon = atoi((char*)hdr->AS.Header+pos+4)-1; |
| 432 |
hdr->AS.Header[pos+4]=0; |
| 433 |
T0.tm_year = atoi((char*)hdr->AS.Header+pos)-1900; |
| 434 |
flag_t0 |= 1; |
| 435 |
break; |
| 436 |
} |
| 437 |
case 0x0008002a: |
| 438 |
{ |
| 439 |
struct tm t0; |
| 440 |
hdr->AS.Header[pos+14]=0; |
| 441 |
t0.tm_sec = atoi((char*)hdr->AS.Header+pos+12); |
| 442 |
hdr->AS.Header[pos+12]=0; |
| 443 |
t0.tm_min = atoi((char*)hdr->AS.Header+pos+10); |
| 444 |
hdr->AS.Header[pos+10]=0; |
| 445 |
t0.tm_hour = atoi((char*)hdr->AS.Header+pos+8); |
| 446 |
hdr->AS.Header[pos+8]=0; |
| 447 |
t0.tm_mday = atoi((char*)hdr->AS.Header+pos+6); |
| 448 |
hdr->AS.Header[pos+6]=0; |
| 449 |
t0.tm_mon = atoi((char*)hdr->AS.Header+pos+4)-1; |
| 450 |
hdr->AS.Header[pos+4]=0; |
| 451 |
t0.tm_year = atoi((char*)hdr->AS.Header+pos)-1900; |
| 452 |
|
| 453 |
hdr->T0 = tm_time2gdf_time(&t0); |
| 454 |
break; |
| 455 |
} |
| 456 |
case 0x00080030: |
| 457 |
case 0x00080033: |
| 458 |
{ |
| 459 |
hdr->AS.Header[pos+6]=0; |
| 460 |
T0.tm_sec = atoi((char*)hdr->AS.Header+pos+4); |
| 461 |
hdr->AS.Header[pos+4]=0; |
| 462 |
T0.tm_min = atoi((char*)hdr->AS.Header+pos+2); |
| 463 |
hdr->AS.Header[pos+2]=0; |
| 464 |
T0.tm_hour = atoi((char*)hdr->AS.Header+pos); |
| 465 |
flag_t0 |= 2; |
| 466 |
break; |
| 467 |
} |
| 468 |
case 0x00080070: |
| 469 |
{ |
| 470 |
strncpy(hdr->ID.Manufacturer._field,(char*)hdr->AS.Header+pos,MAX_LENGTH_MANUF); |
| 471 |
hdr->ID.Manufacturer.Name = hdr->ID.Manufacturer._field; |
| 472 |
break; |
| 473 |
} |
| 474 |
case 0x00081050: |
| 475 |
{ |
| 476 |
strncpy(hdr->ID.Technician,(char*)hdr->AS.Header+pos,MAX_LENGTH_TECHNICIAN); |
| 477 |
break; |
| 478 |
} |
| 479 |
case 0x00081090: |
| 480 |
{ |
| 481 |
const size_t nn = strlen(hdr->ID.Manufacturer.Name)+1; |
| 482 |
strncpy(hdr->ID.Manufacturer._field+nn,(char*)hdr->AS.Header+pos,MAX_LENGTH_MANUF-nn-1); |
| 483 |
hdr->ID.Manufacturer.Model = hdr->ID.Manufacturer._field+nn; |
| 484 |
break; |
| 485 |
} |
| 486 |
|
| 487 |
case 0x00100010: |
| 488 |
if (!hdr->FLAG.ANONYMOUS) { |
| 489 |
strncpy(hdr->Patient.Name,(char*)hdr->AS.Header+pos,MAX_LENGTH_NAME); |
| 490 |
hdr->Patient.Name[MAX_LENGTH_NAME]=0; |
| 491 |
} |
| 492 |
break; |
| 493 |
case 0x00100020: |
| 494 |
strncpy(hdr->Patient.Id,(char*)hdr->AS.Header+pos,MAX_LENGTH_PID); |
| 495 |
hdr->Patient.Id[MAX_LENGTH_PID]=0; |
| 496 |
break; |
| 497 |
|
| 498 |
case 0x00100030: |
| 499 |
{ |
| 500 |
struct tm t0; |
| 501 |
t0.tm_sec = 0; |
| 502 |
t0.tm_min = 0; |
| 503 |
t0.tm_hour = 12; |
| 504 |
|
| 505 |
hdr->AS.Header[pos+8]=0; |
| 506 |
t0.tm_mday = atoi((char*)hdr->AS.Header+pos+6); |
| 507 |
hdr->AS.Header[pos+6]=0; |
| 508 |
t0.tm_mon = atoi((char*)hdr->AS.Header+pos+4)-1; |
| 509 |
hdr->AS.Header[pos+4]=0; |
| 510 |
t0.tm_year = atoi((char*)hdr->AS.Header+pos)-1900; |
| 511 |
|
| 512 |
hdr->Patient.Birthday = tm_time2gdf_time(&t0); |
| 513 |
break; |
| 514 |
} |
| 515 |
case 0x00100040: |
| 516 |
hdr->Patient.Sex = (toupper(hdr->AS.Header[pos])=='M') + 2*(toupper(hdr->AS.Header[pos])=='F'); |
| 517 |
break; |
| 518 |
|
| 519 |
case 0x00101010: |
| 520 |
break; |
| 521 |
case 0x00101020: |
| 522 |
hdr->Patient.Height = (uint8_t)(atof((char*)hdr->AS.Header+pos)*100.0); |
| 523 |
break; |
| 524 |
case 0x00101030: |
| 525 |
hdr->Patient.Weight = (uint8_t)atoi((char*)hdr->AS.Header+pos); |
| 526 |
break; |
| 527 |
|
| 528 |
default: |
| 529 |
flag_ignored = 1; |
| 530 |
if (VERBOSE_LEVEL<7) |
| 531 |
fprintf(stdout,"ignored %6x: (%04x,%04x) %8d\t%s\n",pos,Tag>>16,Tag&0x0ffff,Len,(char*)hdr->AS.Header+pos); |
| 532 |
|
| 533 |
} |
| 534 |
|
| 535 |
if (VERBOSE_LEVEL>6) { |
| 536 |
if (!FLAG_implicite_VR || (Tag < 0x00030000)) |
| 537 |
fprintf(stdout,"%s %6x: (%04x,%04x) %8d %c%c \t%s\n",(flag_ignored?"ignored":" "),pos,Tag>>16,Tag&0x0ffff,Len,hdr->AS.Header[pos-8],hdr->AS.Header[pos-7],(char*)hdr->AS.Header+pos); |
| 538 |
else |
| 539 |
fprintf(stdout,"%s %6x: (%04x,%04x) %8d\t%s\n",(flag_ignored?"ignored":" "),pos,Tag>>16,Tag&0x0ffff,Len,(char*)hdr->AS.Header+pos); |
| 540 |
} |
| 541 |
pos += Len + (Len & 0x01 ? 1 : 0); |
| 542 |
|
| 543 |
} |
| 544 |
if (flag_t0 == 3) hdr->T0 = tm_time2gdf_time(&T0); |
| 545 |
|
| 546 |
if (VERBOSE_LEVEL>7) fprintf(stdout,"%s (line %i)\n",__FILE__,__LINE__); |
| 547 |
|
| 548 |
return(0); |
| 549 |
} |
| 550 |
#endif |
| 551 |
|
| 552 |
|
| 553 |
#ifdef WITH_PDP |
| 554 |
#include "../NONFREE/sopen_pdp_read.c" |
| 555 |
#endif |
| 556 |
|
| 557 |
#ifdef WITH_TRC |
| 558 |
#include "../NONFREE/sopen_trc_read.c" |
| 559 |
#endif |
| 560 |
|
| 561 |
#ifdef __cplusplus |
| 562 |
} |
| 563 |
#endif |
| 564 |
|