I am trying to print out some information within a CUDA kernel using printfs to write code into the console that I can paste into another program to draw the geometric setup that I am working with.
I have, however, trouble getting the locale to work. I am working under Linux Mint 18.1 with CUDA 9.0. When I printf from the C++ part of my program the numbers get printed as follows:
printf("my value: %.3f\n", my_value); // prints 1.234 for example
but using it from a CUDA kernel I get
printf("my value: %.3f\n", my_value); // prints 1,234
This is the format used in Germany, but obviously computers don't understand the latter format. I need it to print with the . instead of the comma.
I have tried manually setting my locale by putting the line
export LC_NUMERIC="en_US.UTF-8"
into my .bashrc. My locale command prints:
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_BE.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_BE.UTF-8
LC_NAME=de_BE.UTF-8
LC_ADDRESS=de_BE.UTF-8
LC_TELEPHONE=de_BE.UTF-8
LC_MEASUREMENT=de_BE.UTF-8
LC_IDENTIFICATION=de_BE.UTF-8
LC_ALL=
But that does not change the output from the CUDA kernel.
I am not sure which other values to overwrite, without messing up default currency and so on. I also cannot find any information on setting locales within CUDA, so I assume it fetches that information from somewhere else. Does anyone know where that is and how to make it do what I want?
It seems like Linux is very adamant on keeping the current language configuration as it is. I managed to get the printout to be like I want it by uninstalling all other language packages that were installed, putting
export LANG=en_US.utf8
in my .bashrc and then rebooting the machine. Not sure if all of those steps were necessary, but it fixed my problem.
Related
I'm trying to use the Ocaml Graphics package. I want to create a GUI for my chat server application. My code is:
let window = Graphics.open_graph "";
Graphics.set_window_title "caml-chat";
Graphics.set_font "ubuntu";
Graphics.set_text_size 12;
Graphics.draw_string "hello!"
However, Graphics.set_font "ubuntu" does not work. The documentation says that the string argument is system dependent, but I cannot find any more information than that. The only mention I found was in the answers to this question, and it didn't work.
Does anyone know anything else about setting the font? (Or can point me in the direction of a simple graphics library with better documentation?)
Although you didn't specify your system, I will assume that it is Linux (I doubt that Windows has an ubuntu font).
On Linux, the set_font function passes the argument to the X Lib's XLoadFont function. You can use the fc-list or xfontsel utilities to query for the available fonts on your system, or call directly to the XListFonts function.
For example,
fc-list | cut -d: -f2 | sort -u
will give you a list of font families, which you can pass to set_font function. Some lines will have more than one family per line, separated with comman (,). There are many more options, you can specify various styles, sizes, etc. But this is all out of the scope. You can the fontconfig guide to learn more about the font subsystem. For example, [here], at the section "Font Names", you can find the explanation of how the font name is constructed.
I am working with a command line tool called 'ideviceinfo' (see https://github.com/libimobiledevice) to help me to quickly get back serial, IMEI and battery health information from the iOS device I work with daily. It executes much quicker than Apple's own 'cfgutil' tools.
Up to know I have been able to develop a more complicated script than the one shown below in PyCharm (my main IDE) to assign specific values etc to individual variables and then to use something like to pyclip and pyautogui to help automatically paste these into the fields of the database app we work with. I have also been able to use the simplified version of the script both in Mac OS X terminal and in the python shell without any hiccups.
I am looking to use AppleScript to help make running the script as easy as possible.
When I try to use Applescript's "do shell script 'python script.py'" I just get back a string of lenght zero when I call 'ideviceinfo'. The exact same thing happens when I try to build an Automator app with a 'Run Shell Script' component for "python script.py".
I have tried my best to isolate the problem down. When other more basic commands such as 'date' are called within the script they return valid strings.
#!/usr/bin/python
import os
ideviceinfoOutput = os.popen('ideviceinfo').read()
print ideviceinfoOutput
print len (ideviceinfoOutput)
boringExample = os.popen('date').read()
print boringExample
print len (boringExample)
I am running Mac OS X 10.11 and am on Python 2.7
Thanks.
I think I've managed to fix it on my own. I just need to be far more explicit about where the 'ideviceinfo' binary (I hope that's the correct term) was stored on the computer.
Changed one line of code to
ideviceinfoOutput = os.popen('/usr/local/bin/ideviceinfo').read()
and all seems to be OK again.
Having this line of code:
print "S\x00A\x00V\x00A"
produces different output. On Windows:
S A V A
and on Linux:
SAVA
What is the difference between the the 2 platform and what can I do to remove the whitespaces from the Windows case?
The difference is at the terminal level.
Windows cmd prints the zero-char as empty whereas your Linux terminal doesn't print it.
Note that in PyScripter console or PyCrust console (wx-based) you only get S (probably because the zero is seen as a line-termination char). So it's definitely not portable :)
To get rid of it just perform a replace:
print("S\x00A\x00V\x00A".replace("\x00",""))
Is it possible to print Bengali Language with C in console? If it can be done, how can I do it?
I tried:
wprintf (L"Character: %lc %lc \n", L'ঈ', 2440);
This does not work. It just shows an unknown symbol. What is the best formula for working with UTF-8 format data in console? If it is possible with C++, I want to know that.
To use a language & display it is very much an OS dependent task and below are few generic possible ways to do it.
On linux :
Set Locale,
In your case it should be : setlocale(LC_ALL, 'bn_IN.utf8');
Refer : (http://www.linuxquestions.org/questions/linux-newbie-8/displaying-hindi-in-linux-command-prompt-terminal-4175448642/)
Download appropriate font & install in your system.
Check your : cd /usr/share/fonts/ for the font.
edit your .bashrc file and add your font like this:
export LANG=bn_IN.UTF-8
(Side effect your whole os may start using this font if it supports).
On Windows :
Necessary criteria for fonts to be available in a command window
How to print a unicode string to console?
Refer
Note : Your Terminal must support Unicode for any of this to work.
Using the ICU library with C++ I'm doing:
char const *lang = Locale::getDefault().getLanguage();
If I write a small test program and run it on my Mac system, I get en for lang. However, inside a larger group project I'm working on, I get root. Anybody have any idea why? I did find this:
http://userguide.icu-project.org/locale/resources
so my guess is that, when running under the larger system, some ICU resources aren't being found, but I don't know what resources, why they're not being found, or how to fix it.
Additional Information
/usr/bin/locale returns:
LANG="en_US.ISO8859-1"
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL="C"
If I write a small C program:
char const *lang = setlocale( LC_ALL, "" ):
I get en_US.ISO8859-1.
OS: Mac OS X 10.6.4 (Snow Leopard)
ICU version: 4.3.4 (latest available via MacPorts).
A little help? Thanks.
root is surely an odd default locale - you don't see many native root-speakers these days.
But seriously, is it safe to assume on the larger system that someone hasn't called one of the variants of setDefault("root")?
What does something like /usr/bin/locale return on this system (if you can run that)?
ICU 4.4 now has a test program called 'icuinfo', does it also return root as the default locale?
What OS/platform is this on, and which version of ICU?