Re: reading ASCII Data [message #14999 is a reply to message #14993] |
Tue, 13 April 1999 00:00   |
R.Bauer
Messages: 1424 Registered: November 1998
|
Senior Member |
|
|
Mirko wrote:
> Was in a hurry this mornig an missed to put an example on.
> 1 08.04.1999 15:27:12:40 11.04 1.05722E-007 2.14 9.9E-009 16.05
> 3.59375E-009 28.02 4.20938E-009 44.03 1.2875E-009
> 2 08.04.1999 15:27:21:60 20.6 1.07047E-007 2.19 1.04469E-008 16.05
> 3.66875E-009 17.06 1.89781E-008 18.09 6.69937E-008 28.02
> 4.11563E-009 31.94 1.49062E-009 43.97 1.35312E-009
> 3 08.04.1999 15:27:30:44 29.44 1.14278E-007 ... and so on for the next
> 700 ranges
>
> Any suggestions?
>
> Cheers
file='test.dat'
IF file_exist(file) THEN A = fileline('test.dat')
R.Bauer
; Copyright (c) 1998, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made. This
; routine is provided as is without any express or implied warranties
; whatsoever.
;
;+
; NAME:
; file_exist
;
; PURPOSE:
; The result of this function is 1 if a file exist and 0 if not
;
; CATEGORY:
; DATAFILES
;
; CALLING SEQUENCE:
; Result=file_exist(file_name)
;
; INPUTS:
; file_name: The name of the File
;
; OUTPUTS:
; This function returns 1 if the file exist and 0 if not
;
; EXAMPLE:
; result=file_exist('otto.nc')
;
; MODIFICATION HISTORY:
; Written by: R.Bauer (ICG-1), 1998-May-18
;-
FUNCTION file_exist,file_name
if n_params() lt 1 then begin
help,call=call
help_of_interest=within_brackets(call[0],brackets=['<','('])
message,help_calling_sequence(help_of_interest),/cont
return,-1
endif
OPENR,lun,file_name,err=err,/GET_LUN
IF n_elements(lun) GT 0 THEN FREE_LUN,lun
IF err NE 0 THEN RETURN,0 ELSE RETURN,1
END
;
; Copyright (c) 1997, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made. This
; routine is provided as is without any express or implied warranties
; whatsoever.
;
;+
; NAME:
; fileline
;
; PURPOSE:
; This function returns 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
;
; KEYWORD PARAMETERS:
; bytarr: optional output
;
; EXAMPLE:
; Result=fileline('test.asc')
;
; MODIFICATION HISTORY:
; Written by: R.Bauer (ICG-1), Oct. 1996
; R.Bauer 1998-11-10 added opt output bytarr
;-
FUNCTION fileline, filename,BYTARR=lesefeld
IF N_PARAMS() LT 1 THEN BEGIN
HELP:HELP,call=call
help_of_interest=within_brackets(call[0],brackets=['<','('])
MESSAGE,help_calling_sequence(help_of_interest),/cont
RETURN,-1
help_open: MESSAGE, 'File: '+filename+' NOT found',/cont
RETURN,-1
help_size: MESSAGE,'File: '+filename+' has a SIZE OF 0 bytes',/cont
RETURN,-1
ENDIF
byt=filesize(filename)
IF byt EQ 0 THEN GOTO,help_size
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
FREE_LUN,lun
IF lesefeld(byt-1) NE 10b THEN lesefeld=[lesefeld,10b]
line=WHERE(lesefeld EQ 10B,count_line)
RETURN,count_line
END
;
; Copyright (c) 1996, Forschungszentrum Juelich GmbH ICG-1
; All rights reserved.
; Unauthorized reproduction prohibited.
; This software may be used, copied, or redistributed as long as it is not
; sold and this copyright notice is reproduced on each copy made. This
; routine is provided as is without any express or implied warranties
; whatsoever.
;+
; NAME:
; filesize
;
; PURPOSE:
; The result of this function is 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
if n_params() lt 1 then begin
help:help,call=call
help_of_interest=within_brackets(call[0],brackets=['<','('])
message,help_calling_sequence(help_of_interest),/cont
return,-1
help_open: message, 'File: '+filename+' not found',/cont
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
|
|
|