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

Home » Public Forums » archive » Counting header lines in a 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
Counting header lines in a file [message #94605] Fri, 21 July 2017 13:59 Go to previous message
thtran296 is currently offline  thtran296
Messages: 8
Registered: June 2017
Junior Member
Hello guys,

I have a .dat file that looks like this:

Date: May 5, 2016
Name: a person's name goes here
Experiment with temperature blabla

Day. Temperature
1 56
2 62
3 63
4 95

___________________________________________
Anyway, you get the idea.
So I'm trying to read in just the numeric part of the data (the 2 cols of numbers), and ignore the headers.
Here's what I have so far:

lineofheaders = 5
file = 'tryhard.dat'
rows = file_lines(file) ;count rows of entire file
openr, lun, file, /get_pun
header = strarr(lineofheaders). ;pre-allocate to read the header
readf, lun, header
point_lun, -lun, currentlocation
line =""
readf, lun, line
cols = n_elements(float(strsplit(line, /regex)))
data = fltarr(cols,rows - lineofheaders)
point_lun, lun, currentlocation
readf, lun, data
free_lun, lun

The above code did work, of course. However, my problem is that I always have to know in advance the number of lines that the header takes up. For example, in this file the header takes up 5 lines, so I will start reading data from line 6 till end of file.

Is there any way to still do the above, without knowing in advance how many lines the header takes up?

Thank you so much.
Thomas
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Polar_contour question
Next Topic: error with cgPS_Close Program

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

Current Time: Wed Oct 08 13:32:18 PDT 2025

Total time taken to generate the page: 0.00447 seconds