public C3dWriter(C3dReader copyMetadataFrom, bool eventsEnabled = false) : this( copyMetadataFrom.Labels.ToArray <string>(), copyMetadataFrom.Header.FrameRate, copyMetadataFrom.AnalogLabels.ToArray <string>(), copyMetadataFrom.Header.AnalogSamplingRate, eventsEnabled) { _header.SetHeader(copyMetadataFrom.Header.GetRawData()); foreach (Parameter p in copyMetadataFrom.AllParameters) { string groupName = copyMetadataFrom.GetGroupName(p); CreateGroupIfNotExist(groupName); ParameterGroup grp = _nameToGroups[groupName]; if (!grp.HasParameter(p.Name)) { Parameter newParam = p.Clone(); if (_fs == null) { grp.Parameters.Add(newParam); } else { throw new ApplicationException("Cannot create a parameter " + newParam.Name + " after file was open."); } } else { Parameter param = grp.GetParameter(p.Name); param.CopyDataFrom(p); } // if file is open and we are modifieng an existig an parameter - update changes. if (_fs != null && p.OffsetInFile > 0) { UpdateParameter(p); } } }
private void RewriteWithEvents() { WriteEventContexts(); WriteEvents(); // reset parameters' offsets to enable writing to new file foreach (int id in _idToGroups.Keys) { _idToGroups[id].ResetOffsetInFile(); } _eventsEnabled = false; C3dReader reader = new C3dReader(); if (!reader.Open(GetTempFile(_c3dFile))) { throw new ApplicationException("Could not open temporary file " + GetTempFile(_c3dFile) + "!"); } Open(_c3dFile); for (int i = 0; i < reader.FramesCount; i++) { Vector4 [] points = reader.ReadFrame(); if (reader.IsFloat) { this.WriteFloatFrame(points); } else if (reader.IsInterger) { this.WriteIntFrame(points); } } reader.Close(); this.Close(); }