comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: unformatted strings (reading)

Re: unformatted strings (reading)
type: item
description: In article <4eule1$si1@news.alaska.edu> immel@gi.alaska.edu (Thomas Immel) writes: > Here's a question for anyone who reads unformatted strings. > Is there a way to read a whole ,say 10 character, string at once > in IDL? Not in general. When written as standard binary, strings don't contain any information about their length, or markers between them. Consequently, IDL has no way of knowing how many bytes to read. However, in the XDR binary mode, stringlengths are stored along with the string, allowing something like the following: IDL> teststrings= ['This','is','a','set of','test strings. Okay?'] IDL> openw,1,'test.dat',/XDR IDL> writeu,1,teststrings IDL> close,1 IDL> openr,1,'test.dat',/XDR IDL> newstrings= strarr(5) ;define some strings, don't worry about their lengths IDL> readu,1,newstrings IDL> print,newstrings This is a set of test strings. Okay? Of course, this is only useful if you can make sure XDR is used in the first place (and if you had control over the writing you could just pad everything out to some known length). Otherwise you can try things like searching for spaces (like another poster suggested), but that could get messy if there are non-strings mixed in with the data. Good luck. Brian Jackel University of Western Ontario
creator: Jackel
date: 1996-02-03T08:00:00-00:00

Re: unformatted strings (reading)
type: item
description: immel@gi.alaska.edu (Thomas Immel) writes: > Here's a question for anyone who reads unformatted strings. > Is there a way to read a whole ,say 10 character, string at once > in IDL? Here's what is happening to me. [example deleted] > 's' !?!? Just the first character. If I define bonk to be two spaces or three > spaces then i get 'st' or 'stu' back. I know it's cause each character is 2 > bytes or something like that. Is there any way, other than defining bonk as 13 > blank spaces before reading, > that I can read this string? Any bright ideas would be appreciated! You could parse the string on delimiters like spaces, commas, tabs etc. I took your example and modified it a little to show this. If your string has just one field, just make your input string array to be one element long (instead of 3 in the example below). There's probably a more elegant way of doing this, but I've used the below routine alot, and it's a good workhorse. You can easily modify it to parse on different delimiters than spaces too. Amara ;*********************************************************** ***************** PRO EXTRACT,A,S,INDEX ;Purpose: This subroutine takes a long string with values separated by ;blanks and extracts the values between the blanks and puts the values into ;the array 'S'. The routine ;automatically figures out how many fields are between the blanks as a check. ;INPUT: A: the long string (a line of data) ; S: a string array already formatted with fields ;OUTPUT: S the array with the values inserted ; INDEX: the number of fields in this line ;----------------------------------------------------------- ------------------ ;Amara Graps 5-16-90 ;----------------------------------------------------------- ------------------ lstring = strlen(a) ;length of input string remainder = a pos = strpos(remainder,' ',0) ;parse on the delimiter ' ' index = 0 while pos ne -1 do begin remainder = strtrim(remainder,2) pos = strpos(remainder,' ',0) if pos ne -1 then begin s(index) = strm…
creator: agraps
date: 1996-02-03T08:00:00-00:00

Re: unformatted strings (reading)
type: item
description: immel@gi.alaska.edu (Thomas Immel) wrote: Thanks for the info and email on this subject. The external data representation is just what I needed to know about. Thanks again Thomas Immel > Here's a question for anyone who reads unformatted strings. > Is there a way to read a whole ,say 10 character, string at once > in IDL? Here's what is happening to me. > 1)Open an unformatted idl file and write a silly string like 'stumblefloppy' > get_lun,unit > openw, unit, 'silly.dat' > writeu,unit,'stumblefloppy' > free_lun, unit > 2) Try to read the string > bonk=' ' ; this is the string variable that I read into > get_lun,unit > openr, unit, 'silly.dat' > readu, unit, bonk > 3) OK, I'm ready to print 'stumblefloppy'! > print,bonk > s > 's' !?!? Just the first character. If I define bonk to be two spaces or three > spaces then i get 'st' or 'stu' back. I know it's cause each character is 2 > bytes or something like that. Is there any way, other than defining bonk as 13 > blank spaces before reading, > that I can read this string? Any bright ideas would be appreciated! > Thomas Immel > Immel@geewiz.gi.alaska.edu > P.S. Ken Knighton, whoever he is, is RIGHT ON!
creator: immel
date: 1996-02-04T08:00:00-00:00

Re: unformatted strings (reading)
type: item
description: immel@gi.alaska.edu (Thomas Immel) wrote: > > > Here's a question for anyone who reads unformatted strings. > Is there a way to read a whole ,say 10 character, string at once > in IDL? Here's what is happening to me. > > > > Thomas Immel > Immel@geewiz.gi.alaska.edu > If you know the length of the string you want to read, you can always do something like: openw, 5, 'test' writeu, 5, 'Whatever' free_lun, 5 openr, 5, 'test' s = string( replicate(32B, 8) ) ; String of 8 spaces readu, 5, s free_lun, 5 print, s Whatever
creator: David Foster
date: 1996-02-07T08:00:00-00:00