Argument Modifications

The example in Arguments for "exec" uses only one file name each time the job runs. What if the job needs two file names? For example, you might want to read the W365B47 image and divide it by the MB940IR image. In the “ls” module you can define a filter that selects one or the other, but only one name is passed to exec. To get the second name, you modify the first one.

A modification goes after the symbol, inside the dollar signs, between two double quotes: $D"X"$, with modification symbol “X”.

Symbol Stands for Works on
P Parent directory name
F File (the last part of the path) directory name
S, s Substitute directory and file names
R Remove file name
start#increment#end Iteration $I$

Directory changes

$D"P"$ is the parent of the directory. You can repeat P to go further up: $D"PP"$ is the parent of the parent. $D"F"$ takes the last name of the absolute path, which is the directory's own name. More than one F does not make sense, and is ignored.

Directory name C:\Image Files\Smith_093r
$D$ C:\Image Files\Smith_093r
$D"P"$ C:\Image Files
$D"PP"$ C:\
$D"F"$ Smith_093r

Writing to a different folder

To read the input image from one folder and write the output to another, add the destination folder's name after the directory modification. For example, if the input folder is “Input Images” and the output folder next to it is “Output Images”:

Input directory C:\Image Files\Input Images
Input file Smith_093r+MB940IR_023_F.tif
exec entry $D"P"$::Output Images::$F$
Result C:\Image Files\Output Images\Smith_093r+MB940IR_023_F.tif

The output folder name is written outside the $ variables, preceded by :: to separate it from the folder before it.

Any output folder must exist before the job runs; otherwise a “file cannot be written” error stops the job. You can create folders with the mkdir module; see Compound Arguments.

Writing to a different disk

The modifications so far only move between folders on the same disk. Moving to another disk works differently on macOS and Windows.

On macOS, go up to the top of the path with P, then add Volumes:: and the disk name. In this example, a file is read from the user's Desktop and written to an external drive, “Disk A”:

Input file path /Users/Smith/Desktop/image.tif
exec entry $D"PPP"$Volumes::Disk A::ImageDir::$F$
Result /Volumes/Disk A/ImageDir/image.tif

On Windows, you cannot go up the path to a place where you can switch disks, so write the disk name separately:

Input file path C:\Smith\Desktop\image.tif
exec entry D:\ImageDir::$F$
Result D:\ImageDir\image.tif

Write the disk name as in Windows, D:\, with the backslash. Elsewhere, :: is used instead of the backslash so that jobs are easier to exchange between Windows and macOS. There is no equivalent for a disk name, so use the full name, with the colon and backslash.

Substitution

The Substitute modification replaces one piece of text with another, in a directory or a file name. It is written S/target/replacement/.

For example, say the “ls” filter selects the fluorescence image W365B47, and you also want the 940 nm infrared image, MB940IR:

File name ($F$) Smith_093r+W365B47_025_F.tif
exec entry $F"S/W365B47_025/MB940IR_016/"$
Result Smith_093r+MB940IR_016_F.tif

Several substitutions

You can put several substitutions in one modification, by repeating S. For example, to rename three input files differently:

Input file Result
Smith_093r+MB450RB_04_F.tif Smith_093r_blue.tif
Smith_093r+MB530GN_07_F.tif Smith_093r_green.tif
Smith_093r+MB630RD_11_F.tif Smith_093r_red.tif

use this exec entry:

$F"S/+MB450RB_04_F/_blue/S/+MB530GN_07_F/_green/S/+MB630RD_11_F/_red/"$

With an upper-case S, at most one substitution is made for each file. Hoku searches the file name for each target phrase in turn, for example +MB450RB_04_F. When it finds one, it makes that substitution (_blue) and stops. If it finds none, the name is not changed. In this way, each file in the list can get a different substitution. Because these entries can get long, you can write them in a text editor and paste them into exec.

With a lower-case s, Hoku makes the substitution and keeps going, trying the remaining substitutions too. Use it to change two separate parts of a name:

Input file Smith_093r+MB450RB_04_F.tif
exec entry $F"s/Smith/ms68/s/tif/jpg/"$
Result ms68_093r+MB450RB_04_F.jpg

Remove

The upper-case R (Remove) modification works only on the file name. It assumes that the file name begins with the name of the folder that holds it, and removes that part, leaving the rest of the name:

Directory ($D$) C:\Image Files\Input Images\Smith_093r
File ($F$) Smith_093r+MB940IR_023_F.tif
$F"R"$ +MB940IR_023_F.tif

Iteration

The iteration parameter $I$ takes a modification that says which numbers to go through:

$I"start#increment#end"$

For example, $I"0#1#4"$ goes through the numbers 0 to 4, one at a time: 5 values. The increment can be negative.

You only need to give the range once. For example, put $band$ in ReadImage's “bands” argument and $title$ in Show's “title” argument. In exec, enter $I"0#1#4"$ for “band” and just $I$ for “title”. The job then shows bands 0 to 4, one at a time, each with its band number as the window title.