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

void write_binary_( int *n, double *d, char *str, int *slen, int *stat ){
  *stat = 0;

  FILE* fp = fopen("test.bin", "wb");
  if( fp == NULL ){
    *stat = 1;
  }

  if( fwrite( n, 8, 1, fp ) < 1 ){
    *stat = 3;
  }
  if( fwrite( d, 8, 1, fp ) < 1 ){
    *stat = 3;
  }
  if( fwrite( str, 8, *slen, fp ) < *slen ){
    *stat = 3;
  }

  if( fclose( fp ) == EOF ){
    *stat = 2;
  }
}

void read_binary_( int *n, double *d, char *str, int *slen, int *stat ){
  *stat = 0;

  FILE* fp = fopen("test.bin", "rb");
  if( fp == NULL ){
    *stat = 1;
  }

  if( fread( n, 4, 1, fp ) < 1 ){
    *stat = 3;
  }
  if( fread( d, 8, 1, fp ) < 1 ){
    *stat = 3;
  }
  if( fread( str, 8, *slen, fp ) < *slen ){
    *stat = 3;
  }

  if( fclose(fp) == EOF ){
    *stat = 2;
  }
}