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

Add character array interface to loadtxt #919

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chuckyvt
Copy link
Contributor

This PR is to add functionality to the loadtxt function to load a text file into a 1-D allocatable character array. The len of the array will be set based on the longest line found in the file, and the size of the array will equal the number of lines in the file. Added a 'skip_blank_lines' option, which is usueful to match list directed read capability, since that typically would skip blank lines.

The PR functionality and code is inspired by this post and thread though it was heavily modified from Beliavsky's initial code.

Initial commit with src additions, added a test and example and updated docs.
@perazz
Copy link
Member

perazz commented Jan 19, 2025

@chuckyvt loadtxt is meant for reading 2D tabular data, so I'm not sure that an interface with the same name would fit a generic text file read.

Could we instead extend the (getfile) in #904 to also return individual lines?

@chuckyvt
Copy link
Contributor Author

My thought was "loadtxt" is a generic name and shouldn't necessarily be limited to numeric arrays. Using "loadtxt" for numeric arrays and "getfile" for character and string arrays isn't obvious at first glance. Compare that to extending loadtxt to interface with numeric, character and string arrays, which I think is an easier approach for someone new to Fortran.

All that said, I'm open to putting this functionality under getfile, however that procedure being a function instead of a subroutine complicates it a bit. We would need to add an argument to getfile to define the type to return. Alternatively, we could convert getfile to a subroutine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants