Re: putting .txt files in a structure [message #91685 is a reply to message #91682] |
Wed, 12 August 2015 22:57   |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
Do you mean you want to have the full text of the file as a string in
your structure?
If so, it's not so bad:
nlines = file_lines(filename)
lines = strarr(nlines)
openr, lun, filename, /get_lun
readf, lun, lines
free_lun, lun
cr = string([10B]) ; string([13B, 10B]) on Windows
text = strjoin(lines, cr)
If you have my library, it's just:
text = mg_strmerge(mg_file(filename, /readf))
Then:
btstruc = {mm: momentmm,$
ros: btstruc.ros, $
readme: text}
-Mike
On 8/12/15 3:52 PM, Paul van Delst wrote:
>
>
> On 08/12/15 17:23, Wayana Dolan wrote:
>> Hi Paul.
>>
>> You are correct in assuming that. I would like the text file as a
>> whole to be part of the structure, so that when I hand off my structure
>> to another person, they can know what all the variables are.
>
> Ah. Well, then, you need to write code to read said text file, create
> the (or a) structure based on what you read (e.g. tag names), and then
> populate your newly created structure with values from the file.
>
> It's a fair bit of work (in any language).
>
> I would look at create_struct. It's what I use to read netcdf files into
> a structure. Same deal as what you're doing apart from teh file format.
>
> Other folks may have better/simpler ideas based on their experience.
> E.g. is there a "read_*" function/procedure to do it?
>
> cheers,
>
> paulv
>
>>
>>
>> On Wednesday, August 12, 2015 at 2:05:06 PM UTC-7, Paul van Delst wrote:
>>> On 08/12/15 16:50, Wayana Dolan wrote:
>>>> So I've created a structure which has a bunch of arrays (both
>>>> string,
>>>> and integer). I handwrote a file called readme.txt which explains all
>>>> the variables in the structure. I can't get the file itself to become
>>>> part of the structure.
>>>
>>> I'm not sure exactly what you mean by "get the file itself to become
>>> part of the structure."
>>>
>>> Do you mean the file *name*? [easy]
>>>
>>> Or...
>>>
>>> Do you mean the file *contents*? [hard]
>>>
>>>> Part of the code looks like this (not the actual code, but similar..):
>>>> btstruc={mm=momentmm,$
>>>> ros=btstruc.ros, $
>>>> readme=readme.txt}
>>>>
>>>> Everything works, except the text file!
>>>
>>> The above pseudo-code tells me you are trying to get the file *name* as
>>> part of the structure.
>>>
>>> But somehow I don't think that's what you want....right?
>>
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
|
|
|