/* intersec.c : Fonctions pour l'intersection entre id[]
                et un fichier de numeros d'etoiles
                jcm 17.07.91
 */

#include "diag.h"

char *err_fr=" Il n'y a pas de fichier: ";
char *err_eng=" No such file: ";

extern short id[];
extern short selec[];
extern float pp[];

void affiche_str();

/* read_noet:  lecture d'un fichier de numeros d'etoiles
 */
short read_noet(file,noet)
  char *file;
  short noet[];
 {
  short i=0, no;
  FILE *fp;

  if((fp=fopen(file,"r")) == NULL)
    {
     affiche_str(err_fr,err_eng,file);
     return(0);
    }
  else
    {
     while (fscanf(fp,"%hd",&no) != EOF)
       noet[i++]=no;
     noet[i]=9999;
     fclose(fp);
    }
  return(i);
 }

/* inter:  Intersection entre les numeros id[]
           et ceux lus avec read_noet
 */
void inter(no,nxy,rm)
 short no[], rm;
 int nxy;
 {
  short j=0, i=0;

  while ( j <= nxy )
  {
   if(id[j] == no[i])
    {
     if(rm == 1)
       selec[j]=0;
     pp[j]=40.0;
     j++;
     i++;
    }
   else if(id[j] < no[i])
     j++;
   else
     i++;
  }
 }
