예제 #1
0
/*@T
 *
 * After the header is a sequence of frames, each of which contains
 * $n_{\mathrm{particles}}$ pairs of 32-bit int floating point numbers
 * and an optional flag which is used to determine the color.
 * There are no markers, end tags, etc; just the raw data.
 * The [[write_frame_data]] routine writes $n$ point records;
 * note that writing a single frame of output may involve multiple
 * calls to [[write_frame_data]].
 *@c*/
void write_frame_data(FILE* fp, int n, particle_t* particles, int* c)
{
    for (int i = 0; i < n; ++i) {
        uint32_t xi = htonf(&particles[i].x[0]);
        uint32_t yi = htonf(&particles[i].x[1]);
        fwrite(&xi, sizeof(xi), 1, fp);
        fwrite(&yi, sizeof(yi), 1, fp);
        uint32_t ci0 = c ? *c++ : 0;
        uint32_t ci = htonl(ci0);
        fwrite(&ci, sizeof(ci), 1, fp);
    }
}
예제 #2
0
static void
fillCineonChannelInfo(CineonFile* cineon, CineonChannelInformation* chan, int des) {

	chan->designator1 = 0;
	chan->designator2 = des;
	chan->bits_per_pixel = 10;
	chan->pixels_per_line = htonl(cineon->width);
	chan->lines_per_image = htonl(cineon->height);
	chan->ref_low_data = htonl(0);
	chan->ref_low_quantity = htonf(0.0);
	chan->ref_high_data = htonl(1023);
	chan->ref_high_quantity = htonf(2.046);
}
예제 #3
0
static int sendRequestPacketForceRGB(uint32_t gem_num, float r, float g, float b) {

  PACKET_PREP(MoveServerRequestPacketForceRGB, MOVE_CLIENT_REQUEST_FORCE_RGB);

  // Serialize data
  packet_data.gem_num = htonl(gem_num);
  packet_data.r = htonf(r);
  packet_data.g = htonf(g);
  packet_data.b = htonf(b);

  // Send
  return sendData((uint8_t *) &packet_data, packet_size);

}
예제 #4
0
static void
fillCineonImageInfo(CineonFile* cineon, CineonImageInformation* imageInfo) {

	imageInfo->orientation = 0;
	imageInfo->channels_per_image = cineon->depth;

	if (cineon->depth == 1) {
		fillCineonChannelInfo(cineon, &imageInfo->channel[0], 0);

	} else if (cineon->depth == 3) {
		fillCineonChannelInfo(cineon, &imageInfo->channel[0], 1);
		fillCineonChannelInfo(cineon, &imageInfo->channel[1], 2);
		fillCineonChannelInfo(cineon, &imageInfo->channel[2], 3);
	}

	imageInfo->white_point_x = htonf(undefined());
	imageInfo->white_point_y = htonf(undefined());
	imageInfo->red_primary_x = htonf(undefined());
	imageInfo->red_primary_y = htonf(undefined());
	imageInfo->green_primary_x = htonf(undefined());
	imageInfo->green_primary_y = htonf(undefined());
	imageInfo->blue_primary_x = htonf(undefined());
	imageInfo->blue_primary_y = htonf(undefined());

	strcpy(imageInfo->label, "David's Cineon writer.");

}
예제 #5
0
 // float32
 void append(float v) {
   is_cached_ = false;
   types_.push_back('f');
   int32_t a = htonf(v);
   ByteArray b(4);
   memcpy(&b[0], (char*)&a, 4);
   data_.insert(data_.end(), b.begin(), b.end()); }
예제 #6
0
파일: Buffer.c 프로젝트: alyawn/craftd-huh
void
SV_BufferAddFloat (CDBuffer* self, SVFloat data)
{
    data = htonf(data);

    evbuffer_add(self->raw, &data, SVFloatSize);
}
        void ProtoSerializerVisitor::write(const uint32_t &id, const float &v) {
            uint32_t key = getKey(id, ProtoSerializerVisitor::FOUR_BYTES);
            m_size += encodeVarInt(m_buffer, key);

            float _v = htonf(v);
            m_buffer.write(reinterpret_cast<const char*>(&_v), sizeof(const float));
            m_size += sizeof(const float);
        }
        void ProtoSerializerVisitor::write(const uint32_t &fourByteID, const uint8_t &oneByteID, const string &/*longName*/, const string &/*shortName*/, const float &v) {
            uint32_t key = getKey( (oneByteID > 0 ? oneByteID : fourByteID) , ProtoSerializerVisitor::FOUR_BYTES);
            m_size += encodeVarInt(m_buffer, key);

            float _v = htonf(v);
            m_buffer.write(reinterpret_cast<const char*>(&_v), sizeof(const float));
            m_size += sizeof(const float);
        }
예제 #9
0
파일: isis_te.c 프로젝트: KaloNK/quagga
static void
set_circuitparams_max_rsv_bw (struct mpls_te_circuit *mtc, float fp)
{
  SUBTLV_TYPE(mtc->max_rsv_bw) = TE_SUBTLV_MAX_RSV_BW;
  SUBTLV_LEN(mtc->max_rsv_bw)  = SUBTLV_DEF_SIZE;
  mtc->max_rsv_bw.value = htonf(fp);
  return;
}
예제 #10
0
/*@T
 *
 * The header data consists of a count of the number of balls (a 32-bit
 * integer) and a scale parameter (a 32-bit floating point number).
 * The scale parameter tells the viewer how big the view box is supposed
 * to be in the coordinate system of the simulation; right now, it is
 * always set to be 1 (i.e. the view box is $[0,1] \times [0,1]$)
 *@c*/
void write_header(FILE* fp, int n)
{
    float scale = 1.0;
    uint32_t nn = htonl((uint32_t) n);
    uint32_t nscale = htonf(&scale);
    fprintf(fp, "%s\n", VERSION_TAG);
    fwrite(&nn,     sizeof(nn),     1, fp);
    fwrite(&nscale, sizeof(nscale), 1, fp);
}
예제 #11
0
파일: Helpers.cpp 프로젝트: Aero348/dune
    static void
    ntohf(float& x)
    {
#if defined(DUNE_CPU_LITTLE_ENDIAN)
      htonf(x);
#else
      (void)x;
#endif
    }
예제 #12
0
파일: isis_te.c 프로젝트: KaloNK/quagga
static void
set_circuitparams_use_bw (struct mpls_te_circuit *mtc, float fp)
{
  /* Note that TLV-length field is the size of array. */
  SUBTLV_TYPE(mtc->use_bw) = TE_SUBTLV_USE_BW;
  SUBTLV_LEN(mtc->use_bw)  = SUBTLV_DEF_SIZE;
  mtc->use_bw.value = htonf(fp);
  return;
}
예제 #13
0
파일: isis_te.c 프로젝트: KaloNK/quagga
static void
set_circuitparams_unrsv_bw (struct mpls_te_circuit *mtc, int priority, float fp)
{
  /* Note that TLV-length field is the size of array. */
  SUBTLV_TYPE(mtc->unrsv_bw) = TE_SUBTLV_UNRSV_BW;
  SUBTLV_LEN(mtc->unrsv_bw)  = TE_SUBTLV_UNRSV_SIZE;
  mtc->unrsv_bw.value[priority] = htonf(fp);
  return;
}
예제 #14
0
파일: htonf.c 프로젝트: xiaoy/Exercise
int main() {
    float f= 3.1415926;
    printf("the before float is:%f\n", f);
    uint32_t i = htonf(f);
    printf("the int is:%d\n", i);
    f = ntohf(i);
    printf("hte float is:%f\n", f);
    return 0;
}
예제 #15
0
static void
fillCineonOriginationInfo(CineonFile* cineon,
	CineonOriginationInformation* originInfo, CineonFileInformation* fileInfo) {
	
	(void)cineon; /* unused */

	originInfo->x_offset = htonl(0);
	originInfo->y_offset = htonl(0);
	strcpy(originInfo->file_name, fileInfo->file_name);
	strcpy(originInfo->create_date, fileInfo->create_date);
	strcpy(originInfo->create_time, fileInfo->create_time);
	strncpy(originInfo->input_device, "David's Cineon writer", 64);
	strncpy(originInfo->model_number, "Software", 32);
	strncpy(originInfo->serial_number, "001", 32);
	originInfo->x_input_samples_per_mm = htonf(undefined());
	originInfo->y_input_samples_per_mm =	htonf(undefined());
	/* this should probably be undefined, too */
	originInfo->input_device_gamma = htonf(1.0);
}
예제 #16
0
파일: dpxlib.c 프로젝트: jinjoh/NOOR
static void
fillDpxChannelInfo(DpxFile* dpx, DpxChannelInformation* chan, int des) {

	chan->signage = 0;
	chan->ref_low_data = htonl(0);
	chan->ref_low_quantity = htonf(0.0);
	chan->ref_high_data = htonl(1023);
	chan->ref_high_quantity = htonf(2.046);
	chan->designator1 = des;
	chan->transfer_characteristics = 0;
	chan->colourimetry = 0;
	chan->bits_per_pixel = 10;
	chan->packing = htons(1);
	chan->encoding = 0;
	chan->data_offset = 0;
	chan->line_padding = htonl(0);
	chan->channel_padding = htonl(0);
	chan->description[0] = 0;
}
예제 #17
0
static int sendRequestPacketPrepareCamera(uint32_t max_exposure, float image_quality) {

  PACKET_PREP(MoveServerRequestPacketPrepareCamera, MOVE_CLIENT_REQUEST_PREPARE_CAMERA);

  // Serialize data
  packet_data.max_exposure = htonl(max_exposure);
  packet_data.image_quality = htonf(image_quality);

  // Send
  return sendData((uint8_t *) &packet_data, packet_size);

}
예제 #18
0
    void readFloatAttributes(Model *model, const std::string &attrName, size_t numParticles, 
                             const std::string &fn, size_t begin, size_t end)
    {
      FILE *file = fopen(fn.c_str(),"rb");
      if (!file) {
        throw std::runtime_error("could not open data file "+fn);
      }
      assert(file);

      fseek(file,begin,SEEK_SET);
      size_t len = end-begin;

      if (len != numParticles*sizeof(float)) {
        PING;
        PRINT(len);
        PRINT(numParticles);
        PRINT(len/numParticles);
      }
      // PRINT(len);
      
      for (int i=0;i<numParticles;i++) {
        float attrib;
        int rc = fread(&attrib,sizeof(attrib),1,file);
        if (rc != 1) {
          fclose(file);
          throw std::runtime_error("read partial data "+fn);
        }
#if 1
        if (big_endian) {
          attrib = htonf(attrib);
        }
#endif

        model->addAttribute(attrName,attrib);
      }
      
      std::stringstream attrs;
      for (std::map<std::string,std::vector<float> *>::const_iterator it=model->attribute.begin();
           it != model->attribute.end();it++) {
        attrs << "," << it->first;
      }
        

      std::cout << "\r#osp:uintah: " << numParticles << " pt.s (tot:" << float((numDumpedParticles+model->atom.size())/1e6) << "M" << attrs.str() << ")";

      fclose(file);
    }
예제 #19
0
int main(int argc, char **argv)
{
	SEGYBinaryFileHeader reel;
	SEGYTraceHeader *header;
	char *dbin;
	char *outfile;
	FILE *fp;
	Pf *pf;
	Arr *channels;  /* channel order list */
	Arr *table_list;  /* array of valid tables */
	int nchan;
	char *stest;

	float **traces;
	char text_file_header[SEGY_TEXT_HEADER_SIZE];
	Dbptr db, trdb, dbj;
	Dbptr trdbss;
	int nsamp0;
	double time0, endtime0, samprate0;
	long int nsamp;
	double samprate;
	int i,j;
	char stime[30],etime[30];
	char s[128];
	double tlength;
	double phi, theta;
	char *newchan_standard[3]={"X1","X2","X3"};
	char *trsubset="chan=~/X./";
	char *newchan[3]={"R","T","Z"};
	Tbl *sortkeys=newtbl(0);
	char sta[10],chan[10];
	double lat, lon, elev, dnorth, deast, edepth;
	char segtype;
	char refsta[10];
	int total_traces=0;
	char *time_str;
	long int evid,shotid=1;
	int rotate=0;
	long int ntraces;
        int ichan;
	int map_to_cdp;  /* logical switch to output data like cdp stacked data */
	char *fmt="%Y %j %H %M %S %s";
	char *pfname;
	int Verbose=0;
	/* New features added 2009 */
	/* this is a boolean.  If true (nonzero) it is assumed stdin will
	contain four numbers:  time,lat, lon, elev.  If false, only the
	time field is read and remainder of any input on each line is dropped.*/
	int input_source_coordinates;
	/* scale factor for source coordinates.  Needed because segy uses
	an int to store source coordinates.  Sensible choices are
	3600 for arc seconds and 10000 for a pseudodecimal. Note this
	parameter is ignored unless input_source_coordinates is true.*/
	int coordScale;
	/* If true use passcal 32 bit extension num_samps as record length.
	SEGY standard uses a 16 bit entry that easily overflows with large
	shots at long offset.  In this ase assume the 16 bit quantity is
	meaningless. */
	int use_32bit_nsamp;
	/* This is switched on by argument switch.  When set to a nonzero
	(default) the reel headers are written.  When 0 `
	the reel headers will not be written -- used by seismic unix
	and passcal*/
	int write_reel_headers=1;

	/* SEG-Y version to output. Default is original 1975 spec (rev 0) */
	int16_t segy_format = SEGY_FORMAT_REV_0;

	/* dbsubset query string */
	char *substr=NULL;

	/* text_header_description is a buffer holding a user-supplied description
	 * to be placed in the 3200-byte text header block. It is controlled by
	 * the parameter file value text_header_description or by the -d command
	 * line option, with the latter taking precedence */
	char* text_header_description=NULL;

	if(argc < 3) usage();
	dbin = argv[1];
	outfile = argv[2];
	pfname = NULL;
	for(i=3;i<argc;++i)
	{
		if(!strcmp(argv[i],"-pf"))
		{
			++i;
			pfname = argv[i];
		}
		else if(!strcmp(argv[i],"-SU"))
		{
			write_reel_headers=0;
		}
		else if(!strcmp(argv[i],"-v"))
		{
			Verbose=1;
		}
		else if(!strcmp(argv[i],"-d"))
		{
			++i;
			text_header_description = strdup(argv[i]);
		}
		else if(!strcmp(argv[i],"-ss"))
		{
			++i;
			substr=argv[i];
		}
		else if(!strcmp(argv[i],"-V"))
		{
			++i;
			if     (!strcmp(argv[i],"0")) {segy_format = SEGY_FORMAT_REV_0;}
			else if(!strcmp(argv[i],"1")) {segy_format = SEGY_FORMAT_REV_1_0;}
			else if(!strcmp(argv[i],"SU"))
			{
				segy_format = SEGY_FORMAT_SU;
				write_reel_headers=0;
			}
			else
			{
				elog_complain(0, "SEG-Y Version must be either 1 or 0");
				usage();
			}
		}
		else
		{
			usage();
		}
	}
	/* Command-line parameter sanity checking */
	if (write_reel_headers==0 && segy_format != SEGY_FORMAT_SU){
		complain(0, "The SU option cannot be used with the -V option");
		usage();
	}
	if(pfname == NULL) pfname = strdup("db2segy");

	elog_init(argc, argv);

	if(pfread(pfname,&pf)) {
		elog_die(0,"pfread error for pf file %s.pf\n",argv[0]);
	}

	/* Read the text_header_description if we weren't passed the -d option */
	if (!text_header_description) {
		text_header_description=pfget_string(pf, "text_header_description");
	}

	/* rotation parameters */
	rotate=pfget_boolean(pf,"rotate");
	if(rotate)
	{
		phi = pfget_double(pf,"phi");
		theta = pfget_double(pf,"theta");
	}
	/* This function creates the channel order list keyed by
	station channel names */
	channels = build_stachan_list(pf,&nchan,Verbose);

	map_to_cdp = pfget_boolean(pf,"map_to_cdp");
	if(map_to_cdp && Verbose)
		elog_notify(0,"Casting data as CDP stacked section\n");
	if(dbopen(dbin,"r",&db) == dbINVALID)
	{
		elog_complain(1,"Cannot open db %s\n", dbin);
		usage();
	}
	/* We grab the sample rate and trace length (in seconds) and
	use this to define global sample rates for the data.
	SEG-Y REV0 REQUIRES fixed length records and sample rates, so
	irregular sample rates will cause this program to die.
	One could add a decimate/interpolate function, but this
	is not currently implemented */
	samprate0 = pfget_double(pf,"sample_rate");
	tlength = pfget_double(pf,"trace_length");
	nsamp0 = (int)(tlength*samprate0);
	use_32bit_nsamp=pfget_boolean(pf,"use_32bit_nsamp");
	if (ntohs(segy_format) >= 0x0100 && use_32bit_nsamp) {
		elog_complain(0,"The 32-bit extension field is incompatible with SEG-Y REV 1. Ignoring 'use_32bit_nsamp' from the parameter file");
		use_32bit_nsamp=0;
	}

	/* nsamp in segy is a 16 bit field.  Handling depends on
	setting of use_32bit_nsamp boolean */
	if(nsamp0 > SEGY_MAX_NSAMP)
	{
		if(use_32bit_nsamp)
		{
			elog_notify(0,"Warning:  segy uses a 16 bit entity to store number of samples\nThat field is garbage. Using the 32 bit extension field.");
		}
		else
		{
		elog_complain(0,
		  "Warning:  segy uses a 16 bit entity to store number of samples. Requested %d samples per trace.  Trucated to %d", nsamp0, SEGY_MAX_NSAMP);
		nsamp0 = SEGY_MAX_NSAMP;
		}
	}

	/* boolean.  When nonzero set coordinates as geographic arc seconds values */
	int use_geo_coordinates=pfget_boolean(pf,"use_geo_coordinates");

	/* boolean. When nonzero, output decimal degrees instead of arcseconds if
	 * the requested output format supports it (rev1 only) */
	int prefer_decimal_degrees=pfget_boolean(pf, "prefer_decimal_degrees");

	/* We now have enough information to decide the coordUnits for all traces */
	int coordUnits = 0;
	if (!use_geo_coordinates) {
		coordUnits=SEGY_TRACE_COORDUNITS_LENGTH;
	} else if (ntohs(segy_format) >= 0x0100 && prefer_decimal_degrees) {
		coordUnits=SEGY_TRACE_COORDUNITS_DECIMAL_DEGREES;
	} else {
		coordUnits=SEGY_TRACE_COORDUNITS_ARCSECONDS;
	}
	/* We should have set our coordinate units now */
	assert(coordUnits!=0);

	input_source_coordinates=pfget_boolean(pf,"input_source_coordinates");
	if(input_source_coordinates)
	{
		coordScale=pfget_int(pf,"coordinate_scale_factor");
	}
	else if (coordUnits==SEGY_TRACE_COORDUNITS_DECIMAL_DEGREES)
	{
		/* Use a sane scalar for decimal degrees. 10000 gives four decimal
		 * places of accuracy, which matches the CSS3.0 spec for lat and lon */
		coordScale=10000;
	}
	else
	{
		coordScale=1;
	}

	/* Print a diagnostic message if the user gave a sub-optimal value for the
	 * coordScale */
	if (coordUnits == SEGY_TRACE_COORDUNITS_DECIMAL_DEGREES &&
			coordScale < 10000)
	{
		elog_alert(0,
				"The supplied parameter 'coordinate_scale_factor' value of %d is less than 10000, and will cause loss of precision for decimal degree coordinates.",
				coordScale);
	}
    else if (coordUnits == SEGY_TRACE_COORDUNITS_ARCSECONDS)
    {
        if (coordScale > 1000) {
            elog_alert(0,
                    "The supplied parameter 'coordinate_scale_factor' value of %d is greater than 1000, and will cause loss of precision for arcsecond coordinates.",
                    coordScale);
        }
    }

	/* trace_gain_type: signed int */
	int16_t trace_gain_type = pfget_int(pf,"trace_gain_type");
	if (trace_gain_type < 0)
	{
		die(0, "The trace_gain_type must be zero or greater");
	}
	else
	{
		trace_gain_type=htons(trace_gain_type);
	}


	/* check list of tables defined in pf.  Return array of
	logicals that define which tables are valid and join
	tables. */
	table_list = check_tables(db,pf);
	check_for_required_tables(table_list);
	dbj = join_tables(db,pf,table_list);
	if(dbj.record == dbINVALID) elog_die(0,"dbjoin error\n");
	if(substr!=NULL) dbj=dbsubset(dbj,substr,0);
	long int ndbrows;
	dbquery(dbj,dbRECORD_COUNT,&ndbrows);
	if(ndbrows<=0)
	{
		elog_complain(1,"Working database view is empty\n");
		if(substr!=NULL) elog_complain(0,"Subset condtion =%s a likely problem\n",
				substr);
		usage();
	}

	fp = fopen(outfile,"w");
	if(fp == NULL)
	{
		elog_complain(0,"Cannot open output file %s\n",outfile);
		usage();
	}

	/* These are needed for sort below */
	pushtbl(sortkeys,"sta");
	pushtbl(sortkeys,"chan");

    /* Set up and write the Textual File Header */
	initialize_text_header(text_file_header, segy_format,
			text_header_description);

	if(write_reel_headers){
		if ( fwrite(text_file_header,1,SEGY_TEXT_HEADER_SIZE,fp) \
				!= SEGY_TEXT_HEADER_SIZE ) {
			elog_die(1,"An error occurred writing the textual file header");
		}
	}

	/* memory allocation for trace data.  This is a large matrix
	that is cleared for each event.  This model works because of
	segy's fixed length format.*/
	traces = calloc(nchan, sizeof(float*));
	if(traces == NULL)
		elog_die(1,"out of memory");
	for (int r = 0; r < nchan; r++)
	{
		traces[r] = calloc(nsamp0, sizeof(float));
		if(traces[r] == NULL)
			elog_die(1,"out of memory");
	}
	header = (SEGYTraceHeader *)calloc((size_t)nchan,sizeof(SEGYTraceHeader));
	if(header == NULL)
			elog_die(0,"Cannot alloc memory for %d segy header workspace\n",nchan);
	if(write_reel_headers)
	{
		if (Verbose) {
			elog_debug(0,"Binary Headers - Using segy_format code 0x%04X\n", ntohs(segy_format));
		}
		initialize_binary_file_header(&reel, segy_format);

		/* now fill in the binary reel header and write it */
		reel.kjob   = htonl(1);
		reel.kline  = htonl(1);
		reel.kreel  = htonl(1);
		reel.kntr   = htons((int16_t)nchan);
		reel.knaux  = htons(0);
		reel.sr     = htons((int16_t)(1000000.0/samprate0));
		reel.kfldsr = reel.sr;
		reel.knsamp = htons((int16_t)nsamp0);
		reel.kfsamp = htons((int16_t)nsamp0);
		reel.dsfc   = htons(5);  /* This is ieee floats*/
		reel.kmfold = htons(0);
		if(map_to_cdp)
			reel.ksort = htons(2);
		else
			reel.ksort = htons(1);
		reel.kunits = htons(1);  /* This sets units to always be meters */

		if(fwrite((void *)(&reel),sizeof(SEGYBinaryFileHeader),1,fp) != 1)
		{
			elog_die(1,"Write error for binary reel header");
		}
	}

	/* Now we enter a loop over stdin reading start times.
	Program will blindly ask for data from each start time to
	time+tlength.  The trace buffer will be initialized to
	zeros at the top of the loop always.  If nothing is found
	only zeros will be written to output.
	*/
	while((stest=fgets(s,80,stdin)) != NULL)
	{
		double slat,slon,selev;  /* Used when reading source location*/
		if(Verbose)
			elog_notify(0,"Processing:  %s\n",s);
		for(i=0;i<nchan;++i)
		{
			initialize_trace_header(&(header[i]), segy_format);
			header[i].gainType = trace_gain_type;
			header[i].lineSeq = htonl(total_traces + i + 1);
			header[i].reelSeq = header[i].lineSeq;
			if(map_to_cdp)
			{
				header[i].cdpEns = htonl(i + 1);
				header[i].traceInEnsemble = htonl(1);/* 1 trace per cdp faked */
			}
			else
			{
				header[i].channel_number = htonl(i + 1);
			}
			header[i].event_number   = htonl(shotid);
			header[i].energySourcePt = htonl(shotid);
			for(j=0;j<nsamp0;++j)  traces[i][j] = htonf((Trsample)0.0);
		}
		if(input_source_coordinates)
		{
			char stmp[40];
			sscanf(s,"%s%ld%lf%lf%lf",stmp,&shotid,&slon,&slat,&selev);
			time0=str2epoch(stmp);
			if(coordUnits == SEGY_TRACE_COORDUNITS_ARCSECONDS) {
				slat*=3600.0;
				slon*=3600.0;
			}
			slat *= (double)coordScale;
			slon *= (double)coordScale;
		}
		else
		{
			time0 = str2epoch(s);
		}
		endtime0 = time0 + tlength;
		sprintf(stime,"%20.4f",time0);
		sprintf(etime,"%20.4f",endtime0);
		trdb.database = -1;
		if(trload_css(dbj,stime,etime,&trdb,0, 0) < 0)
		{
			if(Verbose)
			{
			  elog_notify(0,"trload_css failed for shotid=%ld",shotid);
			  elog_notify(0,"  No data in time range %s to %s\n",
			  	strtime(time0),strtime(endtime0) );
			  elog_notify(0,"No data written for this shotid block.");
			  elog_notify(0,"  Handle this carefully in geometry definitions.\n");
			}

			continue;
		}
		/* This does gap processing */
		repair_gaps(trdb);

		trapply_calib(trdb);

		if(rotate)
		{
			if(rotate_to_standard(trdb,newchan_standard))
				elog_notify(0,"Data loss in rotate_to_standard for event %s to %s\n",
					stime, etime);
			/* This is need to prevent collisions of channel names */
			trdbss = dbsubset(trdb,trsubset,0);
			if(trrotate(trdbss,phi,theta,newchan))
				elog_notify(0,"Data loss in trrotate for event %s to %s\n",
					stime, etime);
		}
		if(Verbose)
			elog_notify(0,"Station  chan_name  chan_number seq_number shotid  evid\n");
		trdb = dbsort(trdb,sortkeys,0,0);
		dbquery(trdb,dbRECORD_COUNT,&ntraces);
		if(Verbose) elog_debug(0,"Read %ld traces for event at time%s\n",
			ntraces,strtime(time0));
		for(trdb.record=0;trdb.record<ntraces;++trdb.record)
		{
			Trsample *trdata;
			if(dbgetv(trdb,0,
			    "evid",&evid,
			    "sta",sta,
			    "chan",chan,
			    "nsamp", &nsamp,
			    "samprate",&samprate,
			    "data",&trdata,
			    "lat", &lat,
			    "lon", &lon,
			    "elev",&elev,
			    "refsta",refsta,
			    "dnorth",&dnorth,
			    "deast",&deast,
			    "edepth",&edepth,
			    "segtype",&segtype,
			    NULL) == dbINVALID)
			{
				elog_complain(0," dbgetv error reading record %ld. Trace will be skipped for station %s and channel %s",
				trdb.record,sta,chan);
				continue;
			}
			/* Allow 1 percent samprate error before killing */
			double fsrskew=fabs((samprate-samprate0)/samprate0);
			double frskewcut=0.01;
			if(fsrskew>frskewcut)
			{
				elog_complain(0,"%s:%s sample rate %f is significantly different from base sample rate of %f. Trace skipped -- segy requires fixed sample rates",
					sta,chan,samprate,samprate0);
				continue;
			}
			if(nsamp > nsamp0)
			{
				elog_complain(0,"%s:%s trace has extra samples=%ld. Truncated to length %d",
					sta, chan, nsamp, nsamp0);
				nsamp = nsamp0;
			}
			else if(nsamp < nsamp0)
			{
				elog_complain(0,"%s:%s trace is shorter than expected %d samples. Zero padded after sample %ld",
					sta, chan, nsamp0, nsamp);
			}

			ichan = get_channel_index(channels,sta,chan);
			if(ichan > nchan)
			{
				elog_die(0,"Channel index %d outside limit of %d. Cannot continue",
					ichan, nchan);
			}
			if(ichan >= 0)
			{
				if(Verbose)
					elog_debug(0,"%s:%s\t%-d\t%-d\t%-ld\t%-ld\n",
					sta,chan,ichan+1,
					ntohl(header[ichan].reelSeq),
					shotid, evid);
				header[ichan].traceID = get_trace_id_code_from_segtype(segtype);
				for(j=0;j<nsamp;++j) {
				   traces[ichan][j] = htonf((float)trdata[j]);
				}
				/* header fields coming from trace table */
				header[ichan].samp_rate = htonl(
						(int32_t) (1000000.0/samprate0));
				/* according to the behavior specified in the man page:
				 * if use_geo_coordinates is false:
				 * - coordUnits is length (meters)
				 * - therefore, we use deast for X and dnorth for Y
				 * if use_geo_coordinates is true:
				 * - we're using either arcseconds or decimal degrees
				 * - and therefore, we use lon for X and lat for Y
				 *
				 * coordUnits is based on use_arcseconds and the requested
				 * version of segY */

				/* set the coordinate units in the trace header */
				header[ichan].coordUnits = coordUnits;

				/* Pick the source db fields for our receiver X and Y */
				double recLongOrX = 0;
				double recLatOrY  = 0;
				if (coordUnits == SEGY_TRACE_COORDUNITS_LENGTH) {
					/* Use deast and dnorth
					 * CSS3.0 Schema specifies deast and dnorth are in KM.
					 * SEG-Y specifies easting and northing as meters,
					 * hence the 1000.0 multiplier here. */
					recLongOrX = deast  * 1000.0;
					recLatOrY  = dnorth * 1000.0;
				} else if (coordUnits == SEGY_TRACE_COORDUNITS_ARCSECONDS){
					/* Use lat and lon, converted to arcseconds */
					recLongOrX = lon * 3600.0;
					recLatOrY  = lat * 3600.0;
				} else {
					/* Default case, which covers decimal degrees */
					recLongOrX = lon;
					recLatOrY  = lat;
				}

				/* Apply our coordScale - the user can specify negative numbers,
				 * but they are treated as inverting the value, not as a divisor
				 * as in the SEG-Y field usage. See below where we always treat
				 * the scalar as a divisor in the SEG-Y field */
				recLongOrX *= (double)coordScale;
				recLatOrY  *= (double)coordScale;

				/* Set the coordScale in the header.
				 * Note negative here.  This is a oddity of segy that - means
				 * divide by this to get actual.  Always make this negative in
				 * case user inputs a negative number.
				 * Don't set it -1 for cosmetic reasons */
				if (abs(coordScale) == 1)
				{
					header[ichan].coordScale = htons(1);
				} else
				{
					header[ichan].coordScale = htons(-abs(coordScale));
				}

				/* Finally, write out the X and Y */
				header[ichan].recLongOrX
					= htonl((int32_t)recLongOrX);
				header[ichan].recLatOrY
					= htonl((int32_t)recLatOrY);

				/* CSS3.0 specfies elev as being in km, SEG-Y wants it in m */
				header[ichan].recElevation = htonl((int32_t)(elev*1000.0));

				header[ichan].deltaSample = htons(
						(int16_t) (1000000.0/samprate0));
				header[ichan].sampleLength = htons((int16_t)nsamp0);
				if (ntohs(segy_format)<0x0100)
				{
					header[ichan].num_samps = htonl((int32_t)nsamp0);
				}
				/* This cracks the time fields */
				time_str = epoch2str(time0,fmt);
				int16_t hyear, hday, hhour, hminute, hsecond, hm_secs;
				hyear=hday=hhour=hminute=hsecond=hm_secs=0;
				sscanf(time_str,"%hd %hd %hd %hd %hd %hd",
						&hyear, &hday, &hhour, &hminute, &hsecond, &hm_secs);
				header[ichan].year   = htons(hyear);
				header[ichan].day    = htons(hday);
				header[ichan].hour   = htons(hhour);
				header[ichan].minute = htons(hminute);
				header[ichan].second = htons(hsecond);
				header[ichan].m_secs = htons(hm_secs);
				if (ntohs(segy_format)<0x0100)
				{
					/* These are IRIS-PASSCAL extensions */
					header[ichan].trigyear   = header[ichan].year;
					header[ichan].trigday    = header[ichan].day;
					header[ichan].trighour   = header[ichan].hour;
					header[ichan].trigminute = header[ichan].minute;
					header[ichan].trigsecond = header[ichan].second;
				}
				free(time_str);
				if(input_source_coordinates)
				{
					/* Write out our pre-scaled and optionally
					 * arcsecond-converted source lat/lon plus our elevation */
					header[ichan].sourceLongOrX = htonl((int32_t)slon);
					header[ichan].sourceLatOrY  = htonl((int32_t)slat);
					header[ichan].sourceSurfaceElevation
						= htonl((int32_t)selev);
					/* No easy way to specify both elev and depth*/
					header[ichan].sourceDepth=htonl(0);
				}
				else if(map_to_cdp)
				{
				/* When faking CDP data we make this look
				like a zero offset, single fold data set */
					header[ichan].sourceLongOrX   = header[ichan].recLongOrX;
					header[ichan].sourceLatOrY    = header[ichan].recLatOrY;
					header[ichan].sourceSurfaceElevation
					                              = header[ichan].recElevation;
					header[ichan].sourceDepth     = htonl(0);
					header[ichan].sourceToRecDist = htonl(0);
				}
				else
				{
				/* This is the mechanism for adding other
				information with added tables.  The one
				table currently supported is a "shot" table
				that holds shot coordinates.  If other tables
				were added new functions could be added with
				a similar calling sequence.  This procedure
				silently does nothing if a shot table is not
				present.*/
					set_shot_variable(db,table_list,
						evid,&header[ichan]);
				}
			}
			else
			{
				if(Verbose)
					elog_notify(0,"Station %s and channel %s skipped\n",
						sta,chan);
			}

		}
		/* Now we write the data */
		for(i=0;i<nchan;++i)
		{
			if(fwrite((void *)(&(header[i])),sizeof(SEGYTraceHeader),1,fp) != 1)
				elog_die(0,"Write error on header for trace %d\n",total_traces+i);
			if(fwrite((void *)traces[i],sizeof(float),
					(size_t)nsamp0,fp) != nsamp0)
				elog_die(0,"Write error while writing data for trace %d\n",
					total_traces+i);
		}
		total_traces += nchan;
		trdestroy(&trdb);
		if(!input_source_coordinates) ++shotid;
	}
	return 0 ;
}
예제 #20
0
void
initialize_trace_header(SEGYTraceHeader *header, int16_t segy_format)
{
	assert( sizeof(SEGYTraceHeader)==SEGY_TRACE_HEADER_SIZE );
	memset(header, '\0', sizeof(SEGYTraceHeader));
	header->lineSeq = htonl(1);
	header->event_number = htonl(1);
	header->channel_number = htonl(1);
	header->energySourcePt = htonl(1);
	header->cdpEns = htonl(0);
	header->traceInEnsemble = htonl(0);
	header->traceID = SEGY_TRACE_ID_DEAD;
	header->vertSum = htons(0);
	header->dataUse = htons(0);
	header->sourceToRecDist = htonl(0);
	header->recElevation = htonl(0);
	header->sourceSurfaceElevation = htonl(0);
	header->sourceDepth = htonl(0);
	header->datumElevRec = htonl(0);
	header->recWaterDepth = htonl(0);
	header->elevationScale = htons(1);
	header->coordScale = htons(1);
	header->sourceLongOrX = htonl(0);
	header->recLongOrX = htonl(0);
	header->coordUnits = SEGY_TRACE_COORDUNITS_LENGTH;  /* sets units to m */
	header->weatheringVelocity = htons(0);
	header->subWeatheringVelocity = htons(0);
	header->sourceUpholeTime = htons(0);
	header->sourceStaticCor = htons(0);
	header->totalStatic = htons(0);
	header->lagTimeA = htons(0);
	header->delay = htons(0);
	header->muteStart = htons(0);
	header->sampleLength = htons(0);
	header->deltaSample = htons(0);
	header->gainType = SEGY_TRACE_GAIN_UNKNOWN;
	header->gainConst = htons(0);
	header->correlated = htons(0);
	header->sweepStart = htons(0);
	header->sweepLength = htons(0);
	header->sweepType = htons(0);
	header->sweepTaperAtStart = htons(0);
	header->taperType = htons(0);
	header->aliasFreq = htons(0);
	header->notchFreq = htons(0);
	header->lowCutFreq = htons(0);
	header->lowCutSlope = htons(0);
	header->year = htons(0);
    /* SEG-Y "classic" supports only time basis codes 0-3. Antelope records
     * in UTC (which has leap second corrections). */
    if (ntohs(segy_format)>=0x0100) {
        header->timeBasisCode = SEGY_TRACE_TIMEBASIS_UTC;
    } else {
        header->timeBasisCode = SEGY_TRACE_TIMEBASIS_GMT;
    }
	header->traceWeightingFactor = htons(0);
	header->phoneRollPos1 = htons(0);
	header->gapSize = htons(0);
	header->taperOvertravel = htons(0);
	/*header->extrash[10] is pre-zero'd */
	header->samp_rate = htonl(0);
	/* Begin Pavlis/IRIS-PASSCAL non-standard extensions */
	if (ntohs(segy_format)<0x0100) {
		/* Always ieee floats in this program for now */
		header->data_form  = htons(5);
		header->trigyear   = htons(0);
		header->trigday    = htons(0);
		header->trighour   = htons(0);
		header->trigminute = htons(0);
		header->trigsecond = htons(0);
		header->trigmills  = htons(0);
		header->scale_fac = htonf(0);
		header->inst_no = htons(0);
		header->not_to_be_used = htons(0);
		header->num_samps = htonl(0);
		/* header->extra is pre-zeroed */
	}
	/* End Pavlis non-standard extension */
	header->reelSeq = htonl(1);
	header->horSum = htons(0);
	header->datumElemSource = htonl(0);
	header->sourceWaterDepth = htonl(0);
	header->sourceLatOrY = htonl(0);
	header->recLatOrY = htonl(0);
	header->recUpholeTime = htons(0);
	header->recStaticCor = htons(0);
	header->lagTimeB = htons(0);
	header->muteEnd = htons(0);
	header->sweepTaperAtEnd = htons(0);
	header->aliasSlope = htons(0);
	header->notchSlope = htons(0);
	header->hiCutFreq = htons(0);
	header->hiCutSlope = htons(0);
	header->day    = htons(0);
	header->hour   = htons(0);
	header->minute = htons(0);
	header->second = htons(0);
	header->phoneFirstTrace = htons(0);
	header->phoneLastTrace  = htons(0);
	header->m_secs = htons(0);
	header->initialGain = htons(0);
	header->sweepEnd    = htons(0);
}
예제 #21
0
void FGNetFDM2Props( FGNetFDM *net ) {
    unsigned int i;

    //if ( net_byte_order ) {
        // Convert to the net buffer from network format
        net->version = ntohl(net->version);

        htond(net->longitude);  // use
        htond(net->latitude);   // use 
        htond(net->altitude);   // use
        htonf(net->agl);
        htonf(net->phi);
        htonf(net->theta);
        htonf(net->psi);
        htonf(net->alpha);
        htonf(net->beta);

		///  custom- put ifdef around?
        htonf(net->p);		// use
        htonf(net->q);	// use
        htonf(net->r); 	// use


        htonf(net->phidot);		// use
        htonf(net->thetadot);	// use
        htonf(net->psidot); 	// use
        htonf(net->vcas);
        htonf(net->climb_rate);
        htonf(net->v_north);
        htonf(net->v_east);
        htonf(net->v_down);
        htonf(net->v_wind_body_north);
        htonf(net->v_wind_body_east);
        htonf(net->v_wind_body_down);

        htonf(net->A_X_pilot);	// use
        htonf(net->A_Y_pilot);  // use
        htonf(net->A_Z_pilot);	// use

        htonf(net->stall_warning);
        htonf(net->slip_deg);

}
예제 #22
0
 void ROSSerializerVisitor::write(const uint32_t &/*id*/, const float &v) {
     m_size += sizeof(const float);
     float _v = htonf(v);
     m_buffer.write(reinterpret_cast<const char*>(&_v), sizeof(const float));
 }
예제 #23
0
파일: efc_variant.cpp 프로젝트: vilkov/efc
size_t Variant::serialize(unsigned char *buffer, size_t size) const
{
    if (!isValid())
        return 0;
    else
    {
        size_t minBufSize = Variant::size() + 1;

        if (m_data->type == STRING || m_data->type == BINARY)
            minBufSize += sizeof(uint32_t);

        if (size >= minBufSize)
        {
            ASSERT(buffer != NULL);

            *buffer = static_cast<uint8_t>(m_data->type);
            ++buffer;

            switch (m_data->type)
            {
                case UINT8:
                case INT8:
                case BOOL:
                case CHAR:
                    *buffer = m_data->data.uint_value.uint8_value[LoByte];
                    break;

                case UINT16:
                case INT16:
                    *reinterpret_cast<uint16_t *>(buffer) = htons(m_data->data.uint_value.uint16_value[LoWord]);
                    break;

                case UINT32:
                case INT32:
                    *reinterpret_cast<uint32_t *>(buffer) = htonl(m_data->data.uint_value.uint32_value[LoDWord]);
                    break;

                case UINT64:
                case INT64:
                    *reinterpret_cast<uint64_t *>(buffer) = htonll(m_data->data.uint_value.uint64_value);
                    break;

                case FLOAT:
                    *reinterpret_cast<uint32_t *>(buffer) = htonf(m_data->data.float_value);
                    break;

                case DOUBLE:
                    *reinterpret_cast<uint64_t *>(buffer) = htond(m_data->data.double_value);
                    break;

                case STRING:
                case BINARY:
                {
                    *reinterpret_cast<uint32_t*>(buffer) = htonl(m_data->data.string_value.size);
                    ::memcpy(buffer + sizeof(uint32_t), m_data->data.string_value.value, m_data->data.string_value.size);

                    break;
                }
            }
        }

        return minBufSize;
    }
}
예제 #24
0
파일: group_move.c 프로젝트: rzel/dim3
void group_moves_synch_with_client(int group_idx,network_reply_group_synch *synch)
{
	int				flags;
	group_type		*group;

		// setup the synch for the client

	synch->group_idx=htons((short)group_idx);

	group=&map.group.groups[group_idx];

	flags=0;
	if (group->run.on) flags|=net_group_synch_flag_on;
	if (group->run.freeze) flags|=net_group_synch_flag_freeze;
	if (group->run.main_move) flags|=net_group_synch_flag_main_move;

	synch->flags=htonl(flags);

	synch->count=htons((short)group->run.count);
	synch->user_id=htons((short)group->run.user_id);
	synch->movement_idx=htons((short)group->run.movement_idx);
	synch->movement_move_idx=htons((short)group->run.movement_move_idx);

	synch->fp_mov_add_x=htonf(group->run.f_mov_add.x);
	synch->fp_mov_add_y=htonf(group->run.f_mov_add.y);
	synch->fp_mov_add_z=htonf(group->run.f_mov_add.z);
	
	synch->fp_mov_accum_add_x=htonf(group->run.f_mov_accum_add.x);
	synch->fp_mov_accum_add_y=htonf(group->run.f_mov_accum_add.y);
	synch->fp_mov_accum_add_z=htonf(group->run.f_mov_accum_add.z);

	synch->fp_rot_add_x=htonf(group->run.rot_add.x);
	synch->fp_rot_add_y=htonf(group->run.rot_add.y);
	synch->fp_rot_add_z=htonf(group->run.rot_add.z);

	synch->cuml_mov_add_x=htonl(group->run.cuml_mov_add.x);
	synch->cuml_mov_add_y=htonl(group->run.cuml_mov_add.y);
	synch->cuml_mov_add_z=htonl(group->run.cuml_mov_add.z);

	synch->fp_cuml_rot_add_x=htonf(group->run.cuml_rot_add.x);
	synch->fp_cuml_rot_add_y=htonf(group->run.cuml_rot_add.y);
	synch->fp_cuml_rot_add_z=htonf(group->run.cuml_rot_add.z);
}
예제 #25
0
//parse the config file
void ConfigSettings::parse_config(char *config_file){
	//first set the defaults
	apply_defaults();
	//store the filename
	strcpy(_config_file, config_file);
	
	FILE *cfile = fopen(_config_file, "r");	
	if (!cfile){
		fprintf(stdout, _("Cannot read file: %s\nUsing defaults...\n"), _config_file);
		return;
	}
	
	char buffer[256];
	char *tmpptr;
	while (fgets(buffer, 256, cfile)){
		//use the # as a comment, and ignore newlines
		if (buffer[0] == '#' || buffer[0] == '\n'){
			continue;
		}
		tmpptr=strtok(buffer, "=\n");
		if (strcmp(tmpptr, "card")==0){
			tmpptr=strtok(NULL, "=\"\n");
			strcpy(card, tmpptr);
		} else if (strcmp(tmpptr, "scaling")==0){
			tmpptr=strtok(NULL, "=\n");
			scaling=atoi(tmpptr);
			if (scaling < 0 || scaling > NUM_SCALE_T - 1){ scaling = _d_scaling; }  //if out of bounds, use default
		} else if (strcmp(tmpptr, "auto_mute")==0){
			tmpptr=strtok(NULL, "=\n");
			auto_mute=(bool)atoi(tmpptr);
		} else if (strcmp(tmpptr, "vertical")==0){
			tmpptr=strtok(NULL, "=\n");
			vertical=(bool)atoi(tmpptr);
		} else if (strcmp(tmpptr, "window_x")==0){
			tmpptr=strtok(NULL, "=\n");
			window_x=atoi(tmpptr);
		} else if (strcmp(tmpptr, "window_y")==0){
			tmpptr=strtok(NULL, "=\n");
			window_y=atoi(tmpptr);
		} else if (strcmp(tmpptr, "window_width")==0){
			tmpptr=strtok(NULL, "=\n");
			window_width=atoi(tmpptr);
		} else if (strcmp(tmpptr, "window_height")==0){
			tmpptr=strtok(NULL, "=\n");
			window_height=atoi(tmpptr);
		} else if (strcmp(tmpptr, "slider_width")==0){
			tmpptr=strtok(NULL, "=\n");
			slider_width=atoi(tmpptr);
		} else if (strcmp(tmpptr, "slider_height")==0){
			tmpptr=strtok(NULL, "=\n");
			slider_height=atoi(tmpptr);
		} else if (strcmp(tmpptr, "slider_margin")==0){
			tmpptr=strtok(NULL, "=\n");
			slider_margin=atoi(tmpptr);
		} else if (strcmp(tmpptr, "seg_thickness")==0){
			tmpptr=strtok(NULL, "=\n");
			seg_thickness=atoi(tmpptr);
		} else if (strcmp(tmpptr, "seg_spacing")==0){
			tmpptr=strtok(NULL, "=\n");
			seg_spacing=atoi(tmpptr);
		} else if (strcmp(tmpptr, "background_color")==0){
			tmpptr=strtok(NULL, "=\n");
			htonf(background_color, tmpptr);
		} else if (strcmp(tmpptr, "border_color")==0){
			tmpptr=strtok(NULL, "=\n");
			htonf(border_color, tmpptr);
		} else if (strcmp(tmpptr, "unlit_color")==0){
			tmpptr=strtok(NULL, "=\n");
			htonf(unlit_color, tmpptr);
		} else if (strcmp(tmpptr, "lit_color")==0){
			tmpptr=strtok(NULL, "=\n");
			htonf(lit_color, tmpptr);
		} else if (strcmp(tmpptr, "enable_tray_icon")==0){
			tmpptr=strtok(NULL, "=\n");
			enable_tray_icon=(bool)atoi(tmpptr);
		} else if (strcmp(tmpptr, "enable_tray_menu")==0){
			tmpptr=strtok(NULL, "=\n");
			enable_tray_menu=(bool)atoi(tmpptr);
		} else if (strcmp(tmpptr, "tray_icon_background_color")==0){
			tmpptr=strtok(NULL, "=\n");
			htonf(tray_icon_background_color, tmpptr);
			enable_tray_icon_background_color=true;
		} else if (strcmp(tmpptr, "tray_slider_vertical")==0){
			tmpptr=strtok(NULL, "=\n");
			tray_slider_vertical=(bool)atoi(tmpptr);
		} else if (strcmp(tmpptr, "tray_slider_width")==0){
			tmpptr=strtok(NULL, "=\n");
			tray_slider_width=atoi(tmpptr);
		} else if (strcmp(tmpptr, "tray_slider_height")==0){
			tmpptr=strtok(NULL, "=\n");
			tray_slider_height=atoi(tmpptr);
		} else if (strcmp(tmpptr, "tray_slider_offset")==0){
			tmpptr=strtok(NULL, "=\n");
			tray_slider_offset=atoi(tmpptr);
		} else if (strcmp(tmpptr, "tray_control")==0){
			tmpptr=strtok(NULL, "=\n");
			tray_control_numid=atoi(tmpptr);
		} else if (strcmp(tmpptr, "sliders:")==0){
			int n;
			for (n=0; fgets(buffer, 256, cfile); n++){
				char *buff = buffer;
				//skip over any whitespace
				while (buff[0] && (buff[0] == ' ' || buff[0] == '\t')){ buff++; }
				//skip any commented lines or newlines
				if (buff[0] == '#' || buff[0] == '\n'){
					n--;
					continue;
				}

				//save the numid and initialize the name to an empty string
				numid_list[n] = atoi(buff);
				name_list[n][0] = '\0';
			}
			num_numids=n;
		}
	}
	
	fclose(cfile);
	
}
/*
 * Formats an Float (32bits) from host to TCP/IP network byte order (which is big-endian)
 * and sends it thought the Socket
 */
void SendFloatClientSocket(SOCKET theSocket, float value)
{
	int htonvalue[] = { htonf(value) };
	send(theSocket, (char*)htonvalue, sizeof(int), 0);
}
예제 #27
0
void toByteArray_htonf(float value, Byte * barr) {
	float temp = htonf(value);
	memcpy (barr, &temp, sizeof(value));
}
예제 #28
0
파일: Helpers.cpp 프로젝트: Aero348/dune
    void
    convertToNetworkEndian(FGNetFDM* net)
    {
      // Convert the net buffer to network format
      net->version = ByteCopy::toBE(net->version);

      htond(net->longitude);
      htond(net->latitude);
      htond(net->altitude);
      htonf(net->agl);
      htonf(net->phi);
      htonf(net->theta);
      htonf(net->psi);
      htonf(net->alpha);
      htonf(net->beta);

      htonf(net->phidot);
      htonf(net->thetadot);
      htonf(net->psidot);
      htonf(net->vcas);
      htonf(net->climb_rate);
      htonf(net->v_north);
      htonf(net->v_east);
      htonf(net->v_down);
      htonf(net->v_wind_body_north);
      htonf(net->v_wind_body_east);
      htonf(net->v_wind_body_down);

      htonf(net->A_X_pilot);
      htonf(net->A_Y_pilot);
      htonf(net->A_Z_pilot);

      htonf(net->stall_warning);
      htonf(net->slip_deg);

      unsigned int i;
      for (i = 0; i < net->num_engines; ++i)
      {
        net->eng_state[i] = ByteCopy::toBE(net->eng_state[i]);
        htonf(net->rpm[i]);
        htonf(net->fuel_flow[i]);
        htonf(net->fuel_px[i]);
        htonf(net->egt[i]);
        htonf(net->cht[i]);
        htonf(net->mp_osi[i]);
        htonf(net->tit[i]);
        htonf(net->oil_temp[i]);
        htonf(net->oil_px[i]);
      }
      net->num_engines = ByteCopy::toBE(net->num_engines);

      for (i = 0; i < net->num_tanks; ++i)
      {
        htonf(net->fuel_quantity[i]);
      }
      net->num_tanks = ByteCopy::toBE(net->num_tanks);

      for (i = 0; i < net->num_wheels; ++i)
      {
        net->wow[i] = ByteCopy::toBE(net->wow[i]);
        htonf(net->gear_pos[i]);
        htonf(net->gear_steer[i]);
        htonf(net->gear_compression[i]);
      }
      net->num_wheels = ByteCopy::toBE(net->num_wheels);

      net->cur_time = ByteCopy::toBE(net->cur_time);
      net->warp = ByteCopy::toBE(net->warp);
      htonf(net->visibility);

      htonf(net->elevator);
      htonf(net->elevator_trim_tab);
      htonf(net->left_flap);
      htonf(net->right_flap);
      htonf(net->left_aileron);
      htonf(net->right_aileron);
      htonf(net->rudder);
      htonf(net->nose_wheel);
      htonf(net->speedbrake);
      htonf(net->spoilers);
    }
예제 #29
0
/**
 * Send FlightGear FDM packet
 * For visualization with moving surfaces (elevator, propeller etc).
 * start fgfs with --native-fdm=socket... option
 */
void nps_flightgear_send_fdm()
{
  struct FGNetFDM fgfdm;

  memset(&fgfdm, 0, sizeof(fgfdm));
  fgfdm.version = htonl(FG_NET_FDM_VERSION);

  fgfdm.latitude  = htond(fdm.lla_pos.lat);
  fgfdm.longitude = htond(fdm.lla_pos.lon);
  fgfdm.altitude  = htond(fdm.lla_pos.alt);


  fgfdm.agl = htonf((float)fdm.agl);

  fgfdm.phi = htonf((float)fdm.ltp_to_body_eulers.phi);
  fgfdm.theta = htonf((float)fdm.ltp_to_body_eulers.theta);
  fgfdm.psi = htonf((float)fdm.ltp_to_body_eulers.psi);

  fgfdm.vcas = htonf(0.);
  fgfdm.climb_rate = htonf(0.);

  fgfdm.num_tanks = htonl(1);
  fgfdm.fuel_quantity[0] = htonf(0.);

  fgfdm.cur_time = htonl(flightgear.initial_time + rint(fdm.time));
  // if cur_time is zero, flightgear would take the real current time
  //gui.cur_time = 0;
  // warp is used as an offset to the current time in seconds
  fgfdm.warp = htonl(flightgear.time_offset);

  // Engine
  fgfdm.num_engines = htonl(fdm.num_engines);
  for (int k = 0; k < FG_NET_FDM_MAX_ENGINES; k++) {
    // Temprary hack to clearly show when the engine is running
    if (fdm.eng_state[k] == 1) {
      fgfdm.rpm[k] = htonf(fdm.rpm[k]);
    } else {
      fgfdm.rpm[k] = htonf(0.0);
    }
    fgfdm.eng_state[k] = htonl(fdm.eng_state[k]);
  }

  //control surfaces
  fgfdm.elevator = htonf(fdm.elevator);
  fgfdm.left_aileron = htonf(fdm.left_aileron);
  fgfdm.right_aileron = htonf(fdm.right_aileron);
  fgfdm.rudder = htonf(fdm.rudder);
  fgfdm.left_flap = htonf(fdm.flap);
  fgfdm.right_flap = htonf(fdm.flap);

  if (sendto(flightgear.socket, (char *)(&fgfdm), sizeof(fgfdm), 0,
             (struct sockaddr *)&flightgear.addr, sizeof(flightgear.addr)) == -1) {
    fprintf(stderr, "error sending to FlightGear\n");
    fflush(stderr);
  }
}
예제 #30
0
float ntohf(float net)
{
	return htonf(net);
}