27#define _FILE_OFFSET_BITS 64
46static const int64_t size_of[6] = {4, 8, 8, 16, 4, 8};
67 for (ii = 0; ii < size; ii++)
69 for (ii = 0; ii < size; ii++)
70 aa[ii] = tmp[size - 1 - ii];
106 strcpy(hp->
text,
"pulpo");
115 for (ii = 0; ii < 5; ii++)
120 if (strcmp(
"pulpo", hp->
text) != 0)
143 *correct_endianness = 0;
145 if (hp->
one_f != 1.0) {
147 if (hp->
one_f != 1.0)
149 *correct_endianness = 1;
152 if (hp->
one_d != 1.0) {
154 if (hp->
one_d != 1.0)
156 *correct_endianness = 1;
174 fd =
open(fname, O_WRONLY | O_CREAT | O_TRUNC,
175 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
178 printf(
"Filename is %s\n", fname);
179 inf_error(
"octopus.write_header in creating the header");
195 inf_error(
"octopus.write_header in writing the header");
205 int *nhd,
int *flpe,
char *fname) {
219 fd =
open(fname, O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
222 inf_error(
"octopus.write_binary in opening the file");
228 lseek(
fd, 0, SEEK_END);
232 for (ii = 0; ii < (*np) * size_of[(*type)]; ii +=
base_size_of[(*type)])
237 bytes_to_write = (*np) * size_of[(*type)];
239 while (bytes_to_write > 0) {
240 moved = write(
fd, ff + offset, bytes_to_write);
247 bytes_to_write -= moved;
264 fd =
open(fname, O_RDONLY);
291 int *output_type,
int *ierr,
int *iio,
char *fname) {
296 int correct_endianness;
311 if (hp->
np < *np + *offset) {
317 fd =
open(fname, O_RDONLY);
326 if (hp->
type == *output_type) {
331 read_f = (
byte *)malloc((*np) * size_of[hp->
type]);
336 lseek(
fd, (*offset) * size_of[hp->
type] +
sizeof(
header_t), SEEK_SET);
341 moved = read(
fd, read_f, (*np) * size_of[hp->
type]);
346 if (moved != (*np) * size_of[hp->
type]) {
349 if (hp->
type != *output_type) {
358 if (correct_endianness) {
364 if (hp->
type != *output_type) {
370 for (ii = 0; ii < *np; ii++)
372 (
multi *)(ff + ii * size_of[*output_type]), hp->
type,
379 if (hp->
type == TYPE_FLOAT_COMPLEX)
381 if (hp->
type == TYPE_DOUBLE)
383 if (hp->
type == TYPE_DOUBLE_COMPLEX)
399 if (t_in == TYPE_FLOAT && t_out == TYPE_DOUBLE) {
400 out->d[0] =
in->f[0];
404 if (t_in == TYPE_DOUBLE && t_out == TYPE_FLOAT) {
405 out->f[0] =
in->d[0];
410 if (t_in == TYPE_FLOAT_COMPLEX && t_out == TYPE_DOUBLE_COMPLEX) {
411 out->d[0] =
in->f[0];
412 out->d[1] =
in->f[1];
415 if (t_in == TYPE_DOUBLE_COMPLEX && t_out == TYPE_FLOAT_COMPLEX) {
416 out->f[0] =
in->d[0];
417 out->f[1] =
in->d[1];
422 if (t_in == TYPE_FLOAT && t_out == TYPE_FLOAT_COMPLEX) {
423 out->f[0] =
in->f[0];
424 out->f[1] = (float)0.0;
428 if (t_in == TYPE_DOUBLE && t_out == TYPE_FLOAT_COMPLEX) {
434 if (t_in == TYPE_FLOAT && t_out == TYPE_DOUBLE_COMPLEX) {
435 out->d[0] =
in->f[0];
436 out->d[1] = (double)0.0;
440 if (t_in == TYPE_DOUBLE && t_out == TYPE_DOUBLE_COMPLEX) {
441 out->d[0] =
in->d[0];
447 if (t_in == TYPE_FLOAT_COMPLEX && t_out == TYPE_FLOAT) {
448 out->f[0] = c2r(
in->f[0],
in->f[1]);
452 if (t_in == TYPE_DOUBLE_COMPLEX && t_out == TYPE_FLOAT) {
457 if (t_in == TYPE_FLOAT_COMPLEX && t_out == TYPE_DOUBLE) {
462 if (t_in == TYPE_DOUBLE_COMPLEX && t_out == TYPE_DOUBLE) {
463 out->d[0] = c2r(
in->d[0],
in->d[1]);
469 int *iio,
char *fname) {
471 int correct_endianness;
490 *file_size = (
int64_t)st.st_size;
static void convert(multi *in, multi *out, int t_in, int t_out)
void get_info_binary(int64_t *np, int *type, int64_t *file_size, int *ierr, int *iio, char *fname)
static int check_header(header_t *hp, int *correct_endianness)
void io_write_header(const int64_t *np, int *type, int *ierr, int *iio, char *fname)
static const int64_t base_size_of[6]
static const int64_t is_integer[6]
void read_binary(const int64_t *np, const int64_t *offset, byte *ff, int *output_type, int *ierr, int *iio, char *fname)
static void init_header(header_t *hp)
static void endian_convert(const int size, char *aa)
void io_read_header(header_t *hp, int *correct_endianness, int *ierr, int *iio, char *fname)
void write_binary(const int64_t *np, void *ff, int *type, int *ierr, int *iio, int *nhd, int *flpe, char *fname)
static void inf_error(const char *msg)
int open(const char *__file, int __oflag,...) __asm__("" "open64") __attribute__((__nonnull__(1)))
character(len=512), private msg
int stat(const char *__restrict __file, struct stat *__restrict __buf) __attribute__((__nothrow__