#include <stdio.h>
#include <stdlib.h>
#include "buffers.h"
#include "load_header.h"

int4 load_cis_data(FILE *l1file, buffer_info *binfo)
{
	record_header	header;
	int		buffer_index, read_res, ii;
	void		*data;
	
	setup_buffers();
	buffer_index = buffer_lookup(binfo);
/*	clear_buffer(buffer_index);	*/
	
	load_header(l1file, &header);
	
	data = malloc(header.product_size+sizeof(record_header));
        ii=0;
	while (feof(l1file) == 0) {

          if (ii != 0) {
            load_header(l1file, &header);
          }
          ii=1;
          
		memcpy(data, (void *) (&header), sizeof(record_header));
		
		read_res=read_data((char *) data + sizeof(record_header),
			header.product_size, l1file);

		if (read_res == 0) {
			store_data_element(buffer_index, data, &header);
                }
                /*load_header(l1file, &header);   */
	}
	
	free(data); 
	
	return 0;
}
