Use gnuplot within Fortran code in Windows - windows

I have a fortran code as below
program compute_plot
integer :: i, n = 10
real :: x(10), y(10)
x(1) = 0.0
y(1) = 0.0
do i = 2, n
x(i) = 0.1*i
y(i) = x(i)*x(i)
end do
open(unit = 5, file = 'data.txt')
do i = 1, n
write(5,*) x(i),y(i)
end do
close(5)
call system('gnuplot -p data_plot.gnu')
end program compute_plot
and another gnuplot script as below
reset
set terminal pngcairo dashed enhanced size 480,360 font 'arial,12' fontscale 1.0
set encoding utf8
set output 'plot.png'
set xlabel "x"
set ylabel "y"
m = "./data.txt"
set title 'The parabola'
plot m using 1:2 w l
These two code work well in Linux terminal, but I could not find a way to make them work in Windows command prompt. I also not sure if it is possible to make them work in Windows. Please advise.

Download gp503-win32-mingw.zip from gnuplot official webpage;
Extract the zip file in your desired folder, e.g. F:Document;
The gnuplot folder will now have the path of F:\Documents\gnuplot\;
Right click This PC, click on Properties, click on Advanced system settings, click on Advanced tab, click on Environment Variables...;
Choose Path on the top table of Environment Variables windows, then click Edit...;
Now click on New to add in the path of gnuplot.exe, e.g. in my desktop F:\Documents\gnuplot\bin
To check if it is working properly, go to Command prompt and run the command of gnuplot.

Related

E764: option 'omnifunc' is not set. Just storing a file in path

Im trying to set path .bash_profile
here is what i write: export PATH=&PATH:/usr/local/ant/bin
To exit and save i use Control + X and Control + O but get this error every time: E764: option 'omnifunc' is not set.
Purpose is to install ant migration tool
Im using mac os
You should put :
export PATH=$PATH:/usr/local/ant/bin
Then
Esc:wq
Control + X and Control + O, is it for nano editor ?

gnuplot under windows: how to specify window size/position when it startup?

Under windows 10, how can I specify window postion (X,Y) and window size (width,height) of gnuplot, via command line arguments?
The path of the application is
D:\gnuplot\bin\wgnuplot.exe
how can specify window postion and size with it? like with cygwin mintty:
D:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico
-p 372,12 -s 135,50 -o Font=Consolas -o FontHeight=13 -
show version long output
Version 5.2 patchlevel 0 last modified 2017-09-01
Compile options:
+READLINE -LIBREADLINE +HISTORY
-BACKWARDS_COMPATIBILITY +UNICODE +OBJECTS +STATS +EXTERNAL_FUNCTIONS
+LIBCERF +GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION
-USE_CWDRC +USE_MOUSE +HIDDEN3D_QUADTREE
MAX_PARALLEL_AXES=13
P.S.
I mean the window of gnuplot, not the graph it plots.
Gnuplot under Windows 10 can use an init file wgnuplot.ini which is located at %AppData% (C:\Users\maij\AppData\Roaming in my case).
You can generate and update the file by clicking the upper left icon of the gnuplot window and following "Options -> Update wgnuplot.ini" (see the following picture). Please play a bit with window positions and sizes and updating the ini file to see how it works.
My suggestion would be to generate wgnuplot.ini with the appropriate entries before launching gnuplot.
Currently my wgnuplot.ini looks as follows:
[WGNUPLOT]
TextOrigin=290 50
TextSize=785 489
TextMinimized=0
TextMaximized=0
TextFont=Consolas,9
TextWrap=1
TextLines=400
SysColors=0
DockVerticalTextFrac=350
DockHorizontalTextFrac=400
TextOrigin and TextSize are the options you are interested in.

Modify File Icon

I have a VBScript that toggles proxy ON and OFF. I'd like to change the file icon accordingly, so that when the proxy is ON the file icon is a green tick and when it's OFF the icon is a red cross (meaning that I can see whether the proxy is active or not before running the script).
How do I change the icon programmatically? Just for THAT file, not ALL VBScripts!
You can't change the icon for a specific file. You can, however, change the icon of a specific shortcut to a file.
Set sh = CreateObject("WScript.Shell")
lnkfile = sh.SpecialFolders("Desktop") & "\your.lnk"
Set lnk = sh.CreateShortcut(lnkfile)
If lnk.IconLocation = "C:\path\to\some.ico" Then
lnk.IconLocation = "C:\path\to\.ico"
Else
lnk.IconLocation = "C:\path\to\some.ico"
End If
lnk.Save
If the shortcut is located in the All Users desktop folder (C:\Users\Public\Desktop) you need to replace "Desktop" with "AllUsersDesktop".

Creating a Matlab run line shortcut (like R)

R has a great shortcut that runs the line your cursor is currently on then moves the cursor onto the next line (cmd + return). In matlab, you have to highlight the line then run the highlighted section (shift + F7).
Is there a way to create an 'R like' run line shortcut? I'm using OSX.
On the Home tab, click New, and then select Command Shortcut.
In the Label field: enter a name for the shortcut.
In the Callback field:
currentEditor = matlab.desktop.editor.getActive;
originalSelection = currentEditor.Selection; assert(originalSelection(1)==originalSelection(3));
currentEditor.Selection = [originalSelection(1) 1 originalSelection(1) Inf]; disp(currentEditor.SelectedText);
eval(currentEditor.SelectedText);
currentEditor.Selection = originalSelection + [1 0 1 0];
Now I can run the line I'm on by pressing Alt+s+1 (perhaps you can change this to an arbitrary hotkey). I hope this helps.
EDIT: In MATLAB R2018a Command Shortcuts have been repackaged as Favorite Commands. So to create a new shortcut in this and later version, you need to go Home tab -> Favorites -> New Favorite.
EDIT: You currently (in MATLAB R2020b) can run this code with Alt+1 (no need for 's' as above). However, it does not appear to be changeable in Preferences -> Keyboard -> Shortcuts
currentEditor = matlab.desktop.editor.getActive;
originalSelection = currentEditor.Selection;
currentEditor.Selection = [originalSelection(1) 1 originalSelection(3) Inf]; disp(currentEditor.SelectedText);
eval(currentEditor.SelectedText);
currentEditor.Selection = [originalSelection(3),0,originalSelection(3),0]+[1,0,0,0];

How to change Screen buffer size in Windows Command Prompt from batch script

I know you can do right click properties ->layout and there change it manually.
But how would you go about changing it from a Windows batch script?
I know you can change size of it from script using something like this
MODE CON: COLS=90 LINES=10
But how can you change buffer size?
The script will run for a while and sometimes before failing and exiting it takes some time, so I need larger buffer.
I was just searching for an answer to this exact question, come to find out the command itself adjusts the buffer!
mode con:cols=140 lines=70
The lines=70 part actually adjusts the Height in the 'Screen Buffer Size' setting, NOT the Height in the 'Window Size' setting.
Easily proven by running the command with a setting for 'lines=2500' (or whatever buffer you want) and then check the 'Properties' of the window, you'll see that indeed the buffer is now set to 2500.
My batch script ends up looking like this:
#echo off
cmd "mode con:cols=140 lines=2500"
I was just giving a try for max lines on windows 7 i can set using mode con command and found it to be 32766 2^15-2 and you can set it with following command
mode con lines=32766
although you can set screen buffer size from the GUI too, but the max you can get is 9999.
mode con lines=32766
sets the buffer, but also increases the window height to full screen, which is ugly.
You can change the settings directly in the registry :
:: escape the environment variable in the key name
set mySysRoot=%%SystemRoot%%
:: 655294544 equals 9999 lines in the GUI
reg.exe add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v ScreenBufferSize /t REG_DWORD /d 655294544 /f
:: We also need to change the Window Height, 3276880 = 50 lines
reg.exe add "HKCU\Console\%mySysRoot%_system32_cmd.exe" /v WindowSize /t REG_DWORD /d 3276880 /f
The next cmd.exe you start has the increase buffer.
So this doesn't work for the cmd.exe you are already in, but just use this in a pre-batch.cmd which than calls your main script.
Below is a very simple VB.NET program that will do what you want.
It will set the buffer to 100 chars wide by 1000 chars high. It then sets the width of the window to match the buffer size.
Module ConsoleBuffer
Sub Main()
Console.WindowWidth = 100
Console.BufferWidth = 100
Console.BufferHeight = 1000
End Sub
End Module
UPDATE
I modified the code to first set Console.WindowWidth and then set Console.BufferWidth because if you try to set Console.BufferWidth to a value less than the current Console.WindowWidth the program will throw an exception.
This is only a sample...you should add code to handle command line parameters and error handling.
There's a solution at CMD: Set buffer height independently of window height effectively employing a powershell command executed from the batch script. This solution let me resize the scrollback buffer in the existing batch script window independently of the window size, exactly what the OP was asking for.
Caveat: It seems to make the script forget variables (or at least it did with my script), so I recommend calling the command only at the beginning and / or end of your script, or otherwise where you don't depend on a session local variable.
Here's what I did in case someone finds it useful (I used a lot of things according to the rest of the answers in this thread):
First I adjusted the layout settings as needed. This changes the window size immediately so it was easier to set the exact size that I wanted. By the way I didn't know that I can also have visible width smaller than width buffer. This was nice since I usually hate a long line to be wrapped.
Then after clicking ok, I opened regedit.exe and went to "HKEY_CURRENT_USER\Console". There is a new child entry there "%SystemRoot%_system32_cmd.exe". I right clicked on that and selected Export:
I saved this as "cmd_settings.reg". Then I created a batch script that imports those settings, invokes my original batch script (name batch_script.bat) and then deletes what I imported in order for the command line window to return to default settings:
regedit /s cmd_settings.reg
start /wait batch_script.bat
reg delete "HKEY_CURRENT_USER\Console\%%SystemRoot%%_system32_cmd.exe" /f
This is a sample batch that could be invoked ("batch_script.bat"):
#echo off
echo test!
pause
exit
Don't forget the exit command at the end of your script if you want the reg delete line to run after the script execution.
There is no "DOS command prompt". DOS fully died with Windows ME (7/11/2006). It's simply called the Command Prompt on Windows NT (which is NT, 2K, XP, Vista, 7).
There is no way to alter the screen buffer through built-in cmd.exe commands. It can be altered through Console API Functions, so you might be able to create a utility to modify it. I've never tried this myself.
Another suggestion would be to redirect output to both a file and to the screen so that you have a "hard copy" of it. Windows does not have a TEE command like Unix, but someone has remedied that.
I created the following utility to set the console size and scroll buffers.
I compiled it using DEV C++ (http://www.bloodshed.net/devcpp.html).
An executable is included in https://sourceforge.net/projects/wa2l-wintools/.
#include <iostream>
#include <windows.h>
using namespace std;
// SetWindow(Width,Height,WidthBuffer,HeightBuffer) -- set console size and buffer dimensions
//
void SetWindow(int Width, int Height, int WidthBuffer, int HeightBuffer) {
_COORD coord;
coord.X = WidthBuffer;
coord.Y = HeightBuffer;
_SMALL_RECT Rect;
Rect.Top = 0;
Rect.Left = 0;
Rect.Bottom = Height - 1;
Rect.Right = Width - 1;
HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE); // Get Handle
SetConsoleScreenBufferSize(Handle, coord); // Set Buffer Size
SetConsoleWindowInfo(Handle, TRUE, &Rect); // Set Window Size
} // SetWindow
// main(Width,Height,WidthBuffer,HeightBuffer) -- main
//
int main(int argc, char *argv[]) {
int width = 80;
int height = 25;
int wbuffer = width + 200;
int hbuffer = height + 1000;
if ( argc == 5 ){
width = atoi(argv[1]);
height = atoi(argv[2]);
wbuffer = atoi(argv[3]);
hbuffer = atoi(argv[4]);
} else if ( argc > 1 ) {
cout << "Usage: " << argv[0] << " [ width height bufferwidth bufferheight ]" << endl << endl;
cout << " Where" << endl;
cout << " width console width" << endl;
cout << " height console height" << endl;
cout << " bufferwidth scroll buffer width" << endl;
cout << " bufferheight scroll buffer height" << endl;
return 4;
}
SetWindow(width,height,wbuffer,hbuffer);
return 0;
}
If anyone is still wondering, on the newer versions of windows you can use powershell:
powershell.exe -command "& {$pshost = Get-Host;$pswindow = $pshost.UI.RawUI;$newsize = $pswindow.BufferSize;$newsize.height = 150;$pswindow.buffersize = $newsize;}"
You can change the buffer size of cmd by clicking the icon at top left corner -->properties --> layout --> screen buffer size.
you can even change it with cmd command
mode con:cols=100 lines=60
Upto lines = 58 the height of the cmd window changes ..
After lines value of 58 the buffer size of the cmd changes...
I know the question is 9 years old, but maybe for someone it will be interested furthermore. According to the question, to change the buffer size only, it can be used Powershell.
The shortest command with Powershell is:
powershell -command "&{(get-host).ui.rawui.buffersize=#{width=155;height=999};}"
Replace the values of width and height with your wanted values.
But supposedly the reason of your question is to modify the size of command line window without reducing of the buffer size. For that you can use the following command:
start /b powershell -command "&{$w=(get-host).ui.rawui;$w.buffersize=#{width=177;height=999};$w.windowsize=#{width=155;height=55};}"
There you can modify the size of buffer and window independly. To avoid an error message, consider that the values of buffersize must be bigger or equal to the values of windowsize.
Additional implemented is the start /b command. The Powershell command sometimes takes a few seconds to execute. With this additional command, Powershell runs parallel and does not significantly delay the processing of the following commands.
I'm expanding upon a comment that I posted here as most people won't notice the comment.
https://lifeboat.com/programs/console.exe is a compiled version of the Visual Basic program described at https://stackoverflow.com/a/4694566/1752929. My version simply sets the buffer height to 32766 which is the maximum buffer height available. It does not adjust anything else. If there is a lot of demand, I could create a more flexible program but generally you can just set other variables in your shortcut layout tab.
Following is the target I use in my shortcut where I wish to start in the f directory. (I have to set the directory this way as Windows won't let you set it any other way if you wish to run the command prompt as administrator.)
C:\Windows\System32\cmd.exe /k "console & cd /d c:\f"
As a workaround, you may use...
Windows Powershell ISE
As the Powershell script editor does not seems to have a buffer limitation in its read-eval-print-loop part (the "blue" part). And with Powershell you may execute DOS commands as well.
PS. I understand this answer is a bit aside the original question, however I believe it is good to mention as it is a good workaround.
I have found a way to resize the buffer size without influencing the window size. It works thanks to a flaw in how batch works but it gets the job done.
mode 648 78 >nul 2>nul
How does it work? There is a syntax error in this command, it should be "mode 648, 78". Because of how batch works, the buffer size will first be resized to 648 and then the window resize will come but it will never finish, because of the syntax error. Voila, buffer size is adjusted and the window size stays the same. This produces an ugly error so to get rid of it just add the ">nul 2>nul" and you're done.

Resources