Convert gds file into text format using gds2text script - python-2.7

How I can to read any gdsii file in python,or Convert gds file into text format using gds2text script?

If you can use a C/C++ compiler you might consider using gds2gdt and gdt2gds to read and/or write GDSII using any language/shell of your choice. GDSII is a stream of records each of which is represented in a single line of compact GDT format text. For instance:
p{10 w1.2 xy(41.2 17.1 41.2 33.9)}
is a two-point path on layer 10 with a width of 1.2. you can run these programs externally or call them within your program similar to reading/writing a text file.
https://sourceforge.net/projects/gds2/

Related

I have a problem to read processor id from txt file in fortran

I'm trying to create a Fortran code for defining processor id. I can write the processor id into a text file. The text file pid2.txt is created but I can not read it in Fortran. While I open the text file in notepad or NotePad++ everything seems OK! In Fortran when I opening the text file it shows unknown parameter. Can any body help me with this problem?
The content of text file is
ProcessorId
BFEBFBFF00010676
The sample code is as below:
program get_PID
implicit none
character(200) :: line
call system('wmic cpu get ProcessorId >pid2.txt ' )
open (1,file='pid2.txt')
read (1,*) line
read (1,*) line
CLOSE (1)
end program
Do you have any advice?
The issue in your case is the encoding of the ouput from wmic. Windows uses UTF-16 as default. Fortran cannot handle this encoding yet. Referring to the help of Intel Fortran, only UTF-8 is supported as described here.
Therefore you have to change the encoding of the output to ANSI and/or your local codepage. This can be done by piping the result of wmic through the more command as described on SO superuser site under combine-batch-wmic-ansi-unicode-output-formatting.
Please change your system call as follows:
call system('wmic cpu get ProcessorId | more >pid2.txt ' )
You'll get the processor ID information in your code now, as expected.
Hope it helps.

Error while downloading to memory using curl

I want to download a file to memory using curl.
I am currently using this and it looks like it works to a certain extent but corrupts my file.
I have used sigbench and it is around 20% different (while comparing original and downloaded)
The file I want to download is a binary so it won't work after it's modified.
I am currently testing with the x86 version of this.
original binary
downloaded binary
This is the code I am using to write it to a file:
ofstream stream = ofstream("test.dll");
stream.write(chunk.memory, chunk.size);
Opening the file like this:
ofstream stream = ofstream("test.dll");
will cause line-end characters to be adjusted to match your target system.
You should instead open the file in binary mode:
ofstream stream = ofstream("test.dll", std::ios::binary);
This will leave the characters that could be interpreted as line-endings unchanged.
Further reading: https://en.cppreference.com/w/cpp/io/c#Binary_and_text_modes

How to create an uncleared file?

I am a beginner C++ programmer.
I want to create a binary file, that is uncleared with the previous information that was in it. This is easy to do with RAM, simply by making an array, but how do I do this on a hard drive?
How do I create a uncleared file?
In other words how do I retrieve data that was not "cleared" but just marked "empty".
However, if the OS does not allow it, can I launch linux from USB and run my software?
To keep the content of a file to be written on, you can open a file in append mode with:
[ofstream ofs ("filename", ios::binary | ios::app);][1]
All output operations append at the end of the file. Alternatively, you could also use ios::ate so that the output position starts at the end of the file (but afterwards it's up to you).
With the usual read operations you can retrieve preexisting content, by first positionning yourself using seekp().

C++ ofstream, printing without CRLF

I have a C++ code I am running in Linux with wine. I think this is actually part of the problem.
Usually, when I do something like this in a native Linux C++ program:
ofstream fout;
fout.open("myfile.txt")
fout<<"blah blah"<<endl;
fout<<"blah blah 2"<<endl;
fout.close;
The file is standard ASCII text. However, in the code I an running under wine, myfile.txt is now ASCII text with CRLF line terminators.
This is a problem because if I want to read the file using a native Linux C++ code running on the same machine, the CRLF line terminators really mess up a lot of the file handling and parsing.
Is there a way to get the code running under wine to output files without CRLF line terminators and in a fashion that I can read it using the native Linux C++ code on the same machine?
You could open the file in ios::binary mode. This doesn't, strictly speaking, mean that it's a binary file [any more than any other file is "text", since all files are binary]. Binary in this context just means "don't muck about with the stuff inside the file by interpreting characters as special, add or remove any characters, etc.
Or when you copy the file to Linux, use dos2unix myfile.txt to convert it from "dos" (and Windows) format to "unix" style text file.

Reading the content of file other than ".txt" file

How can i read content of a file which is not a simple text file in c/c++? For example, I want to read image file such as .jpg/.png/.bmp and see the value at certain index,to check what colour it is? or if I have a .exe/.rar/.zip and want to know what value is stored at different indices?
I am aware of c style reading file, which is
FILE *fp;
fp = fopen("example.txt","r"); /* open for reading */
char c;
c = getc(fp) ;
I want to know if i replace "example.txt" with "image.png" or so, will it works? will i get correct data?
When you open a non-text file, you'll want to specify binary (untranslated) mode:
FILE *fp = fopen("example.png", "rb");
In a typical case, you do most of your reading from binary files by defining structs that mirror the structures in the file, and then using fread to read from the file into the structure (but this has to be done carefully, to ensure that things like padding in the struct don't differ between the representation in-memory and on-disk).
You would need to open the file in binary mode. This allows you to read the bytes in a "raw" mode where they are unchanged from what was in the file.
However, determining the color of a particular pixel, etc. requires that you fully understand the meaning of the bytes in the file and how they are arranged for the file being read. This second requirement is much more difficult. You'll need to do some research on the format of that file type in order to do that.
yea ofcorse you can open any file in binary mode in c. if you are interested then you can also read some 1st byte of any such non text file.
In most of the cases all different file-format has some fixed header so based on that you can identify the type of that file.
Open any matroska(.mkv) file and read 1st 4 byte you will always have this
0x1A 0x45 0xDF 0xA3
you can also see any file in binary representation hexdump utility in linux
====================
Edit:
such as .jpg/.png/.bmp and see the value at certain index,to
check what colour it is?
here you need to understand the format of that file and based on that you can know on which place's data what information is indicating..!!!