/* 
  Routine to extract the filter curves from a binary irfc*.dat FITS
  data segment.

  Format: % gettab irfcNNNN.dat rec_count irfcNNNN.tab
  04 May 2006.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

/*========================================================================*/

main(int argc, char *argv[])

{ FILE *ifp,*ofp;

  long int  rec[2];   /* Record values */
  double    wavelength, transmit;
  long int  rows;
  int       i,j,k;
  char     *rem;

  if (argc != 4)
    { fprintf (stderr,"Usage: gettab irfcNNNN.dat rec_count irfcNNNN.tab\n");
      exit(0);
    }

  if ((ifp = fopen(argv[1],"rb")) == NULL)
    { fprintf(stderr,"Unable to open '%s' for reading (%s).\n",
              argv[1],strerror(errno));
      exit(100);
    }

  if ((ofp = fopen(argv[3],"w")) == NULL)
    { fprintf(stderr,"Unable to open '%s' for writing (%s).\n",
              argv[3],strerror(errno));
      exit(200);
    }

  rows = strtol(argv[2],&rem,10);

  for (i=0; i<rows; i++)
    { fread((void *)rec,8,1,ifp);
      wavelength = (double)rec[0] * 1.e-05;
      transmit   = (double)rec[1] * 1.e-05;
      fprintf(ofp,"%4.2f %5.2f\r\n",wavelength,transmit);
    }

  close(ifp);
  close(ofp);


  /* And we're done: */

  exit(0);
}