/*  Hipparcos ASCII CD-ROM load and search routines Release 1.1 June 1997
    William O'Mullane 
    Astrophysics Division, ESTEC, Noordwijk, The Netherlands. 
    See the readme.pdf file for more information */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "utils.h" 
 
#include "ihipdm.h" 
#include "hip_dm_g.h"
#include "hip_dm_o.h"
#include "hip_dm_v.h"
#include "hip_dm_x.h"
#include "hip_dm_c.h"

main (int argc,char **argv)
{
   FILE* hip_dmgfp;
   FILE* hip_dmofp;
   FILE* hip_dmvfp;
   FILE* hip_dmxfp;
   if (argc == 1) 
   { 
        fprintf (stderr,"You must pass a key value on the command line \n");
   }
   else /* some numbers on the command line */
   { 
	int i,decode=ASRAW,cols=0,quite=0;
	long multiRecs=0,recNo;
	FILE* dataFile;
	for (i=1; i<argc ; i++)
	{
	   INT rec; 
	   idx_hip_dm *idxEntry;
   	   checkIfCommandLineFlag(argv,argc,&i,&cols,&decode,&quite,&multiRecs);
	   

		strAsINT( argv[i], &rec);
		if ( (idxEntry = find_idx_hip_dm(&rec)) != NULL)
		{
		   if (idxEntry->hdm_idx2[0] == 'G')
		   {
			hip_dm_g arec;	
			hip_dmgfp=jump_hip_dm_g(idxEntry->hdm_idx3.value);
			read_hip_dm_g(hip_dmgfp,&arec);
			if (cols)
			   print_hip_dm_g_cols(&arec,decode);
		    	else
			   print_hip_dm_g(&arec,decode);
	   	   }

		   if (idxEntry->hdm_idx2[0] == 'O')
		   {
			hip_dm_o arec;	
			hip_dmofp=jump_hip_dm_o(idxEntry->hdm_idx3.value);
			read_hip_dm_o(hip_dmofp,&arec);
			if (cols)
			   print_hip_dm_o_cols(&arec,decode);
		    	else
			   print_hip_dm_o(&arec,decode);
	   	   }

		   if (idxEntry->hdm_idx2[0] == 'V')
		   {
			hip_dm_v arec;	
			hip_dmvfp=jump_hip_dm_v(idxEntry->hdm_idx3.value);
			read_hip_dm_v(hip_dmvfp,&arec);
			if (cols)
			   print_hip_dm_v_cols(&arec,decode);
		    	else
			   print_hip_dm_v(&arec,decode);
	   	   }

		   if (idxEntry->hdm_idx2[0] == 'X')
		   {
			hip_dm_x arec;	
			hip_dmxfp=jump_hip_dm_x(idxEntry->hdm_idx3.value);
			read_hip_dm_x(hip_dmxfp,&arec);
			if (cols)
			   print_hip_dm_x_cols(&arec,decode);
		    	else
			   print_hip_dm_x(&arec,decode);
	   	   }

		   if (idxEntry->hdm_idx2[0] == 'C')
		   {
			array_hip_dm_c arec;	
			read_array_hip_dm_c(idxEntry->hdm_idx3.value,&arec);
			if (cols)
 			{
			   if (decode==ASRAW) decode=PRINTSUBRECS;
			   print_array_hip_dm_c_cols(&arec,decode);
			}
			else
			   print_array_hip_dm_c(&arec,decode+ARRAYVERBOSE);
	   	   }

		}

	   else
	      printf("%d not found\n",rec.value);
	}
   }
 
} /* End Main for idx_hip_dm_test */

