/*  das_pack.c         eej    2/16/93  */
/*            revised  eej    6/24/93  */

#include <stdio.h>
#include "das_pack.h"

/* Function get_size() -- reads the number of samples in the data file */

unsigned long get_size(fp)
     FILE *fp;
{
    struct dtfl{
	char eth_hdr[ethernet_hdr];
	char fl_hdr[size_offset];
	unsigned long size;
	char hdr[data_rcd_off]; 
    } gt;

    fread(&gt, sizeof(struct dtfl), 1, fp);
    return(gt.size);
}

/* Function next_ref() -- gets the next reference address and timestamp ---*/

int next_ref(trace_file)
     FILE *trace_file;
{
    struct das_record new_rec;
    register struct das_record *rec_ptr;
    register double clocks;
    int code, fc, rw, retval;
    static int fc2type[16] = {3,1,3,3,3,5,3,7,3,0,2,3,3,4,6,7};

    retval = fread(&new_rec, sizeof(struct das_record), 1, trace_file);
    rec_ptr = &new_rec;
    current_ref.address = (rec_ptr->addr[0] << 16) + rec_ptr->addr[1]; 
    current_ref.time = (clocks = (((((double)(rec_ptr->timestamp_a) * 65536.0) 
			    + (double)(rec_ptr->timestamp_b[0])) * 65536.0)
			    + (double)(rec_ptr->timestamp_b[1])) * ClockRatio);
    fc = (rec_ptr->clkqual & 0x70) >> 4;
    rw = rec_ptr->control & 0x200;
    code = (rw >> 6) | fc;
    current_ref.type = fc2type[code];
    return (retval);
}




