====== Compound Arguments ======
{{ :intermediate_level:flowcharts:hoku_intermediate_flowcharts_4.png?nolink&125|A flowchart with two nested loops}}
Say you want to loop over a series of folders: in each folder, read all the files, process them, and write the results into a folder of the same name somewhere else. The output folders must exist, so first create them with "mkdir" if they do not exist yet.
You need two nested loops: one over the folders, and one over the files in each folder.
- **start** sets the folder that contains the series of folders.
- The outer **ls** selects the folders you want, by matching them with its filter.
- **mkdir** creates a new folder to store the results.
- **cd** takes the directory and file name passed by mkdir, and passes on the combined name as the new directory, with a blank file name.
- The inner **ls** looks for the image files that match its filter.
- **exec** uses these names to run the attached job.
===== Example: pack every image in several folders =====
We will look at a few of the Smith folders. In each, we read each input image, pack it, and store the result in a folder of the same name, created in a neighboring folder.
* **start** points to ''D:\Image Files\Raws''.
* The first **ls** uses the filter ''Smith*93*'' to pick out the input folders.
* **mkdir** creates a matching ''Smith*93*'' folder in ''D:\Image Files\Packed''.
* **cd** is set to **child**, which changes the directory to "directory\file".
* The second **ls** lists each input file with the filter ''*.tif''.
The attached job has two dynamic variables: ''$input$'' in ReadImage and ''$output$'' in WriteImage. mkdir's "destination" argument creates the output folders, and exec fills in the two variables:
^ Argument ^ Entry ^
| destination (in mkdir) | ''%%$D"P"$::Packed::$F$%%'' |
| input (in exec) | ''$D$::$F$'' |
| output (in exec) | ''%%$D"PP"$::Packed::$D"F"$::$F$%%'' |
**destination**: mkdir receives ''D:\Image Files\Raws'' as the directory (''$D$''), and each Smith folder as the file name (''$F$''). The entry goes to the parent, ''D:\Image Files'', adds ''Packed'', then the Smith folder's name, giving ''D:\Image Files\Packed\Smith...'', which mkdir creates. If a folder already exists, mkdir leaves it alone.
**input** is used inside each Smith folder, so the directory is that Smith folder and the file is each image in it. The entry combines them, as usual.
**output** is the most complicated, because it uses parts of both names. It starts at the input directory and goes up two levels (''%%$D"PP"$%%''), then adds ''::Packed::'', then the Smith folder's own name (''%%$D"F"$%%''), then ''::'' and the file name.
To check an output name before writing any files, test with Show instead of WriteImage. Put ''$title$'' in Show's "title" argument, and in exec, enter the output entry you plan to use for "title". The result appears as the title of the Show window.
===== ReadStack =====
ReadStack reads several files and makes one multiband image from them. To use ReadStack in a flowchart, you need one entry in exec for each input file name.
Say you want to make a color image in each of several folders, each with its own set of input images. In folder Smith_093r, there are three images to read with ReadStack. In red, green, blue order, they are:
Smith_093r+MB630RD_11_F.tif
Smith_093r+MB530GN_07_F.tif
Smith_093r+MB450RB_04_F.tif
For the 093r folder alone, you would enter those names directly into ReadStack:
{{ :intermediate_level:flowcharts:hoku_intermediate_flowcharts_6.png?nolink&450 |ReadStack with the three file names entered directly}}
To run the job on many folders, the names must come from exec instead, using substitutions. The "ls" filter picks out one of the images, say the red one. The filter cannot include the page name (093r), because the red file's name is different in each folder. The filter ''Smith_*MB630RD_11*.tif'' passes the name of the red image file to exec, along with the name of the folder that contains it:
{{ :intermediate_level:flowcharts:hoku_intermediate_flowcharts_5.png?nolink&355 |The ls filter Smith_*MB630RD_11*.tif}}
In ReadStack, put a single dynamic variable, with any name that reminds you what it is:
{{ :intermediate_level:flowcharts:hoku_intermediate_flowcharts_7.png?nolink&450 |ReadStack with a single dynamic variable}}
In exec, enter one line for each input file. The first is the red file itself; the other two are made from it by substitution. Adjust the band names and numbers to match your own file names.
{{ :intermediate_level:flowcharts:hoku_intermediate_flowcharts_8.png?nolink&550 |The exec entries for the three file names}}
$D$::$F$
$D$::$F"S/MB630RD_11/MB530GN_07/"$
$D$::$F"S/MB630RD_11/MB450RB_04/"$
There must be only one entry in ReadStack, while exec needs one line per input file. Because the three files' names have a common structure, the parts of the names that describe the wavelength identify the three files in each folder.
===== WriteStack =====
WriteStack (an Advanced-level module) reads one multiband image and writes out one single-band image for each band. To use it in a flowchart, follow the same steps: put a single dynamic variable in WriteStack's argument, and in exec, enter one line for each output file. Each line should use the input file name, with substitutions that make a unique name for each output image.