;***The function loadsmallcomma.pro reads comma delimited ascii data files. ;***It is designed to read small data files (<=20,000 lines) quickly. ;*** ;***Use is as follows: ;*** loadsmallcomma,'filename',variablename ;*** ;*** Input: filename - A string that is the filename of the ;*** file where data is stored in ascii format ;*** and is comma delimited. ;*** Note: filename must be in quotes ;*** ;*** Output: variablename - Name of the variable you wish to ;*** contain the data from filename ;*** ;***Written by BWBerger 11/12/99 based heavily on loadsmall.pro pro loadsmallcomma,filename,variablename print,'Loading '+filename ;open the data file openr,f,filename,/get_lun,Error=err if err ne 0 then begin ;check err to see if file was opened print,'!!!WARNING!!!' print,'File does not exist or there are other problems.' print,'Load not executed.' endif else begin first='' readf,f,first ;read first line and figure out how many columns there are first=strtrim(str_sep(strcompress(strtrim(first,2)),','),2) ;string array of 1st line col=n_elements(first) ;no. of columns is no. of elements of string array variablename=fltarr(col,20000);initialize an array to hold data variablename(*,0)=float(first);1st line: convert string array to float dat=fltarr(col) ;temporary float array to hold data as it is read i=1L while not eof(f) do begin ;loop through each file line until eof reached readf,f,dat ;read line of file ;if file is too big discontinue loading, generate message. if i gt 19999L then begin print,'File is longer than 20,000 lines. Need to costomize load program.' variablename=-999. goto,fini endif variablename(*,i)=dat ;load output array i=i+1L endwhile print,'The variable is a '+strtrim(string(col),2)+' column X '+strtrim(string(i),2)+' row array.' ;trim the output array variablename=variablename(*,0:i-1) ;close file and free logical unit number close,f free_lun,f endelse fini: return end