Easy Date Converter Advanced Version
Arrays
 

Arrays in EDC are 1-dimensional and are 1-based. An array is declared and initialized as shown by the following example:

date format = M/D/Y

ARRAY data CE
1/27/2004
2/25/2006
2/25/2008
ENDARRAY

This results in an array whose elements can be referenced by means of data[1], data[2] and data[3].

Formally an array is declared and its elements defined as follows:

ARRAY {array_name} [{calendar_specification} [{mask}]]
{one or more lines with dates or numbers}
ENDARRAY

calendar_specification is either one of the usual calendar codes (CE, ISO, etc.) or is NUM, to indicated that the data is numerical rather than calendrical. It defaults to CE.

mask controls how the data as it occurs in the program text is converted into the actual data in the array. Usually there is no need to use a mask. An illustration of the use of a mask is given in Example F2 below.

After an array has been defined the number of elements in that array may be ascertained by using the COUNT(array_name) function.

An array, once defined, may not be redefined. But the values of elements within the array may be changed, e.g., data[2] = 12/31/2000. The number of elements in an array cannot be changed. If COUNT(data) is 3 then data[4] = 12/31/2000 is invalid.

After an array has been defined one may process each of the elements in the array sequentially by means of the DOFOREACH statement.

DOFOREACH array_name AS variable_name
{some statements here}
ENDDO

The statements between DOFOREACH and ENDDO, which will make use of variable_name, are executed for each element in the array, and variable_name holds the value of that element.

The EXITDO statement may be used within a DOFOREACH block in the usual way (as shown in Example F2).

DOFOREACH blocks may be nested, as shown in the following example.


Example F1

Input file Result in output window
//  Example F1

date format = M/D/Y

ARRAY data CE
1/27/2004
2/25/2006
2/25/2008
ENDARRAY

ARRAY n NUM
2
4
ENDARRAY

output: Array 'data' has;
output: COUNT(data);
output: elements.

output: Array 'n' has;
output: COUNT(n);
output: elements.
bl

DOFOREACH data AS date
    DOFOREACH n AS num_days
        output: DateVal(date,CE);
        output: plus;
        output: Val(num_days);
        output: days is;
        d = date
        d += num_days
        output: DateVal(d,CE)
    ENDDO
    bl
ENDDO
Array 'data' has 3 elements.
Array 'n' has 2 elements.

01/27/2004 CE plus 2 days is 01/29/2004 CE
01/27/2004 CE plus 4 days is 01/31/2004 CE

02/25/2006 CE plus 2 days is 02/27/2006 CE
02/25/2006 CE plus 4 days is 03/01/2006 CE

02/25/2008 CE plus 2 days is 02/27/2008 CE
02/25/2008 CE plus 4 days is 02/29/2008 CE


Example F2

The ARRAY statement is typically used for batch processing which cannot be done by means of the operations of adding or subtracting a number of days to or from a date, or getting the number of days between two dates. (Such batch operations are described in Batch Processing.) If the input data is not quite in the format needed then the use of the mask parameter allows the input data to be converted into the form of the data needed. An example is given below.

In this example we suppose that we have a set of names of files, where the first four characters specifies, say, a location, the next four characters specifies a year, and the 3-character file suffix specifies a day in that year. We wish to obtain the ordinal dates which are coded in the filenames.

The statement ARRAY data ORD ----****-*** says that the array is named data and that the data is to be regarded as ordinal dates. The mask ----****-*** is laid over each data line, and all characters in the data line are ignored except those whose positions in the data line are the positions of an asterisk in the mask. Thus 59552005.126 is read as 2005126 and so on. Since the data is specified as ORD (ordinal) data, 2005126 is stored in the first element of the array not as 2,005,126 but rather as the Julian day number 2,453,497. When displayed in the form of a CE date it is expressed as 2005-05-06 CE, as shown below.

Input file Result in output window
//  Example F2

hyphen = N

ARRAY filename ORD ----****-***
59552005.126
82882005.192
82992005.211
59552006.033
82882006.191
59552006.301
29102007.003
19912007.213
ENDARRAY

output: Array 'filename' has;
output: COUNT(filename);
output: elements.
bl

date = filename[1]
Call OutputOrdinalEquivalent(date)
date = filename[6]
Call OutputOrdinalEquivalent(date)
bl

DOFOREACH filename AS ord_date
    IF YearOf(ord_date,CE) > 2006 THEN
        EXITDO
    ENDIF
    Call OutputOrdinalEquivalent(ord_date)
ENDDO
bl

filename[3] = 2008001 ORD
Call OutputOrdinalEquivalent(filename[3])

SUB OutputOrdinalEquivalent(ordinal_date)
output: DateVal(ordinal_date,ORD);
output: =;
output: DateVal(ordinal_date,CE)
ENDSUB
Array 'filename' has 8 elements.

2005126 ORD = 2005-05-06 CE
2006301 ORD = 2006-10-28 CE

2005126 ORD = 2005-05-06 CE
2005192 ORD = 2005-07-11 CE
2005211 ORD = 2005-07-30 CE
2006033 ORD = 2006-02-02 CE
2006191 ORD = 2006-07-10 CE
2006301 ORD = 2006-10-28 CE

2008001 ORD = 2008-01-01 CE


Easy Date Converter Advanced Version Main Page
Date/Calendar Software Hermetic Systems Home Page