; This macro reads a text file of position and rotation data, then inserts File Sources at those locations

(define InsertFileSourceArray
  (lambda (pos_data source_data)
    
    ; source number and name
    (define source_number 0)
    (define source_name 'source)
    ;source position and rotation
    (define x 0)
    (define y 0)
    (define z 0)
    (define l 0)
    (define m 0)
    (define n 0)
    
    ; open a file
    (define location (open-input-file pos_data))
    ; read header lines
    (read-string location)
    (read-string location)
    
    ; now data
    (do ((i 1 (+ i 0)))
      ((= 0 i) (print "All sources have been defined !!")) 
      
      (set! source_number (read location))
      ; source name in this model
      (cond 
        ((equal? source_number 'zz) (set! i 0)(close-input-port location))
        (else 
          (set! source_name (string-append "source_0" (number->string source_number)))
          (read location)
          (set! x (read location))
          (read location)
          (set! l (read location))
          (read location)
          (set! y (read location))
          (read location)
          (set! m (read location))
          (read location)
          (set! z (read location))
          (read location)
          (set! n (read location))
          (raytrace:add-file-source source_name source_data 1 1 (position x y z) (gvector l m n))
          )
        )
      )
    )
  )  

;  MACRO COMMANDS TO EXECUTE DEMO
(file:new)
(InsertFileSourceArray "location.txt" "source_0.txt")
(property:apply-name (geometry:cylcone 1 3 3 3) "Disk")
(edit:move (entity:get-by-name "Disk") 0.000000 0.000000 3.500000)
(property:apply-surface (tools:face-in-body 1 (entity:get-by-name "Disk")) (list "Perfect Absorber" "Default"))    
(raytrace:all-sources)