Get the resolution of a 2nd or 3rd monitor - windows-xp

How would I go about fetching the resolution of a 2nd or 3rd monitor via an AutoIT script?
Is there a specific function available for this?

Discovered a 3rd party library. It can return the resolutions of each monitor relative to the default display.
I just got an idea how to order them properly as well. I'll have to add a small section to the library where it assigns the smallest x value (includes negative integers) to be the first monitor, the next smallest the 2nd monitor, so on and so forth.
An example to enumerate all physical monitors and obtain their x resolution:
Dim $x = 0, $_enum, $_xRes, $_xResPre
Do
$_enum = _WinAPI_EnumDisplayDevices("", $x)
If $_enum[3] = 35 OR $_enum[3] = 33 Then
$x+=1
$_xResPre = _MonitorAndDesktopInfo()
$_xRes = $_xResPre[$x][1]
msgbox(0, "", $_xRes)
Else
$x+=1
EndIf
Until NOT $_enum[3]

Related

Matlab code to charge to a maximum value of capacity

I want to get rCl, which is remaining charge of a battery in an e-vehicle. Currently the values are wrong as I am not getting the code right.
rCl should be a max of 1000. nCl describes the amount (in kWh) it is using, and pCp the amount (in kWh), it could potentially load. So it should be like that:
rCl(x) = rCl(x-1) -nCl(x-1) + pCp(x-1) --> to a a max of 1000kWh
I tried several things, including this:
for x = 2:2:2734
Cp(x) = min(nC(x-1),pCp(x))
end
for x = 2:1:2734
rC(x) = rC(x-1) - nC(x-1) + Cp(x-1)
end
But I just cant figure it out - I might have been looking at it for to long already... any suggestions are welcome!
If you look at the pic of the data, you may notice, it works as long as pCp is greater than nCl and therefor it can load to full. Once this is not working anymore, the load never goes to full again and keeps on decreasing.
I figured it out:
for x = 2:1:tablesize
rCl(x) = rCl(x-1)-nCl(x-1)+pCp(x-1)
if rCl(x) > 1000
rCl(x) = 1000
end
end

Framework for Managing Matlab Runs

TL;DR: How should custom simulation runs be managed in Matlab? Detailed Questions at the end.
I am working with matlab where i created some code to check the influence of various parameters on a simulated system. It has a lot of inputs and outputs but a MWE would be:
function [number2x,next_letter] = test(number, letter)
number2x = number * 2;
next_letter = letter + 1;
disp(['next letter is ' next_letter])
disp(['number times 2 is ' num2str(number2x)])
end
This works if this is all there is to test. However with time multiple new inputs and outputs had to be added. Also because of the growing number of paramters that have been test some sort of log had to be created:
xlswrite('testfile.xlsx',[num2str(number), letter,num2str(number2x),next_letter],'append');
Also because the calculation takes a few hours and should run over night multiple parameter sets had to be started at one point. This is easily done with [x1,y1] = test(1,'a');[x2,y2] = test(2,'b'); in one line or adding new tasks while the old still run. However this way you can't keep track on how many are still open.
So in total I need some sort of testing framework, that can keep up with changeging inpus and outputs, keeps track on already doen calculations and ideally also handles the open runs.
I feel like i can't be the only one who faces this issue, in fact I think so many people face this issue that Mathworks would already came up with a solution.
For Simulink this has been done in form of a Simluationmanager, but for Matlab functions the closest thing i found is the Testing framework (example below) which seems to be rather for software development and debugging and not at all for what i am trying. And somepoint there seem to be 3rd party solutions but they are no longer continued in favor of this Testing framework.
function solutions = sampleTest
solutions = functiontests({#paramtertest});
end
function paramtertest(vargin)
test(1,'a');
test(2,'b');
end
function [number2x,next_letter] = test(number, letter)
number2x = number * 2;
next_letter = letter + 1;
disp(['next letter is ' next_letter])
disp(['number times 2 is ' num2str(number2x)])
xlswrite('testfile.xlsx',[num2str(number), letter,num2str(number2x),next_letter],'append');
end
Alternatively I could create my test as a class, create an interface similar to the Simulationmanager, create numerous functions for managing inputs and outputs and visualize the progress and then spawn multiple instances of if i want to set up a new set of parameters while already running a simulation. Possible, yet a lot of work that does not involve the simulation directly.
In total following questions arise:
Is there a build in Matlab function for managing simulations that i totally missed so far?
Can the the Testing framework be used for this purpose?
Is there already some Framework (not from Mathworks) that can handle this?
If i create my own class, could multiple instances run individually and keep track of their own progress? And would those be handled simultaniously or would matlab end up running the in the order they started?
I know this question is somewhat in the off-topic: recommend or find a tool, library or favorite off-site resource area. If you feel it is too much so, please focus on the last question.
Thank you!
I've done similar tests using GUI elements. Basic part of simulation was inside while loop, for example in your case:
iter = 0;
iter_max = 5; %the number of your times, you will call script
accu_step = 2; %the accuracy of stored data
Alphabet = 'abcdefghijklmnopqrstuvwxyz'
while iter < iter_max
iter = iter+1;
[x1,y1] = test(i,Alphabet(i));
end
Now you should create a handle to progress bar inside your computation script. It will show you both on which step you are, and the progress of current step.
global h;
global iter_opt;
if isempty(h)
h=waitbar(0,'Solving...');
else
waitbar(t/t_end,h,sprintf('Solving... current step is:%d',iter));
end
You didn't specified which function you use, if it is for example time-depended the above t/t_end example is an estimation of current progress.
The solving of result also require to be changed on every execution of loop, for example:
global iter;
i_line = (t_end/accu_step+2)*(iter-1);
xlswrite('results.xlsx',{'ITERATION ', iter},sheet,strcat('A',num2str(i_line+5)))
xlswrite('results.xlsx',results_matrix(1:6),sheet,strcat('D',num2str(i_line+5)))
The above example were also with assumption that your results are time-related, so you store data every 2 units of time (day, hours, min, what you need), from t_0 to t_end, with additional 2 rows of separation, between steps. The number of columns is just exemplary, you can adjust it to your needs.
After the calculation is done, you can close waitbar with:
global h
close(h)

C++ AMP Division Quirk When Stressing GPU

Wrote a program that uses C++ AMP to run on my laptop's GPU (Intel HD Graphics 520). The GPU kernel is long so I will give a high level description (but let me know if more is needed).
Note that I fall into the "know enough to be dangerous" category of programmer.
parallel_for_each(accelerator_view, number_of_runs.extent, [data](index<1> idx) restrict(amp)
{
double total = data.starting_total[idx];
//these "working variables" are used for a variety of things in the code
double working_variable = 0.0;
double working_variable2 = 0.0;
for (int i = 0; i < 20; i++)
{
...do lots of stuff. "total" is changed by various factors...
//total is still a positive number that is greater than zero
//working_variable now has a positive non-zero value, and I want to find what %
//of the remaining total that value is
working_variable2 = 1.0 / total;
working_variable2 = working_variable * working_variable2;
//Note that if I write it like this the same issue will happen:
working_variable2 = working_variable / total;
...keep going and doing more things, write some values to data..
if (total == 0)
break;
}
}
When I run this without doing much else on my computer this runs just fine and I get the results I expect.
Where it gets really tricky is when I am stressing the system (or I think I am stressing the system). I test stress the system by
1) Kicking off my program
2) Opening up Chrome
3) Going to Youtube and starting a video
When I do that I get unexpected results (either when I am opening a program or running a video). I traced it back to the "1.0 / total" calculation returning infinity (inf), even though "total" is greater than zero. Here is an example of what I output to the console when this issue happens:
total = 51805.6
1.0 / total = inf
precise_math::pow(total, -1) = 1.93029e-05
I am running the kernel about 1.6 million times and I'll see between 0 and 15 of those 1.6 million hit this issue. The number of issues varies and which threads hit the issue varies.
So I feel confident that "total" is not zero and this is not a divide by zero situation. What am I missing? What could be causing this issue? Any way to prevent this? I am thinking of replacing all division in the kernel with the pow(num, -1)
P.S. Yes I am aware that the part of the answer is "don't watch videos while running". It is the opening of programs during execution that I am most concerned about.
Thank you!

gnu sort - default buffer size

I have read the full documentation for gnu sort and searched online but I cannot find what the default for the --buffer-size option is (which determines how much system memory the program uses when it runs). I am guessing it is somehow determined based on total system memory? (or perhaps on memory available at the time the program is begins execution?). How can I determine this?
update: I've experimented a bit and it seems that when I don't specify a particular --buffer-size value, it ends up using very little ram and thus going very slowly. It would be nice though to better understand what exactly is determining this behavior.
I went digging through the coreutils sort source code and found these functions: default_sort_size and sort_buffer_size.
It turns out that --buffer-size (sort_size in the source code) isn't the target buffer size but rather the maximum buffer size. If no --buffer-size value is specified, the default_sort_size function is used to determine a safe maximum buffer size. It does this based on resource limits, available memory, and total memory. A summary of the function is as follows:
size = MIN(SIZE_MAX, resource_limit) / 2;
mem = MAX(available_memory, total_memory / 8);
if ( size > total_memory * 0.75 )
size = total * 0.75;
buffer_max = MIN(mem, size);
buffer_max = MAX(buffer, MIN_SORT_SIZE);
The other function, sort_buffer_size, is used to determine exactly how much memory to allocate for the given input files. A summary of the function is as follows:
if (sort_size is set)
size_bound = sort_size;
else
size_bound = default_sort_size();
buffer_size = line_bytes + 2;
for each input_file
if (input_file is regular)
file_size = input_file_size;
else
if (sort_size is set)
return sort_size;
else
file_size = guess;
worst_case = file_size * worst_case_per_input_byte + 1;
if (worst_case overflows || size + worst_case >= size_bound)
return size_bound;
else
size += worst_case;
return size;
Possibly the most important point of the sort_buffer_size function is that if you're sorting data from STDIN or a pipe, it will automatically default to sort_size (i.e. --buffer-size) if it was provided. Otherwise, for regular files it will make some rough calculations based on the file sizes and only use sort_size as an upper limit.
To summarize in English, the defaults are:
Reading from a real file:
Use all free memory, up to 3/4 and not less than 1/8 of total memory.
(If there is a process (rusage) memory limit in effect, sort will not use more than half of that.)
Reading from a pipe:
Use a small, fixed amount (tens of MB).
You will probably want -S.
Current for GNU coreutils 8.29, Jan 2018.

Plotting multiple time series using VPlotContainers in Chaco. Limit to the number of VPlotContainer objects you can use

I wish to plot multiple time series data stored in a NumPy array, in the same plot but with each time series offset, so effectively it has it's own Y axis. I figured the best way to do this may be to put each series in a separate VPlotContainer, but when I call the configure_traits() call I am just getting a blank window. Is the issue that I have too many time series for the machinery to handle?
class EEGPlot(HasTraits):
plot = Instance(VPlotContainer)
traits_view = View(
Item('plot',editor=ComponentEditor(), show_label=False),
width=1024, height=768, resizable=True, title="EEG Preview")
def __init__(self, eegObject):
super(EEGPlot, self).__init__()
x = xrange(eegObject.windowStart, eegObject.windowEnd)
plotNames = {}
allPlots = []
for idx, column in enumerate(eegObject.data[:,:].transpose()): # only included indexes to indicate array dimensions
y = column
plotdata = ArrayPlotData(x=x, y=y)
myplot = Plot(plotdata)
myplot.plot(("x", "y"), type="line", color="blue")
plotNames["plot{0}".format(idx)] = myplot
allPlots.append(plotNames["plot{0}".format(idx)])
container = VPlotContainer(*allPlots)
container.spacing = 0
self.plot = container
So my EEGObject is a NumPy array with 2 dimensions. Around 1500(row) by 65(col). I am wondering if I getting the blank screen because I am doing something wrong or if I am just giving it too many containers?
The answer appears to be that I was using the wrong tools to try and achieve what I needed. VPlotContainers are for separating distinct plots (most likely from different data sources even) within a main display container.
When I fed a test array into the code in the original question that only had 5 columns, then each column plotted in a separate container, but when I increased the columns to above 6 then the UI window would appear blank.
So I guess the answer is that yes, there would appear to be a limit to the number of VPlotContainers you can use, but I don't know if this limit is absoloute or bound by the space dedicated to the main UI window or what.
Either way, using VPlotContainers is not an appropriate technique to display multiple time series data. The correct object would be a MultiLinePlot if you wish the lines to be separated, or an OverlayPlotContainer.
http://docs.enthought.com/chaco/user_manual/plot_types.html#multi-line-plot
I am also having issues using MultiLinePlot, but have moved this question to a separate thread here:
Chaco MultiLinePlot - unable to get simple plot to display, wondering if package broken?