How can I write a time delaly transfere function like TF=(e^-10*s/(s+1)) in Scilab by using syslin('c', num,den) command or any other command. I know there is a continuous fix delay block in Xcos, but I would like to write this transfere function in Scinote file.
The iodelay toolbox is available for Scilab:
https://atoms.scilab.org/toolboxes/iodelay
Related
I wonder if there is a way to display the current time in the R command line, like in MS DOS, we can use
Prompt $T $P$G
to include the time clock in every prompt line.
Something like
options(prompt=paste(format(Sys.time(), "%H:%M:%S"),"> "))
will do it, but then it is fixed at the time it was set. I'm not sure how to make it update automatically.
Chase points the right way as options("prompt"=...) can be used for this. But his solutions adds a constant time expression which is not what we want.
The documentation for the function taskCallbackManager has the rest:
R> h <- taskCallbackManager()
R> h$add(function(expr, value, ok, visible) {
+ options("prompt"=format(Sys.time(), "%H:%M:%S> "));
+ return(TRUE) },
+ name = "simpleHandler")
[1] "simpleHandler"
07:25:42> a <- 2
07:25:48>
We register a callback that gets evaluated after each command completes. That does the trick. More fancy documentation is in this document from the R developer site.
None of the other methods, which are based on callbacks, will update the prompt unless a top-level command is executed. So, pressing return in the console will not create a change. Such is the nature of R's standard callback handling.
If you install the tcltk2 package, you can set up a task scheduler that changes the option() as follows:
library(tcltk2)
tclTaskSchedule(1000, {options(prompt=paste(Sys.time(),"> "))}, id = "ticktock", redo = TRUE)
Voila, something like the MS DOS prompt.
NB: Inspiration came from this answer.
Note 1: The wait time (1000 in this case) refers to the # of milliseconds, not seconds. You might adjust it downward when sub-second resolution is somehow useful.
Here is an alternative callback solution:
updatePrompt <- function(...) {options(prompt=paste(Sys.time(),"> ")); return(TRUE)}
addTaskCallback(updatePrompt)
This works the same as Dirk's method, but the syntax is a bit simpler to me.
You can change the default character that is displayed through the options() command. You may want to try something like this:
options(prompt = paste(Sys.time(), ">"))
Check out the help page for ?options for a full list of things you can set. It is a very useful thing to know about!
Assuming this is something you want to do for every R session, consider moving that to your .Rprofile. Several other good nuggets of programming happiness can be found hither on that topic.
I don't know of a native R function for doing this, but I know R has interfaces with other languages that do have system time commands. Maybe this is an option?
Thierry mentioned system.time() and there is also proc.time() depending on what you need it for, although neither of these give you the current time.
I am attempting to design a front end GUI for a CLI program by the name of eac3to.exe. The problem as I see it is that this program sends all of it's output to a cmd window. This is giving me no end of trouble because I need to get a lot of this output into a GUI window. This sounds easy enough, but I am begining to wonder whether I have found one of AutoIt's limitations?
I can use the Run() function with a windows internal command such as Dir and then get the output into a variable with the AutoIt StdoutRead() function, but I just can't get the output from an external program such as eac3to.exe - it just doesn't seem to work whatever I do! Just for testing purposesI I don't even need to get the output to a a GUI window: just printing it with ConsoleWrite() is good enough as this proves that I was able to read it into a variable. So at this stage that's all I need to do - get the text (usually about 10 lines) that has been output to a cmd window by my external CLI program into a variable. Once I can do this the rest will be a lot easier. This is what I have been trying, but it never works:
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", #SW_SHOW)
Global $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & #CRLF)
After running this script all I get from the consolWrite() is a blank line - not the text data that was output as a result of running eac3to.exe (running eac3to without any arguments just lists a screen of help text relating to all the commandline options), and that's what I am trying to get into a variable so that I can put it to use later in the program.
Before I suggest a solution let me just tell you that Autoit has one
of the best help files out there. Use it.
You are missing $STDOUT_CHILD = Provide a handle to the child's STDOUT stream.
Also, you can't just do RUN and immediately call stdoutRead. At what point did you give the app some time to do anything and actually print something back to the console?
You need to either use ProcessWaitClose and read the stream then or, you should read the stream in a loop. Simplest check would be to set a sleep between RUN and READ and see what happens.
#include <AutoItConstants.au3>
Global $iPID = Run("C:\VIDEO_EDITING\eac3to\eac3to.exe","", #SW_SHOW, $STDOUT_CHILD)
; Wait until the process has closed using the PID returned by Run.
ProcessWaitClose($iPID)
; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead.
; If the proccess doesnt end when finished you need to put this inside of a loop.
Local $ScreenOutput = StdoutRead($iPID)
ConsoleWrite($ScreenOutput & #CRLF)
I have a problem with my code. It doesn't print out an error, it works but it doesn't do what I actually need it to do. I won't be posting all of the code because it is not needed, I will just post the line we need.
So I have this line of code:
TIME1=$( { time awkfun ; } 2>&1 >/dev/null);
Where awkfun is a function that should print 500 integers, and TIME1 is a variable to store the time that the function will need to run and print. Problem is that normally as I said the function would print around 500 integers in this occasion though that I am using this, it just runs and does the calculations but is not printing. So it actually runs the awkfun function but doesn't let it print, in the time output for this function I also need the time it needs to print everything.
How to do that?
I hope I explained it as good as possible, if any questions arise please don't hesitate to comment, thanks in advance!
P.S
Running in ksh in oracle solaris.
Here is the correct sequence. Adjust as needed:
TIME1=`time (awkfun > /dev/tty) 2>&1`
I have code in which I am sourcing multiple codes one after the other. Something like below
source("t1.r")
source("t2.r")
source("t3.r")
source("t4.r")
While running this main script if any source statement gives an error, I don't want to source any remaining scripts (i.e. don't want to run any subsequent statements).
I don't want to write if error condition after every source statement. I want to do something universal and at the beginning only.
What change should I do in the main script to do this?
Edited as per suggested by Nicola and RHertel
setwd("/Users/xxxx/Desktop/Sub")
scripts<-list.files(pattern="*.R")
for (f in scripts)
{
c<-try(source(f))
ifelse (class(c)!="try-error", print(paste("Script Sourced:", f,sep=" ")), setwd("/Users/xxxx/Desktop")
}
This script prints the scripts sourced. That way you can recognise which didnt get sourced.
Is there anyway to send text to an iESS buffer which does not need to follow (inferior-ess-send-input)?
I basically do this:
(process-send-string "R" "mycommand()")
(select-window (get-buffer-window "*R*"))
(inferior-ess-send-input)
The concern is that like this it ends up with some added characters to that buffer, looking like this:
>
>
Is there a cleaner way to have Emacs interact with the ESS/R process?
I want to use this to create some parallel processing within R being handled by Emacs.
">" is the prompt and is printed by R each time you send something to the process. If you want to avoid that use ess-command instead. You can supply custom buffer for the output.
Parallel processing with emacs is probably not a good idea. Better use R to span multiple R subprocesses.