Format of marks in viminfo - vim

I'm trying to find information on how file marks are stored in the 'viminfo' file. For example, here is an entry I have:
'0 3 11 ~/.vim/hello
|4,48,3,11,1592944829,"~/.vim/hello"
The only obvious things from the above seem to be the filepath the mark is saved, ~/.vim/hello and the timestamp it was created 1592944829. What are the other items, and why are some of the items listed multiple times (3, 11, filename).

you are reading the wrong block.
In the viminfo file, search for the lines beginning with >, they are mark histories.
And there is usually comment in the file.
For example:
# History of marks within files (newest to oldest):
> /tmp/test/whatevertestfile.txt
* 1592998167 0
" 4 0
^ 1 0
. 1 0
+ 1 0
a 4 0
b 9 0
update
Oh, I just noticed you mentioned file marks in the question. Then you are looking at the right block.
The positions in the two lines are always the same because the write_one_filemark() function reads the same values for the two lines.
The first 4 is an index in the viminfo file, it indicates the mark type.
The 48 is the ascii code of the numbered mark 0 .
Then come the position + ts + filename
If you want to know more detailed, why it is so defined and so on, you can read the related part of this file
https://github.com/vim/vim/blob/master/src/viminfo.c

Related

Easytrieve - Removing leading zero in numeric variable

Using Easytrieve program am trying to fetch the details from DB2. But one off the column is having integer datatype and am moving the data to binary variable.
And I need to perform arithmetic operation in this variable and result will be move to output file.
When i try to move binary value to alpha numeric am getting leading zero.
Not sure how to remove those leading value.
For example :
DB2 column name (Period_value) = 240
Easytrieve :
FILE TEMP1
TEMP-PERIOD 1 5 A
WS-VAL1 W 4 B 0
WS-TEMP W 4 N
....
....
using cursor to get the value from Db2
WS-VAL1 is holding the value 240
DISPLAY WS-VAL1 => OUTPUT : 240
* CALCULATION
WS-VAL1 = WS-VAL1 + 1
WS-TEMP = WS-VAL1
DISPLAY WS-TEMP -> OUTPUT : 0241
MOVE WS-TEMP to TEMP-PERIOD
PUT TEMP1
But output file contains
0241
Expected output
241
242 (without leading zero)
Could someone help me on this.

How are input lines defined for I/0 statements?

I want to read some values from a file called Input.txt. The input file looks like this:
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
....
in total its 36 lines of 1,2,3 and 4s
then I use the following code to read from the file:
program outputtest
implicit none
double precision, allocatable, dimension(:) :: A,B,C,D
integer :: counter,ii, ierror
ierror=0
counter=1
open(39, action='read', name='input.txt', status='old')
do
read(39,100, IOSTAT=Ierror)
100 Format(T8,I1)
If (Ierror>0) then
print *, 'error when reading'
stop
end if
If (ierror<0) then
print*, 'end of file reached'
exit
end if
counter=counter+1
end do
If (.not.allocated(A)) ALLocate(A(counter))
If (.not.allocated(b)) ALLocate(b(counter))
If (.not.allocated(c)) ALLocate(c(counter))
If (.not.allocated(d)) ALLocate(d(counter))
do ii=1, counter-1
read(39,110, IOSTAT=ierror) A(ii), B(ii), C(ii), D(ii)
110 Format(T8, I4, T16, I4, T24, I4, T32, I4)
If (ierror.neqv.0) exit
end do
close(39)
write (*,120) A
write (*,120) B
write (*,120) C
write (*,120) D
120 Format('result:', 1x,I2)
end program outputtest
The problem is now that the A,B,C,D are all equal to zero, i.e. my output is:
result: 0
result: 0
result: 0
....
This means that I do not read either from the correct lines or I make another mistake. I used in vim the option ruler to see what lines those entries are in and used those lines together with T. I created the file Input.txt by using tabs. What is my mistake?
A two things:
You don't do a rewind in your file. At first you read through the whole file to get the number of lines, but without a rewind, you start reading at the end -- which means nothing gets actually read into the arrays.
read with explicit formats is dangerous. You have to be really certain that the input file matches the format precisely. In your case, I'd to as #high-performance-mark suggested and use fmt=*. Your input file should easily be read automatically.
That's what I can gleam from a quick browse. See if that helps.

Gnuplot: operations with data in different blocks

I have a data file consisting of two blocks (separated by a single blank line) and would like to plot the difference between data from block 1 and block 2, i.e., something like
plot 'a.dat' using 1:($2_1-$2_2)
where $2_1 is supposed to mean "data from block 1, col.2" and $2_2 "data from block 2, col.2". Is that possible within Gnuplot, and if so, how?
Thanks,
Tom
This task is most likely not possible directly in Gnuplot, however, one can preprocess the data file first, using, e.g., gawk and then plot the modified file. For example:
dataFile="a.dat"
plotCmd(fname)=sprintf("<gawk '\
BEGIN{mode=0;l=0;} \
mode==0{if(NF==0){mode=1;}else{x[NR]=$1;y[NR]=$2;}} \
mode==1{if(NF>0){mode=2;l=NR;}} \
mode==2{print $1,y[NR-l+1],$2}' %s", fname)
plot plotCmd(dataFile) u 1:($2-$3) w l
The gawk script reads the file and saves the first and second column into arrays x and y until it reaches a blank line (zero number of fields). Then it skips all consecutive blank lines until it reaches a non-empty line (NF>0). It remembers the position of this line in the input file and then outputs for each line in the second block the x-coordinate together with the corresponding y-coordinate from the first block, i.e., a data file such as
1 2
2 4
3 6
1 4
2 8
3 12
would be transformed into
1 2 4
2 4 8
3 6 12
This assumes that the x-coordinates in both blocks match...

Remove whitespace padding in matlab fprintf file output

I have large matrices of data that look something like this:
DataOut' = [34 1 0.0 -4.75343000000000 0.0291776000000000 5.32835000000000 1.23598000000000 0.890008000000000;
7 1 0.0902364000000000 -4.74065000000000 0.0 1.97133000000000 9.49706000000000 16.1658000000000]
The first two columns are IDs and always integers and the remaining 6 columns are 2 pairs of (X,Y,Z) coordinates (Floats) for each respective ID.
I'm writing the data to a file using the following syntax:
fprintf(' %u %u %-6.12g %-6.12g %-6.12g %-6.12g %-6.12g %-6.12g \r\n', DataOut)
>> 34 1 0 -4.75343 0.0291776 5.32835 1.23598 0.890008
7 1 0.0902364 -4.74065 0 1.97133 9.49706 16.1658
This format is fine in almost all cases except the one highlighted above, where the insignificant trailing zeros are replaced with spaces, leading to a big gap between some columns instead of the single space. The software reading this data really doesn't like all theses spaces and breaks when it finds more than the expected one.
My desired output is to only have a single space between each column:
>> 34 1 0 -4.75343 0.0291776 5.32835 1.23598 0.890008
7 1 0.0902364 -4.74065 0 1.97133 9.49706 16.1658
Does anyone know how to get fprintf do just leave one space after removing the insignificant trailing zeros? Using fprintf is nice because I don't need any loops and when you have several thousand of these matrices to be written out I guess that would be quite slow if I had to do some checking in a loop?
The format spec that you have used for floating point numbers (%-6.12g) species that you want to remove trailing zeros that are non-significant (with a maximum of 12 numbers after the decimal). However, the -6 specifies that you want each field to be at least 6 characters wide. In the case of your 0, it has a width of 1 so fprintf will pad it to be 6 characters wide (hence all the whitespace). If you simply remove the -6 from the beginning of each of your format specifiers you will get the output you desire.
fprintf(' %u %u %.12g %.12g %.12g %.12g %.12g %.12g \r\n', DataOut)
% 34 7 1 1 0 0.0902364 -4.75343 -4.74065
% 2.917760e-02 0 5.32835 1.97133 1.23598 9.49706 0.890008 16.1658

is it possible to index character strings pulled from an external .txt file?

I'm in a basic MATLAB college course, and need some help with my code.
theres an external .txt file with names in it, with corresponding numbers assigned to each name. my goal is to place all the first names, last names, and numbers into arrays, find the lowest number in the 'number' array, get the corresponding indexer number, and print the first and last name related with that number.
the text file reads 25 different names and numbers
(i.e.:
Bob
Smith
17
Jane
Doe
23
Bill
Johnson
13
...etc...)
here is my general code so far:
1 clear
2
3 clc
4
5
6 fid1=fopen('facedata.txt','rt');
7
8 for index = 1:1:25
9 firstn(index) = fgetl(fid1);
10 lastn(index) = fgetl(fid1);
11 number(index) = fscanf(fid1,'%f');
12 end
13
14 [distmin,I] = min(dist);
15 fprintf('%5.4f %10s %10.0f', distmin, firstn(I), I);
My hope is for the code to run through, get matlab to recognize '13' as the lowest number, and print 'bill johnson' to the screen, but if I run the code, matlab says there are errors
Subscripted assignment dimension mismatch.' # line 9.
and
Index exceeds matrix dimensions.' # the firstn**(I)** in line 15.
any ideas?? i know this is crazy long, but any help would be appreciated! :]
The command fgetl means read a line from the text file. Therefore your code is reading 2x25 = 50 lines of text. How do you know that your file has this many lines in it? You should read a new line, process it, and repeat until you reach the end of the file:
fid = fopen('fgetl.m');
tline = fgetl(fid);
while ischar(tline)
disp(tline)
tline = fgetl(fid);
end
fclose(fid);
However, this would not do what you want. You should rather use fscanf to read data in the format you want. You want to read two consecutive strings (first name, last name) and an integer number. So you can use
A = fscanf(fid, '%s %s %d', [3 inf]);
to read three items at a time and repeat until the end of the file.
I answered my own question earlier today, but here's what I found if anyone is interested:
you have to index a line of string by using curly brackets instead of straight ones.
i.e.:
for index = 1:1:25
firstname{index} = fgetl(fid1);
end
fprintf('%10s', firstn{index});
fprintf will print whichever number index is supplied.
thanks anyway kavka :]

Resources