binaryfiles

How to write .bin file in R and open it in Fortran

谁说我不能喝 提交于 2019-12-11 02:23:59
问题 I have a Fortran model that I would like to force with data coming from a model developed in R, but I have trouble transferring the data between the two environments. I was thinking about using a .bin file. What I am doing in R is using writeBin to store a multi-dim array in a .bin file: a = seq(1,150,1) my.array <- array(a, dim=c(10,5,3)) zz <- file("test.bin", "wb") writeBin (as.vector(my.array),zz) close(zz) I can read the .bin file in R without problem again... zz <- file("test.bin", "rb"

How to add/remove x86 instruction in linux executables without spoiling the alignment

徘徊边缘 提交于 2019-12-11 01:25:37
问题 I'm new to binary and assembly, and I'm curious about how to directly edit binary executables. I tried to remove an instruction from a binary file (according to disassembled instructions provided by objdump ), but after doing that the "executable" seems no longer in an executable format (segmentation fault when running; gdb cannot recognize). I heard that this is due to instruction alignment issue. (Is it?) So, is it possible to add/remove single x86 instructions directly in linux executables

PySpark: Partitioning while reading a binary file using binaryFiles() function

醉酒当歌 提交于 2019-12-11 00:57:06
问题 sc = SparkContext("Local") rdd = sc.binaryFiles(Path to the binary file , minPartitions = 5).partitionBy(8) or sc = SparkContext("Local") rdd = sc.binaryFiles(Path to the binary file , minPartitions = 5).repartition(8) Using either of the above codes, I am trying to make 8 partitions in my RDD {wherein, I want the data to be distributed evenly on all the partitions} . When I am printing {rdd.getNumPartitions()} , the number of partitions shown are 8 only, but on Spark UI , I have observed

Idiomatic C# deserialization of custom binary files?

那年仲夏 提交于 2019-12-11 00:55:05
问题 Greetings, What is the most idiomatic way of performing serialization/deserialization of binary custom formats? For example, how would you read a file with a set of headers specified in bytes (e.g. 4, 4, 16, 4, 8, 8, 4, 16) with no padding, with mixed integer/ byte[] types? In other words, how do you achieve the same level of control as in C when specifying a structure, without having to resort to sequences of Read/WriteBytes over a Stream? Thanks. 回答1: Here's an article which illustrates one

What does SEGMENT_START(“text-segment”, 0x400000) represent?

丶灬走出姿态 提交于 2019-12-10 20:18:56
问题 I'm learning about the layout of executable binaries. My end goal is to analyze a specific executable for things that could be refactored (in its source) to reduce the compiled output size. I've been using https://www.embeddedrelated.com/showarticle/900.php and https://www.geeksforgeeks.org/memory-layout-of-c-program/ as references for this initial learning. From what I've learned, a linker script specifies the addresses where sections of compiled binaries are placed. E.g. > ld --verbose |

Reading strings from unformatted files (variable record length)

假如想象 提交于 2019-12-10 18:32:15
问题 I have an unformatted Fortran file, containing strings of different lengths, and I'm having trouble reading these strings with Fortran itself. Sample program: program test implicit none character(len=200) :: line open(32,file="testfile",form="unformatted",action="write") write(32) "A test string" write(32) "Another longer test string" close(32) open(33,file="testfile",form="unformatted",action="read") read(33) line write(6,*) trim(line) read(33) line write(6,*) trim(line) close(33) end

C++ Storing a dynamic_bitset into a file

这一生的挚爱 提交于 2019-12-10 17:49:22
问题 Sort of a follow up to How does one store a vector<bool> or a bitset into a file, but bit-wise? Basically I am writing a bitset as a binary file with the follow code: boost::dynamic_bitset<boost::dynamic_bitset<>::block_type> filter; vector<boost::dynamic_bitset<>::block_type> filterBlocks(filter.num_blocks()); //populate vector blocks boost::to_block_range(filter, filterBlocks.begin()); ofstream myFile(filterFilePath.c_str(), ios::out | ios::binary); //write out each block for (vector<boost:

C++ - serialize double to binary file in little endian

流过昼夜 提交于 2019-12-10 17:46:39
问题 I'm trying to implement a function that writes double to binary file in little endian byte order. So far I have class BinaryWriter implementation: void BinaryWriter::open_file_stream( const String& path ) { // open output stream m_fstream.open( path.c_str(), std::ios_base::out | std::ios_base::binary); m_fstream.imbue(std::locale::classic()); } void BinaryWriter::write( int v ) { char data[4]; data[0] = static_cast<char>(v & 0xFF); data[1] = static_cast<char>((v >> 8) & 0xFF); data[2] =

Django 1.7: serve a pdf -file (UnicodeDecodeError)

倖福魔咒の 提交于 2019-12-10 15:58:05
问题 I'm trying to serve a PDF file with django 1.7, and this is basically the code that "should" work... it certainly works if I change the content_type to 'text' and download a .tex file with it, but when I try it with a binary file, I get "UnicodeDecodeError at /path/to/file/filename.pdf 'utf-8' codec can't decode byte 0xd0 in position 10: invalid continuation byte" def download(request, file_name): file = open('path/to/file/{}'.format(file_name), 'r') response = HttpResponse(file, content_type

Library for Manipulating S-Record and Intel HEX 16 Files

▼魔方 西西 提交于 2019-12-10 15:48:11
问题 Is there an available open source library, developed in python or java, for manipulating Motorola S-Record files and Intel HEX 16 files (e.g. converting from one format to the other)? I am looking for a 'pure' java or python library, not simply a set of java or python bindings to a library like SRecord. 回答1: http://www.bialix.com/intelhex/ for intel hex, I'm not aware of srec python implementations 回答2: For Python you can use bincopy. It isn't nearly as feature rich as SRecord, but it is