//TIFFCONV.C

typedef unsigned short ushort;
typedef unsigned long ulong;

#include <stdio.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#include "..\scanfile.h"


/* Function Prototypes */

void convert(int type);
void file_close(void);

/* Definitions */

#define	TIFF	1

/* Variable Declarations */

FILE  *in, *out;


/*************************************************************/

void main(void){
  char menukey;


  while(1)
  {

	printf ("\n\n\nScanner File Converter 1.0");
	printf ("\n1 - Convert scan file to TIFF.");
	printf ("\n9 - Exit.");
    printf("\n\nEnter Selection: ");

    menukey = getchar();

    switch(menukey)
    {
      	case '1':
			convert(TIFF);
			break;


      	case '9':
			exit(0);
    }
  }
}


/***************************************************

This function converts a vpaa binary file to a range/magnitude text
file that can be imported into a spreadsheet.  The magnitudes are referenced
to the maximum signal input the vpaa receiver can accept.

****************************************************/

void convert(int type)
{
#pragma unused(type)

  	struct def defaults;
  	char file_in[80];
   
  	// Get the VPAA system info

  	if((in=fopen("init.bin", "rb")) == NULL)
  	{
    	printf("\nCannot open init.bin");
    	return;
  	}

  	if( fread(&defaults, sizeof(defaults), 1, in) != 1 )
  	{
    	printf("\nError reading init.bin");
    	file_close();
    	return;
  	}

  	// Get the input filename
  	printf("\n\nEnter Scan data file name with extension: ");
  	gets(file_in);
  
   
  	// Open the input file
  	if((in = fopen(file_in, "rb")) == NULL)
  	{
    	printf("\nCannot open source file");
    	file_close();
    	return;
  	}
  
 
  	file_close();
  	return;
}



/*****************************************************/

void file_close(void)
{
	if(fclose(in)) printf("\nInput file close error");
	if(fclose(out)) printf("\nOutput file close error");
}

/*****************************************************/
