/****************************************************************************
**  SIONLIB     http://www.fz-juelich.de/jsc/sionlib                       **
*****************************************************************************
**  Copyright (c) 2008-2019                                                **
**  Forschungszentrum Juelich, Juelich Supercomputing Centre               **
**                                                                         **
**  See the file COPYRIGHT in the package base directory for details       **
****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sion.h"

#define N_FILES 4
#define BUFFER_SIZE 1024

int main(int argc, char** argv)
{
  char buffer[BUFFER_SIZE];
  memset(buffer, 'A', BUFFER_SIZE);

  int sid = sion_open("serfile.sion", SION_OPEN_WRITE, N_FILES, NULL);

  size_t bwrote = sion_write(buffer, 1, BUFFER_SIZE, sid);
  printf("Wrote %zd bytes\n", bwrote);

  sion_close(sid);

  sid = sion_open("serfile.sion", SION_OPEN_READ, 0, NULL);

  size_t bread = sion_read(buffer, 1, BUFFER_SIZE, sid);
  printf("Read %zd bytes\n", bread);
  printf("At end of file: %s\n", (sion_eof(sid)) ? "true" : "false");

  sion_close(sid);

  return EXIT_SUCCESS;
}
