In Project 0, you have written a project to process a text file. In this project, you will explore more about file processing: You are given two text files MTable.txt, Vars.txt, and one binary file RawData.dat. Your program will generate an output text file.
The binary raw data file RawData.dat contains data from a real NASA experiment. The scientist on the ground wants to extract the experimental data from the raw data file and save the results in a text file so he can process these results later using MATLAB, gnuplot, or JAVA graphics. The basic elements of the raw data file are packets.
A text file, called MTable.txt file, describes the format of each packet. Since each packet contains many variables and the scientist just wants to extract some of them at a time, so he creates a text file called Vars.txt to help him to define which variables are to be extracted. With the help of the MTable.txt and Vars.txt files, your program will extract data from file RawData.dat and output a nice text file.
1.1 The three given files are:
This is a binary file generated by a PowerPC computer. The data is in JAVA data format. It contains certain number of packets of raw data. Each packet is of size 350 bytes.
---------------- | packet 1 | 350 bytes | | ---------------- | packet 2 | 350 bytes | | ---------------- | packet 3 | | | 350 bytes ---------------- ..... ---------------- | packet n | | | 350 bytes ----------------
This file provides the format information in each data packet in the raw data file. Each line in a packet maybe a comment line, a blank line, or a format line that contains 6 columns. The comment lines start with "#". Your program must skip these comment lines and blank lines.
Let's see a format line example:
2 MET_YEAR 4 2 UINT16
This line says that the second variable is "MET_YEAR", the offset of this variable from the beginning of the packet is 4 bytes, its width is 2 bytes and it has the type named "UINT16". This line has 5 columns and columns are separated by 1 or more tabs ('\t'). The 6th (comment) line is empty.
Let's see another format line example:
23 CMD_REG 82 4 UINT32 (bit encoded)
This line says that the variable "CMD_REG" is the 23rd variable in the packet. Its offset is 82 bytes from the beginning of the packet, its width is 4 and it has the type named "UINT32". Note that this line has 6 columns: The first 5 columns are separated by '\t' and the 5th and 6th columns are separated by one space ' '.
Following is a summary of the format of
the Mtable.txt file:
The columns are separated by whitespace
characters ('\t' or ' '). Column 1: serial number of variable There are five types you have to deal with:
There is another type, ANY, which you can ignore, they are used for padding. This file contains the variables names that the
user wants to extract from the raw data file. This file has all of the variables that are defined in
the MTable file. The user just comments the unwanted variables with
"#".The comment lines start with
"#". So you must skip these commented lines in your program. For example: #SYNC_BYTES These lines show that the user wants to extract
variables "MET_YEAR" and "MET_SEC". 1.2 The output text file has the following
format: 1.2.1 Header The header must start with "#". The
header contains five items: 1.2.2 Body The body consists of the values of the extracted
variables. The values are separated by whitespaces (tabs or spaces, you decide). The following is an except from an example output
file: # File Name: Output.txt 1.3 Shell
Command Your program should run like this:
1.4 Files for Downloading 2.1 The following classes from Java APIs may
provide the functionality you need, (you are free to use any java built-in this
time): 2.2 We will discuss these issues in the following
Lab
sessions:
Column 2: name of variable
Column 3: offset of variable in the packet
Column 4: width of variable
Column 5: type of variable
Column 6: comment (maybe empty)
TYPE NAME LENGTH (in bytes) YOUR INTERNAL REPRESENTATION
STRING string variable length, defined in mtable for each appearance String
UINT8 unsigned byte 1 long
UINT16 unsigned short 2 long
UINT32 unsigned int 4 long
FLOAT float 4 float
MET_YEAR
#MET_DAY
#MET_HOUR
#MET_MIN
MET_SEC
# Generated at Sun Feb 01 15:01:20 MST 2004
# MTable File Name: MTable.txt
# Raw Data File Name: RawData.dat
#
# MET_YEAR MET_SEC PACKET_COUNT TARGET_CPU_ID CH0_DERTEMP
#
1970 32 137 Cetia VMPC5a-Dual 2.21002054
1970 33 138 Cetia VMPC5a-Dual 2.21002054
1970 34 139 Cetia VMPC5a-Dual 2.21002054
1970 35 140 Cetia VMPC5a-Dual 2.21002054
1970 36 141 Cetia VMPC5a-Dual 2.21002054
1970 37 142 Cetia VMPC5a-Dual 2.21002102
1970 38 143 Cetia VMPC5a-Dual 2.21002054
1970 39 144 Cetia VMPC5a-Dual 2.21002102
......
java Extractor Mtable.txt Vars.txt RawData.dat OutputFile
2 Hints