cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3channelWriter.java
public void writeDataAll(WritableByteChannel channel) throws IOException, InvalidRangeException {
    for (Vinfo vinfo : vinfoList) {
      if (!vinfo.isRecord) {
        Variable v = vinfo.v;
        // assert filePos == vinfo.offset;
        //if (debugPos) System.out.println(" writing at "+filePos+" should be "+vinfo.offset+" "+v.getFullName());
        int nbytes = (int) v.readToByteChannel(v.getShapeAsSection(), channel);
        filePos += nbytes;
        filePos += pad(channel, nbytes);
        if (debugPos) System.out.printf(" read=%d vinfo=%s%n", nbytes, vinfo);
      }
    }

    // must use record dimension if it exists+
    boolean useRecordDimension = ncfile.hasUnlimitedDimension();
    if (useRecordDimension) {
      ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

      Structure recordVar = (Structure) ncfile.findVariable("record");
      Section section = new Section().appendRange(null);

      long bytesDone = 0;
      long done = 0;
      long nrecs = (int) recordVar.getSize();
      int structureSize = recordVar.getElementSize();
      int readAtaTime = Math.max( 10, buffer_size / structureSize);

      for (int count = 0; count < nrecs; count+=readAtaTime) {
        long last = Math.min(nrecs, done+readAtaTime); // dont go over nrecs
        int need = (int) (last - done); // how many to read this time

        section.setRange(0, new Range(count, count+need-1));
        try {
          bytesDone += recordVar.readToByteChannel( section, channel);
          done += need;
        } catch (InvalidRangeException e) {
          e.printStackTrace();
          break;
        }
      }
      assert done == nrecs;
      bytesDone /= 1000 * 1000;
      if (debugWrite) System.out.println("write record var; total = " + bytesDone + " Mbytes # recs=" + done);

      // remove the record structure this is rather fishy, perhaps better to leave it
      ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE);
      ncfile.finish();
    }

  }
public void writeDataAll(WritableByteChannel channel) throws IOException, InvalidRangeException {
    for (Vinfo vinfo : vinfoList) {
      if (!vinfo.isRecord) {
        Variable v = vinfo.v;
        // assert filePos == vinfo.offset;
        //if (debugPos) System.out.println(" writing at "+filePos+" should be "+vinfo.offset+" "+v.getFullName());
        int nbytes = (int) v.readToByteChannel(v.getShapeAsSection(), channel);
        filePos += nbytes;
        filePos += pad(channel, nbytes);
        if (debugPos) System.out.printf(" read=%d vinfo=%s%n", nbytes, vinfo);
      }
    }

    // must use record dimension if it exists+
    boolean useRecordDimension = ncfile.hasUnlimitedDimension();
    if (useRecordDimension) {
      ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

      Structure recordVar = (Structure) ncfile.findVariable("record");
      Section section = new Section().appendRange(null);

      long bytesDone = 0;
      long done = 0;
      long nrecs = (int) recordVar.getSize();
      int structureSize = recordVar.getElementSize();
      int readAtaTime = Math.max( 10, buffer_size / structureSize);

      for (int count = 0; count < nrecs; count+=readAtaTime) {
        long last = Math.min(nrecs, done+readAtaTime); // dont go over nrecs
        int need = (int) (last - done); // how many to read this time

        section.setRange(0, new Range(count, count+need-1));
        try {
          bytesDone += recordVar.readToByteChannel( section, channel);
          done += need;
        } catch (InvalidRangeException e) {
          e.printStackTrace();
          break;
        }
      }
      assert done == nrecs;
      bytesDone /= 1000 * 1000;
      if (debugWrite) System.out.println("write record var; total = " + bytesDone + " Mbytes # recs=" + done);

      // remove the record structure this is rather fishy, perhaps better to leave it
      ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE);
      ncfile.finish();
    }

  }
public void writeDataAll ( WritableByteChannel channel ) throws IOException , InvalidRangeException { for ( Vinfo vinfo : vinfoList ) { if ( ! vinfo . isRecord ) { Variable v = vinfo . v ; // assert filePos == vinfo.offset; //if (debugPos) System.out.println(" writing at "+filePos+" should be "+vinfo.offset+" "+v.getFullName()); int nbytes = ( int ) v . readToByteChannel ( v . getShapeAsSection ( ) , channel ) ; filePos += nbytes ; filePos += pad ( channel , nbytes ) ; if ( debugPos ) System . out . printf ( " read=%d vinfo=%s%n" , nbytes , vinfo ) ; } } // must use record dimension if it exists+ boolean useRecordDimension = ncfile . hasUnlimitedDimension ( ) ; if ( useRecordDimension ) { ncfile . sendIospMessage ( NetcdfFile . IOSP_MESSAGE_ADD_RECORD_STRUCTURE ) ; Structure recordVar = ( Structure ) ncfile . findVariable ( "record" ) ; Section section = new Section ( ) . appendRange ( null ) ; long bytesDone = 0 ; long done = 0 ; long nrecs = ( int ) recordVar . getSize ( ) ; int structureSize = recordVar . getElementSize ( ) ; int readAtaTime = Math . max ( 10 , buffer_size / structureSize ) ; for ( int count = 0 ; count < nrecs ; count += readAtaTime ) { long last = Math . min ( nrecs , done + readAtaTime ) ; // dont go over nrecs int need = ( int ) ( last - done ) ; // how many to read this time section . setRange ( 0 , new Range ( count , count + need - 1 ) ) ; try { bytesDone += recordVar . readToByteChannel ( section , channel ) ; done += need ; } catch ( InvalidRangeException e ) { e . printStackTrace ( ) ; break ; } } assert done == nrecs ; bytesDone /= 1000 * 1000 ; if ( debugWrite ) System . out . println ( "write record var; total = " + bytesDone + " Mbytes # recs=" + done ) ; // remove the record structure this is rather fishy, perhaps better to leave it ncfile . sendIospMessage ( NetcdfFile . IOSP_MESSAGE_REMOVE_RECORD_STRUCTURE ) ; ncfile . finish ( ) ; } }
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////