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

Home » Public Forums » archive » Help: Countlines on Win 95 version of IDL
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: Help: Countlines on Win 95 version of IDL [message #10677 is a reply to message #10502] Thu, 18 December 1997 00:00 Go to previous message
David Foster is currently offline  David Foster
Messages: 341
Registered: January 1996
Senior Member
R. Bauer wrote:
>
> PDW wrote:
>
>> I am converting programs from Unix version of IDL to Windows 95, and have a
>> problem with routines using SPAWN and "wc -l" to get the number of lines in
>> a file in order to dimension an array. How can this be done on the PC
>> version?
>

If you need the number of the lines to dimension an array, do you
plan to read the file into a STRARR? If so, you might want to
try FILE_STRARR.PRO, which reads an ASCII file into a STRARR:

========== FILE_STRARR.PRO ===========================================

; FILE_STRARR.PRO 5-27-94
;
; Routine to read text file and return a STRARR containing
; the lines of text. Returns a STRARR(2) containing the null
; string '' and the value of !err_string if an I/O error is encountered
;
; This code adapted from XDISPLAYFILE

FUNCTION file_strarr, fname

ON_IOERROR, IO_ERROR

openr, unit, fname, /get_lun, error=err
if (err ne 0) then begin
return, ['ERROR', !err_string]
endif else begin
max_lines = 1000
a = strarr(max_lines)
i = 0
c = ''
while (not eof(unit)) do begin
readf, unit, c
a(i) = c
i = i + 1
if (i eq max_lines - 2) then begin
a = [a, strarr(1000)]
max_lines = max_lines + 1000
endif
endwhile
a = a(0:i-1)
free_lun, unit
return, a
endelse

IO_ERROR:
message, 'Error reading from file ' + fname, /continue
return, ['ERROR', !err_string]

END

======== .doc file ==============================================
FILE_STRARR

Use this routine to read a text file and return
a STRARR variable containing the lines of text.
This is useful when displaying text-files in
text widgets. If an I/O error such as file-not-
found occurs then returns a STRARR(2) containing
the null string '' and the value of the IDL
system variable !ERR_STRING.


Calling Sequence

Text = FILE_STRARR(Filename)

Arguments

Filename

The name of the file containing the text
you wish to return as a STRARR.

Outputs

Returns the lines of text from the file as
a STRARR variable. If an I/O error occurs
then this will contain two elements: the
string 'ERROR' and the value of the IDL
system variable !ERR_STRING when the error
occured.

Example

Text = FILE_STRARR(Filename)

if (Text(0) eq 'ERROR' and $
n_elements(Text) eq 2) then $
message, 'Error reading file ' + Filename

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
David S. Foster Univ. of California, San Diego
Programmer/Analyst Brain Image Analysis Laboratory
foster@bial1.ucsd.edu Department of Psychiatry
(619) 622-5892 8950 Via La Jolla Drive, Suite 2240
La Jolla, CA 92037
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: DC_Read_Free in IDL?
Next Topic: Re: Object-Oriented Programming Question

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

Current Time: Sun Oct 12 04:50:21 PDT 2025

Total time taken to generate the page: 2.08160 seconds