bool_t
xdr_rpc_loc_assist_data_pos_s_type (XDR *xdrs, rpc_loc_assist_data_pos_s_type *objp)
{
    register int32_t *buf;

    if (!xdr_rpc_loc_assist_pos_valid_mask_type (xdrs, &objp->valid_mask))
        return FALSE;
    if (!xdr_rpc_uint64 (xdrs, &objp->timestamp_utc))
        return FALSE;
    if (!xdr_double (xdrs, &objp->latitude))
        return FALSE;
    if (!xdr_double (xdrs, &objp->longitude))
        return FALSE;
    if (!xdr_float (xdrs, &objp->altitude_wrt_ellipsoid))
        return FALSE;
    if (!xdr_float (xdrs, &objp->altitude_wrt_mean_sea_level))
        return FALSE;
    if (!xdr_float (xdrs, &objp->hor_unc_circular))
        return FALSE;
    if (!xdr_float (xdrs, &objp->vert_unc))
        return FALSE;
    if (!xdr_u_char (xdrs, &objp->confidence_horizontal))
        return FALSE;
    if (!xdr_u_char (xdrs, &objp->confidence_vertical))
        return FALSE;
    if (!xdr_rpc_int32 (xdrs, &objp->timestamp_age))
        return FALSE;
    return TRUE;
}
Example #2
0
File: ssio.c Project: jpcoles/ZM
int
ssioHead(SSIO *ssio,SSHEAD *head) {
    assert(ssio != NULL && head != NULL);
    if (!xdr_double(&ssio->xdrs,&head->time)) return 1;
    if (!xdr_int(&ssio->xdrs,&head->n_data)) return 1;
    if (!xdr_int(&ssio->xdrs,&head->n_planets)) return 1;
    if (!xdr_double(&ssio->xdrs,&head->dEcoll)) return 1;
    if (!xdr_double(&ssio->xdrs,&head->dSunMass)) return 1;
    return 0;
    }
bool_t
xdr_rpc_loc_parsed_position_s_type (XDR *xdrs, rpc_loc_parsed_position_s_type *objp)
{
    register int32_t *buf;

    if (!xdr_rpc_loc_position_valid_mask_type (xdrs, &objp->valid_mask))
        return FALSE;
    if (!xdr_rpc_loc_session_status_e_type (xdrs, &objp->session_status))
        return FALSE;
    if (!xdr_rpc_loc_calendar_time_s_type (xdrs, &objp->timestamp_calendar))
        return FALSE;
    if (!xdr_rpc_uint64 (xdrs, &objp->timestamp_utc))
        return FALSE;
    if (!xdr_rpc_uint8 (xdrs, &objp->leap_seconds))
        return FALSE;
    if (!xdr_float (xdrs, &objp->time_unc))
        return FALSE;
    if (!xdr_double (xdrs, &objp->latitude))
        return FALSE;
    if (!xdr_double (xdrs, &objp->longitude))
        return FALSE;
    if (!xdr_float (xdrs, &objp->altitude_wrt_ellipsoid))
        return FALSE;
    if (!xdr_float (xdrs, &objp->altitude_wrt_mean_sea_level))
        return FALSE;
    if (!xdr_float (xdrs, &objp->speed_horizontal))
        return FALSE;
    if (!xdr_float (xdrs, &objp->speed_vertical))
        return FALSE;
    if (!xdr_float (xdrs, &objp->heading))
        return FALSE;
    if (!xdr_float (xdrs, &objp->hor_unc_circular))
        return FALSE;
    if (!xdr_float (xdrs, &objp->hor_unc_ellipse_semi_major))
        return FALSE;
    if (!xdr_float (xdrs, &objp->hor_unc_ellipse_semi_minor))
        return FALSE;
    if (!xdr_float (xdrs, &objp->hor_unc_ellipse_orient_azimuth))
        return FALSE;
    if (!xdr_float (xdrs, &objp->vert_unc))
        return FALSE;
    if (!xdr_float (xdrs, &objp->speed_unc))
        return FALSE;
    if (!xdr_float (xdrs, &objp->heading_unc))
        return FALSE;
    if (!xdr_u_char (xdrs, &objp->confidence_horizontal))
        return FALSE;
    if (!xdr_u_char (xdrs, &objp->confidence_vertical))
        return FALSE;
    if (!xdr_float (xdrs, &objp->magnetic_deviation))
        return FALSE;
    if (!xdr_rpc_loc_pos_technology_mask_type (xdrs, &objp->technology_mask))
        return FALSE;
    return TRUE;
}
Example #4
0
int
G3d_readRange(const char *name, const char *mapset, struct FPRange *drange)
 /* adapted from G_read_fp_range */
{
    int fd;
    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
    char buf[GNAME_MAX + sizeof(G3D_DIRECTORY) + 2],
	buf2[GMAPSET_MAX + sizeof(G3D_RANGE_ELEMENT) + 2];
    char xdr_buf[100];
    DCELL dcell1, dcell2;
    XDR xdr_str;

    G_init_fp_range(drange);

    fd = -1;

    if (G__name_is_fully_qualified(name, xname, xmapset)) {
	sprintf(buf, "%s/%s", G3D_DIRECTORY, xname);
	sprintf(buf2, "%s@%s", G3D_RANGE_ELEMENT, xmapset);	/* == range@mapset */
    }
    else {
	sprintf(buf, "%s/%s", G3D_DIRECTORY, name);
	sprintf(buf2, "%s", G3D_RANGE_ELEMENT);
    }

    if (G_find_file2(buf, buf2, mapset)) {
	fd = G_open_old(buf, buf2, mapset);
	if (fd < 0)
	    goto error;

	if (read(fd, xdr_buf, 2 * G3D_XDR_DOUBLE_LENGTH) !=
	    2 * G3D_XDR_DOUBLE_LENGTH)
	    return 2;

	xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2,
		      XDR_DECODE);

	/* if the f_range file exists, but empty */
	if (!xdr_double(&xdr_str, &dcell1) || !xdr_double(&xdr_str, &dcell2))
	    goto error;

	G_update_fp_range(dcell1, drange);
	G_update_fp_range(dcell2, drange);
	close(fd);
	return 1;
    }

  error:
    if (fd > 0)
	close(fd);
    G_warning("can't read range file for [%s in %s]", name, mapset);
    return -1;
}
Example #5
0
bool_t
xdr___db_key_range_reply (XDR *xdrs, __db_key_range_reply *objp)
{
	register int32_t *buf;

	 if (!xdr_u_int (xdrs, &objp->status))
		 return FALSE;
	 if (!xdr_double (xdrs, &objp->less))
		 return FALSE;
	 if (!xdr_double (xdrs, &objp->equal))
		 return FALSE;
	 if (!xdr_double (xdrs, &objp->greater))
		 return FALSE;
	return TRUE;
}
Example #6
0
int ssioHead(SSIO *ssio,SSHEAD *head)
{
	assert(ssio != NULL && head != NULL);

#ifdef SSIO_USE_MPI

    if (SSIO_READ == ssio->fmode)
    {
        READ_FUNC(ssio->mfile, &head->time, sizeof(SSHEAD), MPI_CHAR, MPI_STATUS_IGNORE);
    }
    else //if (SSIO_WRITE == ssio->fmode)
    {
        WRITE_FUNC(ssio->mfile, &head->time, sizeof(SSHEAD), MPI_CHAR, MPI_STATUS_IGNORE);
    }

#else

	if (!xdr_double(&ssio->xdrs,&head->time)) return 1;
	if (!xdr_int(&ssio->xdrs,&head->n_data)) return 1;
	if (!xdr_int(&ssio->xdrs,&head->iMagicNumber)) return 1;
	if (head->iMagicNumber != SSIO_MAGIC_STANDARD &&
		head->iMagicNumber != SSIO_MAGIC_REDUCED) {
		(void) fprintf(stderr,"Invalid SSIO magic number (%i).\n",head->iMagicNumber);
		return 1;
		}

#endif /* SSIO_USE_MPI */

	return 0;
}
Example #7
0
static int writeRange(const char *name, struct FPRange *range)
 /* adapted from G_write_fp_range */
{
    char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
    char buf[GNAME_MAX + sizeof(G3D_DIRECTORY) + 2],
	buf2[GMAPSET_MAX + sizeof(G3D_RANGE_ELEMENT) + 2];
    char xdr_buf[100];
    int fd;
    XDR xdr_str;

    if (G__name_is_fully_qualified(name, xname, xmapset)) {
	sprintf(buf, "%s/%s", G3D_DIRECTORY, xname);
	sprintf(buf2, "%s@%s", G3D_RANGE_ELEMENT, xmapset);	/* == range@mapset */
    }
    else {
	sprintf(buf, "%s/%s", G3D_DIRECTORY, name);
	sprintf(buf2, "%s", G3D_RANGE_ELEMENT);
    }

    fd = G_open_new(buf, buf2);
    if (fd < 0)
	goto error;

    if (range->first_time) {
	/* if range hasn't been updated, write empty file meaning NULLs */
	close(fd);
	return 0;
    }

    xdrmem_create(&xdr_str, xdr_buf, (u_int) G3D_XDR_DOUBLE_LENGTH * 2,
		  XDR_ENCODE);

    if (!xdr_double(&xdr_str, &(range->min)))
	goto error;
    if (!xdr_double(&xdr_str, &(range->max)))
	goto error;

    write(fd, xdr_buf, G3D_XDR_DOUBLE_LENGTH * 2);
    close(fd);
    return 0;

  error:
    G_remove(buf, buf2);	/* remove the old file with this name */
    sprintf(buf, "can't write range file for [%s in %s]", name, G_mapset());
    G_warning(buf);
    return -1;
}
Example #8
0
void
F77_FUNC(xdrfdouble,XDRFDOUBLE)(int *xdrid, double *dp, int *ret)
{
        xdr_fortran_lock();
	*ret = xdr_double(xdridptr[*xdrid], dp);
	cnt += sizeof(double);
        xdr_fortran_unlock();
}
Example #9
0
File: ssio.c Project: jpcoles/ZM
int
ssioData(SSIO *ssio,SSDATA *data) {
    int i;

    assert(ssio != NULL && data != NULL);
    if (!xdr_double(&ssio->xdrs,&data->mass)) return 1;
    if (!xdr_double(&ssio->xdrs,&data->radius)) return 1;
    for (i=0;i<N_DIM;i++)
	if (!xdr_double(&ssio->xdrs,&data->pos[i])) return 1;
    for (i=0;i<N_DIM;i++)
	if (!xdr_double(&ssio->xdrs,&data->vel[i])) return 1;
    for (i=0;i<N_DIM;i++)
	if (!xdr_double(&ssio->xdrs,&data->spin[i])) return 1;
    if (!xdr_int(&ssio->xdrs,&data->color)) return 1;
    if (!xdr_int(&ssio->xdrs,&data->org_idx)) return 1;
    return 0;
    }
Example #10
0
File: kd.c Project: N-BodyShop/fof
int xdrHeader(XDR *pxdrs,struct dump *ph)
{
	int pad = 0;
	
	if (!xdr_double(pxdrs,&ph->time)) return 0;
	if (!xdr_int(pxdrs,&ph->nbodies)) return 0;
	if (!xdr_int(pxdrs,&ph->ndim)) return 0;
	if (!xdr_int(pxdrs,&ph->nsph)) return 0;
	if (!xdr_int(pxdrs,&ph->ndark)) return 0;
	if (!xdr_int(pxdrs,&ph->nstar)) return 0;
	if (!xdr_int(pxdrs,&pad)) return 0;
	return 1;
	}
Example #11
0
int xdr_header(XDR *xdrs, struct dump *header)
{
	int pad=0;
  
	if (xdr_double(xdrs,&header->time) != TRUE) return 0;
	if (xdr_int(xdrs,&header->nbodies) != TRUE) return 0;
	if (xdr_int(xdrs,&header->ndim) != TRUE) return 0;
	if (xdr_int(xdrs,&header->nsph) != TRUE) return 0;
	if (xdr_int(xdrs,&header->ndark) != TRUE) return 0;
	if (xdr_int(xdrs,&header->nstar) != TRUE) return 0;
	if (xdr_int(xdrs,&pad) != TRUE) return 0;
	return 1;
	}
Example #12
0
bool_t
xdr_TSP_port_struct (XDR *xdrs, TSP_port_struct *objp)
{
	register int32_t *buf;

	 if (!xdr_int (xdrs, &objp->i))
		 return FALSE;
	 if (!xdr_double (xdrs, &objp->a))
		 return FALSE;
	 if (!xdr_string (xdrs, &objp->status_str, ~0))
		 return FALSE;
	return TRUE;
}
Example #13
0
double d_print( XDR *xdrs, char *fmt )
{
  double dd;

  if( !xdr_double(xdrs, &dd) )
    {
      fflush( stdout);
      exit(1);
    }

  printf( fmt, dd);

  return dd;
}
Example #14
0
void writeInput(void)
{
  const char routineName[] = "writeInput";

  bool_t  result=TRUE, PRD_angle_dep, XRD, big_endian;
  FILE   *fp_out;
  XDR     xdrs;

  if (!strcmp(INPUT_DOT_OUT, "none")) return;

  if ((fp_out = fopen(INPUT_DOT_OUT, "w")) == NULL) {
    sprintf(messageStr, "Unable to open output file %s",
	    INPUT_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
    return;
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  PRD_angle_dep = (input.PRD_angle_dep != PRD_ANGLE_INDEP  &&  atmos.NPRDactive > 0);
  XRD           = (input.XRD  &&  atmos.NPRDactive > 0);

  /* --- Write various input parameters to file --     -------------- */      

  result &= xdr_bool(&xdrs, &input.magneto_optical);
  result &= xdr_bool(&xdrs, &PRD_angle_dep);
  result &= xdr_bool(&xdrs, &XRD);

  result &= xdr_enum(&xdrs, (enum_t *) &input.startJ);
  result &= xdr_enum(&xdrs, (enum_t *) &input.StokesMode);

  result &= xdr_double(&xdrs, &input.metallicity);

  result &= xdr_bool(&xdrs, &input.backgr_pol);

  /* --- Write Endianness of compute architecture so that J can be
         read properly in the analysis --              -------------- */

  big_endian = is_big_endian();
  result &= xdr_bool(&xdrs, &big_endian);


  if (!result) {
    sprintf(messageStr, "Unable to write proper amount to output file %s",
	    INPUT_DOT_OUT);
    Error(ERROR_LEVEL_1, routineName, messageStr);
  }
  xdr_destroy(&xdrs);
  fclose(fp_out);
}
Example #15
0
int xdr_header()
{
  int pad;
  
  if(xdr_double(&xdrs, &header.time) != TRUE)
    return 0;
  if(xdr_int(&xdrs, &header.nbodies) != TRUE)
    return 0;
  if(xdr_int(&xdrs, &header.ndim) != TRUE)
    return 0;
  if(xdr_int(&xdrs, &header.nsph) != TRUE)
    return 0;
  if(xdr_int(&xdrs, &header.ndark) != TRUE)
    return 0;
  if(xdr_int(&xdrs, &header.nstar) != TRUE)
    return 0;
  if(xdr_int(&xdrs, &pad) != TRUE)
    return 0;
  return 1;
}
Example #16
0
static void convert_double(XDR * xdrs, char *null_buf, const DCELL * rast,
			   int row, int n)
{
    int i;

    for (i = 0; i < n; i++) {
	DCELL d;

	/* substitute embeded null vals by 0's */
	if (Rast_is_d_null_value(&rast[i])) {
	    d = 0.;
	    null_buf[i] = 1;
	}
	else
	    d = rast[i];

	if (!xdr_double(xdrs, &d))
	    G_fatal_error(_("xdr_double failed for index %d of row %d"), i, row);
    }
}
Example #17
0
/* write fracture state */
static void fracture_state_write (DOM *dom)
{
  char path [1024];
  double R[3], r, (*disp) [3];
  int i, n, dofs;
  MESH *msh;
  SET *item;
  BODY *bod;
  CON *con;

#if HDF5
  int numbod;
  PBF *f;

  snprintf (path, 1024, "%s/fracture", dom->solfec->outpath);
  ASSERT (f = PBF_Write (path, PBF_ON, PBF_ON), ERR_FILE_OPEN);

  PBF_Time (f, &dom->time);

  for (numbod = 0, bod = dom->bod; bod; bod = bod->next)
  {
    if (bod->fracture)
    {
      msh = bod->shape->data;
      dofs = 3 * msh->nodes_count;
      ERRMEM (disp = malloc (msh->nodes_count * sizeof (double [3])));
      for (i = 0; i < msh->nodes_count; i ++)
      {
        SUB (msh->cur_nodes [i], msh->ref_nodes [i], disp [i]);
      }

      PBF_Uint (f, &bod->id, 1);
      PBF_Int (f, &dofs, 1);
      PBF_Double (f, (double*)disp, dofs);

      n = SET_Size (bod->con);
      PBF_Int (f, &n, 1);
      for (item = SET_First (bod->con); item; item = SET_Next (item))
      {
	con = item->data;
	r = sqrt (con->area/ALG_PI);
	PBF_Double (f, &r, 1);

	if (bod == con->master)
	{
	  PBF_Double (f, con->mpnt, 3);
	}
	else
	{
	  PBF_Double (f, con->spnt, 3);
	}

        NVMUL (con->base, con->R, R);
	PBF_Double (f, R, 3);
      }

      bod->fracture = 0;

      free (disp);
      numbod ++;
    }

    PBF_Int2 (f, "numbod", &numbod, 1);
  }

  PBF_Close (f);
#else
  FILE *f;
  XDR x;

#if MPI
  snprintf (path, 1024, "%s/fracture%d.dat", dom->solfec->outpath, dom->rank);
#else
  snprintf (path, 1024, "%s/fracture.dat", dom->solfec->outpath);
#endif
  ASSERT (f = fopen (path, "a"), ERR_FILE_OPEN);
  xdrstdio_create (&x, f, XDR_ENCODE);

  for (bod = dom->bod; bod; bod = bod->next)
  {
    if (bod->fracture)
    {
      msh = bod->shape->data;
      dofs = 3 * msh->nodes_count;
      ERRMEM (disp = malloc (msh->nodes_count * sizeof (double [3])));
      for (i = 0; i < msh->nodes_count; i ++)
      {
        SUB (msh->cur_nodes [i], msh->ref_nodes [i], disp [i]);
      }

      ASSERT (xdr_u_int (&x, &bod->id), ERR_FILE_WRITE);
      ASSERT (xdr_int (&x, &dofs), ERR_FILE_WRITE);
      ASSERT (xdr_vector (&x, (char*)disp, dofs, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
      n = SET_Size (bod->con);
      ASSERT (xdr_int (&x, &n), ERR_FILE_WRITE);
      for (item = SET_First (bod->con); item; item = SET_Next (item))
      {
	con = item->data;
	r = sqrt (con->area/ALG_PI);
	ASSERT (xdr_double (&x, &r), ERR_FILE_WRITE);

	if (bod == con->master)
	{
          ASSERT (xdr_vector (&x, (char*)con->mpnt, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
	}
	else
	{
          ASSERT (xdr_vector (&x, (char*)con->spnt, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
	}

        NVMUL (con->base, con->R, R);
        ASSERT (xdr_vector (&x, (char*)R, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_WRITE);
      }

      bod->fracture = 0;

      free (disp);
    }
  }

  xdr_destroy (&x);
  fclose (f);
#endif
}
int
ocinternalinitialize(void)
{
    int stat = OC_NOERR;

    /* Compute if we are same as network order v-a-v xdr */
#ifdef XDRBYTEORDER
    {
        XDR xdrs;
        union {
            char tmp[sizeof(unsigned int)];
            unsigned int i;
        } u;
        int testint = 1;
        xrmem_create(&xdrs, (caddr_t)&u.tmp,sizeof(u.tmp), XDR_ENCODE);
        xdr_int(&xdrs, &testint);   
        oc_network_order = (udub.i == testint?1:0);
        oc_big_endian = oc_network_order;
    }
#else   
    {
        int testint = 0x00000001;
        char *byte = (char *)&testint;
        oc_big_endian = (byte[0] == 0 ? 1 : 0);
        oc_network_order = oc_big_endian;
    }
#endif /*XDRBYTEORDER*/
    {
        /* It turns out that various machines
           store double in different formats.
           This affects the conversion code ocdata.c
           when reconstructing; probably could deduce this
           from oc_big_endian, but not sure.
        */
        XDR xdrs;
	union {
	    double dv;
	    unsigned int i;
	    unsigned int iv[2];
	    char tmp[sizeof(double)];
	} udub;
        double testdub = 18000;
	/* verify double vs int size */
        if(sizeof(double) != (2 * sizeof(unsigned int)))
            ocpanic("|double| != 2*|int|");
        if(sizeof(udub) != sizeof(double))
            ocpanic("|double| != |udub|");
	memset((void*)&udub,0,sizeof(udub));
        xdrmem_create(&xdrs, (caddr_t)&udub.tmp,sizeof(udub.tmp), XDR_ENCODE);
        xdr_double(&xdrs, &testdub);
	udub.iv[0] = ocntoh(udub.iv[0]);
	udub.iv[1] = ocntoh(udub.iv[1]);
	if (udub.dv == testdub)
		oc_invert_xdr_double = 0;
	else { /* swap and try again */
	    unsigned int temp = udub.iv[0];
	    udub.iv[0] = udub.iv[1];
	    udub.iv[1] = temp;
	    if (udub.dv != testdub)
		ocpanic("cannot unpack xdr_double");
	    oc_invert_xdr_double = 1;
	}
    }
    oc_loginit();

    /* Determine if this version of curl supports
       "file://..." &/or "https://..." urls.
    */
    {
        const char* const* proto; /*weird*/
        curl_version_info_data* curldata;
        curldata = curl_version_info(CURLVERSION_NOW);
        oc_curl_file_supported = 0;
        oc_curl_https_supported = 0;
        for(proto=curldata->protocols;*proto;proto++) {
            if(strcmp("file",*proto)==0) {oc_curl_file_supported=1;break;}
            if(strcmp("https",*proto)==0) {oc_curl_https_supported=1;break;}
        }
        if(ocdebug > 0) {
            oc_log(LOGNOTE,"Curl file:// support = %d",oc_curl_file_supported);
            oc_log(LOGNOTE,"Curl https:// support = %d",oc_curl_file_supported);
        }
    }

    /* compile the .dodsrc, if any */
    {
        char* path = NULL;
        char* homepath = NULL;
	FILE* f = NULL;
        /* locate the configuration files: . first, then $HOME */
        path = (char*)malloc(strlen("./")+strlen(DODSRC)+1);
	if(path == NULL) return OC_ENOMEM;
        strcpy(path,"./");
        strcat(path,DODSRC);
	/* see if file is readable */
	f = fopen(path,"r");
	if(f == NULL) {
	    /* try $HOME */
            homepath = getenv("HOME");
            if (homepath!= NULL) {
	       if(path != NULL) free(path);
	       path = (char*)malloc(strlen(homepath)+1+strlen(DODSRC)+1);
	       if(path == NULL) return OC_ENOMEM;
	       strcpy(path,homepath);
	       strcat(path,"/");
	       strcat(path,DODSRC);
	       f = fopen(path,"r");
            }
        }
        if(f == NULL) {
	    oc_log(LOGWARN,"Cannot find runtime .dodsrc configuration file");
	} else {
       	    fclose(f);
            if(ocdebug > 1)
		fprintf(stderr, "DODS RC file: %s\n", path);
            if(ocdodsrc_read(path) == 0)
	        oc_log(LOGERR, "Error parsing %s\n",path);
        }
        if(path != NULL) {free(path) ; path = NULL;}
    }
    return THROW(stat);
}
Example #19
0
/* read fracture state */
FS* fracture_state_read (BODY *bod)
{
  FS *out = NULL, *item, *instance;
  char path [1024];
  unsigned int id;
  int i, n, dofs;
  double *disp;

#if HDF5
  PBF *f, *g;

  snprintf (path, 1024, "%s/fracture", bod->dom->solfec->outpath);
  g = PBF_Read (path);

  do
  {
    double time;

    PBF_Time (g, &time); /* unused, but could be useful at some point */

    for (f = g; f; f = f->next)
    {
      int numbod;

      PBF_Int2 (f, "numbod", &numbod, 1);

      while (numbod > 0)
      {
	PBF_Uint (f, &id, 1);
	PBF_Int (f, &dofs, 1);
	ERRMEM (disp = malloc (dofs * sizeof (double)));
	PBF_Double (f, disp, dofs);
	PBF_Int (f, &n, 1);
	for (i = 0, instance = NULL; i < n; i ++)
	{
	  ERRMEM (item = MEM_CALLOC (sizeof (FS)));

	  PBF_Double (f, &item->radius, 1);
	  PBF_Double (f, item->point, 3);
	  PBF_Double (f, item->force, 3);

	  if (id == bod->id)
	  {
	    item->inext = instance;
	    instance = item;

	    if (i == (n-1))
	    {
	      item->disp = disp; /* put displacements into first element of instance list */
	      item->next = out;
	      out = item;
	    }
	  }
	  else free (item);
	}

	if (!out || out->disp != disp) free (disp);  /* not used */

	numbod --;
      }
    }
  } while (PBF_Forward (g, 1));

  PBF_Close (g);
#else
  FILE *f;
  XDR x;

  snprintf (path, 1024, "%s/fracture.dat", bod->dom->solfec->outpath);
  f = fopen (path, "r");
  /* TODO: read MPI mode data in case f == NULL but fractureRANK.dat exit */
  if (f)
  {
    xdrstdio_create (&x, f, XDR_DECODE);

    while (! feof (f))
    {
      if (xdr_u_int (&x, &id) == 0) break;
      ASSERT (xdr_int (&x, &dofs), ERR_FILE_READ);
      ERRMEM (disp = malloc (dofs * sizeof (double)));
      ASSERT (xdr_vector (&x, (char*)disp, dofs, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_READ);
      ASSERT (xdr_int (&x, &n), ERR_FILE_READ);
      for (i = 0, instance = NULL; i < n; i ++)
      {
        ERRMEM (item = MEM_CALLOC (sizeof (FS)));

	ASSERT (xdr_double (&x, &item->radius), ERR_FILE_READ);
        ASSERT (xdr_vector (&x, (char*)item->point, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_READ);
        ASSERT (xdr_vector (&x, (char*)item->force, 3, sizeof (double), (xdrproc_t)xdr_double), ERR_FILE_READ);

	if (id == bod->id)
	{
	  item->inext = instance;
	  instance = item;

	  if (i == (n-1))
	  {
	    item->disp = disp; /* put displacements into first element of instance list */
	    item->next = out;
	    out = item;
	  }
	}
	else free (item);
      }

      if (!out || out->disp != disp) free (disp);  /* not used */
    }

    xdr_destroy (&x);
    fclose (f);
  }
#endif

  return out;
}
Example #20
0
int main(int argc, char *argv[])
{
  register int n, k;

  char    rayFileName[14], inputLine[MAX_LINE_SIZE];
  bool_t  result, exit_on_EOF, to_obs, initialize, crosscoupling,
          analyze_output, equilibria_only;
  int     Nspect, Nread, Nrequired, checkPoint, *wave_index = NULL;
  double  muz, *S, *chi, *J;
  FILE   *fp_out, *fp_ray, *fp_stokes;
  XDR     xdrs;
  ActiveSet *as;

  setOptions(argc, argv);
  getCPU(0, TIME_START, NULL);
  SetFPEtraps();

  /* --- Read input data and initialize --             -------------- */

  readInput();
  spectrum.updateJ = FALSE;

  /* --- Read input data for atmosphere --             -------------- */

  getCPU(1, TIME_START, NULL);
  MULTIatmos(&atmos, &geometry);

  /* --- Read direction cosine for ray --              -------------- */

  if ((fp_ray = fopen(RAY_INPUT_FILE, "r")) == NULL) {
    sprintf(messageStr, "Unable to open inputfile %s", RAY_INPUT_FILE);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
  }
  
  getLine(fp_ray, COMMENT_CHAR, inputLine, exit_on_EOF=TRUE);
  Nread = sscanf(inputLine, "%lf", &muz);
  checkNread(Nread, Nrequired=1, argv[0], checkPoint=1);

  if (muz <= 0.0  ||  muz > 1.0) {
    sprintf(messageStr,
	    "Value of muz = %f does not lie in interval <0.0, 1.0]\n", muz);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
  }

  if (input.StokesMode == FIELD_FREE ||
      input.StokesMode == POLARIZATION_FREE) {
    input.StokesMode = FULL_STOKES;
  }
  /* --- redefine geometry for just this one ray --    -------------- */

  atmos.Nrays = geometry.Nrays = 1;
  geometry.muz[0] = muz;
  geometry.mux[0] = sqrt(1.0 - SQ(geometry.muz[0]));
  geometry.muy[0] = 0.0;
  geometry.wmu[0] = 1.0;
  if (atmos.Stokes) Bproject();

  input.startJ = OLD_J;

  readAtomicModels();
  readMolecularModels();
  SortLambda();

  getBoundary(&geometry);

  /* --- Open file with background opacities --        -------------- */

  if (atmos.moving || input.StokesMode) {
    strcpy(input.background_File, "background.ray");
    Background(analyze_output=FALSE, equilibria_only=FALSE);
  } else {
    Background(analyze_output=FALSE, equilibria_only=TRUE);

    if ((atmos.fd_background =
	 open(input.background_File, O_RDONLY, 0)) == -1) {
      sprintf(messageStr, "Unable to open inputfile %s",
	      input.background_File);
      Error(ERROR_LEVEL_2, argv[0], messageStr);
    }
    readBRS();
  }
  convertScales(&atmos, &geometry);

  getProfiles();
  initSolution();
  initScatter();

  getCPU(1, TIME_POLL, "Total initialize");

  /* --- Solve radiative transfer equations --         -------------- */

  solveSpectrum(FALSE, FALSE);

  /* --- Write emergent spectrum to output file --     -------------- */
 
  sprintf(rayFileName, "spectrum_%4.2f", muz);
  if ((fp_out = fopen(rayFileName, "w" )) == NULL) {
    sprintf(messageStr, "Unable to open output file %s", rayFileName);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
  }
  xdrstdio_create(&xdrs, fp_out, XDR_ENCODE);

  result = xdr_double(&xdrs, &muz);
  result = xdr_vector(&xdrs, (char *) spectrum.I[0], spectrum.Nspect,
		      sizeof(double), (xdrproc_t) xdr_double);

  /* --- Read wavelength indices for which chi and S are to be
         written out for the specified direction --    -------------- */

  Nread = fscanf(fp_ray, "%d", &Nspect);
  checkNread(Nread, 1, argv[0], checkPoint=2);

  if (Nspect > 0) {
    wave_index = (int *) malloc(Nspect * sizeof(int));
    Nread = 0;
    while (fscanf(fp_ray, "%d", &wave_index[Nread]) != EOF) Nread++;
    checkNread(Nread, Nspect, argv[0], checkPoint=3);
    fclose(fp_ray);

    chi = (double *) malloc(atmos.Nspace * sizeof(double));
    if (atmos.Stokes)
      S = (double *) malloc(4 * atmos.Nspace * sizeof(double));
    else
      S = (double *) malloc(atmos.Nspace * sizeof(double));
  }
  result = xdr_int(&xdrs, &Nspect);

  /* --- Go through the list of wavelengths --         -------------- */

  if (Nspect > 0  &&  input.limit_memory)
    J = (double *) malloc(atmos.Nspace * sizeof(double));

  for (n = 0;  n < Nspect;  n++) {
    if (wave_index[n] < 0  ||  wave_index[n] >= spectrum.Nspect) {
      sprintf(messageStr, "Illegal value of wave_index[n]: %4d\n"
	      "Value has to be between 0 and %4d\n", 
	      wave_index[n], spectrum.Nspect);
      Error(ERROR_LEVEL_2, argv[0], messageStr);
      continue;
    }
    sprintf(messageStr, "Processing n = %4d, lambda = %9.3f [nm]\n",
	    wave_index[n], spectrum.lambda[wave_index[n]]);
    Error(MESSAGE, NULL, messageStr);

    as = &spectrum.as[wave_index[n]];
    alloc_as(wave_index[n], crosscoupling=FALSE);
    Opacity(wave_index[n], 0, to_obs=TRUE, initialize=TRUE);
    readBackground(wave_index[n], 0, to_obs=TRUE);

    if (input.limit_memory) {
      readJlambda(wave_index[n], J);
    } else
      J = spectrum.J[wave_index[n]];

    /* --- Add the continuum opacity and emissivity -- -------------- */   

    for (k = 0;  k < atmos.Nspace;  k++) {
      chi[k] = as->chi[k] + as->chi_c[k];
      S[k]   = (as->eta[k] + as->eta_c[k] + as->sca_c[k]*J[k]) / chi[k];
    }
    result = xdr_int(&xdrs, &wave_index[n]);
    result = xdr_vector(&xdrs, (char *) chi, atmos.Nspace,
			sizeof(double), (xdrproc_t) xdr_double);
    result = xdr_vector(&xdrs, (char *) S, atmos.Nspace,
			sizeof(double), (xdrproc_t) xdr_double);

    free_as(wave_index[n], crosscoupling=FALSE);
  }

  /* --- If magnetic fields are present --             -------------- */
  
  if (atmos.Stokes || input.backgr_pol) {
    result = xdr_vector(&xdrs, (char *) spectrum.Stokes_Q[0],
			spectrum.Nspect, sizeof(double),
			(xdrproc_t) xdr_double);
    result = xdr_vector(&xdrs, (char *) spectrum.Stokes_U[0],
			spectrum.Nspect, sizeof(double),
			(xdrproc_t) xdr_double);
    result = xdr_vector(&xdrs, (char *) spectrum.Stokes_V[0],
			spectrum.Nspect, sizeof(double),
			(xdrproc_t) xdr_double);
  }

  if (Nspect > 0  &&  input.limit_memory)
    free(J);

  xdr_destroy(&xdrs);
  fclose(fp_out);
  printTotalCPU();
}
Example #21
0
bool FocRttfTradeMsg::xdr_convert(XDR* xdrs, xdr_op x_op)
{
	char* str;

	if (x_op == XDR_ENCODE)
	{
		if (!header.xdr_convert(xdrs, x_op))
		{
			fprintf(stderr, "Bad XDR conversion on CS header\n");
			return FALSE;
		}
	}
	else xdrs->x_op = x_op;

	if (!xdr_char(xdrs, &ins_upd_del_flag))
	{
		fprintf(stderr, "Bad XDR conversion on 'ins_upd_del_flag'\n");
		return FALSE;
	}
  
	if (!xdr_char(xdrs, &put_call))
	{
		fprintf(stderr, "Bad XDR conversion on 'put_call'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &buy_sell))
	{
		fprintf(stderr, "Bad XDR conversion on 'buy_sell'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &origin))
	{
		fprintf(stderr, "Bad XDR conversion on 'origin'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &open_close))
	{
		fprintf(stderr, "Bad XDR conversion on 'open_close'\n");
		return FALSE;
	}
	
	str = (char *) trade_id;
	if (!xdr_string(xdrs, &str, sizeof(trade_id)))
	{
		fprintf(stderr, "Bad XDR conversion on 'trade_id'\n");
		return FALSE;
	}

	str = (char *) user_id;
	if (!xdr_string(xdrs, &str, sizeof(user_id)))
	{
		fprintf(stderr, "Bad XDR conversion on 'user_id'\n");
		return FALSE;
	}

	str = (char *) trading_sym;
	if (!xdr_string(xdrs, &str, sizeof(trading_sym)))
	{
		fprintf(stderr, "Bad XDR conversion on 'trading_sym'\n");
		return FALSE;
	}

	str = (char *) base_sym;
	if (!xdr_string(xdrs, &str, sizeof(base_sym)))
	{
		fprintf(stderr, "Bad XDR conversion on 'base_sym'\n");
		return FALSE;
	}

	str = (char *) parent_account;
	if (!xdr_string(xdrs, &str, sizeof(parent_account)))
	{
		fprintf(stderr, "Bad XDR conversion on 'parent_account'\n");
		return FALSE;
	}

	str = (char *) account;
	if (!xdr_string(xdrs, &str, sizeof(account)))
	{
		fprintf(stderr, "Bad XDR conversion on 'account'\n");
		return FALSE;
	}

	str = (char *) q_account;
	if (!xdr_string(xdrs, &str, sizeof(q_account)))
	{
		fprintf(stderr, "Bad XDR conversion on 'q_account'\n");
		return FALSE;
	}

	str = (char *) security_type;
	if (!xdr_string(xdrs, &str, sizeof(security_type)))
	{
		fprintf(stderr, "Bad XDR conversion on 'security_type'\n");
		return FALSE;
	}

	str = (char *) security_subtype;
	if (!xdr_string(xdrs, &str, sizeof(security_subtype)))
	{
		fprintf(stderr, "Bad XDR conversion on 'security_subtype'\n");
		return FALSE;
	}

	str = (char *) clearing_firm;
	if (!xdr_string(xdrs, &str, sizeof(clearing_firm)))
	{
		fprintf(stderr, "Bad XDR conversion on 'clearing_firm'\n");
		return FALSE;
	}

	str = (char *) cusip;
	if (!xdr_string(xdrs, &str, sizeof(cusip)))
	{
		fprintf(stderr, "Bad XDR conversion on 'cusip'\n");
		return FALSE;
	}

	str = (char *) basket_id;
	if (!xdr_string(xdrs, &str, sizeof(basket_id)))
	{
		fprintf(stderr, "Bad XDR conversion on 'basket_id'\n");
		return FALSE;
	}

	str = (char *) giveup_firm;
	if (!xdr_string(xdrs, &str, sizeof(giveup_firm)))
	{
		fprintf(stderr, "Bad XDR conversion on 'giveup_firm'\n");
		return FALSE;
	}

	str = (char *) contra_firm;
	if (!xdr_string(xdrs, &str, sizeof(contra_firm)))
	{
		fprintf(stderr, "Bad XDR conversion on 'contra_firm'\n");
		return FALSE;
	}

	str = (char *) exec_broker;
	if (!xdr_string(xdrs, &str, sizeof(exec_broker)))
	{
		fprintf(stderr, "Bad XDR conversion on 'exec_broker'\n");
		return FALSE;
	}

	str = (char *) contra_broker;
	if (!xdr_string(xdrs, &str, sizeof(contra_broker)))
	{
		fprintf(stderr, "Bad XDR conversion on 'contra_broker'\n");
		return FALSE;
	}

	str = (char *) mmcs_sub_acct;
	if (!xdr_string(xdrs, &str, sizeof(mmcs_sub_acct)))
	{
		fprintf(stderr, "Bad XDR conversion on 'mmcs_sub_acct'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &exercise_multiplier))
	{
		fprintf(stderr, "Bad XDR conversion on 'exercise_multiplier'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &extended_premium))
	{
		fprintf(stderr, "Bad XDR conversion on 'extended_premium'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &premium))
	{
		fprintf(stderr, "Bad XDR conversion on 'premium'\n");
		return FALSE;
	}
  
	if (!xdr_double(xdrs, &strike))
	{
		fprintf(stderr, "Bad XDR conversion on 'strike'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &price))
	{
		fprintf(stderr, "Bad XDR conversion on 'price'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &quantity))
	{
		fprintf(stderr, "Bad XDR conversion on 'quantity'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &tag))
	{
		fprintf(stderr, "Bad XDR conversion on 'tag'\n");
		return FALSE;
	}

	if (!xdr_foc_datetime(xdrs, &expiration_date))
	{
		fprintf(stderr, "Bad XDR conversion on 'expiration_date'\n");
		return FALSE;
	}

	if (!xdr_foc_datetime(xdrs, &execution_date))
	{
		fprintf(stderr, "Bad XDR conversion on 'execution_date'\n");
		return FALSE;
	}

	if (!xdr_foc_datetime(xdrs, &last_upd_date))
	{
		fprintf(stderr, "Bad XDR conversion on 'last_upd_date'\n");
		return FALSE;
	}

	if (!xdr_foc_datetime(xdrs, &contract_date))
	{
		fprintf(stderr, "Bad XDR conversion on 'contract_date'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &source_system))
	{
		fprintf(stderr, "Bad XDR conversion on 'source_system'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &trade_id_num))
	{
		fprintf(stderr, "Bad XDR conversion on 'trade_id_num'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &trade_group_id))
	{
		fprintf(stderr, "Bad XDR conversion on 'trade_group_id'\n");
		return FALSE;
	}

	if (!xdr_foc_datetime(xdrs, &settlement_date))
	{
		fprintf(stderr, "Bad XDR conversion on 'settlement_date'\n");
		return FALSE;
	}

	str = (char *) entry_firm;
	if (!xdr_string(xdrs, &str, sizeof(entry_firm)))
	{
		fprintf(stderr, "Bad XDR conversion on 'entry_firm'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &matched_flag))
	{
		fprintf(stderr, "Bad XDR conversion on 'matched_flag'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &spread_ind))
	{
		fprintf(stderr, "Bad XDR conversion on 'spread_ind'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &premium_multiplier))
	{
		fprintf(stderr, "Bad XDR conversion on 'premium_multiplier'\n");
		return FALSE;
	}

	str = (char *) source_code;
	if (!xdr_string(xdrs, &str, sizeof(source_code)))
	{
		fprintf(stderr, "Bad XDR conversion on 'source_code'\n");
		return FALSE;
	}

	str = (char *) parent_acct_intrl_id;
	if (!xdr_string(xdrs, &str, sizeof(parent_acct_intrl_id)))
	{
		fprintf(stderr, "Bad XDR conversion on 'parent_acct_intrl_id'\n");
		return FALSE;
	}

	str = (char *) acct_intrl_id;
	if (!xdr_string(xdrs, &str, sizeof(acct_intrl_id)))
	{
		fprintf(stderr, "Bad XDR conversion on 'acct_intrl_id'\n");
		return FALSE;
	}

	str = (char *) q_acct_intrl_id;
	if (!xdr_string(xdrs, &str, sizeof(q_acct_intrl_id)))
	{
		fprintf(stderr, "Bad XDR conversion on 'q_acct_intrl_id'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &cap_interval))
	{
		fprintf(stderr, "Bad XDR conversion on 'cap_interval'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &trade_exchange))
	{
		fprintf(stderr, "Bad XDR conversion on 'trade_exchange'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &settled_unsettled_ind))
	{
		fprintf(stderr, "Bad XDR conversion on 'settled_unsettled_ind'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &stock_origin))
	{
		fprintf(stderr, "Bad XDR conversion on 'stock_origin'\n");
		return FALSE;
	}

	str = (char *) mm_card_number;
	if (!xdr_string(xdrs, &str, sizeof(mm_card_number)))
	{
		fprintf(stderr, "Bad XDR conversion on 'mm_card_number'\n");
		return FALSE;
	}

	if (!xdr_int(xdrs, &basket_tag))
	{
		fprintf(stderr, "Bad XDR conversion on 'basket_tag'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &basket_price))
	{
		fprintf(stderr, "Bad XDR conversion on 'basket_price'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &short_sale))
	{
		fprintf(stderr, "Bad XDR conversion on 'short_sale'\n");
		return FALSE;
	}

	str = (char *) commission_code;
	if (!xdr_string(xdrs, &str, sizeof(commission_code)))
	{
		fprintf(stderr, "Bad XDR conversion on 'commission_code'\n");
		return FALSE;
	}

	if (!xdr_double(xdrs, &commission))
	{
		fprintf(stderr, "Bad XDR conversion on 'commission'\n");
		return FALSE;
	}

	if (!xdr_char(xdrs, &same_day_exer))
	{
		fprintf(stderr, "Bad XDR conversion on 'same_day_exer'\n");
		return FALSE;
	}

	str = (char *) terminal_name;
	if (!xdr_string(xdrs, &str, sizeof(terminal_name)))
	{
		fprintf(stderr, "Bad XDR conversion on 'terminal_name'\n");
		return FALSE;
	}

	return TRUE;
}	
Example #22
0
int
mbbs_xdrpnghdr(Ping *png, XDR *xdrs, int version)
/*
   Internal routine.
   Does XDR encoding and decoding of a BS ping header.
   Returns 1 if successful, 0 otherwise.
*/
{
	unsigned int flags;
	int tvsec, tvusec;
	unsigned long sidebc;
	int mbbs_xdrside(PingSide *, XDR *, int, unsigned long *);

	switch (version) {
	case BS_VERSION_1_0:
	case BS_VERSION_1_1:
	case BS_VERSION_1_2:
	case BS_VERSION_1_3:

		/* output in obsolete format not allowed! */
		if (xdrs->x_op == XDR_ENCODE)
			return 0;

		break;
	case BS_VERSION_1_4:
		break;
	default:
		return 0;
	}

	bs_iobytecnt= 0;

	if (!bs_ionaninit) {
		bs_ionanf= mbbs_nanf();
		bs_ionand= mbbs_nand();
		bs_ionaninit= 1;
	}

	/* always clear the PNG_BTYSSFLAGSABSENT bit when writing
	   since all current format output files are guaranteed to
	   include bathymetry and sidescan flags -- this bit should
	   normally be set only by I/O functions from this library
	   when reading flagless older format version files */	
	if (xdrs->x_op == XDR_ENCODE) {
		flags= png->png_flags;
		flags&= ~PNG_BTYSSFLAGSABSENT;
	}
	if (!xdr_u_int(xdrs, &flags))
		return 0;
	bs_iobytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE)
		png->png_flags= flags;

	/* depending upon the platform, the size of the timeval
	   struct's fields may be 4 or 8 bytes; for backward
	   compatibility with old files that use 4-byte fields,
	   we force these quantities into 4-byte primitives when
	   doing output, returning an error when overflow would result */
	if (xdrs->x_op == XDR_ENCODE) {
		if (((long) png->png_tm.tv_sec < INT32_MIN) ||
		    ((long) png->png_tm.tv_sec > INT32_MAX))
			return 0;

		/* on some platforms where tv_usec is 4 bytes (e.g., mac_x8664
		   under MacOS 10.7) the following may generate a compiler
		   warning about an invalid comparison -- it's probably best to
		   leave this as is rather than code around this unusual size
		   and risk failure in the future if it's ever increased */
		if ((sizeof png->png_tm.tv_usec > 4) &&
		    (((long) png->png_tm.tv_usec < INT32_MIN) ||
		     ((long) png->png_tm.tv_usec > INT32_MAX)))
			return 0;

		tvsec= (int) png->png_tm.tv_sec;
		tvusec= (int) png->png_tm.tv_usec;
	}
	if (!xdr_int(xdrs, &tvsec))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &tvusec))
		return 0;
	bs_iobytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE) {
		png->png_tm.tv_sec= tvsec;
		png->png_tm.tv_usec= tvusec;
	}

	if (!xdr_float(xdrs, &(png->png_period)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_double(xdrs, &(png->png_slon)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_double(xdrs, &(png->png_slat)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_float(xdrs, &(png->png_scourse)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_laybackrng)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_laybackbrg)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_double(xdrs, &(png->png_tlon)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_double(xdrs, &(png->png_tlat)))
		return 0;
	bs_iobytecnt+= 8;
	if (!xdr_float(xdrs, &(png->png_tcourse)))
		return 0;
	bs_iobytecnt+= 4;

	if (!xdr_float(xdrs, &(png->png_compass.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_compass.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_compass.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_compass.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_depth.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_depth.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_depth.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_depth.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_pitch.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_pitch.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_pitch.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_pitch.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_roll.sns_int)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_int(xdrs, &(png->png_roll.sns_nsamps)))
		return 0;
	bs_iobytecnt+= 4;
	if (png->png_roll.sns_nsamps < 0)
		return 0;
	if (!xdr_float(xdrs, &(png->png_roll.sns_repval)))
		return 0;
	bs_iobytecnt+= 4;
	if (xdrs->x_op == XDR_DECODE)
		png->png_snspad= 0;

	if (!xdr_float(xdrs, &(png->png_temp)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_ssincr)))
		return 0;
	bs_iobytecnt+= 4;
	if (version >= BS_VERSION_1_4) {
		if (!xdr_int(xdrs, &(png->png_ssyoffsetmode)))
			return 0;
		bs_iobytecnt+= 4;
	}
	else {
		if (xdrs->x_op == XDR_DECODE)
			png->png_ssyoffsetmode= PNG_SSYOM_UNKNOWN;
	}
	if (!xdr_float(xdrs, &(png->png_alt)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_magcorr)))
		return 0;
	bs_iobytecnt+= 4;
	if (!xdr_float(xdrs, &(png->png_sndvel)))
		return 0;
	bs_iobytecnt+= 4;
	if (version >= BS_VERSION_1_1) {
		if (!xdr_float(xdrs, &(png->png_cond)))
			return 0;
		bs_iobytecnt+= 4;
		if (!xdr_float(xdrs, &(png->png_magx)))
			return 0;
		bs_iobytecnt+= 4;
		if (!xdr_float(xdrs, &(png->png_magy)))
			return 0;
		bs_iobytecnt+= 4;
		if (!xdr_float(xdrs, &(png->png_magz)))
			return 0;
		bs_iobytecnt+= 4;
	}
	else {
		if (xdrs->x_op == XDR_DECODE) {
			png->png_cond= bs_ionanf;
			png->png_magx= bs_ionanf;
			png->png_magy= bs_ionanf;
			png->png_magz= bs_ionanf;
		}
	}

	if (!mbbs_xdrside(&(png->png_sides[ACP_PORT]), xdrs, version, &sidebc))
		return 0;
	bs_iobytecnt+= sidebc;
	if (!mbbs_xdrside(&(png->png_sides[ACP_STBD]), xdrs, version, &sidebc))
		return 0;
	bs_iobytecnt+= sidebc;

	return 1;
}
Example #23
0
int ssioData(SSIO *ssio, SSDATA *data)
{
	assert(ssio != NULL && data != NULL);

#ifdef SSIO_USE_MPI

    /*
     *  Buffer a certain amount before reading or writing it to the file.
     */

    if (SSIO_READ == ssio->fmode)
    {
        /*
         *  FIXME
         *  Need to read a number of particles that is exactly divisible by
         *  the number allocated to each task or else each task will read a
         *  chunk including some which should be read by other tasks, but is
         *  then discarded
         */
        if (ssio->max_buf_particles == ssio->particles_read)
        {
            // reset
            ssio->particles_read = 0;
            ssio->cur_buf_ptr = ssio->file_buf;

            // if the max equal divison has been read, only buffer 1 at a time
            if (ssio->total_read == ssio->total_to_buffer)
            {
                ssio->max_buf_particles = 1;
            }
            /*
            if (ssio->max_buf_particles == 1)
            {
                fprintf(stdout, "Reading 1 extra...\n");
            }
            */
            ssio->total_read += ssio->max_buf_particles;

            READ_FUNC(ssio->mfile,
                      ssio->file_buf,
                      ssio->max_buf_particles*SSDATA_SIZE,
                      MPI_BYTE,
                      MPI_STATUS_IGNORE);
        }

        memcpy(&data->mass,
               ssio->cur_buf_ptr,
               2*sizeof(double));
        memcpy(data->pos,
               ssio->cur_buf_ptr + 2*sizeof(double),
               N_DIM*sizeof(double));
        memcpy(data->vel,
               ssio->cur_buf_ptr + 2*sizeof(double) + N_DIM*sizeof(double),
               N_DIM*sizeof(double));
        memcpy(data->spin,
               ssio->cur_buf_ptr + 2*sizeof(double) + 2*N_DIM*sizeof(double),
               N_DIM*sizeof(double));
        memcpy(&data->color,
               ssio->cur_buf_ptr + 2*sizeof(double) + 3*N_DIM*sizeof(double),
               2*sizeof(ptcl_idx_t));

        ssio->particles_read += 1;
        ssio->cur_buf_ptr += SSDATA_SIZE;
    }
    else //if (SSIO_WRITE == ssio->fmode)
    {
        memcpy(ssio->cur_buf_ptr,
               &data->mass,
               2*sizeof(double));
        memcpy(ssio->cur_buf_ptr + 2*sizeof(double),
               data->pos,
               N_DIM*sizeof(double));
        memcpy(ssio->cur_buf_ptr + 2*sizeof(double) + N_DIM*sizeof(double),
               data->vel,
               N_DIM*sizeof(double));
        memcpy(ssio->cur_buf_ptr + 2*sizeof(double) + 2*N_DIM*sizeof(double),
               data->spin,
               N_DIM*sizeof(double));
        memcpy(ssio->cur_buf_ptr + 2*sizeof(double) + 3*N_DIM*sizeof(double),
               &data->color,
               2*sizeof(ptcl_idx_t));
        
        ssio->particles_written += 1;
        ssio->cur_buf_ptr += SSDATA_SIZE;

        if (ssio->max_buf_particles == ssio->particles_written)
        {
            // reset
            ssio->particles_written = 0;
            ssio->cur_buf_ptr = ssio->file_buf;

            // write block
            WRITE_FUNC(ssio->mfile,
                       ssio->file_buf,
                       ssio->max_buf_particles*SSDATA_SIZE,
                       MPI_BYTE,
                       MPI_STATUS_IGNORE);
        }
    }

#else

	int i;
    
	if (!xdr_double(&ssio->xdrs,&data->mass)) return 1;
	if (!xdr_double(&ssio->xdrs,&data->radius)) return 1;
	for (i=0;i<N_DIM;i++)
		if (!xdr_double(&ssio->xdrs,&data->pos[i])) return 1;
	for (i=0;i<N_DIM;i++)
		if (!xdr_double(&ssio->xdrs,&data->vel[i])) return 1;
	for (i=0;i<N_DIM;i++)
		if (!xdr_double(&ssio->xdrs,&data->spin[i])) return 1;
	if (!xdr_int(&ssio->xdrs,&data->color)) return 1;
	if (!xdr_int(&ssio->xdrs,&data->org_idx)) return 1;

#endif /* SSIO_USE_MPI */

	return 0;
}
Example #24
0
static gmx_bool do_xdr(t_fileio *fio, void *item, int nitem, int eio, 
                   const char *desc, const char *srcfile, int line)
{
    unsigned char ucdum, *ucptr;
    bool_t res = 0;
    float fvec[DIM];
    double dvec[DIM];
    int j, m, *iptr, idum;
    gmx_large_int_t sdum;
    real *ptr;
    unsigned short us;
    double d = 0;
    float f = 0;

    gmx_fio_check_nitem(fio, eio, nitem, srcfile, line);
    switch (eio)
    {
    case eioREAL:
        if (fio->bDouble)
        {
            if (item && !fio->bRead)
                d = *((real *) item);
            res = xdr_double(fio->xdr, &d);
            if (item)
                *((real *) item) = d;
        }
        else
        {
            if (item && !fio->bRead)
                f = *((real *) item);
            res = xdr_float(fio->xdr, &f);
            if (item)
                *((real *) item) = f;
        }
        break;
    case eioFLOAT:
        if (item && !fio->bRead)
            f = *((float *) item);
        res = xdr_float(fio->xdr, &f);
        if (item)
            *((float *) item) = f;
        break;
    case eioDOUBLE:
        if (item && !fio->bRead)
            d = *((double *) item);
        res = xdr_double(fio->xdr, &d);
        if (item)
            *((double *) item) = d;
        break;
    case eioINT:
        if (item && !fio->bRead)
            idum = *(int *) item;
        res = xdr_int(fio->xdr, &idum);
        if (item)
            *(int *) item = idum;
        break;
    case eioGMX_LARGE_INT:
        /* do_xdr will not generate a warning when a 64bit gmx_large_int_t
         * value that is out of 32bit range is read into a 32bit gmx_large_int_t.
         */
        if (item && !fio->bRead)
            sdum = *(gmx_large_int_t *) item;
        res = xdr_gmx_large_int(fio->xdr, &sdum, NULL);
        if (item)
            *(gmx_large_int_t *) item = sdum;
        break;
    case eioUCHAR:
        if (item && !fio->bRead)
            ucdum = *(unsigned char *) item;
        res = xdr_u_char(fio->xdr, &ucdum);
        if (item)
            *(unsigned char *) item = ucdum;
        break;
    case eioNUCHAR:
        ucptr = (unsigned char *) item;
        res = 1;
        for (j = 0; (j < nitem) && res; j++)
        {
            res = xdr_u_char(fio->xdr, &(ucptr[j]));
        }
        break;
    case eioUSHORT:
        if (item && !fio->bRead)
            us = *(unsigned short *) item;
        res = xdr_u_short(fio->xdr, (unsigned short *) &us);
        if (item)
            *(unsigned short *) item = us;
        break;
    case eioRVEC:
        if (fio->bDouble)
        {
            if (item && !fio->bRead)
                for (m = 0; (m < DIM); m++)
                    dvec[m] = ((real *) item)[m];
            res = xdr_vector(fio->xdr, (char *) dvec, DIM,
                             (unsigned int) sizeof(double),
                             (xdrproc_t) xdr_double);
            if (item)
                for (m = 0; (m < DIM); m++)
                    ((real *) item)[m] = dvec[m];
        }
        else
        {
            if (item && !fio->bRead)
                for (m = 0; (m < DIM); m++)
                    fvec[m] = ((real *) item)[m];
            res = xdr_vector(fio->xdr, (char *) fvec, DIM,
                             (unsigned int) sizeof(float),
                             (xdrproc_t) xdr_float);
            if (item)
                for (m = 0; (m < DIM); m++)
                    ((real *) item)[m] = fvec[m];
        }
        break;
    case eioNRVEC:
        ptr = NULL;
        res = 1;
        for (j = 0; (j < nitem) && res; j++)
        {
            if (item)
                ptr = ((rvec *) item)[j];
            res = do_xdr(fio, ptr, 1, eioRVEC, desc, srcfile, line);
        }
        break;
    case eioIVEC:
        iptr = (int *) item;
        res = 1;
        for (m = 0; (m < DIM) && res; m++)
        {
            if (item && !fio->bRead)
                idum = iptr[m];
            res = xdr_int(fio->xdr, &idum);
            if (item)
                iptr[m] = idum;
        }
        break;
    case eioSTRING:
    {
        char *cptr;
        int slen;

        if (item)
        {
            if (!fio->bRead)
                slen = strlen((char *) item) + 1;
            else
                slen = 0;
        }
        else
            slen = 0;

        if (xdr_int(fio->xdr, &slen) <= 0)
            gmx_fatal(FARGS, "wrong string length %d for string %s"
                      " (source %s, line %d)",slen,desc,srcfile,line);
        if (!item && fio->bRead)
            snew(cptr,slen);
        else
            cptr=(char *)item;
        if (cptr)
            res = xdr_string(fio->xdr,&cptr,slen);
        else
            res = 1;
        if (!item && fio->bRead)
            sfree(cptr);
        break;
    }
    default:
        gmx_fio_fe(fio, eio, desc, srcfile, line);
    }
    if ((res == 0) && (fio->bDebug))
        fprintf(stderr,"Error in xdr I/O %s %s to file %s (source %s, line %d)\n",
                eioNames[eio],desc,fio->fn,srcfile,line);

    return (res != 0);
}
Example #25
0
int
mr1_xdrpnghdrv1(Ping *png, XDR *xdrs)
/*
   Internal routine.
   Does XDR decoding of an MR1 version 1 ping header.
   Returns 1 if successful, 0 otherwise.
*/
{
	int mr1_xdrsidev1(PingSide *, XDR *);

	/* output in obsolete version 1 format not allowed! */
	if (xdrs->x_op == XDR_ENCODE)
		return 0;

	if (!nan_init) {
		nan_f= mr1_nanf();
		nan_d= mr1_nand();
		nan_init= 1;
	}

	if (!xdr_long(xdrs, (MR1PR_LONG *) &(png->png_tm.tv_sec)))
		return 0;
	if (!xdr_long(xdrs, (MR1PR_LONG *) &(png->png_tm.tv_usec)))
		return 0;
	png->png_period= nan_f;

	png->png_slon= nan_d;
	png->png_slat= nan_d;
	png->png_scourse= nan_f;
	png->png_laybackrng= nan_f;
	png->png_laybackbrg= nan_f;

	if (!xdr_double(xdrs, &(png->png_tlon)))
		return 0;
	if (!xdr_double(xdrs, &(png->png_tlat)))
		return 0;
	if (!xdr_float(xdrs, &(png->png_tcourse)))
		return 0;

	png->png_compass.sns_int= nan_f;
	png->png_compass.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_compass.sns_repval)))
		return 0;

	png->png_depth.sns_int= nan_f;
	png->png_depth.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_depth.sns_repval)))
		return 0;

	if (!xdr_float(xdrs, &(png->png_alt)))
		return 0;

	png->png_pitch.sns_int= nan_f;
	png->png_pitch.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_pitch.sns_repval)))
		return 0;

	png->png_roll.sns_int= nan_f;
	png->png_roll.sns_nsamps= 0;
	if (!xdr_float(xdrs, &(png->png_roll.sns_repval)))
		return 0;

	png->png_snspad= 0;

	if (!xdr_float(xdrs, &(png->png_temp)))
		return 0;
	if (!xdr_float(xdrs, &(png->png_atssincr)))
		return 0;

	png->png_magcorr= nan_f;
	png->png_sndvel= nan_f;

	if (!mr1_xdrsidev1(&(png->png_sides[ACP_PORT]), xdrs))
		return 0;
	png->png_sides[ACP_PORT].ps_bdrange= png->png_alt;

	if (!mr1_xdrsidev1(&(png->png_sides[ACP_STBD]), xdrs))
		return 0;
	png->png_sides[ACP_STBD].ps_bdrange= png->png_alt;

	return 1;
}
Example #26
0
bool_t P_xdr_double(XDR *x, double *d) { return (xdr_double(x, d));}
Example #27
0
void
F77_FUNC(xdrfdouble,XDRFDOUBLE)(int *xdrid, double *dp, int *ret)
{
	*ret = xdr_double(xdridptr[*xdrid], dp);
	cnt += sizeof(double);
}
bool_t xdr_datas(XDR * pt_xdr, struct datas *pt)
{
	return (xdr_double(pt_xdr, &(pt->a)) &&
		xdr_double(pt_xdr, &(pt->b)) && xdr_double(pt_xdr, &(pt->c)));
}
Example #29
0
int main(int argc, char *argv[])
{
  register int k, l, n, la;

  int     Nspace, result, NmaxIter, Ngdelay, Ngorder, Ngperiod, btype[3],
          inputs[N_INPUTS], nwrite, Nx, Nz;
  double  iterLimit, *lambda, Adamp;

  stats.printCPU = TRUE;
  commandline.quiet = FALSE;
  commandline.logfile = stderr;
  input.Eddington = FALSE;

  getCPU(0, TIME_START, NULL);
  SetFPEtraps();

  fpin  = fopen("2dinput.dat", "r");
  xdrstdio_create(&xdrs, fpin, XDR_DECODE);

  result = xdr_vector(&xdrs, (char *) inputs, N_INPUTS,
		      sizeof(int), (xdrproc_t) xdr_int);

  atmos.angleSet.set = (enum angleset) inputs[0];
  if (atmos.angleSet.set == SET_GL) {
     result = xdr_int(&xdrs, &atmos.angleSet.Ninclination);
     result = xdr_int(&xdrs, &atmos.angleSet.Nazimuth);
  }
  result = xdr_double(&xdrs, &iterLimit);
  result = xdr_double(&xdrs, &Adamp);

  Nx = geometry.Nx = inputs[1];
  Nz = geometry.Nz = inputs[2];
  NmaxIter = inputs[3];
  Ngdelay  = inputs[4];  Ngorder = inputs[5];  Ngperiod = inputs[6];
  Nlambda  = inputs[7];
  Nspace   = atmos.Nspace = geometry.Nx * geometry.Nz;

  result = xdr_vector(&xdrs, (char *) btype, 3,
		      sizeof(int), (xdrproc_t) xdr_int);
  geometry.hboundary = (enum boundary) btype[0];
  for (n = 0;  n < 2;  n++)
    geometry.bvalue[n] = (enum boundval) btype[1+n];

  /* --- Check the validity of boundary conditions and values -- ---- */ 

  switch (geometry.hboundary) {
  case FIXED:     break;
  case PERIODIC:  break;
  default:
    sprintf(messageStr, "Invalid horizontal boundary condition: %d",
	    geometry.hboundary);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
    break;
  }

  switch (geometry.bvalue[TOP]) {
  case IRRADIATED:   break;
  case ZERO:         break;
  case THERMALIZED:  break;
  default:
    sprintf(messageStr, "Invalid boundary value at TOP: %d\n",
	    geometry.bvalue[TOP]);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
    break;
  }
  switch (geometry.bvalue[BOTTOM]) {
  case IRRADIATED:   break;
  case ZERO:         break;
  case THERMALIZED:  break;
  default:
    sprintf(messageStr, "Invalid boundary value at BOTTOM: %d",
	    geometry.bvalue[BOTTOM]);
    Error(ERROR_LEVEL_2, argv[0], messageStr);
    break;
  }

  /* --- Get increments in x, store and check for monotonicity -- --- */

  geometry.dx = (double *) malloc(Nx * sizeof(double));
  result = xdr_vector(&xdrs, (char *) geometry.dx, Nx,
		       sizeof(double), (xdrproc_t) xdr_double);
  for (l = 0;  l < ((geometry.hboundary == PERIODIC) ? Nx : Nx-1);  l++) {
    geometry.dx[l] *= KM_TO_M;
    if (geometry.dx[l] <= 0.0) {
      sprintf(messageStr, "At l = %d:\n x does not increase strictly "
              "monotonically towards the right", l);
      Error(ERROR_LEVEL_2, argv[0], messageStr);
    } 
  }
  geometry.x = (double *) malloc(Nx * sizeof(double));
  geometry.x[0] = 0.0;
  for (l = 0;  l < Nx-1;  l++)
    geometry.x[l+1] = geometry.x[l] + geometry.dx[l];

  /* --- Get vertical grid --                          -------------- */

  geometry.z = (double *) malloc(Nz * sizeof(double));
  result = xdr_vector(&xdrs, (char *) geometry.z, Nz,
		      sizeof(double), (xdrproc_t) xdr_double);
  for (k = 0;  k < Nz;  k++) geometry.z[k] *= KM_TO_M;

  geometry.dz = (double *) malloc(Nz * sizeof(double));
  for (k = 0;  k < Nz-1;  k++) {
    geometry.dz[k] = geometry.z[k] - geometry.z[k+1];
    if (geometry.dz[k] <= 0.0) {
      sprintf(messageStr, "At k = %d:\n z does not decrease strictly "
              "monotonically towards the bottom", k);
      Error(ERROR_LEVEL_2, argv[0], messageStr);
    }
  }
  geometry.dz[Nz-1] = 0.0;


  chi = (double *) malloc(Nspace * sizeof(double));
  S   = (double *) malloc(Nspace * sizeof(double));
  Bp  = (double *) malloc(Nspace * sizeof(double));
  epsilon = (double *) malloc(Nspace * sizeof(double));

  result = xdr_vector(&xdrs, (char *) chi, Nspace,
		       sizeof(double), (xdrproc_t) xdr_double);
  result = xdr_vector(&xdrs, (char *) Bp, Nspace,
		       sizeof(double), (xdrproc_t) xdr_double);
  result = xdr_vector(&xdrs, (char *) epsilon, Nspace,
		       sizeof(double), (xdrproc_t) xdr_double);

  getBoundary(&atmos, &geometry);
  getAngleQuadr(&geometry);
  atmos.Nrays = geometry.Nrays;
  atmos.wmu   = geometry.wmu;
  fillMesh(&geometry);

  lambda = (double *) malloc(Nlambda * sizeof(double));
  phi    = (double *) malloc(Nlambda * sizeof(double));
  wlamb  = (double *) malloc(Nlambda * sizeof(double));

  result = xdr_vector(&xdrs, (char *) lambda, Nlambda,
		      sizeof(double), (xdrproc_t) xdr_double);
  wlamb[0] = (lambda[1] - lambda[0]);
  for (la = 1;  la < Nlambda-1;  la++)
    wlamb[la] = (lambda[la+1] - lambda[la-1]);
  wlamb[Nlambda-1] = (lambda[Nlambda-1] - lambda[Nlambda-2]);

  wphi = 0.0;
  for (la = 0;  la < Nlambda;  la++) {
    phi[la] = Voigt(Adamp, lambda[la], NULL, RYBICKI)/SQRTPI;
    wphi   += wlamb[la]*phi[la];
  }
  wphi = 1.0/wphi;

  xdr_destroy(&xdrs);
  fclose(fpin);

  for (k = 0;  k < Nspace;  k++)  S[k] = Bp[k];
  Ng_S = NgInit(Nspace, Ngdelay, Ngorder, Ngperiod, S);

  Iterate(NmaxIter, iterLimit);

  nwrite = fwrite(S, sizeof(double), Nspace, stdout);
  printTotalCPU();
}
Example #30
0
ULONG CAN_encode_decode(burp_rel* relation, lstring* buffer, UCHAR* data, bool_t direction)
{
/**************************************
 *
 *	C A N _ e n c o d e _ d e c o d e
 *
 **************************************
 *
 * Functional description
 *	encode and decode canonical backup.
 *
 **************************************/
	const burp_fld* field;
	SSHORT n;

	XDR xdr;
	XDR* xdrs = &xdr;

	xdr_init(xdrs, buffer, direction ? XDR_ENCODE : XDR_DECODE);

	RCRD_OFFSET offset = 0;
	for (field = relation->rel_fields; field; field = field->fld_next)
	{
		if (field->fld_flags & FLD_computed)
			continue;
		UCHAR* p = data + field->fld_offset;
		const bool array_fld = ((field->fld_flags & FLD_array) != 0);
		const FLD_LENGTH length = array_fld ? 8 : field->fld_length;
		if (field->fld_offset >= offset)
			offset = field->fld_offset + length;
		if (field->fld_type == blr_varying && !array_fld)
			offset += sizeof(SSHORT);
		SSHORT dtype;
		if (field->fld_type == blr_blob || array_fld)
			dtype = dtype_blob;
		else
			dtype = (SSHORT) gds_cvt_blr_dtype[field->fld_type];
		switch (dtype)
		{
		case dtype_text:
			if (!xdr_opaque(xdrs, reinterpret_cast<char*>(p), length))
			{
				return FALSE;
			}
			break;

		case dtype_varying:
			{
				vary* pVary = reinterpret_cast<vary*>(p);
				if (!xdr_short(xdrs, reinterpret_cast<SSHORT*>(&pVary->vary_length)))
				{
					return FALSE;
				}
				if (!xdr_opaque(xdrs, reinterpret_cast<SCHAR*>(pVary->vary_string),
								MIN(pVary->vary_length, length)))
				{
				  return FALSE;
				}
			}
			break;

		case dtype_cstring:
			if (xdrs->x_op == XDR_ENCODE)
				n = static_cast<SSHORT>(MIN(strlen(reinterpret_cast<const char*>(p)), length));
			if (!xdr_short(xdrs, &n))
				return FALSE;
			if (!xdr_opaque(xdrs, reinterpret_cast<SCHAR*>(p), n))
				  return FALSE;
			if (xdrs->x_op == XDR_DECODE)
				p[n] = 0;
			break;

		case dtype_short:
			if (!xdr_short(xdrs, (SSHORT *) p))
				return FALSE;
			break;

		case dtype_long:
		case dtype_sql_time:
		case dtype_sql_date:
			if (!xdr_long(xdrs, (SLONG *) p))
				return FALSE;
			break;

		case dtype_real:
			if (!xdr_float(xdrs, (float *) p))
				return FALSE;
			break;

		case dtype_double:
			if (!xdr_double(xdrs, (double *) p))
				return FALSE;
			break;

		case dtype_timestamp:
			if (!xdr_long(xdrs, &((SLONG*) p)[0]))
				return FALSE;
			if (!xdr_long(xdrs, &((SLONG*) p)[1]))
				return FALSE;
			break;

		case dtype_quad:
		case dtype_blob:
			if (!xdr_quad(xdrs, (SQUAD*) p))
				return FALSE;
			break;

		case dtype_int64:
			if (!xdr_hyper(xdrs, (SINT64*) p))
				return FALSE;
			break;

		case dtype_boolean:
			if (!xdr_opaque(xdrs, (SCHAR*) p, length))
				return FALSE;
			break;

		default:
			fb_assert(FALSE);
			return FALSE;
		}
	}

	// Next, get null flags

	for (field = relation->rel_fields; field; field = field->fld_next)
	{
		if (field->fld_flags & FLD_computed)
			continue;
		offset = FB_ALIGN(offset, sizeof(SSHORT));
		UCHAR* p = data + offset;
		if (!xdr_short(xdrs, (SSHORT*) p))
			return FALSE;
		offset += sizeof(SSHORT);
	}
	return (xdrs->x_private - xdrs->x_base);
}