Generate output file name

@param result date holder for experiment data
@param fileType the last letter from file extend name
@return file name
509668
protected synchronized String getFileName(Map result, String fileType) {
        String exname = getExName(result);
        String crid;
        if (getValueOr(result, "seasonal_dome_applied", "N").equals("Y")) {
            crid = "SN";
        } else {
            crid = getCrid(result);
        }
        if (exname.length() == 10) {
            if (crid.equals("XX") || crid.equals("FA")) {
                crid = exname.substring(exname.length() - 2, exname.length());
            }
        }

        String ret;
        if (exToFileMap.containsKey(exname + "_" + crid)) {
            return exToFileMap.get(exname + "_" + crid) + fileType;
        } else {
            ret = exname;
            if (ret.equals("")) {
                ret = "TEMP0001";
            } else {
                try {
                    if (ret.endsWith(crid)) {
                        ret = ret.substring(0, ret.length() - crid.length());
                    }
                    // If the exname is too long
                    if (ret.length() > 8) {
                        ret = ret.substring(0, 8);
                    }
                    // If the exname do not follow the Dssat rule
                    if (!ret.matches("[\\w ]{1,6}\\d{2}$")) {
                        if (ret.length() > 6) {
                            ret = ret.substring(0, 6);
                        }
                        ret += "01";
                    }
                } catch (Exception e) {
                    ret = "TEMP0001";
                }
            }

            // Special handling for batch
            if (exname.matches(".+_\\d+_b\\S+(__\\d+)?$")) {
                int idx = exname.lastIndexOf("_b") + 2;
                ret += "B" + exname.substring(idx).replaceAll("__\\d+$", "");
            }

            // Find a non-repeated file name
            int count;
            while (fileNameSet.contains(ret + "." + crid)) {
                try {
                    count = Integer.parseInt(ret.substring(ret.length() - 2, ret.length()));
                    count++;
                } catch (Exception e) {
                    count = 1;
                }
                ret = ret.replaceAll("\\w{2}$", String.format("%02d", count));
            }
        }

        exToFileMap.put(exname + "_" + crid, ret + "." + crid);
        fileNameSet.add(ret + "." + crid);

        return ret + "." + crid + fileType;
    }
393320
public static String fileTypeAsString( int fileType ) {

		String result;
		switch( fileType ) {
		case AGGREGATOR:
			result = "aggregator";
			break;

		case GRAPH:
			result = "graph";
			break;

		case INSTANCE:
			result = "intsnace";
			break;

		case UNDETERMINED:
			result = "undetermined";
			break;

		default:
			result = "unknown";
			break;
		}

		return result;
	}
959087
@Override
    public void writeFile(String arg0, Map result) {

        // Initial variables
        BufferedWriter bwB;                         // output object
        StringBuilder sbData = new StringBuilder(); // construct the data info in the output

        try {

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

            // Get version number
            if (dssatVerStr == null) {
                dssatVerStr = getObjectOr(result, "crop_model_version", "").replaceAll("\\D", "");
                if (!dssatVerStr.matches("\\d+")) {
                    dssatVerStr = DssatVersion.DSSAT45.toString();
                }
            }

            // Initial BufferedWriter
            arg0 = revisePath(arg0);
            outputFile = new File(arg0 + "DSSBatch.v" + dssatVerStr);
            bwB = new BufferedWriter(new FileWriter(outputFile));

            // Output Batch File
            // Titel Section
            String crop = getCropName(result);
            String dssatPath = "C:\\DSSAT" + dssatVerStr + "\\";
            String exFileName = getFileName(result, "X");
            int expNo = 1;

            // Write title section
            sbData.append("$BATCH(").append(crop).append(")\r\n!\r\n");
            sbData.append(String.format("! Command Line : %1$sDSCSM0%2$s.EXE B DSSBatch.v%2$s\r\n", dssatPath, dssatVerStr));
            sbData.append("! Crop         : ").append(crop).append("\r\n");
            sbData.append("! Experiment   : ").append(exFileName).append("\r\n");
            sbData.append("! ExpNo        : ").append(expNo).append("\r\n");
            sbData.append(String.format("! Debug        : %1$sDSCSM0%2$s.EXE \" B DSSBatch.v%2$s\"\r\n!\r\n", dssatPath, dssatVerStr));

            // Body Section
            sbData.append("@FILEX                                                                                        TRTNO     RP     SQ     OP     CO\r\n");
            // Get DSSAT Sequence info
            HashMap dssatSeqData = getObjectOr(result, "dssat_sequence", new HashMap());
            ArrayList<HashMap> dssatSeqArr = getObjectOr(dssatSeqData, "data", new ArrayList<HashMap>());
            // If missing, set default value
            if (dssatSeqArr.isEmpty()) {
                HashMap tmp = new HashMap();
                tmp.put("sq", "1");
                tmp.put("op", "1");
                tmp.put("co", "0");
                dssatSeqArr.add(tmp);
            }
            // Output all info
            for (HashMap dssatSeqSubData : dssatSeqArr) {
                sbData.append(String.format("%1$-92s %2$6s %3$6s %4$6s %5$6s %6$6s", exFileName, "1", "1", getObjectOr(dssatSeqSubData, "sq", "1"), getObjectOr(dssatSeqSubData, "op", "1"), getObjectOr(dssatSeqSubData, "co", "0")));
            }

            // Output finish
            bwB.write(sbError.toString());
            bwB.write(sbData.toString());
            bwB.close();
        } catch (IOException e) {
            LOG.error(DssatCommonOutput.getStackTrace(e));
        }
    }
500439
def _format_output(self, outfile_name, out_type):
        

        outfile_name = self._absolute(outfile_name)
        outparts = outfile_name.split("/")
        outparts[-1] = self._out_format % (out_type, outparts[-1] )

        return '/'.join(outparts)
1250802
@Override
    public void writeFile(String arg0, Map result) {

        long estTime = 0;

        try {
            if (getObjectOr(result, "experiments", new ArrayList()).isEmpty()
                    && getObjectOr(result, "soils", new ArrayList()).isEmpty()
                    && getObjectOr(result, "weathers", new ArrayList()).isEmpty()) {

                // Calculate estimated time consume
                HashMap wth = getObjectOr(result, "weather", new HashMap());
                estTime += getObjectOr(wth, "dailyWeather", new ArrayList()).size();

                // Write files
                recordSWData(result, new DssatSoilOutput());
                recordSWData(result, new DssatWeatherOutput());
                writeWthFiles(arg0);
                writeSoilFiles(arg0);
                String exname = getValueOr(result, "exname", "N/A");
                writeSingleExp(arg0, result, new DssatXFileOutput(), exname + "_X");
                writeSingleExp(arg0, result, new DssatAFileOutput(), exname + "_A");
                writeSingleExp(arg0, result, new DssatTFileOutput(), exname + "_T");
                writeSingleExp(arg0, result, new DssatCulFileOutput(), exname + "_Cul");
                writeSingleExp(arg0, result, new DssatBatchFileOutput(DssatVersion.DSSAT45), "DSSBatch.v45");
                writeSingleExp(arg0, result, new DssatBatchFileOutput(DssatVersion.DSSAT46), "DSSBatch.v46");
                writeSingleExp(arg0, result, new DssatRunFileOutput(DssatVersion.DSSAT45), "Run45.bat");
                writeSingleExp(arg0, result, new DssatRunFileOutput(DssatVersion.DSSAT46), "Run46.bat");

                // compress all output files into one zip file
                outputFile = new File(revisePath(arg0) + exname + ".ZIP");

                //createZip();
            } else {
                // Calculate estimated time consume
                for (HashMap wth : (ArrayList<HashMap>) getObjectOr(result, "weathers", new ArrayList<HashMap>())) {
                    estTime += getObjectOr(wth, "dailyWeather", new ArrayList()).size();
                }
                writeMultipleExp(arg0, result);
            }

            if (estTime > 0) {
                estTime *= 10;
            } else {
                estTime = 10000;
            }

            executor.shutdown();
            long timer = System.currentTimeMillis();
            HashSet<String> keys = new HashSet(futFiles.keySet());
            int counter = 0;
            while (!executor.isTerminated()) {
                if (System.currentTimeMillis() - timer > estTime) {
                    counter++;
                    timer = System.currentTimeMillis();
                    if (keys.isEmpty()) {
                        LOG.info("The executor should be terminated");
                        executor.shutdownNow();
                    } else if (counter > 3) {
                        LOG.info("The executor is going to be force terminated");
                        executor.shutdownNow();
                    }
                    String[] arr = keys.toArray(new String[0]);
                    for (String key : arr) {
                        Future futFile = futFiles.get(key);
                        if (futFile.isCancelled() || futFile.isDone()) {
                            keys.remove(key);
                        } else {
                            LOG.info("DSSAT translation for {} is still under processing...", key);
                        }
                    }
                }
            }
            executor = null;
            LOG.debug("Consume {} s", (System.currentTimeMillis() - timer) / 1000.0);

            // Get output result files into output array
            for (String key : futFiles.keySet()) {
                try {
                    File f = futFiles.get(key).get();
                    if (f != null) {
                        files.put(f.getPath(), f);
                    }
                } catch (InterruptedException ex) {
                    LOG.error(getStackTrace(ex));
                } catch (ExecutionException ex) {
                    if (!ex.getMessage().contains("NoOutputFileException")) {
                        LOG.error(getStackTrace(ex));
                    }
                }
            }

        } catch (FileNotFoundException e) {
            LOG.error(getStackTrace(e));
        } catch (IOException e) {
            LOG.error(getStackTrace(e));
        }
    }
501228
protected String toFilename(final Resource resource) throws UnsupportedOperationException {
        if (resource instanceof FileResource) {
            return ((FileResource) resource).getFile().getPath();
        }

        throw new UnsupportedOperationException("Unsupported resource type: " + resource);
    }
1042306
private void outputResult() throws DITAOTException {
        try {
            tempFileNameScheme = (TempFileNameScheme) Class.forName(job.getProperty("temp-file-name-scheme")).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        tempFileNameScheme.setBaseDir(baseInputDir);

        // assume empty Job
        final URI rootTemp = tempFileNameScheme.generateTempFileName(rootFile);
        final File relativeRootFile = toFile(rootTemp);

        job.setInputDir(baseInputDir);
        job.setInputMap(rootTemp);
        
        //If root input file is marked resource only due to conref or other feature, remove that designation
        if (resourceOnlySet.contains(rootFile)) {
            resourceOnlySet.remove(rootFile);
        }

        job.setProperty(INPUT_DITAMAP_LIST_FILE_LIST, USER_INPUT_FILE_LIST_FILE);
        final File inputfile = new File(job.tempDir, USER_INPUT_FILE_LIST_FILE);
        writeListFile(inputfile, relativeRootFile.toString());

        job.setProperty("tempdirToinputmapdir.relative.value", StringUtils.escapeRegExp(getPrefix(relativeRootFile)));
        job.setProperty("uplevels", getLevelsPath(rootTemp));

        resourceOnlySet.addAll(listFilter.getResourceOnlySet());

        if (job.getOnlyTopicInMap() || !job.crawlTopics()) {
            resourceOnlySet.addAll(listFilter.getNonTopicrefReferenceSet());
        }

        for (final URI file: outDitaFilesSet) {
            getOrCreateFileInfo(fileinfos, file).isOutDita = true;
        }
        for (final URI file: fullTopicSet) {
            final FileInfo ff = getOrCreateFileInfo(fileinfos, file);
            if (ff.format == null) {
                ff.format = sourceFormat.getOrDefault(ff.src, ATTR_FORMAT_VALUE_DITA);
            }
        }
        for (final URI file: fullMapSet) {
            final FileInfo ff = getOrCreateFileInfo(fileinfos, file);
            if (ff.format == null) {
                ff.format = ATTR_FORMAT_VALUE_DITAMAP;
            }
        }
        for (final URI file: hrefTopicSet) {
            final FileInfo f = getOrCreateFileInfo(fileinfos, file);
            f.hasLink = true;
            if (f.format == null && sourceFormat.containsKey(f.src)) {
                f.format = sourceFormat.get(f.src);
            }
        }
        for (final URI file: conrefSet) {
            getOrCreateFileInfo(fileinfos, file).hasConref = true;
        }
        for (final Reference file: formatSet) {
            getOrCreateFileInfo(fileinfos, file.filename).format = file.format;
        }
        for (final URI file: flagImageSet) {
            final FileInfo f = getOrCreateFileInfo(fileinfos, file);
            f.isFlagImage = true;
            f.format = ATTR_FORMAT_VALUE_IMAGE;
        }
        for (final String format: htmlSet.keySet()) {
            for (final URI file : htmlSet.get(format)) {
                getOrCreateFileInfo(fileinfos, file).format = format;
            }
        }
        for (final URI file: hrefTargetSet) {
            final FileInfo f = getOrCreateFileInfo(fileinfos, file);
            f.isTarget = true;
            if (f.format == null && sourceFormat.containsKey(f.src)) {
                f.format = sourceFormat.get(f.src);
            }
        }
        for (final URI file: schemeSet) {
            getOrCreateFileInfo(fileinfos, file).isSubjectScheme = true;
        }
        for (final URI file: coderefTargetSet) {
            final FileInfo f = getOrCreateFileInfo(fileinfos, file);
            f.isSubtarget = true;
            if (f.format == null) {
                f.format = PR_D_CODEREF.localName;
            }
        }
        for (final URI file: conrefpushSet) {
            getOrCreateFileInfo(fileinfos, file).isConrefPush = true;
        }
        for (final URI file: keyrefSet) {
            getOrCreateFileInfo(fileinfos, file).hasKeyref = true;
        }
        for (final URI file: coderefSet) {
            getOrCreateFileInfo(fileinfos, file).hasCoderef = true;
        }
        for (final URI file: resourceOnlySet) {
            getOrCreateFileInfo(fileinfos, file).isResourceOnly = true;
        }

        addFlagImagesSetToProperties(job, relFlagImagesSet);

        final Map<URI, URI> filteredCopyTo = filterConflictingCopyTo(copyTo, fileinfos.values());

        for (final FileInfo fs: fileinfos.values()) {
            if (!failureList.contains(fs.src)) {
                final URI src = filteredCopyTo.get(fs.src);
                // correct copy-to
                if (src != null) {
                    final FileInfo corr = new FileInfo.Builder(fs).src(src).build();
                    job.add(corr);
                } else {
                    job.add(fs);
                }
            }
        }
        for (final URI target : filteredCopyTo.keySet()) {
            final URI tmp = tempFileNameScheme.generateTempFileName(target);
            final FileInfo fi = new FileInfo.Builder().result(target).uri(tmp).build();
            job.add(fi);
        }

        final FileInfo root = job.getFileInfo(rootFile);
        if (root == null) {
            throw new RuntimeException("Unable to set input file to job configuration");
        }
        job.add(new FileInfo.Builder(root)
                .isInput(true)
                .build());

        try {
            logger.info("Serializing job specification");
            if (!job.tempDir.exists() && !job.tempDir.mkdirs()) {
                throw new DITAOTException("Failed to create " + job.tempDir + " directory");
            }
            job.write();
        } catch (final IOException e) {
            throw new DITAOTException("Failed to serialize job configuration files: " + e.getMessage(), e);
        }

        try {
            SubjectSchemeReader.writeMapToXML(addMapFilePrefix(listFilter.getRelationshipGrap()), new File(job.tempDir, FILE_NAME_SUBJECT_RELATION));
            SubjectSchemeReader.writeMapToXML(addMapFilePrefix(schemeDictionary), new File(job.tempDir, FILE_NAME_SUBJECT_DICTIONARY));
        } catch (final IOException e) {
            throw new DITAOTException("Failed to serialize subject scheme files: " + e.getMessage(), e);
        }

        if (INDEX_TYPE_ECLIPSEHELP.equals(transtype)) {
            final DelayConrefUtils delayConrefUtils = new DelayConrefUtils();
            delayConrefUtils.setLogger(logger);
            delayConrefUtils.setJob(job);
            delayConrefUtils.writeMapToXML(exportAnchorsFilter.getPluginMap());
            delayConrefUtils.writeExportAnchors(exportAnchorsFilter, tempFileNameScheme);
        }

        KeyDef.writeKeydef(new File(job.tempDir, SUBJECT_SCHEME_KEYDEF_LIST_FILE), addFilePrefix(schemekeydefMap.values()));
    }
774556
public void addResult(CmsResourceTypeStatResult result) {

        if (!m_results.contains(result)) {
            m_results.add(result);
            m_updated = false;
        } else {
            m_results.remove(result);
            m_results.add(result);
            m_updated = true;
        }
    }
860660
private String getOutputName() throws MojoExecutionException
    {
        if ( MSBuildPackaging.isSolution( mavenProject.getPackaging() ) )
        {
            throw new MojoExecutionException( "Internal error: Cannot determine single output name for a solutions" );
        }
        String projectFileName = projectFile.getName();
        if ( ! projectFileName.contains( "." ) )
        {
            throw new MojoExecutionException( "Project file name has no extension, please check your configuration" );
        }
        projectFileName = projectFileName.substring( 0, projectFileName.lastIndexOf( '.' ) );
        return projectFileName;
    }
247192
public String getFileName(String strFileName, String strPackage, CodeType codeType, ClassProject recClassProject)
    {
        return recClassProject.getFileName(strFileName, strPackage, codeType, true, true);
    }
504970
private String generateFilename() {
        String counter = "";
        if (capabilities.getInstance() > 0) {
            counter = "_" + capabilities.getInstance();
        }
        return test + counter;
    }
895204
def get_filename(self, runSetName, fileExtension):
        '''
        
        '''

        fileName = self.benchmark.output_base_name + ".results."

        if runSetName:
            fileName += runSetName + "."

        return fileName + fileExtension
474480
def file_name(self, file_type: Optional[FileType] = None) -> str:
        
        name = self.__text.word()
        ext = self.extension(file_type)

        return '{name}{ext}'.format(
            name=self.__sub(name),
            ext=ext,
        )
1186617
public static String getDumpFileDirectoryName(
			DumpContentType dumpContentType, String dateStamp) {
		return dumpContentType.toString().toLowerCase() + "-" + dateStamp;
	}
777295
public static String createSummary(final TasksResult result) {
        StringBuilder summary = new StringBuilder();
        int tasks = result.getNumberOfAnnotations();

        summary.append(Messages.Tasks_ResultAction_Summary());
        summary.append(" ");
        if (tasks > 0) {
            summary.append("<a href=\"tasksResult\">");
        }
        if (tasks == 1) {
            summary.append(Messages.Tasks_ResultAction_OneWarning());
        }
        else {
            summary.append(Messages.Tasks_ResultAction_MultipleWarnings(tasks));
        }
        if (tasks > 0) {
            summary.append("</a>");
        }
        summary.append(" ");
        if (result.getNumberOfFiles() > 1) {
            summary.append(Messages.Tasks_ResultAction_MultipleFiles(result.getNumberOfFiles()));
        }
        else {
            summary.append(Messages.Tasks_ResultAction_OneFile());
        }
        summary.append(".");
        return summary.toString();
    }
87841
@Override
  public String generateFileName(int logLevel, long timestamp) {
    SimpleDateFormat sdf = mLocalDateFormat.get();
    sdf.setTimeZone(TimeZone.getDefault());
    return sdf.format(new Date(timestamp));
  }
634954
public void writeBegin(final OutputStream result) {
        try {
            result.write(COLOR_NUMBER);
            result.write(intToByteArray(colorNumber));
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
    }