Beginner question: I am trying to use SAS macro arrays as explained in this article: http://www2.sas.com/proceedings/sugi31/040-31.pdf, specifically in the section %ARRAY WITH DATA= AND VAR=. Unfortunately there are no examples of a full program using this, and I can't find any simple examples online. I tried to create a simple example, guessing at some things, but it didn't work. (I got two errors for each macro: "Apparent invocation of macro ARRAY not resolved." and "Statement is not valid or it is used out of proper order.") What am I doing wrong?
Here is the code:
data data1;
input variable1;
datalines;
1
2
3
4
run;
%array(array1, data=data1, var=variable1);
%do_over(array1, phrase=PROC PRINT DATA=data1(obs=?));
run;
(Also, does anyone know the name of the SAS website which is sort of like this one? I remember seeing it but I can't find it again.)
Thanks!
You can download a zip file with the macros at the SAS Community website: http://www.sascommunity.org/wiki/Tight_Looping_with_Macro_Arrays
Include them in your SAS program and it should work.
Related
I'm using ESNACC for compiling multiple ASN source files to C code. For ease of understanding, I will explain the scenario here as succintly as possible:-
FileA.asn1 contains the following:-
FileA DEFINITIONS ::=
BEGIN
A ::= SEQUENCE
{
AContent [0] OCTET STRING (CONTAINING FileB.B)
}
END
FileB.asn1 contains the following:-
FileB DEFINITIONS ::=
BEGIN
B ::= SEQUENCE
{
BElem1 [0] INTEGER,
BElem2 [1] INTEGER
}
END
I used ESNACC to compile both files in one command. Upon analysing the C source files generated, I observed that the AContent field will be decoded as a constructed OCTET STRING (the data being received in the application guarantees that the field will be specified as constructed) with its contents being filled into a simple string. This means that FileB does not come into the picture at all. I was hoping that AContent would be further decoded with a structure of FileB being filled, so that I can easily access the elements within. This does not seem to be the case.
I'm fairly new with ASN1, so please let me know if my understanding is wrong in any way.
Is ESNACC not capable of generating code for supporting CONTAINING keyword properly?
Are there other compilers that are able to do this?
Can this be done by using ESNACC in any way?
If this cannot be done using ESNACC, and I don't want to use any other compiler, how would I access the contents within AContent at runtime easily?
I am not sure of the capabilities of ESNACC, but there are many other compilers that support the CONTAINING keyword. An excellent list of compilers can be found at https://www.itu.int/en/ITU-T/asn1/Pages/Tools.aspx which is part of the ITU-T ASN.1 Project.
Heimdal's ASN.1 compiler (lib/asn1/) has support for the funky Information Object System syntax extensions that allow you to declare things like what all goes into Certificate Extensions (for example), and the generated code will decode everything recursively in one go.
For a class assignment we needed to write a compiler. This includes an optimizer portion. In other words, we take in a file with some "code". An output file is generated. In the second step we take in the outputted code and remove any "dead" code and re-output to a second file. I have some problems with the optimizer portion and would like to use gdb. But I can't get gdb to operate properly with the input and output files arguments. The way we would normally run the optimizer is:
./optimize <tinyL.out> optimized.out
where tinyL.out is the file outputted in the first step and optimized.out is the file I want to output with the new optimized and compiled code.
I have searched Google for the solution and the tips I have found do not seem to work for my situation. Most people seem to want to only accept an input file and not output a separate file as I need to do.
Any help is appreciated (of course)
I'm not exactly sure what you're asking. But since I'm not yet able to comment everywhere, I write this answer with a guess and edit/delete if necessary.
When GDB is started and before you start the program you wish to debug, set the arguments you want to use with set args.
A reference to the documentation.
You just need to do the file redirection within gdb.
gdb ./optimize
(gdb) run < tinyL.out > optimized.out
https://stackoverflow.com/a/2388594/5657035
I'm developing a module that will be run on an Embedded ARM chip to run an attitude controller, which is written in C. We have a MATLAB simulation, with a bunch of low-level functions that I'd like to be able to make unit tests for with data generated by the MATLAB program.
Each function is reasonably complex, and I'd like to calculate the error between the Matlab output and the C output for validation purposes. Each function has the same Inputs and Outputs between the two implementations, so they should match (to an allowable tolerance).
Are there any good existing file formats that could be useful? The types of test data would be:
<Test Input 1> <Test Input 2> <Test input 3> <Expected Output 1> <Expected output 2>
Where inputs and outputs are arbitrary single floats, arrays or matrices. I have considered XML because there are some nice parsers, but thats about all i know.
Any suggestions or direction?
an easy way is to use CSV file format:
it is easy to handle from C. see here
use OpenOffice/Excel later by just changing the file suffix to *.csv
see more here about CSV files
It sounds like you want to run these unit tests from C? Have you considered running them in MATLAB instead? If so then you would be able to leverage the MATLAB Unit Test Framework and parameterized testing to encode the actual and expected values (using the "sequential" ParameterCombination attribute in your MATLAB test. This would require that you create MEX wrappers for your C code so that you can invoke them from MATLAB, but other than that extra step this could be quite seamless. Also, have you looked into using MATLAB Coder for this?
The MATLAB Unit Test would look something like this:
classdef Times2Test < matlab.unittest.TestCase
properties(TestParameter)
input = {1,2,3};
expectedResult = {2,4,6};
end
methods(Test, ParameterCombination='sequential')
function testMATLABSimulation(testCase, input, expectedResult)
actualResult = times2(input);
testCase.verifyEqual(actualResult, expectedResult, ...
'RelTol', 1e-6);
end
function testCAlgorithm(testCase, input, expectedResult)
% Must expose to MATLAB by compiling C code to Mex
actualResult = times2Mex(input);
testCase.verifyEqual(actualResult, expectedResult, ...
'RelTol', 1e-6);
end
end
end
Since each function has the same input, there is no reason not to create input files in the most simple form - just numbers!
You know exactly the type and amount of numbers you want to read, so just read them using fscanf
The file could look like:
12.3 100 200.3
1 2 3
4 5 6
7 8 9
The first row is the arbitrary float numbers, you read each one into a variable.
The next 9 are a matrix, so you read them in a loop into a 3x3 matrix, etc...
There is one bit in your question which is kind of an eyebrow raiser:
"inputs and outputs are arbitrary single floats, arrays or matrices". This is going to add some complexity but maybe there is no way around that.
An .Xml file format is a good choice because it gives you a lot of flexibility and you can import/export your tests in an editor to help you make sense of it.
But perhaps an even better choice is a .JSON file format. It offers the same flexibility as a xml files but is not as heavy weight. There are open source libraries available to work with them in C and I'm sure matlab can export data in this format as well.
I try to dump an array (reg [31:0] data [31:0]) but I can't do it successfully.
I've tried the way that is in the iverilog wiki:
integer idx;
for (idx = 0; idx < 32; idx = idx + 1)
$dumpvars(0,cpu_tb.cpu0.cpu_dp.cpu_regs.data[idx]);
It works, but 2 things happen.
A warning shows up: VCD warning: array word cpu_tb.cpu0.cpu_dp.cpu_regs.data[0] will conflict with an escaped identifier.
In GTKWave I have something like this in SST window: \data[0][31:0]
Is there any solution about that?
Thanks in advance and sorry for my English.
I have e-mailed the mailing list of Icarus Verilog. Here are some answers:
To dump an array word Icarus needs to escape the name so it is
compatible with the VCD dump format. That's what \data[0][31:0] is. It
is the zeroth 32-bit word of the data array. Because an escaped name
and an array name could now conflict Icarus produces the warning. It
would be best if it could check for an escaped identifier conflict and
only print a message when there is a problem, but as I remember this
was not possible.
We chose to use escaped identifiers so that all the dumpers could
handle array words. The other common choice is to only support them
using a special dump command that only works with certain dump
formats.
I agree it would be nice if we could make the warning more accurate,
but we are usually busy working on other things so minor annoyances
that appear to be complicated to fix do not often get fixed. As I
remember, and it has been a number of years, the issue is if you
search for the escaped identifier it find the array element and there
is no way in the VPI to search for the next occurrence. It's possible
that finding the array element in the Icarus search by name
implementation is a bug.
Cary
"To dump an array word Icarus needs to escape the name so it is
compatible with the VCD dump format. That's what \data[0][31:0] is.
It is the zeroth? 32-bit word of the data array. Because an escaped
name and an array name could now conflict Icarus produces the
warning. It would be best if it could check for an escaped identifier
conflict and only print a message when there is a problem, but as I
remember this was not possible."
...I don't think that there's a need to escape the names. Both VCS
(followed by fsdb2vcd) and CVC emit the name directly with no
problems. Cut and paste example shown below:
$var wire 5 `' IC_DrAd0 [3][4:0] $end $var wire 5 a' IC_DrAd0 [2][4:0]
$end $var wire 5 b' IC_DrAd0 [1][4:0] $end $var wire 5 c' IC_DrAd0
[0][4:0] $end
I realize the VCD spec doesn't define this, but I've had to fold in a
lot of these kinds of extensions into gtkwave over the years as other
tools generate these constructs. The escapes can cause save file
incompatibilities (missing signals) when trying to simulate on
iverilog versus VCS.
Over time, SV constructs likely will cause further things added to the
VCD files. AFAIK, the VCD part of the 1364 spec hasn't updated at all
since Verilog-XL. CVC gets around possible incompatibilities by
adding a +dump_arrays plusarg (and no, you don't have to loop on each
array element either).
-Tony
I also sent a mail to GTKWave creator Tony Bybell:
Hello,
The problem is that the compiler is not emitting those values into the
dump file. You'll have to get in contact with the iverilog
developers. I see the same problem if I run sim and compare against
another simulator such as CVC with +dump_arrays turned on which does
dump the arrays and they are visible in gtkwave.
http://iverilog.wikia.com/wiki/Release_Notes_Icarus_Verilog_0_9_2 |
Allow $dumpvars to accept array members for dumping,
...it looks like during "initial" time you might need to add a
$dumpvars statement for each array element you want dumped. I don't
know if the array name by itself works. Assigning each element to a
"wire" might work too.
I have never tried this functionality in iverilog so I don't know if
it works. You might have to experiment or ask the developers.
-Tony
I had a similar issue recently:
When dumping vars with the for cycle like the question, this vcd error happens:
ERROR: $dumpvars cannot dump a vpiConstant.
My workaround is to generate n wires with assign statement assigning it the respective array word like this:
reg [31:0] registers [31:0];
generate
genvar idx;
for(idx = 0; idx < 32; idx = idx+1) begin: register
wire [31:0] tmp;
assign tmp = registers[idx];
end
endgenerate
Now in GTKWave I have the generate blocks dumped correctly.
I'm new to Prolog and I have just started looking around. I read the Define Clause Grammar chapter on both Simply Logical and Learn Prolog now!, so now I wanted to get started with some exercise but I'm stuck.
I have to read from a file with this syntax
setName = {elemen1, element2,..., elementN}.
element1: element2 > element3.
Now I have read that when you define a DCG you have a parser for free, so I wanted to do that to get the data from my file to the Prolog program.
My problem is that in all the examples I have read they always provide a basic dictionary like
article --> [the]
but I cannot do that because I don't know what is going to be written in the file.
Any suggestions?
In SWI-Prolog, consider using library(dcg/basics). It provides building-blocks that you can use in your DCG. Focus on a clear declarative description of what the contents of the file look like, state this with a DCG. Then use phrase_from_file/2 from library(pio) to apply the DCG to a file.