PV-WAVE Foundation > Programmer Guide > Format Strings > Group Repeat Specifications
Group Repeat Specifications
For data that is not all the same type, but follows a regularly repeated pattern in the file, you can use a nested format specification enclosed in parentheses as part of the format string. This is called a group specification, and has the following form:
[n](q1f1s1f2s2...fnqn)
A group specification consists of an optional repeat count n followed by a format specification enclosed in parentheses. The specification inside the parentheses is reused n times before more of the string is processed.
Use of group specifications allows more compact format specifications to be written. For example, the format specification:
Format='("Result: ", "<", I5, ">", "<", I5, ">")'
can be written more concisely using a group specification:
Format='("Result: ", 2("<", I5, ">"))'
If the repeat count is one, or is not given, the parentheses serve only to group format codes for use in format reversion.
Example—Using Group Repeat Specifications to Read Data File
Suppose you had a data file that contains data that needs to be read into three variables; the file is organized like the file shown below:
Bullwinkle
Boris
Natasha
Rocky
 
 
10
11
10
11
 
 
1000.0
9000.97
1100.0
0.0
0.0
2000.0
5000.0
3000.0
1000.12
3500.0
6000.0
900.0
400.0
500.0
1300.10
350.0
745.0
3000.0
200.0
100.0
100.0
50.0
60.0
0.25
950.0
1050.0
1350.0
410.0
797.0
200.36
2600.0
2000.0
1500.0
2000.0
1000.0
400.0
1000.0
9000.0
1100.0
0.0
0.0
2000.37
5000.0
3000.0
1000.01
3500.0
6000.0
900.12
The following statements read the data file shown above and place the data into three variables:
; Create variables to hold the name, number of years, and monthly
; salaries.
name = STRARR(4) & years = INTARR(4)
salary = FLTARR(12, 4)
; DC_READ_FIXED transfers the values in “bullwinkle.wp” to the
; variables in the variable list, working from left to right. Two
; slashes in the format string force DC_READ_FIXED to switch to 
; a new record in the input file.
status = DC_READ_FIXED('bullwinkle.wp', name, years, salary, $ 
Format= "(4A16, " + "/, I3, 3(10X,I3), /, 48(F7.2, 3X))", $
Ignore=["$BLANK_LINES"])
When reading row-oriented data with DC_READ_FIXED, each variable is “filled up” before any data is transferred to the next variable in the variable list. The four strings are transferred into the variable name, the four integers are transferred into the variable years, and the 48 floating-point values are transferred into the variable salary.
Because this example uses one of the “DC” functions, the data could also be read using C format specifiers:
status = DC_READ_FIXED('bullwinkle.wp', name, years, salary, $ 
Ignore= ["$BLANK_LINES"], Format="4%s 4%i 48%f")
 
note
The value of the Ignore keyword in the statements shown above insures that all blank lines are skipped instead of being interpreted as zeroes.