Batchmake documentation: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
 
(47 intermediate revisions by 5 users not shown)
Line 1: Line 1:
[http://www.batchmake.org/Wiki/BatchMake <back to main page]
[[BatchMake | < Main BatchMake]]
 
==Main Commands==
==Main Commands==
===AddError - Manually generates an error===
'''AddError( [<description>] ... )'''
Manually generates an error. Display the error description on the output via the ProgressManager ( std::cerr ).
If ExitOnError() has been previously set to true, the script is stopped.
'''Example :'''
If( ${my_var} != '0' )
  AddError( 'Error in segmentation. Error number:' ${my_var} )
EndIf( ${my_var} )
See Also:
ClearErrors()
Exit()
ExitOnError()
GetErrorCount()
===AppendFile - Add a string to the end of a file===
===AppendFile - Add a string to the end of a file===
'''AppendFile( <filename> <value1> <value2> ... )'''
'''AppendFile( <filename> <value1> <value2> ... )'''
Line 9: Line 26:
  sequence(seq 1 3 1)
  sequence(seq 1 3 1)
  foreach(value ${seq})
  foreach(value ${seq})
  appendFile('C:/bmtest.txt' 'value: ${value}\n')
  appendFile('C:/bmtest.txt' 'value: '${value}'\n')
  endforeach(value)
  endforeach(value)


Line 16: Line 33:
  "value: 2"
  "value: 2"
  "value: 3"
  "value: 3"
See also
WriteFile()
===ClearErrors - Reset the number of errors===
'''ClearErrors( )'''
'''Example :'''
ClearErrors( )
... # A failing action
GetErrorCount( errorcount )
echo( ${errorcount} )
ClearErrors( )
GetErrorCount( errorcount )
Echo( ${errorcount} )
Displays on screen:
1
0
See Also:
AddError()
Exit()
ExitOnError()
GetErrorCount()


===CloseTCPSocket - Close a TCP/IP socket===  
===CloseTCPSocket - Close a TCP/IP socket===  
Line 23: Line 63:
  CloseTCPSocket(MySocket)
  CloseTCPSocket(MySocket)


===CopyFile - Copy a file from disk to disk ===
'''CopyFile( <src filename> <dst filename> [<dst2 filename>] ... )'''
<br>Copy a file on disk to one or many files. It can also copy directories.
'''Example :'''
CopyFile('myfile.txt' 'copyofmyfile.txt' 'anothercopyofmyfile.txt')
See Also:
DeleteFile()
ListFileInDir()
FileExists()


===DashboardExperiment - Specify the encrypted name of the experiment to report on===
===DashboardExperiment - Specify the encrypted name of the experiment to report on===
Line 55: Line 107:
===DeleteFile - Delete a file on disk ===
===DeleteFile - Delete a file on disk ===
'''DeleteFile( <filename> )'''
'''DeleteFile( <filename> )'''
<br>Note: It also deletes directories.


'''Example :'''
'''Example :'''
  DeleteFile('myfile.txt')
  DeleteFile('myfile.txt')
See also
CopyFile()
FileExists()
GetFilename()


===DownloadXcedeDataSet - Download a DataSet from an URL===
===DownloadXcedeDataSet - Download a DataSet from an URL===
'''DownloadXcedeDataSet ( <xcedeData> <directory> [login] [password])'''
'''DownloadXcedeDataSet ( <xcedeData> <directory> [login] [password])'''


The first parameter is a "XcedeDataSet" which looks like url;name
The first parameter is a XcedeDataSet which is a camiantion between the url and the name of the file. It looks like : url;filename.


The directory is the path where the file will be downloaded.
The directory is the path where the file will be downloaded.
Line 71: Line 129:


'''Example :'''
'''Example :'''
  Set(url 'http://www.insight-journal.org/dspace/view_item.php?itemid=118#')
  Set(url '//www.insight-journal.org/dspace/view_item.php?itemid=118#')
  Set(filename MyImage.mha)
  Set(filename MyImage.mha)
  Set(url_filename "${url};${filename}")
  Set(url_filename "${url};${filename}")
Line 94: Line 152:


'''Example :'''
'''Example :'''
  Set(url 'http://central.xnat.org:8080/archive/cache/VQYPEjndn96JMCiRVniaAwA3K4Wtv2useiTCuyTkDVSjtPBvqEwPqNhFaV34LQLF')
  Set(url '//central.xnat.org:8080/archive/cache/VQYPEjndn96JMCiRVniaAwA3K4Wtv2useiTCuyTkDVSjtPBvqEwPqNhFaV34LQLF')
  Set(filename MyImage.img)
  Set(filename MyImage.img)
Set(url_filename "${url};${filename}")
  Set(path 'C://Download')
  Set(path 'C://Download')
  DownloadXnatDataSet(${filename} ${url} ${path} 'myLogin' 'myPassword')
  DownloadXnatDataSet(${url_filename} ${path} 'myLogin' 'myPassword')
or
or
  GetXnatDataSets(xnatDatas ${xnatCatalog} 'myLogin' 'myPassword')
  GetXnatDataSets(xnatDatas ${xnatCatalog} 'myLogin' 'myPassword')
Line 122: Line 181:
  value: 2 2
  value: 2 2


'''Note :'''
Single quotes prevents the variables to be expanded:
Set( foo My car is red )
Echo( '${foo}' <- ${foo} )
This script will print the following line on the screen :
${foo} <- My car is red


===ExtractSlice - Extract a slice from a 3D image volume===
===ExtractSlice - Extract a slice from a 3D image volume===
Line 127: Line 192:


'''Example :'''
'''Example :'''
  ExtractSlice('head.mha','slice.jpg',0,23)
  ExtractSlice('head.mha' 'slice.jpg' 0 23)
This command extracts the saggital slice #23 from the volume head.mha and write the extracted slice to slice.jpg
This command extracts the saggital slice #23 from the volume head.mha and write the extracted slice to slice.jpg


===ExtractString - Extract a string from a string chain===
===ExtractString - Extract a string from a string chain===
'''ExtractString( <output> <input> <lenght> [FROMEND]  [KEEPEND] )'''
'''ExtractString( <output> <input> <length> [FROMEND]  [KEEPEND] )'''


The parameter <output> will contain the <lenght> first characters of <input> if FROMEND is not set. With FROMEND the <lenght> last characters won't be copied. if KEEPEND is specified then the end of the string is returned.
The parameter <output> will contain the <length> first characters of <input> if FROMEND is not set. With FROMEND the <length> last characters won't be copied. if KEEPEND is specified then the end of the string is returned.


'''Example :'''
'''Example :'''
Line 152: Line 216:
  lo
  lo


===Exit - Stop the running script===
'''Exit( )'''
'''Example :'''
If( ${my_var} == '0' )
  Exit()
EndIf( ${my_var} )
See also
AddError()
ExitOnError()
===ExitOnError - Stop the script if an action returns an error===
'''ExitOnError(  '1' or '0' or 'true' or 'false' or 'TRUE' or ... )'''
'''Example :'''
ExitOnError( 'TrUe' )
WriteFile( ${my_file} ${my_data}) # -> WriteFile fails to write on disk. An error is returned
CopyFile( ${my_file} ${my_duplicate_file} ) # -> won't be executed
See also
AddError()
GetErrorCount()
ClearErrors()
===FileExists - check if a file exists on disk ===
'''FileExists(<myvar> <filename>)'''
'''Example :'''
FileExists(fileCreated 'myfile.mha')
If( ${myvar} == 1 )
  ...
EndIf
See also
AppendFile()
CopyFile()
DeleteFile()
GetFilename()
ListDirInDir()
ListFileInDir()
WriteFile()


===ForEach / EndForEach  - Create a "for" loop===
===ForEach / EndForEach  - Create a "for" loop===
Line 172: Line 278:
  e
  e
  f
  f
===GetErrorCount - Return the number of errors found===
GetErrorCount( <variable> )
'''Example :'''
AddError( )
WriteFile( ${my_file} ${my_data} ) # -> WriteFile fails to write ${my_file}
GetErrorCount( errorcount )
echo(${errorcount})
Displays on screen:
2
See also
AddError()
ClearErrors()
ExitOnError()
===GetFilename - Get some information about a file===
GetFilename(<outputvariale> <input> [NAME PATH PARENT_PATH EXTENSION NAME_WITHOUT_EXTENSION])
'''Example :'''
Set( my_file 'foo.txt' )
GetFilename( filewithnoextension ${my_file} NAME_WITHOUT_EXTENSION )
Echo( ${filewithnoextension} )
Prints on screen
foo
See also
FileExists()
ListDirInDir()
ListFileInDir()


===GetListSize - Return the size of sequence/list===
===GetListSize - Return the size of sequence/list===
Line 204: Line 341:
  1 5
  1 5


===GetParamCount - Return the number of items in a set===
'''GetParamCount( <variable count> <variable>  )'''
'''Example :'''
sequence(seq 1 10 1)
echo(${seq})
GetParamCount(seqSize ${seq})
echo(${seqSize})
This script will print the following lines on the screen:
1 2 3 4 5 6 7 8 9 10
11
See also:
GetParam()
Sequence()
GetErrorCount()
ForEach()


===GetXcedeDataSets - Get the DataSets form an XcedeCatalog===
===GetXcedeDataSets - Get the DataSets form an XcedeCatalog===
'''GetXcedeFilename( <urls> <xcedeCatalog> [catalogID] [login] [password])'''
'''GetXcedeDataSets( <urls;filenames> <xcedeCatalog> [catalogID] [login] [password])'''


The first parameter is a list which will contain all the urls of the catalog.
The first parameter is a list which will contain all the DataSets (url;filename) of the catalog.


The second one is an xcedeCatalog : catalog.xcede or catalog.xml for example.
The second one is an xcedeCatalog : catalog.xcede or catalog.xml for example.
Line 217: Line 373:


'''Example :'''
'''Example :'''
  GetXcedeDataSets(xcedeUrls 'Catalog.xcede' 'ID02')
  GetXcedeDataSets(xcedeDatas 'Catalog.xcede' '11')


After that you will be able to access to each filename and url that your catalog contain.
After that you will be able to access to each filename and url that your catalog contain.
ForEach(xcedeData ${xcedeDatas})
echo(${xcedeData})
EndForEach(${xcedeData})
This script will print the following lines on the screen:
//rigel/midas/download_bitstream?bitstreamid=23;ellipse4.mha
//rigel/midas/download_bitstream?bitstreamid=24;ellipse5.mha
//rigel/midas/download_bitstream?bitstreamid=25;ellipse6.mha


===GetXnatDataSets - Get the DataSets form an XcedeCatalog===
===GetXnatDataSets - Get the DataSets form an XcedeCatalog===
'''GetXnatFilename( <urls> <xcedeCatalog> [login] [password])'''
'''GetXnatDataSets( <urls;filenames> <xcedeCatalog> [login] [password])'''


The first parameter is a list which will contain all the urls of the catalog.
The first parameter is a list which will contain all the DataSets (url;filename) of the catalog.


The second one is an xnatCatalog : catalog.xml for example.
The second one is an xnatCatalog : catalog.xml for example.
Line 231: Line 395:


'''Example :'''
'''Example :'''
  GetXcedeDataSets(xnatUrls 'Catalog.xml' 'myLogin' 'mYPassword')
  GetXnatDataSets(xnatDatas 'Catalog.xml' ${xnatLogin} ${psw})
ForEach(url ${xnatUrls})
  ForEach(xnatData ${xnatDatas})
echo(${url})
  echo(${xnatData})
  GetXnatFilename(xnatFilename ${url})
  EndForEach(${xnatData})
  echo(${xnatFilename})
DownloadXnatDataSet(${xnatFilename} ${url} 'C:/')
  EndForEach(${url})


This script will print the following lines on the screen:  
This script will print the following lines on the screen:  
  arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-2_anon.img
  //central.xnat.org:8080/archive/emKizxu19ejyoO2w5FQ5yMH;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-2_anon.img
http://central.xnat.org:8080/archive/cache/ozlOTU6wIPZz5ZMNUvQpZyl4ZgtT2hkymb5D25uPSemKizxu19ejyoO2w5FQ5yMH
  //central.xnat.org:8080/archive/A5JNLmBqhv0b5GI3LZw7iDn;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-2_anon_sag_66.gif
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-2_anon_sag_66.gif
  //central.xnat.org:8080/archive/m7jStt2fGIGs0XcAwtYfFfU;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon.hdr
http://central.xnat.org:8080/archive/cache/kjy0nYMAng80CHgDGTACJJa2USCjm4liJddnWJF5JNLmBqhv0b5GI3LZw7iDk2pn
  //central.xnat.org:8080/archive/0GoncvLOR8M28QaczLpuX6e;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon.img
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon.hdr
http://central.xnat.org:8080/archive/cache/m7jStt2LKug1rVG5RIysbQbfGIGsqCnh6aVTQJDbEE0XcAwLuQfiPipeCvtYfFfU
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon.img
  http://central.xnat.org:8080/archive/cache/0Gm5UOjCMnqXr8bfNSfmnt29k4lHyoncvLOR8M28QacTRy6ublyOQq3XkzLpuX6e
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon_sag_66.gif
  http://central.xnat.org:8080/archive/cache/dpLzQ8hM61vwj2RWKUOpEBgyEoKTYW8C9dBgYmtP1Gi6QlMdtQyijRlWkJUonkBo
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-4_anon.img
http://central.xnat.org:8080/archive/cache/19ntONbyxdUPdAnaLVyupWm3zdWg7R1lFSeUN7RnIZS2J9XwZXbGUScOuAnYzaDK
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-4_anon.hdr
  http://central.xnat.org:8080/archive/cache/MRsIDez3d3O5WvXL2iPFZOrodSf4BsAcSEtpeY881ItrLof1WsPSXvFikDEkE1gZ
arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-4_anon_sag_66.gif


===GetXcedeFilename - Get the filename of an URL===
===GetXcedeFilename - Get the filename of an URL===
'''GetXcedeFilename( <filename> <URL> )'''
'''GetXcedeFilename( <filename> <XcedeData> )'''
 
The first parameter is your new varaiable : the filename.
 
The second one is A XcedeData which lokks like : url;filename.
 
Basically, this function will cut the url and will return only the filename.


If you want to use this command, you have to launch the "GetXcedeDataSets" command first.
'''Example :'''
'''Example :'''
  Set(url 'http://www.insight-journal.org/dspace/view_item.php?itemid=118#')
  Set(dataSet '//www.insight-journal.org/dspace/view_item.php?itemid=118#;JelloPhantom001_CT_000004_0.48x0.48x3.00.mha')
  GetXcedeFilename(filename ${url})
  GetXcedeFilename(filename ${dataSet})
  echo(Filename : ${filename })
  echo(Filename : ${filename})
This script will print the following line on the screen:
This script will print the following line on the screen:
  Filename : JelloPhantom001_CT_000004_0.48x0.48x3.00.mha
  Filename : JelloPhantom001_CT_000004_0.48x0.48x3.00.mha


===GetXnatFilename - Get the filename of an URL===
===GetXnatFilename - Get the filename of an URL===
'''GetXnatFilename( <filename> <URL> )'''
'''GetXnatFilename( <filename> <dataSet> )'''
 
The first parameter is your new varaiable : the filename.
 
The second one is A XnatData which looks like : url;filename.
 
Basically, this function will cut the url and will return only the filename.


If you want to use this command, you have to launch the "GetXnatDataSets" command first.
'''Example :'''
'''Example :'''
  Set(url 'http://'http://central.xnat.org:8080/archive/cache/VQYPEjndn96JMCiRVniaAwA3K4Wtv2useiTCuyTkDVSjtPBvqEwPqNhFaV34LQLF')
  Set(dataSet '//central.xnat.org:8080/archive/FaV34LQLF;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-1_anon.img')
  GetXcedeFilename(filename ${url})
  GetXcedeFilename(filename ${dataSet})
  echo(Filename : ${filename })
  echo(Filename : ${filename})
This script will print the following line on the screen:
This script will print the following line on the screen:
  Filename : arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-1_anon.img
  Filename : arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-1_anon.img


===If / EndIf - Defines a conditional statement====
===If / EndIf - Defines a conditional statement====
'''If( <variable1> == or <= or >= or != <variable2> )'''
'''If(<$variable1> ==|<=|>=|!= <$variable2> [ || <condition> ] [ && <condition> ])'''
'''EndIf( <variable> )'''
''' ... EndIf(<condition>)'''


'''Example :'''
'''Example :'''
Line 297: Line 457:
This script will print the following lines on the screen :
This script will print the following lines on the screen :
  2 <= 4
  2 <= 4
  test == test  
  test == test
 


===Inc  Increment a number by a certain amount===
===Inc  Increment a number by a certain amount===
'''Inc( <variable> <number> )'''
'''Inc( <variable> <number or variable> )'''


'''<variable> = <variable> + <number>'''
'''<variable> = <variable> + <number or variable>'''


'''Example :'''
'''Example :'''
  Set(value 2)
  Set(value 2)
Set(value2 3)
  Inc(${value} 5)
  Inc(${value} 5)
  echo(2 + 5 = ${value})
Inc(${value} ${value2})
  echo( 2 + 5 + ${value2} = ${value})


This script will print the following lines on the screen :
This script will print the following lines on the screen :
  2 + 5 = 7.000000
  2 + 5 + 3 = 10.000000


===Include - Include another batchmake script===
===Include - Include another batchmake script===
Line 363: Line 524:
This script will print the following lines on the screen:
This script will print the following lines on the screen:
  number1/ number2/ number3/
  number1/ number2/ number3/
See also
FileExists()
ListFileInDir()


===ListFileInDir - List all the files in a specified directory===
===ListFileInDir - List all the files in a specified directory===
Line 384: Line 549:
  number1.txt number2.txt number3.txt
  number1.txt number2.txt number3.txt


See also
FileExists()
ListDirInDir()
===MakeDirectory - Create a directory===
'''MakeDirectory( <dirname> )'''
Create a directory at the path dirname on your system.
'''Example'''
MakeDirectory( ${project_dir}/test )
See also
AppendFile()
CopyFile()
DeleteFile()
ListDirInDir()
ListFileInDir()
WriteFile()
===Math - Compute an algebra expression===
'''Math(<result> <var1> <operator> <var2>)'''
'''Example'''
Set( val 18 )
MakeDirectory( res ${val} / 2 )
Echo( ${res} )
This script will print the following line on the screen:
9
See also
Inc()


===OpenTCPSocket - Open a TCP/IP socket===
===OpenTCPSocket - Open a TCP/IP socket===
Line 403: Line 600:
This script will print on the screen a random number between 0 and 1 following a uniform distribution.
This script will print on the screen a random number between 0 and 1 following a uniform distribution.


===RegEx - Apply regular expressions on a variable===
'''RegEx(<newvar> <variable> <RegularExpression> <MATCH or REPLACE> [replacevar])'''
Below are the metacharacters recognized by the regular expression engine
^        Matches at beginning of a line
$        Matches at end of a line
.        Matches any single character
[ ]      Matches any character(s) inside the brackets
[^ ]    Matches any character(s) not inside the brackets
-        Matches any character in range on either side of a dash
*        Matches preceding pattern zero or more times
+        Matches preceding pattern one or more times
?        Matches preceding pattern zero or once only
()      Saves a matched expression and uses it in a later match
'''Example :'''
RegEx( result 'foo' 'o' REPLACE 'a' )
Set to result the value 'faa'
RegEx( result 'the car is green' 'c.*e' MATCH )
Set 'car is gree' to result


===Run - Execute a program in a thread===
===Run - Execute a program in a thread===
'''Run( <output variable> <'program.exe param1 param2 ....'> )'''
'''Run( <output variable> <'program.exe param1 param2 ....'> [<error variable>] [<exit status variable>])'''


The program called 'program.exe' will be launched with the parameters 'param1 param2' ...
The program called 'program.exe' will be launched with the parameters 'param1 param2 ...'<br>
<output> and <error> are filled with the std::cout and std::cerr streams of the program.<br>
<exit status> is set with the return value of the program.<br>
Note that the Application Wrapper can be used to defined the parameters as names.  
Note that the Application Wrapper can be used to defined the parameters as names.  


'''Example :'''
'''Example :'''
  Run( output 'MyProgram.exe -in input -out output' )
  Run( prog_output 'MyProgram.exe -in input -out output' prog_error prog_status)
Or
Set( my_program MyProgram.exe)
Set( my_input input)
Set( my_output output)
Set( command_line ${my_program} -in ${my_input} -out ${my_output} )
Run( prog_output ${command_line} prog_error)
Or:
Set( my_program MyProgram.exe)
Set( my_input input)
Set( my_output output)
Run( prog_output ${my_program}' -in '${my_input}' -out '${my_output} prog_error prog_exit_status)
In this last example, make sure you do not have space between ${my_program} and the parameter 'quote'.<br>
Or using the Application Wrapper (if MyProgram.exe is already wrapped ):
SetApp( my_program @MyProg )
SetAppOption( my_program.in ${my_input} )
SetAppOption( my_program.out ${my_output} )
Run( prog_output ${my_program} prog_error)


This script will run the program called MyProgram.exe with the parameters input and output.
This script will run the program called MyProgram.exe with the parameters input and output.


===SendTCP - Send a message thru a TCP socket===
===SendTCP - Send a message thru a TCP socket===
Line 445: Line 680:
  echo(${example})
  echo(${example})


This script will print the following lines on the screen :
This script will print the following line on the screen :
  name1 name2 name3  
  name1 name2 name3
 
Set( foo name )
Set( bar ${foo} )
Echo( ${bar} )
 
This script will print the following line on the screen :
name


'''Note'''
Single quotes prevents the variables to be expanded:
Set( foo name )
Set( bar '${foo}' )
Echo( ${bar} )
This script will print the following line on the screen :
${bar}


===SetApp - Assign a variable to an Application defined by the Application Wrapper===
===SetApp - Assign a variable to an Application defined by the Application Wrapper===
Line 503: Line 752:
This script will print the following lines into the file : F:\example.txt :
This script will print the following lines into the file : F:\example.txt :
  12345678910end
  12345678910end
See also
AppendFile()
CopyFile()
DeleteFile()

Latest revision as of 15:55, 3 February 2011

< Main BatchMake

Main Commands

AddError - Manually generates an error

AddError( [<description>] ... )

Manually generates an error. Display the error description on the output via the ProgressManager ( std::cerr ). If ExitOnError() has been previously set to true, the script is stopped.

Example :

If( ${my_var} != '0' )
 AddError( 'Error in segmentation. Error number:' ${my_var} )
EndIf( ${my_var} )

See Also:

ClearErrors()
Exit()
ExitOnError()
GetErrorCount()

AppendFile - Add a string to the end of a file

AppendFile( <filename> <value1> <value2> ... )

The first parameter is the name of the file and all the others parameters will be added at the end of this file.

Example :

sequence(seq 1 3 1)
foreach(value ${seq})
appendFile('C:/bmtest.txt' 'value: '${value}'\n')
endforeach(value)

This script will add the following strings at the end of the file entitled "C:/bmtest.txt" :

"value: 1"
"value: 2"
"value: 3"

See also

WriteFile()

ClearErrors - Reset the number of errors

ClearErrors( )

Example :

ClearErrors( )
... # A failing action
GetErrorCount( errorcount )
echo( ${errorcount} )
ClearErrors( ) 
GetErrorCount( errorcount )
Echo( ${errorcount} )

Displays on screen:

1
0

See Also:

AddError()
Exit()
ExitOnError()
GetErrorCount()

CloseTCPSocket - Close a TCP/IP socket

CloseTCPSocket( <SocketName> )

Example :

CloseTCPSocket(MySocket)


CopyFile - Copy a file from disk to disk

CopyFile( <src filename> <dst filename> [<dst2 filename>] ... )
Copy a file on disk to one or many files. It can also copy directories.

Example :

CopyFile('myfile.txt' 'copyofmyfile.txt' 'anothercopyofmyfile.txt')

See Also:

DeleteFile()
ListFileInDir()
FileExists()

DashboardExperiment - Specify the encrypted name of the experiment to report on

DashboardExperiment( <encryptedExperiment> )

The encryptedExperiment is given when creating a new experiment online (this requires a login/pass)

Example :

DashboardExperiment( 7YF04vELWW4m1B88t)


DashboardHost - Specify the hostname of the central database manager

DashboardHost( <hostname> )

Example :

DashboardHost(www.kitware.com)

DashboardNotify - Add a new string to the central database

DashboardNotify( <message> )

Example :

DashboardNotify('End of first experiment')


DashboardSend - Send the results of a program to the central database for data collection

DashboardSend( <methodid> <value1> <value2> )

Example :

DashboardSend(1,${value1},${value2})


DeleteFile - Delete a file on disk

DeleteFile( <filename> )
Note: It also deletes directories.

Example :

DeleteFile('myfile.txt')

See also

CopyFile()
FileExists()
GetFilename()

DownloadXcedeDataSet - Download a DataSet from an URL

DownloadXcedeDataSet ( <xcedeData> <directory> [login] [password])

The first parameter is a XcedeDataSet which is a camiantion between the url and the name of the file. It looks like : url;filename.

The directory is the path where the file will be downloaded.

The two last one are the parameters of connection. Sometimes you need them to be allowed to access to an XcedetDataBase.

Attention : If your filename looks like 'dir1/dir2/filename.img', and if dir1 exists, but dir2 doesn't : it will be created.

Example :

Set(url '//www.insight-journal.org/dspace/view_item.php?itemid=118#')
Set(filename MyImage.mha)
Set(url_filename "${url};${filename}")
Set(path 'C://Download')
DownloadXcedeDataSet(${url_filename} 'C:/Downloads' myLogin myPassword)

or

GetXcedeDataSets(xcedeDatas 'Catalog.xcede' '11' 'myLogin'   'myPassword')
ForEach(xcedeData ${xcedeDatas})
DownloadXcedeDataSet(${xcedeData} 'C:/Downloads' 'myLogin'  'myPassword')
EndForEach(${xcedeData})

DownloadXnatDataSet - Download a DataSet from an URL

DownloadXnatDataSet ( <XnatDataSet> <directory> [login] [password])

The first parameter is a XnatDataSet which is a camiantion between the url and the name of the file. It looks like : url;filename.

The directory is the path where the file will be downloaded.

The two last one are the parameters of connection. Sometimes you need them to be allowed to access to an XnatDataBase.

Attention : If your filename looks like 'dir1/dir2/filename.img', and if dir1 exists, but dir2 doesn't : it will be created.

Example :

Set(url '//central.xnat.org:8080/archive/cache/VQYPEjndn96JMCiRVniaAwA3K4Wtv2useiTCuyTkDVSjtPBvqEwPqNhFaV34LQLF')
Set(filename MyImage.img)
Set(url_filename "${url};${filename}")
Set(path 'C://Download')
DownloadXnatDataSet(${url_filename} ${path} 'myLogin' 'myPassword')

or

GetXnatDataSets(xnatDatas ${xnatCatalog} 'myLogin' 'myPassword')
ForEach(xnatData ${xnatDatas})
DownloadXnatDataSet(${xnatData} 'C:/Downloads' 'myLogin' 'myPassword')
EndForEach(${xnatData})

Echo - Print messages on the standard output

Echo( <value1> <value2> ... )

Example :

sequence(seq 1 2 1)
sequence(seq2 1 2 1)
foreach(value ${seq})
foreach(value2 ${seq2})
Echo(value: ${value} ${value2})
endforeach(value2)
endforeach(value)

This script will print the following lines on the screen :

value: 1 1
value: 1 2
value: 2 1
value: 2 2

Note : Single quotes prevents the variables to be expanded:

Set( foo My car is red )
Echo( '${foo}' <- ${foo} )

This script will print the following line on the screen :

${foo} <- My car is red

ExtractSlice - Extract a slice from a 3D image volume

ExtractSlice( <3D image filename> <2D image filename> <orientation> <slice> )

Example :

ExtractSlice('head.mha' 'slice.jpg' 0 23)

This command extracts the saggital slice #23 from the volume head.mha and write the extracted slice to slice.jpg

ExtractString - Extract a string from a string chain

ExtractString( <output> <input> <length> [FROMEND] [KEEPEND] )

The parameter <output> will contain the <length> first characters of <input> if FROMEND is not set. With FROMEND the <length> last characters won't be copied. if KEEPEND is specified then the end of the string is returned.

Example :

set(example 'hello')
extractstring(result ${example} 1)
extractstring(result2 ${example} 2 FROMEND)
extractstring(result3 ${example} 2 KEEPEND)
extractstring(result4 ${example} 2 FROMEND KEEPEND) 
echo(${result})
echo(${result2})
echo(${result3})
echo(${result4})

This script will print the following lines on the screen :

h
hel
llo
lo

Exit - Stop the running script

Exit( )

Example :

If( ${my_var} == '0' )
 Exit()
EndIf( ${my_var} )

See also

AddError()
ExitOnError()

ExitOnError - Stop the script if an action returns an error

ExitOnError( '1' or '0' or 'true' or 'false' or 'TRUE' or ... )

Example :

ExitOnError( 'TrUe' )
WriteFile( ${my_file} ${my_data}) # -> WriteFile fails to write on disk. An error is returned
CopyFile( ${my_file} ${my_duplicate_file} ) # -> won't be executed

See also

AddError()
GetErrorCount()
ClearErrors()

FileExists - check if a file exists on disk

FileExists(<myvar> <filename>)

Example :

FileExists(fileCreated 'myfile.mha')
If( ${myvar} == 1 )
 ...
EndIf

See also

AppendFile()
CopyFile()
DeleteFile()
GetFilename()
ListDirInDir()
ListFileInDir()
WriteFile()

ForEach / EndForEach - Create a "for" loop

ForEach( <variable> <sequence> )

EndForEach( <variable> )

During the ith iteration, <variable> contains the ith parameter of <sequence>. The EndForEach command allows to define the end of the loop.

Example :

set(seq a b c d e f)
ForEach(letter ${seq})
echo(${letter})
EndForEach(letter)

This script will print the following lines on the screen :

a
b
c
d
e
f

GetErrorCount - Return the number of errors found

GetErrorCount( <variable> )

Example :

AddError( )
WriteFile( ${my_file} ${my_data} ) # -> WriteFile fails to write ${my_file}
GetErrorCount( errorcount )
echo(${errorcount})

Displays on screen:

2

See also

AddError()
ClearErrors()
ExitOnError()

GetFilename - Get some information about a file

GetFilename(<outputvariale> <input> [NAME PATH PARENT_PATH EXTENSION NAME_WITHOUT_EXTENSION])

Example :

Set( my_file 'foo.txt' )
GetFilename( filewithnoextension ${my_file} NAME_WITHOUT_EXTENSION )
Echo( ${filewithnoextension} )

Prints on screen

foo

See also

FileExists()
ListDirInDir()
ListFileInDir()

GetListSize - Return the size of sequence/list

GetListSize( <new variable> <sequence>)

Example : sequence(seq 1 9 1) GetListSize(size ${seq}) echo(${size})

will return:

10

GetParam - Access directly a parameter from a sequence/list

GetParam( <new variable> <sequence> <number> [<number2>] ... )

<number> corresponds to the argument of <sequence> to copy into <new variable>. We can copy as many arguments of <sequence> as we want adding at the end the rank of the argument in <sequence>.

Example :

sequence(seq 1 7 2)
echo(${seq})
GetParam(new1 ${seq} 0)
GetParam(new2 ${seq} 3)
echo(${new1})
echo(${new2})
GetParam(new ${seq} 0 2)
echo(${new})

This script will print the following lines on the screen:

1 3 5 7
1
7
1 5


GetParamCount - Return the number of items in a set

GetParamCount( <variable count> <variable> )

Example :

sequence(seq 1 10 1)
echo(${seq})
GetParamCount(seqSize ${seq})
echo(${seqSize})

This script will print the following lines on the screen:

1 2 3 4 5 6 7 8 9 10
11

See also:

GetParam()
Sequence()
GetErrorCount()
ForEach()

GetXcedeDataSets - Get the DataSets form an XcedeCatalog

GetXcedeDataSets( <urls;filenames> <xcedeCatalog> [catalogID] [login] [password])

The first parameter is a list which will contain all the DataSets (url;filename) of the catalog.

The second one is an xcedeCatalog : catalog.xcede or catalog.xml for example.

The third one (which is an option) is the ID of the catalog you are looking for, if you don't want all the catalogs in the main one.

login et password are sometimes required to connect to an xcede database.

Example :

GetXcedeDataSets(xcedeDatas 'Catalog.xcede' '11')

After that you will be able to access to each filename and url that your catalog contain.

ForEach(xcedeData ${xcedeDatas})
echo(${xcedeData})
EndForEach(${xcedeData})

This script will print the following lines on the screen:

//rigel/midas/download_bitstream?bitstreamid=23;ellipse4.mha
//rigel/midas/download_bitstream?bitstreamid=24;ellipse5.mha
//rigel/midas/download_bitstream?bitstreamid=25;ellipse6.mha

GetXnatDataSets - Get the DataSets form an XcedeCatalog

GetXnatDataSets( <urls;filenames> <xcedeCatalog> [login] [password])

The first parameter is a list which will contain all the DataSets (url;filename) of the catalog.

The second one is an xnatCatalog : catalog.xml for example.

login et password are sometimes required to connect to an xnat database.

Example :

GetXnatDataSets(xnatDatas 'Catalog.xml' ${xnatLogin} ${psw})
ForEach(xnatData ${xnatDatas})
echo(${xnatData})
EndForEach(${xnatData})

This script will print the following lines on the screen:

//central.xnat.org:8080/archive/emKizxu19ejyoO2w5FQ5yMH;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-2_anon.img
//central.xnat.org:8080/archive/A5JNLmBqhv0b5GI3LZw7iDn;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-2_anon_sag_66.gif
//central.xnat.org:8080/archive/m7jStt2fGIGs0XcAwtYfFfU;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon.hdr
//central.xnat.org:8080/archive/0GoncvLOR8M28QaczLpuX6e;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-3_anon.img

GetXcedeFilename - Get the filename of an URL

GetXcedeFilename( <filename> <XcedeData> )

The first parameter is your new varaiable : the filename.

The second one is A XcedeData which lokks like : url;filename.

Basically, this function will cut the url and will return only the filename.

Example :

Set(dataSet '//www.insight-journal.org/dspace/view_item.php?itemid=118#;JelloPhantom001_CT_000004_0.48x0.48x3.00.mha')
GetXcedeFilename(filename ${dataSet})
echo(Filename : ${filename})

This script will print the following line on the screen:

Filename : JelloPhantom001_CT_000004_0.48x0.48x3.00.mha

GetXnatFilename - Get the filename of an URL

GetXnatFilename( <filename> <dataSet> )

The first parameter is your new varaiable : the filename.

The second one is A XnatData which looks like : url;filename.

Basically, this function will cut the url and will return only the filename.

Example :

Set(dataSet '//central.xnat.org:8080/archive/FaV34LQLF;arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-1_anon.img')
GetXcedeFilename(filename ${dataSet})
echo(Filename : ${filename})

This script will print the following line on the screen:

Filename : arc001/OAS1_0289_MR1/RAW/OAS1_0289_MR1_mpr-1_anon.img

If / EndIf - Defines a conditional statement=

If(<$variable1> ==|<=|>=|!= <$variable2> [ || <condition> ] [ && <condition> ]) ... EndIf(<condition>)

Example :

set(var1 2)
set(var2 4)
If(${var1} <= ${var2})
echo(${var1} <= ${var2})
EndIf(${var1})

set(char1 test)
set(char2 test)
If(${char1} == ${char2})
echo(${char1} == ${char2})
EndIf(${char1})

This script will print the following lines on the screen :

2 <= 4
test == test

Inc Increment a number by a certain amount

Inc( <variable> <number or variable> )

<variable> = <variable> + <number or variable>

Example :

Set(value 2)
Set(value2 3)
Inc(${value} 5)
Inc(${value} ${value2})
echo( 2 + 5 + ${value2} = ${value})

This script will print the following lines on the screen :

2 + 5 + 3 = 10.000000

Include - Include another batchmake script

Include( <ScriptFilename> )

Example :

#Script1 : F:\Script1.bms
echo('Script1')

#Script2 : F:\Script2.bms
echo('Script2')

#Script3 :
Include(F:\Script1.bms)
Include(F:\Script2.bms)

When we execute Script3 the following lines will be printed on the screen :

Script1
Script2

Int - Convert a variable to integer

Int( <variable> )

Example :

Set(value 2)
Inc(${value} 5)
Int(${value})
echo(2 + 5 = ${value})

This script prints the following lines on the screen:

2 + 5 = 7  ( instead of 7.000000 if we Int() is not used)


ListDirInDir - List all the directories in a specified directory

ListDirInDir( <dirlist> <directory> [ *.* ] )

<dirlist> contains the name of all the subdirectories included in <directory>. We can also list only the subdirectories with a specific string in their names : for instance if 'doc*' is added at the end of ListDirInDir only the subdirectories started wtih 'doc' will be listed.

Example :

Structure of the Hard Drive :
 F:\
    Example
         number1
         number2
         number3
set(dir F:\Example)
ListDirInDir(example ${dir})
echo(${example})

This script will print the following lines on the screen:

number1/ number2/ number3/

See also

FileExists()
ListFileInDir()

ListFileInDir - List all the files in a specified directory

ListFileInDir( <filelist> <directory> [ *.* ] )

<filelist> contains the name of all the files included in <directory>. We can also list only the files with a specific string in their names : for instance if *.txt' is added at the end of ListFileInDir only the files wtih the '.txt' extension will be listed.

Example :

Structure of the Hard Drive :
 F:\
    Example
        number1.txt
        number2.txt
        number3.txt 
set(dir F:\Example)
ListFileInDir(example ${dir})
echo(${example})

This script will print the following lines on the screen:

number1.txt number2.txt number3.txt

See also

FileExists()
ListDirInDir()

MakeDirectory - Create a directory

MakeDirectory( <dirname> ) Create a directory at the path dirname on your system.

Example

MakeDirectory( ${project_dir}/test )

See also

AppendFile()
CopyFile()
DeleteFile()
ListDirInDir()
ListFileInDir()
WriteFile()

Math - Compute an algebra expression

Math(<result> <var1> <operator> <var2>)

Example

Set( val 18 )
MakeDirectory( res ${val} / 2 )
Echo( ${res} )

This script will print the following line on the screen:

9

See also

Inc()

OpenTCPSocket - Open a TCP/IP socket

OpenTCPSocket( <SocketName> <IPAddress> <Port> )

Example :

OpenTCPSocket(MySocket,10.0.0.1,8081)


Randomize - Create a random number

Randomize( <variable> <uniform | gaussian | categorical> <min> <max> )

<variable> contains the result. The distribtion can be set thanks to one of these 3 words : uniform, gaussian or categorical. The range an be set thanks to <min> and <max>.

Example :

Randomize(result uniform 0 1)
echo(${result}) 

This script will print on the screen a random number between 0 and 1 following a uniform distribution.


RegEx - Apply regular expressions on a variable

RegEx(<newvar> <variable> <RegularExpression> <MATCH or REPLACE> [replacevar]) Below are the metacharacters recognized by the regular expression engine

^        Matches at beginning of a line
$        Matches at end of a line
.        Matches any single character
[ ]      Matches any character(s) inside the brackets
[^ ]     Matches any character(s) not inside the brackets
-        Matches any character in range on either side of a dash
*        Matches preceding pattern zero or more times
+        Matches preceding pattern one or more times
?        Matches preceding pattern zero or once only
()       Saves a matched expression and uses it in a later match

Example :

RegEx( result 'foo' 'o' REPLACE 'a' )

Set to result the value 'faa'

RegEx( result 'the car is green' 'c.*e' MATCH )

Set 'car is gree' to result

Run - Execute a program in a thread

Run( <output variable> <'program.exe param1 param2 ....'> [<error variable>] [<exit status variable>])

The program called 'program.exe' will be launched with the parameters 'param1 param2 ...'
<output> and <error> are filled with the std::cout and std::cerr streams of the program.
<exit status> is set with the return value of the program.
Note that the Application Wrapper can be used to defined the parameters as names.

Example :

Run( prog_output 'MyProgram.exe -in input -out output' prog_error prog_status)

Or

Set( my_program MyProgram.exe)
Set( my_input input)
Set( my_output output)
Set( command_line ${my_program} -in ${my_input} -out ${my_output} )
Run( prog_output ${command_line} prog_error)

Or:

Set( my_program MyProgram.exe)
Set( my_input input)
Set( my_output output)
Run( prog_output ${my_program}' -in '${my_input}' -out '${my_output} prog_error prog_exit_status)

In this last example, make sure you do not have space between ${my_program} and the parameter 'quote'.
Or using the Application Wrapper (if MyProgram.exe is already wrapped ):

SetApp( my_program @MyProg )
SetAppOption( my_program.in ${my_input} )
SetAppOption( my_program.out ${my_output} )
Run( prog_output ${my_program} prog_error)

This script will run the program called MyProgram.exe with the parameters input and output.

SendTCP - Send a message thru a TCP socket

SendTCP( <SocketName> <message> )

The socket should be open using OpenTCPSocket and closed via CloseTCPSocket

Example :

SendTCP(MySocket 'my message to send')


Sequence - Create a sequence of numbers

Sequence( <variable> <From> <To> <Step> )

A sequence starting at <From> ending at <To> with a step of <Step> is generated and stored in <variable>.

Example :

sequence(seq 0 10 2)
echo(${seq})

This script will print the following lines on the screen :

0 2 4 6 8 10


Set - Assign a value to a variable

Set( <variable> <name1> <name2> ... )

Example :

Set(example name1 name2 name3)
echo(${example})

This script will print the following line on the screen :

name1 name2 name3
Set( foo name )
Set( bar ${foo} )
Echo( ${bar} )

This script will print the following line on the screen :

name

Note Single quotes prevents the variables to be expanded:

Set( foo name )
Set( bar '${foo}' )
Echo( ${bar} )

This script will print the following line on the screen :

${bar}

SetApp - Assign a variable to an Application defined by the Application Wrapper

'SetApp( <variable> <application> )

Before using this command we must declare the program we want to execute in Application Wraper ( clic on the Application Wrapper button -> new ).

Example :

SetApp( prog @MyProgam)
Run(output ${prog})
 

This script will run the software called MyProgram.

NOTE : When the @ key is pressed the list of the programs known by Application Wrapper is displayed.


SetAppOption - Assign a value to a predefined option of a program

SetAppOption( <application.option> <value> )

Before using this command we must use the SetApp command to set an application.

Warning : We can only use this command if the software use the MetaCommand library to parse its arguments.

Example :

SetApp(prog @MyProgam)
SetAppOption( prog.input MyInput )
SetAppOption( prog.output MyOutput )
Run(output ${prog})

This script is equivalent to : MyProgram.exe -in MyInput -out MyOutput.

NOTE : When the "." key is pressedafter the nam eof the application the list of the option available is displayed.


Sin - Evaluate the sin() function

Sin( <output variable> <input> )

The input number must be given in radian.

Example :

Sin(result 1.57)
echo(${result})

This script wiill print the following lines on the screen :

1.000000

WriteFile - Write variables into a file

WriteFile( <filename> <variable1> <variable2> ... )

Example :

sequence(seq 1 10 1)
set(end 'end')
WriteFile(F:\example.txt ${seq} ${end})

This script will print the following lines into the file : F:\example.txt :

12345678910end

See also

AppendFile()
CopyFile()
DeleteFile()