class NcFileStitcher {

    static File stitchNcFiles(String fileName, File targetDirectory, Date creationDate,
                              File[] ncFiles, ImageSize targetImageSize, ImageSize[] imageSizes) throws IOException, PDUStitchingException {
        NetcdfFile[] inputFiles = new NetcdfFile[ncFiles.length];
        List<Attribute>[] globalAttributes = new ArrayList[ncFiles.length];
        List<Dimension>[] dimensions = new List[ncFiles.length];
        List<Variable>[] variables = new List[ncFiles.length];
        for (int i = 0; i < ncFiles.length; i++) {
            inputFiles[i] = NetcdfFileOpener.open(ncFiles[i]);
            globalAttributes[i] = inputFiles[i].getGlobalAttributes();
            dimensions[i] = inputFiles[i].getDimensions();
            variables[i] = inputFiles[i].getVariables();
        }
        final File file = new File(targetDirectory, fileName);
        final SlstrNFileWritable netcdfWriteable = new SlstrNFileWritable(file.getAbsolutePath());
        setGlobalAttributes(netcdfWriteable, globalAttributes, targetDirectory.getName(), creationDate);
        setDimensions(netcdfWriteable, dimensions, targetImageSize, variables);
        final Map<String, Array> variableToArrayMap =
                defineVariables(netcdfWriteable, variables, targetImageSize, imageSizes);
        netcdfWriteable.create();
        for (String variableName : variableToArrayMap.keySet()) {
            netcdfWriteable.findVariable(variableName).writeFullyInSections(variableToArrayMap.get(variableName));
        }
        netcdfWriteable.close();
        for (NetcdfFile inputFile : inputFiles) {
            inputFile.close();
        }
        return file;
    }

}