/* selection.c :  Selection sur les positions et magnitudes
                  jcm 18.07.91
 */

#include "diag.h"

extern short selec[];
extern float xx[][10],pp[];
extern float r2[];
extern char *msg_fr[];
extern char *msg_eng[];

extern FLAG flags;

extern float ask_value();
extern float read_scale();
extern float read_xy();

float rascl;
float limit_xy();

/* marque_xy: marquage: r2 <= x2 + y2
 */
void marque_xy(nxy)
  int nxy;
 {
  short j,nlu;
  float limit,fraction;

  fraction=ask_value(msg_fr[2],msg_eng[2]);

  if( flags.scl == 0)
    rascl=read_scale();

  if( flags.xy == 0)
    nlu=read_xy(nxy);

  limit=limit_xy(rascl,fraction);

  for(j=0; j <= nxy; j++)
    if( r2[j] < 0. || r2[j] > limit )
      pp[j]=40.0;
    else
      pp[j]=43.0;

  flags.vect=1;
 }

/* select_xy: selection: r2 <= x2 + y2
 */
void select_xy(nxy)
  int nxy;
 {
  short j,nlu;
  float limit,fraction;

  fraction=ask_value(msg_fr[2],msg_eng[2]);

  if( flags.scl == 0)
    rascl=read_scale();

  if( flags.xy == 0)
    nlu=read_xy(nxy);

  limit=limit_xy(rascl,fraction);

  for(j=0; j <= nxy; j++)
    if( r2[j] < 0. || r2[j] > limit )
      selec[j] = 0;

  flags.vect=1;
 }

/* select_out: selection: r2 > x2 + y2
 */
void select_out(nxy)
  int nxy;
 {
  short j,nlu;
  float limit,fraction;

  fraction=ask_value(msg_fr[2],msg_eng[2]);

  if( flags.scl == 0)
    rascl=read_scale();

  if( flags.xy == 0)
    nlu=read_xy(nxy);

  limit=limit_xy(rascl,fraction);

  for(j=0; j <= nxy; j++)
    if( r2[j] <= limit )
      selec[j] = 0;

  flags.vect=1;
 }

/* select_int: selection: lim2 < r2 < lim2
 */
void select_int(nxy)
  int nxy;
 {
  int nlu; 
  short j;
  float lim1,lim2,frac1,frac2;

  frac1=ask_value(msg_fr[3],msg_eng[3]);
  frac2=ask_value(msg_fr[4],msg_eng[4]);

  if( flags.scl == 0)
    rascl=read_scale();

  if( flags.xy == 0)
    nlu=read_xy(nxy);

  lim1=limit_xy(rascl,frac1);
  lim2=limit_xy(rascl,frac2);

  for(j=0; j <= nxy; j++)
    if( r2[j] <= lim1 || r2[j] > lim2 )
      selec[j] = 0;

  flags.vect=1;
 }

/* limit_xy: calcul de la limite
 */
float limit_xy(rascl,fraction)
  float rascl, fraction;
 {
  float limit;

  limit = rascl * fraction;
  return(limit * limit);
 }

/* select_V:  selection sur les magnitudes: V < seuil
 */
void select_V(nxy)
 int nxy;
 {
  short j;
  float seuil;

  seuil=ask_value(msg_fr[7],msg_eng[7]);

  for(j=0; j <= nxy; j++)
    if( xx[j][1] > seuil )
      selec[j] = 0;

  flags.vect=1;
 }
