(String arg)
| 61 | |
| 62 | |
| 63 | @AstroImageJ(reason = "Create missing directories if they don't exist", modified = true) |
| 64 | public void run(String arg) { |
| 65 | if (imp==null) |
| 66 | imp = WindowManager.getCurrentImage(); |
| 67 | if (imp==null || (imp!=null && imp.getStackSize()<2&&!IJ.isMacro())) { |
| 68 | IJ.error("Stack Writer", "This command requires a stack."); |
| 69 | return; |
| 70 | } |
| 71 | int stackSize = imp.getStackSize(); |
| 72 | if (name==null) { |
| 73 | name = imp.getTitle(); |
| 74 | int dotIndex = name.lastIndexOf("."); |
| 75 | if (dotIndex>=0) |
| 76 | name = name.substring(0, dotIndex); |
| 77 | } |
| 78 | hyperstack = imp.isHyperStack(); |
| 79 | LUT[] luts = null; |
| 80 | int lutIndex = 0; |
| 81 | int nChannels = imp.getNChannels(); |
| 82 | if (hyperstack) { |
| 83 | dim = imp.getDimensions(); |
| 84 | if (imp.isComposite()) |
| 85 | luts = ((CompositeImage)imp).getLuts(); |
| 86 | if (firstTime && ndigits==4) { |
| 87 | ndigits = 3; |
| 88 | firstTime = false; |
| 89 | } |
| 90 | } |
| 91 | if (arg!=null && arg.length()>0) |
| 92 | directory = arg; |
| 93 | else { |
| 94 | if (!showDialog(imp)) |
| 95 | return; |
| 96 | } |
| 97 | try { |
| 98 | Files.createDirectories(Path.of(directory)); |
| 99 | } catch (IOException e) { |
| 100 | e.printStackTrace(); |
| 101 | } |
| 102 | File d = new File(directory); |
| 103 | if (d==null || !d.isDirectory()) { |
| 104 | IJ.error("File>Save As>Image Sequence", "Directory not found: "+directory); |
| 105 | return; |
| 106 | } |
| 107 | int number = 0; |
| 108 | if (ndigits<1) ndigits = 1; |
| 109 | if (ndigits>8) ndigits = 8; |
| 110 | int maxImages = (int)Math.pow(10,ndigits); |
| 111 | if (stackSize>maxImages && !useLabels && !hyperstack) { |
| 112 | IJ.error("Stack Writer", "More than " + ndigits |
| 113 | +" digits are required to generate \nunique file names for "+stackSize+" images."); |
| 114 | return; |
| 115 | } |
| 116 | if (format.equals("fits") && !FileSaver.okForFits(imp)) |
| 117 | return; |
| 118 | if (format.equals("text")) |
| 119 | format = "text image"; |
| 120 | String extension = "." + format; |
no test coverage detected