opendap/src/main/java/opendap/servlet/ascii/asciiArray.java
private int asciiArray(PrintWriter os, boolean addName, String label, int index, int dims, int shape[],
                           int offset) {

        //os.println("\n\n");
        //os.println("\tdims:   " + dims);
        //os.println("\toffset: " + offset);
        //os.println("\tshape["+offset+"]: " + shape[offset]);
        //os.println("\tindex: " + index);
        //os.println("\n");

        if (dims == 1) {

            if (addName)
                os.print(label);

            for (int i = 0; i < shape[offset]; i++) {


                PrimitiveVector pv = getPrimitiveVector();

                if (pv instanceof BaseTypePrimitiveVector) {

                    BaseType bt = ((BaseTypePrimitiveVector) pv).getValue(index++);

                    if (i > 0) {
                        if (bt instanceof DString)
                            os.print(", ");
                        else
                            os.println("");
                    }
                    ((toASCII) bt).toASCII(os, false, null, false);


                } else {

                    if (i > 0)
                        os.print(", ");
                    pv.printSingleVal(os, index++);
                }


            }
            if (addName) os.print("\n");

            return index;
        } else {
            for (int i = 0; i < shape[offset]; i++) {
                StringBuilder s = new StringBuilder();
                s.append(label);
                s.append("[");
                s.append(i);
                s.append("]");
                if ((dims - 1) == 1)
                    s.append(", ");
                index = asciiArray(os, addName, s.toString(), index, dims - 1, shape, offset + 1);
            }
            return index;
        }
    }
private int asciiArray(PrintWriter os, boolean addName, String label, int index, int dims, int shape[],
                           int offset) {

        //os.println("\n\n");
        //os.println("\tdims:   " + dims);
        //os.println("\toffset: " + offset);
        //os.println("\tshape["+offset+"]: " + shape[offset]);
        //os.println("\tindex: " + index);
        //os.println("\n");

        if (dims == 1) {

            if (addName)
                os.print(label);

            for (int i = 0; i < shape[offset]; i++) {


                PrimitiveVector pv = getPrimitiveVector();

                if (pv instanceof BaseTypePrimitiveVector) {

                    BaseType bt = ((BaseTypePrimitiveVector) pv).getValue(index++);

                    if (i > 0) {
                        if (bt instanceof DString)
                            os.print(", ");
                        else
                            os.println("");
                    }
                    ((toASCII) bt).toASCII(os, false, null, false);


                } else {

                    if (i > 0)
                        os.print(", ");
                    pv.printSingleVal(os, index++);
                }


            }
            if (addName) os.print("\n");

            return index;
        } else {
            for (int i = 0; i < shape[offset]; i++) {
                StringBuilder s = new StringBuilder();
                s.append(label);
                s.append("[");
                s.append(i);
                s.append("]");
                if ((dims - 1) == 1)
                    s.append(", ");
                index = asciiArray(os, addName, s.toString(), index, dims - 1, shape, offset + 1);
            }
            return index;
        }
    }
Print an array. This is a private member function.

@param os     is the stream used for writing
@param index  is the index of VEC to start printing
@param dims   is the number of dimensions in the array
@param shape  holds the size of the dimensions of the array.
@param offset holds the current offset into the shape array.
@return the number of elements written.