FUNCTION load_list,list_out

 @wload.com
 @chandle.com

     wd = GETENV('WORK')+!delimiter+GETENV('USER')+!delimiter+'list'+!delimiter
     temps = rd_asc(wd+list_out)

             ; *** separate dirs and files ***
     dirs = ['']
     files= ['']
     n_files = N_ELEMENTS(temps)
     FOR i=0,n_files-1 DO BEGIN
        tmp= STRCOMPRESS(temps(i),/REMOVE_ALL)
        lc = RSTRPOS(tmp, !delimiter)
        dirs = [dirs, STRMID(tmp, 0, lc+1)]
        files= [files, STRMID(tmp, lc+1, STRLEN(tmp)-lc)]
     ENDFOR
     i_tmp = WHERE(files GT '')
     files = files(i_tmp)
     dirs  = dirs(i_tmp)

     IF files(0) EQ "No files found" OR files(0) EQ "" THEN BEGIN 
        msg = WIDGET_MESSAGE(" Please, select loading method! ")
        RETURN,-1
     ENDIF
     
     IF N_ELEMENTS(h_array) EQ 0 THEN h_array = lonarr(1)
     IF N_ELEMENTS(h_name)  EQ 0 THEN h_name  = lonarr(1)
     IF N_ELEMENTS(h_head)  EQ 0 THEN h_head  = lonarr(1)
     IF N_ELEMENTS(h_small) EQ 0 THEN h_small = lonarr(1)

     n_files = N_ELEMENTS(files) - 1
            
;    FOR j=0,n_files DO BEGIN
     j = 0          
     REPEAT BEGIN

        next_valid_image: print,"Image ",j," : ",dirs(j),files(j)
        
        new_name = dirs(j) + !delimiter + files(j)
               
        check_path = RSTRPOS(new_name,!delimiter)
        IF check_path GT 0 THEN BEGIN
           new_path = STRMID(new_name,0,check_path)
           new_name=STRMID(new_name,check_path+1,STRLEN(new_name))
        ENDIF
        name = new_path + new_name
print,"LOAD",name
	image = READFITS(name,head)
	IF N_ELEMENTS(image) EQ 1 THEN BEGIN
	   undefine, image
           IF j EQ n_files THEN GOTO,load_image
	      j=j+1 & GOTO,next_valid_image
	   ENDIF

           resize = img_resize 
           IF img_resize EQ -1 THEN BEGIN
                 ; check header for SUMROW and SUMCOL
                 sumrow = FIX(chk_h4s(head,"SUMROW")) 
                 sumcol = FIX(chk_h4s(head,"SUMCOL"))
                 naxis1 = FIX(chk_h4s(head,"NAXIS1"))
                 naxis2 = FIX(chk_h4s(head,"NAXIS2"))

                 IF sumrow EQ 0 OR sumcol EQ 0 THEN BEGIN
                   resize = naxis1
                 ENDIF ELSE BEGIN
                   resize = naxis1 * sumrow
                 ENDELSE
               ENDIF

               IF img_resize NE 0 THEN BEGIN
                 image = resize_img(image,resize,head)
               ENDIF

               name = new_name

               IF ld.dark GT 0 THEN image = image - ld.dark
               IF ld.net  EQ 1 THEN BEGIN
                 exptime = FLOAT(chk_h4s(head,"EXPTIME"))
                 IF exptime EQ -1 THEN XVAREDIT,exptime
                 image = image / exptime
               ENDIF 

               chandle

         j = j+1 
        ENDREP UNTIL (j GT n_files) OR (GET_KBRD(0) EQ 'c')

          
  load_image:

     IF N_ELEMENTS(index) GT 0 THEN  ghandle, index ; get last valid image

   ;  END   ; *** end of load ***

RETURN,1
END
