]> Creatis software - gdcm.git/blob - src/gdcmDataEntry.cxx
Trying to normalize JPEG Writing (not yet finished)
[gdcm.git] / src / gdcmDataEntry.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDataEntry.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/08/27 16:14:47 $
7   Version:   $Revision: 1.46 $
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=true : The area : *belongs" to the DataEntry 
94  *                                  : will be delete with the DataEntry
95  *             self=false  The area *is not* deleted with the DataEntry
96  *              
97  */
98 void DataEntry::SetBinArea( uint8_t *area, bool self )  
99
100    DeleteBinArea();
101
102    BinArea = area;
103    SelfArea = self;
104
105    State = STATE_LOADED;
106 }
107 /**
108  * \brief Inserts the value (non string) into the current DataEntry
109  * @param area area
110  * @param length length 
111  */
112 void DataEntry::CopyBinArea( uint8_t *area, uint32_t length )
113 {
114    DeleteBinArea();
115
116    uint32_t lgh = length + length%2;
117    SetLength(lgh);
118
119    if( area && length > 0 )
120    {
121       NewBinArea();
122       memcpy(BinArea,area,length);
123       if( length!=lgh )
124          BinArea[length]=0; // padd with zero
125
126       State = STATE_LOADED;
127    }
128 }
129
130 /**
131  * \brief Inserts the elementary (non string) value into the current DataEntry
132  * @param id index of the elementary value to be set
133  * @param val value, passed as a double 
134  */
135 void DataEntry::SetValue(const uint32_t &id, const double &val)
136 {
137    if( !BinArea )
138       NewBinArea();
139    State = STATE_LOADED;
140
141    if( id > GetValueCount() )
142    {
143       gdcmErrorMacro("Index (" << id << ") is greater than the data size");
144       return;
145    }
146
147    const VRKey &vr = GetVR();
148    if( vr == "US" || vr == "SS" )
149    {
150       uint16_t *data = (uint16_t *)BinArea;
151       data[id] = (uint16_t)val;
152    }
153    else if( vr == "UL" || vr == "SL" )
154    {
155       uint32_t *data = (uint32_t *)BinArea;
156       data[id] = (uint32_t)val;
157    }
158    else if( vr == "FL" )
159    {
160       float *data = (float *)BinArea;
161       data[id] = (float)val;
162    }
163    else if( vr == "FD" )
164    {
165       double *data = (double *)BinArea;
166       data[id] = (double)val;
167    }
168    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
169    {
170       gdcmErrorMacro("SetValue on String representable not implemented yet");
171    }
172    else
173    {
174       BinArea[id] = (uint8_t)val;
175    }
176 }
177 /**
178  * \brief returns, as a double one of the values 
179  *      (when entry is multivaluated), identified by its index.
180  *      Returns 0.0 if index is wrong
181  * @param id id
182  */
183 double DataEntry::GetValue(const uint32_t &id) const
184 {
185    if( !BinArea )
186    {
187       if (GetLength() != 0) // avoid stupid messages
188    /// \todo warn the user there was a problem !
189          gdcmErrorMacro("BinArea not set " << std::hex 
190                      << GetGroup() << " " << GetElement() 
191                      << " Can't get the value");
192       return 0.0;
193    }
194
195    uint32_t count = GetValueCount();
196    if( id > count )
197    {
198       gdcmErrorMacro("Index (" << id << ") is greater than the data size");
199       return 0.0;
200    }
201
202    // if user *knows* that entry contains a US, 
203    // he just has to cast the double he receives
204    
205    const VRKey &vr = GetVR();
206
207    if( vr == "US" || vr == "SS" )
208       return ((uint16_t *)BinArea)[id];
209    else if( vr == "UL" || vr == "SL" )
210       return ((uint32_t *)BinArea)[id];
211    else if( vr == "FL" )
212       return ((float *)BinArea)[id];
213    else if( vr == "FD" )
214       return ((double *)BinArea)[id];
215    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
216    {
217       // this is for VR = "DS", ...
218       if( GetLength() )
219       {
220          // Don't use std::string to accelerate processing
221          double val;
222          char *tmp = new char[GetLength()+1];
223          memcpy(tmp,BinArea,GetLength());
224          tmp[GetLength()]=0;
225
226          if( count == 0 )
227          {
228             val = atof(tmp);
229          }
230          else
231          {
232             count = id;
233             char *beg = tmp;
234             for(uint32_t i=0;i<GetLength();i++)
235             {
236                if( tmp[i] == '\\' )
237                {
238                   if( count == 0 )
239                   {
240                      tmp[i] = 0;
241                      break;
242                   }
243                   else
244                   {
245                      count--;
246                      beg = &(tmp[i+1]);
247                   }
248                }
249             }
250             val = atof(beg);
251          }
252
253          delete[] tmp;
254          return val;
255       }
256       else 
257          return 0.0;
258    }
259    else
260       return BinArea[id];
261 }
262
263 /**
264  * \brief Checks if the multiplicity of the value follows Dictionary VM
265  */
266 bool DataEntry::IsValueCountValid() /*const*/
267 {
268   uint32_t vm;
269   const std::string &strVM = GetVM();
270   uint32_t vc = GetValueCount();
271   bool valid = vc == 0;
272   if( valid )
273     return true;
274   
275   // FIXME : what shall we do with VM = "2-n", "3-n", etc
276   
277   if( strVM == "1-n" )
278   {
279     // make sure there is at least one ??? FIXME
280     valid = vc >= 1;
281   }
282   else
283   {
284     std::istringstream os;
285     os.str( strVM );
286     os >> vm;
287     // Two cases:
288     // vm respects the one from the dict
289     // vm is 0 (we need to check if this element is allowed to be empty) FIXME
290
291     // note  (JPR)
292     // ----    
293     // Entries whose type is 1 are mandatory, with a mandatory value.
294     // Entries whose type is 1c are mandatory-inside-a-Sequence,
295     //                          with a mandatory value.
296     // Entries whose type is 2 are mandatory, with an optional value.
297     // Entries whose type is 2c are mandatory-inside-a-Sequence,
298     //                          with an optional value.
299     // Entries whose type is 3 are optional.
300
301     // case vc == 0 is only applicable for 'type 2' entries.
302     // Problem : entry type may depend on the modality and/or the Sequence
303     //           it's embedded in !
304     //          (Get the information in the 'Conformance Statements' ...)  
305     valid = vc == vm;
306   }
307   return valid;
308 }
309
310 /**
311  * \brief returns the number of elementary values
312  */ 
313 uint32_t DataEntry::GetValueCount( ) const
314 {
315    const VRKey &vr = GetVR();
316    if( vr == "US" || vr == "SS" )
317       return GetLength()/sizeof(uint16_t);
318    else if( vr == "UL" || vr == "SL" )
319       return GetLength()/sizeof(uint32_t);
320    else if( vr == "FL" || vr == "OF" )
321       return GetLength()/4 ; // FL has a *4* length! sizeof(float);
322    else if( vr == "FD" )
323       return GetLength()/8;  // FD has a *8* length! sizeof(double);
324    else if( Global::GetVR()->IsVROfStringRepresentable(vr) )
325    {
326       // Some element in DICOM are allowed to be empty
327       if( !GetLength() ) 
328          return 0;
329       // Don't use std::string to accelerate processing
330       uint32_t count = 1;
331       for(uint32_t i=0;i<GetLength();i++)
332       {
333          if( BinArea[i] == '\\')
334             count++;
335       }
336       return count;
337    }
338    return GetLength();
339 }
340
341 /**
342  * \brief Gets a std::vector of 'double' holding the value(s) of a DS DataEntry
343  * @param valueVector std::vector double of value(s)
344  * \return false if VR not "DS" or DataEntry empty
345  */
346  bool DataEntry::GetDSValue(std::vector <double> &valueVector)
347  {
348     /// \todo rewrite the whole method, in order *not to use* std::string !
349     std::vector<std::string> tokens;
350     
351     if (GetVR() != "DS") // never trust a user !
352        return false;    
353        
354     Util::Tokenize ( GetString().c_str(), tokens, "\\" );
355         
356     int nbValues= tokens.size();
357     if (nbValues == 0)
358        return false;
359                
360     for (int loop=0; loop<nbValues; loop++) 
361        valueVector.push_back(atof(tokens[loop].c_str()));
362     
363     return true;  
364  }
365  
366 /**
367  * \brief Sets the 'value' of a DataEntry, passed as a std::string
368  * @param value string representation of the value to be set
369  */ 
370 void DataEntry::SetString(std::string const &value)
371 {
372    DeleteBinArea();
373    const VRKey &vr = GetVR();
374    if ( vr == "US" || vr == "SS" )
375    {
376       std::vector<std::string> tokens;
377       Util::Tokenize (value, tokens, "\\");
378       SetLength(tokens.size()*sizeof(uint16_t));
379       NewBinArea();
380
381       uint16_t *data = (uint16_t *)BinArea;
382       for (unsigned int i=0; i<tokens.size();i++)
383          data[i] = atoi(tokens[i].c_str());
384       tokens.clear();
385    }
386    else if ( vr == "UL" || vr == "SL" )
387    {
388       std::vector<std::string> tokens;
389       Util::Tokenize (value, tokens, "\\");
390       SetLength(tokens.size()*sizeof(uint32_t));
391       NewBinArea();
392
393       uint32_t *data = (uint32_t *)BinArea;
394       for (unsigned int i=0; i<tokens.size();i++)
395          data[i] = atoi(tokens[i].c_str());
396       tokens.clear();
397    }
398    else if ( vr == "FL" )
399    {
400       std::vector<std::string> tokens;
401       Util::Tokenize (value, tokens, "\\");
402       SetLength(tokens.size()*sizeof(float));
403       NewBinArea();
404
405       float *data = (float *)BinArea;
406       for (unsigned int i=0; i<tokens.size();i++)
407          data[i] = (float)atof(tokens[i].c_str());
408       tokens.clear();
409    }
410    else if ( vr == "FD" )
411    {
412       std::vector<std::string> tokens;
413       Util::Tokenize (value, tokens, "\\");
414       SetLength(tokens.size()*sizeof(double));
415       NewBinArea();
416
417       double *data = (double *)BinArea;
418       for (unsigned int i=0; i<tokens.size();i++)
419          data[i] = atof(tokens[i].c_str());
420       tokens.clear();
421    }
422    else
423    {      
424       size_t l =  value.size();    
425       SetLength(l + l%2);
426       NewBinArea();
427       memcpy(BinArea, value.c_str(), l);
428       if (l%2) // padded with blank except for UI
429          if ( vr == "UI" ) 
430             BinArea[l] = '\0';
431          else
432             BinArea[l] = ' ';                
433    }
434    State = STATE_LOADED;
435 }
436 /**
437  * \brief   returns as a string (when possible) the value of the DataEntry
438  */
439 std::string const &DataEntry::GetString() const
440 {
441   static std::ostringstream s;
442   const VRKey &vr = GetVR();
443   s.str("");
444   
445   if (!StrArea)
446      StrArea = new std::string();
447   else 
448      *StrArea="";
449
450   if( !BinArea )
451      return *StrArea;
452       // When short integer(s) are stored, convert the following (n * 2) characters
453   // as a displayable string, the values being separated by a back-slash
454   if( vr == "US" )
455   {
456      uint16_t *data=(uint16_t *)BinArea;
457      for (unsigned int i=0; i < GetValueCount(); i++)
458      {
459         if( i!=0 )
460            s << '\\';
461         s << data[i];
462      }
463      *StrArea=s.str();
464   }
465   else if (vr == "SS" )
466   {
467      int16_t *data=(int16_t *)BinArea;
468      for (unsigned int i=0; i < GetValueCount(); i++)
469      {
470         if( i!=0 )
471            s << '\\';
472         s << data[i];
473      }
474      *StrArea=s.str();
475   }      // See above comment on multiple short integers (mutatis mutandis).
476   else if( vr == "UL" )
477   {
478      uint32_t *data=(uint32_t *)BinArea;
479      for (unsigned int i=0; i < GetValueCount(); i++)
480      {
481         if( i!=0 )
482            s << '\\';
483         s << data[i];
484      }
485      *StrArea=s.str();
486   }
487   else if( vr == "SL" )
488   {
489      int32_t *data=(int32_t *)BinArea;
490      for (unsigned int i=0; i < GetValueCount(); i++)
491      {
492         if( i!=0 )
493            s << '\\';
494         s << data[i];
495      }
496      *StrArea=s.str();
497   }    else if( vr == "FL" )
498   {
499      float *data=(float *)BinArea;
500      for (unsigned int i=0; i < GetValueCount(); i++)
501      {
502         if( i!=0 )
503            s << '\\';
504         s << data[i];
505      }
506      *StrArea=s.str();
507   }
508   else if( vr == "FD" )
509   {
510      double *data=(double *)BinArea;
511      for (unsigned int i=0; i < GetValueCount(); i++)
512      {
513         if( i!=0 )
514            s << '\\';
515         s << data[i];
516      }
517      *StrArea=s.str();
518   }
519   else
520   {
521      StrArea->append((const char *)BinArea,GetLength());
522      // to avoid gdcm to propagate oddities in lengthes
523      if ( GetLength()%2)
524         StrArea->append(" ",1);   }
525   return *StrArea;
526 }
527
528
529 /**
530  * \brief Copies all the attributes from an other DocEntry 
531  * @param doc entry to copy from
532  * @remarks The content BinArea is copied too (StrArea is not)
533  */
534 void DataEntry::Copy(DocEntry *doc)
535 {
536    DocEntry::Copy(doc);
537
538    DataEntry *entry = dynamic_cast<DataEntry *>(doc);
539    if ( entry )
540    {
541       State = entry->State;
542       Flag = entry->Flag;
543       CopyBinArea(entry->BinArea,entry->GetLength());      
544    }
545 }
546
547 /**
548  * \brief   Writes the 'common part' + the 'value' area of a DataEntry
549  * @param fp already open ofstream pointer
550  * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
551  */
552 void DataEntry::WriteContent(std::ofstream *fp, FileType filetype, 
553                                                       bool insideMetaElements)
554
555    // writes the 'common part'
556    DocEntry::WriteContent(fp, filetype, insideMetaElements);
557
558    if ( GetGroup() == 0xfffe )
559    {
560       return; //delimitors have NO value
561    }
562    
563    // --> We only deal with Little Endian writting.
564    // --> forget Big Endian Transfer Syntax writting!
565    //     Next DICOM version will give it up ...
566  
567    // WARNING - For Implicit VR private element,
568    //           we have *no choice* but considering them as
569    //           something like 'OB' values.
570    //           we rewrite them as we found them on disc.
571    //           Some trouble will occur if element was 
572    //           *actually* OW, if image was produced 
573    //           on Big endian based processor, read and writen 
574    //           on Little endian based processor
575    //           and, later on, somebody needs
576    //           this 'OW' Implicit VR private element (?!?)
577    //           (Same stuff, mutatis mutandis, for Little/Big)
578  
579    // 8/16 bits Pixels problem should be solved automatiquely,
580    // since we ensure the VR (OB vs OW) is conform to Pixel size.
581         
582    uint8_t *data = BinArea; //safe notation
583    size_t l = GetLength(); 
584 //   gdcmDebugMacro("in DataEntry::WriteContent " << GetKey() << " AtomicLength: "
585 //              << Global::GetVR()->GetAtomicElementLength(this->GetVR() ) // << " BinArea in :" << &BinArea
586 //             );
587    if (BinArea) // the binArea was *actually* loaded
588    {
589 #if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION)
590       unsigned short vrLgth = 
591                         Global::GetVR()->GetAtomicElementLength(this->GetVR());
592       unsigned int i;
593       switch(vrLgth)
594       {
595          case 1:
596          {
597             binary_write (*fp, data, l );           
598             break;
599          }     
600          case 2:
601          {
602             uint16_t *data16 = (uint16_t *)data;
603             for(i=0;i<l/vrLgth;i++)
604                binary_write( *fp, data16[i]);
605             break;
606          }
607          case 4:
608          {
609             uint32_t *data32 = (uint32_t *)data;
610             for(i=0;i<l/vrLgth;i++)
611                binary_write( *fp, data32[i]);
612             break;
613          }
614          case 8:
615          {
616             double *data64 = (double *)data;
617             for(i=0;i<l/vrLgth;i++)
618                binary_write( *fp, data64[i]);
619             break;
620          }
621       }
622 #else
623    binary_write (*fp, data, l );
624 #endif //GDCM_WORDS_BIGENDIAN
625
626    }
627    else
628    {
629       // nothing was loaded, but we need to skip space on disc     
630       if (l != 0)
631       {
632       //  --> WARNING : nothing is written; 
633       //  --> the initial data (on the the source image) is lost
634       //  --> user is *not* informed !      
635          gdcmDebugMacro ("Nothing was loaded, but we need to skip space on disc. "
636                       << "Length =" << l << " for " << GetKey() );   
637          fp->seekp(l, std::ios::cur); // At Write time, for unloaded elems
638       }
639    }
640    // to avoid gdcm to propagate oddities
641    // (length was already modified)  
642    if (l%2)
643       fp->seekp(1, std::ios::cur);  // At Write time, for non even length elems
644 }
645
646 /**
647  * \brief   Compute the full length of the elementary DataEntry (not only value
648  *          length) depending on the VR.
649  */
650 uint32_t DataEntry::ComputeFullLength()
651 {
652    return GetFullLength();
653 }
654
655 //-----------------------------------------------------------------------------
656 // Protected
657 /// \brief Creates a DataEntry owned BinArea 
658 ///       (remove previous one if any and relevant StrArea if any)
659 void DataEntry::NewBinArea( )
660 {
661    DeleteBinArea();
662    if( GetLength() > 0 )
663       BinArea = new uint8_t[GetLength()];
664    SelfArea = true;
665 }
666 /// \brief Removes the BinArea, if owned by the DataEntry, 
667 ///        and the relevant StrArea if any
668 void DataEntry::DeleteBinArea(void)
669 {
670    if (BinArea && SelfArea)
671    {
672       delete[] BinArea;
673       BinArea = NULL;
674    }
675    if (StrArea)
676    {
677       delete StrArea;
678       StrArea = 0;
679    }
680 }
681
682 //-----------------------------------------------------------------------------
683 // Private
684
685 //-----------------------------------------------------------------------------
686 // Print
687 /**
688  * \brief   Prints a DataEntry (Dicom entry)
689  * @param   os ostream we want to print in
690  * @param indent Indentation string to be prepended during printing
691  */
692 void DataEntry::Print(std::ostream &os, std::string const & )
693 {
694    os << "D ";
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