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 #10540 is a reply to message #10502] Wed, 17 December 1997 00:00 Go to previous messageGo to previous message
R. Bauer is currently offline  R. Bauer
Messages: 137
Registered: November 1996
Senior Member
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?


Hy Paul,

I have included two of my routines.
filesize uses fstat to get the byte size of the file
This is used by fileline to read the file at once in a byte array.
Then the 10b are counted and returned.

This routines works on win95 and unix.

R.Bauer


; $Id: filesize.pro,v 1. 1997/06/13 13:31:13 RwB ICG-1 $
;
; Copyright (c) 1997, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
;+
; NAME:
; filesize
;
; PURPOSE:
; This function founds the bytelength of an ascii file
;
; CATEGORY:
; DATAFILES/FILE
;
; CALLING SEQUENCE:
; Result=filesize(file_name)
;
; INPUTS:
; file_name: the name of an ascii file
;
;
; OUTPUTS:
; This function returns the number of bytes of an ascii file
;
;
; EXAMPLE:
; Result=filesize('test.asc')
;
; MODIFICATION HISTORY:
; Written by: R.Bauer (ICG-1), Oct. 1996
;-

function filesize, filename


;debug,'<filesize> 1.1 RB 1997-Sep-16'

if n_params(0) lt 1 then begin
help: print, ' Diese Hilfe kommt mit a=filesize().'
print,' '
print,' stellt fest wieviele Bytes in einer Datei sind.'
print,''
print,'Example'
print,"a=filesize('testfile.asc')"
print,'----------------------------------------------------- --'
return,-1
help_open: print,'(filesize) Das File: ',filename,' gibt es nicht.'
return,-1
ENDIF

openr, lun, filename, /get_lun,error=err
if err ne 0 then goto, help_open
stats = fstat(lun)
free_lun, lun

return, stats.size
end



; $Id: fileline.pro,v 1. 1997/06/13 13:31:13 RwB ICG-1 $
;
; Copyright (c) 1997, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
;+
; NAME:
; fileline
;
; PURPOSE:
; This function founds the number of lines of an ascii file
;
; CATEGORY:
; DATAFILES/FILE
;
;
; CALLING SEQUENCE:
; Result=fileline(file_name)
;
; INPUTS:
; file_name: the name of an ascii file
;
;
; OUTPUTS:
; This function returns the number of lines of an asii file
;
;
; EXAMPLE:
; Result=fileline('test.asc')
;
; MODIFICATION HISTORY:
; Written by: R.Bauer (ICG-1), Oct. 1996
;-


function fileline, filename


;debug,'<fileline> 1.1 RB 1997-Sep-16'

if n_params(0) lt 1 then begin
help: print, ' Diese Hilfe kommt mit a=fileline().'
print,' '
print,' stellt fest wieviele Zeilen in einer ASCII Datei sind.'
print,''
print,'Example'
print,"a=fileline('testfile.asc')"
print,'----------------------------------------------------- --'
return,-1
help_open: print,'(fileline) Das File: ',filename,' gibt es nicht.'
return,-1
ENDIF

byt=filesize(filename)


if byt eq -1 then goto, help_open

lesefeld=bytarr(byt)

openr,lun,filename,/get_lun,error=err
if err ne 0 then goto, help_open
readu,lun,lesefeld
close,lun

free_lun,lun
line=where(lesefeld eq 10B,count_line)

return,count_line
END




--
R.Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
[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: Sat Oct 11 23:19:34 PDT 2025

Total time taken to generate the page: 0.96310 seconds