pro loadgz,filename,variablename ;***The function load.pro reads ascii data contained in filename and ;***puts it into variablename. ;*** Use: load,'filename',variablename ;*** ;*** ;*** 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/13/98 ;***Modified by BWBerger 2/6/98 to change the zinfo.inf file into ;***zinfoWXYZ.inf where WXYZ is a random number. This will help ;***eliminate problems where load is used by two or more idl sessions ;running simultaneously in the same directory. Also, one spawn command ;was removed by reading in all necessary info from zinfo in one read and ;using str_sep to get the information; this should speed up the program. 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,/compress 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=fltarr(columns,lines) openr,f,filename,/get_lun,/compress readf,f,dat close,f free_lun,f ;***Put the data into the variablename variablename=dat return end