void write_unstructured_mesh(const char *filename, int ub, int npts, float *pts, int ncells, int *celltypes, int *conn, int nvars, int *vardim, int *centering, const char * const *varnames, float **vars) { int i, j; char str[128]; int conn_size = 0; int *curr_conn = conn; useBinary = ub; open_file(filename); write_header(); write_string("DATASET UNSTRUCTURED_GRID\n"); sprintf(str, "POINTS %d float\n", npts); write_string(str); for (i = 0 ; i < 3*npts ; i++) { write_float(pts[i]); } new_section(); for (i = 0 ; i < ncells ; i++) { int npts = num_points_for_cell(celltypes[i]); conn_size += npts+1; } sprintf(str, "CELLS %d %d\n", ncells, conn_size); write_string(str); for (i = 0 ; i < ncells ; i++) { int npts = num_points_for_cell(celltypes[i]); write_int(npts); for (j = 0 ; j < npts ; j++) write_int(*curr_conn++); end_line(); } new_section(); sprintf(str, "CELL_TYPES %d\n", ncells); write_string(str); for (i = 0 ; i < ncells ; i++) { write_int(celltypes[i]); end_line(); } write_variables(nvars, vardim, centering, varnames, vars, npts, ncells); close_file(); }
int key_value_write_lines(FILE *f, struct key_value_specification *kvs, void *base_address[]) { struct key_value_specification *k; int rc; int errs = 0; for (k = kvs; k->key; k++) { switch (k->type) { case KVS_STRING: rc = write_string(f, k, base_address); break; case KVS_INT64: rc = write_int64(f, k, base_address); break; case KVS_INT32: rc = write_int32(f, k, base_address); break; case KVS_INT16: rc = write_int16(f, k, base_address); break; case KVS_INT8: rc = write_int8(f, k, base_address); break; case KVS_UINT64: rc = write_uint64(f, k, base_address); break; case KVS_UINT32: rc = write_uint32(f, k, base_address); break; case KVS_UINT16: rc = write_uint16(f, k, base_address); break; case KVS_UINT8: rc = write_uint8(f, k, base_address); break; case KVS_DOUBLE: rc = write_double(f, k, base_address); break; case KVS_FLOAT: rc = write_float(f, k, base_address); break; default: fprintf(stderr, "%s:%d: unknown key type '%c' for key '%s'\n", __func__, __LINE__, k->type, k->key); rc = -1; break; } if (rc) errs++; } return errs; }
static void write_field( FILE *f, const save_field_t *field, void *base ) { void *p = (byte *)base + field->ofs; int i; switch( field->type ) { case F_BYTE: write_data( p, field->size, f ); break; case F_SHORT: for( i = 0; i < field->size; i++ ) { write_short( f, (( short * )p)[i] ); } break; case F_INT: for( i = 0; i < field->size; i++ ) { write_int( f, (( int * )p)[i] ); } break; case F_FLOAT: for( i = 0; i < field->size; i++ ) { write_float( f, (( float * )p)[i] ); } break; case F_VECTOR: write_vector( f, ( vec_t * )p ); break; case F_ZSTRING: write_string( f, ( char * )p ); break; case F_LSTRING: write_string( f, *( char ** )p ); break; case F_EDICT: write_index( f, *( void ** )p, sizeof( edict_t ), g_edicts, MAX_EDICTS - 1 ); break; case F_CLIENT: write_index( f, *( void ** )p, sizeof( gclient_t ), game.clients, game.maxclients - 1 ); break; case F_ITEM: write_index( f, *( void ** )p, sizeof( gitem_t ), itemlist, game.num_items - 1 ); break; case F_POINTER: write_pointer( f, *( void ** )p, field->size ); break; default: gi.error( "%s: unknown field type", __func__ ); } }
void write_rectilinear_mesh(const char *filename, int ub, int *dims, float *x, float *y, float *z, int nvars, int *vardim, int *centering, const char * const *varnames, float **vars) { int i; char str[128]; int npts = dims[0]*dims[1]*dims[2]; int ncX = (dims[0] - 1 < 1 ? 1 : dims[0] - 1); int ncY = (dims[1] - 1 < 1 ? 1 : dims[1] - 1); int ncZ = (dims[2] - 1 < 1 ? 1 : dims[2] - 1); int ncells = ncX*ncY*ncZ; useBinary = ub; open_file(filename); write_header(); write_string("DATASET RECTILINEAR_GRID\n"); sprintf(str, "DIMENSIONS %d %d %d\n", dims[0], dims[1], dims[2]); write_string(str); sprintf(str, "X_COORDINATES %d float\n", dims[0]); write_string(str); for (i = 0 ; i < dims[0] ; i++) write_float(x[i]); new_section(); sprintf(str, "Y_COORDINATES %d float\n", dims[1]); write_string(str); for (i = 0 ; i < dims[1] ; i++) write_float(y[i]); new_section(); sprintf(str, "Z_COORDINATES %d float\n", dims[2]); write_string(str); for (i = 0 ; i < dims[2] ; i++) write_float(z[i]); write_variables(nvars, vardim, centering, varnames, vars, npts, ncells); close_file(); }
void write_point_mesh(const char *filename, int ub, int npts, float *pts, int nvars, int *vardim, const char * const *varnames, float **vars) { int i; char str[128]; int *centering = NULL; useBinary = ub; open_file(filename); write_header(); write_string("DATASET UNSTRUCTURED_GRID\n"); sprintf(str, "POINTS %d float\n", npts); write_string(str); for (i = 0 ; i < 3*npts ; i++) { write_float(pts[i]); } new_section(); sprintf(str, "CELLS %d %d\n", npts, 2*npts); write_string(str); for (i = 0 ; i < npts ; i++) { write_int(1); write_int(i); end_line(); } new_section(); sprintf(str, "CELL_TYPES %d\n", npts); write_string(str); for (i = 0 ; i < npts ; i++) { write_int(VISIT_VERTEX); end_line(); } centering = (int *) malloc(nvars*sizeof(int)); for (i = 0 ; i < nvars ; i++) centering[i] = 1; write_variables(nvars, vardim, centering, varnames, vars, npts, npts); free(centering); close_file(); }
void data_store::save(std::string f_name) { std::cout << "# Saving regridded data" << std::endl; std::ofstream out; out.open(f_name.c_str(), std::ios::out | std::ios::binary); if (!out) throw(std::string("Saving regridded data. File could not be opened or written to: " + f_name)); if (meta_data.size() != 0) write_meta_data(out, meta_data); // write out the number of time steps and indices write_int(out, n_t_steps); write_int(out, n_idxs); write_float(out, missing_value); // write the big array! out.write(reinterpret_cast<char*>(data), sizeof(FP_TYPE)*n_t_steps*n_idxs); out.close(); }
static void write_element(const region_element* element, DWORD *buffer, INT* filled) { write_dword(buffer, filled, element->type); switch (element->type) { case CombineModeReplace: case CombineModeIntersect: case CombineModeUnion: case CombineModeXor: case CombineModeExclude: case CombineModeComplement: write_element(element->elementdata.combine.left, buffer, filled); write_element(element->elementdata.combine.right, buffer, filled); break; case RegionDataRect: write_float(buffer, filled, element->elementdata.rect.X); write_float(buffer, filled, element->elementdata.rect.Y); write_float(buffer, filled, element->elementdata.rect.Width); write_float(buffer, filled, element->elementdata.rect.Height); break; case RegionDataPath: { INT i; const GpPath* path = element->elementdata.pathdata.path; memcpy(buffer + *filled, &element->elementdata.pathdata.pathheader, sizeof(element->elementdata.pathdata.pathheader)); *filled += sizeof(element->elementdata.pathdata.pathheader) / sizeof(DWORD); switch (element->elementdata.pathdata.pathheader.flags) { case FLAGS_NOFLAGS: for (i = 0; i < path->pathdata.Count; i++) { write_float(buffer, filled, path->pathdata.Points[i].X); write_float(buffer, filled, path->pathdata.Points[i].Y); } break; case FLAGS_INTPATH: for (i = 0; i < path->pathdata.Count; i++) { write_packed_point(buffer, filled, &path->pathdata.Points[i]); } } write_path_types(buffer, filled, path); break; } case RegionDataEmptyRect: case RegionDataInfiniteRect: break; } }
size_t CameraMessage::serialize(unsigned char *write_buffer) { /* 长度,类型,id,内容 */ size_t len = getSize(); write_uint(write_buffer, 0, &len); write_uint(write_buffer, 4, &_msg_type); write_uint(write_buffer, 8, &_client_id); write_float(write_buffer, 12, &_camera._eyex); write_float(write_buffer, 16, &_camera._eyey); write_float(write_buffer, 20, &_camera._eyez); write_float(write_buffer, 24, &_camera._centerx); write_float(write_buffer, 28, &_camera._centery); write_float(write_buffer, 32, &_camera._centerz); write_float(write_buffer, 36, &_camera._upx); write_float(write_buffer, 40, &_camera._upy); write_float(write_buffer, 44, &_camera._upz); return len; }
void Cxif_value::save(byte*& data) const { *data++ = m_type; switch (m_type) { case vt_bin32: case vt_int32: data = write_int_le(4, data, get_int()); break; case vt_float: data = write_float(data, get_float()); break; default: { int size = get_size(); data = write_int_le(4, data, size); memcpy(data, get_data(), size); data += size; } } }
int le_save_task(le_task *t, const char *file) { int i, j; FILE *fp = fopen(file, "w"); if (fp == NULL) { perror("Failed to open file"); return 1; } fprintf(fp, "# vtk DataFile Version 3.0\n"); fprintf(fp, "Created by le_save_task\n"); fprintf(fp, "BINARY\n"); fprintf(fp, "DATASET STRUCTURED_POINTS\n"); fprintf(fp, "DIMENSIONS %d %d 1\n", t->n.x, t->n.y); fprintf(fp, "SPACING %f %f 0.0\n", t->h.x, t->h.y); fprintf(fp, "ORIGIN 0.0 0.0 0.0\n"); fprintf(fp, "POINT_DATA %d\n", t->n.x * t->n.y); /* velocity */ fprintf(fp, "SCALARS v float 1\n"); fprintf(fp, "LOOKUP_TABLE v_table\n"); for (j = 0; j < t->n.y; j++) { for (i = 0; i < t->n.x; i++) { float v; if (t->stype == ST_AOS) { v = vnorm(gind(i, j).v); } else if (t->stype == ST_SOA) { le_vec2 vt = { soa_vx(i, j), soa_vy(i, j) }; v = vnorm(vt); } else { assert(0); } write_float(fp, v); } } /* * You can use the same code for saving other variables. */ fclose(fp); return 0; }
void steering_extremum::save(std::ofstream& out) { // write the extremum out as a binary chunk // write the timestep, longitude, latitude, intensity, delta, geostrophic wind u & v write_float(out, lon); write_float(out, lat); write_float(out, intensity); write_float(out, delta); write_float(out, sv_u); write_float(out, sv_v); // write number of object labels first write_int(out, object_labels.size()); for (LABEL_STORE::iterator it_obj_lab = object_labels.begin(); it_obj_lab != object_labels.end(); it_obj_lab++) write_label(out, *it_obj_lab); }
int crf1mmw_put_feature(crf1mmw_t* writer, int fid, const crf1mm_feature_t* f) { FILE *fp = writer->fp; feature_header_t* hfeat = writer->hfeat; /* Make sure that we are writing attribute feature references. */ if (writer->state != WSTATE_FEATURES) { return CRFERR_INTERNAL_LOGIC; } /* We must put features #0, #1, ..., #(K-1) in this order. */ if (fid != hfeat->num) { return CRFERR_INTERNAL_LOGIC; } write_uint32(fp, f->type); write_uint32(fp, f->src); write_uint32(fp, f->dst); write_float(fp, f->weight); ++hfeat->num; return 0; }
void Temp::save(int32_t &addr) { write_float(addr, R0); write_float(addr, R1); write_float(addr, logRc); write_float(addr, Tc); write_float(addr, beta); /* write_float(addr, core_C); write_float(addr, shell_C); write_float(addr, transfer); write_float(addr, radiation); write_float(addr, power); */ write_16(addr, power_pin[0].write()); write_16(addr, power_pin[1].write()); write_16(addr, thermistor_pin.write()); write_float(addr, target[1]); write_float(addr, arch_get_duty(power_pin[1])); }
static void io_write (void) { int status = 0; if (lua_getparam (2) == LUA_NOOBJECT) /* free format */ { lua_Object o1 = lua_getparam(1); if (lua_isnumber(o1)) status = fprintf (out, "%g", lua_getnumber(o1)) >= 0; else if (lua_isstring(o1)) status = fprintf (out, "%s", lua_getstring(o1)) >= 0; } else /* formated */ { int just, m, n; switch (getformat (lua_check_string(2, "write"), &just, &m, &n)) { case 's': { lua_Object p = lua_getparam(1); if (lua_isstring(p)) status = write_string(lua_getstring(p), just, m); else status = 0; break; } case 'f': status = write_float(just, m, n); break; case 'i': status = write_int(just, m, n); break; } } if (status) lua_pushnumber(status); else lua_pushnil(); }
bool Profile::write_profile(const char *section) { bool res = true; bool err = true; if(!cfg) return(false); for(int i=0;cfg[i].name;i++) { switch(cfg[i].type) { case cfgINT: res = write_int(section,cfg[i].name,*(int*)cfg[i].var ); if(!res) { error("write_profile(%s) : write_int error",section); write_str(section,cfg[i].name,cfg[i].defval); } break; case cfgSTR: res = write_str(section,cfg[i].name,(const char*)cfg[i].var); if(!res) { error("write_profile(%s) : write_str error",section); write_str(section,cfg[i].name,cfg[i].defval); } break; case cfgFLOAT: res = write_float(section, cfg[i].name,*(float*)cfg[i].var ); if(!res) { error("write_profile(%s) : write_float error",section); write_str(section,cfg[i].name,cfg[i].defval); } break; case cfgNULL: break; } } return(err); }
static void write_real (st_parameter_dt *dtp, const char *source, int length) { fnode f ; int org_scale = dtp->u.p.scale_factor; f.format = FMT_G; dtp->u.p.scale_factor = 1; switch (length) { case 4: f.u.real.w = 14; f.u.real.d = 7; f.u.real.e = 2; break; case 8: f.u.real.w = 23; f.u.real.d = 15; f.u.real.e = 3; break; case 10: f.u.real.w = 28; f.u.real.d = 19; f.u.real.e = 4; break; case 16: f.u.real.w = 43; f.u.real.d = 34; f.u.real.e = 4; break; default: internal_error (&dtp->common, "bad real kind"); break; } write_float (dtp, &f, source , length); dtp->u.p.scale_factor = org_scale; }
void globals_save(int32_t &addr) { write_8(addr, QUEUE_LENGTH); write_8(addr, NUM_PINS); write_8(addr, num_temps); write_8(addr, num_gpios); write_16(addr, led_pin.write()); write_16(addr, stop_pin.write()); write_16(addr, probe_pin.write()); write_16(addr, spiss_pin.write()); write_16(addr, timeout); write_16(addr, bed_id); write_16(addr, fan_id); write_16(addr, spindle_id); write_float(addr, feedrate); write_float(addr, max_deviation); write_float(addr, max_v); write_8(addr, current_extruder); write_float(addr, targetx); write_float(addr, targety); write_float(addr, zoffset); write_8(addr, store_adc != NULL); }
static void write_element(const region_element* element, DWORD *buffer, INT* filled) { write_dword(buffer, filled, element->type); switch (element->type) { case CombineModeReplace: case CombineModeIntersect: case CombineModeUnion: case CombineModeXor: case CombineModeExclude: case CombineModeComplement: write_element(element->elementdata.combine.left, buffer, filled); write_element(element->elementdata.combine.right, buffer, filled); break; case RegionDataRect: write_float(buffer, filled, element->elementdata.rect.X); write_float(buffer, filled, element->elementdata.rect.Y); write_float(buffer, filled, element->elementdata.rect.Width); write_float(buffer, filled, element->elementdata.rect.Height); break; case RegionDataPath: { INT i; const GpPath* path = element->elementdata.path; struct _pathheader { DWORD size; DWORD magic; DWORD count; DWORD flags; } *pathheader; pathheader = (struct _pathheader *)(buffer + *filled); pathheader->flags = is_integer_path(path) ? FLAGS_INTPATH : FLAGS_NOFLAGS; /* 3 for headers, once again size doesn't count itself */ pathheader->size = sizeof(DWORD) * 3; if (pathheader->flags & FLAGS_INTPATH) pathheader->size += 2 * sizeof(SHORT) * path->pathdata.Count; else pathheader->size += 2 * sizeof(FLOAT) * path->pathdata.Count; pathheader->size += get_pathtypes_size(path); pathheader->magic = VERSION_MAGIC; pathheader->count = path->pathdata.Count; *filled += 4; switch (pathheader->flags & FLAGS_INTPATH) { case FLAGS_NOFLAGS: for (i = 0; i < path->pathdata.Count; i++) { write_float(buffer, filled, path->pathdata.Points[i].X); write_float(buffer, filled, path->pathdata.Points[i].Y); } break; case FLAGS_INTPATH: for (i = 0; i < path->pathdata.Count; i++) { write_packed_point(buffer, filled, &path->pathdata.Points[i]); } break; } write_path_types(buffer, filled, path); break; } case RegionDataEmptyRect: case RegionDataInfiniteRect: break; } }
static void write_vector(FILE *f, vec_t *v) { write_float(f, v[0]); write_float(f, v[1]); write_float(f, v[2]); }
void write_es (st_parameter_dt *dtp, const fnode *f, const char *p, int len) { write_float (dtp, f, p, len); }
void Space::save_axis(uint8_t a, int32_t &addr) { // {{{ write_float(addr, axis[a]->park); write_8(addr, axis[a]->park_order); write_float(addr, axis[a]->min_pos); write_float(addr, axis[a]->max_pos); } // }}}
static DATA_apdu *weight_scale_populate_event_report(void *edata) { DATA_apdu *data; EventReportArgumentSimple evt; ScanReportInfoFixed scan; ObservationScanFixedList scan_fixed; ObservationScanFixed measure[4]; AbsoluteTime nu_time; FLOAT_Type nu_weight; FLOAT_Type nu_bmi; struct weightscale_event_report_data *evtdata; data = calloc(sizeof(DATA_apdu), 1); evtdata = (struct weightscale_event_report_data*) edata; nu_time = date_util_create_absolute_time(evtdata->century * 100 + evtdata->year, evtdata->month, evtdata->day, evtdata->hour, evtdata->minute, evtdata->second, evtdata->sec_fractions); nu_weight = evtdata->weight; nu_bmi = evtdata->bmi; // will be filled afterwards by service_* function data->invoke_id = 0xffff; data->message.choice = ROIV_CMIP_CONFIRMED_EVENT_REPORT_CHOSEN; data->message.length = 82; evt.obj_handle = 0; evt.event_time = 0xFFFFFFFF; evt.event_type = MDC_NOTI_SCAN_REPORT_FIXED; evt.event_info.length = 72; scan.data_req_id = 0xF000; scan.scan_report_no = 0; scan_fixed.count = 4; scan_fixed.length = 64; scan_fixed.value = measure; measure[0].obj_handle = 1; measure[0].obs_val_data.length = 12; ByteStreamWriter *writer0 = byte_stream_writer_instance(measure[0].obs_val_data.length); write_float(writer0, nu_weight); encode_absolutetime(writer0, &nu_time); measure[1].obj_handle = 3; measure[1].obs_val_data.length = 12; ByteStreamWriter *writer1 = byte_stream_writer_instance(measure[1].obs_val_data.length); write_float(writer1, nu_bmi); encode_absolutetime(writer1, &nu_time); measure[2].obj_handle = 1; measure[2].obs_val_data.length = 12; ByteStreamWriter *writer2 = byte_stream_writer_instance(measure[2].obs_val_data.length); write_float(writer2, nu_weight); encode_absolutetime(writer2, &nu_time); measure[3].obj_handle = 3; measure[3].obs_val_data.length = 12; ByteStreamWriter *writer3 = byte_stream_writer_instance(measure[3].obs_val_data.length); write_float(writer3, nu_bmi); encode_absolutetime(writer3, &nu_time); measure[0].obs_val_data.value = writer0->buffer; measure[1].obs_val_data.value = writer1->buffer; measure[2].obs_val_data.value = writer2->buffer; measure[3].obs_val_data.value = writer3->buffer; scan.obs_scan_fixed = scan_fixed; ByteStreamWriter *scan_writer = byte_stream_writer_instance(evt.event_info.length); encode_scanreportinfofixed(scan_writer, &scan); del_byte_stream_writer(writer0, 1); del_byte_stream_writer(writer1, 1); del_byte_stream_writer(writer2, 1); del_byte_stream_writer(writer3, 1); evt.event_info.value = scan_writer->buffer; data->message.u.roiv_cmipEventReport = evt; del_byte_stream_writer(scan_writer, 0); return data; }
void write_variables(int nvars, int *vardim, int *centering, const char * const * varname, float **vars, int npts, int ncells) { char str[1024]; int i, j, first_scalar, first_vector; int num_scalars, num_vectors; int num_field = 0; new_section(); sprintf(str, "CELL_DATA %d\n", ncells); write_string(str); first_scalar = 0; first_vector = 0; num_scalars = 0; num_vectors = 0; /* The field data is where the non-primary scalars and vectors are * stored. They must all be grouped together at the end of the point * data. So write out the primary scalars and vectors first. */ for (i = 0 ; i < nvars ; i++) { if (centering[i] == 0) { int num_to_write = 0; int should_write = 0; if (vardim[i] == 1) { if (first_scalar == 0) { should_write = 1; sprintf(str, "SCALARS %s float\n", varname[i]); write_string(str); write_string("LOOKUP_TABLE default\n"); first_scalar = 1; } else num_scalars++; } else if (vardim[i] == 3) { if (first_vector == 0) { should_write = 1; sprintf(str, "VECTORS %s float\n", varname[i]); write_string(str); first_vector = 1; } else num_vectors++; } else { printf("Only supported variable dimensions are 1 and 3.\n"); printf("Ignoring variable %s.\n", varname[i]); continue; } if (should_write) { num_to_write = ncells*vardim[i]; for (j = 0 ; j < num_to_write ; j++) { write_float(vars[i][j]); } end_line(); } } } first_scalar = 0; if (num_scalars > 0) { sprintf(str, "FIELD FieldData %d\n", num_scalars); write_string(str); for (i = 0 ; i < nvars ; i++) { int should_write = 0; if (centering[i] == 0) { if (vardim[i] == 1) { if (first_scalar == 0) { first_scalar = 1; } else { should_write = 1; sprintf(str, "%s 1 %d float\n", varname[i], ncells); write_string(str); } } } if (should_write) { int num_to_write = ncells*vardim[i]; for (j = 0 ; j < num_to_write ; j++) { write_float(vars[i][j]); } end_line(); } } } first_vector = 0; if (num_vectors > 0) { sprintf(str, "FIELD FieldData %d\n", num_vectors); write_string(str); for (i = 0 ; i < nvars ; i++) { int should_write = 0; if (centering[i] == 0) { int num_to_write = 0; if (vardim[i] == 3) { if (first_vector == 0) { first_vector = 1; } else { should_write = 1; sprintf(str, "%s 3 %d float\n", varname[i], ncells); write_string(str); } } } if (should_write) { int num_to_write = ncells*vardim[i]; for (j = 0 ; j < num_to_write ; j++) { write_float(vars[i][j]); } end_line(); } } } new_section(); sprintf(str, "POINT_DATA %d\n", npts); write_string(str); first_scalar = 0; first_vector = 0; num_scalars = 0; num_vectors = 0; /* The field data is where the non-primary scalars and vectors are * stored. They must all be grouped together at the end of the point * data. So write out the primary scalars and vectors first. */ for (i = 0 ; i < nvars ; i++) { if (centering[i] != 0) { int num_to_write = 0; int should_write = 0; if (vardim[i] == 1) { if (first_scalar == 0) { should_write = 1; sprintf(str, "SCALARS %s float\n", varname[i]); write_string(str); write_string("LOOKUP_TABLE default\n"); first_scalar = 1; } else num_scalars++; } else if (vardim[i] == 3) { if (first_vector == 0) { should_write = 1; sprintf(str, "VECTORS %s float\n", varname[i]); write_string(str); first_vector = 1; } else num_vectors++; } else { printf("Only supported variable dimensions are 1 and 3.\n"); printf("Ignoring variable %s.\n", varname[i]); continue; } if (should_write) { num_to_write = npts*vardim[i]; for (j = 0 ; j < num_to_write ; j++) { write_float(vars[i][j]); } end_line(); } } } first_scalar = 0; if (num_scalars > 0) { sprintf(str, "FIELD FieldData %d\n", num_scalars); write_string(str); for (i = 0 ; i < nvars ; i++) { int should_write = 0; if (centering[i] != 0) { if (vardim[i] == 1) { if (first_scalar == 0) { first_scalar = 1; } else { should_write = 1; sprintf(str, "%s 1 %d float\n", varname[i], npts); write_string(str); } } } if (should_write) { int num_to_write = npts*vardim[i]; for (j = 0 ; j < num_to_write ; j++) { write_float(vars[i][j]); } end_line(); } } } first_vector = 0; if (num_vectors > 0) { sprintf(str, "FIELD FieldData %d\n", num_vectors); write_string(str); for (i = 0 ; i < nvars ; i++) { int should_write = 0; if (centering[i] != 0) { int num_to_write = 0; if (vardim[i] == 3) { if (first_vector == 0) { first_vector = 1; } else { should_write = 1; sprintf(str, "%s 3 %d float\n", varname[i], npts); write_string(str); } } } if (should_write) { int num_to_write = npts*vardim[i]; for (j = 0 ; j < num_to_write ; j++) { write_float(vars[i][j]); } end_line(); } } } }
//--------------------------------------------------------------------------------------------- void BitMessage::write_vec3(const Vec3& v) { write_float(v.x); write_float(v.y); write_float(v.z); }
static void write_core(pic_state *pic, pic_value obj, pic_value port, struct writer_control *p) { pic_value labels = p->labels; int i; /* shared objects */ if (is_shared_object(pic, obj, p)) { if (pic_weak_has(pic, labels, obj)) { pic_fprintf(pic, port, "#%d#", pic_int(pic, pic_weak_ref(pic, labels, obj))); return; } i = p->cnt++; pic_fprintf(pic, port, "#%d=", i); pic_weak_set(pic, labels, obj, pic_int_value(pic, i)); } switch (pic_type(pic, obj)) { case PIC_TYPE_UNDEF: pic_fprintf(pic, port, "#undefined"); break; case PIC_TYPE_NIL: pic_fprintf(pic, port, "()"); break; case PIC_TYPE_TRUE: pic_fprintf(pic, port, "#t"); break; case PIC_TYPE_FALSE: pic_fprintf(pic, port, "#f"); break; case PIC_TYPE_ID: pic_fprintf(pic, port, "#<identifier %s>", pic_str(pic, pic_id_name(pic, obj))); break; case PIC_TYPE_EOF: pic_fprintf(pic, port, "#.(eof-object)"); break; case PIC_TYPE_INT: pic_fprintf(pic, port, "%d", pic_int(pic, obj)); break; case PIC_TYPE_SYMBOL: pic_fprintf(pic, port, "%s", pic_sym(pic, obj)); break; case PIC_TYPE_FLOAT: write_float(pic, obj, port); break; case PIC_TYPE_BLOB: write_blob(pic, obj, port); break; case PIC_TYPE_CHAR: write_char(pic, obj, port, p); break; case PIC_TYPE_STRING: write_str(pic, obj, port, p); break; case PIC_TYPE_PAIR: write_pair(pic, obj, port, p); break; case PIC_TYPE_VECTOR: write_vec(pic, obj, port, p); break; case PIC_TYPE_DICT: write_dict(pic, obj, port, p); break; default: pic_fprintf(pic, port, "#<%s %p>", pic_typename(pic, pic_type(pic, obj)), pic_obj_ptr(obj)); break; } if (p->op == OP_WRITE) { if (is_shared_object(pic, obj, p)) { pic_weak_del(pic, labels, obj); } } }
static void save(Space *s, int32_t &addr) { write_float(addr, PRIVATE(s).max_r); }
int main(int argc, char const *argv[]) { // Usage statements if (argc < 2) { usage(); return -1; } // Option handler int option = atoi(argv[1]); if (option < 1 || option > 7) { usage(); return -1; } int res = 0; float f1 = -187.33667, f2 = 0.0, f3 = 0.0; int i3 = 0; uint u3 = 0; res = read_float(&f2); if (res) return -1; switch (option) { case 1: //fadd f3 = f1 + f2; res = write_float(&f3); break; case 2: //fsub f3 = f1 - f2; res = write_float(&f3); break; case 3: //fmul f3 = f1 * f2; res = write_float(&f3); break; case 4: //fdiv f3 = f1 / f2; res = write_float(&f3); break; case 5: //fcmp f3 = (f1 < f2); res = write_float(&f3); break; case 6: //fptosi i3 = static_cast<int>(f2); res = write_int(&i3); break; case 7: //fptoui u3 = static_cast<uint>(f2); res = write_uint(&u3); break; default: //ERROR should not happen return -1; break; } if (res) return -1; return 0; }
/* * Write a grid in binary format */ int writegridbin(int gridno, char *fname) { FILE *fp; int i, itmp, *intptr; float *floatptr; char buf[1024]; if ((fp = fopen(fname, "w")) == NULL) { sprintf(buf, "In writegrid, unable to open file %s\n", fname); errwin(buf); return 0; } itmp = 4; write_int(&itmp, 1, fp); itmp = 2; /* magic number for real*4 based binary grid * files */ write_int(&itmp, 1, fp); itmp = 4; write_int(&itmp, 1, fp); write_int(&itmp, 1, fp); write_int(&grid[gridno].nmel, 1, fp); write_int(&itmp, 1, fp); write_int(&itmp, 1, fp); write_int(&grid[gridno].nmnp, 1, fp); write_int(&itmp, 1, fp); floatptr = (float *) calloc(grid[gridno].nmnp, sizeof(float)); if (floatptr == NULL) { errwin("Can't allocate memory for floatptr"); Free_grid(gridno); fclose(fp); return 0; } itmp = grid[gridno].nmnp * sizeof(float); write_int(&itmp, 1, fp); for (i = 0; i < grid[gridno].nmnp; i++) { floatptr[i] = grid[gridno].xord[i]; } write_float(floatptr, grid[gridno].nmnp, fp); write_int(&itmp, 1, fp); write_int(&itmp, 1, fp); for (i = 0; i < grid[gridno].nmnp; i++) { floatptr[i] = grid[gridno].yord[i]; } write_float(floatptr, grid[gridno].nmnp, fp); write_int(&itmp, 1, fp); write_int(&itmp, 1, fp); for (i = 0; i < grid[gridno].nmnp; i++) { floatptr[i] = grid[gridno].depth[i]; } write_float(floatptr, grid[gridno].nmnp, fp); write_int(&itmp, 1, fp); free(floatptr); intptr = (int *) calloc(grid[gridno].nmel, sizeof(int)); if (intptr == NULL) { errwin("Can't allocate memory for intptr"); Free_grid(gridno); free(floatptr); fclose(fp); return 0; } itmp = grid[gridno].nmel * sizeof(int); write_int(&itmp, 1, fp); for (i = 0; i < grid[gridno].nmel; i++) { intptr[i] = grid[gridno].icon[i].nl[0]; } write_int(intptr, grid[gridno].nmel, fp); write_int(&itmp, 1, fp); write_int(&itmp, 1, fp); for (i = 0; i < grid[gridno].nmel; i++) { intptr[i] = grid[gridno].icon[i].nl[1]; } write_int(intptr, grid[gridno].nmel, fp); write_int(&itmp, 1, fp); write_int(&itmp, 1, fp); for (i = 0; i < grid[gridno].nmel; i++) { intptr[i] = grid[gridno].icon[i].nl[2]; } write_int(intptr, grid[gridno].nmel, fp); write_int(&itmp, 1, fp); free(intptr); fclose(fp); return 1; }
static int writer_float(lua_State* L) { writer_t* writer = lua_touserdata(L, 1); write_float(writer, luaL_checknumber(L, 2)); return 0; }
void float_setting::write_to_archive(archive_writer& writer, const char* name) const { write_float(writer, name, get_current_value()); }