PsychToolBox: Error passing input from GUI to simple Pavlovian script - psych

I have a GUI created from GUIDE (PITGUI.m) that is supposed to pass some simple input from the GUI to a Pavlovian script (PITtask.m) as a structure. When running it I'm receiving the following error:
Error: File: PITtask.m Line: 61 Column: 113
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for
mismatched delimiters.[enter link description here][1]
Error in PITGUI>RunExp_Callback (line 271)
PITtask(handles);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in PITGUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>#(hObject,eventdata)PITGUI('R. unExp_Callback',hObject,eventdata,guidata(hObject))
Error using uiwait (line 81)
Error while evaluating DestroyedObject Callback.
I have put the links for the GUI and Pavlovian scripts as well. Any help would be greatly appreciated!
Lauren
https://www.dropbox.com/s/8jspl7l233w62ek/PITGUI.m?dl=0
https://www.dropbox.com/s/g3pabwtqs06g4xj/PITtask.m?dl=0

To run your code, you would also need to post 'PITGUI.fig'. But, the error message you posted is triggered on line 61 of 'PITtask.m'. On line 61, it looks like you have command that spans multiple lines, but you haven't used ellipses (...) to indicate a multi-line command
Try changing:
fprintf(outfile, '%i %s %s %i %i %s \n', InputDataStruct.subn, InputDataStruct.subname, InputDataStruct.subsex,
InputDataStruct.subage, InputDataStruct.nblocks, InputDataStruct.subnote);
To:
fprintf(outfile, '%i %s %s %i %i %s \n', InputDataStruct.subn, InputDataStruct.subname, InputDataStruct.subsex,...
InputDataStruct.subage, InputDataStruct.nblocks, InputDataStruct.subnote);

Related

How do I make printf() print output in the correct order?

I have a simple working function that creates a table logging file information.
However, printf prints my output in the wrong order. I tried using fflush(stdout) to flush the buffer but it didn't change anything.
The function:
void printTable(char *libraryName)
{
printf("%-40s%-30s%-25s%-20s\n", "[File Name]", "[Creation Time]", "[Version]", "[Size]");
fflush(stdout);
printf("%-40s%-30d%-25d%-20f\n", libraryName, getCreationTime(libraryName), getVersion(libraryName), getSize(libraryName));
fflush(stdout);
}
The get functions are defined in a seperate file and give accurate output.
After compilation, the output looks like this:
[File Name] [Creation Time] [Version] [Size]
125 kB
Version: 1.0.0.0 [6-02-2020 03:32:21 PM] Objects.dll
But it needs to look like this:
[File Name] [Creation Time] [Version] [Size]
Objects.dll [6-02-2020 03:32:21 PM] 1.0.0.0 125 kB
What do I need to do to my printf() function to get the correct order output? I've tried flushing the buffer and rearranging order of the functions. Is it possible to get the output in the correct order without writing a separate printf() statement for each function?
The code you posted is fine and flushing isn't the answer. There's no way %d specifier could print strings like [6-02-2020 03:32:21 PM] and Version: 1.0.0.0, nor could %f result in 125 kB.
I suspect your get functions are printing their results rather than returning them, something like:
int getCreationTime(char *libraryName)
{
printf("[6-02-2020 03:32:21 PM] ");
}
int getVersion(char *libraryName)
{
printf("Version: 1.0.0.0 ");
}
double getSize(char *libraryName)
{
printf("125 kB\n");
}
I'm not sure what you are returning. Perhaps nothing? I have the feeling that you've got some compiler warnings you're ignoring. If so, read them, and address them!
If you're wondering why the results are mixed up it's because C doesn't proscribe that function arguments be evaluated in any particular order, such as left-to-right. It looks like getSize is being called first followed by getVersion and getCreationTime. Finally, the printf we see prints libraryName.

Passing Variable Number of Arguments to an Entry in a Char* Array

I have been using the following link: https://www.embedded.com/design/programming-languages-and-tools/4215552/Seventeen-steps-to-safer-C-code to enhance the current error logging of a project I am working on.
My end goal is to generate an enum "error type". I would map these error types to a lookup table of char*'s which I could use to log a more detailed explanation of what the error is.
This way, I have all my error codes and corresponding error strings in a central location and can easily modify/lookup a message and errorcode without having to dig through the code.
As a PoC, my header file contains the following:
typedef enum {
ECODE_OK = 0, // OK
ECODE_SAMPLE_ERR = 1,
ECODE_LAST
} myEcodes;
char * ecodeMap[ECODE_LAST+1];
char * ecodeName(myEcodes err);
My implementation in C of the header is included below:
char * ecodeMap[ECODE_LAST+1] =
{
"No error to report",
"Example Error Code - Invalid Value",
"Last ecode place holder"
};
char * ecodeName(myEcodes err)
{
return (char *) eyescanEcodeMap[err];
}
My question is, say I have the following code snippet to log an error I encountered:
fprintf(fp, "%s", ecodeName(ECODE_SAMPLE_ERR));
What if I want ECODE_SAMPLE_ERR to actually contain a formatted string like
"Example Error Code - Invalid Values: %d %d", myVarInt1, myVarInt2
instead of just
"Example Error Code - Invalid Value"
What would be the best way to be able to format individual strings in my array of char* such that I can include the value of variables in particular entries?
If the main aim is to add print along with other variable values, let ERROR string be constant. You can just add additional values when you are writing to file fp.
fprintf(fp, "%s: %d %d", ecodeName(ECODE_SAMPLE_ERR), myVarInt1, myVarInt2);

perl6 IO::Handle has no printf method, inconsistent with documentation, or I missed something?

I am trying to open a file for writing and use printf to do formatting, but documentation and reality do not seem to agree. Am I missing something?
To exit type 'exit' or '^D'
> my $fh=open "test", :w;
IO::Handle<"test".IO>(opened, at octet 0)
> $fh.printf: "test";
No such method 'printf' for invocant of type 'IO::Handle'
in block <unit> at <unknown file> line 1
But my code seems okay according to documentation:
https://docs.perl6.org/routine/printf
Thank you very much !!
Apparently IO::Handle.printf was added on Nov 27, 2016 and Rakudo 2016.11 is tagged on Nov 19. So my guess is your Rakudo is older than that.
The printf() example in the docs doesn't work for me either:
~/p6_programs$ perl6 -v
This is Rakudo version 2016.11 built on MoarVM version 2016.11
implementing Perl 6.c.
~/p6_programs$ cat 4.pl6
my $fh = open 'outfile.txt', :w;
$fh.printf: "The value is %d\n", 32;
$fh.close;
~/p6_programs$ perl6 4.pl6
No such method 'printf' for invocant of type 'IO::Handle'
in block <unit> at 4.pl6 line 3
You could use sprintf() as a workaround:
my $fh = open 'outfile.txt', :w;
$fh.say: sprintf "The value is %d", 32;
$fh.close;
or fmt():
my $fh = open 'outfile.txt', :w;
$fh.say: 32.fmt("The value is %d");
$fh.close;

LoadRunner sprintf and lr_eval_string

I am facing some issues that I'm certain is correct code, as I've seen it work before today, and without any changes made to the script, only a VUGen version change/upgrade.
HP Virtual User Generator:: Version: 12.02.0.0
ClockingIDCount = atoi(lr_eval_string("{ClockingID_count}"));
lr_output_message("CIDCount:%d",ClockingIDCount);
lr_output_message("ClockingID1::%s",lr_eval_string("{ClockingID_1}"));
for (i = 1; i <= ClockingIDCount; i++) {
sprintf(loopParam, "{ClockingID_%d}", i);
lr_output_message("ClockingID: %s %s %s", loopParam, lr_eval_string("{loopParam}"), lr_eval_string(lr_eval_string("{loopParam}")));
}
Outputs:
Action.c(120): CIDCount:21
Action.c(121): Notify: Parameter Substitution: parameter "ClockingID_1" = "6829888"
Action.c(121): ClockingID1::6829888
But using the sprintf function to iterate over the items captured, returns;
Action.c(125): ClockingID: {ClockingID_1} {loopParam} {loopParam}
Note: I'm aware the 3rd %s evaluation shouldn't work - was just a thought as I've seen it resolve things like this before.
Code tampered!
Solution :: Remove the "{ }" from the lr_eval_string function;
Solution :: lr_output_message("ClockingID: %s", lr_eval_string(loopParam));

Unable to Execute script starting with Character 'U'

I have the below code snippet which executes a script through C program.
char upgrd_bb[512] = "";
sprintf(upgrd_bb,"/usr/bin/./\UPGRD_BB_ALL '%s'", path_argv[5]);
if(!(system(upgrd_bb)))
{
dw_flag = 0;
printf("Unable to Upgrade BB ");
}
During Cross-compilation i get error
/home/ubuntu/Documents/FileOper.c:829:14: warning: universal character names are only valid in C++ and C99
/home/ubuntu/Documents/FileOper.c:829:14: error: incomplete universal character name \U
make: *** [/home/ubuntu/Documents/FileOper.o] Error 1
If i am changing the name of the script to any other character it compiles fine. can any one focus on this.
thanks in advance !!
In the string
"/usr/bin/./\UPGRD_BB_ALL '%s'"
You have the sequence \U, which is being treated as a Unicode escape sequence. If you delete the extra backslash to get
"/usr/bin/./UPGRD_BB_ALL '%s'"
then you should be all set.
On the other hand, if you need the extra backslash in the name, then escape it:
"/usr/bin/./\\UPGRD_BB_ALL '%s'"
Hope this helps!

Resources