#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

void help()
{
	printf(	"Usage:	checker file_name\n");

}

#define PKT_SIZE	4096
#define MAX_VAL		0x3FFF


int main(int argc, char *argv[])
{
	FILE *fp = NULL;
	FILE *cfp = NULL;
	uint16_t buf[PKT_SIZE/2];
	char *fn = NULL;
	char fname[300];
	int ret = 0;
	struct pkt_t *pkt;
	printf("*** Cecilie RDMA application - data checker ***\n");

	if(argc != 2){
		printf("Not enough arguments\n");
		help();
		return 1;
	}

	fn = argv[1];
	printf("Input file name: %s\n", fn);
	memset(fname, '\0', sizeof(fname));
	snprintf(fname, sizeof(fname), "%s.txt", fn);
	printf("Output file name: %s\n", fn);
	memset(buf, 0x00, sizeof(buf));

	
	fp = fopen(fn, "rb");
	if(!fp){
		printf("Couldn't open file %s\n", fn);
		return 1;	
	}
	
	cfp = fopen(fname, "w");
	if(!cfp){
		fclose(fp);
		printf("Couldn't open file %s\n", fname);
		return 1;	
	}
	
	printf("Converting ...\n");
	while((ret = fread(buf, sizeof(*buf), sizeof(buf)/sizeof(*buf), fp)) == sizeof(buf)/sizeof(*buf)){
		for(int i = 0; i < sizeof(buf)/sizeof(*buf); i++){
			fprintf(cfp, "%f\n", (float)buf[i]);
		}
	}
	
	fclose(fp);
	fclose(cfp);
	printf("Converted\n");
	return 0;

}

