This method writes assignment data to a Planner file.
426847
private void writeAssignments()
   {
      Allocations allocations = m_factory.createAllocations();
      m_plannerProject.setAllocations(allocations);

      List<Allocation> allocationList = allocations.getAllocation();
      for (ResourceAssignment mpxjAssignment : m_projectFile.getResourceAssignments())
      {
         Allocation plannerAllocation = m_factory.createAllocation();
         allocationList.add(plannerAllocation);

         plannerAllocation.setTaskId(getIntegerString(mpxjAssignment.getTask().getUniqueID()));
         plannerAllocation.setResourceId(getIntegerString(mpxjAssignment.getResourceUniqueID()));
         plannerAllocation.setUnits(getIntegerString(mpxjAssignment.getUnits()));

         m_eventManager.fireAssignmentWrittenEvent(mpxjAssignment);
      }
   }
160862
def write_bus_data(self, file):
        
        bus_sheet = self.book.add_sheet("Buses")

        for i, bus in enumerate(self.case.buses):
            for j, attr in enumerate(BUS_ATTRS):
                bus_sheet.write(i, j, getattr(bus, attr))
785054
private void writeTask(Task mpxjTask, List<net.sf.mpxj.planner.schema.Task> taskList) throws JAXBException
   {
      net.sf.mpxj.planner.schema.Task plannerTask = m_factory.createTask();
      taskList.add(plannerTask);
      plannerTask.setEnd(getDateTimeString(mpxjTask.getFinish()));
      plannerTask.setId(getIntegerString(mpxjTask.getUniqueID()));
      plannerTask.setName(getString(mpxjTask.getName()));
      plannerTask.setNote(mpxjTask.getNotes());
      plannerTask.setPercentComplete(getIntegerString(mpxjTask.getPercentageWorkComplete()));
      plannerTask.setPriority(mpxjTask.getPriority() == null ? null : getIntegerString(mpxjTask.getPriority().getValue() * 10));
      plannerTask.setScheduling(getScheduling(mpxjTask.getType()));
      plannerTask.setStart(getDateTimeString(DateHelper.getDayStartDate(mpxjTask.getStart())));
      if (mpxjTask.getMilestone())
      {
         plannerTask.setType("milestone");
      }
      else
      {
         plannerTask.setType("normal");
      }
      plannerTask.setWork(getDurationString(mpxjTask.getWork()));
      plannerTask.setWorkStart(getDateTimeString(mpxjTask.getStart()));

      ConstraintType mpxjConstraintType = mpxjTask.getConstraintType();
      if (mpxjConstraintType != ConstraintType.AS_SOON_AS_POSSIBLE)
      {
         Constraint plannerConstraint = m_factory.createConstraint();
         plannerTask.setConstraint(plannerConstraint);
         if (mpxjConstraintType == ConstraintType.START_NO_EARLIER_THAN)
         {
            plannerConstraint.setType("start-no-earlier-than");
         }
         else
         {
            if (mpxjConstraintType == ConstraintType.MUST_START_ON)
            {
               plannerConstraint.setType("must-start-on");
            }
         }

         plannerConstraint.setTime(getDateTimeString(mpxjTask.getConstraintDate()));
      }

      //
      // Write predecessors
      //
      writePredecessors(mpxjTask, plannerTask);

      m_eventManager.fireTaskWrittenEvent(mpxjTask);

      //
      // Write child tasks
      //
      List<net.sf.mpxj.planner.schema.Task> childTaskList = plannerTask.getTask();
      for (Task task : mpxjTask.getChildTasks())
      {
         writeTask(task, childTaskList);
      }
   }
915654
def write(self, data):
        """"""
        cnpj, data = data

        path = os.path.join(self.output, '%s.json' % cnpj)
        with open(path, 'w') as f:
            json.dump(data, f, encoding='utf-8')
750075
def _write(self, session, openFile, replaceParamFile):
        
        # Enforce cards that must be written in certain order
        PRIORITY_CARDS = ('WMS', 'MASK_WATERSHED', 'REPLACE_LINE',
                          'REPLACE_PARAMS', 'REPLACE_VALS', 'REPLACE_FOLDER')

        filename = os.path.split(openFile.name)[1]
        name = filename.split('.')[0]

        # Write lines
        openFile.write('GSSHAPROJECT\n')

        # Write priority lines
        for card_key in PRIORITY_CARDS:
            card = self.getCard(card_key)

            # Write the card
            if card is not None:
                openFile.write(card.write(originalPrefix=self.name, newPrefix=name))

        # Initiate write on each ProjectCard that belongs to this ProjectFile
        for card in self.projectCards:
            if card.name not in PRIORITY_CARDS:
                openFile.write(card.write(originalPrefix=self.name, newPrefix=name))
455928
private void write(FieldInfos fieldInfos, Fields fields) {
    IndexOutput outField;
    IndexOutput outDoc;
    IndexOutput outIndexDocId;
    IndexOutput outIndexObjectId;
    IndexOutput outIndexObjectPosition;
    IndexOutput outIndexObjectParent;
    IndexOutput outTerm;
    IndexOutput outObject;
    IndexOutput outPrefix;
    IndexOutput outTmpDoc;
    IndexOutput outTmpField;
    HashSet<Closeable> closeables = new HashSet<>();
    // prefix stats
    intersectingPrefixes = new HashMap<>();
    singlePositionPrefix = new HashMap<>();
    multiplePositionPrefix = new HashMap<>();
    setPositionPrefix = new HashMap<>();
    prefixReferenceIndex = new HashMap<>();
    prefixIdIndex = new HashMap<>();
    // temporary temporary index in memory for doc
    SortedMap<Integer, Long> memoryIndexTemporaryObject = new TreeMap<>();
    // create (backwards) chained new temporary index docs
    SortedMap<Integer, Long> memoryTmpDocChainList = new TreeMap<>();
    // list of objectIds and references to objects
    SortedMap<Integer, Long> memoryIndexDocList = new TreeMap<>();

    try {
      // create file tmpDoc
      closeables.add(outTmpDoc = state.directory
          .createOutput(mtasTmpDocFileName, state.context));
      // create file tmpField
      closeables.add(outTmpField = state.directory
          .createOutput(mtasTmpFieldFileName, state.context));
      // create file indexDoc
      closeables.add(outDoc = state.directory.createOutput(mtasDocFileName,
          state.context));
      CodecUtil.writeIndexHeader(outDoc, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outDoc.writeString(delegatePostingsFormatName);
      // create file indexDocId
      closeables.add(outIndexDocId = state.directory
          .createOutput(mtasIndexDocIdFileName, state.context));
      CodecUtil.writeIndexHeader(outIndexDocId, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outIndexDocId.writeString(delegatePostingsFormatName);
      // create file indexObjectId
      closeables.add(outIndexObjectId = state.directory
          .createOutput(mtasIndexObjectIdFileName, state.context));
      CodecUtil.writeIndexHeader(outIndexObjectId, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outIndexObjectId.writeString(delegatePostingsFormatName);
      // create file indexObjectPosition
      closeables.add(outIndexObjectPosition = state.directory
          .createOutput(mtasIndexObjectPositionFileName, state.context));
      CodecUtil.writeIndexHeader(outIndexObjectPosition, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outIndexObjectPosition.writeString(delegatePostingsFormatName);
      // create file indexObjectParent
      closeables.add(outIndexObjectParent = state.directory
          .createOutput(mtasIndexObjectParentFileName, state.context));
      CodecUtil.writeIndexHeader(outIndexObjectParent, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outIndexObjectParent.writeString(delegatePostingsFormatName);
      // create file term
      closeables.add(outTerm = state.directory.createOutput(mtasTermFileName,
          state.context));
      CodecUtil.writeIndexHeader(outTerm, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outTerm.writeString(delegatePostingsFormatName);
      // create file prefix
      closeables.add(outPrefix = state.directory
          .createOutput(mtasPrefixFileName, state.context));
      CodecUtil.writeIndexHeader(outPrefix, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outPrefix.writeString(delegatePostingsFormatName);
      // create file object
      closeables.add(outObject = state.directory
          .createOutput(mtasObjectFileName, state.context));
      CodecUtil.writeIndexHeader(outObject, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outObject.writeString(delegatePostingsFormatName);
      // For each field
      for (String field : fields) {
        Terms terms = fields.terms(field);
        if (terms == null) {
          continue;
        } else {
          // new temporary object storage for this field
          IndexOutput outTmpObject = state.directory
              .createOutput(mtasTmpObjectFileName, state.context);
          closeables.add(outTmpObject);
          // new temporary index docs for this field
          IndexOutput outTmpDocs = state.directory
              .createOutput(mtasTmpDocsFileName, state.context);
          closeables.add(outTmpDocs);
          // get fieldInfo
          FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
          // get properties terms
          boolean hasPositions = terms.hasPositions();
          boolean hasFreqs = terms.hasFreqs();
          boolean hasPayloads = fieldInfo.hasPayloads();
          boolean hasOffsets = terms.hasOffsets();
          // register references
          Long smallestTermFilepointer = outTerm.getFilePointer();
          Long smallestPrefixFilepointer = outPrefix.getFilePointer();
          int termCounter = 0;
          // only if freqs, positions and payload available
          if (hasFreqs && hasPositions && hasPayloads) {
            // compute flags
            int flags = PostingsEnum.POSITIONS | PostingsEnum.PAYLOADS;
            if (hasOffsets) {
              flags = flags | PostingsEnum.OFFSETS;
            }
            // get terms
            TermsEnum termsEnum = terms.iterator();
            PostingsEnum postingsEnum = null;
            // for each term in field
            while (true) {
              BytesRef term = termsEnum.next();
              if (term == null) {
                break;
              }
              // store term and get ref
              Long termRef = outTerm.getFilePointer();
              outTerm.writeString(term.utf8ToString());
              termCounter++;
              // get postings
              postingsEnum = termsEnum.postings(postingsEnum, flags);
              // for each doc in field+term
              while (true) {
                Integer docId = postingsEnum.nextDoc();
                if (docId.equals(DocIdSetIterator.NO_MORE_DOCS)) {
                  break;
                }
                int freq = postingsEnum.freq();
                // temporary storage objects and temporary index in memory for
                // doc
                memoryIndexTemporaryObject.clear();
                Long offsetFilePointerTmpObject = outTmpObject.getFilePointer();
                for (int i = 0; i < freq; i++) {
                  Long currentFilePointerTmpObject = outTmpObject
                      .getFilePointer();
                  Integer mtasId;
                  int position = postingsEnum.nextPosition();
                  BytesRef payload = postingsEnum.getPayload();
                  if (hasOffsets) {
                    mtasId = createObjectAndRegisterPrefix(field, outTmpObject,
                        term, termRef, position, payload,
                        postingsEnum.startOffset(), postingsEnum.endOffset(),
                        outPrefix);
                  } else {
                    mtasId = createObjectAndRegisterPrefix(field, outTmpObject,
                        term, termRef, position, payload, outPrefix);
                  }
                  if (mtasId != null) {
                    assert !memoryIndexTemporaryObject.containsKey(
                        mtasId) : "mtasId should be unique in this selection";
                    memoryIndexTemporaryObject.put(mtasId,
                        currentFilePointerTmpObject);
                  }
                } // end loop positions
                // store temporary index for this doc
                if (memoryIndexTemporaryObject.size() > 0) {
                  // docId for this part
                  outTmpDocs.writeVInt(docId);
                  // number of objects/tokens in this part
                  outTmpDocs.writeVInt(memoryIndexTemporaryObject.size());
                  // offset to be used for references
                  outTmpDocs.writeVLong(offsetFilePointerTmpObject);
                  // loop over tokens
                  for (Entry<Integer, Long> entry : memoryIndexTemporaryObject
                      .entrySet()) {
                    // mtasId object
                    outTmpDocs.writeVInt(entry.getKey());
                    // reference object
                    outTmpDocs.writeVLong(
                        (entry.getValue() - offsetFilePointerTmpObject));
                  }
                }
                // clean up
                memoryIndexTemporaryObject.clear();
              } // end loop docs
            } // end loop terms
            // set fieldInfo
            fieldInfos.fieldInfo(field).putAttribute(
                MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_SINGLE_POSITION,
                getPrefixStatsSinglePositionPrefixAttribute(field));
            fieldInfos.fieldInfo(field).putAttribute(
                MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_MULTIPLE_POSITION,
                getPrefixStatsMultiplePositionPrefixAttribute(field));
            fieldInfos.fieldInfo(field).putAttribute(
                MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_SET_POSITION,
                getPrefixStatsSetPositionPrefixAttribute(field));
          } // end processing field with freqs, positions and payload
          // close temporary object storage and index docs
          outTmpObject.close();
          closeables.remove(outTmpObject);
          outTmpDocs.close();
          closeables.remove(outTmpDocs);

          // create (backwards) chained new temporary index docs
          IndexInput inTmpDocs = state.directory.openInput(mtasTmpDocsFileName,
              state.context);
          closeables.add(inTmpDocs);
          IndexOutput outTmpDocsChained = state.directory
              .createOutput(mtasTmpDocsChainedFileName, state.context);
          closeables.add(outTmpDocsChained);
          memoryTmpDocChainList.clear();
          while (true) {
            try {
              Long currentFilepointer = outTmpDocsChained.getFilePointer();
              // copy docId
              int docId = inTmpDocs.readVInt();
              outTmpDocsChained.writeVInt(docId);
              // copy size
              int size = inTmpDocs.readVInt();
              outTmpDocsChained.writeVInt(size);
              // offset references
              outTmpDocsChained.writeVLong(inTmpDocs.readVLong());
              for (int t = 0; t < size; t++) {
                outTmpDocsChained.writeVInt(inTmpDocs.readVInt());
                outTmpDocsChained.writeVLong(inTmpDocs.readVLong());
              }
              // set back reference to part with same docId
              if (memoryTmpDocChainList.containsKey(docId)) {
                // reference to previous
                outTmpDocsChained.writeVLong(memoryTmpDocChainList.get(docId));
              } else {
                // self reference indicates end of chain
                outTmpDocsChained.writeVLong(currentFilepointer);
              }
              // update temporary index in memory
              memoryTmpDocChainList.put(docId, currentFilepointer);
            } catch (IOException ex) {
              log.debug(ex);
              break;
            }
          }
          outTmpDocsChained.close();
          closeables.remove(outTmpDocsChained);
          inTmpDocs.close();
          closeables.remove(inTmpDocs);
          state.directory.deleteFile(mtasTmpDocsFileName);

          // set reference to tmpDoc in Field
          if (memoryTmpDocChainList.size() > 0) {
            outTmpField.writeString(field);
            outTmpField.writeVLong(outTmpDoc.getFilePointer());
            outTmpField.writeVInt(memoryTmpDocChainList.size());
            outTmpField.writeVLong(smallestTermFilepointer);
            outTmpField.writeVInt(termCounter);
            outTmpField.writeVLong(smallestPrefixFilepointer);
            outTmpField.writeVInt(prefixReferenceIndex.get(field).size());
            // fill indexDoc
            IndexInput inTmpDocsChained = state.directory
                .openInput(mtasTmpDocsChainedFileName, state.context);
            closeables.add(inTmpDocsChained);
            IndexInput inTmpObject = state.directory
                .openInput(mtasTmpObjectFileName, state.context);
            closeables.add(inTmpObject);
            for (Entry<Integer, Long> entry : memoryTmpDocChainList
                .entrySet()) {
              Integer docId = entry.getKey();
              Long currentFilePointer;
              Long newFilePointer;
              // list of objectIds and references to objects
              memoryIndexDocList.clear();
              // construct final object + indexObjectId for docId
              currentFilePointer = entry.getValue();
              // collect objects for document
              tokenStatsMinPos = null;
              tokenStatsMaxPos = null;
              tokenStatsNumber = 0;
              while (true) {
                inTmpDocsChained.seek(currentFilePointer);
                Integer docIdPart = inTmpDocsChained.readVInt();
                assert docIdPart.equals(
                    docId) : "conflicting docId in reference to temporaryIndexDocsChained";
                // number of objects/tokens in part
                int size = inTmpDocsChained.readVInt();
                long offsetFilePointerTmpObject = inTmpDocsChained.readVLong();
                assert size > 0 : "number of objects/tokens in part cannot be "
                    + size;
                for (int t = 0; t < size; t++) {
                  int mtasId = inTmpDocsChained.readVInt();
                  Long tmpObjectRef = inTmpDocsChained.readVLong()
                      + offsetFilePointerTmpObject;
                  assert !memoryIndexDocList.containsKey(
                      mtasId) : "mtasId should be unique in this selection";
                  // initially, store ref to tmpObject
                  memoryIndexDocList.put(mtasId, tmpObjectRef);
                }
                // reference to next part
                newFilePointer = inTmpDocsChained.readVLong();
                if (newFilePointer.equals(currentFilePointer)) {
                  break; // end of chained parts
                } else {
                  currentFilePointer = newFilePointer;
                }
              }
              // now create new objects, sorted by mtasId
              Long smallestObjectFilepointer = outObject.getFilePointer();
              for (Entry<Integer, Long> objectEntry : memoryIndexDocList
                  .entrySet()) {
                int mtasId = objectEntry.getKey();
                Long tmpObjectRef = objectEntry.getValue();
                Long objectRef = outObject.getFilePointer();
                copyObjectAndUpdateStats(mtasId, inTmpObject, tmpObjectRef,
                    outObject);
                // update with new ref
                memoryIndexDocList.put(mtasId, objectRef);
              }
              // check mtasIds properties
              assert memoryIndexDocList.firstKey()
                  .equals(0) : "first mtasId should not be "
                      + memoryIndexDocList.firstKey();
              assert (1 + memoryIndexDocList.lastKey()
                  - memoryIndexDocList.firstKey()) == memoryIndexDocList
                      .size() : "missing mtasId";
              assert tokenStatsNumber.equals(memoryIndexDocList
                  .size()) : "incorrect number of items in tokenStats";

              // store item in tmpDoc
              outTmpDoc.writeVInt(docId);
              outTmpDoc.writeVLong(outIndexObjectId.getFilePointer());

              int mtasId = 0;
              // compute linear approximation (least squares method, integer
              // constants)
              long tmpN = memoryIndexDocList.size();
              long tmpSumY = 0;
              long tmpSumXY = 0;
              long tmpSumX = 0;
              long tmpSumXX = 0;
              for (Entry<Integer, Long> objectEntry : memoryIndexDocList
                  .entrySet()) {
                assert objectEntry.getKey()
                    .equals(mtasId) : "unexpected mtasId";
                tmpSumY += objectEntry.getValue();
                tmpSumX += mtasId;
                tmpSumXY += mtasId * objectEntry.getValue();
                tmpSumXX += mtasId * mtasId;
                mtasId++;
              }
              int objectRefApproxQuotient;
              if(tmpN>1) {
                objectRefApproxQuotient= (int) (((tmpN * tmpSumXY)              
                  - (tmpSumX * tmpSumY))
                  / ((tmpN * tmpSumXX) - (tmpSumX * tmpSumX)));
              } else {
                objectRefApproxQuotient = 0;
              }
              long objectRefApproxOffset = (tmpSumY
                  - objectRefApproxQuotient * tmpSumX) / tmpN;
              Long objectRefApproxCorrection;
              long maxAbsObjectRefApproxCorrection = 0;
              // compute maximum correction
              mtasId = 0;
              for (Entry<Integer, Long> objectEntry : memoryIndexDocList
                  .entrySet()) {
                objectRefApproxCorrection = (objectEntry.getValue()
                    - (objectRefApproxOffset
                        + (mtasId * objectRefApproxQuotient)));
                maxAbsObjectRefApproxCorrection = Math.max(
                    maxAbsObjectRefApproxCorrection,
                    Math.abs(objectRefApproxCorrection));
                mtasId++;
              }
              byte storageFlags;
              if (maxAbsObjectRefApproxCorrection <= Long
                  .valueOf(Byte.MAX_VALUE)) {
                storageFlags = MtasCodecPostingsFormat.MTAS_STORAGE_BYTE;
              } else if (maxAbsObjectRefApproxCorrection <= Long
                  .valueOf(Short.MAX_VALUE)) {
                storageFlags = MtasCodecPostingsFormat.MTAS_STORAGE_SHORT;
              } else if (maxAbsObjectRefApproxCorrection <= Long
                  .valueOf(Integer.MAX_VALUE)) {
                storageFlags = MtasCodecPostingsFormat.MTAS_STORAGE_INTEGER;
              } else {
                storageFlags = MtasCodecPostingsFormat.MTAS_STORAGE_LONG;
              }
              // update indexObjectId with correction on approximated ref
              // (assume
              // can be stored as int)
              mtasId = 0;
              for (Entry<Integer, Long> objectEntry : memoryIndexDocList
                  .entrySet()) {
                objectRefApproxCorrection = (objectEntry.getValue()
                    - (objectRefApproxOffset
                        + (mtasId * objectRefApproxQuotient)));
                if (storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_BYTE) {
                  outIndexObjectId
                      .writeByte(objectRefApproxCorrection.byteValue());
                } else if (storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_SHORT) {
                  outIndexObjectId
                      .writeShort(objectRefApproxCorrection.shortValue());
                } else if (storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_INTEGER) {
                  outIndexObjectId
                      .writeInt(objectRefApproxCorrection.intValue());
                } else {
                  outIndexObjectId.writeLong(objectRefApproxCorrection);
                }
                mtasId++;
              }
              outTmpDoc.writeVLong(smallestObjectFilepointer);
              outTmpDoc.writeVInt(objectRefApproxQuotient);
              outTmpDoc.writeZLong(objectRefApproxOffset);
              outTmpDoc.writeByte(storageFlags);
              outTmpDoc.writeVInt(tokenStatsNumber);
              outTmpDoc.writeVInt(tokenStatsMinPos);
              outTmpDoc.writeVInt(tokenStatsMaxPos);
              // clean up
              memoryIndexDocList.clear();
            } // end loop over docs
            inTmpDocsChained.close();
            closeables.remove(inTmpDocsChained);
            inTmpObject.close();
            closeables.remove(inTmpObject);
          }
          // clean up
          memoryTmpDocChainList.clear();
          // remove temporary files
          state.directory.deleteFile(mtasTmpObjectFileName);
          state.directory.deleteFile(mtasTmpDocsChainedFileName);
          // store references for field

        } // end processing field
      } // end loop fields
      // close temporary index doc
      outTmpDoc.close();
      closeables.remove(outTmpDoc);
      // close indexField, indexObjectId and object
      CodecUtil.writeFooter(outTmpField);
      outTmpField.close();
      closeables.remove(outTmpField);
      CodecUtil.writeFooter(outIndexObjectId);
      outIndexObjectId.close();
      closeables.remove(outIndexObjectId);
      CodecUtil.writeFooter(outObject);
      outObject.close();
      closeables.remove(outObject);
      CodecUtil.writeFooter(outTerm);
      outTerm.close();
      closeables.remove(outTerm);
      CodecUtil.writeFooter(outPrefix);
      outPrefix.close();
      closeables.remove(outPrefix);

      // create final doc, fill indexObjectPosition, indexObjectParent and
      // indexTermPrefixPosition, create final field
      IndexInput inTmpField = state.directory.openInput(mtasTmpFieldFileName,
          state.context);
      closeables.add(inTmpField);
      IndexInput inTmpDoc = state.directory.openInput(mtasTmpDocFileName,
          state.context);
      closeables.add(inTmpDoc);
      IndexInput inObjectId = state.directory
          .openInput(mtasIndexObjectIdFileName, state.context);
      closeables.add(inObjectId);
      IndexInput inObject = state.directory.openInput(mtasObjectFileName,
          state.context);
      closeables.add(inObject);
      IndexInput inTerm = state.directory.openInput(mtasTermFileName,
          state.context);
      closeables.add(inTerm);
      closeables.add(outField = state.directory
          .createOutput(mtasIndexFieldFileName, state.context));
      CodecUtil.writeIndexHeader(outField, name,
          MtasCodecPostingsFormat.VERSION_CURRENT, state.segmentInfo.getId(),
          state.segmentSuffix);
      outField.writeString(delegatePostingsFormatName);
      boolean doWrite = true;
      do {
        try {
          // read from tmpField
          String field = inTmpField.readString();
          long fpTmpDoc = inTmpField.readVLong();
          int numberDocs = inTmpField.readVInt();
          long fpTerm = inTmpField.readVLong();
          int numberTerms = inTmpField.readVInt();
          long fpPrefix = inTmpField.readVLong();
          int numberPrefixes = inTmpField.readVInt();
          inTmpDoc.seek(fpTmpDoc);
          long fpFirstDoc = outDoc.getFilePointer();
          // get prefixId index
          HashMap<String, Integer> prefixIdIndexField = prefixIdIndex
              .get(field);
          // construct MtasRBTree for indexDocId
          MtasRBTree mtasDocIdTree = new MtasRBTree(true, false);
          for (int docCounter = 0; docCounter < numberDocs; docCounter++) {
            // get info from tmpDoc
            int docId = inTmpDoc.readVInt();
            // filePointer indexObjectId
            Long fpIndexObjectId = inTmpDoc.readVLong();
            // filePointer indexObjectPosition (unknown)
            Long fpIndexObjectPosition;
            // filePointer indexObjectParent (unknown)
            Long fpIndexObjectParent;
            // constants for approximation object references for this document
            long smallestObjectFilepointer = inTmpDoc.readVLong();
            int objectRefApproxQuotient = inTmpDoc.readVInt();
            long objectRefApproxOffset = inTmpDoc.readZLong();
            byte storageFlags = inTmpDoc.readByte();
            // number objects/tokens
            int size = inTmpDoc.readVInt();
            // construct MtasRBTree
            MtasRBTree mtasPositionTree = new MtasRBTree(false, true);
            MtasRBTree mtasParentTree = new MtasRBTree(false, true);
            inObjectId.seek(fpIndexObjectId);
            long refCorrection;
            long ref;
            HashMap<String, HashSet<Integer>> docFieldAdministration = new HashMap<>();
            for (int mtasId = 0; mtasId < size; mtasId++) {
              if (storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_BYTE) {
                refCorrection = inObjectId.readByte();
              } else if (storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_SHORT) {
                refCorrection = inObjectId.readShort();
              } else if (storageFlags == MtasCodecPostingsFormat.MTAS_STORAGE_INTEGER) {
                refCorrection = inObjectId.readInt();
              } else {
                refCorrection = inObjectId.readLong();
              }
              ref = objectRefApproxOffset + mtasId * objectRefApproxQuotient
                  + refCorrection;
              MtasTokenString token = MtasCodecPostingsFormat.getToken(inObject,
                  inTerm, ref);
              String prefix = token.getPrefix();
              registerPrefixIntersection(field, prefix,
                  token.getPositionStart(), token.getPositionEnd(),
                  docFieldAdministration);
              int prefixId = prefixIdIndexField.containsKey(prefix)
                  ? prefixIdIndexField.get(prefix) : 0;
              token.setPrefixId(prefixId);
              assert token.getId().equals(mtasId) : "unexpected mtasId "
                  + mtasId;
              mtasPositionTree.addPositionAndObjectFromToken(token);
              mtasParentTree.addParentFromToken(token);
            }
            // store mtasPositionTree and mtasParentTree
            fpIndexObjectPosition = storeTree(mtasPositionTree,
                outIndexObjectPosition, smallestObjectFilepointer);
            fpIndexObjectParent = storeTree(mtasParentTree,
                outIndexObjectParent, smallestObjectFilepointer);
            long fpDoc = outDoc.getFilePointer();
            // create indexDoc with updated fpIndexObjectPosition from tmpDoc
            outDoc.writeVInt(docId); // docId
            // reference indexObjectId
            outDoc.writeVLong(fpIndexObjectId);
            // reference indexObjectPosition
            outDoc.writeVLong(fpIndexObjectPosition);
            // reference indexObjectParent
            outDoc.writeVLong(fpIndexObjectParent);
            // variables approximation and storage references object
            outDoc.writeVLong(smallestObjectFilepointer);
            outDoc.writeVInt(objectRefApproxQuotient);
            outDoc.writeZLong(objectRefApproxOffset);
            outDoc.writeByte(storageFlags);
            // number of objects
            outDoc.writeVInt(size);
            // minPosition
            outDoc.writeVInt(inTmpDoc.readVInt());
            // maxPosition
            outDoc.writeVInt(inTmpDoc.readVInt());
            // add to tree for indexDocId
            mtasDocIdTree.addIdFromDoc(docId, fpDoc);
          }
          long fpIndexDocId = storeTree(mtasDocIdTree, outIndexDocId,
              fpFirstDoc);

          // store in indexField
          outField.writeString(field);
          outField.writeVLong(fpFirstDoc);
          outField.writeVLong(fpIndexDocId);
          outField.writeVInt(numberDocs);
          outField.writeVLong(fpTerm);
          outField.writeVInt(numberTerms);
          outField.writeVLong(fpPrefix);
          outField.writeVInt(numberPrefixes);
          // register intersection
          fieldInfos.fieldInfo(field).putAttribute(
              MtasCodecPostingsFormat.MTAS_FIELDINFO_ATTRIBUTE_PREFIX_INTERSECTION,
              getPrefixStatsIntersectionPrefixAttribute(field));
        } catch (EOFException e) {
          log.debug(e);
          doWrite = false;
        }
        // end loop over fields
      } while (doWrite);
      inTerm.close();
      closeables.remove(inTerm);
      inObject.close();
      closeables.remove(inObject);
      inObjectId.close();
      closeables.remove(inObjectId);
      inTmpDoc.close();
      closeables.remove(inTmpDoc);
      inTmpField.close();
      closeables.remove(inTmpField);

      // remove temporary files
      state.directory.deleteFile(mtasTmpDocFileName);
      state.directory.deleteFile(mtasTmpFieldFileName);
      // close indexDoc, indexObjectPosition and indexObjectParent
      CodecUtil.writeFooter(outDoc);
      outDoc.close();
      closeables.remove(outDoc);
      CodecUtil.writeFooter(outIndexObjectPosition);
      outIndexObjectPosition.close();
      closeables.remove(outIndexObjectPosition);
      CodecUtil.writeFooter(outIndexObjectParent);
      outIndexObjectParent.close();
      closeables.remove(outIndexObjectParent);
      CodecUtil.writeFooter(outIndexDocId);
      outIndexDocId.close();
      closeables.remove(outIndexDocId);
      CodecUtil.writeFooter(outField);
      outField.close();
      closeables.remove(outField);
    } catch (IOException e) {
      // ignore, can happen when merging segment already written by
      // delegateFieldsConsumer
      log.error(e);
    } finally {
      IOUtils.closeWhileHandlingException(closeables);
      try {
        state.directory.deleteFile(mtasTmpDocsFileName);
      } catch (IOException e) {
        log.debug(e);
      }
      try {
        state.directory.deleteFile(mtasTmpDocFileName);
      } catch (IOException e) {
        log.debug(e);
      }
      try {
        state.directory.deleteFile(mtasTmpFieldFileName);
      } catch (IOException e) {
        log.debug(e);
      }
    }
  }
938605
def _copy_plans(self, branch_from, turn_from, tick_from):
        """"""
        plan_ticks = self._plan_ticks
        plan_ticks_uncommitted = self._plan_ticks_uncommitted
        time_plan = self._time_plan
        plans = self._plans
        branch = self.branch
        where_cached = self._where_cached
        last_plan = self._last_plan
        turn_end_plan = self._turn_end_plan
        for plan_id in self._branches_plans[branch_from]:
            _, start_turn, start_tick = plans[plan_id]
            if start_turn > turn_from or (start_turn == turn_from and start_tick > tick_from):
                continue
            incremented = False
            for turn, ticks in list(plan_ticks[plan_id].items()):
                if turn < turn_from:
                    continue
                for tick in ticks:
                    if turn == turn_from and tick < tick_from:
                        continue
                    if not incremented:
                        self._last_plan = last_plan = last_plan + 1
                        incremented = True
                        plans[last_plan] = branch, turn, tick
                    for cache in where_cached[branch_from, turn, tick]:
                        data = cache.settings[branch_from][turn][tick]
                        value = data[-1]
                        key = data[:-1]
                        args = key + (branch, turn, tick, value)
                        if hasattr(cache, 'setdb'):
                            cache.setdb(*args)
                        cache.store(*args, planning=True)
                        plan_ticks[last_plan][turn].append(tick)
                        plan_ticks_uncommitted.append((last_plan, turn, tick))
                        time_plan[branch, turn, tick] = last_plan
                        turn_end_plan[branch, turn] = tick
356614
private void processAssignmentData() throws IOException
   {
      FieldMap fieldMap = new FieldMap9(m_file.getProjectProperties(), m_file.getCustomFields());
      fieldMap.createAssignmentFieldMap(m_projectProps);

      DirectoryEntry assnDir = (DirectoryEntry) m_projectDir.getEntry("TBkndAssn");
      VarMeta assnVarMeta = new VarMeta9(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("VarMeta"))));
      Var2Data assnVarData = new Var2Data(assnVarMeta, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("Var2Data"))));

      FixedMeta assnFixedMeta = new FixedMeta(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixedMeta"))), 34);
      FixedData assnFixedData = new FixedData(142, m_inputStreamFactory.getInstance(assnDir, "FixedData"));
      if (assnFixedData.getItemCount() != assnFixedMeta.getAdjustedItemCount())
      {
         assnFixedData = new FixedData(assnFixedMeta, m_inputStreamFactory.getInstance(assnDir, "FixedData"));
      }

      ResourceAssignmentFactory factory = new ResourceAssignmentFactory();
      factory.process(m_file, fieldMap, null, m_reader.getUseRawTimephasedData(), m_reader.getPreserveNoteFormatting(), assnVarMeta, assnVarData, assnFixedMeta, assnFixedData, null, assnFixedMeta.getAdjustedItemCount());
   }
742959
private void writeFileCreationRecord() throws IOException
   {
      ProjectProperties properties = m_projectFile.getProjectProperties();

      m_buffer.setLength(0);
      m_buffer.append("MPX");
      m_buffer.append(m_delimiter);
      m_buffer.append(properties.getMpxProgramName());
      m_buffer.append(m_delimiter);
      m_buffer.append(properties.getMpxFileVersion());
      m_buffer.append(m_delimiter);
      m_buffer.append(properties.getMpxCodePage());
      m_buffer.append(MPXConstants.EOL);
      m_writer.write(m_buffer.toString());
   }
608201
def write_data(data):
    

    sorted_dict = sort_recursive(data)

    with open(_datafile, 'w') as file:
        _json.dump(sorted_dict, file, indent=2)
484695
def write_data(self, data, file_datetime):
        
        with self.__lock:
            assert data is not None
            absolute_file_path = self.__file_path
            #logging.debug("WRITE data file %s for %s", absolute_file_path, key)
            make_directory_if_needed(os.path.dirname(absolute_file_path))
            properties = self.read_properties() if os.path.exists(absolute_file_path) else dict()
            write_zip(absolute_file_path, data, properties)
            # convert to utc time.
            tz_minutes = Utility.local_utcoffset_minutes(file_datetime)
            timestamp = calendar.timegm(file_datetime.timetuple()) - tz_minutes * 60
            os.utime(absolute_file_path, (time.time(), timestamp))
923528
public void write(DataOutput out) throws IOException {
    Text.writeString(out, jobFile);
    taskId.write(out);
    out.writeInt(partition);
    out.writeInt(numSlotsRequired);
    taskStatus.write(out);
    skipRanges.write(out);
    out.writeBoolean(skipping);
    out.writeBoolean(jobCleanup);
    if (jobCleanup) {
      WritableUtils.writeEnum(out, jobRunStateForCleanup);
    }
    out.writeBoolean(jobSetup);
    Text.writeString(out, username);
    out.writeBoolean(writeSkipRecs);
    out.writeBoolean(taskCleanup);  
    extraData.write(out);
  }
444490
def write_sub_files(self):
    
    if not self.__nodes_finalized:
      for node in self.__nodes:
        node.finalize()
    if not self.is_dax():
      for job in self.__jobs:
        job.write_sub_file()
482371
def write(self, session, directory, name, replaceParamFile=None, **kwargs):
        
        if self.raster is not None or self.rasterText is not None:
            super(RasterMapFile, self).write(session, directory, name, replaceParamFile, **kwargs)
972229
public void write(Model project, Document document, String encoding, OutputStreamWriter writer)
            throws java.io.IOException
   {
      Format format = Format.getRawFormat().setEncoding(encoding).setLineSeparator(LS);
      write(project, document, writer, format);
   }
1372642
def _write(self, session, openFile, replaceParamFile):
        
        # Retrieve output locations
        locations = self.outputLocations

        # Write lines
        openFile.write('%s\n' % self.numLocations)

        for location in locations:
            openFile.write('%s %s\n' % (location.linkOrCellI,
                                        location.nodeOrCellJ))
182728
@Override
    public void writeFile(String arg0, Map result) {

        // Initial variables
        HashMap wthFile;                  // Data holder for whole weather data
        ArrayList wthRecords;                   // Daily data array
        HashMap wthRecord;                // Data holder for daily data
        BufferedWriter bwW;                     // output object
        StringBuilder sbData = new StringBuilder();     // construct the data info in the output
        LinkedHashMap dailyVarHeaderMap = new LinkedHashMap();   // Define the mapping of daily data fields and header
        dailyVarHeaderMap.put("tdew", "DEWP");
        dailyVarHeaderMap.put("wind", "WIND");
        dailyVarHeaderMap.put("pard", "PAR");
        dailyVarHeaderMap.put("vprsd", "VPRS");
        dailyVarHeaderMap.put("rhumd", "RHUM");
        String dailyKey = "dailyWeather";  // P.S. the key name might change
        HeaderArrayList<String> dailyHeaders = new HeaderArrayList();
        StringBuilder[] dailyData;

        try {

            // Set default value for missing data
            setDefVal();

            // Get weather files
            wthFile = (HashMap) getObjectOr(result, "weather", new HashMap());
            if (wthFile.isEmpty()) {
                return;
            }
//            decompressData(wthFiles);

            // Output all weather files
            wthRecords = (ArrayList) getObjectOr(wthFile, dailyKey, new ArrayList());

            // Initial BufferedWriter
            // Get File name
            String fileName = getValueOr(result, "wst_id", "");
            if (fileName.equals("")) {
                fileName = getWthFileName(result);
            }
            fileName += ".WTH";
            arg0 = revisePath(arg0);
            outputFile = new File(arg0 + fileName);
            bwW = new BufferedWriter(new FileWriter(outputFile));

            // Output Weather File
            // Titel Section
            if (getObjectOr(wthFile, "wst_notes", ".AgMIP File").equals(".AgMIP File")) {
                sbData.append(String.format("*WEATHER DATA : %1$s\r\n!Climate ID: %2$s\r\n", getObjectOr(wthFile, "wst_source", defValBlank), getValueOr(wthFile, "clim_id", "N/A")));
            } else {
                sbData.append(String.format("*WEATHER DATA : %1$s\r\n!Climate ID: %2$s\r\n", getObjectOr(wthFile, "wst_notes", defValBlank), getValueOr(wthFile, "clim_id", "N/A")));
            }

            // Weather Station Section
            String wid = getObjectOr(wthFile, "wst_id", defValC);
            if (wid.length() > 4) {
                wid = wid.substring(0, 4);
            }
            sbData.append("@ INSI      LAT     LONG  ELEV   TAV   AMP REFHT WNDHT  CCO2\r\n");
            sbData.append(String.format("  %1$-4s %2$8s %3$8s %4$5s %5$5s %6$5s %7$5s %8$5s %9$5s\r\n",
                    formatStr(4, wthFile, "dssat_insi", wid),
                    formatNumStr(8, wthFile, "wst_lat", defValR),
                    formatNumStr(8, wthFile, "wst_long", defValR),
                    formatNumStr(5, wthFile, "wst_elev", defValR),
                    formatNumStr(5, wthFile, "tav", defValR),
                    formatNumStr(5, wthFile, "tamp", defValR),
                    formatNumStr(5, wthFile, "refht", defValR),
                    formatNumStr(5, wthFile, "wndht", defValR),
                    formatNumStr(5, wthFile, "co2y", defValR)));

            // Daily weather data section
            // Title line
            sbData.append("@DATE  SRAD  TMAX  TMIN  RAIN  DEWP  WIND   PAR");
            // Register fixed headers
            dailyHeaders.add("w_date");
            dailyHeaders.add("srad");
            dailyHeaders.add("tmax");
            dailyHeaders.add("tmin");
            dailyHeaders.add("rain");
            dailyHeaders.add("tdew");
            dailyHeaders.add("wind");
            dailyHeaders.add("pard");

            // Output daily data
            dailyData = new StringBuilder[wthRecords.size()];
            for (int i = 0; i < wthRecords.size(); i++) {

                wthRecord = (HashMap) wthRecords.get(i);
                dailyData[i] = new StringBuilder();
                dailyHeaders.seCurItems(wthRecord.keySet());

                // if date is missing, jump the record
                if (!getObjectOr(wthRecord, "w_date", "").equals("")) {
                    //  Format handling for daily date
                    dailyData[i].append(String.format("%1$5s", formatDateStr(getObjectOr(wthRecord, dailyHeaders.get(0), defValD))));

                    // Output the registered variables
                    for (int j = 1; j < dailyHeaders.size(); j++) {
                        dailyData[i].append(String.format(" %1$5s", formatNumStr(5, wthRecord, dailyHeaders.get(j), defValR)));
                    }

                    // Check if there is new variable not been regitered in the output list
                    while (dailyHeaders.hasMoreItem()) {
                        // Register the variable
                        String key = dailyHeaders.applyNext();

                        if (key != null) {
                            // Add title to the header line
                            sbData.append(String.format("%1$6s", getObjectOr(dailyVarHeaderMap, key, key.toUpperCase())));
                            // Add blank for previous lines (this might be optional)
                            for (int j = 0; j < i; j++) {
                                dailyData[j].append("   -99");
                            }
                            // Output new variable
                            dailyData[i].append(String.format(" %1$5s", formatNumStr(5, wthRecord, key, defValR)));
                        }
                    }
                } else {
                    sbError.append("! Warning: A daily record has the missing date in it.\r\n");
                }
            }

            // Combine the daily data
            sbData.append("\r\n");
            for (int i = 0; i < dailyData.length; i++) {
                dailyData[i].append("\r\n");
                sbData.append(dailyData[i]);
                dailyData[i] = null;
            }

            // Output finish
            bwW.write(sbError.toString());
            bwW.write(sbData.toString());
            bwW.close();
            sbError = new StringBuilder();

        } catch (IOException e) {
            LOG.error(DssatCommonOutput.getStackTrace(e));
        }
    }