• Re: Back & Forth - 4tH I/O and You

    From albert@spenarnc.xs4all.nl@21:1/5 to the.beez.speaks@gmail.com on Sun May 18 20:55:27 2025
    In article <nnd$68843db9$0f3297b6@f356aed0e515fe8b>,
    Hans Bezemer <the.beez.speaks@gmail.com> wrote:
    <SNIP>
    Note: this isn't Python or PHP like "easy to use" - where the magician
    hides the rabbit behind his back. The effect is perfectly predictable -
    and quite intuitive (if I may say so myself).

    Note in C, printf() isn't capable of redirection (unless from OS level). >fprintf() is - but how many people use it in combination with stdout
    (present company excepted)?

    I sold my soul to the c people, and embraced single bytes characters
    and redirection.
    : EMIT
    DSP@ 1 TYPE DROP
    ;

    : TYPE
    1 WRITE-FILE THROW
    ;

    (Windows: replace 1 with STDOUT)

    What I like is that I can test all errors/exceptions in my Forth
    bye 2>&1 .

    The integration with the OS-es makes for useful applications. ~/PROJECT/ciforths/ciforth/TOOLS/ALLOCATE: cat printhex.frt
    : doit 1 ARG[] EVALUATE HEX . ;
    ~/PROJECT/ciforths/ciforth/TOOLS/ALLOCATE: printhex 1024;echo
    400

    [lina -c printhex.frt]


    Hans Bezemer



    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to albert@spenarnc.xs4all.nl on Sun May 18 19:10:34 2025
    On Sun, 18 May 2025 18:55:27 +0000, albert@spenarnc.xs4all.nl wrote:

    In article <nnd$68843db9$0f3297b6@f356aed0e515fe8b>,

    The integration with the OS-es makes for useful applications. ~/PROJECT/ciforths/ciforth/TOOLS/ALLOCATE: cat printhex.frt
    : doit 1 ARG[] EVALUATE HEX . ;
    ~/PROJECT/ciforths/ciforth/TOOLS/ALLOCATE: printhex 1024;echo
    400

    [lina -c printhex.frt]

    In iForth we can redirect to a string:

    : ngspice-POSTLUDE ( -- c-addr u )
    DRY-RUN ( using TASK-DATA setup by SP>NGSPICE )
    |head .paramdata LOCAL mem
    <$$ ." * Generated by iSPICE on " .TIME$ ." -- do not edit"
    CR
    CR ." .control"
    CR ." unset ltspice"
    CR ." unset dotstep"
    CR ." set numthreads=1
    CR ." set ispice = " #|params 0<> 1 AND .
    CR ." "
    ." let spiceidx = $SPICEIDX ; "
    ." let ntasks=" #|tasks ."#"
    ." let ncpus=" #|cpus ."#"
    ." let nparams=" #|params ."#"
    ." let nresults=" #|results ."#"
    #|params
    IF CR ." compose p values "
    #|tasks 0 ?DO CR ." + "
    #|params 0 ?DO mem DF@+ TO mem
    F.N2+_
    LOOP
    LOOP
    CR #|params 1 > IF ." reshape p[" #|tasks
    0DEC.R ." ][" #|params
    0DEC.R ." ]"
    ENDIF
    ENDIF
    CR ." let ignore = 0"
    CR ." let buf = 0"
    CR ." let done = 0"
    CR ." let ix = spiceidx"
    CR ." compose arg values " #|tasks #|results * .
    #|results 0DEC.R ." ix 0 0.0"
    CR ." compose status values ncpus spiceidx"

    CR ." dowhile ix < ntasks"
    #|params 0 ?DO CR #|params 1 > IF ." let buf = p[ix][" I
    0DEC.R ." ]"
    ELSE ." let buf = p[ix]"
    ENDIF
    CR ." alterparam " |head .pnames I CSTR[] .$
    ." = $&buf"
    LOOP
    #|params IF CR ." mc_source" ENDIF
    CR ." " $SIM @+ 1 /STRING TYPE
    #|results 0 ?DO CR ." let arg[3] = " I ."#"
    CR ." " I (meashead) TYPE
    ." arg[4] " I (measbody) TYPE
    CR ." let ignore=setresult(arg) "
    LOOP
    CR ." let ix = ix + ncpus"
    CR ." let arg[2] = ix"
    CR ." write " RAWDATA-NAME
    NO-EXTENSION
    S" _{$spiceidx}{.raw}"
    $+ TYPE
    #|tasks IF CR ." set appendwrite" ENDIF
    CR ." end"
    CR ." let done = setfinish(status)"
    CR ." quit"
    CR ." .endc"

    SCRIPTFILE-NAME DUMP-TO-FILE
    CR ." Please manually add the following lines to `" cktfile .$ ." .sp`"
    CR
    CR ." .LIBRARY basic.lib basicstuff"
    CR ." .OPTION savecurrents"
    CR ." .INC " cktfile .$ ." .iscript"
    CR ; PRIVATE

    ( This mixes Forth with the SPICE shell script language )

    Result:

    * Generated by iSPICE on 23:19:11, December 9, 2024 -- do not edit

    control
    unset ltspice
    unset dotstep
    set numthreads=1 $ make sure spinit has this too; we can't overrule spinit!
    set ispice = 0
    let spiceidx = $SPICEIDX ; let ntasks=1; let ncpus=8;
    let nparams=0; let nresults=2;
    let ignore = 0
    let buf = 0
    let done = 0
    let ix = spiceidx
    compose arg values 2 2 ix 0 0.0
    compose status values ncpus spiceidx
    dowhile ix < ntasks
    TRAN 30u 30ms 0 30u
    let arg[3] = 0;
    meas tran arg[4] AVG @i1[current]
    let ignore=setresult(arg)
    let arg[3] = 1;
    meas tran arg[4] AVG @i2[current]
    let ignore=setresult(arg)
    let ix = ix + ncpus
    let arg[2] = ix
    write f:/2jsource_test_{$spiceidx}{.raw}
    set appendwrite
    end
    let done = setfinish(status)
    quit
    endc

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From albert@spenarnc.xs4all.nl@21:1/5 to mhx on Mon May 19 00:51:36 2025
    In article <fce9942b8d6e52702b330d5edcde5b4f@www.novabbs.com>,
    mhx <mhx@iae.nl> wrote:
    Mime-Version: 1.0
    User-Agent: Rocksolid Light
    Path: not-for-mail
    From: mhx@iae.nl (mhx)
    Newsgroups: comp.lang.forth
    Organization: novaBBS
    Injection-Info: i2pn2.org; logging-data="921598"; mail-complaints-to="usenet@i2pn2.org"; posting-account="J+nubxJRM7ncpF4l6KLO+OONWmFAYJHVJegfwQXJ8vc";
    Subject: Re: Back & Forth - 4tH I/O and You
    References: <nnd$306ecdcd$714b9ebb@8c19de68479dc08d> <b2a4690cc4cdcb9e39310166d37070ab2a16d8b2@i2pn2.org> <nnd$68843db9$0f3297b6@f356aed0e515fe8b> <nnd$0346461b$62171617@be8ddde8960df4cb>
    Content-Transfer-Encoding: 8bit
    X-Rslight-Site: $2y$10$OOQsNDELF5uNo3A3Uv7gJOwfOwKYrncFKKKX4OxnyyB9YDRoHEGxG >X-Rslight-Posting-User: 4e0dc1fdad1ead10b39e7eb5db19bf73d73e3ab3
    Date: Sun, 18 May 2025 19:10:34 +0000
    Message-Id: <fce9942b8d6e52702b330d5edcde5b4f@www.novabbs.com>
    Content-Type: text/plain; charset=utf-8; format=flowed >X-Spam-Checker-Version: SpamAssassin 4.0.0

    On Sun, 18 May 2025 18:55:27 +0000, albert@spenarnc.xs4all.nl wrote:

    In article <nnd$68843db9$0f3297b6@f356aed0e515fe8b>,

    The integration with the OS-es makes for useful applications.
    ~/PROJECT/ciforths/ciforth/TOOLS/ALLOCATE: cat printhex.frt
    : doit 1 ARG[] EVALUATE HEX . ;
    ~/PROJECT/ciforths/ciforth/TOOLS/ALLOCATE: printhex 1024;echo
    400

    [lina -c printhex.frt]

    In iForth we can redirect to a string:

    : ngspice-POSTLUDE ( -- c-addr u )
    DRY-RUN ( using TASK-DATA setup by SP>NGSPICE )
    |head .paramdata LOCAL mem
    <$$ ." * Generated by iSPICE on " .TIME$ ." -- do not edit"
    CR
    CR ." .control"
    CR ." unset ltspice"
    CR ." unset dotstep"
    CR ." set numthreads=1
    CR ." set ispice = " #|params 0<> 1 AND .
    CR ." "
    ." let spiceidx = $SPICEIDX ; "
    ." let ntasks=" #|tasks ."#"
    ." let ncpus=" #|cpus ."#"
    ." let nparams=" #|params ."#"
    ." let nresults=" #|results ."#"
    #|params
    IF CR ." compose p values "
    #|tasks 0 ?DO CR ." + "
    #|params 0 ?DO mem DF@+ TO mem
    F.N2+_
    LOOP
    LOOP
    CR #|params 1 > IF ." reshape p[" #|tasks
    0DEC.R ." ][" #|params
    0DEC.R ." ]"
    ENDIF
    ENDIF
    CR ." let ignore = 0"
    CR ." let buf = 0"
    CR ." let done = 0"
    CR ." let ix = spiceidx"
    CR ." compose arg values " #|tasks #|results * .
    #|results 0DEC.R ." ix 0 0.0"
    CR ." compose status values ncpus spiceidx"

    CR ." dowhile ix < ntasks"
    #|params 0 ?DO CR #|params 1 > IF ." let buf = p[ix][" I
    0DEC.R ." ]"
    ELSE ." let buf = p[ix]"
    ENDIF
    CR ." alterparam " |head .pnames I CSTR[] .$
    ." = $&buf"
    LOOP
    #|params IF CR ." mc_source" ENDIF
    CR ." " $SIM @+ 1 /STRING TYPE
    #|results 0 ?DO CR ." let arg[3] = " I ."#"
    CR ." " I (meashead) TYPE
    ." arg[4] " I (measbody) TYPE
    CR ." let ignore=setresult(arg) "
    LOOP
    CR ." let ix = ix + ncpus"
    CR ." let arg[2] = ix"
    CR ." write " RAWDATA-NAME
    NO-EXTENSION
    S" _{$spiceidx}{.raw}"
    $+ TYPE
    #|tasks IF CR ." set appendwrite" ENDIF
    CR ." end"
    CR ." let done = setfinish(status)"
    CR ." quit"
    CR ." .endc"
    $$>
    SCRIPTFILE-NAME DUMP-TO-FILE
    CR ." Please manually add the following lines to `" cktfile .$ ." .sp`"
    CR
    CR ." .LIBRARY basic.lib basicstuff"
    CR ." .OPTION savecurrents"
    CR ." .INC " cktfile .$ ." .iscript"
    CR ; PRIVATE

    ( This mixes Forth with the SPICE shell script language )

    Result:

    * Generated by iSPICE on 23:19:11, December 9, 2024 -- do not edit

    control
    unset ltspice
    unset dotstep
    set numthreads=1 $ make sure spinit has this too; we can't overrule
    spinit!
    set ispice = 0
    let spiceidx = $SPICEIDX ; let ntasks=1; let ncpus=8;
    let nparams=0; let nresults=2;
    let ignore = 0
    let buf = 0
    let done = 0
    let ix = spiceidx
    compose arg values 2 2 ix 0 0.0
    compose status values ncpus spiceidx
    dowhile ix < ntasks
    TRAN 30u 30ms 0 30u
    let arg[3] = 0;
    meas tran arg[4] AVG @i1[current]
    let ignore=setresult(arg)
    let arg[3] = 1;
    meas tran arg[4] AVG @i2[current]
    let ignore=setresult(arg)
    let ix = ix + ncpus
    let arg[2] = ix
    write f:/2jsource_test_{$spiceidx}{.raw}
    set appendwrite
    end
    let done = setfinish(status)
    quit
    endc

    That doesn't convince I could do this myself.


    -marcel
    --
    Temu exploits Christians: (Disclaimer, only 10 apostles)
    Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
    Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
    And Gifts For Friends Family And Colleagues.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From mhx@21:1/5 to albert@spenarnc.xs4all.nl on Mon May 19 00:05:56 2025
    On Sun, 18 May 2025 22:51:36 +0000, albert@spenarnc.xs4all.nl wrote:

    In article <fce9942b8d6e52702b330d5edcde5b4f@www.novabbs.com>,
    mhx <mhx@iae.nl> wrote:
    [..]
    That doesn't convince I could do this myself.

    In Forth we can do everything ourselves.

    ngspice-postlude is a word from the netlist converter that translates
    a standard SPICE netlist to the iSPICE dialect. The control constructs
    tailor the script so that it coordinates parallel execution on a 44
    core HPZ840. Each core runs ngspice inside an iForth instance. After
    the simulations finish, each copy runs it own set of measurements
    on its own rawfile. The data is written to shared memory so that
    2.5-D plots can be generated.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)