]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.cxx
5bdfe968afebd336c100987a906cd635fa7bd524
[gdcm.git] / src / gdcmDataEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2006/07/10 08:27:27 $
7   Version:   $Revision: 1.41 $
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 
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 <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 '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
553    DocEntry::WriteContent(fp, filetype);
554
555    if ( GetGroup() == 0xfffe )
556    {
557       return; //delimitors have NO value
558    }
559    
560    // --> We only deal with Little Endian writting.
561    // --> forget Big Endian Transfer Syntax writting!
562    //     Next DICOM version will give it up ...
563  
564    // WARNING - For Implicit VR private element,
565    //           we have *no choice* but considering them as
566    //           something like 'OB' values.
567    //           we rewrite them as we found them on disc.
568    //           Some trouble will occur if element was 
569    //           *actually* OW, if image was produced 
570    //           on Big endian based processor, read and writen 
571    //           on Little endian based processor
572    //           and, later on, somebody needs
573    //           this 'OW' Implicit VR private element (?!?)
574    //           (Same stuff, mutatis mutandis, for Little/Big)
575  
576    // 8/16 bits Pixels problem should be solved automatiquely,
577    // since we ensure the VR (OB vs OW) is conform to Pixel size.
578         
579    uint8_t *data = BinArea; //safe notation
580    size_t l = GetLength(); 
581 //   gdcmDebugMacro("in DataEntry::WriteContent " << GetKey() << " AtomicLength: "
582 //              << Global::GetVR()->GetAtomicElementLength(this->GetVR() ) // << " BinArea in :" << &BinArea
583 //             );
584    if (BinArea) // the binArea was *actually* loaded
585    {
586 #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)
587       unsigned short vrLgth = 
588                         Global::GetVR()->GetAtomicElementLength(this->GetVR());
589       unsigned int i;
590       switch(vrLgth)
591       {
592          case 1:
593          {
594             binary_write (*fp, data, l );           
595             break;
596          }     
597          case 2:
598          {
599             uint16_t *data16 = (uint16_t *)data;
600             for(i=0;i<l/vrLgth;i++)
601                binary_write( *fp, data16[i]);
602             break;
603          }
604          case 4:
605          {
606             uint32_t *data32 = (uint32_t *)data;
607             for(i=0;i<l/vrLgth;i++)
608                binary_write( *fp, data32[i]);
609             break;
610          }
611          case 8:
612          {
613             double *data64 = (double *)data;
614             for(i=0;i<l/vrLgth;i++)
615                binary_write( *fp, data64[i]);
616             break;
617          }
618       }
619 #else
620    binary_write (*fp, data, l );
621 #endif //GDCM_WORDS_BIGENDIAN
622
623    }
624    else
625    {
626       // nothing was loaded, but we need to skip space on disc     
627       if (l != 0)
628       {
629       //  --> WARNING : nothing is written; 
630       //  --> the initial data (on the the source image) is lost
631       //  --> user is *not* informed !      
632          gdcmDebugMacro ("Nothing was loaded, but we need to skip space on disc. "
633                       << "Length =" << l << " for " << GetKey() );   
634          fp->seekp(l, std::ios::cur); // At Write time, for unloaded elems
635       }
636    }
637    // to avoid gdcm to propagate oddities
638    // (length was already modified)  
639    if (l%2)
640       fp->seekp(1, std::ios::cur);  // At Write time, for non even length elems
641 }
642
643 /**
644  * \brief   Compute the full length of the elementary DataEntry (not only value
645  *          length) depending on the VR.
646  */
647 uint32_t DataEntry::ComputeFullLength()
648 {
649    return GetFullLength();
650 }
651
652 //-----------------------------------------------------------------------------
653 // Protected
654 /// \brief Creates a DataEntry owned BinArea 
655 ///       (remove previous one if any and relevant StrArea if any)
656 void DataEntry::NewBinArea( )
657 {
658    DeleteBinArea();
659    if( GetLength() > 0 )
660       BinArea = new uint8_t[GetLength()];
661    SelfArea = true;
662 }
663 /// \brief Removes the BinArea, if owned by the DataEntry, 
664 ///        and the relevant StrArea if any
665 void DataEntry::DeleteBinArea(void)
666 {
667    if (BinArea && SelfArea)
668    {
669       delete[] BinArea;
670       BinArea = NULL;
671    }
672    if (StrArea)
673    {
674       delete StrArea;
675       StrArea = 0;
676    }
677 }
678
679 //-----------------------------------------------------------------------------
680 // Private
681
682 //-----------------------------------------------------------------------------
683 // Print
684 /**
685  * \brief   Prints a DataEntry (Dicom entry)
686  * @param   os ostream we want to print in
687  * @param indent Indentation string to be prepended during printing
688  */
689 void DataEntry::Print(std::ostream &os, std::string const & )
690 {
691    os << "D ";
692    DocEntry::Print(os);
693
694    uint16_t g = GetGroup();
695    if (g == 0xfffe) // delimiters have NO value
696    {          
697       return; // just to avoid identing all the remaining code 
698    }
699
700    std::ostringstream s;
701    TSAtr v;
702
703    if( BinArea )
704    {
705       v = GetString();
706       const VRKey &vr = GetVR();
707
708       if( vr == "US" || vr == "SS" || vr == "UL" || vr == "SL" 
709        || vr == "FL" || vr == "FD")
710          s << " [" << GetString() << "]";
711       else
712       { 
713          if(Global::GetVR()->IsVROfStringRepresentable(vr))
714          {
715             // replace non printable characters by '.'
716             std::string cleanString = Util::CreateCleanString(v);
717             if ( cleanString.length() <= GetMaxSizePrintEntry()
718               || PrintLevel >= 3
719               || IsNotLoaded() )
720            // FIXME : when IsNotLoaded(), you create a Clean String ?!?
721            // FIXME : PrintLevel<2 *does* print the values 
722            //        (3 is only for extra offsets printing)
723            // What do you wanted to do ? JPR
724             {
725                s << " [" << cleanString << "]";
726             }
727             else
728             {
729                s << " [gdcm::too long for print (" << cleanString.length() << ") ]";
730             }
731          }
732          else
733          {
734             // A lot of Private elements (with no VR) contain actually 
735             // only printable characters;
736             // Let's deal with them as is they were VR std::string representable
737     
738             if ( Util::IsCleanArea( GetBinArea(), GetLength()  ) )
739             {
740                // FIXME : since the 'Area' *is* clean, just use
741                //         a 'CreateString' method, to save CPU time.
742                std::string cleanString = 
743                      Util::CreateCleanString( BinArea,GetLength()  );
744                s << " [" << cleanString << "]";
745             }
746             else
747             {
748                s << " [" << GDCM_BINLOADED << ";"
749                << "length = " << GetLength() << "]";
750             }
751          }
752       }
753    }
754    else
755    {
756       if( IsNotLoaded() )
757          s << " [" << GDCM_NOTLOADED << "]";
758       else if( IsUnfound() )
759          s << " [" << GDCM_UNFOUND << "]";
760       else if( IsUnread() )
761          s << " [" << GDCM_UNREAD << "]";
762       else if ( GetLength() == 0 )
763          s << " []";
764    }
765
766    if( IsPixelData() )
767       s << " (" << GDCM_PIXELDATA << ")";
768
769    // Display the UID value (instead of displaying only the rough code)
770    // First 'clean' trailing character (space or zero) 
771    if(BinArea)
772    {
773       const uint16_t &gr = GetGroup();
774       const uint16_t &elt = GetElement();
775       TS *ts = Global::GetTS();
776
777       if (gr == 0x0002)
778       {
779          // Any more to be displayed ?
780          if ( elt == 0x0010 || elt == 0x0002 )
781          {
782             if ( v.length() != 0 )  // for brain damaged headers
783             {
784                if ( ! isdigit((unsigned char)v[v.length()-1]) )
785                {
786                   v.erase(v.length()-1, 1);
787                }
788             }
789             s << "  ==>\t[" << ts->GetValue(v) << "]";
790          }
791       }
792       else if (gr == 0x0008)
793       {
794          if ( elt == 0x0016 || elt == 0x1150 )
795          {
796             if ( v.length() != 0 )  // for brain damaged headers
797             {
798                if ( ! isdigit((unsigned char)v[v.length()-1]) )
799                {
800                   v.erase(v.length()-1, 1);
801                }
802             }
803             s << "  ==>\t[" << ts->GetValue(v) << "]";
804          }
805       }
806       else if (gr == 0x0004)
807       {
808          if ( elt == 0x1510 || elt == 0x1512  )
809          {
810             if ( v.length() != 0 )  // for brain damaged headers  
811             {
812                if ( ! isdigit((unsigned char)v[v.length()-1]) )
813                {
814                   v.erase(v.length()-1, 1);  
815                }
816             }
817             s << "  ==>\t[" << ts->GetValue(v) << "]";
818          }
819       }
820    }
821
822    os << s.str();
823 }
824
825 //-----------------------------------------------------------------------------
826 } // end namespace gdcm
827