;***The function loadpdqcomma.pro reads comma delimited ascii data ;contained in filename and puts it into variablename. It is designed to read ;***small data files (<=20,000 lines) quickly. ;***This program may run slower than loadsmallcomma.pro, but ;***should use less memory since it continuously concatenates the ;***output variable as it reads the input file instead of initializing ;***a large array and filling and trimming as necessary. ;*** ;***Use is as follows: ;*** loadpdqcomma,'filename',variablename ;*** ;*** Input: filename - A string that is the filename of the ;*** file where data is comma delimited ;*** and stored in ascii format. ;*** 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 loadpdq.pro pro loadpdqcomma,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 ;file was presumably ok 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 mat=float(first) ;convert first line to float dat=fltarr(col) ;initialize temporary array to read data into i=1L while not eof(f) do begin ;loop until end of file is encountered readf,f,dat ;read line of file mat=[[mat],[dat]] ;concatenate new line of data to those read before i=i+1L ;increment counter ;generate messages if file is too big for efficient loading if i eq 8000 and col ge 4 then begin print,'File has multiple columns and more than 8000 lines.' print,'Quicker loading may result by using loadsmall.pro.' endif if i eq 20000 then begin print,'File has more than 20000 lines.' print,'This load routine may be exceptionally slow to read the file.' print,' Use of load.pro is recommended.' endif endwhile print,'The variable is a '+strtrim(string(col),2)+' column X '+strtrim(string(i),2)+' row array.' ;***Put the data matrix into the variablename variablename=mat ;close file and free logical unit number close,f free_lun,f endelse return end