Example #1
0
void xysetpl_c(int thandle,int naxis,Const int *axes)
/**xysetpl -- Set which plane of a cube is to be accessed.		*/
/*:image-i/o								*/
/*+ FORTRAN call sequence:

	subroutine xysetpl(tno,naxis,nsize)
	integer tno,naxis,nsize(naxis)

  This sets up which plane of a cube is to be accessed.

  Input:
    tno		Handle of the image file.
    naxis	Size of the "nsize" array.
    nsize	This gives the indices, along the 3rd, 4th, 5th, etc
		dimensions, of the plane that is to be accessed. nsize(1)
		corresponds to the index along the 3rd dimension.	*/
/*----------------------------------------------------------------------*/
{
  int i;
  size_t size;

  if(naxis+2 > MAXNAX)
     bug_c('f',"xysetpl_c: Too many dimensions");
  size = 0;
  for(i=naxis-1; i >= 0; i--){
    if(axes[i] < 1 || axes[i] > images[thandle].axes[i+2])
	bug_c('f',"Dimension error in XYSETPL");
    size = ( size + axes[i] - 1) * images[thandle].axes[i+1];
  }
  images[thandle].offset = size * images[thandle].axes[0];
}
Example #2
0
void xymkwr_c(int thandle,int index,Const int *runs,int n)
/**xymkwr -- write image masking information (runs format).		*/
/*:image-i/o								*/
/*+ FORTRAN call sequence:

	subroutine xymkwr(tno,index,runs,n)
	integer tno,index,n
	integer runs(n)

  This writes out the masking information associated with a row of an image.
  This information is passes in in "runs" format. 

  Input:
    tnoe	The handle associated with the image.
    index	The index of the row to determine mask info about. The
		last call to xysetpl determines which plane to access.
    n		The size of the array containing the mask info.
    runs	The mask info, in "runs" form. If "i" varies from 1 to
		nread/2, then pixels runs(2*i-1) to runs(2*i) are
		good, whereas pixels runs(2*i) to runs(2*i+1) are bad.	*/
/*----------------------------------------------------------------------*/
{
  off_t offset;
  size_t length;

  if(images[thandle].mask == NULL) xymkopen_c(thandle,NEW);
  if(images[thandle].mask == NULL) 
    bug_c('f',"xymkwr_c: Error writing to image mask file");
  length = images[thandle].axes[0];
  offset = images[thandle].offset + (index-1) * length;
  mkwrite_c(images[thandle].mask,MK_RUNS,runs,offset,length,n);
}
Example #3
0
void xyflgwr_c(int thandle,int index,Const int *flags)
/**xyflgwr -- Write image masking information (flags format).		*/
/*:image-i/o								*/
/*+ FORTRAN call sequence:

	subroutine xyflgwr(tno,index,flags)
	integer tno,index
	logical flags(*)

  This writes image mask information. It is the counterpart of xywrite.
  Input:
    tno		Handle of the image file.
    index	The row in a plane to write out. This varies between 1 and
		NAXIS2. See xysetpl to set the which plane is to be
		accessed.
    flags	A logical array of NAXIS1 elements. A true value indicates
		that the pixel is good.					*/
/*----------------------------------------------------------------------*/
{
  off_t offset;
  size_t length;

  if(images[thandle].mask == NULL)xymkopen_c(thandle,NEW);
  if(images[thandle].mask == NULL) 
    bug_c('f',"xyflgwr_c: Error writing to image mask file");
  length = images[thandle].axes[0];
  offset = images[thandle].offset + (index-1) * length;
  mkwrite_c(images[thandle].mask,MK_FLAGS,flags,offset,length,length);
}
Example #4
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);
  }
}
Example #5
0
void scrread_c(int handle,float *buffer,int offset,int length)
/**scrread -- Read real data from a scratch file.			*/
/*:scratch-i/o								*/
/*+  FORTRAN call sequence:

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

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

  hreadb_c(handle,(char *)buffer,
    (off64_t)sizeof(float)*offset,sizeof(float)*length,&iostat);
  if(iostat){
    bug_c(  'w',"Error reading from scratch file");
    bugno_c('f',iostat);
  }
}
Example #6
0
void bugno_c(char s,int n)
/** bugno -- Issue an error message, given a system error number.	*/
/*& pjt									*/
/*: error-handling							*/
/*+ FORTRAN call sequence:
	subroutine bugno(severity,errno)

	implicit none
	character severity*1
	integer errno

  Output the error message associated with a particular error number.

  Input:
    severity	Error severity. Can be one of 'i', 'w', 'e' or 'f'
		for "informational", "warning", "error", or "fatal"
    errno	host error number.					*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  if (n == -1)bug_c(s,"End of file detected");
  else bug_c(s,errmsg_c(n));
}
Example #7
0
void dopen_c(int *fd,char *name,char *status,off_t *size,int *iostat)
/*
  Open a file.
  Input:
    name	Name of file to create (in host format).
    status	Either "read", "write", "append" or "scratch".
                "scratch" files are using $TMPDIR, if present, else current.

  Output:
    fd		File descriptor.
    size	Size of file.
    iostat	I/O status.

------------------------------------------------------------------------*/
{
  int is_scratch,pid,flags=0;
  char *s,sname[MAXPATH];

  is_scratch = *iostat = 0;
  s = name;

  if     (!strcmp(status,"read"))    flags = O_RDONLY;
  else if(!strcmp(status,"write"))   flags = O_CREAT|O_TRUNC|O_RDWR;
  else if(!strcmp(status,"append"))  flags = O_CREAT|O_RDWR;
  else if(!strcmp(status,"scratch")){
    flags = O_CREAT|O_TRUNC|O_RDWR;
    is_scratch = 1;
    s = getenv("TMPDIR");
    pid = getpid();
    if(s != NULL)sprintf(sname,"%s/%s.%d",s,name,pid);
    else         sprintf(sname,"%s.%d",name,pid);
    s = sname;
  } else bug_c('f',"dopen_c: Unrecognised status");
#ifdef O_LARGEFILE
  flags |= O_LARGEFILE;
#endif
  if((*fd = open(s,flags,0644)) < 0){*iostat = errno; return;}
  *size = Lseek(*fd,0,SEEK_END);

/* If its a scratch file, unlink it now, so that the file will disappear
   when it is closed (or this program crashes). */

  if(is_scratch)(void)unlink(s);
}
Example #8
0
void xymkrd_c(int thandle,int index,int *runs,int n,int *nread)
/**xymkrd -- Read the masking information for an image (runs format).	*/
/*:image-i/o								*/
/*+ FORTRAN call sequence:

	subroutine xymkrd(tno,index,runs,n,nread)
	integer tno,index,n,nread
	integer runs(n)

  This reads the masking information associated with a row of an image,
  and returns it in "runs" format. 

  Input:
    tnoe	The handle associated with the image.
    index	The index of the row to determine mask info about. The
		last call to xysetpl determines which plane to access.
    n		The size of the array to receive the mask info.
  Output:
    runs	The mask info, in "runs" form. If "i" varies from 1 to
		nread/2, then pixels runs(2*i-1) to runs(2*i) are
		good, whereas pixels runs(2*i) to runs(2*i+1) are bad.
    nread	The number of "runs" read.				*/
/*----------------------------------------------------------------------*/
{
  off_t offset;
  size_t length;

  if(images[thandle].mask == NULL && images[thandle].mask_exists)
						xymkopen_c(thandle,OLD);
  if(images[thandle].mask_exists){
    length = images[thandle].axes[0];
    offset = images[thandle].offset + (index-1) * length;
    *nread = mkread_c(images[thandle].mask,MK_RUNS,runs,offset,length,n);
  } else {
    if(n < 2) 
        bug_c('f',"xymkrd_c: Runs array overflow");
    runs[0] = 1;
    runs[1] = images[thandle].axes[0];
    *nread = 2;
  }
}
Example #9
0
void scrclose_c(int handle)
/**scrclose -- Close and delete a scratch file.				*/
/*:scratch-i/o								*/
/*+  FORTRAN call sequence:

	subroutine scrclose(tno)
	integer tno

  This closes and deletes a scratch file. The scratch file cannot be
  accessed again, after it is closed.
  Input:
    tno		The handle of the scratch file.				*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int iostat;

  hdaccess_c(handle,&iostat);
  if(iostat){
    bug_c(  'w',"Error closing scratch file");
    bugno_c('f',iostat);
  }
}
Example #10
0
void hisopen_c(int tno,Const char *status)
/** hisopen -- Open the history file.					*/
/*& pjt									*/
/*: header-i/o								*/
/*+ FORTRAN call sequence:

	subroutine hisopen(tno,status)
	integer tno
	character status

  This opens the history file, and readies it to be read or written.

  Inputs:
    tno		The handle of the open data set.
    status	Either "read", "write" or "append".			*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int iostat;
  haccess_c(tno,&history[tno],"history",status,&iostat);
  if(iostat) {bug_c('e',"Problem with history item");};
  check(iostat);
}
Example #11
0
void scropen_c(int *handle)
/**scropen -- Open a scratch file.					*/
/*:scratch-i/o								*/
/*+  FORTRAN call sequence:

	subroutine scropen(tno)
	integer tno

  This opens a scratch file, and readies it for use.
  Output:
    tno		The handle of the scratch file.				*/
/*--									*/
/*----------------------------------------------------------------------*/
{
  int iostat;
  char name[32];

  (void)sprintf(name,"scratch%d",number++);
  haccess_c(0,handle,name,"scratch",&iostat);
  if(iostat){
    bug_c(  'w',"Error opening scratch file");
    bugno_c('f',iostat);
  }
}