julia: Change printed function output - output

In julia when a function is called it automatically prints the output to the console i.e.
julia> [1:10]+5
10-element Array{Int64,1}:
6
7
8
9
10
11
12
13
14
15
I'm using Gadfly's plotting functions, which creates a plot. The output looks atrocious though. I don't want to completely suppress the output though (I think that can be done using the ;). I want to retain the summary portion (in the above example 10-element Array{Int64,1})
How can I do that?

If I'm understanding you correctly, the simple solution is to define a show method for Gadfly's plots:
Base.show(io::IO,p::Gadfly.Plot) = print(io, summary(p))
You can make it more complicated to show more information about p if you wish. In most cases, though, I think Gadfly should actually generate an image of the plot and show it to you (through the richer display mechanism).

Related

how to convert/match a handwritten list of names? (HWR)

I would like to see if I can scan a sign-in sheet for a class. The good news is I know 90% of the names that might be written.
My idea was to use tessaract to parse an image of names, and then use the Levenshtein algorithm to compare each line with a list of names in my database and if I get reasonably close matches, then that name is right.
Does this approach sound like a good one? If not, other ideas?
I tried using tesseract on a sample sheet (see below)
I used:
tesseract simple.png -psm 4 outtxt
Tesseract Open Source OCR Engine v3.05.01 with Leptonica
Warning. Invalid resolution 0 dpi. Using 70 instead.
Error in boxClipToRectangle: box outside rectangle
Error in pixScanForForeground: invalid box
I am assuming it didn't like line 2 because I went below the line.
The results I got were:
1.. AM: (harm;
l. ’E (J 22 a 00k
2‘ wau \\) [HQ
4. KIM TAYLOE
5. LN] Davis
6‘ Mzflé! Ha K
Obviously not the greatest, my guess is the distance matches for 4 & 5 would work, but the rest are not even close.
I have control of my sign-in sheet, but not the handwriting of folks coming in, so if any changes to that I can do to help, please let me know.
Since your goal is to get names only - I would suggest you to reduce tessedit_char_whitelist to english alphabetical ones("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.") so that you will not get characters that you don't expect as output like \\) [ .
Your initial approach to calculate L distance is fine if you success to extract text from handwritten image (which is a hard task for tesseract).
I would also suggest to run some preprocessing on your image. For example you can remove horizontal lines and extract text ROIs around them. In the best case you will be able to extract separated characters, but even if you don't do that - you will get better results & will be able to distinguish result names "line by line".
You should also try other recommended output quality improvement stages which you can find in Tesseract OCR wiki (link)

Pascal results window

I have written a programme which merges two 1D arrays containing names. I print the list of arr1, arr2 and arr3.
I am using Lazarus Free Pascal v. 1.0.14 . I was wondering if anyone knows how to break the results in the dos-like window because the list is so long that I can only see the last few names in the returned results. The rest go by too fast to read.
I know I can save the resuls to file and I also use the delay command, but would like to know if there is a way to somehow break the results or slow them down or even edit the output console?
I appreciate your help.
This isn't really a programming question, because your console application should output the values without pause. Otherwise your program would become useless if you ever wanted it to run as part of another pipeline in an automated fashion.
Instead you need a tool that you wrap around your program to paginate the output if, and when, you so desire. Such tools are known as terminal pagers and the basic one that ships with Windows is called more. You execute your program and pipe the output to the more program. Like this:
C:\SomeDir>MyProject.exe <input_args> | more
You can change the code of your loop in the following way:
say you print the results by the followng loop:
for i:=0 to 250 do
WriteLn(ArrUnited[i]);
you can replace it with:
for i:=0 to 250 do
begin
WriteLn(ArrUnited[i]);
if (i mod 25) = 24 then //the code will wait for the user pressing Enter every 25 rows
ReadLn;
end;
For the future please! post MCVE in your questions otherwise everyone has to guess what your code is.

Can I read the rest of the line after a positive value of IOSTAT?

I have a file with 13 columns and 41 lines consisting of the coefficients for the Joback Method for 41 different groups. Some of the values are non-existing, though, and the table lists them as "X". I saved the table as a .csv and in my code read the file to an array. An excerpt of two lines from the .csv (the second one contains non-exisiting coefficients) looks like this:
48.84,11.74,0.0169,0.0074,9.0,123.34,163.16,453.0,1124.0,-31.1,0.227,-0.00032,0.000000146
X,74.6,0.0255,-0.0099,X,23.61,X,797.0,X,X,X,X,X
What I've tried doing was to read and define an array to hold each IOSTAT value so I can know if an "X" was read (that is, IOSTAT would be positive):
DO I = 1, 41
(READ(25,*,IOSTAT=ReadStatus(I,J)) JobackCoeff, J = 1, 13)
END DO
The problem, I've found, is that if the first value of the line to be read is "X", producing a positive value of ReadStatus, then the rest of the values of those line are not read correctly.
My intent was to use the ReadStatus array to produce an error message if JobackCoeff(I,J) caused a read error, therefore pinpointing the "X"s.
Can I force the program to keep reading a line after there is a reading error? Or is there a better way of doing this?
As soon as an error occurs during the input execution then processing of the input list terminates. Further, all variables specified in the input list become undefined. The short answer to your first question is: no, there is no way to keep reading a line after a reading error.
We come, then, to the usual answer when more complicated input processing is required: read the line into a character variable and process that. I won't write complete code for you (mostly because it isn't clear exactly what is required), but when you have a character variable you may find the index intrinsic useful. With this you can locate Xs (with repeated calls on substrings to find all of them on a line).
Alternatively, if you provide an explicit format (rather than relying on list-directed (fmt=*) input) you may be able to do something with non-advancing input (advance='no' in the read statement). However, as soon as an error condition comes about then the position of the file becomes indeterminate: you'll also have to handle this. It's probably much simpler to process the line-as-a-character-variable.
An outline of the concept (without declarations, robustness) is given below.
read(iunit, '(A)') line
idx = 1
do i=1, 13
read(line(idx:), *, iostat=iostat) x(i)
if (iostat.gt.0) then
print '("Column ",I0," has an X")', i
x(i) = -HUGE(0.) ! Recall x(i) was left undefined
end if
idx = idx + INDEX(line(idx:), ',')
end do
An alternative, long used by many many Fortran programmers, and programmers in other languages, would be to use an editor of some sort (I like sed) and modify the file by changing all the Xs to NANs. Your compiler has to provide support for IEEE NaNs for this to work (most of the current crop in widespread use do) and they will correctly interpret NAN in the input file to a real number with value NaN.
This approach has the benefit, compared with the already accepted (and perfectly good) answer, of not requiring clever programming in Fortran to parse input lines containing mixed entries. Use an editor for string processing, use Fortran for reading numbers.

Is is possible create/delete/disable multiple breskpoints once in GDB?

I really like to create/delete/disable (and all other actions to breakpoint) multiple breakpoints in just one command line, such as:
b 12 28 30
to create 3 breakpoints at line 12, 28 and 30.
I googled many times, but got nothing.
The only built-in way to create multiple breakpoints with a single command is rbreak, but this isn't applicable to you, as it doesn't allow line numbers.
If you really need this for some reason, you can write a new command to do it. You might be able to do this from the CLI using define, but, if not, you can easily use Python to write new commands.
Many other breakpoint commands like enable (but not all commands -- I think, e.g., not cond for syntax reasons) take a list of breakpoints to work on.

Get list of moves from PGN

I have a PGN (Portable Game Notation) of a chess game. What I would like is to get just a list of the moves. For example:
PGN :
1. e4 e5 2. f4 exf4 3. Nf3 d5 4. exd5 Nf6 5. Nc3 Nxd5 6. Nxd5 Qxd5 7. d4 Bg4 8.
Bxf4 Nc6 9. Be2 O-O-O 10. c3 Qe4 11. Qd2 Rxd4 12. Nxd4 Nxd4 13. cxd4 Bb4 14.
Kf2 Bxd2 15. Bxg4+ f5 16. Bxd2 fxg4 17. Rhe1 Qxd4+ 18. Be3 Qxb2+ 19. Kf1 Re8
0-1
output:
['e4','e5','f4','exf4','Nf3','d5', .... , 'Re8']
My idea was the take the string and split it at the spaces and then arrange a new array that way, but I'm wondering if there are any better ways of doing this. There's no specific language I'm just interested in general. Could be python, javascript, doesn't really matter.
Also, sometimes PGN comes with notation in the middle of the string or "variations" which are denoted in brackets, I'd like to ignore these. Any ideas?
Thanks
Strange, I couldn't find good PGN parsers for Ruby or Javascript. Here are two other libraries that I briefly tested:
PHP: https://github.com/DHTMLGoodies/chessParser (seems to be broken; when I tried I always got an empty array of games)
Perl: http://metacpan.org/pod/Chess::PGN::Parse
(seems to work, at least I could see the moves of a PGN game. Not easy to get started, though.)
Maybe it is really the best approach to write the parser yourself. You can eliminate the comments with regular expressions as they are not nested.
(from Wikipedia)
Comments are inserted by either a ";" (a comment that continues to the end of the line) or a "{" (which continues until a matching "}"). Comments do not nest.
After the comments (including the variants) are gone, you can parse the moves as you intended (split for whitespaces and filter the move numbers).
I've just started using the Ruby PGN gem at https://rubygems.org/gems/pgn It has a parser module, you can do PGN-> FEN, play through the game, set up positions with FEN import, etc. i've been using a branch of this as well at https://github.com/tobiasvl/pgn/tree/pgn-annotations this branch is able to parse PGNs containing variations and comments.
Here's a javascript version, https://github.com/jhlywa/chess.js