+/**
+ * \ingroup DocEntry
+ * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry
+ * @param fp already open file pointer
+ * @param filetype type of the file to be written
+ */
+void DocEntry::Write(FILE* fp, FileType filetype)
+{
+ uint32_t ffff = 0xffffffff;
+ uint16_t group = GetGroup();
+ VRKey vr = GetVR();
+ uint16_t el = GetElement();
+ uint32_t lgr = GetReadLength();
+
+ if ( group == 0xfffe && el == 0x0000 )
+ {
+ // Fix in order to make some MR PHILIPS images e-film readable
+ // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
+ // we just *always* ignore spurious fffe|0000 tag !
+ return;
+ }
+
+ //
+ // ----------- Writes the common part
+ //
+ fwrite ( &group,(size_t)2 ,(size_t)1 ,fp); //group
+ fwrite ( &el, (size_t)2 ,(size_t)1 ,fp); //element
+
+ if ( filetype == ExplicitVR )
+ {
+ // Special case of delimiters:
+ if (group == 0xfffe)
+ {
+ // Delimiters have NO Value Representation
+ // Hence we skip writing the VR.
+ // In order to avoid further troubles, we choose to write them
+ // as 'no-length' Item Delimitors (we pad by writing 0xffffffff)
+ // The end of a given Item will be found when :
+ // - a new Item Delimitor Item is encountered (the Seq goes on)
+ // - a Sequence Delimitor Item is encountered (the Seq just ended)
+
+ // TODO : verify if the Sequence Delimitor Item was forced during Parsing
+
+ int ff = 0xffffffff;
+ fwrite (&ff,(size_t)4 ,(size_t)1 ,fp);
+ return;
+ }
+
+ uint16_t z = 0;
+ uint16_t shortLgr = lgr;
+
+ if (vr == "unkn")
+ {
+ // Unknown was 'written'
+ // deal with Little Endian
+ fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
+ fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
+ }
+ else
+ {
+ fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,fp);
+
+ if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") || (vr == "UN") )
+ {
+ fwrite ( &z, (size_t)2 ,(size_t)1 ,fp);
+ if (vr == "SQ")
+ {
+ // we set SQ length to ffffffff
+ // and we shall write a Sequence Delimitor Item
+ // at the end of the Sequence!
+ fwrite ( &ffff,(size_t)4 ,(size_t)1 ,fp);
+ }
+ else
+ {
+ fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
+ }
+ }
+ else
+ {
+ fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,fp);
+ }
+ }
+ }
+ else // IMPLICIT VR
+ {
+ if (vr == "SQ")
+ {
+ fwrite ( &ffff,(size_t)4 ,(size_t)1 ,fp);
+ }
+ else
+ {
+ fwrite ( &lgr,(size_t)4 ,(size_t)1 ,fp);
+ }
+ }
+}
+