Executing an external program |
Once all the problem type files are finished (.cnd, .mat, .prb, .sim, .bas files), you can run the solver. You may wish to run it directly from inside GiD.
To do so, it is necessary to create the file problem_type_name.bat
in the Problem Type directory. This must be a shell script that can contain any type of information and that will be different for every operating system. When you select the Caluculate option in GiD Preprocess this shell script is executed (see CALCULATE
).
Because the .bat file will be different depending on the operating system, it is possible to create two files: one for Windows and another for Unix/Linux. The Windows file has to be called: problem_type_name.win.bat;
the Unix/Linux file has to be called: problem_type_name.unix.bat.
If GiD
finds a .win.bat
or .unix.bat
file, the file problem_type_name.bat
will be ignored.
If a .bat
file exists in the problem type directory when choosing Start in the calculations window, GiD will automatically write the analysis file inside the example directory assigning the name project_name.dat
to this file (if there are more files, the names project_name-1.dat
... are used). Next, this shell script will be executed. GiD will assign three arguments to this script:
project_name
(name of the current project); c:\a\b\c\project_name.gid
(path of the current project); c:\a\b\c\problem_type_name.gid
(path of the problem type selected); Among other utilities, this script can move or rename files and execute the process until it finishes.
Note1: This file must have the executable flag set (see the UNIX command chmod) in UNIX systems.
Note2:
GiD sets as the current directory the model directory (example: c:\examples\test1.gid)
just before executing the .bat file. Therefore, the lines (cd $directory
) are not necessary in the scripts.
Commands accepted by the GiD command.exe |
The keywords are as follows:
%
Shift
Rem
Chdir (Cd)
Del (Delete, Erase)
Copy
Rename (Ren, Move)
Mkdir (Md)
Set
Echo (@echo)
If
Call
Goto
:
Type
Unknown instructions will be executed as from an external file.
Not all the possible parameters and modifiers available in the operating system are implemented in the GiD executable command.exe.
Note: At the moment, command.exe is only used in Windows operating systems as an alternative to command.com or cmd.exe. With the GiD command.exe some of the disadvantages of Windows can be avoided (the limited length of parameters, temporary use of letters of virtual units that sometimes cannot be eliminated, fleeting appearance of the console window, etc).
If GiD finds the file command.exe located next to gid.exe , it will be used to interpret the *.bat file of the problem type; if the file command.exe cannot be found, the *.bat file will be interpreted by the windows command.com.
If conflicts appear by the use of some instruction still not implemented in the GiD command.exe , it is possible to rename the command.exe file, so that GiD does not find it, and the operating system command.com is used.
%
Returns the value of a variable.
%number
%name%
Parameters
number
The number is the position (from 0 to 9) of one of the parameters which the *.bat file receives.
name
The name of an environment variable. That variable has to be declared with the instruction "set".
Note: GiD sends three parameters to the *.bat file: %1, %2, %3
%1 is the name of the current project (project_name)
%2 is the path of the current project (c:\a\b\c\project_name.gid)
%3 is path of the problem type (c:\a\b\c\problem_type_name.gid)
For example, if GiD is installed in c:\gidwin,
the "problemtype" name is cmas2d.gid
and the project is test.gid, located in c:\temp
(the project is a directory called c:\temp\test.gid
with some files inside), parameters will have the following values:
%1 test
%2 c:\temp\test.gid
%3 c:\gidwin\problemtypes\cmas2d.gid
Note:
It is possible that the file and directory names of these parameters are in the short mode Windows format. So, parameter %3 would be: c:\GIDWIN\PROBLE~\CMAS2D.GID.
Examples
echo %1 > %2\%1.txt
echo %TEMP% >> %1.txt
Shift
The shift command changes the values of parameters %0 to %9 copying each parameter in the previous one. That is to say, value %1 is copied to %0, value %2 is copied to %1, etc.
Shift
Parameter
None.
Note: The shift command can be used to create a batch program that accepts more than 10 parameters. If it specifies more than 10 parameters in the command line, those that appear after tenth (%9) will move to parameter %9 one by one.
Rem
Rem is used to include comments in a *.bat file or in a configuration file.
rem [comment]
Parameter
comment
Any character string.
Note: Some comments are GiD commands.
Chdir (Cd)
Changes to a different directory.
chdir [drive:path] [..]
-or-
cd [drive:path] [..]
Parameters
[drive:path]
Disk and path of the new directory.
[..]
Goes back one directory. For example if you are within the C:\WINDOWS\COMMAND> directory this would take you to C:\WINDOWS>.
Note: When GiD calls the *.bat file, the path of the project is the current path, so it is not necessary to use cd %2 at the beginning of the *.bat file.
Examples
chdir e:\tmp cd ..
Delete (Del, Erase) Command used to delete files permanently from the computer.
delete [drive:][path] fileName [fileName]
Parameters
[drive:][path] fileName [fileName] Parameters that specify the location and the name of the file that has to be erased from disk. Several file names can be given.
Note: Files will be eliminated although they have the hidden or read only flag. Use of wildcards is not allowed. For example del *.* is not valid. File names must be separated by spaces and if the path contains blank spaces, the path should be inside inverted commas (the short path without spaces can also be used).
Examples
delete %2\%1\file.cal
del C:\tmp\fa.dat C:\tmp\fb.dat
del "C:\Program files\test 4.txt"
Copy
Copies one or more files to another location.
copy source [+ source [+ ...]] destination
Parameters
source Specifies the file or files to be copied.
destination Specifies the filename for the new file(s).
To append files, specify a single file for destination, but multiple files for source (using the file1 + file2 + file3 format).
Note: If the destination file already exists, it will be overwritten without prompting whether or not you wish to overwrite it.
File names must be separated by spaces. If the destination only contains the path but not the filename, the new name will be the same as the source filename.
Examples
copy f1.txt f2.txt
copy f1.txt c:\tmp
rem if directory c:\tmp exists, c:\tmp\f1.txt will be created, if it does not exist, file c:\tmp will be created.
copy a.txt + b.txt + c.txt abc.txt
Rename (Ren, Move)
Used to rename files and directories from the original name to a new name.
rename [drive:][path] fileName1 fileName2
Parameter [drive:][path] fileName1 Specifies the path and the name of the file which is to be renamed.
fileName2 Specifies the new name file.
Note: If the destination file already exists, it will be overwritten without prompting whether or not you wish to overwrite it. Wildcards are not accepted (*,?), so only one file can be renamed every time. Note that you cannot specify a new drive for your destination. A directory can be renamed in the same way as if it was a file.
Examples
Rename fa.txt fa.dat
Rename "c:\Program Files\fa.txt" c:\tmp\fa.txt
Rename c:\test.gid c:\test2.gid
Mkdir (md)
Allows you to create your own directories.
mkdir[drive:]pathmd [drive:]path
Parameter
drive: Specifies the drive where the new directory has to be created.
path Specifies the name and location of the new directory. The maximum length of the path is limited by the file system.
Note: mkdir can be used to create a new path with many new directories.
Examples
mkdir e:\tmp2
mkdir d1\d2\d3
Set
Displays, sets, or removes Windows environment variables.
set variable=[string]
Parameters
variable Specifies the environment-variable name.
string Specifies a series of characters to assign to the variable.
Note: The set command creates variables which can be used in the same way as the variables %0 to %9. Variables %0 to %9 can be assigned to new variables using the set command.
To get the value of a variable, the variable has to be written inside two % symbols. For example, if the environment-variable name is V1, its value is %V1%. Variable names are not case-sensitive.
Examples
set basename = %1
set v1 = my text
Echo (@echo)
Displays messages.
echo [message]
Parameters
message Specifies the text that will be displayed in the screen.
Note: The message will not be visible because the console is not visible, since GiD hides it.Therefore, this command is only useful if the output is redirected to a file (using > or >>). The symbol > sends the text to a new file, and the symbol >> sends the text to a file if it already exists. The if and echo commands can be used in the same command line.
Examples
Echo %1 > out.txt
Echo %path% >> out.txt
If Not Exist %2\%1.flavia.res Echo "Program failed" >> %2\%1.err
If
Executes a conditional sentence. If the specified condition is true, the command which follows the condition will be executed; if the condition is false, the next line is ignored.
Parameters
not Specifies that the command has to be executed only if the condition is false.
exist file Returns true if file exists.
command Is the command that has to be executed if the condition returns true.
string1==string2 Returns true if string1 and string2 are equal. It is possible to compare two strings, or variables (for example, %1).
errorlevel number Returns true if the last program executed returned a code equal to or bigger than the number specified.
Note: Exist can also be used to check if a directory exists.
Examples
If exist sphere.igs echo File exists >> out.txt
if not exist test.gid echo Dir does not exist >> out.txt
if %1 == test echo Equal %1 >> out.txt
Call
Executes a new program.
call [drive:][path] file [parameters]
Parameter
[drive:][path] file Specifies the location and the name of the program that has to be executed.
parameters Parameters required by the program executed.
Note: The program can be *.bat file, a *.exe file or a *.com file. If the program does a recursive call, some condition has to be imposed to avoid an endless curl.
Examples
call test.bat %1
call gid.exe -n -PostResultsToBinary %1.flavia.res %1.flavia.bin
Goto
The execution jumps to a line identified by a label.
goto label
Parameter
label It specifies a line of the *.bat file where the execution will continue. That label must exist when the Goto command is executed. A label is a line of the *.bat file and starts with (:). Goto is often used with the command if, in order to execute conditional operations. The Goto command can be used with the label :EOF to make the execution jump to the end of the *.bat file and finish.
Note: The label can have more than eight characters and there cannot be spaces between them. The label name is not case-sensitive.
Example
goto :EOF
if exist %1.err goto end
...
:end
:
Declares a label.
: labelName
Parameter
labelName A string which identifies a line of the file, so that the Goto command can jump there. The label line will not be executed.
Note: The label can have more than eight characters and there cannot be spaces between them. The label name is not case-sensitive.
Examples
:my_label
:end
Type
Displays the contents of text files.
type [drive:][path] fileName
Parameters
[drive:][path] fileName Specifies the location and the name of the file to be displayed. If the file name contains blank spaces it should be inside inverted commas ("file name").
Note: The text will not be visible because the console is not visible, since GiD hides it Therefore, this command is only useful if the output is redirected to a file (using > or >>). The symbol > sends the text to a new file, and the symbol >> sends the text to a file if it already exists. It is recommended to use the copy command instead of type.
In general, the type command should not be used with binary files.
Examples
type %2\%1.dat > %2\%1.txt
Showing feedback when running the solver |
The information about what is displayed when Output view: is pressed is also given here. To determine what will be shown, the script must include a comment line in the following form:
For Windows :
rem OutputFile: %1.log
For Linux/Unix:
# OutputFile: $1.log
where $1.log means to display in that window a file whose name is: project_name.log. The name can also be an absolute name like output.dat. If this line is omitted, when you press Output view:, nothing will be displayed.
Managing errors |
A line of code like
For Windows
rem ErrorFile: %1.err
For Linux/UNIX
# ErrorFile: $1.err
included in the .bat file means that the given filename is the error file. At the end of the execution of the .bat file, if the errorfile does not exist or is zero, execution is considered to be successful. If not, an error window appears and the contents of the error file are considered to be the error message. If this line exists, GiD will delete this file just before calculating to avoid errors with previous calculations.
A comment line like
# WarningFile: $1.err
or
rem WarningFile: %1.err
included in the .bat file means that the given filename is the warning file. This file stores the warnings that may appear during the execution of the .bat file.
Examples |
Here are two examples of easy scripts to do. One of them is for Unix/Linux machines and the other one is for MS-Dos or Windows.
#!/bin/csh set basename = $1
set directory = $2
set ProblemDirectory = $3
# OutputFile: $1.log
IT IS USED BY GiD
# ErrorFile: $1.err
IT IS USED BY GiD
rm -f $basename.flavia.res
$ProblemDirectory/myprogram $basename
mv $basename.post $basename.flavia.res
rem basename=%1
JUST INFORMATIVE
rem directory=%2
JUST INFORMATIVE
rem ProblemDirectory=%3
JUST INFORMATIVE
rem OutputFile: %1.log
IT IS USED BY GiD
rem ErrorFile: %1.err
IT IS USED BY GiD
del %1.flavia.res%3\myprogram %1
move %1.post %1.flavia.res