CS611
Programming Assignment 1
Spring 1999


Write a C program to analyze a binary data file.

The program should be called "prog1".

The program should read from stdin and write to stdout. It should take an optional command line argument "-d" that will enable debugging output of the analysis. If anything else appears on the command line, then the following error message should be displayed and the program should exit:
usage: prog1 [-d] <in >out

The input data file will be a sequence of 24-bit binary numbers. The 24-bit numbers will be contained in three consecutive bytes in Little Endian order. Each 24-bit number has two interpretations:

The analysis should compute the difference, high - low, for all 01 numbers and sum these differences. Note, that despite the names, low could be larger than high so the difference and the sum are signed values. Compute both the difference and the sum in a 32-bit integer (i.e. a C int). At end-of-file on the input, the analysis should report a single line in this format:
Sum(high-low) is ddddd.
where ddddd stands for the actual sum computed and displayed in decimal. If no 01 numbers are seen then the analysis should report a sum of 0.

The analysis should find the largest absolute value of the time field in the 10 numbers. At end-of-file on the input, the analysis should report a single line in this format:
Max(Abs(time)) is ddddd.
where ddddd stands for the actual maximum computed and displayed in decimal. If no 10 numbers are seen then the analysis should report a maximum of 0.

Any 24-bit number that does not have bits 22-23 set to 01 or 10 should be ignored.

If the last 24-bit number in the file is incomplete (all 3 bytes are not present) then it should be ignored.

If the "-d" flag is given on the command line, then a line of output should be generated for each 24-bit number in the input:

No line need to appear for an incomplete 24-bit number at the end of the file.

The directory ~cs611/public/prog1 contains a test data file. There will also be hidden tests for this assignment so please test carefully.

Since the input is binary, you will probably need to write a program to create test data.

You should use the standard C library routine "getchar" for reading the bytes from stdin. You should use the standard C library routine "printf" for printing the output. Be sure to #include <stdio.h>. You should also produce a Makefile for building your program. Be sure to name the executable "prog1".

The following are the requirements to get full credit for program structure and documentation:

Points will be assigned in the following manner:

You may find using the od command on alberti helpful for analyzing the test files. In particular, using the -tx1 flag will display the bytes of a file, one byte at a time, in hexadecimal.

You must write your programs in C. Be sure to submit all your source files and your Makefile. You must submit a Makefile (called "Makefile") so that we can conveniently build your programs. Your programs will be graded using an Alpha machine (e.g. alberti) so be sure to test in that environment.

Your programs should be submitted for grading from alberti (or hopper or christa). To turn in this assignment, type:
~cs611/bin/submit prog1 <list of files to submit>

Do not turn in any non-Ascii files (i.e. no object files, no executable files, etc.).

Submissions can be checked by typing:
~cs611/bin/scheck prog1

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday February 1. Late submissions will be accepted at the penalty of 5% per day up to one week late.

Remember: as always you are expected to do your own work on this assignment.


Last modified on January 24, 1999.

Comments and questions should be directed to pjh@cs.unh.edu