+ for (TagElValueHT::iterator tag2=tagHt.begin();
+ tag2 != tagHt.end();
+ ++tag2){
+
+ gr = tag2->second->GetGroup();
+ el = tag2->second->GetElement();
+ lgr = tag2->second->GetLength();
+ val = tag2->second->GetValue().c_str();
+ vr = tag2->second->GetVR();
+
+ // cout << "Tag "<< hex << gr << " " << el << "\n";
+
+ if ( type == ACR ) {
+ if (gr < 0x0008) continue; // ignore pure DICOM V3 groups
+ if (gr %2) continue; // ignore shadow groups
+ if (vr == "SQ" ) continue; // ignore Sequences
+ if (gr == 0xfffe ) continue; // ignore delimiters
+ }
+
+ fwrite ( &gr,(size_t)2 ,(size_t)1 ,_fp); //group
+ fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element
+
+ if ( (type == ExplicitVR) && (gr <= 0x0002) ) {
+ // EXPLICIT VR
+ guint16 z=0, shortLgr;
+ fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp);
+
+ if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") ) {
+ fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp);
+ fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
+
+ } else {
+ shortLgr=lgr;
+ fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
+ }
+ } else { // IMPLICIT VR
+ fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
+ }
+
+ if (vr == "US" || vr == "SS") {
+ tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+ Tokenize (tag2->second->GetValue(), tokens, "\\");
+ for (unsigned int i=0; i<tokens.size();i++) {
+ val_uint16 = atoi(tokens[i].c_str());
+ ptr = &val_uint16;
+ fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
+ }
+ tokens.clear();
+ continue;
+ }
+ if (vr == "UL" || vr == "SL") {
+ tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+ Tokenize (tag2->second->GetValue(), tokens, "\\");
+ for (unsigned int i=0; i<tokens.size();i++) {
+ val_uint32 = atoi(tokens[i].c_str());
+ ptr = &val_uint32;
+ fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
+ }
+ tokens.clear();
+ continue;
+ }
+ // Pixels are never loaded in the element !
+ if ((gr == 0x7fe0) && (el == 0x0010) ) break;
+
+ fwrite ( val,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
+ }
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param _fp
+ * @param type
+ * @return
+ */
+int gdcmElValSet::Write(FILE * _fp, FileType type) {
+
+ if (type == ImplicitVR) {
+ string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
+ SetElValueByNumber(implicitVRTransfertSyntax, 0x0002, 0x0010);
+
+ //FIXME Refer to standards on page 21, chapter 6.2 "Value representation":
+ // values with a VR of UI shall be padded with a single trailing null
+ // Dans le cas suivant on doit pader manuellement avec un 0
+
+ SetElValueLengthByNumber(18, 0x0002, 0x0010);
+ }
+ // Question :
+ // Comment pourrait-on savoir si le DcmHeader vient d'un fichier DicomV3 ou non ,