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 #67593 is a reply to message #67592] Thu, 06 August 2009 15:08 Go to previous message
Paul Van Delst[1] is currently offline  Paul Van Delst[1]
Messages: 1157
Registered: April 2002
Senior Member
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
[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 17 05:09:12 PDT 2025

Total time taken to generate the page: 0.14040 seconds