< previous page page_177 next page >

Page 177
2.) An external sort, which sorts on Julian Day number.
3.) A print program, which reads the sorted data file and prints the date and name, breaking on change of year.
This approach is consistent with the SCDTL philosophy of defining and using standard tools and using them in standard ways. Both programs are simpler to write than DTLT_142.C, and the external sort is normally available as a standard system utility, thus saving the writing of unnecessary sort code in C. As a bonus, the print program is not tied to any particular application and can be used as a utility in its own right. Finally, the front-end program can output the dates in any order, so maintenance is easier.
Examine the test programs DTLT_143.C and DTLT_144.C for the details of implementing this approach. For this application, consider the days of observance for Upper Slobovia, a mythical country whose official days of observance just happen to dovetail rather nicely with our requirement for an example of date overlap.
These two test programs should be viewed as a pair, with DTLT_143.C being the front-end and DTLT_144.C being the report program. An external sort is assumed to accept the output of DTLT_143.C, file DTLT_143.UST, and export a sorted file, DTLT_143.SRT, which is accepted as input by the DTLT_144.C program.
Note that DTLT_143.UST is a text file of one line for each day of observance. The days occur in the order of generation by their respective functions, but because of overlap stemming from their definitional rules, the days do not occur in chronological order.
The purpose of generating each day of observance with its associated Julian Day number, of course, is to provide a sort key, which is used by the external sort to rear-range the lines as required. In a DOS environment, this can be as simple as:
sort <dtlt_143.ust >dtlt_143.srt
DTLT_144.C then reads the sorted file and produces the required file, simply performing a break for each new year. There are a few techniques the reader may find useful.
First, notice that the alternation of read and write is accomplished by placing the exit logic in the read module, and arranging the logic within the loop in write-read order. This technique provides simple exit logic. The end-of-file situation is an error condition and occurs at the beginning of the file, not the end, so a separate initial read with separate error-handling is more congruent with the actual logic of the situation.
Second, the scanf function family is traditionally a bit cantankerous in C, so I use a common technique for bypassing the problem with white space by replacing all space characters in the output filename area with the character [. The fscanf () in DTLT_144.C does not choke on these, and a simple scan converts them to the desired form before printing. This is a simple and effective way to avoid an entire class of problems with scanf functions in general.

 
< previous page page_177 next page >