]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.cxx
avoid Doxygen Warnings
[gdcm.git] / src / gdcmDataEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/09/14 08:22:19 $
7   Version:   $Revision: 1.48 $
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 // Public
87 /**
88  * \brief Sets the value (non string) of the current DataEntry
89  * @param area area
90  * @param self self=true : The area : *belongs" to the DataEntry 
91  *                                  : will be delete with the DataEntry
92  *             self=false  The area *is not* deleted with the DataEntry
93  *              
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; // padd with zero
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    // if user *knows* that entry contains a US, 
200    // he just has to cast the double he receives
201    
202    const VRKey &vr = GetVR();
203
204    if( vr == "US" || vr == "SS" )
205       return ((uint16_t *)BinArea)[id];
206    else if( vr == "UL" || vr == "SL" )
207       return ((uint32_t *)BinArea)[id];
208    else if( vr == "FL" )
209       return ((float *)BinArea)[id];
210    else if( vr == "FD" )
211       return ((double *)BinArea)[id];
212    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
213    {
214       // this is for VR = "DS", ...
215       if( GetLength() )
216       {
217          // Don't use std::string to accelerate processing
218          double val;
219          char *tmp = new char[GetLength()+1];
220          memcpy(tmp,BinArea,GetLength());
221          tmp[GetLength()]=0;
222
223          if( count == 0 )
224          {
225             val = atof(tmp);
226          }
227          else
228          {
229             count = id;
230             char *beg = tmp;
231             for(uint32_t i=0;i<GetLength();i++)
232             {
233                if( tmp[i] == '\\' )
234                {
235                   if( count == 0 )
236                   {
237                      tmp[i] = 0;
238                      break;
239                   }
240                   else
241                   {
242                      count--;
243                      beg = &(tmp[i+1]);
244                   }
245                }
246             }
247             val = atof(beg);
248          }
249
250          delete[] tmp;
251          return val;
252       }
253       else 
254          return 0.0;
255    }
256    else
257       return BinArea[id];
258 }
259
260 /**
261  * \brief Checks if the multiplicity of the value follows Dictionary VM
262  */
263 bool DataEntry::IsValueCountValid() /*const*/
264 {
265   uint32_t vm;
266   const std::string &strVM = GetVM();
267   uint32_t vc = GetValueCount();
268   bool valid = vc == 0;
269   if( valid )
270     return true;
271   
272   // FIXME : what shall we do with VM = "2-n", "3-n", etc
273   
274   if( strVM == "1-n" )
275   {
276     // make sure there is at least one ??? FIXME
277     valid = vc >= 1;
278   }
279   else
280   {
281     std::istringstream os;
282     os.str( strVM );
283     os >> vm;
284     // Two cases:
285     // vm respects the one from the dict
286     // vm is 0 (we need to check if this element is allowed to be empty) FIXME
287
288     // note  (JPR)
289     // ----    
290     // Entries whose type is 1 are mandatory, with a mandatory value.
291     // Entries whose type is 1c are mandatory-inside-a-Sequence,
292     //                          with a mandatory value.
293     // Entries whose type is 2 are mandatory, with an optional value.
294     // Entries whose type is 2c are mandatory-inside-a-Sequence,
295     //                          with an optional value.
296     // Entries whose type is 3 are optional.
297
298     // case vc == 0 is only applicable for 'type 2' entries.
299     // Problem : entry type may depend on the modality and/or the Sequence
300     //           it's embedded in !
301     //          (Get the information in the 'Conformance Statements' ...)  
302     valid = vc == vm;
303   }
304   return valid;
305 }
306
307 /**
308  * \brief returns the number of elementary values
309  */ 
310 uint32_t DataEntry::GetValueCount( ) const
311 {
312    const VRKey &vr = GetVR();
313    if( vr == "US" || vr == "SS" )
314       return GetLength()/sizeof(uint16_t);
315    else if( vr == "UL" || vr == "SL" )
316       return GetLength()/sizeof(uint32_t);
317    else if( vr == "FL" || vr == "OF" )
318       return GetLength()/4 ; // FL has a *4* length! sizeof(float);
319    else if( vr == "FD" )
320       return GetLength()/8;  // FD has a *8* length! sizeof(double);
321    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
322    {
323       // Some element in DICOM are allowed to be empty
324       if( !GetLength() ) 
325          return 0;
326       // Don't use std::string to accelerate processing
327       uint32_t count = 1;
328       for(uint32_t i=0;i<GetLength();i++)
329       {
330          if( BinArea[i] == '\\')
331             count++;
332       }
333       return count;
334    }
335    return GetLength();
336 }
337
338 /**
339  * \brief Gets a std::vector of 'double' holding the value(s) of a DS DataEntry
340  * @param valueVector std::vector double of value(s)
341  * \return false if VR not "DS" or DataEntry empty
342  */
343  bool DataEntry::GetDSValue(std::vector <double> &valueVector)
344  {
345     /// \todo rewrite the whole method, in order *not to use* std::string !
346     std::vector<std::string> tokens;
347     
348     if (GetVR() != "DS") // never trust a user !
349        return false;    
350        
351     Util::Tokenize ( GetString().c_str(), tokens, "\\" );
352         
353     int nbValues= tokens.size();
354     if (nbValues == 0)
355        return false;
356                
357     for (int loop=0; loop<nbValues; loop++) 
358        valueVector.push_back(atof(tokens[loop].c_str()));
359     
360     return true;  
361  }
362  
363 /**
364  * \brief Sets the 'value' of a DataEntry, passed as a std::string
365  * @param value string representation of the value to be set
366  */ 
367 void DataEntry::SetString(std::string const &value)
368 {
369    DeleteBinArea();
370    const VRKey &vr = GetVR();
371    if ( vr == "US" || vr == "SS" )
372    {
373       std::vector<std::string> tokens;
374       Util::Tokenize (value, tokens, "\\");
375       SetLength(tokens.size()*sizeof(uint16_t));
376       NewBinArea();
377
378       uint16_t *data = (uint16_t *)BinArea;
379       for (unsigned int i=0; i<tokens.size();i++)
380          data[i] = atoi(tokens[i].c_str());
381       tokens.clear();
382    }
383    else if ( vr == "UL" || vr == "SL" )
384    {
385       std::vector<std::string> tokens;
386       Util::Tokenize (value, tokens, "\\");
387       SetLength(tokens.size()*sizeof(uint32_t));
388       NewBinArea();
389
390       uint32_t *data = (uint32_t *)BinArea;
391       for (unsigned int i=0; i<tokens.size();i++)
392          data[i] = atoi(tokens[i].c_str());
393       tokens.clear();
394    }
395    else if ( vr == "FL" )
396    {
397       std::vector<std::string> tokens;
398       Util::Tokenize (value, tokens, "\\");
399       SetLength(tokens.size()*sizeof(float));
400       NewBinArea();
401
402       float *data = (float *)BinArea;
403       for (unsigned int i=0; i<tokens.size();i++)
404          data[i] = (float)atof(tokens[i].c_str());
405       tokens.clear();
406    }
407    else if ( vr == "FD" )
408    {
409       std::vector<std::string> tokens;
410       Util::Tokenize (value, tokens, "\\");
411       SetLength(tokens.size()*sizeof(double));
412       NewBinArea();
413
414       double *data = (double *)BinArea;
415       for (unsigned int i=0; i<tokens.size();i++)
416          data[i] = atof(tokens[i].c_str());
417       tokens.clear();
418    }
419    else
420    {      
421       size_t l =  value.size();    
422       SetLength(l + l%2);
423       NewBinArea();
424       memcpy(BinArea, value.c_str(), l);
425       if (l%2) // padded with blank except for UI
426          if ( vr == "UI" ) 
427             BinArea[l] = '\0';
428          else
429             BinArea[l] = ' ';                
430    }
431    State = STATE_LOADED;
432 }
433 /**
434  * \brief   returns as a string (when possible) the value of the DataEntry
435  */
436 std::string const &DataEntry::GetString() const
437 {
438   static std::ostringstream s;
439   const VRKey &vr = GetVR();
440   s.str("");
441   
442   if (!StrArea)
443      StrArea = new std::string();
444   else 
445      *StrArea="";
446
447   if( !BinArea )
448      return *StrArea;
449       // When short integer(s) are stored, convert the following (n * 2) characters
450   // as a displayable string, the values being separated by a back-slash
451   if( vr == "US" )
452   {
453      uint16_t *data=(uint16_t *)BinArea;
454      for (unsigned int i=0; i < GetValueCount(); i++)
455      {
456         if( i!=0 )
457            s << '\\';
458         s << data[i];
459      }
460      *StrArea=s.str();
461   }
462   else if (vr == "SS" )
463   {
464      int16_t *data=(int16_t *)BinArea;
465      for (unsigned int i=0; i < GetValueCount(); i++)
466      {
467         if( i!=0 )
468            s << '\\';
469         s << data[i];
470      }
471      *StrArea=s.str();
472   }      // See above comment on multiple short integers (mutatis mutandis).
473   else if( vr == "UL" )
474   {
475      uint32_t *data=(uint32_t *)BinArea;
476      for (unsigned int i=0; i < GetValueCount(); i++)
477      {
478         if( i!=0 )
479            s << '\\';
480         s << data[i];
481      }
482      *StrArea=s.str();
483   }
484   else if( vr == "SL" )
485   {
486      int32_t *data=(int32_t *)BinArea;
487      for (unsigned int i=0; i < GetValueCount(); i++)
488      {
489         if( i!=0 )
490            s << '\\';
491         s << data[i];
492      }
493      *StrArea=s.str();
494   }    else if( vr == "FL" )
495   {
496      float *data=(float *)BinArea;
497      for (unsigned int i=0; i < GetValueCount(); i++)
498      {
499         if( i!=0 )
500            s << '\\';
501         s << data[i];
502      }
503      *StrArea=s.str();
504   }
505   else if( vr == "FD" )
506   {
507      double *data=(double *)BinArea;
508      for (unsigned int i=0; i < GetValueCount(); i++)
509      {
510         if( i!=0 )
511            s << '\\';
512         s << data[i];
513      }
514      *StrArea=s.str();
515   }
516   else
517   {
518      StrArea->append((const char *)BinArea,GetLength());
519      // to avoid gdcm to propagate oddities in lengthes
520      if ( GetLength()%2)
521         StrArea->append(" ",1);   }
522   return *StrArea;
523 }
524
525
526 /**
527  * \brief Copies all the attributes from an other DocEntry 
528  * @param doc entry to copy from
529  * @remarks The content BinArea is copied too (StrArea is not)
530  */
531 void DataEntry::Copy(DocEntry *doc)
532 {
533    DocEntry::Copy(doc);
534
535    DataEntry *entry = dynamic_cast<DataEntry *>(doc);
536    if ( entry )
537    {
538       State = entry->State;
539       Flag = entry->Flag;
540       CopyBinArea(entry->BinArea,entry->GetLength());      
541    }
542 }
543
544 /**
545  * \brief   Writes the 'common part' + the 'value' area of a DataEntry
546  * @param fp already open ofstream pointer
547  * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
548  */
549 void DataEntry::WriteContent(std::ofstream *fp, FileType filetype, 
550                                                       bool insideMetaElements, bool insideSequence)
551
552    // writes the 'common part'
553    DocEntry::WriteContent(fp, filetype, insideMetaElements, insideSequence);
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
655 /// \brief Creates a DataEntry owned BinArea 
656 ///       (remove previous one if any and relevant StrArea if any)
657 void DataEntry::NewBinArea( )
658 {
659    DeleteBinArea();
660    if( GetLength() > 0 )
661       BinArea = new uint8_t[GetLength()];
662    SelfArea = true;
663 }
664 /// \brief Removes the BinArea, if owned by the DataEntry, 
665 ///        and the relevant StrArea if any
666 void DataEntry::DeleteBinArea(void)
667 {
668    if (BinArea && SelfArea)
669    {
670       delete[] BinArea;
671       BinArea = NULL;
672    }
673    if (StrArea)
674    {
675       delete StrArea;
676       StrArea = 0;
677    }
678 }
679
680 //-----------------------------------------------------------------------------
681 // Private
682
683 //-----------------------------------------------------------------------------
684 // Print
685 /**
686  * \brief   Prints a DataEntry (Dicom entry)
687  * @param   os ostream we want to print in
688  * @param indent Indentation string to be prepended during printing
689  */
690 void DataEntry::Print(std::ostream &os, std::string const & )
691 {
692    //os << "D ";
693    
694    // First, Print the common part (vr [length offset] name).
695    DocEntry::Print(os);
696
697    uint16_t g = GetGroup();
698    if (g == 0xfffe) // delimiters have NO value
699    {          
700       return; // just to avoid identing all the remaining code 
701    }
702
703    std::ostringstream s;
704    TSAtr v;
705
706    if( BinArea )
707    {
708       v = GetString();
709       const VRKey &vr = GetVR();
710
711       if( vr == "US" || vr == "SS" || vr == "UL" || vr == "SL" 
712        || vr == "FL" || vr == "FD")
713          s << " [" << GetString() << "]";
714       else
715       { 
716          if(Global::GetVR()->IsVROfStringRepresentable(vr))
717          {
718             // replace non printable characters by '.'
719             std::string cleanString = Util::CreateCleanString(v);
720             if ( cleanString.length() <= GetMaxSizePrintEntry()
721               || PrintLevel >= 3
722               || IsNotLoaded() )
723            // FIXME : when IsNotLoaded(), you create a Clean String ?!?
724            // FIXME : PrintLevel<2 *does* print the values 
725            //        (3 is only for extra offsets printing)
726            // What do you wanted to do ? JPR
727             {
728                s << " [" << cleanString << "]";
729             }
730             else
731             {
732                s << " [GDCM_NAME_SPACE::too long for print (" << cleanString.length() << ") ]";
733             }
734          }
735          else
736          {
737             // A lot of Private elements (with no VR) contain actually 
738             // only printable characters;
739             // Let's deal with them as is they were VR std::string representable
740     
741             if ( Util::IsCleanArea( GetBinArea(), GetLength()  ) )
742             {
743                // FIXME : since the 'Area' *is* clean, just use
744                //         a 'CreateString' method, to save CPU time.
745                std::string cleanString = 
746                      Util::CreateCleanString( BinArea,GetLength()  );
747                s << " [" << cleanString << "]";
748             }
749             else
750             {
751                s << " [" << GDCM_BINLOADED << ";"
752                << "length = " << GetLength() << "]";
753             }
754          }
755       }
756    }
757    else
758    {
759       if( IsNotLoaded() )
760          s << " [" << GDCM_NOTLOADED << "]";
761       else if( IsUnfound() )
762          s << " [" << GDCM_UNFOUND << "]";
763       else if( IsUnread() )
764          s << " [" << GDCM_UNREAD << "]";
765       else if ( GetLength() == 0 )
766          s << " []";
767    }
768
769    if( IsPixelData() )
770       s << " (" << GDCM_PIXELDATA << ")";
771
772    // Display the UID value (instead of displaying only the rough code)
773    // First 'clean' trailing character (space or zero) 
774    if(BinArea)
775    {
776       const uint16_t &gr = GetGroup();
777       const uint16_t &elt = GetElement();
778       TS *ts = Global::GetTS();
779
780       if (gr == 0x0002)
781       {
782          // Any more to be displayed ?
783          if ( elt == 0x0010 || elt == 0x0002 )
784          {
785             if ( v.length() != 0 )  // for brain damaged headers
786             {
787                if ( ! isdigit((unsigned char)v[v.length()-1]) )
788                {
789                   v.erase(v.length()-1, 1);
790                }
791             }
792             s << "  ==>\t[" << ts->GetValue(v) << "]";
793          }
794       }
795       else if (gr == 0x0008)
796       {
797          if ( elt == 0x0016 || elt == 0x1150 )
798          {
799             if ( v.length() != 0 )  // for brain damaged headers
800             {
801                if ( ! isdigit((unsigned char)v[v.length()-1]) )
802                {
803                   v.erase(v.length()-1, 1);
804                }
805             }
806             s << "  ==>\t[" << ts->GetValue(v) << "]";
807          }
808       }
809       else if (gr == 0x0004)
810       {
811          if ( elt == 0x1510 || elt == 0x1512  )
812          {
813             if ( v.length() != 0 )  // for brain damaged headers  
814             {
815                if ( ! isdigit((unsigned char)v[v.length()-1]) )
816                {
817                   v.erase(v.length()-1, 1);  
818                }
819             }
820             s << "  ==>\t[" << ts->GetValue(v) << "]";
821          }
822       }
823    }
824
825    os << s.str();
826 }
827
828 //-----------------------------------------------------------------------------
829 } // end namespace gdcm
830