forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading records - each has words separated by spaces

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
Don Wright



Joined: 23 Aug 2016
Posts: 10
Location: Telford, Shropshire, UK

PostPosted: Mon May 29, 2017 10:10 am    Post subject: Reading records - each has words separated by spaces Reply with quote

Need to make an alphabetically sorted list of phrases. Each phrase has several words separated by spaces. Although I have allocated an array for the records specifying expected max record length, each "read" only "strips off" the first word of each record, ignoring the rest. I have looked at all sorts of "qualifiers" for the "open file" and "read record" statements without finding any solution.

There is the obvious, but to me very "unpalatable", solution of replacing all the intervening spaces in any input record, by some other character, like an "underscore". But that, seems a clumsy solution (it's so easy to just tap the space bar between the words in an input record)!

Has any one met with, and overcome, this "truncation of a read at intervening spaces" problem???
Back to top
View user's profile Send private message
Don Wright



Joined: 23 Aug 2016
Posts: 10
Location: Telford, Shropshire, UK

PostPosted: Mon May 29, 2017 10:45 am    Post subject: Reply with quote

I was getting a bit desperate to overcome my problem - but had a mini-brainwave after posting my query, that provided the solution! As with most things the answer is (sometimes) simple. I just changed my "read" statement to read from the input file - to include a specific "format" declaration. Making a guess that there wouldn't be many words in each phrase of each input record - I went for "overkill" and specified "10a" in the specified "format", and that solved my problem, reading all of each record - as one would expect!
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1651
Location: Yateley, Hants, UK

PostPosted: Tue May 30, 2017 11:25 am    Post subject: Reply with quote

I think that my answer to the problem would be to read with (say) A80 and then count back through the trailing blanks to the first non-blank character, which would give me the length of the phrase including words and contained blanks.

If I wanted the words, and how many there were, I'd run through the string looking for separators.

FTN95 does something similar when scanning through a command line: it's in the help file under 'command line parsing options'. Sadly, you can't pretend that your string is a pseudo command line and let FTN95 do the hard work. However, there are some character handling routines in FTN77 that might prove helpful: the manual for that is in the 'Documentation' section of this website and can be downloaded as a PDF.

If Paul was looking for a job in an idle moment, he might please someone by producing the matching routines for sorting out words from a string in the same was as the command line parsing works (in the command line stuff the individual words are referred to as 'tokens' and the separators are somewhat different potentially from just 'blanks'. Perhaps all punctuation counts - I haven't thought that through).

It looks like a simple job to meet your needs, but a much more involved one to deal with the general case.

Eddie
Back to top
View user's profile Send private message
wahorger



Joined: 13 Oct 2014
Posts: 361
Location: Morrison, CO

PostPosted: Thu Jun 01, 2017 5:35 am    Post subject: Reply with quote

This works for me.

Declare a character variable whose length is sufficiient to contain the largetst record in the file.

Declare a character array whose elements are long enough for each word, and enough elements for the longest line.

Something like this:
Code:

character*4096 input_line
character*32 words(128)

read(1,'(a)')input_line
read(input_line,*,end=100)(words(i),i=1,128)
100 i=i-1 ! i now contains the number of words in that line

Process away!
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group