view utils/export.lisp @ 290:6af1f19a4475

Add (David's) function for converting beats into seconds. Ignore-this: c720d6d4b4d8d7eec42cddc7bcd8f26 darcs-hash:20090716170208-16a00-6cca92c55db29b8378605f411e1dc4ff33f6d1b8.gz
author j.forth <j.forth@gold.ac.uk>
date Thu, 16 Jul 2009 18:02:08 +0100
parents
children
line wrap: on
line source
(cl:in-package #:amuse-utils) 

(defun beats->seconds (composition &optional (stream t))
  "Prints a table of beat timepoints in seconds."
  (loop for i from 0 to (timepoint (cut-off composition))
     do (format stream
		"~A~C~F~%" i #\Tab
		(amuse-utils:beats-to-seconds
		 (make-moment i) composition))))

(defun export-data-from-composition (function composition pathname)
  "Function that applies another function to a composition, witing
the output to a file, e.g. use this to call beats->seconds."
  (with-open-file (stream pathname
			  :direction :output
			  :if-exists :supersede)
    (funcall function composition stream)))

(defun export-data-from-dataset (dataset function pathname)
  "Same as above except that processes an entire amuse-dataset."
  (loop for composition-identifier in
       (%list-slot-sequence-data dataset)
     do (with-open-file (stream
			 (concatenate 'string pathname
				      (princ-to-string
				       (composition-id
					composition-identifier)))
			 :direction :output
			 :if-exists :supersede)
	  (funcall function
		   (get-composition composition-identifier) stream))))