I have a .bin file on my hard drive.
It's recl is nx*ny*4. Its dimensions are (241,121). 241 in x dimension. 121 in y dimension.
How would I convert it using fortran to an ascii file that I can open and read numbers off of?
So, far I have tried
real :: g1(241,121)
open(unit=1,file=gaugemax2010.bin',status='old',
form='unformatted',access='direct',recl=nx*ny*4)
open(unit=5,file='g2010.txt',status='unknown',
form='unformatted',access='direct',recl=1)
read(1, rec=1) ((g1(i,j,),i=1,nx,j=1,ny)
write(5, rec=1) (g1(i,j,),i=1,241),h=1,121)
end
and it has not worked
FORM='UNFORMATTED' opens a file for binary content. For pure text you have to specify FORM='FORMATTED'.
For more details on the OPEN statement see here: Opening Binary Files in Fortran: Status, Form, Access
Related
Hi I have a question for Matlab programming, I want to ask if I am using Mac OS and I have placed all my audio files in the same folder as Matlab, how do I read all the .wav audio files? I want to automate the process.
Example:
Firstly, I have an excel sheet with the audio file name and information.
Secondly, I want to extract the audio file names from the excel sheet (first column) and put it into the audioread function in MatLab.
I need to use the following audioread function.
[y,Fs]=audioread('audio1.wav');
I want to read audio1.wav and do some calculations on it. After finishing the calculation, I will proceed to read audio2.wav and do the same calculation for it. Can you teach me how to do this and show me the code for this?
Thank you.
In Matlab you can read xls files with readmatrix. You are maybe best to export your spreadsheet of audio files to a csv file first.
With regard to organising the data, it would be easiest for the spreadsheet to contain the full pathname to the file (i.e. /path/from/root/to/file.wav)
So, say you had a audio_files.csv of file paths like
/path/to/file1.wav, file1data
/path/to/file2.wav, file2data
/path/to/file3.wav, file3data
You could read each file with something like
filename = 'audio_files.csv';
audio_file_list = readmatrix(filename);
for audio_file = audio_file_list(:,1) % so long as the first column is the file paths
[y,Fs]=audioread(audio_file);
% do something to y
end
Of course, the % do something to y will depend entirely on what you want to achieve.
I am upgrading some code from python 2 to python 3.
There is a function to open and read files. In Python 2 there is no need to specify binary mode or as a string. While in Python 3 I should specify the mode.
The python 2 code is:
with open(f_path, mode=open_mode) as fp:
content = fp.read()
This is causing me problems as it is called by various other functions where I don't necessarily know the file type in advance. (Sometimes the data is written to a zip file, other times the data is returned via an HTTP endpoint).
I expect most data will be binary image files, though CSv and text files will also be present.
What would be the best way of opening a file of unknown type and detecting if it is binary or string data?
Is it possible for example to open a file in binary mode, then detect that it contains text and convert it (or alternatively generate an exception and open it in string mode instead)?
You might try the binaryornot library.
pip install binaryornot
Then in the code:
from binaryornot.check import is_binary
is_binary(f_path)
Here is their documentation:
https://pypi.org/project/binaryornot/
I was looping some files to copy the content of somes file to a new file but after I run the code, the result shows lot of symbols in the new file, not the text content of the files I looped.
first, when I ran the code without putting the 'encoding' attribute in open file line, it showed an error message like,
UnicodeEncodeError: 'charmap' codec can't encode character '\x8b' in position 12: character maps to .
I tried various encodings like utf-8,latin1 but nothing worked and when i put 'errors=ignore' in the open file line, then the result showed like I described above.
import os
import glob
folder = os.path.join('R:', os.sep, 'Files')
def notes():
for doc in glob.glob(folder + r'\*'):
if doc.endswith('.pdf'):
with open(doc,'r') as f:
x = f.readlines()
with open('doc1.text', 'w+') as f1:
for line in x:
f1.write(line)
notes()
If I understand your example correctly and you’re trying to read PDF files, your problem is not one of encoding but of file format. PDF files don’t just to store your text in coding materials are unique format that you need to be able to read in order to extract the text. There are a couple of python libraries that can read PDF files (such as Py2PDF), please refer to this thread for more information: How to extract text from a PDF file?
I'm trying to build a suffix tree from a .docx file.
So first I unzipped the .docx file and then again created a .docx file with out compressing it. I used ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetLevel(0) method. Here I used C#.
This uncompressed .docx files can be opened without any error.
For the next step I used vc++. By using ifstream.open ("uncompressed.docx", ios::binary ); method I tried to open the file and store the content in a char array by using ifstream.read ( (char *)T, MAX_LENGTH - 1 ) method. But I could not get the actual content of uncompressed.docx file. When I tried to print the content of the char array(T) it printed some formatting tags rather than printing the actual text content of the uncompressed.docx.
I could not figure out what is the actual file that ifstream.open() method opens.It is not the document.xml file.
Please tell me how to get the actual text content from the uncompressed.docx file using VC++.
I am using automation to download a .dat file and parse it using excel parser module in perl.
But whenever i tried to access the .dat file it says not a valid excel file. (all these operation has been done in linux)
As a work around I have moved the .dat file to windows machine and opened it using excel file.
Then saved the .dat file as an excel file in windows. Then resend that file to Linux machine. Now the perl script can parse the file.
Instead of this long path can I convert the .dat file to excel file in linux itself?
If yes then how?
First Few Lines from my .dat file :
F_NF_CD ART_GRP_NO ART_GRP_DESCR ART_GRP_SUB_NO ART_GRP_SUB_DESCR ART_NO ART_DESC SELL_UNIT PACK_TYPE SELL_PR VAT_PERC MRP_PRICE STOCK ART_STATUS EXTRA_INFO BLOCK_IND
F 191 HYGIENE PAPERS 3 LADIE'S HYGIENE 287432 SOFY SIDE WALLS LARGE SOFT15P 1 EA 89.8 5 99 47 1 SELL
F 191 HYGIENE PAPERS 3 LADIE'S HYGIENE 287422 SOFY SIDE WALLS REGULAR SOFT15P 1 EA 80.73 5 89 0 1 SELL
Actually the script tries to read the meta data of a file before parsing it. If the module see the metadata is not excel it won't proceed further. So it is important to change the metadata of the .dat file to .xls. Which i dont think possible without proper conversion tool.