Home > Community > Forums > Custom IC SKILL > assigning to ocean script variable result of c-shell command.

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 assigning to ocean script variable result of c-shell command. 

Last post Wed, Jun 16 2010 2:32 AM by skillUser. 4 replies.
Started by tyanata 03 May 2010 12:20 AM. Topic has 4 replies and 2680 views
Page 1 of 1 (5 items)
Sort Posts:
  • Mon, May 3 2010 12:20 AM

    • tyanata
    • Top 75 Contributor
    • Joined on Mon, May 3 2010
    • Posts 89
    • Points 1,480
    assigning to ocean script variable result of c-shell command. Reply

     Hi,

     

    I have following problem I want to count time for cetrain operations in ocean sript.

    So I use getCurrentTime() command and after that compareTime command. But the problem is that getCurrentTime counts time with accuracy second, but I need larger resolution so I decided to use c-shell command date, I mean following construction:

    csh("date +%s.%N")

     

    My question is: how to assing the result of this command to the ocean script variable. Now when I do that

     a = csh("date +%s.%N") . The ocean script considers that a = t.

    Thanks in advance if some body can help me.

     

     

     

    • Post Points: 35
  • Tue, May 4 2010 5:14 AM

    Re: assigning to ocean script variable result of c-shell command. Reply

    Well, you could use:

    id=ipcBeginProcess("date +%s.%N")
    ipcWait(id)
    dateInfo=ipcReadProcess(id)

    I'm not convinced it's worthwhile though, because there's some overhead in launching a child process for communication this way, and I think it would wipe out the extra resolution you're after.

    You could potentially run a background "slave" process which sat listening for requests for the time, which responded with the date. That way you could do the ipcBeginProcess() once, and then send a "command" to the child to request the date whenever you wanted the current date, and it would feed it back.

    One way to do this would be to use a little C program like this:

     #include <stdio.h>
    #include <sys/time.h>

    main(argc,argv)
    int argc;
    char *argv[;
    {
        struct timeval time;
        char line[256];

        while(fgets(line,256,stdin)) {
        gettimeofday(&time, NULL);
        fprintf(stdout,"%d.%d\n",time.tv_sec,time.tv_usec);
        fflush(stdout);
        }
    }

    I compiled this with "cc -o datequery datequery.c" and then use this SKILL:

     procedure(CCSgetDate()
        unless(CCSgetDate.cid && ipcIsAliveProcess(CCSgetDate.cid)
            CCSgetDate.cid=ipcBeginProcess("datequery")
            ipcWaitForProcess(CCSgetDate.cid)
        )
        ipcWriteProcess(CCSgetDate.cid "get\n")
        ipcReadProcess(CCSgetDate.cid 2)
    )

    and then call CCSgetDate() whenever you want the date (in form seconds.microseconds).

    Alternatively, if you're trying to optimize code, you could use the SKILL profiler, or use the cputime() function in SKILL. Depends really what you're trying to achieve.

    Regards,

    Andrew.

    • Post Points: 20
  • Wed, May 5 2010 3:14 AM

    • tyanata
    • Top 75 Contributor
    • Joined on Mon, May 3 2010
    • Posts 89
    • Points 1,480
    Re: assigning to ocean script variable result of c-shell command. Reply

     Thanks for the help!

    I did the approach with cc progam and calling it as procedure.

    There was one syntaxys error in the C program:

    char *argv[;

    I repaired it. And now system works perferctly

     Best regards,

    tyanata

     

     

     

    • Post Points: 20
  • Wed, May 5 2010 3:27 AM

    Re: assigning to ocean script variable result of c-shell command. Reply

    Hi tyanata,

    Something odd must have happened when I posted it, because the syntax is correct in my original code. In fact I just went to edit the earlier post to correct it, and when I hit "Edit" the code is correct... So I don't know why it doesn't have the close square bracket.

    Anyway, glad it worked for you.

    Regards,

    Andrew.

    • Post Points: 5
  • Wed, Jun 16 2010 2:32 AM

    • skillUser
    • Top 10 Contributor
    • Joined on Fri, Sep 19 2008
    • Austin, TX
    • Posts 2,598
    • Points 16,075
    Re: assigning to ocean script variable result of c-shell command. Reply
    Hi Tyanata,

    You can use the ipcBeginProcess() SKILL command to start the external shell command and then you can read the result into a variable, for example:

    cid = ipcBeginProcess("date +%s.%N")
    => ipc:0
    a = ipcReadProcess(cid)
    => "1272902857.153277000"

    Check out the "Interprocess Communication SKILL Functions" documentation.

    Regards,
    Lawrence.
    • Post Points: 5
Page 1 of 1 (5 items)
Sort Posts:
Started by tyanata at 03 May 2010 12:20 AM. Topic has 4 replies.