-
Notifications
You must be signed in to change notification settings - Fork 181
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
Derived type IO #312
Comments
Yes, this looks like it would be a useful addition. |
I agree with @milancurcic: it would be a nice addition. |
Just a practical question, how would one document the API of such procedure? The official name is user defined derived type input output, which shortens to UDDTIO, which is a completely unwieldable abbreviation in my opinion and I'm saying this coming quantum chemistry background ;). My suggestion would be something along the lines of this: ### Formatted read
#### Description
Read a character sequence from a connected formatted unit into the string.
#### Syntax
`read(unit, fmt, iostat=iostat, iomsg=iomsg) string`
#### Status
Experimental
#### Class
Formatted derived type IO.
#### Argument
- `string`: Instance of the string type to read. This argument is `intent(inout)`.
- `unit`: Formatted unit for input. This argument is `intent(in)`.
- `iotype`: Type of formatted data transfer, has the value `"LISTDIRECTED"` for `fmt=*`,
`"NAMELIST"` for namelist input or starts with `"DT"` for derived type input.
This argument is `intent(in)`.
- `v_list`: Rank one array of default integer type containing the edit descriptors for
derived type input.
This argument is `intent(in)`.
- `iostat`: Status identifier to indicate success of input operation.
This argument is `intent(out)`.
- `iomsg`: Buffer to return error message in case of failing input operation.
This argument is `intent(inout)`.
#### Example
```fortran
use stdlib_string_type
implicit none
type(string_type) :: string
integer :: io
string = "Important saved value"
open(newunit=io, form="formatted", status="scratch")
write(io, *) string
write(io, *)
rewind(io)
read(io, *) string
close(io)
end
``` |
Well, these would be internal so they wouldn't have a user facing API, right? For example, everything in the Arguments section is irrelevant for the user, unless I'm unaware of some feature of UDDTIO. I think the following sentence or similar, in the derived type docstring would suffice:
|
At least We should of course start simple first, just putting in a note for formatted/unformatted read/write is sufficient for now, but there are details which could become important / useful later. |
As long as I am going to address issue #383 for bitsets, I can try to add the appropriate UDDTIO for them. However I have never used or written UDDTIO routines. Does someone have a good reference on how to write and test them? |
@wclodius2 , I am only aware of the Section 11.6 "Defined derived-type input/output" in MRC (the red book). You can also follow the stdlib/src/stdlib_string_type.fypp Line 326 in 8228b94
The formatted interfaces will look like:
The actual implementation can go in the submodule (only shown here for
The error checking and messages could use further improving. Press here for an example
Output:
|
@ivan-pi thanks! I am a bit busy to have more than one git iron in the fire at a time, but once the sorting PR is approved this will be my next project. |
There is no rush, I've been working on some small bitset example programs and I will probably open an issue with other suggestions soon. With the UDDTIO usage is really simplified and it makes it feel much more natural! No need to use the string conversion routines and look-up the details of which procedure to call. A simple |
With types like the
bitset_type
it might be a really useful feature to use them in normal IO (read
andwrite
data transfer). Thebitset_type
for example implements awrite_bitset
interface, but could as well define the very same function as derived type IO:An interface to a formatted write usually looks like
While an interface to an unformatted write is given here for short reference
This would allow to easily write a bitset with
The text was updated successfully, but these errors were encountered: