pro load_dbl,filename,variablename ;***The function load_dbl.pro reads ascii data contained in filename and ;***puts it into a double precision float array called variablename. ;***Use is as follows: ;*** load_dbl,'filename',variablename ;***Where ;*** ;*** Input: filename - A string that is the filename of the ;*** file where data is 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 7/7/99 - copied almost entirely from load.pro print,'Loading '+filename ;***Find the number of rows and columns of the data file: ;First get a random name for an information file (this will allow the ;program to be run several times simultaneously from different idl ;sessions in the same directory without having the files conflict). zinfoname='zinfo'+strtrim(string(fix(randomu(seed)*10000)),2)+'.inf' ;***Get the number of lines (=rows) and words in file to be loaded: ;a1="spawn,'wc -l "+filename+" > "+zinfoname+"'" ;a2=execute(a1) ;openr,f,zinfoname,/get_lun ;list='' THIS IS THE OLD CODE (PRE 2/6/99) ;readf,f,lines ;close,f ;free_lun,f ;***Get the number of words: ;b1="spawn,'wc -w "+filename+" > "+zinfoname+"'" ;b2=execute(b1) ;openr,f,zinfoname,/get_lun ;words=0L THIS IS THE OLD CODE (PRE 2/6/99) ;readf,f,words ;close,f ;free_lun,f a1="spawn,'wc "+filename+" > "+zinfoname+"'" a2=execute(a1) openr,f,zinfoname,/get_lun list='' readf,f,list close,f free_lun,f linesandwords=str_sep(strtrim(strcompress(list),2),' ') lines=linesandwords(0) words=linesandwords(1) ;***Get rid of info file c1="spawn,'rm "+zinfoname+"'" c2=execute(c1) ;***The number of columns=words/lines (if rectangular, otherwise print error.) columns=float(words)/float(lines) if (abs(columns-fix(columns)) gt .001) then begin print,'WARNING: Data matrix not rectangular.' endif else begin columns=fix(float(words)/float(lines)) print,'The variable is a ',columns,' column X ',lines,' row array.' endelse ;***Read the data file dat=dblarr(columns,lines) openr,f,filename,/get_lun readf,f,dat close,f free_lun,f ;***Put the data into the variablename variablename=dat return stop end