Number Parsing in Co-array Fortran
In Co-array Fortran, number parsing is typically handled using internal read statements or intrinsic functions. Here’s how to parse numbers from strings:
In this Co-array Fortran example:
We use the
iso_fortran_env
module to ensure we have 64-bit real and integer types.For parsing floating-point numbers and integers, we use internal read statements. The
*
format specifier allows for free-format input.For hexadecimal parsing, we use a specific format specifier
Z20
.Error handling is done by checking the
iostat
variable after each read operation.Co-array Fortran doesn’t have a direct equivalent to
ParseUint
, so we use a regular integer read for the unsigned integer example.There’s no direct equivalent to
Atoi
, but using a regular integer read accomplishes the same thing.The last example demonstrates error handling when trying to parse an invalid input.
To run this program:
This will compile and run the program, outputting the parsed numbers or error messages.
Co-array Fortran’s approach to number parsing is more verbose than some other languages, but it provides fine-grained control over the parsing process and error handling.