comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Skipping Commented Line in File
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Skipping Commented Line in File [message #67592 is a reply to message #67585] Thu, 06 August 2009 15:13 Go to previous messageGo to previous message
vikramivatury is currently offline  vikramivatury
Messages: 24
Registered: May 2009
Junior Member
On Aug 6, 6:08 pm, Paul van Delst <paul.vande...@noaa.gov> wrote:
> Vikram wrote:
>> Hello,
>
>> I was wondering if there is a way to skip a commented line in a .txt
>> file, for example:
>
>> #Count Time
>> 1 60
>> 2 80
>> 3 100
>
>> I would like to start from the second row data and skip the labels.
>
>> Thanks,
>> Vikram
>
> I can think of several ways, but below is what I use for files that may also include
> embedded blank lines and comments:
>
> FUNCTION Is_A_CommentLine, Line
> RETURN, STRMID(STRTRIM(Line,1),0,1) EQ '#'
> END ; FUNCTION Is_A_CommentLine
>
> FUNCTION Is_A_BlankLine, Line
> RETURN, STRLEN(STRTRIM(Line,2)) EQ 0
> END ; FUNCTION Is_A_BlankLine
>
> PRO test
> Line = ''
> OPENR, fid, 'test.txt', /GET_LUN
> WHILE ( NOT EOF(fid) ) DO BEGIN
> ; ...Read a line from the file
> READF, fid, Line
> ; ...Cycle loop if this is an embedded comment or blank line
> IF ( Is_A_CommentLine(Line) OR Is_A_BlankLine(Line) ) THEN CONTINUE
> ; Otherwise read the line into variables
> READS, Line, x, y
> PRINT, x, y
> ; Store x and y into array
> ; .... etc etc ....
> ENDWHILE
> FREE_LUN, fid
> END
>
> Here's my test.txt file:
>
> #<----start of file----->
> #Count Time
> 1 60
> 2 80
> 3 100
> 4 80
> 5 100
> 6 100
> #embedded comment!
> 7 80
> 8 100
> 9 100
> 10 80
>
> # comment surrounded by blank lines!
>
> 11 100
> 12 100
> 13 80
> 14 100
> 15 100
> 16 80
> 17 100
> #<----end of file----->
>
> and here the above test.pro output:
>
> IDL> .run test
> % Compiled module: IS_A_COMMENTLINE.
> % Compiled module: IS_A_BLANKLINE.
> % Compiled module: TEST.
> IDL> test
> 1.00000 60.0000
> 2.00000 80.0000
> 3.00000 100.000
> 4.00000 80.0000
> 5.00000 100.000
> 6.00000 100.000
> 7.00000 80.0000
> 8.00000 100.000
> 9.00000 100.000
> 10.0000 80.0000
> 11.0000 100.000
> 12.0000 100.000
> 13.0000 80.0000
> 14.0000 100.000
> 15.0000 100.000
> 16.0000 80.0000
> 17.0000 100.000
>
> cheers,
>
> paulv

Thanks for your help Paul! I will take at look at this program.

-Vikram
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: closing tabs of widget_tab()
Next Topic: Re: IDL PostScript Landscape Mode (Not!) Fixed

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Oct 10 12:59:41 PDT 2025

Total time taken to generate the page: 0.32068 seconds