r8525: fix bug in L circuit
[rlc.git] / main.lisp
index 171b51849b1c651214317881b0052a95a49f732b..87fec0580b5888a1e5a78600bdda04bb00bd3e20 100644 (file)
--- a/main.lisp
+++ b/main.lisp
 
 (in-package #:rlc)
 
-(defun plot-series-rlc-current (v r l c t-inc t-end &optional (t-start 0))
+(defun plot-series-rlc-current (v r l c t-inc t-end &optional (t-start 0)
+                               (graph-function 'run-xgraph))
   (let ((path (make-pathname
               :directory '(:absolute "tmp")
               :name
               (concatenate 'string "rlc-data-"
                            (write-to-string (get-universal-time)))
               :type "dat")))
-    (write-series-rlc-graph path v r l c t-inc t-end t-start)
-    (run-xgraph path)
+    (write-series-rlc-current-graph path v r l c t-inc t-end t-start)
+    (funcall graph-function path)
     (sleep 2)
     (delete-file path)))
 
     
 (defun write-series-rlc-current-graph (path v r l c t-inc t-end
                                       &optional (t-start 0))
+  (with-open-file (out path :direction :output :if-exists :supersede
+                  :if-does-not-exist :create)
+    (write-series-rlc-current-graph-stream out v r l c t-inc t-end t-start)))
+
+(defun write-series-rlc-current-graph-stream (out v r l c t-inc t-end
+                                      &optional (t-start 0))
   (multiple-value-bind (x y)
       (series-rlc-current-graph-data v r l c t-inc t-end t-start)
-    (with-open-file (out path :direction :output :if-exists :supersede
-                        :if-does-not-exist :create)
-      (dotimes (i (length x))
-       (format out "~D ~D~%" (aref x i) (aref y i))))))
+    (dotimes (i (length x))
+      (format out "~D ~D~%" (aref x i) (aref y i)))))
 
 (defun series-rlc-current-graph-data (v r l c t-inc t-end &optional (t-start 0))
   (let* ((formula-list (series-rlc-current-formula v r l c))
@@ -88,7 +93,7 @@
          0)))
     (:l
      `(lambda (tm)
-       (* ,(/ v l) t)))
+       (* ,(/ v l) tm)))
     (:rl
       `(lambda (tm)
         (* ,(/ v r) (- 1 (exp (- (* tm ,(/ r l))))))))