SDDS ToolKit Programs and Libraries for C and Python
Loading...
Searching...
No Matches
sddspp_write_demo.cc File Reference

Detailed Description

Demonstrates writing every SDDS scalar type with SDDS++.

This is the C++ counterpart of SDDSlib/demo/sdds_write_demo.c. It writes parameters, arrays, and columns to two pages of an ASCII SDDS file.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.

Definition in file sddspp_write_demo.cc.

#include "SDDS.hpp"
#include <cstdint>
#include <exception>
#include <filesystem>
#include <iostream>
#include <optional>
#include <string>
#include <utility>
#include <vector>

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Writes an SDDS++ example file.
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Writes an SDDS++ example file.

Parameters
argcArgument count; an optional output path may be supplied.
argvArgument vector.
Returns
Zero on success, nonzero on failure.

Definition at line 193 of file sddspp_write_demo.cc.

193 {
194 if (argc > 2) {
195 std::cerr << "usage: " << argv[0] << " [output.sdds]\n";
196 return 1;
197 }
198
199 const std::filesystem::path output = argc == 2 ? argv[1] : "example.sdds";
200 try {
201 auto writer = sdds::Writer::create(output, makeLayout());
202 writeFirstPage(writer);
203 writeSecondPage(writer);
204 writer.close();
205 std::cout << "Wrote " << output << "\n";
206 } catch (const std::exception &error) {
207 std::cerr << "Unable to write " << output << ": " << error.what() << '\n';
208 return 1;
209 }
210 return 0;
211}