Working with MultiDimensional arrays

Hi,
Just wondering if anyone could help with a problem Im
having with multi-dimensional arrays in Java:-
I want to create a multi-dimensional array (e.g. 3 dimensions). I know this can be defined by code such as:-
int[ ][ ][ ] my_array = new int[10][10][10];
(would create a 10x10x10)
My problem is that I want to address the array with indexes that aren't known at compile time, trying to do this causes an error:-
e.g. my_array[0][0][0] = 1; is ok (i.e. the element at 0,0,0 is set to 1)
but if the indexes 0,0,0 are replaced by the return value of some function,
e.g.
my_index1 = generateIndex(x, y, .... etc);
my_index2 = generateIndex(a, b, ...etc);
my_index3 = generateIndex(f,g, .. etc);
(where generateIndex is some function that returns an integer)
and the array element set with
my_array[my_index1][my_index2][my_index3] = 3;
This generates an error. I know that this problem can be overcome through the use of pointers in C++ but since Java doesn't use pointers, im a bit stuck!
I have come across a method that overcomes this for a 1D array, using the setInt function of the Array class, e.g.
Array.setInt(my_1Darray, 0, 1); (would set the first value of my_1Darray to 1);
(i.e. Array.setInt(array_name, int index, int value);
But I can't see how this works with multidimensional arrays.
If anyone could shed any light on this problem, that would be great.
Thanks,
Peter

public class NDArray {
        public static void main(String[] s) {
                int[][][] _3D = new int[10][10][10];
                for (int c = 0; c < 1000; c++)
                        _3D[rnd()][rnd()][rnd()]=rnd();
                for (int i=0; i < 10; i++) {
                  for (int j=0; j < 10; j++) {
                    for (int k=0; k < 10; k++) {
                        System.out.print(_3D[i][j][k]);
                        System.out.print(" ");
                  System.out.println();
                System.out.println();
        static int rnd() {return (int) (10*Math.random());}
/* output (example):
7 0 0 4 9 9 3 0 0 2
0 1 8 9 6 0 0 0 0 0
5 3 0 5 0 0 1 0 0 3
5 6 0 5 0 0 3 0 0 0
0 0 0 0 4 0 0 5 8 6
0 9 0 9 0 1 0 2 0 0
3 3 8 6 0 0 1 0 3 4
9 6 7 0 0 0 3 6 6 3
2 0 8 7 0 1 4 0 7 0
8 0 4 4 3 0 0 5 4 0
0 0 0 0 3 0 1 0 0 4
9 0 8 9 1 0 9 0 9 0
0 8 3 4 1 0 8 0 0 2
3 0 0 7 3 3 0 5 0 0
0 0 0 1 4 6 0 0 0 3
3 5 8 5 8 0 8 2 0 4
4 0 1 7 0 1 0 4 4 0
6 0 5 0 0 4 0 8 1 0
0 0 6 6 2 0 0 4 5 0
0 6 7 0 4 0 7 5 0 0
2 4 0 5 0 0 0 2 1 7
0 6 0 9 0 0 6 1 2 0
0 5 9 0 1 2 4 0 8 6
0 0 8 0 0 3 3 8 0 0
4 7 5 9 0 8 1 0 0 9
2 0 0 3 0 0 8 3 0 7
0 6 0 6 0 0 0 0 1 0
0 9 9 8 4 2 0 0 7 2
4 0 0 9 0 0 0 1 0 6
7 0 6 5 2 3 7 8 0 2
0 0 3 5 0 0 0 0 0 0
3 0 0 0 0 2 0 0 6 0
6 0 3 3 6 0 4 0 1 6
0 0 7 2 0 8 0 0 0 0
0 0 9 0 6 8 2 1 0 0
9 0 4 1 3 9 3 2 7 7
0 3 1 0 3 0 0 9 0 5
0 0 0 0 6 0 4 8 0 5
1 8 4 6 7 0 0 4 4 0
0 4 8 0 0 0 6 0 4 0
0 9 3 0 0 0 6 0 0 8
6 8 2 9 6 0 0 7 9 0
7 1 9 0 0 5 0 2 3 0
0 0 0 0 9 9 0 7 0 9
9 8 8 2 9 8 0 5 8 0
2 3 0 4 0 4 1 0 6 9
3 3 0 0 0 0 7 6 9 3
6 2 2 1 0 5 8 3 0 6
0 6 0 0 0 0 0 0 7 5
0 6 0 0 0 3 3 0 2 0
3 6 5 5 8 2 0 9 1 0
8 0 7 0 9 0 9 0 2 0
0 2 9 0 0 1 2 4 0 2
3 1 0 2 0 0 0 0 0 0
0 5 0 3 8 8 3 0 0 0
9 0 9 0 5 1 0 9 5 0
8 0 0 8 8 7 0 3 1 0
4 0 0 0 1 8 0 9 0 5
0 0 6 6 0 0 5 2 6 8
0 4 0 9 0 0 2 0 0 3
0 5 8 1 7 0 0 4 2 0
6 5 0 0 2 0 6 8 8 7
0 0 0 0 3 0 8 4 0 0
2 3 3 0 0 7 6 8 0 4
4 1 7 3 8 0 2 3 3 0
1 5 0 0 4 1 3 7 3 1
0 0 0 6 0 6 0 0 3 0
3 7 0 4 5 9 5 5 0 8
3 8 6 4 0 0 0 1 6 0
0 0 2 0 2 9 0 0 0 5
0 5 6 0 5 5 4 0 6 7
0 2 2 0 9 7 4 2 9 0
4 0 5 4 8 3 0 0 2 0
0 0 9 3 3 0 8 8 7 0
0 7 9 7 0 0 0 7 1 0
2 0 0 0 5 8 2 0 0 5
2 4 9 6 6 0 0 0 6 0
0 6 6 7 0 2 0 0 5 2
0 9 0 4 8 5 1 0 7 6
0 0 7 0 4 0 3 8 0 9
9 4 0 0 0 4 0 0 0 5
2 0 4 7 7 5 4 0 9 0
0 0 1 0 5 0 1 0 6 0
0 6 0 9 0 9 0 4 7 0
5 9 6 6 2 8 8 4 1 4
9 7 3 2 7 6 0 2 3 0
3 1 5 0 8 0 0 0 0 0
9 0 0 3 0 8 7 0 4 0
8 6 6 4 0 4 6 4 5 0
0 0 0 0 0 4 4 0 0 9
8 8 0 2 0 0 0 1 0 0
6 2 1 1 9 0 5 1 0 0
0 9 1 0 6 0 4 0 0 0
9 4 0 3 0 1 0 7 6 0
0 9 0 7 8 6 0 5 0 0
0 8 8 9 0 5 7 0 0 0
0 4 5 1 6 0 5 2 9 3
6 0 0 0 0 0 0 9 1 0
5 9 1 9 2 5 3 0 0 9
2 9 5 1 7 0 0 0 9 0
*/Seems to work just fine. How is your code different from mine?

Similar Messages

  • Doesn't NVL work with Assosiative array elements

    Doesn't NVL work with Assosiative arrays? When i tried to UPDATE empdtls table with the values stored
    in v_ename array, i got no_data_found error because
    the query, select ename bulk collect into v_ename.....returns only 5 rows and v_ename(6) was null. So i tried NVL and COALESCE for v_ename(6). I couldn't succeed.
    Any workarounds?
    create table empdtls
    (ename1 varchar2(30),
    ename2 varchar2(30),
    ename3 varchar2(30),
    ename4 varchar2(30),
    ename5 varchar2(30),
    ename6 varchar2(30),
    location varchar2(30));
    SQL> insert into empdtls(location) values ('NY');
    1 row created.
    SQL> commit;
    declare
    type ename_arraytyp is table of varchar2(100) index by binary_integer;
    v_ename ename_arraytyp;
    begin
    select ename bulk collect into v_ename from emp where sal>2900;
    dbms_output.put_line(v_ename(1));
    dbms_output.put_line(v_ename(2));
    dbms_output.put_line(v_ename(3));
    update empdtls
               set ename1=v_ename(1),
                   ename2=v_ename(2),
                   ename3=v_ename(3),
                   ename4=v_ename(4),
                   ename5=v_ename(5),
                   ename6=NVL(v_ename(6),'No Name')
               where location='NY';
    commit;
    end;
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 9Message was edited by:
    J.Kiechle

    If you used a schema level collection type (i.e. created with CREATE TYPE) you could also use the unsupported SYS_OP_CEG function which appears to return collection elements for given index values without error if the element does not exist.
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> CREATE OR REPLACE TYPE varchar2_table
      2  AS
      3     TABLE OF VARCHAR2 (4000);
      4  /
    Type created.
    SQL> DECLARE
      2     v_ename varchar2_table;
      3  BEGIN
      4     SELECT ename
      5     BULK COLLECT INTO v_ename
      6     FROM   emp
      7     WHERE  sal > 2900;
      8
      9     UPDATE empdtls
    10        SET ename1 = sys_op_ceg (v_ename, 1),
    11            ename2 = sys_op_ceg (v_ename, 2),
    12            ename3 = sys_op_ceg (v_ename, 3),
    13            ename4 = sys_op_ceg (v_ename, 4),
    14            ename5 = sys_op_ceg (v_ename, 5),
    15            ename6 = sys_op_ceg (v_ename, 6)
    16      WHERE location = 'NY';
    17  END;
    18  /
    PL/SQL procedure successfully completed.
    SQL>

  • For each loop with multidimensional arrays?

    Hi.I have a problem with for each and multidimensional combination.
    public class TestCards
    static int[][] dizi={{1,2},{3,4}};
    static int t ;
    public static void main(String[]args)
         for (int[] i : dizi)
         System.out.println(i);
    The result of the codes above is like this
    [I@9304b1
    [I@190d11
    In other words the result is now integer.It has some strange chars which i dont know
    Pls help me !

    You're printing an array. Arrays don't override toString.
    - You could iterate over both dimensions and print each value yourself.
    - You could iterate over one dimension and call java.util.Arrays.toString to print a row at a time.*
    - You could call java.util.Arrays.deepToString to print the entire thing in one shot.
    *The second option is closest to what you're doing now.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Working with word arrays in a game

    In my spelling game, I have arrays of words that is added to a text field one at a time (through a loop). They are also split into letters so that the player can click on a corresponding letter tile to copy the word. The active letter would be 100% visible (alpha setting )and the other letters would be set to 80%.
    Splitting each word works well it you just want the entire word broken into individual letters, BUT I want my game to be phonics based - so sometimes the sound in a word will have more than one letter e.g. for the word "elephant" the array would be: activeWord:Array = ["e","l","e","ph","a","nt"] and there would of cause be letter tiles with the sound -ph- and -nt- on them to click on too.
    I guess this is where arrays within arrays gets the job done? I have 10 words per level and 30 levels. I will break each word into it's sounds and hardcode each word like I did elephant above.
    How do I rewrite the loop below to accomodate the 10 word loop within a level. After each level I want a score to appear with the option to click next for the next level.
    public var  wordsL1:Array = ["elephant","has","of","off","on","not","got","in","is","it"];
                    private var tf:TextField;
                    public var letterArray:LetterArray;
                    public var tileTimer = new Timer(500,384);
                    // ***constructor code
                    public function WordArray(_tf:TextField)
                        tf = _tf;
                        nextWordF();
                        //**Run letter Tiles Start**//
                        letterArray = new LetterArray();
                        addChild(letterArray);
                        tileTimer.addEventListener(TimerEvent.TIMER, gameLoop);
                        tileTimer.start();
                        public function gameLoop(timerEvent:TimerEvent):void
                            trace("Tile Timer Started");
                            letterArray.gameLoop();
                        //**end**//   
                    function nextWordF():void
                        if(wordsL1.length>0)
                            activeWordF();
                            populateMyWordBox();
                        else
                                //quiz is complete
                        private function activeWordF():void
                            activeWordArray = wordsL1.shift().split("");
                             // this array needs to be passed to the class that checks which letters are clicked (or used in this class if that's where the clicked letters are handled) so the clicked letters                               can be compared to activeWordArray's elements.   
                            // when the clicked letters are completed for this word, call nextWordF().

    There's always a better way to do things but ultimately it comes down to if what you're doing works for your audience. If it does, the majority would say you did it correct. After you did it correctly you can spend time optimizing it however you like. If you get down to those specific questions be sure to provide a sample and some code that you think needs optimization and I'm sure we'll be able to help. You're welcome and good luck!

  • ACL not working with RAID array

    Posted this before but it wasn't clear.
    Brand new install of Leopard Server 10.5.1. Have an HFS+ SCSI RAID array attached. I am unable to get ACLs to work using this volume.
    Using the command sudo fsaclctl -a I get the following:
    <CFDictionary 0x106580 0xa00c5174>{type = mutable, count = 9, capacity = 12, pairs = (
    0 : <CFString 0x1020f0 0xa00c5174>{contents = "device_manufacturer"} = <CFString 0x106140 0xa00c5174>{contents = "HPT"}
    1 : <CFString 0x1066b0 0xa00c5174>{contents = "spparallelscsidevicetype"} = <CFNumber 0x1066e0 0xa00c5174>{value = +0, type = kCFNumberSInt32Type}
    3 : <CFString 0x101ac0 0xa00c5174>{contents = "device_revision"} = <CFString 0x106170 0xa00c5174>{contents = "4.00"}
    4 : <CFString 0x106660 0xa00c5174>{contents = "spparallelscsidevicefeatures"} = <CFArray 0x106690 0xa00c5174>{type = immutable, count = 0, values = (
    5 : <CFString 0x106740 0xa00c5174>{contents = "spparallelscsi_target"} = <CFString 0xa00d16b4 0xa00c5174>{contents = "0"}
    6 : <CFString 0x101a60 0xa00c5174>{contents = "device_model"} = <CFString 0x106150 0xa00c5174>{contents = "DISK 1_0"}
    7 : <CFString 0x1066f0 0xa00c5174>{contents = "spparallelscsiit_nexusfeatures"} = <CFArray 0x106720 0xa00c5174>{type = immutable, count = 0, values = (
    9 : <CFString 0x1018f0 0xa00c5174>{contents = "_items"} = <CFArray 0x106030 0xa00c5174>{type = mutable-small, count = 1, values = (
    0 : <CFDictionary 0x106070 0xa00c5174>{type = mutable, count = 14, capacity = 24, pairs = (
    0 : <CFString 0x103c80 0xa00c5174>{contents = "os9_drivers"} = <CFString 0xa00d4024 0xa00c5174>{contents = "no"}
    1 : <CFString 0x106180 0xa00c5174>{contents = "partitionmaptype"} = <CFString 0x1061a0 0xa00c5174>{contents = "applepartition_maptype"}
    2 : <CFString 0x1029b0 0xa00c5174>{contents = "volumes"} = <CFArray 0x106250 0xa00c5174>{type = mutable-small, count = 1, values = (
    0 : <CFDictionary 0x106290 0xa00c5174>{type = mutable, count = 7, capacity = 12, pairs = (
    5 : <CFString 0x1026b0 0xa00c5174>{contents = "mount_point"} = <CFString 0x1063a0 0xa00c5174>{contents = "/Volumes/SUPERBACKUP"}
    9 : <CFString 0x101940 0xa00c5174>{contents = "_name"} = <CFString 0x106270 0xa00c5174>{contents = "SUPERBACKUP"}
    10 : <CFString 0x103820 0xa00c5174>{contents = "writable"} = <CFString 0xa00d4024 0xa00c5174>{contents = "no"}
    12 : <CFString 0x101f40 0xa00c5174>{contents = "bsd_name"} = <CFString 0x106350 0xa00c5174>{contents = "disk3s3"}
    13 : <CFString 0x1025d0 0xa00c5174>{contents = "free_space"} = <CFString 0x106380 0xa00c5174>{contents = "3.27 TB"}
    14 : <CFString 0x1024f0 0xa00c5174>{contents = "file_system"} = <CFString 0x106370 0xa00c5174>{contents = "HFS+"}
    15 : <CFString 0xa00d4ca4 0xa00c5174>{contents = "size"} = <CFString 0x1061d0 0xa00c5174>{contents = "4.09 TB"}
    3 : <CFString 0x101ac0 0xa00c5174>{contents = "device_revision"} = <CFString 0x106170 0xa00c5174>{contents = "4.00"}
    6 : <CFString 0x101a60 0xa00c5174>{contents = "device_model"} = <CFString 0x106150 0xa00c5174>{contents = "DISK 1_0"}
    9 : <CFString 0x101940 0xa00c5174>{contents = "_name"} = <CFString 0x106050 0xa00c5174>{contents = "SCSI Logical Unit @ 0"}
    10 : <CFString 0x103720 0xa00c5174>{contents = "volumes_anonymous"} = <CFArray 0x1060b0 0xa00c5174>{type = mutable-small, count = 1, values = (
    0 : <CFDictionary 0x1060f0 0xa00c5174>{type = mutable, count = 5, capacity = 12, pairs = (
    9 : <CFString 0x101940 0xa00c5174>{contents = "_name"} = <CFString 0x106350 0xa00c5174>{contents = "disk3s3"}
    10 : <CFString 0x103820 0xa00c5174>{contents = "writable"} = <CFString 0xa00d4024 0xa00c5174>{contents = "no"}
    12 : <CFString 0x1025d0 0xa00c5174>{contents = "free_space"} = <CFString 0x106380 0xa00c5174>{contents = "3.27 TB"}
    14 : <CFString 0x1024f0 0xa00c5174>{contents = "file_system"} = <CFString 0x106370 0xa00c5174>{contents = "HFS+"}
    15 : <CFString 0xa00d4ca4 0xa00c5174>{contents = "size"} = <CFString 0x1061d0 0xa00c5174>{contents = "4.09 TB"}
    12 : <CFString 0x101f40 0xa00c5174>{contents = "bsd_name"} = <CFString 0x106130 0xa00c5174>{contents = "disk3"}
    13 : <CFString 0x106230 0xa00c5174>{contents = "spparallelscsi_lun"} = <CFString 0xa00d16b4 0xa00c5174>{contents = "0"}
    14 : <CFString 0x101a40 0xa00c5174>{contents = "detachable_drive"} = <CFString 0xa00d4024 0xa00c5174>{contents = "no"}
    16 : <CFString 0x1020f0 0xa00c5174>{contents = "device_manufacturer"} = <CFString 0x106140 0xa00c5174>{contents = "HPT"}
    17 : <CFString 0x101ec0 0xa00c5174>{contents = "removable_media"} = <CFString 0xa00d4024 0xa00c5174>{contents = "no"}
    30 : <CFString 0x1061f0 0xa00c5174>{contents = "smart_status"} = <CFString 0x106210 0xa00c5174>{contents = "Not Supported"}
    31 : <CFString 0xa00d4ca4 0xa00c5174>{contents = "size"} = <CFString 0x1061d0 0xa00c5174>{contents = "4.09 TB"}
    10 : <CFString 0x101940 0xa00c5174>{contents = "_name"} = <CFString 0x106640 0xa00c5174>{contents = "SCSI Target Device @ 0"}
    ProcessVolume: processing /
    Access control lists are supported on /.
    ProcessVolume: processing /Volumes/Superserver Internal 750
    Access control lists are supported on /Volumes/Superserver Internal 750.
    Does this mean that the RAID volume is incompatible with ACLs despite being a HFS+ formatted array? Would a fresh install of server fix this?
    Completely lost here...can someone help?
    Many thanks,
    Joel.

    I tried our old "unimporant" SCSI RAID and it reported:
    "Support for access control lists is unknown."
    I guess our RAID was formated/initialized ona a pre Intel server, yours too?
    But your volume doesn't support a journaled HFS + (easliy changed in Disk Utility)
    Better/faster if you get a server hang (takes much less time to "replay" the disk at boot than to wait for fsck to finish on such a large volume).
    Ours look like this :
    <CFString 0x1024b0 [0xa016a1a0]>{contents = "file_system"} = <CFString 0x106490 [0xa016a1a0]>{contents = "Journaled HFS+"} <-------------
    It might be worth while trying a repartition on the new server beacuse our say:
    <CFString 0x1062a0 [0xa016a1a0]>{contents = "partitionmaptype"} = <CFString 0x1062c0 [0xa016a1a0]>{contents = "applepartition_maptype"} <------ maybe not really important but (doesn't support booting on Intel systems). What should be used on Intel systems?). Should be GUID instead? Doesn't matter for non boot drives???
    You haven't got too much data on it yet : Size "4.09 TB" - "3.27 TB" free.
    In Tiger you set up the volume to use ACLs in WGM.
    In Leopard SA it's a bit bewildering (haven't look at it since before 10.5.2 update though)...

  • Does "AirPort Disk" work with RAID arrays?

    I currently have a RAID 10 array consisting of four USB hard drives all attached to a USB hub. I use it with three different macs (two leopard, one tiger) and have never had any problems. I know that you can attach multiple USB hard drives to an AirPort Extreme Base Station via a hub, but will it recognize a RAID array and make it available as a single volume over the network?

    ...but will it recognize a RAID array and make it available as a single volume over the network?
    Why did you ask that question if the device has never appeared as multiple drives?
    I understand that the AEBS is NOT a Mac.
    (a) Some RAID devices are hardware RAID devices. These devices use several hard drives but appear to the outside world as a single hard drive.
    (b) Some devices allow you to install several hard drives and then these must be pieced together into a software RAID and then appear as a single hard drive. OS X has the ability to do this.
    If this device operates like the description in (a) it should have no problem connected to the AEBS.

  • BPEL - Error while working with XML Arrays

    Hi,
    I am getting an error when i try to do the following Copy Operation.
    <copy>
    <from expression="ora:getElement('Invoke2_OutputVariable','LinetDetailsResponse','/ns8:LinetDetailsResponse/ns8:lineDetails/ns8:item/ns8:telNo',bpws:getVariableData('Counter'))"/>
    <to variable="outputVariable" part="payload"
    query="/ns3:Response/ns5:LineDetailsInfo[bpws:getVariableData('Counter')]/ns5:lineID"/>
    </copy>
    The error seems to be with the bpws:getVariableData('Counter') function in the 'copy to' section. If I hard code the value instead of using the function, it works. The exact error message is
    "XPath query string returns zero node.
    The assign activity of the to node query is returning zero node.
    Either the to node data or the xpath query in the to node was invalid.
    According to BPEL4WS spec 1.1 section 14.3, verify the to node value at line number 308 in the BPEL source."
    Could someone suggest what is the issue?
    Regards,
    Shyam
    Edited by: user8310006 on Jul 13, 2010 5:50 AM

    It is not able to find a variable where it has to copy data.
    <to variable="outputVariable" part="payload"
    query="/ns3:Response/ns5:LineDetailsInfo[bpws:getVariableData('Counter')]/ns5:lineID"/>
    try to do this
    <to variable="outputVariable" part="payload"
    query="/ns3:Response/ns5:LineDetailsInfo[$Counter]/ns5:lineID"/>
    or try this
    <to variable="outputVariable" part="payload"
    query="/ns3:Response/ns5:LineDetailsInfo[$bpws:getVariableData('Counter')]/ns5:lineID"/>
    -Yatan

  • Help with working with an array of objects

    Help!
    I'm trying to make an array of objects.
    I have a class named enemy.
    I want an array of enemy's.
    enemy[] Elist = new enemy[num];
    I now have an empty array.
    My question is, How do I initialize and retrieve vars from the objects?

    To create you need a loop that for each slot in the array you create a new enemy (should be Enemy) and store it in the array.
    Do you know how to access a single element in an array? ie the syntax to do that. If not then re-read your book or notes on arrays. I'm sure it mentions it there.
    Or you can just read the code provided above.
    Message was edited by:
    flounder

  • Multidimensional arrays with enhanced for statement

    hello, do you know if it is possible to use enhanced for loop with multidimensional arrays, and if yes, then how?
    for example:
    int[][] arr = {{1,2},{3,4}};
    for(int i[][] : arr){
        doSomethingWith(i[][]);
    }

    The syntax is nice'n'easy:
    void f(int[][] m) {
        for(int[] row : m) {
            for(int x : row) {
    }

  • Multidimensional arrays

    I need help in creating a program that assigns a rock star name when they enter their own name. It must assign the same name to the same user's name, but different last names when that changes.

    Sorry?
    And what has it to do with multidimensional arrays?

  • Synthesis bug with SV packed multidimensional array slices

    I've been using SV packed multidimensional arrays to do things like representing a bus which is many bytes wide, e.g. a 128-bit bus can be declared like this:
    logic [15:0] [7:0] myBus;
    You should be able to write "myBus[15:8]" to get the upper 64 bits (8 bytes) of this 128-bit wide packed value. However, I've found that in some expressions this produces some very buggy behavior. I've reduced it to a simplified example, with comments to show what works and what doesn't.
    `timescale 1ns / 1ps
    module sv_array_select (
    input logic sel,
    input logic [3:0] [1:0] i,
    output logic [3:0] outA,
    output logic [3:0] outB,
    output logic [3:0] outC
    // Works; equivalent to assign outA = {i[1], i[0]};
    assign outA = i[1:0];
    // Works; equivalent to assign outB = {i[3], i[2]};
    assign outB = i[3:2];
    // FAILURE
    // Synthesizes to equivalent of:
    // assign outC[2:1] = sel ? i[2] : i[0];
    // assign outC[3] = 1'bZ;
    // assign outC[0] = 1'bZ;
    assign outC = sel ? i[3:2] : i[1:0];
    endmodule
     I get this result in Vivado 2015.2 and 2013.2, haven't tried other tool versions.

    ,
    Yes, I can see that incorrect logic is getting generated by the tool.
    I will file a CR on this issue and will let you know the CR number.
    Thanks,
    Anusheel
    Search for documents/answer records related to your device and tool before posting query on forums.
    Search related forums and make sure your query is not repeated.
    Please mark the post as an answer "Accept as solution" in case it helps to resolve your query.
    Helpful answer -> Give Kudos
     

  • How to make an acquired array of data work with point-by-point functions

    Hello everyone,
    I am working on a LabVIEW project using the Measurement Computing PCI-DAS6402/16 board. I am attempting to use point-by-point analysis with data acquired from the board, but I am having some difficulty. I am currently only able to acquire an array of data and not just a single point of data per scan. So, I was wondering if i) anybody possibly had any knowledge/experience using this particular board and getting it to be compatable with point-by-point VIs or ii) if anybody possibly knows anyway to convert an array of acquired data to work with point-by-point VIs in a hard realtime application. Thanks
    Pat
    Message Edited by Support on 11-16-2005 07:56 AM

    Hi Pat
    I just can tell you how you can use the pt-by-pt functions. As you said you have an array of data. To use the pt-by-pt functions, you need the single datapoints. So the only way is to use a loop to get the single elements and pass them to the pt-by-pt functions.
    I've attache a simple example.
    If this is the right way for you concerning processor and memory load, execution speed etc. I can't tell you.
    Hope this helps.
    Thomas 
    Using LV8.0
    Don't be afraid to rate a good answer...
    Attachments:
    PtByPt.vi ‏17 KB

  • Working with ExtensionData attribute (byte arrays)

    Hello all,
    I am working with the ExtensionData attribute in PowerShell, which is in byte array form. What I am wanting to do is change a part of this ExtensionData attribute, but still keep the byte array form. What I am currently trying makes the change successfully,
    but I lose the byte array form. For example, before changing the ExtensionData attribute, Group1's ExtensionData attribute is populated on several lines within the attribute. After changing the attribute, Group1's ExtensionData attribute has all the same values,
    but is now contained on a single line. Here is the code used:
    #Finding Group1's ExtensionData attribute, in string form
    $ExtensionData = Get-ADGroup "Group1" -Properties extensiondata | select -ExpandProperty extensiondata | ForEach-Object {
    [System.Text.Encoding]::ASCII.GetString($_)
    #Let's assume Group1's ExtensionData attribute looks like this (multiple lines):
    #OldLine1
    #OldLine2
    #OldLine3
    $StringOld = "OldLine1"
    $StringNew = "NewLine1"
    #making sure line I want to change is present in string form of ExtensionData attribute, then we change the part we want
    If($ExtensionData -match $StringOld){
    $ExtensionData -replace "$StringOld","$StringNew"
    #Now we convert our new ExtensionData string form back to ASCII form
    $change = [System.Text.Encoding]::ASCII
    $NewExtensionData = $change.GetBytes($ExtensionData)
    #Now, we can replace Group1's ExtensionData attribute with our new ExtensionData attribute
    Set-ADGroup Group1 -Replace @{extensiondata=$NewExtensionData}
    #However, now Group1's ExtensionData attribute looks like this (no multiple lines):
    #NewLine1OldLine2OldLine3
    How can I replace a line in the ExtensionData attribute and still keep the multiple lines within the attribute?

    David,
    Thanks again for taking time to help me out with this problem! I've solved my problem, but had to perform a few steps along the way. Long story short, I slightly modified the code you provided using -match and -replace for the strings, and then
    when I tried to use -replace on the set-adgroup cmdlet, PowerShell griped and said value already present.
    However, I was able to get it to work by clearing the extensiondata attribute first and then using -add. This put the bytes into the extensiondata attribute as expected, but there were 2 problems with this. First, it looked like each byte was it's own array
    within the attribute. Second, the original ExtensionData attribute had strings in it, not bytes. I have since realized that bytes is how PowerShell reads the array, but not how ADUC displays it.
    What I did was use the following code:
    cls
    $ExtensionData = @(
    Get-ADGroup "Group1" -Properties extensiondata |
    Select-Object -ExpandProperty extensiondata |
    ForEach-Object {
    [System.Text.Encoding]::ASCII.GetString($_)
    $StringOld = "OldString"
    $StringNew = "NewString"
    for ($i = 0; $i -lt $ExtensionData.Count; $i++)
    if ($ExtensionData[$i] -match $StringOld)
    $ExtensionData[$i] = $ExtensionData[$i] -replace "$Stringold","$StringNew"
    Set-ADGroup SmartDL-test -replace @{extensiondata=$ExtensionData}
    As you can see, I still use -match and -replace to swap out the part of ExtensionData that I want. But it turns out I didn't need to convert the strings into bytes before using the set-adgroup command. I was able to just replace the part of the extensiondata
    collection I wanted, and then just paste the entire new collection into the attribute, and for my purposes it appeared to work.
    Anyway, I really appreciate your help on this, and it must be difficult helping someone troubleshoot when you can't see specifically what they're trying to do. Your post was extremely helpful however, and it led to the solution that worked for me. Thanks
    again!

  • NXT Flatten to String Not Working with Clusters and Arrays

    Hello,
    My name is Joshua and I am from the FIRST Tech Challenge Team 4318, Green Machine. We are trying to write a program that will write to a configuration file and read it back. The idea is that we will be able to write to a config file from our computer that will be read by our autonomous program when it runs. This will define what the autonomous program does.
    The easiest way to do this seems to be flattening a data structure to a string, saving it to a file, and then reading back and unflattening it. The issue is that the flatten to string and unflatten from string VIs don't seem to work with arrays and clusters on the NXT. It does work when running on the computer. We've tried arrays, clusters, clusters in arrays and arrays in clusters, none seem to work. Thinking it was something to do with reading the string from a file, we tried bypassing the file functionality, still not working. It does work with basic data types though, such as strings and numbers.
    No error is thrown from what we can tell. All you get is a blank data structure out of the unflatten VI.
    The program attached is a test program I've been working on to get this functionality to work. It will display the hex content of what is going into the file, coming out of the file, and then the resulting data from the unflatten string, as well as any errors that have been thrown. The data type we are using simulates what we would like to store. There is also a file length in and out counter. The out file is a little larger because the NXT write file VI adds a new line character on to the end (thus the use of the strip white space VI). This character was corrupting even basic data types saved to file.
    I would like to know if there is a problem with what we are doing, or if it is simply not possible to flatten arrays on the NXT. Please ask if you have any questions about the code. Thank you in advanced!
    Joshua
    Attachments:
    ReadableTest.vi ‏20 KB

    Hi jfireball,
    This is a very interesting situation. Take a look at what kbbersch said. I also urge you to post in the FTC Forums. You posted your question to the general LabVIEW forums, but by posting to the FTC Forums, you will have access to others that are using the NXT hardware.
    David B.
    Applications Engineer
    National Instruments

  • Working with Classes and Arrays

    hello to all,
    public class Store
    //private data
    private Person list[];
    private int count;
    private int maxSize;
    //constructor starts
    public Store(int max)
    count = Person.count(); //sets count to 0     
    maxSize = max;//maxSize is equals to max
    Person list[] = new Person[maxSize];
    }//end of store
    //constructor ends
    //accessor starts   
    public int getCount()
    for(int i=0; i<list.length; i++)
    int result = list;
    return result;
    }//returns the number of elements currently in store
    the code above is working with classes and some arrays
    what am trying to do is to display what the array holds
    and then i meet an error saying that
    INCOPATIBLE TYPES - FOUND PERSON BUT EXPECTED INT
    Please note that am new to this!
    Thank you in advanced!
    <img src="file:///C:/Documents%20and%20Settings/fh84/Desktop/untitled.JPG" alt="" />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    public class Store
        //private data
        private Person list[];
        private int count;
        private int maxSize;
    //constructor starts
        public Store(int max)
             count = Person.count(); //sets count to 0     
             maxSize = max;//maxSize is equals to max
            // Person list[] = new Person[maxSize];
             Person list[] = new Person[maxSize]; //set tne
        }//end of store
    //constructor ends
    //accessor starts  
        public int getCount()
            for(int i=0; i<list.length; i++)
                int  result = list;
    return result;
    am sending the code again                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for