Exemplo n.º 1
0
void wrhda_c(int thandle,Const char *keyword,Const char *value)
/** wrhda -- Write a string-valued header variable.			*/
/*& mjs									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine wrhda(tno,keyword,value)
	integer tno
	character keyword*(*)
	character value*(*)

  Write a string valued header variable.

  Input:
    tno		The file handle of the data set.
    keyword	The name of the header variable.
    value	The value of the header variable.			*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int item;
  int iostat;

  haccess_c(thandle,&item,keyword,"write",&iostat);		check(iostat);
  hwriteb_c(item,char_item,0,ITEM_HDR_SIZE,&iostat);		check(iostat);
  hwriteb_c(item,(char *)value,ITEM_HDR_SIZE,
	    strlen(value),&iostat);                             check(iostat);
  hdaccess_c(item,&iostat);					check(iostat);
}
Exemplo n.º 2
0
void scrwrite_c(int handle,Const float *buffer,int offset,int length)
/**scrwrite -- Write real data to the scratch file.			*/
/*:scratch-i/o								*/
/*+  FORTRAN call sequence:

	subroutine scrwrite(tno,buf,offset,length)
	integer tno,offset,length
	real buf(length)

  This writes real data to the scratch file.
  Input:
    tno		The handle of the scratch file.
    offset	The offset (measured in reals) into the scratch file
		to write. The first real has offset 0.
    length	The number of reals to write.
    buf		The data to write.					*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int iostat;

  hwriteb_c(handle,(char *)buffer,
    (off64_t)sizeof(float)*offset,sizeof(float)*length,&iostat);
  if(iostat){
    bug_c(  'w',"Error writing to scratch file");
    bugno_c('f',iostat);
  }
}
Exemplo n.º 3
0
void wrhdc_c(int thandle,Const char *keyword,Const float *value)
/** wrhdc -- Write a complex-valued header variable.			*/
/*& mjs									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine wrhdc(tno,keyword,value)
	integer tno
	character keyword*(*)
	complex value

  Write a complex valued header variable.
  Input:
    tno		The file handle fo the data set.
    keyword	The name of the header variable.
    value	The complex value of the header variable.		*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int item;
  int iostat,offset;

  haccess_c(thandle,&item,keyword,"write",&iostat);		check(iostat);
  hwriteb_c(item,cmplx_item,0,ITEM_HDR_SIZE,&iostat);		check(iostat);
  offset = mroundup(ITEM_HDR_SIZE,H_CMPLX_SIZE);
  hwritec_c(item,value,offset,H_CMPLX_SIZE,&iostat);		check(iostat);
  hdaccess_c(item,&iostat);					check(iostat);
}
Exemplo n.º 4
0
void wrhdl_c(int thandle,Const char *keyword,int8 value)
/** wrhdl -- Write an integer*8 valued header variable.			*/
/*& pjt									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine wrhdl(tno,keyword,value)
	integer tno
	character keyword*(*)
	integer*8 value

  Write an integer*8 valued header variable. This is only supported
  on compilers that know how to handle integer*8 (e.g. gnu, intel).
  Without this support, some files in miriad will be limited to
  8 GB.

  Input:
    tno		The handle of the data set.
    keyword	The name of the header variable.
    value	The integer*8 value of the header variable.		*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int item;
  int iostat,offset;

  /* Sault proposes to write an INT if below 2^31, else INT8 */

  haccess_c(thandle,&item,keyword,"write",&iostat);		check(iostat);
  hwriteb_c(item,int8_item,0,ITEM_HDR_SIZE,&iostat);		check(iostat);
  offset = mroundup(ITEM_HDR_SIZE,H_INT8_SIZE);
  hwritel_c(item,&value,offset,H_INT8_SIZE,&iostat);		check(iostat);
  hdaccess_c(item,&iostat);					check(iostat);
}
Exemplo n.º 5
0
void wrhdi_c(int thandle,Const char *keyword,int value)
/** wrhdi -- Write an integer valued header variable.			*/
/*& mjs									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine wrhdi(tno,keyword,value)
	integer tno
	character keyword*(*)
	integer value

  Write an integer valued header variable.

  Input:
    tno		The handle of the data set.
    keyword	The name of the header variable.
    value	The integer value of the header variable.		*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int item;
  int iostat,offset;

  haccess_c(thandle,&item,keyword,"write",&iostat);		check(iostat);
  hwriteb_c(item,int_item,0,ITEM_HDR_SIZE,&iostat);		check(iostat);
  offset = mroundup(ITEM_HDR_SIZE,H_INT_SIZE);
  hwritei_c(item,&value,offset,H_INT_SIZE,&iostat);		check(iostat);
  hdaccess_c(item,&iostat);					check(iostat);
}
Exemplo n.º 6
0
void wrhdd_c(int thandle,Const char *keyword,double value)
/** wrhdd -- Write a double precision valued header variable.		*/
/*& mjs									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine wrhdd(tno,keyword,value)
	integer tno
	character keyword*(*)
	double precision value

  Write the value of a header variable which has a double precision value.

  Input:
    tno		The handle of the data set.
    keyword	Name to the keyword.
    value	The double precision value.				*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int item;
  int iostat,offset;

  haccess_c(thandle,&item,keyword,"write",&iostat);		check(iostat);
  hwriteb_c(item,dble_item,0,ITEM_HDR_SIZE,&iostat);		check(iostat);
  offset = mroundup(ITEM_HDR_SIZE,H_DBLE_SIZE);
  hwrited_c(item,&value,offset,H_DBLE_SIZE,&iostat);		check(iostat);
  hdaccess_c(item,&iostat);					check(iostat);
}
Exemplo n.º 7
0
void wrhdr_c(int thandle,Const char *keyword,double value)
/** wrhdr -- Write a real valued header variable.			*/
/*& pjt									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine wrhdr(tno,keyword,value)
	integer tno
	character keyword*(*)
	real value

  This writes a real-valued header keyword.
  Input:
    tno		Handle of the data set.
    keyword	Name of the keyword to write.
    value	The value of the keyword.				*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int item;
  float temp;
  int iostat,offset;

  temp = value;
  haccess_c(thandle,&item,keyword,"write",&iostat);		check(iostat);
  hwriteb_c(item,real_item,0,ITEM_HDR_SIZE,&iostat);		check(iostat);
  offset = mroundup(ITEM_HDR_SIZE,H_REAL_SIZE);
  hwriter_c(item,&temp,offset,H_REAL_SIZE,&iostat);		check(iostat);
  hdaccess_c(item,&iostat);					check(iostat);
}
Exemplo n.º 8
0
void hdcopy_c(int tin,int tout,Const char *keyword)
/** hdcopy -- Copy a headfer variable from one data set to another.	*/
/*& mjs									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine hdcopy(tin,tout,keyword)
	integer tin,tout
	character keyword*(*)

  Copy a header item from one data set to another.

  Input:
    tin		File handle of the input data set.
    tout	File handle of the output data set.
    keyword	Name of the header variable to be copied.		*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  char buf[MAXSIZE];
  int item_in,item_out;
  int length,offset,iostat,size;

  haccess_c(tin,&item_in,keyword,"read",&iostat);	if(iostat)return;
  haccess_c(tout,&item_out,keyword,"write",&iostat);	check(iostat);

  size = hsize_c(item_in);
  offset = 0;
  while(offset < size){
    length = min(size - offset, sizeof(buf));
    hreadb_c(item_in,buf,offset,length,&iostat);	check(iostat);
    hwriteb_c(item_out,buf,offset,length,&iostat);	check(iostat);
    offset += length;
  }
  hdaccess_c(item_in,&iostat);				check(iostat);
  hdaccess_c(item_out,&iostat);				check(iostat);
}
Exemplo n.º 9
0
void xyopen_c(int *thandle,Const char *name,Const char *status,int naxis,int *axes)
/**xyopen -- Open an image file.					*/
/*:image-i/o								*/
/*+ FORTRAN call sequence:

	subroutine xyopen(tno,name,status,naxis,axes)
	integer tno,naxis,axes(naxis)
	character name*(*),status*(*)

  This opens an image file. For an old file, determine the size of
  each axe. For a new file, it writes out this info.

  Input:
    name	The name of the file to be opened.
    status	Either 'old', 'new' or 'append'.
    naxis	The maximum number of axes that the calling program can
		handle. For an 'old' file, if the data file has fewer
		than naxis axes, the higher dimensions are treated as having
		only one element. If the data file has more than naxis
		axes, and the higher dimensions are more than 1 element
		deep, xyopen bombs out.
  Input or Output:
    axes	This is input for status='new' and output for status='old'.
		It gives the number of elements along each axis.
  Output:
    tno		The handle of the output file.				*/
/*----------------------------------------------------------------------*/
{
  int iostat,length,access,tno,i,ndim,npix,temp;
  char *stat,*mode,naxes[16],s[ITEM_HDR_SIZE];

  if(!strcmp("old",status))	   { access = OLD; mode = "read";  stat = "old";}
  else if(!strcmp("append",status)){ access = OLD; mode = "append";stat = "old";}
  else if(!strcmp("new",status))   { access = NEW; mode = "write"; stat = "new";}
  else
   ERROR('f',(message,"Unrecognised status when opening %s, in XYOPEN",name));

/* Access the image data. */

  hopen_c(&tno,name,stat,&iostat);
  CHECK(iostat,(message,"Error opening %s, in XYOPEN",name));
  haccess_c(tno,&(images[tno].image),"image",mode,&iostat);
  CHECK(iostat,(message,"Error accessing pixel data of %s, in XYOPEN",name));

/*----------------------------------------------------------------------*/
/*									*/
/*	Handle an old image. Get number of axes, and then the length	*/
/*	of each axis. Also compute and check that the size of the 	*/
/*	image file looks OK.						*/
/*									*/
/*----------------------------------------------------------------------*/

  if(access == OLD){
    rdhdi_c(tno,"naxis",&ndim,0);
    if(ndim <= 0 || ndim > MAXNAX) 
        ERROR('f',(message,"Bad number of dimensions for %s in XYOPEN",name));

    Strcpy(naxes,"naxis0");
    length = strlen(naxes) - 1;
    npix = 1;
    for(i=0; i<max(ndim,naxis); i++){
      naxes[length] ++;
      if(i < ndim) rdhdi_c(tno,naxes,&temp,0);
      else temp = 1;
      if(temp <= 0)
	ERROR('f',(message,"Bad image dimension for %s, in XYOPEN",name));
      npix = npix * temp;
      if(i < naxis) axes[i] = temp;
      else if(temp > 1)
	ERROR('f',(message,"Too many dimensions for %s, in XYOPEN",name));
    }

/* Check the file size if OK and that it starts with the "real_item"
   sequence. */

    if(hsize_c(images[tno].image) < H_REAL_SIZE*npix+ITEM_HDR_SIZE)
      ERROR('f',(message,"Pixel data for %s appears too small, in XYOPEN",name));
    hreadb_c(images[tno].image,s,0,ITEM_HDR_SIZE,&iostat);
      CHECK(iostat,(message,"Error reading pixel data label for %s, in XYOPEN",name));
    if( memcmp(s,real_item,ITEM_HDR_SIZE) ) 
      ERROR('f',(message,"Bad pixel data label for %s, in XYOPEN",name));

/*----------------------------------------------------------------------*/
/*									*/
/*	A new image. Write out all the axes infomation, and initialise	*/
/*	the file with the "binary item" sequence.			*/
/*									*/
/*----------------------------------------------------------------------*/

  } else {
    wrhdi_c(tno,"naxis",naxis);
    Strcpy(naxes,"naxis0");
    length = strlen(naxes) - 1;
    for(i=0; i < naxis; i++){
      naxes[length] ++;
      wrhdi_c(tno,naxes,axes[i]);
    }
    hwriteb_c(images[tno].image,real_item,0,ITEM_HDR_SIZE,&iostat);
    CHECK(iostat,(message,"Error writing pixel data label for %s, in XYOPEN",name));
  }

/* Common to old and new. Copy the dimension info to the local description. */

  images[tno].offset = 0;
  images[tno].naxis  = naxis;
  for(i=0; i < naxis; i++) images[tno].axes[i] = axes[i];
  for(i = naxis; i < MAXNAX; i++) images[tno].axes[i] = 1;
  images[tno].mask = NULL;
  images[tno].image_exists = TRUE;
  images[tno].mask_exists = TRUE;
  *thandle = tno;
}
Exemplo n.º 10
0
/* hwrite supports writing to header items of all types, using the various
 * hwrite_c calls.  Writes one item per call. */
PyObject * WRAP_hwrite(PyObject *self, PyObject *args) {
    int item_hdl, offset, iostat;
    char *type;
    PyObject *val;
    int in; short sh; long lg; float fl; double db; float cx[2]; char *st;
    if (!PyArg_ParseTuple(args, "iiOs", &item_hdl, &offset, &val, &type))
        return NULL;
    try {
        switch (type[0]) {
            case 'a':
                CHK_STRING(val);
                st = PyString_AsString(val);
                in = PyString_Size(val); // # bytes to write
                hwriteb_c(item_hdl, st, offset, in, &iostat);
                CHK_IO(iostat);
                offset = H_BYTE_SIZE * in;
                break;
            case 'i':
                CHK_INT(val);
                in = (int) PyInt_AsLong(val);
                hwritei_c(item_hdl, &in, offset, H_INT_SIZE, &iostat);
                CHK_IO(iostat);
                offset = H_INT_SIZE;
                break;
            case 'j':
                CHK_INT(val);
                sh = (short) PyInt_AsLong(val);
                hwritej_c(item_hdl, &sh, offset, H_INT2_SIZE, &iostat);
                CHK_IO(iostat);
                offset = H_INT2_SIZE;
                break;
            case 'l':
                CHK_LONG(val);
                lg = PyLong_AsLong(val);
                hwritel_c(item_hdl, &lg, offset, H_INT8_SIZE, &iostat);
                CHK_IO(iostat);
                offset = H_INT8_SIZE;
                break;
            case 'r':
                CHK_FLOAT(val);
                fl = (float) PyFloat_AsDouble(val);
                hwriter_c(item_hdl, &fl, offset, H_REAL_SIZE, &iostat);
                CHK_IO(iostat);
                offset = H_REAL_SIZE;
                break;
            case 'd':
                CHK_FLOAT(val);
                db = PyFloat_AsDouble(val);
                hwrited_c(item_hdl, &db, offset, H_DBLE_SIZE, &iostat);
                CHK_IO(iostat);
                offset = H_DBLE_SIZE;
                break;
            case 'c':
                CHK_COMPLEX(val);
                cx[0] = (float) PyComplex_RealAsDouble(val);
                cx[1] = (float) PyComplex_ImagAsDouble(val);
                hwritec_c(item_hdl, cx, offset, H_CMPLX_SIZE, &iostat);
                CHK_IO(iostat);
                offset = H_CMPLX_SIZE;
                break;
            default:
                PyErr_Format(PyExc_ValueError, "unknown item type: %c",type[0]);
                return NULL;
        }
        return PyInt_FromLong(offset);
    } catch (MiriadError &e) {
        PyErr_Format(PyExc_RuntimeError, e.get_message());
        return NULL;
    }
}