- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want to be able to transter a sequence of numbers in a string to an array.
My question is what will be the most intuitive way to behave when the number
of elements in s are different from size of isq
Integer, Allocatable :: isq(:) Call split ( "2/3/5", "/", isq ) subroutine split (s,delim,isq) Character (len=*) :: s Character (len=1) :: delim Integer :: isq end subroutine
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If size(isq) < nfields(s,delim) I fill array elements until size(isq) is reached, neglecting the rest.
When they are same size there is no problem.
So what remains is when size(isq) has more elements being passed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The best thing I found has been not to touch them, unless the user demands to repeat the last element of s.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You may want to consider starting from the basics - see Dr Fortran blog at https://software.intel.com/en-us/blogs/2013/12/30/doctor-fortran-in-its-a-modern-fortran-world. The books mentioned in this blog can give you a sound footing in the fundamentals.
Back to your example, you can allocate the integer array within your procedure which can then make your question moot.
Integer, Allocatable :: isq(:) Call split ( "2/3/5", "/", isq ) subroutine split (s,delim,isq) Character (len=*), intent(in) :: s Character (len=1), intent(in) :: delim Integer, allocatable, intent(out) :: isq(:) .. allocate(isq(..), stat=..) .. end subroutine
Consider the intent specifications for the dummy argument of procedure split: look up the details of intent(out) specification for dummy arguments with allocatable attribute.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
FortranFan,
I think you intended to count the number of delim's then allocate isq(nDelims+1), then fill in the array.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
jimdempseyatthecove wrote:
FortranFan,
I think you intended to count the number of delim's then allocate isq(nDelims+1), then fill in the array.
Jim Dempsey
Yes, you're right Jim.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page