GiD - The personal pre and post processor
*format, *intformat, *realformat
- *format, *intformat, *realformat, . These commands explain how the output of different mathematical expressions will be written to the analysis file. The use of this command consists of a line which begins with the corresponding version, *intformat, *realformat or *format (again, these are not case-sensitive), and continues with the desired writing format, expressed in C-language syntax argument, between double quotes (").
The integer definition of *intformat and the real number definition of *realformat remain unchanged until another definition is provided via *intformat and *realformat, respectively. The argument of these two commands is composed of a unique field. This is the reason why the *intformat and *realformat commands are usually invoked in the initial stages of the .bas file, to set the format configuration of the integer or real numbers to be output during the rest of the process.
The *format command can include several field definitions in its argument, mixing integer and real definitions, but it will only affect the line that follows the command's instance one. Hence, the *format command is typically used when outputting a listing, to set a temporary configuration.
In the paragraphs that follow, there is an explanation of the C format specification, which refers to the field specifications to be included in the arguments of these commands. Keep in mind that the type of argument that the *format command expects may be composed of several fields, and the *intformat and *realformat commands' arguments are composed of an unique field, declared as integer and real, respectively, all inside double quotes:
A format specification, which consists of optional and required fields, has the following form:
%[flags][width][.precision]type
The start of a field is signaled by the percentage symbol (%). Each field specification is composed of: some flags, the minimum width, a separator point, the level of precision of the field, and a letter which specifies the type of the data to be represented. The field type is the only one required.
The most common flags are:
- To left align the result
+ To prefix the numerical output with a sign (+ or -)
# To force the real output value to contain a decimal point.
The most usual representations are integers and floats. For integers the letters d and i are available, which force the data to be read as signed decimal integers, and u for unsigned decimal integers.
For floating point representation, there are the letters e, f and g, these being followed by a decimal point to separate the minimum width of the number from the figure giving the level of precision.The number of digits after the decimal point depends on the requested level of precision.
Note: The standard width specification never causes a value to be truncated. A special command exists in GiD: *SetFormatForceWidth, which enables this truncation to a prescribed number of digits.
For string representations, the letter s must be used. Characters are printed until the precision value is reached.
The following are valid examples of the use of format:
*Intformat "%5i"
With this sentence, usually located at the start of the file, the output of an integer quantity is forced to be right aligned on the fifth column of the text format on the right side. If the number of digits exceeds five, the representation of the number is not truncated.
*Realformat "%10.3e"
This sentence, which is also frequently located in the first lines of the template file, sets the output format for the real numbers as exponential with a minimum of ten digits, and three digits after the decimal point.
*format "%10i%10.3e%10i%15.6e"
This complex command will specify a multiple assignment of formats to some output columns. These columns are generated with the line command that will follow the format line. The subsequent lines will not use this format, and will follow the general settings of the template file or the general formats: *IntFormat, *RealFormat.
- *SetFormatForceWidth, *SetFormatStandard The default width specification of a "C/C+" format, never causes a value to be truncated.
*SetFormatForceWidth is a special command that allows a figure to be truncated if the number of characters to print exceeds the specified width.
*SetFormatStandard changes to the default state, with truncation disabled.
For example:
*SetFormatForceWidth *set var num=-31415.16789 *format "%8.3f" *num *SetFormatStandard *format "%8.3f" *num
Output:
-31415.1
-31415.168
The first number is truncated to 8 digits, but the second number, printed with "C" standard, has 3 numbers after the decimal point, but more than 8 digits.
COPYRIGHT © 2022 · GID · CIMNE