pro load_wc_stor,filename,variablename,err ; 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: openr,1,filename,error=err if( err ne 0) then begin close,1 return endif close,1 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=fltarr(columns,lines) ON_IOERROR,bad_num openr,f,filename,/get_lun readf,f,dat close,f free_lun,f ; Put the data into the variablename variablename=dat GOTO, c10 bad_num: err=101 close,f c10: return end