protected ArrayStructure convert ( Array data , Section section ) throws IOException { ArrayStructure orgAS = ( ArrayStructure ) data ; if ( ! convertNeeded ( orgAS . getStructureMembers ( ) ) ) { // name, info change only convertMemberInfo ( orgAS . getStructureMembers ( ) ) ; return orgAS ; } // LOOK! converting to ArrayStructureMA // do any enum/scale/offset/missing/unsigned conversions ArrayStructure newAS = ArrayStructureMA . factoryMA ( orgAS ) ; for ( StructureMembers . Member m : newAS . getMembers ( ) ) { VariableEnhanced v2 = ( VariableEnhanced ) findVariable ( m . getName ( ) ) ; if ( ( v2 == null ) && ( orgVar != null ) ) // these are from orgVar - may have been renamed v2 = findVariableFromOrgName ( m . getName ( ) ) ; if ( v2 == null ) continue ; if ( v2 instanceof VariableDS ) { VariableDS vds = ( VariableDS ) v2 ; if ( vds . needConvert ( ) ) { Array mdata = newAS . extractMemberArray ( m ) ; // mdata has not yet been enhanced, but vds would *think* that it has been if we used the 1-arg version of // VariableDS.convert(). So, we use the 2-arg version to explicitly request enhancement. mdata = vds . convert ( mdata , vds . getEnhanceMode ( ) ) ; newAS . setMemberArray ( m , mdata ) ; } } else if ( v2 instanceof StructureDS ) { StructureDS innerStruct = ( StructureDS ) v2 ; if ( innerStruct . convertNeeded ( null ) ) { if ( innerStruct . getDataType ( ) == DataType . SEQUENCE ) { ArrayObject . D1 seqArray = ( ArrayObject . D1 ) newAS . extractMemberArray ( m ) ; ArrayObject . D1 newSeq = ( ArrayObject . D1 ) Array . factory ( DataType . SEQUENCE , new int [ ] { ( int ) seqArray . getSize ( ) } ) ; m . setDataArray ( newSeq ) ; // put back into member array // wrap each Sequence for ( int i = 0 ; i < seqArray . getSize ( ) ; i ++ ) { ArraySequence innerSeq = ( ArraySequence ) seqArray . get ( i ) ; // get old ArraySequence newSeq . set ( i , new SequenceConverter ( innerStruct , innerSeq ) ) ; // wrap in converter } // non-Sequence Structures } else { Array mdata = newAS . extractMemberArray ( m ) ; mdata = innerStruct . convert ( mdata , null ) ; newAS . setMemberArray ( m , mdata ) ; } } // always convert the inner StructureMembers innerStruct . convertMemberInfo ( m . getStructureMembers ( ) ) ; } } StructureMembers sm = newAS . getStructureMembers ( ) ; convertMemberInfo ( sm ) ; // check for variables that have been added by NcML for ( Variable v : getVariables ( ) ) { if ( ! varHasData ( v , sm ) ) { try { Variable completeVar = getParentGroup ( ) . findVariable ( v . getShortName ( ) ) ; // LOOK BAD Array mdata = completeVar . read ( section ) ; StructureMembers . Member m = sm . addMember ( v . getShortName ( ) , v . getDescription ( ) , v . getUnitsString ( ) , v . getDataType ( ) , v . getShape ( ) ) ; newAS . setMemberArray ( m , mdata ) ; } catch ( InvalidRangeException e ) { throw new IOException ( e . getMessage ( ) ) ; } } } return newAS ; }
3 ) variable with cached data added to StructureDS through NcML