- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (((gdcmValEntry *)tag)->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint32 val_uint32 = atoi(tokens[i].c_str());
- void *ptr = &val_uint32;
- fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- fwrite (((gdcmValEntry *)tag)->GetValue().c_str(), (size_t)lgr ,(size_t)1, _fp); // Elem value
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * a single gdcmDocEntry passed as argument.
- * \sa WriteEntryValue, WriteEntryTagVRLength.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written
- */
-
-bool gdcmDocument::WriteEntry(gdcmDocEntry *tag, FILE *_fp,FileType type)
-{
- guint32 length = tag->GetLength();
-
- if (gdcmValEntry* ValEntry = dynamic_cast< gdcmValEntry* >(tag) ) {
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
- if(length%2==1) {
- ValEntry->SetValue(ValEntry->GetValue()+"\0");
- ValEntry->SetLength(ValEntry->GetReadLength()+1);
- }
- WriteEntryTagVRLength(ValEntry, _fp, type);
- WriteEntryValue(ValEntry, _fp, type);
- return true;
- }
-
- if (gdcmBinEntry* BinEntry = dynamic_cast< gdcmBinEntry* >(tag) ) {
- //
- // FIXME : when voidArea belong to gdcmBinEntry only, fix voidArea length
- //
- // The value of a tag MUST (see the DICOM norm) be an odd number of
- // bytes. When this is not the case, pad with an additional byte:
- /*
- if(length%2==1) {
- tag->SetValue(tag->GetValue()+"\0");
- tag->SetLength(tag->GetReadLength()+1);
- }
-*/
- WriteEntryTagVRLength(tag, _fp, type);
- WriteEntryValue(tag, _fp, type);
- return true;
- }
-}
-
-/**
- * \brief writes on disc according to the requested format
- * (ACR-NEMA, ExplicitVR, ImplicitVR) the image
- * using the Chained List
- * \warning does NOT add the missing elements in the header :
- * it's up to the user doing it !
- * (function CheckHeaderCoherence to be written)
- * \warning DON'T try, right now, to write a DICOM image
- * from an ACR Header (meta elements will be missing!)
- * @param type type of the File to be written
- * (ACR-NEMA, ExplicitVR, ImplicitVR)
- * @param _fp already open file pointer
- */
-
-bool gdcmDocument::WriteEntries(FILE *_fp,FileType type)
-{
-
-// FIXME : explore recursively the whole structure...
-
- /// \todo (?) check write failures (after *each* fwrite)
-
- std::cout << "--------------------- gdcmDocument::WriteEntries " << std::endl;
- for (TagDocEntryHT::iterator tag2=tagHT.begin();
- tag2 != tagHT.end();
- ++tag2)
- {
-
- (*tag2).second->Print();
-
- if ( type == gdcmACR ){
- if ((*tag2).second->GetGroup() < 0x0008)
- // Ignore pure DICOM V3 groups
- continue;
- if ((*tag2).second->GetGroup() %2)
- // Ignore the "shadow" groups
- continue;
- if ((*tag2).second->GetVR() == "SQ" ) // ignore Sequences
- continue;
- }
- if (! WriteEntry((*tag2).second,_fp,type) ) {
- std::cout << "Write Failure " << std::endl;
- return false;
- } else {
-
- }