Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an input file to read values from and one such value is 1d10.
How to make sense of that value?
The input file is below and its for LU factorization:
8000 8000 8000 1d10 120 120 8
The variables above are:
min_n max_n stepsize total_flops_in_timing_block blower bupper bstride
Assuming all of those values are integers except for the flops variable, this example code will work. Also note this depends on the fixed width of your input file and the values being separated by a single space. If you have more general needs this will need tweaking to work.
program test
implicit none
integer :: n_min, n_max, n_step, b_low, b_high, b_stride
integer :: ufile
real(kind=kind(1d0)) :: flops
open(newunit=ufile, file="input2.txt", access="sequential")
read(ufile,*) n_min, n_max, n_step, flops, b_low, b_high, b_stride
close(ufile)
print *, "min_n = ", n_min
print *, "max_n = ", n_max
print *, "stepsize = ", n_step
print *, "flops = ", flops
print *, "blower = ",b_low
print *, "bupper = ", b_high
print *, "bstride = ", b_stride
end program test
Given the input file:
8000 8000 8000 1d10 120 120 8
produces this output:
% ./read_input
min_n = 8000
max_n = 8000
stepsize = 8000
flops = 10000000000.000000
blower = 120
bupper = 120
bstride = 8
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I am having some difficulty writing an awk/sed code for finding the distances between every row and the last row systematically. To be more specific, suppose I have a file f1 as follows.
1 2 3
4 5 6
7 8 9
.
.
.
51 52 53
30 31 32
where the first column is the x coordinate, second column is the y coordinate, and third column is the z coordinate. How do I create a file containing the distances between the first row and the last row (i.e. distance between (1,2,3) and (30,31,32)), second row and last row, third row and last row, and so on, until the penultimate row and last row. If f1 has n rows, then the file (let's call it f2) would therefore have n-1 rows.
I have been stuck on this for a long time, but any help would be much appreciated. Thanks!
Use tac to get last line first:
$ tac file | awk '(NR == 1){ x=$1; y=$2; z=$3; next } {
print sqrt((x-$1)^2 + (y-$2)^2 + (z-$3)^2)
}' | tac
50.2295
45.0333
39.8372
36.3731
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How can I get blocks from a string ( NSString ) and copy then to a array?
int BlockSize = 3
char array[3];
NSString *ns = #"ABCDEFGHI";
What I want to do is get the the first 3 elements and put on array[0] , the next 3 elements and put then on array[1] , the next 3 on array[2]
Thanks
to get character from string you can use below code:
NSString *ns = #"ABCDEFGHI";
arr[0]= [ns characterAtIndex:0];
NSLog(#"%c",arr[0]);
arr[1]= [ns characterAtIndex:1];
NSLog(#"%c",arr[1]);
Or even you go through forloop to iterate to complete string length
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have learned about shift left and shift right registers in bitwise operators. But i am confused with below code.
RX_DR shifted ? what does that mean ? this is just random example i just need to know meaning of it.
nrf24_configRegister(STATUS,(1<<RX_DR)|(1<<TX_DS)|(1<<MAX_RT));
Please help.
It looks like these constants are the bit numbers of various flags in a register. Looking at nRF24L01.h leads me to believe their values are:
#define RX_DR 6
#define TX_DS 5
#define MAX_RT 4
This corresponds to a bit layout like:
TX_DS
v
(bit #) 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
^ ^
(flag) RX_DR MAX_RT
Here I've labeled a few of the bits in an 8-bit register. Bit 6 is the RX_DR flag, bit 5 is the TX_DS flag, and bit 4 is the MAX_RT flag.
(1<<RX_DR)|(1<<TX_DS)|(1<<MAX_RT)
This bit of code constructs a register value where those three bits are set and the rest are unset. How does it do that? Consider 1<<TX_DS. This takes the value 1 (binary 00000001) and shifts it left 5 places, yielding 32 (binary 00100000).
That value is bitwise ORed (|) with the other two flags. ORing numbers together combines their 1 bits, yielding a value where all of the 1 bits from each operand are set.
1<<RX_DR == 1<<6 == 01000000 in binary
1<<TX_DS == 1<<5 == 00100000 in binary
1<<MAX_RT == 1<<4 == 00010000 in binary
ORing 1<<RX_DR and 1<<TX_DS and 1<<MAX_RT together gives the value 112, or in binary:
01110000
See how that binary value has bits 6, 5, and 4 set?
I have a similiar problem like this question:
selecting every Nth column in using SQLDF or read.csv.sql
I want to read some columns of large files (table of 150rows, >500,000 columns, space separated, filled with numeric data and only a 32 bit system available). This file has no header, therefore the code in the thread above didn't work and I decided to write a new post.
Do you have an idea to solve this problem?
I thought about something like that, but any results with fread or read.table are also ok:
MyConnection <- file("path/file.txt")
df<-sqldf("select column 1 100 1000 235612 from MyConnection",file.format = list(header=F,sep=" "))
You can use substr to specify the start and end position of the columns you want to read in if they are fixed width:
x <- tempfile()
cat("12345", "67890", "09876", "54321", sep = "\n", file = x)
myfile <- file(x)
sqldf("select substr(V1, 1, 1) var1, substr(V1, 3, 5) var2 from myfile")
# var1 var2
# 1 1 345
# 2 6 890
# 3 9 76
# 4 5 321
See this blog post for some more examples. The "select" statement can easily be constructed with paste if you know the details about the column starting positions and widths.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I want to get the line numbers where the implementation of objective c method start.
1 #include "foobar.h"
2 -(void)Foo{
3 ...
4 }
5
6 +(NSInteger *)bar{
7 ...
8 }
The output should be: 2,6
How can i achieve it with libclang.
I do not want to use a regex for that, because it will be sufficient.
Solution:
CXSourceRange range = clang_getCursorExtent(cursor);
CXSourceLocation startLocation = clang_getRangeStart(range);
CXSourceLocation endLocation = clang_getRangeEnd(range);
CXFile file;
unsigned int line, column, offset;
clang_getInstantiationLocation(startLocation, &file, &line, &column, &offset);
enum CXCursorKind curKind = clang_getCursorKind(cursor);
CXString curKindName = clang_getCursorKindSpelling(curKind);
const char *funcDecl="ObjCInstanceMethodDecl";
if(strcmp(clang_getCString(curKindName),funcDecl)==0){
printf("%u",line);
}