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

loadtxt and savetxt #16

Closed
certik opened this issue Dec 19, 2019 · 10 comments · Fixed by #23
Closed

loadtxt and savetxt #16

certik opened this issue Dec 19, 2019 · 10 comments · Fixed by #23
Labels
in progress This proposal is being worked on topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...

Comments

@certik
Copy link
Member

certik commented Dec 19, 2019

Implementation: https://github.com/certik/fortran-utils/blob/b43bd24cd421509a5bc6d3b9c3eeae8ce856ed88/src/utils.f90#L176

The interface is compatible with NumPy (e.g., you can do savetxt from Fortran and do loadtxt from NumPy and it just works, and vice versa).

The loadtxt has the argument as allocatable, intent(out), because you typically do not know the size of the matrix ahead of time.

NumPy: savetxt, loadtxt

@milancurcic
Copy link
Member

I think these are great functions to start with and figure out the workflow. Good to go ahead as far as I'm concerened.

What module would this belong to? stdlib_io in io.f90?

@certik
Copy link
Member Author

certik commented Dec 19, 2019

I think we agreed to prefix modules with stdlib_.

The io module (stdlib_io.f90) might be a good name for it. NumPy has this directly in the numpy namespace, but I think we should have things in modules, not the global stdlib namespace. Because we can always later expose some frequently used functionality in stdlib.f90 directly, but if we put it there now, it will be hard to remove later, as it would break people's code.

There is also scipy.io, with loadmat that loads Matlab's file.

So stdlib_io.f90 works.

@jvdp1
Copy link
Member

jvdp1 commented Dec 19, 2019

@certik Nice examples. I think it could be easily combine with something like

real, allocatable :: a(:)
type(File) :: f
f = File('log.txt')
call f%read(a)
call f%close()

Float, double-precision,integer,... could be then supported.

@milancurcic
Copy link
Member

@certik Correct, I just re-read #9. module stdlib_io in stdlib_io.f90 is good.

@milancurcic
Copy link
Member

@jvdp1 Indeed, plain savetxt and loadtxt will be useful on their own, and the File derived type (a higher level abstraction) can later figure out if and how to use these more basic building blocks.

certik added a commit to certik/stdlib that referenced this issue Dec 19, 2019
This also includes a minimal CMake build system. We can improve the
build system in further PRs.

Fixes fortran-lang#16.
@certik
Copy link
Member Author

certik commented Dec 19, 2019

I sent a PR in #23.

@jacobwilliams
Copy link
Member

We can also get some inspiration from this csv read/write one of mine: https://github.com/jacobwilliams/fortran-csv-module

@certik
Copy link
Member Author

certik commented Dec 19, 2019

@jacobwilliams good point, I created a standalone issue #24 for CSV. You are right that it is related, as in NumPy one can use genfromtxt to read CSV.

@milancurcic milancurcic added the in progress This proposal is being worked on label Dec 19, 2019
@epagone
Copy link

epagone commented Dec 20, 2019

Very nice start. What do you think of adding some optional functionalities like the following?

  • Header handling (we might need to define a "comment" character that introduces the header):
    • when reading simply detect it and store it somewhere;
    • when writing add it and number the columns automatically (very useful for writing plotting scripts).
  • column sorting or indexing using, for example, ODERPACK (if there is no licence clash).

I found very useful (actually necessary) both them but I don't know how much general interest there is.

@certik
Copy link
Member Author

certik commented Dec 20, 2019

@epagone, yes, we can add the header, footer, comments, newline, delimiter arguments for savetxt that NumPy has. We can also do the fmt argument and pass in Fortran formatting string.

All these arguments go after the fname and X arguments, so I think we can add them in subsequent PRs after #23 is merged.

Can you elaborate on the column sorting or indexing using? I don't think NumPy does that. What prevents the user to sort the data before calling savetxt?

jvdp1 pushed a commit to jvdp1/stdlib that referenced this issue Dec 21, 2019
This also includes a minimal CMake build system. We can improve the
build system in further PRs.

Fixes fortran-lang#16.
@jvdp1 jvdp1 added the topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ... label Jan 18, 2020
jvdp1 pushed a commit to jvdp1/stdlib that referenced this issue Dec 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress This proposal is being worked on topic: utilities containers, strings, files, OS/environment integration, unit testing, assertions, logging, ...
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants