]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.cxx
We are no longer cheated by Elem belonging to group 0x0002,
[gdcm.git] / src / gdcmDataEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/07/26 08:36:49 $
7   Version:   $Revision: 1.44 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmDataEntry.h"
20 #include "gdcmVR.h"
21 #include "gdcmTS.h"
22 #include "gdcmGlobal.h"
23 #include "gdcmUtil.h"
24 #include "gdcmDebug.h"
25
26 #include <fstream>
27
28 #if defined(__BORLANDC__)
29  #include <mem.h>    // for memcpy
30  #include <stdlib.h> // for atof
31  #include <ctype.h>  // for isdigit
32 #endif
33
34 namespace GDCM_NAME_SPACE 
35 {
36 //-----------------------------------------------------------------------------
37 #define MAX_SIZE_PRINT_ELEMENT_VALUE 0x7fffffff
38 uint32_t DataEntry::MaxSizePrintEntry = MAX_SIZE_PRINT_ELEMENT_VALUE;
39
40 //-----------------------------------------------------------------------------
41 // Constructor / Destructor
42 /**
43  * \brief   Constructor for a given DataEntry
44  * @param   group group number of the Data Entry to be created
45  * @param   elem element number of the Data Entry to be created
46  * @param   vr Value Representation of the Data Entry to be created 
47  */
48 DataEntry::DataEntry(uint16_t group,uint16_t elem,
49                                      VRKey const &vr) 
50             : DocEntry(group,elem,vr)
51 {
52    State = STATE_LOADED;
53    Flag = FLAG_NONE;
54
55    StrArea = 0;
56    BinArea = 0;
57    SelfArea = true;
58 }
59
60 /**
61  * \brief   Constructor for a given DocEntry
62  * @param   e Pointer to existing Doc entry
63  */
64 DataEntry::DataEntry(DocEntry *e)
65             //: DocEntry(e->GetDictEntry())
66             : DocEntry(e->GetGroup(),e->GetElement(), e->GetVR()  )
67 {
68    Flag = FLAG_NONE;
69    BinArea = 0;
70    
71    SelfArea = true;
72
73    Copy(e);
74 }
75
76 /**
77  * \brief   Canonical destructor.
78  */
79 DataEntry::~DataEntry ()
80 {
81    DeleteBinArea();
82    
83 }
84
85 //-----------------------------------------------------------------------------
86 // Print
87
88 //-----------------------------------------------------------------------------
89 // Public
90 /**
91  * \brief Sets the value (non string) of the current DataEntry
92  * @param area area
93  * @param self self
94  */
95 void DataEntry::SetBinArea( uint8_t *area, bool self )  
96
97    DeleteBinArea();
98
99    BinArea = area;
100    SelfArea = self;
101
102    State = STATE_LOADED;
103 }
104 /**
105  * \brief Inserts the value (non string) into the current DataEntry
106  * @param area area
107  * @param length length 
108  */
109 void DataEntry::CopyBinArea( uint8_t *area, uint32_t length )
110 {
111    DeleteBinArea();
112
113    uint32_t lgh = length + length%2;
114    SetLength(lgh);
115
116    if( area && length > 0 )
117    {
118       NewBinArea();
119       memcpy(BinArea,area,length);
120       if( length!=lgh )
121          BinArea[length]=0;
122
123       State = STATE_LOADED;
124    }
125 }
126
127 /**
128  * \brief Inserts the elementary (non string) value into the current DataEntry
129  * @param id index of the elementary value to be set
130  * @param val value, passed as a double 
131  */
132 void DataEntry::SetValue(const uint32_t &id, const double &val)
133 {
134    if( !BinArea )
135       NewBinArea();
136    State = STATE_LOADED;
137
138    if( id > GetValueCount() )
139    {
140       gdcmErrorMacro("Index (" << id << ")is greater than the data size");
141       return;
142    }
143
144    const VRKey &vr = GetVR();
145    if( vr == "US" || vr == "SS" )
146    {
147       uint16_t *data = (uint16_t *)BinArea;
148       data[id] = (uint16_t)val;
149    }
150    else if( vr == "UL" || vr == "SL" )
151    {
152       uint32_t *data = (uint32_t *)BinArea;
153       data[id] = (uint32_t)val;
154    }
155    else if( vr == "FL" )
156    {
157       float *data = (float *)BinArea;
158       data[id] = (float)val;
159    }
160    else if( vr == "FD" )
161    {
162       double *data = (double *)BinArea;
163       data[id] = (double)val;
164    }
165    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
166    {
167       gdcmErrorMacro("SetValue on String representable not implemented yet");
168    }
169    else
170    {
171       BinArea[id] = (uint8_t)val;
172    }
173 }
174 /**
175  * \brief returns, as a double (?!?) one of the values 
176  *      (when entry is multivaluated), identified by its index.
177  *      Returns 0.0 if index is wrong
178  * @param id id
179  */
180 double DataEntry::GetValue(const uint32_t &id) const
181 {
182    if( !BinArea )
183    {
184       if (GetLength() != 0) // avoid stupid messages
185    /// \todo warn the user there was a problem !
186          gdcmErrorMacro("BinArea not set " << std::hex 
187                      << GetGroup() << " " << GetElement() 
188                      << " Can't get the value");
189       return 0.0;
190    }
191
192    uint32_t count = GetValueCount();
193    if( id > count )
194    {
195       gdcmErrorMacro("Index (" << id << ") is greater than the data size");
196       return 0.0;
197    }
198
199    /// \todo FIX the API : user *knows* that entry contains a US
200    ///               and he receives a double ?!?
201    
202    const VRKey &vr = GetVR();
203    /// \todo FIX the API : user *knows* that entry contains a US,
204    ///       the method is supposed to return a double
205    ///       but sends a US ?!? 
206    if( vr == "US" || vr == "SS" )
207       return ((uint16_t *)BinArea)[id];
208    else if( vr == "UL" || vr == "SL" )
209       return ((uint32_t *)BinArea)[id];
210    else if( vr == "FL" )
211       return ((float *)BinArea)[id];
212    else if( vr == "FD" )
213       return ((double *)BinArea)[id];
214    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
215    {
216       // this is for VR = "DS", ...
217       if( GetLength() )
218       {
219          // Don't use std::string to accelerate processing
220          double val;
221          char *tmp = new char[GetLength()+1];
222          memcpy(tmp,BinArea,GetLength());
223          tmp[GetLength()]=0;
224
225          if( count == 0 )
226          {
227             val = atof(tmp);
228          }
229          else
230          {
231             count = id;
232             char *beg = tmp;
233             for(uint32_t i=0;i<GetLength();i++)
234             {
235                if( tmp[i] == '\\' )
236                {
237                   if( count == 0 )
238                   {
239                      tmp[i] = 0;
240                      break;
241                   }
242                   else
243                   {
244                      count--;
245                      beg = &(tmp[i+1]);
246                   }
247                }
248             }
249             val = atof(beg);
250          }
251
252          delete[] tmp;
253          return val;
254       }
255       else 
256          return 0.0;
257    }
258    else
259       return BinArea[id];
260 }
261
262 /**
263  * \brief Checks if the multiplicity of the value follows Dictionary VM
264  */
265 bool DataEntry::IsValueCountValid() /*const*/
266 {
267   uint32_t vm;
268   const std::string &strVM = GetVM();
269   uint32_t vc = GetValueCount();
270   bool valid = vc == 0;
271   if( valid )
272     return true;
273   
274   // FIXME : what shall we do with VM = "2-n", "3-n", etc
275   
276   if( strVM == "1-n" )
277   {
278     // make sure there is at least one ??? FIXME
279     valid = vc >= 1;
280   }
281   else
282   {
283     std::istringstream os;
284     os.str( strVM );
285     os >> vm;
286     // Two cases:
287     // vm respects the one from the dict
288     // vm is 0 (we need to check if this element is allowed to be empty) FIXME
289
290     // note  (JPR)
291     // ----    
292     // Entries whose type is 1 are mandatory, with a mandatory value.
293     // Entries whose type is 1c are mandatory-inside-a-Sequence,
294     //                          with a mandatory value.
295     // Entries whose type is 2 are mandatory, with an optional value.
296     // Entries whose type is 2c are mandatory-inside-a-Sequence,
297     //                          with an optional value.
298     // Entries whose type is 3 are optional.
299
300     // case vc == 0 is only applicable for 'type 2' entries.
301     // Problem : entry type may depend on the modality and/or the Sequence
302     //           it's embedded in !
303     //          (Get the information in the 'Conformance Statements' ...)  
304     valid = vc == vm;
305   }
306   return valid;
307 }
308
309 /**
310  * \brief returns the number of elementary values
311  */ 
312 uint32_t DataEntry::GetValueCount( ) const
313 {
314    const VRKey &vr = GetVR();
315    if( vr == "US" || vr == "SS" )
316       return GetLength()/sizeof(uint16_t);
317    else if( vr == "UL" || vr == "SL" )
318       return GetLength()/sizeof(uint32_t);
319    else if( vr == "FL" || vr == "OF" )
320       return GetLength()/4 ; // FL has a *4* length! sizeof(float);
321    else if( vr == "FD" )
322       return GetLength()/8;  // FD has a *8* length! sizeof(double);
323    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
324    {
325       // Some element in DICOM are allowed to be empty
326       if( !GetLength() ) 
327          return 0;
328       // Don't use std::string to accelerate processing
329       uint32_t count = 1;
330       for(uint32_t i=0;i<GetLength();i++)
331       {
332          if( BinArea[i] == '\\')
333             count++;
334       }
335       return count;
336    }
337    return GetLength();
338 }
339
340 /**
341  * \brief Gets a std::vector of 'double' holding the value(s) of a DS DataEntry
342  * @param valueVector std::vector double of value(s)
343  * \return false if VR not "DS" or DataEntry empty
344  */
345  bool DataEntry::GetDSValue(std::vector <double> &valueVector)
346  {
347     /// \todo rewrite the whole method, in order *not to use* std::string !
348     std::vector<std::string> tokens;
349     
350     if (GetVR() != "DS") // never trust a user !
351        return false;    
352        
353     Util::Tokenize ( GetString().c_str(), tokens, "\\" );
354         
355     int nbValues= tokens.size();
356     if (nbValues == 0)
357        return false;
358                
359     for (int loop=0; loop<nbValues; loop++) 
360        valueVector.push_back(atof(tokens[loop].c_str()));
361     
362     return true;  
363  }
364  
365 /**
366  * \brief Sets the 'value' of a DataEntry, passed as a std::string
367  * @param value string representation of the value to be set
368  */ 
369 void DataEntry::SetString(std::string const &value)
370 {
371    DeleteBinArea();
372    const VRKey &vr = GetVR();
373    if ( vr == "US" || vr == "SS" )
374    {
375       std::vector<std::string> tokens;
376       Util::Tokenize (value, tokens, "\\");
377       SetLength(tokens.size()*sizeof(uint16_t));
378       NewBinArea();
379
380       uint16_t *data = (uint16_t *)BinArea;
381       for (unsigned int i=0; i<tokens.size();i++)
382          data[i] = atoi(tokens[i].c_str());
383       tokens.clear();
384    }
385    else if ( vr == "UL" || vr == "SL" )
386    {
387       std::vector<std::string> tokens;
388       Util::Tokenize (value, tokens, "\\");
389       SetLength(tokens.size()*sizeof(uint32_t));
390       NewBinArea();
391
392       uint32_t *data = (uint32_t *)BinArea;
393       for (unsigned int i=0; i<tokens.size();i++)
394          data[i] = atoi(tokens[i].c_str());
395       tokens.clear();
396    }
397    else if ( vr == "FL" )
398    {
399       std::vector<std::string> tokens;
400       Util::Tokenize (value, tokens, "\\");
401       SetLength(tokens.size()*sizeof(float));
402       NewBinArea();
403
404       float *data = (float *)BinArea;
405       for (unsigned int i=0; i<tokens.size();i++)
406          data[i] = (float)atof(tokens[i].c_str());
407       tokens.clear();
408    }
409    else if ( vr == "FD" )
410    {
411       std::vector<std::string> tokens;
412       Util::Tokenize (value, tokens, "\\");
413       SetLength(tokens.size()*sizeof(double));
414       NewBinArea();
415
416       double *data = (double *)BinArea;
417       for (unsigned int i=0; i<tokens.size();i++)
418          data[i] = atof(tokens[i].c_str());
419       tokens.clear();
420    }
421    else
422    {      
423       size_t l =  value.size();    
424       SetLength(l + l%2);
425       NewBinArea();
426       memcpy(BinArea, value.c_str(), l);
427       if (l%2) // padded with blank except for UI
428          if ( vr == "UI" ) 
429             BinArea[l] = '\0';
430          else
431             BinArea[l] = ' ';                
432    }
433    State = STATE_LOADED;
434 }
435 /**
436  * \brief   returns as a string (when possible) the value of the DataEntry
437  */
438 std::string const &DataEntry::GetString() const
439 {
440   static std::ostringstream s;
441   const VRKey &vr = GetVR();
442   s.str("");
443   
444   if (!StrArea)
445      StrArea = new std::string();
446   else 
447      *StrArea="";
448
449   if( !BinArea )
450      return *StrArea;
451       // When short integer(s) are stored, convert the following (n * 2) characters
452   // as a displayable string, the values being separated by a back-slash
453   if( vr == "US" )
454   {
455      uint16_t *data=(uint16_t *)BinArea;
456      for (unsigned int i=0; i < GetValueCount(); i++)
457      {
458         if( i!=0 )
459            s << '\\';
460         s << data[i];
461      }
462      *StrArea=s.str();
463   }
464   else if (vr == "SS" )
465   {
466      int16_t *data=(int16_t *)BinArea;
467      for (unsigned int i=0; i < GetValueCount(); i++)
468      {
469         if( i!=0 )
470            s << '\\';
471         s << data[i];
472      }
473      *StrArea=s.str();
474   }      // See above comment on multiple short integers (mutatis mutandis).
475   else if( vr == "UL" )
476   {
477      uint32_t *data=(uint32_t *)BinArea;
478      for (unsigned int i=0; i < GetValueCount(); i++)
479      {
480         if( i!=0 )
481            s << '\\';
482         s << data[i];
483      }
484      *StrArea=s.str();
485   }
486   else if( vr == "SL" )
487   {
488      int32_t *data=(int32_t *)BinArea;
489      for (unsigned int i=0; i < GetValueCount(); i++)
490      {
491         if( i!=0 )
492            s << '\\';
493         s << data[i];
494      }
495      *StrArea=s.str();
496   }    else if( vr == "FL" )
497   {
498      float *data=(float *)BinArea;
499      for (unsigned int i=0; i < GetValueCount(); i++)
500      {
501         if( i!=0 )
502            s << '\\';
503         s << data[i];
504      }
505      *StrArea=s.str();
506   }
507   else if( vr == "FD" )
508   {
509      double *data=(double *)BinArea;
510      for (unsigned int i=0; i < GetValueCount(); i++)
511      {
512         if( i!=0 )
513            s << '\\';
514         s << data[i];
515      }
516      *StrArea=s.str();
517   }
518   else
519   {
520      StrArea->append((const char *)BinArea,GetLength());
521      // to avoid gdcm to propagate oddities in lengthes
522      if ( GetLength()%2)
523         StrArea->append(" ",1);   }
524   return *StrArea;
525 }
526
527
528 /**
529  * \brief Copies all the attributes from an other DocEntry 
530  * @param doc entry to copy from
531  * @remarks The content BinArea is copied too (StrArea is not)
532  */
533 void DataEntry::Copy(DocEntry *doc)
534 {
535    DocEntry::Copy(doc);
536
537    DataEntry *entry = dynamic_cast<DataEntry *>(doc);
538    if ( entry )
539    {
540       State = entry->State;
541       Flag = entry->Flag;
542       CopyBinArea(entry->BinArea,entry->GetLength());      
543    }
544 }
545
546 /**
547  * \brief   Writes the 'common part' + the 'value' area of a DataEntry
548  * @param fp already open ofstream pointer
549  * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
550  */
551 void DataEntry::WriteContent(std::ofstream *fp, FileType filetype, 
552                                                       bool insideMetaElements)
553
554    // writes the 'common part'
555    DocEntry::WriteContent(fp, filetype, insideMetaElements);
556
557    if ( GetGroup() == 0xfffe )
558    {
559       return; //delimitors have NO value
560    }
561    
562    // --> We only deal with Little Endian writting.
563    // --> forget Big Endian Transfer Syntax writting!
564    //     Next DICOM version will give it up ...
565  
566    // WARNING - For Implicit VR private element,
567    //           we have *no choice* but considering them as
568    //           something like 'OB' values.
569    //           we rewrite them as we found them on disc.
570    //           Some trouble will occur if element was 
571    //           *actually* OW, if image was produced 
572    //           on Big endian based processor, read and writen 
573    //           on Little endian based processor
574    //           and, later on, somebody needs
575    //           this 'OW' Implicit VR private element (?!?)
576    //           (Same stuff, mutatis mutandis, for Little/Big)
577  
578    // 8/16 bits Pixels problem should be solved automatiquely,
579    // since we ensure the VR (OB vs OW) is conform to Pixel size.
580         
581    uint8_t *data = BinArea; //safe notation
582    size_t l = GetLength(); 
583 //   gdcmDebugMacro("in DataEntry::WriteContent " << GetKey() << " AtomicLength: "
584 //              << Global::GetVR()->GetAtomicElementLength(this->GetVR() ) // << " BinArea in :" << &BinArea
585 //             );
586    if (BinArea) // the binArea was *actually* loaded
587    {
588 #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)
589       unsigned short vrLgth = 
590                         Global::GetVR()->GetAtomicElementLength(this->GetVR());
591       unsigned int i;
592       switch(vrLgth)
593       {
594          case 1:
595          {
596             binary_write (*fp, data, l );           
597             break;
598          }     
599          case 2:
600          {
601             uint16_t *data16 = (uint16_t *)data;
602             for(i=0;i<l/vrLgth;i++)
603                binary_write( *fp, data16[i]);
604             break;
605          }
606          case 4:
607          {
608             uint32_t *data32 = (uint32_t *)data;
609             for(i=0;i<l/vrLgth;i++)
610                binary_write( *fp, data32[i]);
611             break;
612          }
613          case 8:
614          {
615             double *data64 = (double *)data;
616             for(i=0;i<l/vrLgth;i++)
617                binary_write( *fp, data64[i]);
618             break;
619          }
620       }
621 #else
622    binary_write (*fp, data, l );
623 #endif //GDCM_WORDS_BIGENDIAN
624
625    }
626    else
627    {
628       // nothing was loaded, but we need to skip space on disc     
629       if (l != 0)
630       {
631       //  --> WARNING : nothing is written; 
632       //  --> the initial data (on the the source image) is lost
633       //  --> user is *not* informed !      
634          gdcmDebugMacro ("Nothing was loaded, but we need to skip space on disc. "
635                       << "Length =" << l << " for " << GetKey() );   
636          fp->seekp(l, std::ios::cur); // At Write time, for unloaded elems
637       }
638    }
639    // to avoid gdcm to propagate oddities
640    // (length was already modified)  
641    if (l%2)
642       fp->seekp(1, std::ios::cur);  // At Write time, for non even length elems
643 }
644
645 /**
646  * \brief   Compute the full length of the elementary DataEntry (not only value
647  *          length) depending on the VR.
648  */
649 uint32_t DataEntry::ComputeFullLength()
650 {
651    return GetFullLength();
652 }
653
654 //-----------------------------------------------------------------------------
655 // Protected
656 /// \brief Creates a DataEntry owned BinArea 
657 ///       (remove previous one if any and relevant StrArea if any)
658 void DataEntry::NewBinArea( )
659 {
660    DeleteBinArea();
661    if( GetLength() > 0 )
662       BinArea = new uint8_t[GetLength()];
663    SelfArea = true;
664 }
665 /// \brief Removes the BinArea, if owned by the DataEntry, 
666 ///        and the relevant StrArea if any
667 void DataEntry::DeleteBinArea(void)
668 {
669    if (BinArea && SelfArea)
670    {
671       delete[] BinArea;
672       BinArea = NULL;
673    }
674    if (StrArea)
675    {
676       delete StrArea;
677       StrArea = 0;
678    }
679 }
680
681 //-----------------------------------------------------------------------------
682 // Private
683
684 //-----------------------------------------------------------------------------
685 // Print
686 /**
687  * \brief   Prints a DataEntry (Dicom entry)
688  * @param   os ostream we want to print in
689  * @param indent Indentation string to be prepended during printing
690  */
691 void DataEntry::Print(std::ostream &os, std::string const & )
692 {
693    os << "D ";
694    DocEntry::Print(os);
695
696    uint16_t g = GetGroup();
697    if (g == 0xfffe) // delimiters have NO value
698    {          
699       return; // just to avoid identing all the remaining code 
700    }
701
702    std::ostringstream s;
703    TSAtr v;
704
705    if( BinArea )
706    {
707       v = GetString();
708       const VRKey &vr = GetVR();
709
710       if( vr == "US" || vr == "SS" || vr == "UL" || vr == "SL" 
711        || vr == "FL" || vr == "FD")
712          s << " [" << GetString() << "]";
713       else
714       { 
715          if(Global::GetVR()->IsVROfStringRepresentable(vr))
716          {
717             // replace non printable characters by '.'
718             std::string cleanString = Util::CreateCleanString(v);
719             if ( cleanString.length() <= GetMaxSizePrintEntry()
720               || PrintLevel >= 3
721               || IsNotLoaded() )
722            // FIXME : when IsNotLoaded(), you create a Clean String ?!?
723            // FIXME : PrintLevel<2 *does* print the values 
724            //        (3 is only for extra offsets printing)
725            // What do you wanted to do ? JPR
726             {
727                s << " [" << cleanString << "]";
728             }
729             else
730             {
731                s << " [GDCM_NAME_SPACE::too long for print (" << cleanString.length() << ") ]";
732             }
733          }
734          else
735          {
736             // A lot of Private elements (with no VR) contain actually 
737             // only printable characters;
738             // Let's deal with them as is they were VR std::string representable
739     
740             if ( Util::IsCleanArea( GetBinArea(), GetLength()  ) )
741             {
742                // FIXME : since the 'Area' *is* clean, just use
743                //         a 'CreateString' method, to save CPU time.
744                std::string cleanString = 
745                      Util::CreateCleanString( BinArea,GetLength()  );
746                s << " [" << cleanString << "]";
747             }
748             else
749             {
750                s << " [" << GDCM_BINLOADED << ";"
751                << "length = " << GetLength() << "]";
752             }
753          }
754       }
755    }
756    else
757    {
758       if( IsNotLoaded() )
759          s << " [" << GDCM_NOTLOADED << "]";
760       else if( IsUnfound() )
761          s << " [" << GDCM_UNFOUND << "]";
762       else if( IsUnread() )
763          s << " [" << GDCM_UNREAD << "]";
764       else if ( GetLength() == 0 )
765          s << " []";
766    }
767
768    if( IsPixelData() )
769       s << " (" << GDCM_PIXELDATA << ")";
770
771    // Display the UID value (instead of displaying only the rough code)
772    // First 'clean' trailing character (space or zero) 
773    if(BinArea)
774    {
775       const uint16_t &gr = GetGroup();
776       const uint16_t &elt = GetElement();
777       TS *ts = Global::GetTS();
778
779       if (gr == 0x0002)
780       {
781          // Any more to be displayed ?
782          if ( elt == 0x0010 || elt == 0x0002 )
783          {
784             if ( v.length() != 0 )  // for brain damaged headers
785             {
786                if ( ! isdigit((unsigned char)v[v.length()-1]) )
787                {
788                   v.erase(v.length()-1, 1);
789                }
790             }
791             s << "  ==>\t[" << ts->GetValue(v) << "]";
792          }
793       }
794       else if (gr == 0x0008)
795       {
796          if ( elt == 0x0016 || elt == 0x1150 )
797          {
798             if ( v.length() != 0 )  // for brain damaged headers
799             {
800                if ( ! isdigit((unsigned char)v[v.length()-1]) )
801                {
802                   v.erase(v.length()-1, 1);
803                }
804             }
805             s << "  ==>\t[" << ts->GetValue(v) << "]";
806          }
807       }
808       else if (gr == 0x0004)
809       {
810          if ( elt == 0x1510 || elt == 0x1512  )
811          {
812             if ( v.length() != 0 )  // for brain damaged headers  
813             {
814                if ( ! isdigit((unsigned char)v[v.length()-1]) )
815                {
816                   v.erase(v.length()-1, 1);  
817                }
818             }
819             s << "  ==>\t[" << ts->GetValue(v) << "]";
820          }
821       }
822    }
823
824    os << s.str();
825 }
826
827 //-----------------------------------------------------------------------------
828 } // end namespace gdcm
829