Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save and load subroutines using unformatted stream? #507

Open
Beliavsky opened this issue Sep 1, 2021 · 4 comments
Open

Save and load subroutines using unformatted stream? #507

Beliavsky opened this issue Sep 1, 2021 · 4 comments
Labels
implementation Implementation in experimental and submission of a PR topic: IO Common input/output related features

Comments

@Beliavsky
Copy link

Looking at savetxt and loadtxt are not portable #505 I wonder if save and load subroutines using unformatted stream should be added. The dimensions could be written at the beginning of the file so that a load subroutine can allocate an array of the appropriate shape. I can write a file with this format on Windows and read it with a program compiled by gfortran, Intel, or g95, and also gfortran on WSL. I don't know about more general portability.

@arjenmarkus
Copy link
Member

arjenmarkus commented Sep 1, 2021 via email

@milancurcic
Copy link
Member

Let's discuss the API first. What do you think about savebin and loadbin, analogous to savetxt and loadtxt?

In NumPy, these are called tofile and fromfile.

In its most basic implementation, perhaps we can let the user worry about the array shape? savebin would flatten the input array and write it to file. On loadbin, the user would need to provide an allocated array with the shape they want.

If we then allow the user to specify and encode the array shape in the file, it opens a door toward self-describing formats which we shouldn't try to re-invent considering existing solutions.

@Beliavsky
Copy link
Author

Beliavsky commented Sep 7, 2021

Will savebin write the size (not the dimensions) of the array before writing the array? If not, how will the user provide an allocated array with the proper size to loadbin? One way is to get the file size with inquire(file=data_file,size=file_size) and infer the number of elements.

@awvwgk awvwgk added implementation Implementation in experimental and submission of a PR topic: IO Common input/output related features labels Sep 18, 2021
@14NGiestas
Copy link
Member

Hi @Beliavsky, since #581 we have routines to read and write uncompressed npy files which are basically a self-described binary that can be used for data portability as you suggested. The savebin(array) should not write anything else besides the data being dumped, and the loadbin(array, ...) should receive enough arguments to interpret the binary.

This has some other applications and is related to #621.

It would be awesome to have a binary stream-like thingy like python's bytes (immutable), bytearray (mutable), and the struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
implementation Implementation in experimental and submission of a PR topic: IO Common input/output related features
Projects
None yet
Development

No branches or pull requests

5 participants