The user can declare and use character variables in the same way as INTEGERs and REALs. The default maximum number of character variable is 50, but this can be altered in SATLIT.
Variables are declared by the command CHAR (CHARACter being already reserved PIL word); eg CHAR(CH1,CH2,CH3,CH4).
CHAR variables, which are 68 elements long, are defaulted to a blank line.
Variables are assigned by statements such as:
CH1 = <character expression>.
Permitted character expressions are:
:<character variable>: <character string> or any concatenation of these two.
If, for example, the following PIL instructions are issued:
NX=2;NY=4;NZ=8
CHAR(CH1,CH2,CH3)
CH1=XXX;CH2=XXXZZ
the following assign the indicated values to CH3 ;
CH3=CH1 | is equivalent to | CH3 = CH1 |
CH3=:CH1: | is equivalent to | CH3 = XXX |
CH3=CH1:CH1:QQQ:CH2: | is equivalent to | CH3 = CH1XXXQQQXXXZZ |
The values of individual variables can be ascertained by typing the variable name (as with integers and reals). Alternatively, typing SEE C gives the values of all currently-declared character variables
Character-variable names placed between colons have their values substituted for their names. This process is actually carried out at a pre-processing stage and applies to integer and real expressions a well as character-variable names. It therefore has more power than merely allowing string concatenation, as will now be illustrated.
The following two PIL statements are exactly equivalent:
NX=4;PATCH(INL:NX:,NORTH,1,:NX:,1,NY,1,1,1,1)
NX=4;PATCH(INL4,NORTH,1,4,1,NY,1,1,1,1)
This feature can be used to set real or integer variables from character variables, as shown below:
REAL(RR);CHAR(CC)
CC=4.5
RR=:CC:
XFRAC(4)=:RR:
However, RR=CC would elicit an 'Invalid variable' message.
PIL commands are usually upper-cased and compressed to remove all spaces before processing. This means that unless avoiding action is taken, character strings may not be displayed as expected.
To prevent a character string from being upper-cased and compressed it should be enclosed in quote marks '. Thus whereas
CHAR(AA)
AA=Hello world
MESG(:AA:
will display
HELLOWORLD
If the string is enclosed in quotes
AA='Hello world'
MESG(:AA:
will display
Hello world
To display a quote , a double quote must be used, as shown here:
CHAR(AA,BB)
AA='It''s my party'; BB=' and I''ll cry if I want to'
MESG(:AA::BB:
will display
It's my party and I'll cry if I want to
-----------------------------------
The following character variables are recognised by PIL:
TITLE, NAMFI, NAMGRD, NAMSAT, NAMXYZ, NSAVE, CSG1, CSG2, ..., CSG10.
The following character arrays are recognised by PIL:
CG, NAME, NAMPAT.
See the entry CHAR for declarations of users' own character variables.