예제 #1
0
/**
   Setting up aperture cordinate grid aper_locs, and amplitude map for
performance evaluation. */
APER_T * setup_aper(const PARMS_T *const parms){
    APER_T *aper = mycalloc(1,APER_T);
    tic;
    if(parms->aper.fnamp){
	info2("Reading aperture amplitude map from %s\n", parms->aper.fnamp);
	aper->ampground=mapread("%s",parms->aper.fnamp);
	if(fabs(aper->ampground->h)>1.e-14){
	    warning("ampground is not on ground, this is not tested\n");
	}else{
	    double amp_d, amp_din;
	    map_d_din(aper->ampground, &amp_d, &amp_din);
	    if(fabs(parms->aper.d - amp_d) > 1 ||
	       fabs(parms->aper.din - amp_din) > 0.5){
		if(!parms->aper.fnampuser){
		    warning2("Amplitude map does not match aperture diameter: amp.d=(%g, %g) aper.d=(%g, %g). Disabled\n", 
			     amp_d, amp_din, parms->aper.d, parms->aper.din);
		    mapfree(aper->ampground);
		    free(((PARMS_T*)parms)->aper.fnamp);
		    ((PARMS_T*)parms)->aper.fnamp=0;
		}else{
		    error("Use supplied amplitude map does not match aperture diameter: amp.d=(%g, %g) aper.d=(%g, %g).\n", 
			  amp_d, amp_din, parms->aper.d, parms->aper.din);
		}
	    }
	}
	if(fabs(parms->aper.rotdeg)>1.e-12){
	    warning("Pupil is rotated by %g deg\n",parms->aper.rotdeg);
	    const long nx=aper->ampground->nx;
	    const long ny=aper->ampground->ny;
	    dmat *B=dnew_data(nx, ny, aper->ampground->p);
	    aper->ampground->p=mycalloc(nx*ny,double);
	    dembed((dmat*)aper->ampground,B,parms->aper.rotdeg/180.*M_PI);
	    dfree(B);
	}
예제 #2
0
int index_search_item::load(int fd)
{
  file_closer fd_closer(fd);	// close fd on return
  unused(&fd_closer);
  struct stat sb;
  if (fstat(fd, &sb) < 0) {
    error("can't fstat `%1': %2", name, strerror(errno));
    return 0;
  }
  if (!S_ISREG(sb.st_mode)) {
    error("`%1' is not a regular file", name);
    return 0;
  }
  mtime = sb.st_mtime;
  int size = int(sb.st_size);
  char *addr;
  map_addr = mapread(fd, size);
  if (map_addr) {
    addr = (char *)map_addr;
    map_len = size;
  }
  else {
    addr = buffer = (char *)malloc(size);
    if (buffer == 0) {
      error("can't allocate buffer for `%1'", name);
      return 0;
    }
    char *ptr = buffer;
    int bytes_to_read = size;
    while (bytes_to_read > 0) {
      int nread = read(fd, ptr, bytes_to_read);
      if (nread == 0) {
	error("unexpected EOF on `%1'", name);
	return 0;
      }
      if (nread < 0) {
	error("read error on `%1': %2", name, strerror(errno));
	return 0;
      }
      bytes_to_read -= nread;
      ptr += nread;
    }
  }
  header = *(index_header *)addr;
  if (header.magic != INDEX_MAGIC) {
    error("`%1' is not an index file: wrong magic number", name);
    return 0;
  }
  if (header.version != INDEX_VERSION) {
    error("version number in `%1' is wrong: was %2, should be %3",
	  name, header.version, INDEX_VERSION);
    return 0;
  }
  int sz = (header.tags_size * sizeof(tag)
	    + header.lists_size * sizeof(int)
	    + header.table_size * sizeof(int)
	    + header.strings_size
	    + sizeof(header));
  if (sz != size) {
    error("size of `%1' is wrong: was %2, should be %3",
	  name, size, sz);
    return 0;
  }
  tags = (tag *)(addr + sizeof(header));
  lists = (int *)(tags + header.tags_size);
  table = (int *)(lists + header.lists_size);
  pool = (char *)(table + header.table_size);
  ignore_fields = strchr(strchr(pool, '\0') + 1, '\0') + 1;
  key_buffer = new char[header.truncate];
  read_common_words_file();
  return 1;
}