From jht@ing.iac.es Mon Jul 21 03:58 PDT 1997
Return-Path: <jht@ing.iac.es>
Received: from ing.iac.es by pikake.astro.washington.edu
	(8.6.12/UW-NDC Revision: 2.33 ) id DAA16312;
	Mon, 21 Jul 1997 03:58:40 -0700
Received: by ing.iac.es (4.1/1.0)
	id AA20304; Mon, 21 Jul 97 11:58:27 BST
Date: Mon, 21 Jul 1997 11:58:26 +0100 (BST)
From: John Telting <jht@ing.iac.es>
To: Eugene Magnier <gene@pikake.astro.washington.edu>
Cc: Saskia Prins <stp@ing.iac.es>, John Telting <jht@ing.iac.es>
Subject: Re: fits tools on linux
In-Reply-To: <199706101748.KAA22094@pikake.astro.washington.edu>
Message-Id: <Pine.SUN.3.91.970721114404.19653B-100000@vega.ing.iac.es>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
Content-Length: 3744
Status: O

hi gene,

HOWZIT?
we saw lots of dreamcatchers on indian territory, but only few
were 3D like the one you gave us.  Stunning views in and in between
the national parks/monuments.  Great vacation behind us!!

gdb is useful!
apparently the linux C compiler reads the FITS bytes into the
variables in the reverse order (NOT a byteswap!!).
i only tested SIGNED bitpix=16,32,-32.
for bitpix=8 there is a sign problem.

we had a closer look at sas's linux mana version, and all data values
are affected by the same problem. (So Sas cannot really use it conveniently.)

below a hack in the 1D vector routine you made especially for my use
when we both were in amsterdam.  I guess you can make use of my hacking.
if/when you are going to do a port to linux, please let us know!!!

See You!!
John

ps. the compiler gives warnings about the way i coded the pointers.
dont know how to do it the way it likes it, sorry.

----------------------------------------------------------------
file: F_get_V_value.c
----------------------------------------------------------------
# include "fits.h"

/***************** fits get matrix value *******************/
double fits_get_vector_value (matrix, x) 
Matrix *matrix; 
int x;
{

  double value;
  float float1, float2;
  int pixel, int1, int2;
  short short1, short2;
  char yyy[3], zzz[3];

  if ((x < 0) || (x >= matrix[0].Naxis[0])) {
    fprintf (stderr, "%6d %d\n", x, matrix[0].Naxis[0]);
    return (0.0);
  }
  pixel = x;
  value = fmod (1.0,0.0);

  if (pixel==0) {
    fprintf(stderr,"\n\n!!  fits_get_vector_value  !!\n");
    fprintf(stderr,"!!  USE THIS hack ONLY UNDER linux !!\n");
    fprintf(stderr,"!!  DONT USE FOR bitpix=8  !!\n");
    fprintf(stderr,"!!  DONT USE FOR bitpix=-64  !!\n");
    fprintf(stderr,"!!  DONT USE FOR UNSIGNED TYPES  !!\n");
  }

  if (matrix[0].unsign) {
    switch (matrix[0].bitpix) {
    case 8:
      value = *((unsigned char  *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR UNSIGNED TYPES  !!\n");
      break;
    case 16:
      value = *((unsigned short *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR UNSIGNED TYPES  !!\n");
      break;
    case 32:
      value = *((unsigned int   *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR UNSIGNED TYPES  !!\n");
      break;
    case -32:
      value = *((float          *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR UNSIGNED TYPES  !!\n");
      break;
    case -64:
      value = *((double         *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR UNSIGNED TYPES  !!\n");
      break;
    }
  }
  else {
    switch (matrix[0].bitpix) {
    case 8:
      value = *((char  *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR bitpix=8  !!\n");
      break;
    case 16:
      short1 = *((short *) matrix[0].buffer + pixel);
      short2 = 0;
      swab(&short1,&short2,2);
      value = short2;
      break;
    case 32:
      int1 = *((int   *) matrix[0].buffer + pixel);
      int2 = 0;
      bcopy(&int1,&zzz[0],4);
      yyy[0] = zzz[3];
      yyy[1] = zzz[2];
      yyy[2] = zzz[1];
      yyy[3] = zzz[0];
      bcopy(&yyy[0],&int2,4);
      value = int2;
      break;
    case -32:
      float1 = *((float          *) matrix[0].buffer + pixel);
      float2 = 0;
      bcopy(&float1,&zzz[0],4);
      yyy[0] = zzz[3];
      yyy[1] = zzz[2];
      yyy[2] = zzz[1];
      yyy[3] = zzz[0];
      bcopy(&yyy[0],&float2,4);
      value = float2;
      break;
    case -64:
      value = *((double         *) matrix[0].buffer + pixel);
      fprintf(stderr,"!!  DONT USE FOR bitpix=-64  !!\n");
      break;
    }
  }

  value = matrix[0].bscale*value + matrix[0].bzero;
  return (value);

}


