{"id":19528190,"url":"https://github.com/pucklaj/dynareadout","last_synced_at":"2025-04-26T11:33:01.034Z","repository":{"id":41144253,"uuid":"508086604","full_name":"PucklaJ/dynareadout","owner":"PucklaJ","description":"High-Performance C/C++ library for parsing binary output files and key files of LS Dyna (d3plot, binout, input deck)","archived":false,"fork":false,"pushed_at":"2024-07-24T08:11:53.000Z","size":2701,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-10-28T22:43:33.091Z","etag":null,"topics":["binout","c","cae","cpp","d3plot","dyna","keyfile","ls-dyna"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"zlib","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PucklaJ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-27T23:04:09.000Z","updated_at":"2024-09-02T01:10:23.000Z","dependencies_parsed_at":"2022-07-13T19:30:37.408Z","dependency_job_id":"2da53d49-c2a6-4d5b-869f-bc247ec06f75","html_url":"https://github.com/PucklaJ/dynareadout","commit_stats":{"total_commits":279,"total_committers":1,"mean_commits":279.0,"dds":0.0,"last_synced_commit":"f12438e6b3ed89312ae76766c775880d1fa7f9c8"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PucklaJ%2Fdynareadout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PucklaJ%2Fdynareadout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PucklaJ%2Fdynareadout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PucklaJ%2Fdynareadout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PucklaJ","download_url":"https://codeload.github.com/PucklaJ/dynareadout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224032115,"owners_count":17244373,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binout","c","cae","cpp","d3plot","dyna","keyfile","ls-dyna"],"created_at":"2024-11-11T01:17:54.266Z","updated_at":"2024-11-11T01:17:55.463Z","avatar_url":"https://github.com/PucklaJ.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dynareadout\n\nHigh-Performance and Thread-Safe C/C++ library for parsing binary output files and key files of LS Dyna (d3plot, binout, input deck). The core is written in Ansi C to ensure the highest compatibility and portability to other programming languages.\n\n## Bindings\n\nThis library also supports bindings to other languages\n\n| Language | Repository                                                          |\n| -------- | ------------------------------------------------------------------- |\n| C++      | [dynareadout](https://github.com/PucklaJ/dynareadout)               |\n| Python   | [dynareadout_python](https://github.com/PucklaJ/dynareadout_python) |\n| Go       | [dynareadout_go](https://github.com/PucklaJ/dynareadout_go)         |\n| Odin     | [dynareadout_odin](https://github.com/PucklaJ/dynareadout_odin)     |\n\n## Wiki\n\nThis library has a [wiki](https://github.com/PucklaJ/dynareadout/wiki) which includes the API documentation for all languages.\n\n## Build\n\nYou just need any C compiler and [xmake](https://xmake.io) as the build system. Just call `xmake` and the library will build. You can find the built binaries inside the build folder. To also build some of the bindings you need to call `xmake f` with one or more of the following flags. And then `xmake` again.\n\n| Language | Flag               | Default |\n| -------- | ------------------ | :-----: |\n| C++      | `--build_cpp=y`    |    ✅    |\n| Python   | `--build_python=y` |    ❌    |\n\nThe repository also contains a Makefile. This file can be used to build the C and C++ libraries of dynareadout. By default calling `make` will only compile the C library with **gcc** for **x86_64**, but when executing `make all` it will also build the C++ library. Note that the C++ library requires a gcc installation supporting C++17. The built binaries can be found inside the `build/linux/x86_64/release` folder.\n\n## xmake repo\n\nThis library has been added to the [xmake repo](https://github.com/xmake-io/xmake-repo). Therefore it can be installed using `xrepo install dynareadout`. To use it inside an xmake project use the following code inside your xmake.lua.\n\n```lua\nadd_requires(\"dynareadout\")\n-- enable or disable C++ bindings\n-- add_requires(\"dynareadout\", {configs = {cpp = false}})\n-- shared build instead of static\n-- add_requires(\"dynareadout\", {shared = true})\n-- no thread safety\n-- add_requires(\"dynareadout\", {configs = {thread_safe = false}})\n\ntarget(\"example\")\n  set_kind(\"binary\")\n  add_packages(\"dynareadout\")\n  add_files(\"src/example.c\")\n```\n\n## Python\n\nThe python version of this library can by installed using pip:\n\n```console\npython -m pip install dynareadout\n```\n\nExamples for the python version can be found on the [repository](https://github.com/PucklaJ/dynareadout_python)\n\n## Examples\n\n### C - Binout\n\n```c\n\n#include \u003cbinout.h\u003e\n#include \u003cstdio.h\u003e\n\nint main(int args, char* argv[]) {\n  /* This library also supports opening multiple binout files at once by globing them*/\n  binout_file bin_file = binout_open(\"simulation/binout*\");\n  if (bin_file.error_string) {\n    fprintf(stderr, \"Failed to open binout: %s\\n\", bin_file.error_string);\n    binout_close(\u0026bin_file);\n    /* You could continue after an open error, since it just means that one file failed to open, but in this example we quit*/\n    return 1;\n  }\n\n  /* Print the children of the binout*/\n  size_t num_children;\n  char** children = binout_get_children(\u0026bin_file, \"/\", \u0026num_children);\n  size_t i = 0;\n  while(i \u003c 0) {\n    printf(\"Child %d: %s\\n\", i, children[i]);\n\n    i++;\n  }\n  binout_free_children(children);\n\n  /* Read some data. The library implements read functions for multiple types*/\n  size_t num_node_ids;\n  int32_t* node_ids = binout_read_i32(\u0026bin_file, \"/nodout/metadata/ids\", \u0026num_node_ids);\n  /* After any read you should check error_string*/\n  if (bin_file.error_string) {\n    fprintf(stderr, \"Failed to read node ids: %s\\n\", bin_file.error_string);\n    /* You can just continue with the program*/\n  } else {\n    i = 0;\n    while(i \u003c num_node_ids) {\n      printf(\"Node ID %d: %d\\n\", i, node_ids[i]);\n\n      i++;\n    }\n\n    /* Always make sure to free the data*/\n    free(node_ids);\n  }\n\n\n  binout_close(\u0026bin_file);\n\n  return 0;\n}\n```\n\n### C - D3plot\n\n```c\n#include \u003cd3plot.h\u003e\n#include \u003cstdio.h\u003e\n\nint main(int args, char* argv[]) {\n  /* Just give it the first d3plot file and it opens all of them*/\n  d3plot_file plot_file = d3plot_open(\"simulation/d3plot\");\n  /* Always make sure to check for errors*/\n  if (plot_file.error_string) {\n    fprintf(stderr, \"Failed to open: %s\\n\", plot_file.error_string);\n    d3plot_close(\u0026plot_file);\n    return 1;\n  }\n\n  /* Read the title and run time*/\n  char* title = d3plot_read_title(\u0026plot_file);\n  printf(\"Title: %s\\n\", title);\n  /* Always make sure to check if the return value needs to be deallocated*/\n  free(title);\n\n  struct tm* run_time = d3plot_read_run_time(\u0026plot_file);\n  printf(\"Date: %d.%d.%d\\n\", run_time.tm_mday, run_time.tm_mon, run_time.tm_year);\n\n  /* Read node ids*/\n  size_t num_nodes;\n  d3_word* node_ids = d3plot_read_node_ids(\u0026plot_file, \u0026num_nodes);\n\n  printf(\"Nodes: %d\\n\", num_nodes);\n  for (size_t i = 0; i \u003c num_nodes; i++) {\n    printf(\"Node %d: %d\\n\", i, node_ids[i]);\n  }\n\n  free(node_ids);\n\n  /* Read node coordinates of time step 10*/\n  double* node_coords = d3plot_read_node_coordinates(\u0026plot_file, 10, \u0026num_nodes);\n\n  for (size_t i = 0; i \u003c num_nodes; i++) {\n    printf(\"Node Coords %d: (%.2f, %.2f, %.2f)\\n\", i, node_coords[i * 3 + 0], node_coords[i * 3 + 1], node_coords[i * 3 + 2]);\n  }\n\n  free(node_coords);\n\n  /* Close the d3plot file at the end*/\n  d3plot_close(\u0026plot_file);\n\n  return 0;\n}\n\n```\n\n### C - KeyFile\n\n```c\n#include \u003cerrno.h\u003e\n#include \u003ckey.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003cstdlib.h\u003e\n\nint main(int args, char *argv[]) {\n  size_t num_keywords;\n  char *error_string;\n  keyword_t *keywords =\n      key_file_parse(\"simulation/input.k\", \u0026num_keywords, 1, \u0026error_string);\n  /* Always make sure to check for errors */\n  if (error_string) {\n    fprintf(stderr, \"Failed to parse key file: %s\\n\", error_string);\n    free(error_string);\n    return 1;\n  }\n\n  /* Print all nodes */\n  size_t node_index = 0;\n  keyword_t *node_keyword =\n      key_file_get(keywords, num_keywords, \"NODE\", node_index++);\n  while (node_keyword) {\n    size_t card_index = 0;\n    while (card_index \u003c node_keyword-\u003enum_cards) {\n      card_t *card = \u0026node_keyword-\u003ecards[card_index];\n\n      /* Parse the values of a card by iterating over them*/\n      card_parse_begin(card, DEFAULT_VALUE_WIDTH);\n      const int64_t nid = card_parse_int_width(card, 8);\n      card_parse_next_width(card, 8);\n      const double x = card_parse_float64_width(card, 16);\n      card_parse_next_width(card, 16);\n      const double y = card_parse_float64_width(card, 16);\n      card_parse_next_width(card, 16);\n      const double z = card_parse_float64_width(card, 16);\n\n      /* You can check for parsing errors using errno */\n      if (errno != 0) {\n        fprintf(stderr, \"An error occurred while parsing NODE\\n\");\n      } else {\n        printf(\"NODE %ld: (%.3f; %.3f; %.3f)\\n\", nid, x, y, z);\n      }\n\n      card_index++;\n    }\n\n    node_keyword = key_file_get(keywords, num_keywords, \"NODE\", node_index++);\n  }\n\n  /* Always make sure to deallocate the memory */\n  key_file_free(keywords, num_keywords);\n\n  return 0;\n}\n```\n\n### C++ - Binout\n\n```C++\n#include \u003ciostream\u003e\n#include \u003cbinout.hpp\u003e\n\nint main(int args, char* argv[]) {\n  // The library throws an exception on an error\n  try {\n    dro::Binout bin_file(\"simulation/binout*\");\n\n    const std::vector\u003cdro::String\u003e children = bin_file.get_children(\"/\");\n    for (const auto\u0026 child : children) {\n      std::cout \u003c\u003c \"Child: \" \u003c\u003c child \u003c\u003c std::endl;\n    }\n\n    const dro::Array\u003cint32_t\u003e node_ids = bin_file.read\u003cint32_t\u003e(\"/nodout/metadata/ids\");\n    for (const auto id : node_ids) {\n      std::cout \u003c\u003c \"Node ID: \" \u003c\u003c id \u003c\u003c std::endl;\n    }\n  } catch (const dro::Binout::Exception\u0026 e) {\n    std::cerr \u003c\u003c \"An error occurred: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n    return 1;\n  }\n\n  return 0;\n}\n\n```\n\n### C++ - D3plot\n\n```C++\n#include \u003ciostream\u003e\n#include \u003cd3plot.hpp\u003e\n\nint main(int args, char* argv[]) {\n  try {\n    dro::D3plot plot_file(\"simulation/d3plot\");\n\n    const dro::String title(plot_file.read_title());\n    std::cout \u003c\u003c \"Title: \" \u003c\u003c title \u003c\u003c std::endl;\n\n    struct tm* run_time = plot_file.read_run_time();\n    std::cout \u003c\u003c \"Date: \" \u003c\u003c run_time.tm_mday \u003c\u003c \".\" \u003c\u003c run_time.tm_mon \u003c\u003c \".\" \u003c\u003c run_time.tm_year \u003c\u003c std::endl;\n\n    const dro::Array\u003cd3_word\u003e node_ids(plot_file.read_node_ids());\n    std::cout \u003c\u003c \"Nodes: \" \u003c\u003c node_ids.size() \u003c\u003c std::endl;\n\n    for (const auto\u0026 nid : node_ids) {\n      std::cout \u003c\u003c \"Node ID: \" \u003c\u003c nid \u003c\u003c std::endl;\n    }\n\n    const dro::Array\u003cdro::dVec3\u003e node_coords(plot_file.read_node_coordinates(10));\n    for (const auto\u0026 coords : node_coords) {\n      std::cout \u003c\u003c \"Node Coords: (\" \u003c\u003c coords[0] \u003c\u003c \", \" \u003c\u003c coords[1] \u003c\u003c \", \" \u003c\u003c coords[2] \u003c\u003c \")\" \u003c\u003c std::endl;\n    }\n  } catch (const dro::D3plot::Exception\u0026 e) {\n    std::cerr \u003c\u003c \"An error occurred: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n    return 1;\n  }\n\n  return 0;\n}\n\n```\n\n### C++ - KeyFile\n\n```C++\n#include \u003ciomanip\u003e\n#include \u003ciostream\u003e\n#include \u003ckey.hpp\u003e\n\nint main(int args, char *argv[]) {\n  try {\n    dro::Keywords keywords = dro::KeyFile::parse(\"simulation/input.k\");\n\n    // Parse all nodes\n    for (auto node_keyword : keywords[\"NODE\"]) {\n      for (auto node_card : node_keyword) {\n        auto [nid, x, y, z] =\n            node_card.parse_whole\u003cint, float, float, float\u003e({8, 16, 16, 16});\n\n        std::cout \u003c\u003c std::setprecision(3) \u003c\u003c std::fixed;\n        std::cout \u003c\u003c \"NODE \" \u003c\u003c nid \u003c\u003c \": (\" \u003c\u003c x \u003c\u003c \"; \" \u003c\u003c y \u003c\u003c \"; \" \u003c\u003c z\n                  \u003c\u003c \")\" \u003c\u003c std::endl;\n      }\n    }\n\n  } catch (const dro::KeyFile::Exception \u0026e) {\n    std::cerr \u003c\u003c \"An error occurred: \" \u003c\u003c e.what() \u003c\u003c std::endl;\n  }\n\n  return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpucklaj%2Fdynareadout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpucklaj%2Fdynareadout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpucklaj%2Fdynareadout/lists"}