$fmonitorh(file_handler, conv1, conv2, conv3, conv4);
In this conv1, conv2... are my outputs and I want to write these values in text file, line by line or , between two values. While running above command I am getting values in one line only.
the format of the file output command is:
$f...(file_handler, format_string, arg1, ...);
the format_string is the one which defines output layout and uses '%' specifiers to layout your data, similar to printf in 'c'.
so, you can use something like this:
$fmonitorh(file_handler, "%x\n%x\n%x\n%x", conv1, conv2, conv3, conv4);
Related
I'm trying to write a simple header line in Intel Fortran (containing actual content commas) to an Excel csv. What I'd like to see in the first two columns is:
FMG(1,1) FMG(2,1)
Enclosing each term in quotes "FGM(i,j)" worked when I did it line by line:
Code: write (*,*) "FMG(1,1), kg/s (O2): ", FMG(1,1)
Output: FMG(1,1), kg/s (O2): 0.129000000000000
Some of the things I've tried include:
code: write (10,*) "FMG(1,1)","FMG(2,1)"
csv column output: FMG(1 1)FMG(2 1)
code: write (10,*) "FMG(1,1)" , "FMG(2,1)"
csv column output: FMG(1 1)FMG(2 1) (same thing)
code: write (10,*) " FMG(1,1)," "FMG(2,1)"
csv column output: FMG(1 1) FMG(2,1)
got the 2nd one correctly
CSV by name means Comma Separated Values. If you output "FMG(1,1),FMG(1,2)" then removing the commas, you will get
FMG(1
1)
FMG(1
2)
which is what you are seeing. To include the commas, the strings need to be enclosed in quotes. If you write
write (10,*) '"FMG(1,1)","FMG(2,1)"'
it might achieve what you are looking for.
I have a csv file which is not consistent. It looks like this where some have a middle name and some do not. I don't know the best way to fix this. The middle name will always be in the second position if it exists. But if a middle name doesn't exist the last name is in the second position.
john,doe,52,florida
jane,mary,doe,55,texas
fred,johnson,23,maine
wally,mark,david,44,florida
Let's say that you have ① wrong.csv and want to produce ② fixed.csv.
You want to read a line from ①, fix it and write the fixed line to ②, this can be done like this
with open('wrong.csv') as input, open('fixed.csv', 'w') as output:
for line in input:
line = fix(line)
output.write(line)
Now we want to define the fix function...
Each line has either 3 or 4 fields, separated by commas, so what we want to do is splitting the line using the comma as a delimiter, return the unmodified line if the number of fields is 3, otherwise join the field 0 and the field 1 (Python counts from zero...), reassemble the output line and return it to the caller.
def fix(line):
items = line.split(',') # items is a list of strings
if len(items) == 3: # the line is OK as it stands
return line
# join first and middle name
first_middle = join(' ')((items[0], items[1]))
# we want to return a "fixed" line,
# i.e., a string not a list of strings
# we have to join the new name with the remaining info
return ','.join([first_second]+items[2:])
Can some one let me know how to modify the follow text
My sample data looks like this
INPUT file data
P100
11,1
91,1
12,1
215,1
215,1
P101
1,2
8,2
18,2
99,2
00,2
20,2
I want to put comma when ever the line dose not have a comma
So my output for the following file should look like
,P100
11,1
91,1
12,1
215,1
215,1
,P101
1,2
8,2
18,2
99,2
00,2
20,2
You can match lines that don't contain , and then prepend it:
sed '/,/!s/^/,/' infile > outfile
The ! operator means to apply the following operation to lines that don't match the regular expression.
After executing code, I received an error:
load('firstdiff.mat')
xlswrite('test.xlsx', firstdiff)
mat file consist only numeric values (0 and 1)
Undefined function or variable 'firstdiff'
Using load without output arguments is something which often confuses programmers. I recommend to use it with an output argument:
data=load('firstdiff.mat')
This way you get a struct containing the data of your mat file. A typical next step would be using fieldnames(data) to check which variables are present or if you already know, index a variable with an expression like data.x
In this case I assume you only have one variable in your matfile.
data=load('firstdiff.mat');
fn=fieldnames(data); %get all variable names
assert(numel(fn)==1); %assert there is only one variable in your mat, otherwise raise error
firstdiff=data.(fn{1}); %get the first variable
xlswrite('test.xlsx', firstdiff); %write it
I have the need in Lua to read a specific line in a text file I select, I know how to open it:
filename = "hallo.txt"
fp = io.open( filename, "r" )
but I don't know how to read a specific line in that specific text file.
How do you though?
If you have to do it several times, then read the whole file into memory, storing the lines in a table.
If you only have to do this once, try something like this:
local n=0
for l in io.lines(filename) do
n=n+1
if n==lineno then process(l); break end
end