Changeset 12561 in project
 Timestamp:
 11/20/08 08:39:21 (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

release/3/nemo/trunk/nemomatlab.scm
r12558 r12561 458 458 459 459 (matchlet (((statelist asgnlist g) deps*)) 460 (let* ((poset (vector>list ((dis 'depgraph>bfsdistposet) g))) 460 (let* ((constdefs (filtermap 461 (lambda (nv) 462 (and (not (member (first nv) matlabbuiltinconsts)) 463 (let ((v1 (canonicalizeexpr/MATLAB (second nv)))) 464 (list (first nv) v1)))) 465 consts)) 466 (poset (vector>list ((dis 'depgraph>bfsdistposet) g))) 461 467 (asgneqdefs (poset>asgneqdefs poset sys)) 462 468 (permions (fold (lambda (ionch ax) … … 488 494 `(,(matlabname ion) ,(matlabname (s+ 'i ion)) ,(matlabname (s+ ion 'i))))) 489 495 epools))) 490 496 491 497 (foreach 492 498 (lambda (a) … … 505 511 poolions) 506 512 507 (let* ((with (inexact>exact (round (/ (abs ( maxv minv)) step)))) 508 (definefn (makedefinefn table? minv maxv with))) 509 (foreach (lambda (fndef) 510 (if (not (member (car fndef) builtinfns)) 511 (apply definefn (cons indent fndef)))) 512 defuns)) 513 514 (pp indent ,nl) 515 516 (let* ((constdefs (filtermap 517 (lambda (nv) 518 (and (not (member (first nv) matlabbuiltinconsts)) 519 (let ((v1 (canonicalizeexpr/MATLAB (second nv)))) 520 (list (first nv) v1)))) 521 consts))) 522 523 (foreach (lambda (def) 524 (let ((n (first def)) (b (second def))) 525 (pp indent ,(expr>string/MATLAB b n)))) constdefs) 526 527 (foreach (lambda (ep) 528 (let* ((epname (first ep)) 529 (epprops (second ep)) 530 (initexpr (lookupdef 'initial epprops)) 531 (tempexpr (lookupdef 'tempadj epprops)) 532 (betaexpr (lookupdef 'beta epprops)) 533 (depthexpr (lookupdef 'depth epprops)) 534 (initname (matlabname (s+ epname 'init))) 535 (tempname (matlabname (s+ epname 'tempadj))) 536 (betaname (matlabname (s+ epname 'beta))) 537 (depthname (matlabname (s+ epname 'depth)))) 538 (if (or (not betaexpr) (not depthexpr) (not initexpr)) 539 (nemo:error 'nemo:matlabtranslator 540 ": ion pool " epname " requires initial value, depth and beta parameters")) 541 (let ((tempval (and tempexpr (evalconst sys tempexpr))) 542 (initval (evalconst sys initexpr)) 543 (betaval (evalconst sys betaexpr)) 544 (depthval (evalconst sys depthexpr))) 545 (pp indent 546 ,(expr>string/MATLAB initval initname) 547 ,(expr>string/MATLAB tempval tempname) 548 ,(expr>string/MATLAB betaval betaname) 549 ,(expr>string/MATLAB depthval depthname))))) 550 epools)) 551 552 (pp indent ,nl (function dy = ,sysname (,(sl\ ", " `(dy t))))) 553 554 (if (not (null? exports)) (pp indent+ (global ,(sl\ ", " exports)))) 555 556 (if (not (null? asgns)) 557 (foreach (lambda (def) 558 (let ((n (matlabname (first def)) ) 559 (b (second def))) 560 (pp indent+ ,(expr>string/MATLAB b n)))) asgneqdefs)) 561 513 514 (foreach (lambda (ep) 515 (let* ((epname (first ep)) 516 (epprops (second ep)) 517 (initexpr (lookupdef 'initial epprops)) 518 (tempexpr (lookupdef 'tempadj epprops)) 519 (betaexpr (lookupdef 'beta epprops)) 520 (depthexpr (lookupdef 'depth epprops)) 521 (initname (matlabname (s+ epname 'init))) 522 (tempname (matlabname (s+ epname 'tempadj))) 523 (betaname (matlabname (s+ epname 'beta))) 524 (depthname (matlabname (s+ epname 'depth)))) 525 (if (or (not betaexpr) (not depthexpr) (not initexpr)) 526 (nemo:error 'nemo:matlabtranslator 527 ": ion pool " epname " requires initial value, depth and beta parameters")) 528 (let ((tempval (and tempexpr (evalconst sys tempexpr))) 529 (initval (evalconst sys initexpr)) 530 (betaval (evalconst sys betaexpr)) 531 (depthval (evalconst sys depthexpr))) 532 (pp indent 533 ,(expr>string/MATLAB initval initname) 534 ,(expr>string/MATLAB tempval tempname) 535 ,(expr>string/MATLAB betaval betaname) 536 ,(expr>string/MATLAB depthval depthname))))) 537 epools) 538 539 (pp indent ,nl (function dy = ,sysname (,(sl\ ", " `(dy t))))) 540 541 (if (not (null? exports)) (pp indent+ (global ,(sl\ ", " exports)))) 542 543 (if (not (null? asgns)) 544 (foreach (lambda (def) 545 (let ((n (matlabname (first def)) ) 546 (b (second def))) 547 (pp indent+ ,(expr>string/MATLAB b n)))) asgneqdefs)) 548 562 549 (let* ((ieqs (filtermap 563 550 (lambda (ionch) 564 551 565 552 (let* ((label (first ionch)) 566 553 (n (second ionch)) … … 572 559 (gate (lookupdef 'gate subcomps)) 573 560 (sts (and gate ((dis 'componentexports) sys (cid gate))))) 574 561 575 562 (cond ((and perm pore gate) 576 563 (case (cn perm) … … 591 578 (gion `(* ,gmax ,@sptms))) 592 579 (list i e gion))))) 593 580 594 581 ((and perm pore) 595 582 (case (cn perm) … … 597 584 (let* ((i (matlabname 'i)) 598 585 (e (car permqs)) 599 586 (gmax (car ((dis 'componentexports) sys (cid pore))))) 600 587 (list i e gmax))) 601 588 (else 602 589 (nemo:error 'nemo:matlabtranslator ": invalid ion channel definition " label)))) 603 604 605 606 607 608 609 610 611 612 590 591 ((and acc pore gate) 592 (let* ((i (matlabname (s+ 'i (cn acc)))) 593 (gmax (car ((dis 'componentexports) sys (cid pore)))) 594 (pwrs (map (lambda (n) (statepower sys n)) sts)) 595 (sptms (map (lambda (st pwr) `(pow ,st ,pwr)) sts pwrs)) 596 (gion `(* ,gmax ,@sptms))) 597 (list i #f gion))) 598 (else (nemo:error 'nemo:matlabtranslator ": invalid ion channel definition " label)) 599 ))) 613 600 ionchs)) 614 601 615 602 (ibkts (bucketpartition (lambda (x y) (eq? (car x) (car y))) ieqs)) 616 603 617 604 (ieqs (fold (lambda (b ax) 618 605 (match b … … 624 611 (sum1 (canonicalizeexpr/MATLAB sum0))) 625 612 (cons (list i sum1) ax))) 626 613 627 614 ((i e gion) 628 615 (let* ((expr0 (rhsexpr/MATLAB (if e `(* ,gion ( v ,e)) gion))) 629 616 (expr1 (canonicalizeexpr/MATLAB expr0))) 630 617 (cons (list i expr1) ax))) 631 618 632 619 (else ax))) 633 620 (list) ibkts)) 634 621 635 622 (stateeqdefs (reverse (poset>stateeqdefs poset sys))) 636 623 637 624 (stcompeqdefs (poset>stcompeqdefs poset sys)) 638 625 639 626 (pooleqdefs 640 627 (map (lambda (ep) … … 652 639 `(,(s+ epname) ,rhs))) 653 640 epools)) 654 641 655 642 (rateeqdefs (append pooleqdefs stateeqdefs)) 656 643 … … 660 647 (cons `(,stname ,(first ax)) (second ax))))) 661 648 (list 0 (list)) rateeqdefs))) 662 (second acc)))649 (second acc))) 663 650 ) 664 651 … … 690 677 691 678 (if (not (null? exports)) (pp indent+ (global ,(sl\ ", " exports)))) 679 (if (not (null? exports)) (pp indent+ (global ,(sl\ ", " (map first constdefs))))) 692 680 693 681 (let* ((initdefs (poset>stateinitdefs poset sys))) 694 682 ;; (initeqdefs (poset>stateiniteqdefs poset sys))) 683 684 (foreach (lambda (def) 685 (let ((n (first def)) (b (second def))) 686 (pp indent+ ,(expr>string/MATLAB b n)))) constdefs) 695 687 696 688 (foreach (lambda (def) … … 721 713 (pp indent ,nl (endfunction)) 722 714 715 (pp indent ,nl) 716 717 (let* ((with (inexact>exact (round (/ (abs ( maxv minv)) step)))) 718 (definefn (makedefinefn table? minv maxv with))) 719 (foreach (lambda (fndef) 720 (if (not (member (car fndef) builtinfns)) 721 (apply definefn (cons indent fndef)))) 722 defuns)) 723 723 724 724 725 )))))))) 726
Note: See TracChangeset
for help on using the changeset viewer.