/*  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 "hip_main.h" 

int read_hip_main (FILE* fp, hip_main* entry) 
{
/* Routine to read one record from the datafile into the structure 
 * hip_main - this structure should already exist and be alloced
 * in the calling routine. The file should be positioned at the correct
 * place
 */
   char buffer[hip_main_REC_LEN+3];
   char delimiter[3]="|\r\0"; 
   char *token;
   if (entry == NULL) 
   {
      fprintf (stderr,"read_hip_main NULL pointer for entry\n");
      return (-1);
   } 
	if (fgets ((char *)&buffer,hip_main_REC_LEN+2,fp) == NULL)
		return -1;
	token=strtok((char *)&buffer,(char *)&delimiter); 
	strcpy((char *)&entry->H0,token);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H1);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H2,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H3,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H4,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H5);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H6,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H7,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H8);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H9);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H10,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H11);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H12);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H13);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H14);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H15);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H16);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H17);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H18);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H19);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H20);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H21);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H22);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H23);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H24);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H25);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H26);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H27);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H28);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H29);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H30);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H31);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H32);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H33);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H34);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H35);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H36,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H37);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H38);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H39,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H40);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H41);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H42,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H43,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H44);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H45);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H46);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H47);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H48,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H49);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H50);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H51);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H52,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H53,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H54,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H55,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H56,token);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H57);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H58);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H59,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H60,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H61,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H62,token);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H63);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H64);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H65);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H66);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H67);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H68,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H69,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H70,token);
	token=strtok(NULL,delimiter);
	strAsINT(token,&entry->H71);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H72,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H73,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H74,token);
	token=strtok(NULL,delimiter);
	strAsFLOAT(token,&entry->H75);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H76,token);
	token=strtok(NULL,delimiter);
	strcpy((char *)&entry->H77,token);
	if (entry->H70[0]=='D' || entry->H70[0]=='W' || 
	    entry->H70[0]=='X' || entry->H70[0]=='Z' )
	   search_hd_notes(&entry->H1,&entry->HDNOTES);
	else
	   entry->HDNOTES.no_entries=0;
	if (entry->H70[0]=='G' || entry->H70[0]=='Y' || 
	    entry->H70[0]=='X' || entry->H70[0]=='Z' )
	   search_hg_notes(&entry->H1,&entry->HGNOTES);
	else
	   entry->HGNOTES.no_entries=0;
	if (entry->H70[0]=='P' || entry->H70[0]=='W' || 
	    entry->H70[0]=='Y' || entry->H70[0]=='Z' )
	   search_hp_notes(&entry->H1,&entry->HPNOTES);
	else
	   entry->HPNOTES.no_entries=0;
	search_hp_auth(&entry->H1,&entry->AUTHREF);
   return 0;
} /* End of read_hip_main */ 

FILE* jump_hip_main (long recNum) 
{
   static int init=0;
   static FILE* dataFile;
   if (init==0)
   {
      if ((dataFile = fopen ("hip_main.dat","r")) == NULL)
      {
         fprintf(stderr,"Could not open hip_main.dat \n");
         return NULL;
      }
      init=1;
   }
   if ( fseek (dataFile, (recNum - 1) * hip_main_REC_LEN, 0) == 0)
     return dataFile;
   else
     return NULL;
}


int print_hip_main (hip_main* entry, int decode) 
{
/*  Just print out each attribute with its value  */
   char outputStr[50];
   if (entry == NULL) 
   {
      fprintf (stderr,"print_hip_main NULL pointer for entry\n");
      return (-1);
   }

	printf("H0  : %1.1s                    Catalogue (H = Hipparcos, T = Tycho)\n",entry->H0 );
	INTasStr((char *)&outputStr,"%8d",&entry->H1 );
	printf("H1  : %s             Identifier (HIP number)\n",outputStr);
	printf("H2  : %1.1s                    Proximity flag\n",entry->H2 );
	printf("H3  :  %11.11s         Identifier RA,  h m s (J1991.25)\n",entry->H3 );
	printf("H4  : %11.11s          Identifier Dec, d m s (J1991.25)\n",entry->H4 );
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H5 );
	printf("H5  : %s          V (Johnson) magnitude \n",outputStr);
	printf("H6  : %1.1s                    Coarse variability flag\n",entry->H6 );
	printf("H7  : %1.1s                    Source of magnitude identifier\n",entry->H7 );
	FLOATasStr((char *)&outputStr,"%17.8f",&entry->H8 );
	printf("H8  : %s    alpha, degrees (J1991.25)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%17.8f",&entry->H9 );
	printf("H9  : %s    delta, degrees (J1991.25)\n",outputStr);
	printf("H10 : %1.1s                    Reference flag for astrometry\n",entry->H10);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H11);
	printf("H11 : %s          Trigonometric parallax (mas)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H12);
	printf("H12 : %s          mu_alpha* (mas/yr)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H13);
	printf("H13 : %s          mu_delta (mas/yr)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H14);
	printf("H14 : %s          Standard error in alpha* at J1991.25 (mas)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H15);
	printf("H15 : %s          Standard error in delta at J1991.25 (mas)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H16);
	printf("H16 : %s          Standard error in pi (mas)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H17);
	printf("H17 : %s          Standard error in mu_alpha* (mas/yr)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H18);
	printf("H18 : %s          Standard error in mu_delta (mas/yr)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H19);
	printf("H19 : %s          Correlation: alpha*/delta\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H20);
	printf("H20 : %s          Correlation: alpha*/pi\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H21);
	printf("H21 : %s          Correlation: delta/pi\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H22);
	printf("H22 : %s          Correlation: alpha*/mu_alpha*\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H23);
	printf("H23 : %s          Correlation: delta/mu_alpha*\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H24);
	printf("H24 : %s          Correlation: pi/mu_alpha*\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H25);
	printf("H25 : %s          Correlation: alpha*/mu_delta\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H26);
	printf("H26 : %s          Correlation: delta/mu_delta\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H27);
	printf("H27 : %s          Correlation: pi/mu_delta\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H28);
	printf("H28 : %s          Correlation: mu_alpha*/mu_delta\n",outputStr);
	INTasStr((char *)&outputStr,"%8d",&entry->H29);
	printf("H29 : %s             F1, data points rejected (per cent)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H30);
	printf("H30 : %s          F2, goodness-of-fit\n",outputStr);
	INTasStr((char *)&outputStr,"%8d",&entry->H31);
	printf("H31 : %s             HIP number\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H32);
	printf("H32 : %s         BT (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H33);
	printf("H33 : %s         sigma BT (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H34);
	printf("H34 : %s         VT (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H35);
	printf("H35 : %s         sigma VT (mag)\n",outputStr);
	printf("H36 : %1.1s                    Reference flag for BT and VT \n",entry->H36);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H37);
	printf("H37 : %s         B-V (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H38);
	printf("H38 : %s         sigma B-V (mag)\n",outputStr);
	printf("H39 : %1.1s                    Source of B-V\n",entry->H39);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H40);
	printf("H40 : %s          V-I (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H41);
	printf("H41 : %s          sigma V-I (mag)\n",outputStr);
	printf("H42 : %1.1s                    Source of V-I\n",entry->H42);
	printf("H43 : %1.1s                    Reference flag for colour indices\n",entry->H43);
	FLOATasStr((char *)&outputStr,"%13.4f",&entry->H44);
	printf("H44 : %s        Median Hp (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%13.4f",&entry->H45);
	printf("H45 : %s        sigma Hp (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H46);
	printf("H46 : %s         Scatter, s (mag)\n",outputStr);
	INTasStr((char *)&outputStr,"%8d",&entry->H47);
	printf("H47 : %s             Accepted transits, N\n",outputStr);
	printf("H48 : %1.1s                    Reference flag for photometry\n",entry->H48);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H49);
	printf("H49 : %s          Mag at max, Hp (5th percentile)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H50);
	printf("H50 : %s          Mag at min, Hp (95th percentile)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H51);
	printf("H51 : %s          Period (days)\n",outputStr);
	printf("H52 : %1.1s                    Flag (variability type)\n",entry->H52);
	printf("H53 : %1.1s                    Flag (variability tables)\n",entry->H53);
	printf("H54 : %1.1s                    Flag (light curves)\n",entry->H54);
	printf("H55 : %10.10s           CCDM Identifier\n",entry->H55);
	printf("H56 : %1.1s                    Historical status flag\n",entry->H56);
	INTasStr((char *)&outputStr,"%8d",&entry->H57);
	printf("H57 : %s             Number of catalogue entries\n",outputStr);
	INTasStr((char *)&outputStr,"%8d",&entry->H58);
	printf("H58 : %s             Number of components\n",outputStr);
	printf("H59 : %1.1s                    Double/Multiple Systems Annex flag\n",entry->H59);
	printf("H60 : %1.1s                    Astrometric source flag\n",entry->H60);
	printf("H61 : %1.1s                    Solution quality\n",entry->H61);
	printf("H62 : %2.2s                   Component identifiers\n",entry->H62);
	INTasStr((char *)&outputStr,"%8d",&entry->H63);
	printf("H63 : %s             Position angle (degrees)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H64);
	printf("H64 : %s         Angular separation (arcsec)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%12.3f",&entry->H65);
	printf("H65 : %s         sigma separation (arcsec)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H66);
	printf("H66 : %s          Delta Hp (mag)\n",outputStr);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H67);
	printf("H67 : %s          sigma Delta Hp (mag)\n",outputStr);
	printf("H68 : %1.1s                    Survey flag\n",entry->H68);
	printf("H69 : %1.1s                    Chart flag\n",entry->H69);
	printf("H70 : %1.1s                    Notes\n",entry->H70);
	INTasStr((char *)&outputStr,"%8d",&entry->H71);
	printf("H71 : %s             HD identifier \n",outputStr);
	printf("H72 : %10.10s           DM (BD) identifier\n",entry->H72);
	printf("H73 : %10.10s           DM (CoD) identifier\n",entry->H73);
	printf("H74 : %10.10s           DM (CPD) identifier\n",entry->H74);
	FLOATasStr((char *)&outputStr,"%11.2f",&entry->H75);
	printf("H75 : %s          V-I (mag) used for reductions\n",outputStr);
	printf("H76 : %12.12s         Spectral type \n",entry->H76);
	printf("H77 : %2.2s                   Source of spectral type \n",entry->H77);
	if (decode == ARRAYVERBOSE || 
	    decode ==(ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE) || 
	    decode ==(ARRAYVERBOSE+EXTRACTCOEFF) ||
	    decode ==(PRINTSUBRECS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode == DOALL )
	   print_array_hg_notes(&entry->HGNOTES,decode);
	else
	{
	   printf("HGNOTES\n");
	   print_array_hg_notes_cols(&entry->HGNOTES,decode);
	}
	if (decode == ARRAYVERBOSE || 
	    decode ==(ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE) || 
	    decode ==(ARRAYVERBOSE+EXTRACTCOEFF) ||
	    decode ==(PRINTSUBRECS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode == DOALL )
	   print_array_hd_notes(&entry->HDNOTES,decode);
	else
	{
	   printf("HDNOTES\n");
	   print_array_hd_notes_cols(&entry->HDNOTES,decode);
	}
	if (decode == ARRAYVERBOSE || 
	    decode ==(ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE) || 
	    decode ==(ARRAYVERBOSE+EXTRACTCOEFF) ||
	    decode ==(PRINTSUBRECS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode == DOALL )
	   print_array_hp_notes(&entry->HPNOTES,decode);
	else
	{
	   printf("HPNOTES\n");
	   print_array_hp_notes_cols(&entry->HPNOTES,decode);
	}
	if (decode == ARRAYVERBOSE || 
	    decode ==(ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE) || 
	    decode ==(ARRAYVERBOSE+EXTRACTCOEFF) ||
	    decode ==(PRINTSUBRECS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+EXTRACTCOEFF) || 
	    decode ==(DECODEBITS+ARRAYVERBOSE+PRINTSUBRECS) || 
	    decode == DOALL )
	   print_array_hp_auth(&entry->AUTHREF,decode);
	else
	{
	   printf("AUTHREF\n");
	   print_array_hp_auth_cols(&entry->AUTHREF,decode);
	}
   return (0);
} /* End of print_hip_main */

int print_hip_main_cols (hip_main* entry, int decode) 
{
   char outputStr[200];
/*  print attributes accross screen as in datafile - 
    decode fields depending on the value of decode (values defined in utils.h */
   if (entry == NULL) 
   {
      fprintf (stderr,"print_hip_main_cols NULL pointer for entry\n");
      return (-1);
   }

	printf("%1s",entry->H0);
	INTasStr((char *)&outputStr,"%12d",&entry->H1);
	printf("|%s",outputStr);
	printf("|%1s",entry->H2);
	printf("|%11s",entry->H3);
	printf("|%11s",entry->H4);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H5);
	printf("|%s",outputStr);
	printf("|%1s",entry->H6);
	printf("|%1s",entry->H7);
	FLOATasStr((char *)&outputStr,"%012.8f",&entry->H8);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%+012.8f",&entry->H9);
	printf("|%s",outputStr);
	printf("|%1s",entry->H10);
	FLOATasStr((char *)&outputStr,"%7.2f",&entry->H11);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%8.2f",&entry->H12);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%8.2f",&entry->H13);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.2f",&entry->H14);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.2f",&entry->H15);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.2f",&entry->H16);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.2f",&entry->H17);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.2f",&entry->H18);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H19);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H20);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H21);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H22);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H23);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H24);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H25);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H26);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H27);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H28);
	printf("|%s",outputStr);
	INTasStr((char *)&outputStr,"%3d",&entry->H29);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H30);
	printf("|%s",outputStr);
	INTasStr((char *)&outputStr,"%6d",&entry->H31);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.3f",&entry->H32);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.3f",&entry->H33);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.3f",&entry->H34);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.3f",&entry->H35);
	printf("|%s",outputStr);
	printf("|%1s",entry->H36);
	FLOATasStr((char *)&outputStr,"%6.3f",&entry->H37);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.3f",&entry->H38);
	printf("|%s",outputStr);
	printf("|%1s",entry->H39);
	FLOATasStr((char *)&outputStr,"%4.2f",&entry->H40);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%4.2f",&entry->H41);
	printf("|%s",outputStr);
	printf("|%1s",entry->H42);
	printf("|%1s",entry->H43);
	FLOATasStr((char *)&outputStr,"%7.4f",&entry->H44);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%6.4f",&entry->H45);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.3f",&entry->H46);
	printf("|%s",outputStr);
	INTasStr((char *)&outputStr,"%3d",&entry->H47);
	printf("|%s",outputStr);
	printf("|%1s",entry->H48);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H49);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H50);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%7.2f",&entry->H51);
	printf("|%s",outputStr);
	printf("|%1s",entry->H52);
	printf("|%1s",entry->H53);
	printf("|%1s",entry->H54);
	printf("|%10s",entry->H55);
	printf("|%1s",entry->H56);
	INTasStr((char *)&outputStr,"%2d",&entry->H57);
	printf("|%s",outputStr);
	INTasStr((char *)&outputStr,"%2d",&entry->H58);
	printf("|%s",outputStr);
	printf("|%1s",entry->H59);
	printf("|%1s",entry->H60);
	printf("|%1s",entry->H61);
	printf("|%2s",entry->H62);
	INTasStr((char *)&outputStr,"%3d",&entry->H63);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%7.3f",&entry->H64);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.3f",&entry->H65);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%5.2f",&entry->H66);
	printf("|%s",outputStr);
	FLOATasStr((char *)&outputStr,"%4.2f",&entry->H67);
	printf("|%s",outputStr);
	printf("|%1s",entry->H68);
	printf("|%1s",entry->H69);
	printf("|%1s",entry->H70);
	INTasStr((char *)&outputStr,"%6d",&entry->H71);
	printf("|%s",outputStr);
	printf("|%10s",entry->H72);
	printf("|%10s",entry->H73);
	printf("|%10s",entry->H74);
	FLOATasStr((char *)&outputStr,"%4.2f",&entry->H75);
	printf("|%s",outputStr);
	printf("|%12s",entry->H76);
	printf("|%1s",entry->H77);
	if ((entry->HGNOTES.no_entries > 0 )&&
	    (decode == PRINTSUBRECS ||
	     decode ==(EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode ==(DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+PRINTSUBRECS) ||
	     decode ==(DECODEBITS+EXTRACTCOEFF+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode == DOALL ) ) 
	{
	   printf("\n");
	   print_array_hg_notes_cols(&entry->HGNOTES,decode);
	}
	if ((entry->HDNOTES.no_entries > 0 )&&
	    (decode == PRINTSUBRECS ||
	     decode ==(EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode ==(DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+PRINTSUBRECS) ||
	     decode ==(DECODEBITS+EXTRACTCOEFF+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode == DOALL ) ) 
	{
	   printf("\n");
	   print_array_hd_notes_cols(&entry->HDNOTES,decode);
	}
	if ((entry->HPNOTES.no_entries > 0 )&&
	    (decode == PRINTSUBRECS ||
	     decode ==(EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode ==(DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+PRINTSUBRECS) ||
	     decode ==(DECODEBITS+EXTRACTCOEFF+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode == DOALL ) ) 
	{
	   printf("\n");
	   print_array_hp_notes_cols(&entry->HPNOTES,decode);
	}
	if ((entry->AUTHREF.no_entries > 0 )&&
	    (decode == PRINTSUBRECS ||
	     decode ==(EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode ==(DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+PRINTSUBRECS) ||
	     decode ==(DECODEBITS+EXTRACTCOEFF+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+DECODEBITS+PRINTSUBRECS) ||
	     decode ==(ARRAYVERBOSE+EXTRACTCOEFF+PRINTSUBRECS) || 
	     decode == DOALL ) ) 
	{
	   printf("\n");
	   print_array_hp_auth_cols(&entry->AUTHREF,decode);
	}
	printf("\r\n");
	return (0);
} /* End of print_hip_main_cols */

int print_hip_main_header () 
{
/*  print col names accross screen as in datafile */

	printf("0|H1          |2|H3         |H4         |H5   |6|7|H8          |H9          |0|H11    |H12     |H13     |H14   |H15   |H16   |H17   |H18   |H19  |H20  |H21  |H22  |H23  |H24  |H25  |H26  |H27  |H28  |H29|H30  |H31   |H32   |H33  |H34   |H35  |6|H37   |H38  |9|H40 |H41 |2|3|H44    |H45   |H46  |H47|8|H49  |H50  |H51    |2|3|4|H55       |6|57|58|9|0|1|62|H63|H64    |H65  |H66  |H67 |8|9|0|H71   |H72       |H73       |H74       |H75 |H76         |7\n");
   return (0);
} /* End of print_hip_main_headre */



FILE* search_hip_main (idx_hip_main* key, hip_main* arecord)
{
   FILE* dataFile=NULL;
   long recNum;
   
   recNum= find_idx_hip_main (key);
   if (recNum >= 0)
   {
	dataFile=jump_hip_main(recNum);
	if (read_hip_main (dataFile,arecord)==0)
	   return dataFile;
	else
	   return NULL;
   }
   else
   {
	return NULL;
   }
}/* End search_idx_hip_main */

