legacy/src/main/java/ucar/nc2/dt/point/WriterStationObsDataset.java
private void write(StationObsDataset sobsDataset) throws IOException {
    createGlobalAttributes();
    createStations(sobsDataset.getStations());

    ncfile.addGlobalAttribute("time_coverage_start", dateFormatter.toDateTimeStringISO(sobsDataset.getStartDate()));
    ncfile.addGlobalAttribute("time_coverage_end", dateFormatter.toDateTimeStringISO(sobsDataset.getEndDate()));

    createDataVariables(sobsDataset.getDataVariables());

    // global attributes
    List gatts = sobsDataset.getGlobalAttributes();
    for (int i = 0; i < gatts.size(); i++) {
      Attribute att = (Attribute) gatts.get(i);
      ncfile.addGlobalAttribute(att);
    }

    // done with define mode
    ncfile.create();

    // write out the station info
    writeStationData(sobsDataset.getStations());

    // now write the observations
    if (! (Boolean) ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE))
      throw new IllegalStateException("can't add record variable");

    int[] origin = new int[1];
    int[] originTime = new int[2];
    int recno = 0;
    ArrayStructureW sArray = null;
    ArrayObject.D1 timeArray = new ArrayObject.D1(DataType.STRING, String.class, false, 1);

    DataIterator diter = sobsDataset.getDataIterator(1000 * 1000);
    while (diter.hasNext()) {
      StationObsDatatype sobs = (StationObsDatatype) diter.nextData();
      StructureData recordData = sobs.getData();

      // needs to be wrapped as an ArrayStructure, even though we are only writing one at a time.
      if (sArray == null)
        sArray = new ArrayStructureW(recordData.getStructureMembers(), new int[]{1});
      sArray.setStructureData(recordData, 0);

      // date is handled specially
      timeArray.set(0, dateFormatter.toDateTimeStringISO(sobs.getObservationTimeAsDate()));

      // write the recno record
      origin[0] = recno;
      originTime[0] = recno;
      try {
        ncfile.write("record", origin, sArray);
        ncfile.writeStringData(timeName, originTime, timeArray);

      } catch (InvalidRangeException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }
      recno++;
    }

    ncfile.close();
  }
private void write(StationObsDataset sobsDataset) throws IOException {
    createGlobalAttributes();
    createStations(sobsDataset.getStations());

    ncfile.addGlobalAttribute("time_coverage_start", dateFormatter.toDateTimeStringISO(sobsDataset.getStartDate()));
    ncfile.addGlobalAttribute("time_coverage_end", dateFormatter.toDateTimeStringISO(sobsDataset.getEndDate()));

    createDataVariables(sobsDataset.getDataVariables());

    // global attributes
    List gatts = sobsDataset.getGlobalAttributes();
    for (int i = 0; i < gatts.size(); i++) {
      Attribute att = (Attribute) gatts.get(i);
      ncfile.addGlobalAttribute(att);
    }

    // done with define mode
    ncfile.create();

    // write out the station info
    writeStationData(sobsDataset.getStations());

    // now write the observations
    if (! (Boolean) ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE))
      throw new IllegalStateException("can't add record variable");

    int[] origin = new int[1];
    int[] originTime = new int[2];
    int recno = 0;
    ArrayStructureW sArray = null;
    ArrayObject.D1 timeArray = new ArrayObject.D1(DataType.STRING, String.class, false, 1);

    DataIterator diter = sobsDataset.getDataIterator(1000 * 1000);
    while (diter.hasNext()) {
      StationObsDatatype sobs = (StationObsDatatype) diter.nextData();
      StructureData recordData = sobs.getData();

      // needs to be wrapped as an ArrayStructure, even though we are only writing one at a time.
      if (sArray == null)
        sArray = new ArrayStructureW(recordData.getStructureMembers(), new int[]{1});
      sArray.setStructureData(recordData, 0);

      // date is handled specially
      timeArray.set(0, dateFormatter.toDateTimeStringISO(sobs.getObservationTimeAsDate()));

      // write the recno record
      origin[0] = recno;
      originTime[0] = recno;
      try {
        ncfile.write("record", origin, sArray);
        ncfile.writeStringData(timeName, originTime, timeArray);

      } catch (InvalidRangeException e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }
      recno++;
    }

    ncfile.close();
  }
private void write ( StationObsDataset sobsDataset ) throws IOException { createGlobalAttributes ( ) ; createStations ( sobsDataset . getStations ( ) ) ; ncfile . addGlobalAttribute ( "time_coverage_start" , dateFormatter . toDateTimeStringISO ( sobsDataset . getStartDate ( ) ) ) ; ncfile . addGlobalAttribute ( "time_coverage_end" , dateFormatter . toDateTimeStringISO ( sobsDataset . getEndDate ( ) ) ) ; createDataVariables ( sobsDataset . getDataVariables ( ) ) ; // global attributes List gatts = sobsDataset . getGlobalAttributes ( ) ; for ( int i = 0 ; i < gatts . size ( ) ; i ++ ) { Attribute att = ( Attribute ) gatts . get ( i ) ; ncfile . addGlobalAttribute ( att ) ; } // done with define mode ncfile . create ( ) ; // write out the station info writeStationData ( sobsDataset . getStations ( ) ) ; // now write the observations if ( ! ( Boolean ) ncfile . sendIospMessage ( NetcdfFile . IOSP_MESSAGE_ADD_RECORD_STRUCTURE ) ) throw new IllegalStateException ( "can't add record variable" ) ; int [ ] origin = new int [ 1 ] ; int [ ] originTime = new int [ 2 ] ; int recno = 0 ; ArrayStructureW sArray = null ; ArrayObject . D1 timeArray = new ArrayObject . D1 ( DataType . STRING , String . class , false , 1 ) ; DataIterator diter = sobsDataset . getDataIterator ( 1000 * 1000 ) ; while ( diter . hasNext ( ) ) { StationObsDatatype sobs = ( StationObsDatatype ) diter . nextData ( ) ; StructureData recordData = sobs . getData ( ) ; // needs to be wrapped as an ArrayStructure, even though we are only writing one at a time. if ( sArray == null ) sArray = new ArrayStructureW ( recordData . getStructureMembers ( ) , new int [ ] { 1 } ) ; sArray . setStructureData ( recordData , 0 ) ; // date is handled specially timeArray . set ( 0 , dateFormatter . toDateTimeStringISO ( sobs . getObservationTimeAsDate ( ) ) ) ; // write the recno record origin [ 0 ] = recno ; originTime [ 0 ] = recno ; try { ncfile . write ( "record" , origin , sArray ) ; ncfile . writeStringData ( timeName , originTime , timeArray ) ; } catch ( InvalidRangeException e ) { e . printStackTrace ( ) ; throw new IllegalStateException ( e ) ; } recno ++ ; } ncfile . close ( ) ; }
not tested
not tested