dap4/d4cdm/src/main/java/dap4/cdm/nc2/DMRToCDM.java
protected void
    createVar(DapVariable dapvar, NetcdfFile ncfile,
              Group cdmgroup, Structure cdmparentstruct)
            throws DapException
    {
        Variable cdmvar = null;
	    DapType basetype = dapvar.getBaseType();
        if(basetype.isAtomic()) {
            DapVariable atomvar = (DapVariable) dapvar;
            cdmvar = new Variable(ncfile,
                    cdmgroup,
                    cdmparentstruct,
                    atomvar.getShortName());
            DataType cdmbasetype;
            if(basetype.isEnumType())
                cdmbasetype = CDMTypeFcns.enumTypeFor(basetype);
            else
                cdmbasetype = CDMTypeFcns.daptype2cdmtype(basetype);
            if(cdmbasetype == null)
                throw new DapException("Unknown basetype:" + basetype);
            cdmvar.setDataType(cdmbasetype);
            if(basetype.isEnumType()) {
                EnumTypedef cdmenum = (EnumTypedef) this.nodemap.get(basetype);
                if(cdmenum == null)
                    throw new DapException("Unknown enumeration type:" + basetype.toString());
                cdmvar.setEnumTypedef(cdmenum);
            }
            this.nodemap.put(cdmvar,dapvar);
        } else if(basetype.isStructType()) {
            DapStructure dapstruct = (DapStructure) basetype;
            Structure cdmstruct = new Structure(ncfile,
                    cdmgroup,
                    cdmparentstruct,
                    dapstruct.getShortName());
            cdmvar = cdmstruct;
            this.nodemap.put(cdmvar,dapvar);
            // Add the fields
            for(DapVariable field : dapstruct.getFields()) {
                createVar(field, ncfile, cdmgroup, cdmstruct);
            }
        } else if(basetype.isSeqType()) {
            DapSequence dapseq = (DapSequence) basetype;
            // In general one would convert the sequence
            // to a CDM sequence with vlen
            // so Sequence {...} s[d1]...[dn]
            // => Sequence {...} s[d1]...[dn]
            Sequence cdmseq = new Sequence(ncfile,
                    cdmgroup,
                    cdmparentstruct,
                    dapseq.getShortName());
            cdmvar = cdmseq;
            this.nodemap.put(cdmvar,dapvar);
            // Add the fields
            for(DapVariable field : dapseq.getFields()) {
                createVar(field, ncfile, cdmgroup, cdmseq);
            }
            // If the rank > 0, then add warning attribute
            if(dapvar.getRank() > 0) {
                List value = new ArrayList();
                value.add("CDM does not support Sequences with rank > 0");
                Attribute warning = new Attribute("_WARNING:", value);
                cdmvar.addAttribute(warning);
            }

        } else
            assert (false) : "Unknown variable sort: " + dapvar.getSort();
        int rank = dapvar.getRank();
        List<Dimension> cdmdims = new ArrayList<Dimension>(rank + 1); // +1 for vlen
        for(int i = 0; i < rank; i++) {
            DapDimension dim = dapvar.getDimension(i);
            Dimension cdmdim = createDimensionRef(dim, cdmgroup);
            cdmdims.add(cdmdim);
        }
        if(basetype.isSeqType()) {
            // Add the final vlen
            cdmdims.add(Dimension.VLEN);
        }
        cdmvar.setDimensions(cdmdims);
        // Create variable's attributes
        for(String key : dapvar.getAttributes().keySet()) {
            DapAttribute attr = dapvar.getAttributes().get(key);
            Attribute cdmattr = createAttribute(attr);
            cdmvar.addAttribute(cdmattr);
        }
        if(cdmparentstruct != null)
            cdmparentstruct.addMemberVariable(cdmvar);
        else if(cdmgroup != null)
            cdmgroup.addVariable(cdmvar);

    }
protected void
    createVar(DapVariable dapvar, NetcdfFile ncfile,
              Group cdmgroup, Structure cdmparentstruct)
            throws DapException
    {
        Variable cdmvar = null;
	    DapType basetype = dapvar.getBaseType();
        if(basetype.isAtomic()) {
            DapVariable atomvar = (DapVariable) dapvar;
            cdmvar = new Variable(ncfile,
                    cdmgroup,
                    cdmparentstruct,
                    atomvar.getShortName());
            DataType cdmbasetype;
            if(basetype.isEnumType())
                cdmbasetype = CDMTypeFcns.enumTypeFor(basetype);
            else
                cdmbasetype = CDMTypeFcns.daptype2cdmtype(basetype);
            if(cdmbasetype == null)
                throw new DapException("Unknown basetype:" + basetype);
            cdmvar.setDataType(cdmbasetype);
            if(basetype.isEnumType()) {
                EnumTypedef cdmenum = (EnumTypedef) this.nodemap.get(basetype);
                if(cdmenum == null)
                    throw new DapException("Unknown enumeration type:" + basetype.toString());
                cdmvar.setEnumTypedef(cdmenum);
            }
            this.nodemap.put(cdmvar,dapvar);
        } else if(basetype.isStructType()) {
            DapStructure dapstruct = (DapStructure) basetype;
            Structure cdmstruct = new Structure(ncfile,
                    cdmgroup,
                    cdmparentstruct,
                    dapstruct.getShortName());
            cdmvar = cdmstruct;
            this.nodemap.put(cdmvar,dapvar);
            // Add the fields
            for(DapVariable field : dapstruct.getFields()) {
                createVar(field, ncfile, cdmgroup, cdmstruct);
            }
        } else if(basetype.isSeqType()) {
            DapSequence dapseq = (DapSequence) basetype;
            // In general one would convert the sequence
            // to a CDM sequence with vlen
            // so Sequence {...} s[d1]...[dn]
            // => Sequence {...} s[d1]...[dn]
            Sequence cdmseq = new Sequence(ncfile,
                    cdmgroup,
                    cdmparentstruct,
                    dapseq.getShortName());
            cdmvar = cdmseq;
            this.nodemap.put(cdmvar,dapvar);
            // Add the fields
            for(DapVariable field : dapseq.getFields()) {
                createVar(field, ncfile, cdmgroup, cdmseq);
            }
            // If the rank > 0, then add warning attribute
            if(dapvar.getRank() > 0) {
                List value = new ArrayList();
                value.add("CDM does not support Sequences with rank > 0");
                Attribute warning = new Attribute("_WARNING:", value);
                cdmvar.addAttribute(warning);
            }

        } else
            assert (false) : "Unknown variable sort: " + dapvar.getSort();
        int rank = dapvar.getRank();
        List<Dimension> cdmdims = new ArrayList<Dimension>(rank + 1); // +1 for vlen
        for(int i = 0; i < rank; i++) {
            DapDimension dim = dapvar.getDimension(i);
            Dimension cdmdim = createDimensionRef(dim, cdmgroup);
            cdmdims.add(cdmdim);
        }
        if(basetype.isSeqType()) {
            // Add the final vlen
            cdmdims.add(Dimension.VLEN);
        }
        cdmvar.setDimensions(cdmdims);
        // Create variable's attributes
        for(String key : dapvar.getAttributes().keySet()) {
            DapAttribute attr = dapvar.getAttributes().get(key);
            Attribute cdmattr = createAttribute(attr);
            cdmvar.addAttribute(cdmattr);
        }
        if(cdmparentstruct != null)
            cdmparentstruct.addMemberVariable(cdmvar);
        else if(cdmgroup != null)
            cdmgroup.addVariable(cdmvar);

    }
Create a variable or field

@param dapvar          the template variable
@param ncfile          the containing NetcdfFile (really NetcdfDataset)
@param cdmgroup        the containing CDM group
@param cdmparentstruct the containing CDM structure (or null)