;; ;; !! PATCH VERSION 1.0.3 THAT COPIES THE PROJECTIONS ;; TO OUTPUT FILE. ;; ;; ONLY TO BE USED WITH GRAPH V2.92 WITH VV-UPGRADE. ;; ;; User routine to cut evoked fif files. ;; ;; (export '(make-evoked-file max-evoked-data-size)) (defvar max-evoked-data-size 500000 "Maximum allowed amount of numbers in evoked data.") (defun make-evoked-file(&key (selection (x-selection)) (source default-data-source) (filename nil) (comment "Sample") (if-exists :ask) (n-averages 1)) "Take some data and make a .fif file out of it. Usage:(make-evoked-file &keys ...) This function generates a evoked style .fif file. The default is to take selected (by cursor on a display) portion of the data and write it in file .m.fif. If the filename is symbol :interactive then system asks the name interactively. If the filename is given explicitely with a keyword, the file name extension defaults to fif. Function also supports several keys to alter its behaviour. Keywords are as follows: :filename name of the file to be created (string) :selection list ( ) :source G-widget (or its name) where the data is taken from. (Defaults to the value of default-data-source) :comment comment string to be included in the file :if-exists what to do if the file exits. Choises: nil :error :supersede :ask :n-averages number of averages in the data. See also: make-fiff-file make-simple-file " (setq source (G-widget source "Bad data source for make-evoked-file")) ;; allow names (if (null filename) (setq filename (default-evoked-filename source selection))) (unless (eq filename :interactive) (setq filename (expand-filename (default-extension filename "fif")))) (if (null selection) (if (yes-or-no-p "No selection, shall we really write everything") (setq selection (list (sample-to-x source (low-bound source)) (sample-to-x source (- (high-bound source)(low-bound source) 1)))) (return nil) )) (let* ((start (first selection)) (len (second selection)) (sample nil) (samplen nil)) (if (not (and (numberp start)(numberp len))) (error "Invalid selection ~s. should be list (start len)")) (setq sample (x-to-sample source start)) (setq samplen (+ 1 (x-to-sample source len))) (if (< samplen 2) (error "write-evoked-file: too short sample: ~a" "should be at least 2 points")) (if (> (* samplen (resource source :channels)) max-evoked-data-size) (error "make-evoked-file: Too large file (~d numbers) ~@ If needed, you can alter the size limit in variable max-evoked-data-size." (* samplen (resource source :channels)))) (if (eql filename :interactive) (if (null (setq filename (ask-filename "Give name for evoked file!" :new t :default (default-evoked-filename source selection) :template "*.fif" :if-exists if-exists))) (error "make-evoked-file: Cancelled")) (cond ((eql if-exists nil) (if (file-exists-p filename) (return nil))) ((eql if-exists :error) (if (file-exists-p filename) (error "File ~s already exists" filename))) ((eql if-exists :ask) (if (file-exists-p filename) (if (not (yes-or-no-p "File ~s exists! Overwrite?" filename)) (error "Can not owerwrite the existing file")))) ((eql if-exists :supersede)) (t (error "make-fiff-file: Invalid :if-exists key: ~s" if-exists)) )) (with-status "Transferring data..." (if (GtWriteEvokedFile filename source sample samplen n-averages comment) (error "Could not create average file ~s" filename)) (let ((sname (get-property source 0 :source-name))) ;; We are ignoring errors in projection copy on purpose. (if (stringp sname) (system (format nil "/neuro/bin/util/copy_proj_fiff ~a ~a" sname filename)) ) ) ) ) filename )