+/*! \brief
+ * Fill information into the header only from state before writing.
+ *
+ * Populating the header needs to be independent from writing the information
+ * to file to allow things like writing the raw byte stream.
+ *
+ * \param[in] state The current simulation state. Can't write without it.
+ * \param[in] ir Parameter and system information.
+ * \param[in] mtop Global topology.
+ * \returns Fully populated header.
+ */
+static TpxFileHeader populateTpxHeader(const t_state &state,
+ const t_inputrec *ir,
+ const gmx_mtop_t *mtop)
+{
+ TpxFileHeader header;
+ header.natoms = state.natoms;
+ header.ngtc = state.ngtc;
+ header.fep_state = state.fep_state;
+ header.lambda = state.lambda[efptFEP];
+ header.bIr = ir != nullptr;
+ header.bTop = mtop != nullptr;
+ header.bX = (state.flags & (1 << estX)) != 0;
+ header.bV = (state.flags & (1 << estV)) != 0;
+ header.bF = false;
+ header.bBox = true;
+ header.fileVersion = tpx_version;
+ header.fileGeneration = tpx_generation;
+
+ return header;
+}
+