Gnuplot: Convert integer to ASCII value - ascii

I would like to generate multiple plots within one gnuplot script, and would like to start each plot's title with a running capital letter, i.e., the first plot will have the title (A) sample title for first chart, the second one (B) sample title for second chart, and so on.
In Java, for this I basically have to do
int i = 65; // ASCII value for 65
char c = (char)i; // Convert 65 to corresponding ASCII value ('A')
i++;
// Use c; then repeat
I just tried something similar in gnuplot by using gprintf and using the %c formatter, yet I could not get it working due to the problem
These format specifiers are not the same as those used by the standard C-language routine sprintf().
Long question short: How to convert an integer to its corresponding ASCII value?

gnuplot> print sprintf("%c", 65)
#A
Gnuplot provides a gprintf which uses gnuplot format specifiers and sprintf.

Related

golang screen printing formatted data with color attributes

Want to print a row/column table that is formatted as in a typical
fmt.Printf("%5s %5s %5s\n",col1, col2, col3)
Works fine of course if the strings are plain text, but if a string has display attributes
like color, bold, font - even though the visible data is the same length as the plain text,
and would be fine in %5s; doing len(col1) is much longer it skews the table alignment.
Is there a way for Printf to accomplish this, or another std Go package?
Want:
Item Item Item
===== ===== ====
abc defgh xyz
x abc d
vv xxxxx zz <=== this happens if string xxxxx has display attributes from
fatih,gchalk, etc. to set foreground/background color
`
//
package main
import (
"fmt"
"github.com/jwalton/gchalk"
"github.com/fatih/color"
)
func main() {
var colorWithGchalk = gchalk.Red
var data = []string{"one", "ten", "twenty"}
gchalk.SetLevel(gchalk.LevelAnsi16m) // seems needed for gitbash
// note output columns framed by <> just to see actual width
fmt.Println("desired formatted output")
fmt.Printf("<%-10s> <%-10s> <%-10s>\n\n", data[0],data[1],data[2])
/*
** gchalk
*/
// first try using gchalk for color
// colorize second column - column width ignored?
fmt.Println("colorized field loses its 10 character width, so subsequent fields now misaligned")
fmt.Printf("<%-10s> <%-10s> <%-10s>\n", data[0], colorWithGchalk(data[1]), data[2])
// same as above but eliminate gchalk function and just apply colorizing directly - same result
fmt.Printf("<%-10s> <%-10s> <%-10s>\n", data[0], gchalk.Red(data[1]), data[2])
/*
** fatih
*/
fmt.Println("\nwith fatih")
var colorWithFatih = color.New(color.FgRed).SprintFunc()
fmt.Printf("<%-10s> <%-10s> <%-10s>\n", data[0], colorWithFatih(data[1]), data[2])
}
`
Output:
`
desired formatted output
colorized field loses its 10 character width,
so subsequent fields now misaligned
with fatih
`
On screen the above 3 lines display the word "ten" in red as desired, but the field is no longer 10 wide.
Is there a way for Printf to accomplish this,
No
or another std Go package?
No
(What you call "display attributes" are part of the output stream of bytes, they are not "attributes", this is "inline data" interpreted by the terminal emulator. What you can do is filter out this inline data before printing.)
You could use https://github.com/olekukonko/tablewriter as an example for how to output tables or just use the package.
With the advice of Jason Walton the porter of chalk to gchalk. I got fmt.Printf %s to satisfy my need, although their may be issues if the field widths (%s) were narrow.
I wanted to concatenate at least two strings together to provide to one %s.
The first string was plain text (sgCharToPrint) the next string was colorized so it was the actual screen text (missedRaw) (missed was the color string e.g. missedRaw wrapped with ansi formatting characters.
myLen = len(sgCharToPrint) + len(missedRaw)
padded = sgCharToPrint + missed + strings.Repeat(" ", 30 - olen)
fmt.Printf("%30s %4d %10s \n",padded, value, tail)
Now the "table" display stays in alignment.

Ruby pack and Latin (high-ASCII) characters

An action outputs a fixed-length string via Ruby's pack function
clean = [edc_unico, sequenza_sede, cliente_id.to_s, nome, indirizzo, cap, comune, provincia, persona, note, telefono, email]
string = clean.pack('A15A5A6A40A35A5A30A2A40A40A18A25')
However, the data is in UTF-8 as to allow latin/high-ascii characters. The result of the pack action is logical. high-ascii characters take the space of 2 regular ascii characters. The resulting string is shortened by 1 space character, defeating the original purpose.
What would be a concise ruby command to interpret high-ascii characters and thus add an extra space at the end of each variable for each high-ascii character, so that the length can be brought to its proper target? (note: I am assuming there is no directive that addresses this specifically, and the whole lot of pack directives is mind-muddling)
update an example where the second line shifts positions based on accented characters
CNFrigo 539 Via Privata Da Via Iseo 6C 20098San Giuliano Milanese MI02 98282410 02 98287686 12886480156 12886480156 Bo3 Euro Giuseppe Frigo Transport 349 2803433 M.Gianoli#Delanchy.Fr S.Galliard#Delanchy.Fr
CNIn's M 497 Via Istituto S.Maria della Pietà, 30173Venezia Ve041 8690111 340 6311408 0041 5136113 00115180283 02896940273 B60Fm Euro Per Documentazioni Tecniche Inviare Materiale A : Silvia_Scarpa#Insmercato.It Amministrazione : Michela_Bianco#Insmercato.It Silvia Scarpa Per Liberatorie 041/5136171 Sig.Ra Bianco Per Pagamento Fatture 041/5136111 (Solo Il Giovedi Pomeriggio Dalle 14 All Beniservizi.Insmercato#Pec.Gruppopam.It
It looks like you are trying to use pack to format strings to fixed width columns for display. That’s not what it’s for, it is generally used for packing data into fixed byte structures for things like network protocols.
You probably want to use a format string instead, which is better suited for manipulating data for display.
Have a look at String#% (i.e. the % method on string). Like pack it uses another little language which is defined in Kernel#sprintf.
Taking a simplified example, with the two arrays:
plain = ["Iseo", "Next field"]
accent = ["Pietà", "Next field"]
then using pack like this:
puts plain.pack("A10A10")
puts accent.pack("A10A10")
will produce a result that looks like this, where “Next field” isn’t aligned since pack is dealing with the width in bytes, not the displayed width:
Iseo Next field
Pietà Next field
Using a format string, like this:
puts "%-10s%-10s" % plain
puts "%-10s%-10s" % accent
produces the desired result, since it is dealing with the displayable width:
Iseo Next field
Pietà Next field

Automatically increment filename VideoWriter MATLAB

I have MATLAB set to record three webcams at the same time. I want to capture and save each feed to a file and automatically increment it the file name, it will be replaced by experiment_0001.avi, followed by experiment_0002.avi, etc.
My code looks like this at the moment
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
avi1 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_002.AVI');
avi2 = VideoWriter('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI');
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
and I am incrementing the 002 each time.
Any thoughts on how to implement this efficiently?
Thanks.
dont forget matlab has some roots to C programming language. That means things like sprintf will work
so since you are printing out an integer value zero padded to 3 spaces you would need something like this sprintf('%03d',n) then % means there is a value to print that isn't text. 0 means zero pad on the left, 3 means pad to 3 digits, d means the number itself is an integer
just use sprintf in place of a string. the s means String print formatted. so it will output a string. here is an idea of what you might do
set(vid1,'LoggingMode','disk');
set(vid2,'LoggingMode','disk');
for (n=1:2:max_num_captures)
avi1 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentA_%03d.AVI',n));
avi2 = VideoWriter(sprintf('X:\ABC\Data Collection\Presentations\Correct\ExperimentB_002.AVI',n));
set(vid1,'DiskLogger',avi1);
set(vid2,'DiskLogger',avi2);
end

Using Char.chr in SML

I need to convert an int to its equivalent char using the Char.chr-function, but why does the function return every char in the form of #"\^A" instead of just #"A" (that's how I want it to be).
What you see there is just the way control characters (ASCII code 0-31) are pretty-printed by the interactive toplevel. For example, #"\^A" is equivalent to #"\001". The SML system presumably uses its own Char.toString function to print values of type char. Try chr 65, which should be printed as #"A".

How to split input by ASCII control codes with Progress 4GL?

how can I split this barcode by group separator with Progress? I've tried chr(29) without any luck.
Barcode scanned into Notepad++: http://i.imgur.com/8DmPZ.png
Barcode scanned into input field: 2409271405202120330017100282
Thanks.
def var c as char no-undo.
def var i as int no-undo.
update c format "x(50)".
do i = 1 to length(c):
message substr(c, i, 1) = chr(29).
end.
The problem is that GS is an undefined control code. So you need to make it be recognized.
Add the following to your terminal's entry in protermcap to define GS as F13:
:(F13)=\035:\
(The octal code for GS is \035 and F13 is an undefined function key -- so the combination should work. I don't have a scanner to test with but this works for the control codes that I can type into my keyboard...)
Then use code like this:
define variable bc as character no-undo format "X(50)".
update bc editing:
if lastkey = 313 then
apply ".". /* 313 is the code for F13 */
else
apply lastkey.
end.
This should cause "." to be inserted instead of GS. Which will allow you to parse the string using "." rather than GS.
It's a wild guess, but I'm thinking ENTRY(entry-num, barcode-string, "group-separator-string")?
This works for me:
/* create a test file (otherwise not needed...)
*/
output to "barcode.dat".
put control "240927140520" chr(29) "2120330017" chr(29) "100282".
output close.
/* if you already have barcode.dat start here
*/
define variable m as memptr no-undo.
define variable bc as character no-undo.
set-size( m ) = 100.
input from "barcode.dat" binary no-convert.
import unformatted m.
input close.
bc = get-string( m, 1 ).
display
entry( 1, bc, chr(29)) format "x(12)" skip
entry( 2, bc, chr(29)) format "x(12)" skip
entry( 3, bc, chr(29)) format "x(12)" skip
.

Resources