]> Creatis software - gdcm.git/blob - src/gdcmHeader.cxx
1b81bf220d4bf4d2abc36eff89b1bf94aa044add
[gdcm.git] / src / gdcmHeader.cxx
1 #include "gdcm.h"
2 extern "C" {
3 #include "glib.h"
4 }
5 #include <stdio.h>
6 // For nthos:
7 #ifdef _MSC_VER
8 #include <winsock.h>
9 #else
10 #include <netinet/in.h>
11 #endif
12 #include <cctype>               // for isalpha
13 #include <map>
14 #include <sstream>
15 #include "gdcmUtil.h"
16
17 #define HEADER_LENGHT_TO_READ 256 // on ne lit plus que le debut
18
19 namespace Error {
20         struct FileReadError {
21                 FileReadError(FILE* fp, const char* Mesg) {
22                         if (feof(fp))
23                                 dbg.Verbose(1, "EOF encountered :", Mesg);
24                         if (ferror(fp))
25                                 dbg.Verbose(1, "Error on reading :", Mesg);
26                 }
27         };
28 }
29
30 //FIXME: this looks dirty to me...
31 #define str2num(str, typeNum) *((typeNum *)(str))
32
33 VRHT * gdcmHeader::dicom_vr = (VRHT*)0;
34 gdcmDictSet* gdcmHeader::Dicts = new gdcmDictSet();
35
36 void gdcmHeader::Initialise(void) {
37         if (!gdcmHeader::dicom_vr)
38                 InitVRDict();
39         RefPubDict = gdcmHeader::Dicts->GetDefaultPublicDict();
40         RefShaDict = (gdcmDict*)0;
41 }
42
43 gdcmHeader::gdcmHeader (const char* InFilename) {
44         filename = InFilename;
45         Initialise();
46         fp=fopen(InFilename,"rw");
47         dbg.Error(!fp, "gdcmHeader::gdcmHeader cannot open file", InFilename);
48         ParseHeader();
49 }
50
51 gdcmHeader::~gdcmHeader (void) {
52         fclose(fp);
53         return;
54 }
55
56 void gdcmHeader::InitVRDict (void) {
57         if (dicom_vr) {
58                 dbg.Verbose(0, "gdcmHeader::InitVRDict:", "VR dictionary allready set");
59                 return;
60         }
61         VRHT *vr = new VRHT;
62         (*vr)["AE"] = "Application Entity";       // 16 car max
63         (*vr)["AS"] = "Age String";               // 4 car fixe
64         (*vr)["AT"] = "Attribute Tag";            // 2 unsigned short int
65         (*vr)["CS"] = "Code String";              // 16 car max
66         (*vr)["DA"] = "Date";                     // 8 car fixe
67         (*vr)["DS"] = "Decimal String";           // Decimal codé Binaire 16 max
68         (*vr)["DT"] = "Date Time";                // 26 car max
69         (*vr)["FL"] = "Floating Point Single";    // 4 octets IEEE 754:1985
70         (*vr)["FD"] = "Floating Point Double";    // 8 octets IEEE 754:1985
71         (*vr)["IS"] = "Integer String";           // en format externe 12 max
72         (*vr)["LO"] = "Long String";              // 64 octets max
73         (*vr)["LT"] = "Long Text";                // 10240 max
74         (*vr)["OB"] = "Other Byte String";
75         (*vr)["OW"] = "Other Word String";
76         (*vr)["PN"] = "Person Name";
77         (*vr)["SH"] = "Short String";             // 16 car max
78         (*vr)["SL"] = "Signed Long";
79         (*vr)["SQ"] = "Sequence of Items";        // Not Applicable
80         (*vr)["SS"] = "Signed Short";             // 2 octets
81         (*vr)["ST"] = "Short Text";               // 1024 car max
82         (*vr)["TM"] = "Time";                     // 16 car max
83         (*vr)["UI"] = "Unique Identifier";        // 64 car max
84         (*vr)["UN"] = "Unknown";
85         (*vr)["UT"] = "Unlimited Text";           //  2 puissance 32 -1 car max
86         (*vr)["UL"] = "Unsigned Long ";           // 4 octets fixe
87         (*vr)["US"] = "Unsigned Short ";          // 2 octets fixe
88    dicom_vr = vr;       
89 }
90
91 /**
92  * \ingroup gdcmHeader
93  * \brief   La seule maniere sure que l'on aie pour determiner 
94  *          si on est en   LITTLE_ENDIAN,       BIG-ENDIAN, 
95  *          BAD-LITTLE-ENDIAN, BAD-BIG-ENDIAN
96  *          est de trouver l'element qui donne la longueur d'un 'GROUP'
97  *          (on sait que la longueur de cet element vaut 0x00000004)
98  *          et de regarder comment cette longueur est codee en memoire  
99  *          
100  *          Le probleme vient de ce que parfois, il n'y en a pas ...
101  *          
102  *          On fait alors le pari qu'on a a faire a du LITTLE_ENDIAN propre.
103  *          (Ce qui est la norme -pas respectee- depuis ACR-NEMA)
104  *          Si ce n'est pas le cas, on ne peut rien faire.
105  *
106  *          (il faudrait avoir des fonctions auxquelles 
107  *          on passe le code Swap en parametre, pour faire des essais 'manuels')
108  */
109 void gdcmHeader::CheckSwap()
110 {
111         guint32  s;
112         guint32  x=4;  // x : pour ntohs
113         bool net2host; // true when HostByteOrder is the same as NetworkByteOrder
114          
115         int lgrLue;
116         char * entCur;
117         char deb[HEADER_LENGHT_TO_READ];
118          
119         // First, compare HostByteOrder and NetworkByteOrder in order to
120         // determine if we shall need to swap bytes (i.e. the Endian type).
121         if (x==ntohs(x))
122                 net2host = true;
123         else
124                 net2host = false;
125         
126         // The easiest case is the one of a DICOM header, since it possesses a
127         // file preamble where it suffice to look for the sting "DICM".
128         lgrLue = fread(deb, 1, HEADER_LENGHT_TO_READ, fp);
129         
130         entCur = deb + 128;
131         if(memcmp(entCur, "DICM", (size_t)4) == 0) {
132                 filetype = TrueDicom;
133                 dbg.Verbose(1, "gdcmHeader::CheckSwap:", "looks like DICOM Version3");
134         } else {
135                 filetype = Unknown;
136                 dbg.Verbose(1, "gdcmHeader::CheckSwap:", "not a DICOM Version3 file");
137         }
138
139         if(filetype == TrueDicom) {
140                 // Next, determine the value representation (VR). Let's skip to the
141                 // first element (0002, 0000) and check there if we find "UL", in
142                 // which case we (almost) know it is explicit VR.
143                 // WARNING: if it happens to be implicit VR then what we will read
144                 // is the length of the group. If this ascii representation of this
145                 // length happens to be "UL" then we shall believe it is explicit VR.
146                 // FIXME: in order to fix the above warning, we could read the next
147                 // element value (or a couple of elements values) in order to make
148                 // sure we are not commiting a big mistake.
149                 // We need to skip :
150                 // * the 128 bytes of File Preamble (often padded with zeroes),
151                 // * the 4 bytes of "DICM" string,
152                 // * the 4 bytes of the first tag (0002, 0000),
153                 // i.e. a total of  136 bytes.
154                 entCur = deb + 136;
155                 if(memcmp(entCur, "UL", (size_t)2) == 0) {
156                         filetype = ExplicitVR;
157                         dbg.Verbose(0, "gdcmHeader::CheckSwap:",
158                                     "explicit Value Representation");
159                 } else {
160                         filetype = ImplicitVR;
161                         dbg.Verbose(0, "gdcmHeader::CheckSwap:",
162                                     "not an explicit Value Representation");
163                 }
164
165                 if (net2host) {
166                         sw = 4321;
167                         dbg.Verbose(0, "gdcmHeader::CheckSwap:",
168                                        "HostByteOrder != NetworkByteOrder");
169                 } else {
170                         sw = 0;
171                         dbg.Verbose(0, "gdcmHeader::CheckSwap:",
172                                        "HostByteOrder = NetworkByteOrder");
173                 }
174                 
175                 // Position the file position indicator at first tag (i.e.
176                 // after the file preamble and the "DICM" string).
177                 rewind(fp);
178                 fseek (fp, 132L, SEEK_SET);
179                 return;
180         } // End of TrueDicom
181
182         // Alas, this is not a DicomV3 file and whatever happens there is no file
183         // preamble. We can reset the file position indicator to where the data
184         // is (i.e. the beginning of the file).
185         rewind(fp);
186
187         // Our next best chance would be to be considering a 'clean' ACR/NEMA file.
188         // By clean we mean that the length of the first tag is written down.
189         // If this is the case and since the length of the first group HAS to be
190         // four (bytes), then determining the proper swap code is straightforward.
191
192         entCur = deb + 4;
193         s = str2num(entCur, int);
194         
195         switch (s) {
196         case 0x00040000 :
197                 sw=3412;
198                 filetype = ACR;
199                 return;
200         case 0x04000000 :
201                 sw=4321;
202                 filetype = ACR;
203                 return;
204         case 0x00000400 :
205                 sw=2143;
206                 filetype = ACR;
207                 return;
208         case 0x00000004 :
209                 sw=0;
210                 filetype = ACR;
211                 return;
212         default :
213                 dbg.Verbose(0, "gdcmHeader::CheckSwap:",
214                                "ACE/NEMA unfound swap info (time to raise bets)");
215         }
216
217         // We are out of luck. It is not a DicomV3 nor a 'clean' ACR/NEMA file.
218         // It is time for despaired wild guesses. So, let's assume this file
219         // happens to be 'dirty' ACR/NEMA, i.e. the length of the group it
220         // not present. Then the only info we have is the net2host one.
221         //FIXME  Si c'est du RAW, ca degagera + tard
222         
223         if (! net2host )
224                 sw = 0;
225         else
226                 sw = 4321;
227         return;
228 }
229
230 /**
231  * \ingroup   gdcmHeader
232  * \brief     recupere la longueur d'un champ DICOM.
233  *            Preconditions:
234  *            1/ le fichier doit deja avoir ete ouvert,
235  *            2/ CheckSwap() doit avoir ete appele
236  *            3/ la  partie 'group'  ainsi que la  partie 'elem' 
237  *               de l'acr_element doivent avoir ete lues.
238  *
239  *            ACR-NEMA : we allways get
240  *                 GroupNumber   (2 Octets) 
241  *                 ElementNumber (2 Octets) 
242  *                 ElementSize   (4 Octets)
243  *            DICOM en implicit Value Representation :
244  *                 GroupNumber   (2 Octets) 
245  *                 ElementNumber (2 Octets) 
246  *                 ElementSize   (4 Octets)
247  *
248  *            DICOM en explicit Value Representation :
249  *                 GroupNumber         (2 Octets) 
250  *                 ElementNumber       (2 Octets) 
251  *                 ValueRepresentation (2 Octets) 
252  *                 ElementSize         (2 Octets)
253  *
254  *            ATTENTION : dans le cas ou ValueRepresentation = OB, OW, SQ, UN
255  *                 GroupNumber         (2 Octets) 
256  *                 ElementNumber       (2 Octets) 
257  *                 ValueRepresentation (2 Octets)
258  *                 zone reservee       (2 Octets) 
259  *                 ElementSize         (4 Octets)
260  *
261  * @param sw  code swap
262  * @param skippedLength  pointeur sur nombre d'octets que l'on a saute qd
263  *                       la lecture est finie
264  * @param longueurLue    pointeur sur longueur (en nombre d'octets) 
265  *                       effectivement lue
266  * @return               longueur retenue pour le champ 
267  */
268
269 void gdcmHeader::FindVR( ElValue *ElVal) {
270         char VR[3];
271         string vr;
272         int lgrLue;
273         long PositionOnEntry = ftell(fp);
274         // Warning: we believe this is explicit VR (Value Representation) because
275         // we used a heuristic that found "UL" in the first tag. Alas this
276         // doesn't guarantee that all the tags will be in explicit VR. In some
277         // cases (see e-film filtered files) one finds implicit VR tags mixed
278         // within an explicit VR file. Hence we make sure the present tag
279         // is in explicit VR and try to fix things if it happens not to be
280         // the case.
281         bool RealExplicit = true;
282         
283         if (filetype != ExplicitVR)
284                 return;
285
286         lgrLue=fread (&VR, (size_t)2,(size_t)1, fp);
287         VR[2]=0;
288         vr = string(VR);
289                 
290         // Assume we are reading a falsely explicit VR file i.e. we reached
291         // a tag where we expect reading a VR but are in fact we read the
292         // first to bytes of the length. Then we will interogate (through find)
293         // the dicom_vr dictionary with oddities like "\004\0" which crashes
294         // both GCC and VC++ implentations of the STL map. Hence when the
295         // expected VR read happens to be non-ascii characters we consider
296         // we hit falsely explicit VR tag.
297
298         if ( (!isalpha(VR[0])) && (!isalpha(VR[1])) )
299                 RealExplicit = false;
300
301         // CLEANME searching the dicom_vr at each occurence is expensive.
302         // PostPone this test in an optional integrity check at the end
303         // of parsing or only in debug mode.
304         if ( RealExplicit && !dicom_vr->count(vr) )
305                 RealExplicit = false;
306
307         if ( RealExplicit ) {
308                 ElVal->SetVR(vr);
309                 return; 
310         }
311         
312         // We thought this was explicit VR, but we end up with an
313         // implicit VR tag. Let's backtrack.
314         dbg.Verbose(1, "gdcmHeader::FindVR:",
315                        "Falsely explicit vr file");
316         ElVal->SetVR("Implicit");
317         fseek(fp, PositionOnEntry, SEEK_SET);
318 }
319
320 void gdcmHeader::FindLength( ElValue * ElVal) {
321         guint32 length32;
322         guint16 length16;
323         string vr = ElVal->GetVR();
324         
325         if ( (filetype == ExplicitVR) && (vr != "Implicit") ) {
326                 if ( (vr=="OB") || (vr=="OW") || (vr=="SQ") || (vr=="UN") ) {
327                         
328                         // The following two bytes are reserved, so we skip them,
329                         // and we proceed on reading the length on 4 bytes.
330                         fseek(fp, 2L,SEEK_CUR);
331                         length32 = ReadInt32();
332                         
333                 } else {
334                         // Length is encoded on 2 bytes.
335                         length16 = ReadInt16();
336                          
337                         if ( length16 == 0xffff) {
338                                 length32 = 0;
339                         } else {
340                                 length32 = length16;
341                         }
342                 }
343         } else {
344                 // Either implicit VR or an explicit VR that (at least for this
345                 // element) lied a little bit. Length is on 4 bytes.
346                 length32 = ReadInt32();
347         }
348         
349         // Traitement des curiosites sur la longueur
350         if ( length32 == 0xffffffff)
351                 length32=0;
352         
353         ElVal->SetLength(length32);
354 }
355
356
357 /**
358  * \ingroup gdcmHeader
359  * \brief   remet les octets dans un ordre compatible avec celui du processeur
360
361  * @return  longueur retenue pour le champ 
362  */
363 guint32 gdcmHeader::SwapLong(guint32 a) {
364         // FIXME: il pourrait y avoir un pb pour les entiers negatifs ...
365         switch (sw) {
366         case    0 :
367                 break;
368         case 4321 :
369                 a=(   ((a<<24) & 0xff000000) | ((a<<8)  & 0x00ff0000)    | 
370                       ((a>>8)  & 0x0000ff00) | ((a>>24) & 0x000000ff) );
371                 break;
372         
373         case 3412 :
374                 a=(   ((a<<16) & 0xffff0000) | ((a>>16) & 0x0000ffff) );
375                 break;
376         
377         case 2143 :
378                 a=(    ((a<<8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff)  );
379                 break;
380         default :
381                 dbg.Error(" gdcmHeader::SwapLong : unset swap code");
382                 a=0;
383         }
384         return(a);
385 }
386
387 /**
388  * \ingroup gdcmHeader
389  * \brief   Swaps the bytes so they agree with the processor order
390
391  * @return  longueur retenue pour le champ 
392  */
393 guint16 gdcmHeader::SwapShort(guint16 a) {
394         //FIXME how could sw be equal to 2143 since we never set it this way ?
395         if ( (sw==4321)  || (sw==2143) )
396                 a =(((a<<8) & 0x0ff00) | ((a>>8)&0x00ff));
397         return (a);
398 }
399
400 void gdcmHeader::SkipElementValue(ElValue * ElVal) {
401         //FIXME don't dump the returned value
402         (void)fseek(fp, (long)ElVal->GetLength(), SEEK_CUR);
403 }
404
405 /**
406  * \ingroup       gdcmHeader
407  * \brief         Loads the element if it's size is not to big.
408  * @param ElVal   Element whose value shall be loaded. 
409  * @param MaxSize Size treshold above which the element value is not
410  *                loaded in memory. The element value is allways loaded
411  *                when MaxSize is equal to UINT32_MAX.
412  * @return  
413  */
414 void gdcmHeader::LoadElementValue(ElValue * ElVal) {
415         size_t item_read;
416         guint16 group  = ElVal->GetGroup();
417         guint16 elem   = ElVal->GetElement();
418         string  vr     = ElVal->GetVR();
419         guint32 length = ElVal->GetLength();
420         fseek(fp, (long)ElVal->GetOffset(), SEEK_SET);
421         
422         // Sequences not treated yet !
423         if( vr == "SQ" ) {
424                 SkipElementValue(ElVal);
425                 ElVal->SetLength(0);
426                 return;
427         }
428         // A sequence "contains" a set of tags (called items). It looks like
429         // the last tag of a sequence (the one that terminates the sequence)
430         // has a group of 0xfffe (with a dummy length).
431         if( group == 0xfffe) {
432                 SkipElementValue(ElVal);
433                 ElVal->SetLength(0);
434                 return;
435         }
436         
437         if ( IsAnInteger(group, elem, vr, length) ) {
438                 guint32 NewInt;
439                 if( length == 2 ) {
440                         NewInt = ReadInt16();
441                 } else if( length == 4 ) {
442                         NewInt = ReadInt32();
443                 } else
444                         dbg.Error(true, "LoadElementValue: Inconsistency when reading Int.");
445                 
446                 //FIXME: make the following an util fonction
447                 ostringstream s;
448                 s << NewInt;
449                 ElVal->SetValue(s.str());
450                 return;
451         }
452         
453         // FIXME The exact size should be length if we move to strings or whatever
454         char* NewValue = (char*)g_malloc(length+1);
455         if( !NewValue) {
456                 dbg.Verbose(1, "LoadElementValue: Failed to allocate NewValue");
457                 return;
458         }
459         NewValue[length]= 0;
460         
461         // FIXME les elements trop long (seuil a fixer a la main) ne devraient
462         // pas etre charge's !!!! Voir TODO.
463         item_read = fread(NewValue, (size_t)length, (size_t)1, fp);
464         if ( item_read != 1 ) {
465                 g_free(NewValue);
466                 Error::FileReadError(fp, "gdcmHeader::LoadElementValue");
467                 ElVal->SetValue("gdcm::UnRead");
468                 return;
469         }
470         ElVal->SetValue(NewValue);
471 }
472
473
474 guint16 gdcmHeader::ReadInt16(void) {
475         guint16 g;
476         size_t item_read;
477         item_read = fread (&g, (size_t)2,(size_t)1, fp);
478         if ( item_read != 1 )
479                 throw Error::FileReadError(fp, "gdcmHeader::ReadInt16");
480         g = SwapShort(g);
481         return g;
482 }
483
484 guint32 gdcmHeader::ReadInt32(void) {
485         guint32 g;
486         size_t item_read;
487         item_read = fread (&g, (size_t)4,(size_t)1, fp);
488         if ( item_read != 1 )
489                 throw Error::FileReadError(fp, "gdcmHeader::ReadInt32");
490         g = SwapLong(g);
491         return g;
492 }
493
494 /**
495  * \ingroup gdcmHeader
496  * \brief   Read the next tag without loading it's value
497  * @return  On succes the newly created ElValue, NULL on failure.      
498  */
499
500 ElValue * gdcmHeader::ReadNextElement(void) {
501         guint16 g;
502         guint16 n;
503         ElValue * NewElVal;
504         
505         try {
506                 g = ReadInt16();
507                 n = ReadInt16();
508         }
509         catch ( Error::FileReadError ) {
510                 // We reached the EOF (or an error occured) and header parsing
511                 // has to be considered as finished.
512                 return (ElValue *)0;
513         }
514
515         // Find out if the tag we encountered is in the dictionaries:
516         gdcmDictEntry * NewTag = IsInDicts(g, n);
517         if (!NewTag)
518                 NewTag = new gdcmDictEntry(g, n, "Unknown", "Unknown", "Unknown");
519
520         NewElVal = new ElValue(NewTag);
521         if (!NewElVal) {
522                 dbg.Verbose(1, "ReadNextElement: failed to allocate ElValue");
523                 return (ElValue*)0;
524         }
525
526         FindVR(NewElVal);
527         FindLength(NewElVal);
528         NewElVal->SetOffset(ftell(fp));
529         return NewElVal;
530 }
531
532 bool gdcmHeader::IsAnInteger(guint16 group, guint16 element,
533                                      string vr, guint32 length ) {
534         // When we have some semantics on the element we just read, and we
535         // a priori now we are dealing with an integer, then we can swap it's
536         // element value properly.
537         if ( element == 0 )  {  // This is the group length of the group
538                 if (length != 4)
539                         dbg.Error("gdcmHeader::ShouldBeSwaped", "should be four");
540                 return true;
541         }
542         
543         if ( group % 2 != 0 )
544                 // We only have some semantics on documented elements, which are
545                 // the even ones.
546                 return false;
547         
548         if ( (length != 4) && ( length != 2) )
549                 // Swapping only make sense on integers which are 2 or 4 bytes long.
550                 return false;
551         
552         if ( (vr == "UL") || (vr == "US") || (vr == "SL") || (vr == "SS") )
553                 return true;
554         
555         if ( (group == 0x0028) && (element == 0x0005) )
556                 // This tag is retained from ACR/NEMA
557                 // CHECKME Why should "Image Dimensions" be a single integer ?
558                 return true;
559         
560         if ( (group == 0x0028) && (element == 0x0200) )
561                 // This tag is retained from ACR/NEMA
562                 return true;
563         
564         return false;
565 }
566
567 /**
568  * \ingroup gdcmHeader
569  * \brief   Recover the offset (from the beginning of the file) of the pixels.
570  */
571 size_t gdcmHeader::GetPixelOffset(void) {
572         // If this file complies with the norm we should encounter the
573         // "Image Location" tag (0x0028,  0x0200). This tag contains the
574         // the group that contains the pixel data (hence the "Pixel Data"
575         // is found by indirection through the "Image Location").
576         // Inside the group pointed by "Image Location" the searched element
577         // is conventionally the element 0x0010 (when the norm is respected).
578         //    When the "Image Location" is absent we default to group 0x7fe0.
579         guint16 grPixel;
580         guint16 numPixel;
581         string ImageLocation = GetPubElValByName("Image Location");
582         if ( ImageLocation == "UNFOUND" ) {
583                 grPixel = 0x7FE0;
584         } else {
585                 grPixel = (guint16) atoi( ImageLocation.c_str() );
586         }
587         if (grPixel != 0x7fe0)
588                 // FIXME is this still necessary ?
589                 // Now, this looks like an old dirty fix for Philips imager
590                 numPixel = 0x1010;
591         else
592                 numPixel = 0x0010;
593         ElValue* PixelElement = PubElVals.GetElement(grPixel, numPixel);
594         if (PixelElement)
595                 return PixelElement->GetOffset();
596         else
597                 return 0;
598 }
599
600 gdcmDictEntry * gdcmHeader::IsInDicts(guint32 group, guint32 element) {
601         gdcmDictEntry * found = (gdcmDictEntry*)0;
602         if (!RefPubDict && !RefShaDict) {
603                 //FIXME build a default dictionary !
604                 printf("FIXME in gdcmHeader::IsInDicts\n");
605         }
606         if (RefPubDict) {
607                 found = RefPubDict->GetTag(group, element);
608                 if (found)
609                         return found;
610         }
611         if (RefShaDict) {
612                 found = RefShaDict->GetTag(group, element);
613                 if (found)
614                         return found;
615         }
616         return found;
617 }
618
619 string gdcmHeader::GetPubElValByNumber(guint16 group, guint16 element) {
620         return PubElVals.GetElValue(group, element);
621 }
622
623 string gdcmHeader::GetPubElValByName(string TagName) {
624         return PubElVals.GetElValue(TagName);
625 }
626
627 /**
628  * \ingroup gdcmHeader
629  * \brief   Parses the header of the file but does NOT load element values.
630  */
631 void gdcmHeader::ParseHeader(void) {
632         ElValue * newElValue = (ElValue *)0;
633         
634         rewind(fp);
635         CheckSwap();
636         while ( (newElValue = ReadNextElement()) ) {
637                 SkipElementValue(newElValue);
638                 PubElVals.Add(newElValue);
639         }
640 }
641
642 /**
643  * \ingroup gdcmHeader
644  * \brief   Loads the element values of all the elements present in the
645  *          public tag based hash table.
646  */
647 void gdcmHeader::LoadElements(void) {
648         rewind(fp);    
649         TagElValueHT ht = PubElVals.GetTagHt();
650         for (TagElValueHT::iterator tag = ht.begin(); tag != ht.end(); ++tag)
651                 LoadElementValue(tag->second);
652 }
653
654 void gdcmHeader::PrintPubElVal(ostream & os) {
655         PubElVals.Print(os);
656 }
657
658 void gdcmHeader::PrintPubDict(ostream & os) {
659         RefPubDict->Print(os);
660 }