Call mencoder from Fortran or gnuplot - fortran

I have made a Fortran program thats plot a vector field with gnuplot, I want to make a animation of this. I have managed to print a 1000 pictures with the name framee_000000001.png, framee_000000002.png, framee_000000003.png and so on. Now i want to compile these pictures into a single movie. A user named bibi suggested i should use mencoder and gave me the following code: mencoder mf://frame_%09d.png -mf fps=30 -ovc lavc -o my_video.avi
I want to call on mencoder from Fortran or gnuplot, is this possible? In that case how?

You can use system call which works fairly well depending on platform and compiler. For example you can call from fortran,
call system("mencoder mf://frame_%09d.png -mf fps=30 -ovc lavc -o my_video.avi")

Related

Is there a utility supporting g++ or clang memory resident compilation?

Apache commons provides a Java API to compile code without loading it from a file. Is there any similar API for C++, either g++ or clang? I would like to be able to have the compiler loaded in memory and feed it code to compile without having to run it every time, and without having to load the code from a file.
GCC accepts input from a pipe:
> echo 'int main(){}'|g++ -x c++ -o prog -
note: you need to specify the language -x c++ and the end hyphen - is important.

How to configure gnuplot-iostream with C++?

I'm a complete noob to gnuplot and linux in general. I need to plot scientific graphs for my project for which I will be using C++. After looking for various plotting options available, I've decided to use gnuplot for plotting due to its features and quality of graphs. So I downloaded gnuplot as a program and could plot the graphs using .dat files, however I need to plot the graphs within C++ without explicitly launching gnuplot. Is it possible to plot dynamic graphs using gnuplot? I would also like to plot the solution as is it computed for every time step!
I came to know that gnuplot-iostream interface makes this possible. However I did not understand how to install this library for C++ at all. I do not understand Git, or anything posted on the website to be able to configure that library. Can anybody point me to the tutorial/how to document for the same? I have Ubuntu 12.04 and also Windows 8.1.
Is it possible to configure this library with an IDE (I'm using code::blocks), if yes how that can be done?
First of all gnuplot-iostream relies on the Boost library, it is a very common library, but it doesn't come together with the C++ compiler, so make sure it is properly installed.
Obviously it also needs gnuplot: if it is properly installed you should be able to launch it from the terminal.
Then paste this minimal example in a file main.cpp:
#include <vector>
#include <utility>
#include "gnuplot-iostream.h"
int main() {
std::vector<std::pair<double,double>> data;
data.emplace_back(-2,-0.8);
data.emplace_back(-1,-0.4);
data.emplace_back(0,-0);
data.emplace_back(1,0.4);
data.emplace_back(1,0.8);
Gnuplot gp;
gp << "plot [-5:5] sin(x) tit 'sin(x)', '-' tit 'data'\n";
gp.send1d(data);
return 0;
}
Save the header gnuplot-iostream.h in the same folder and compile with:
g++ -std=c++11 main.cpp -o main -lboost_iostreams -lboost_system -lboost_filesystem
When running ./main you should get a plot of the sine function and of the few dots.
recently I was using Gnuplot to visualize data from an iterative solver. To run Gnuplot in "pseudo" real-time I did the following steps:
establish a pipeline from C++ to Gnuplot:
FILE *GnuPipe = popen("...\bin\pgnuplot -persist","w");
start the solver (or data source) and write to a file e.g. 'data.txt'
start a script which tells Gnuplot to replot the data.txt as long as flag is NOT set. In this case I created a text file 'flag.txt' and wrote in a=0, which serves as flag. The script for Gnuplot could look like:
load 'flag.txt'
plot 'data.txt' u 1:2 with lines
pause 0.1
if (a==0) reread
if the solver converges, or if there is no further data to plot, set a=1 in the 'flag.txt'
Gnuplot is loading the 'flag.txt' and sees that the flag is set and stops rereading.

Compiling DISLIN gfortran

I am having trouble compiling Fortran code with references to DISLIN. I have downloaded DISLIN from the website, unzipped the file and ran the setup. I have added an environment variable called DISLIN (C:\dislin) and added C:\dislin\win to the PATH section of my system variables.
I am trying to compile some example code of the DISLIN website which includes line
USE DISLIN
I am using a MinGW shell to compile with command gfortran -o progrname -ldislin EX11_1.f90 and am getting the following error:
Fatal Error: Cant open module file 'dislin.mod' for reading at (1): No such file or directory.
I have tried changing the variable path and even moving the dislin.mod file (which is there) but still get the same message.
Ok I fixed this problem so thought I come back and post what worked for me incase any one else needs it...
Install both DISLIN and MinGW on the c drive
Copy disgf.a from /c/dislin and dislin.f90 from /c/dislin/gf into the directory containing your fortran files
(for me this is /c/MinGW/pnote)
Using the MinGW shell navigate to you files: cd /c/MinGW/pnote
compile dislin.f90 and your fortran program: gfortran -c dislin.f90 progName.f90 (dislin.f90 obviously only needs to be done once)
link libraries etc and compile: gfortran progName.o disgf.a -luser32 -lgdi32 -lopengl32 -o exeName
'run' exeName
You probably need to specify the path to the DISLIN module files:
gfortran EX11_1.f90 -o progrname -ldislin -I/path/to/DISLIN/modules
and, if not already configured like described here, also the path to the library itself:
gfortran EX11_1.f90 -o progrname -ldislin -I/path/to/DISLIN/modules \
-L/path/to/DISLIN/library
They provide a batch file (windows) to do the compiling and linking for you.
f90link -c My_Program
This is located in c:\dislin\Win
Also, if you are having trouble with the dislin.mod file which resides in c:\dislin\gf then recompile that with the -c compile option. I found all of this info in c:\dislin\readme.inf
near as I can tell (Jan 2018) dislin (64 bit) fails miserably with gfortran 7.2, period; and probably with many other newer compilers.
When trying to link, gfortran 7 says 'dislin.mod' is an unrecognizable format.
I think this program is highly dependent on exactly correct version synchronization - something that renders such software useless imho after many years in research.
and no, the correctness of various 'paths' seems not to help.
after all, gnuplot works, "at all". Not sure why I spent so much time on brand x.
jrc

Embedding prolog engine in a dll

I've been working on a C++ application that embeds a prolog reasoning engine lately and, as stated in the title, I am now trying to generate a DLL instead of an executable so I can use it in another project. Since I am new to DLL development, I thought I could start with a small example. I have 3 files:
likes.pl: sample prolog file defining the predicate likes/2
likes.cpp: defining the function get_food() that calls PlQuery and return the results in a std::string
food.cpp: using the DLL to list all kinds of food that Sam likes
So my first try was the following:
swipl-ld -shared -dll -o likes -goal true likes.cpp likes.pl -DLIKES_EXPORTS -v
g++ -o food.exe -s food.cpp -L. -llikes -I. -L"c:/program files (x86)/swipl/lib" -lswipl -I"c:/program files (x86)/swipl/include"
First of all, let me point out that when get_food() only returns a string without any call to prolog, this works fine. However, after two days of investigation, I can't figure out how to get the DLL to call prolog. I think there are two things I am possibly doing wrong, maybe both: the PlEngine intialization and the saved state.
I've tried both calling PlEngine in get_food() and in food.cpp main() function, same result. So for now I am sticking to the first option since I am more interested in having everything done in the DLL. I see here (Embedding SWI-Prolog in a dll) that it can later be done in the DllMain but also that it is not recommended. What is the best way to do it? Should I give food.exe asargv[0] or something else (libswipl.dll? a saved state?)
Secondly, I noticed that one difference when using swipl-ld to generate a DLL instead of an EXE is that it ommits the lines:
swipl.exe -f none -F none -g true -t"consult(['likes.pl']),qsave_program('pltmp-4228.exe',[goal=true,toplevel=prolog,init_file=none])"
cat pltmp-4228.exe >> food.exe
So I tried to do it manually, replacing the random name by "mystate.exe" and using the Win32 copy /b command to append it to food.exe. This makes food.exe a toplevel console where I can test likes/2. Is it because the Dll doesn't have any main()? Anyway, this is the furthest I could get for now and I guess there were a few things to change in the qsave_program/2 second argument. I tried replacing toplevel=prolog with stand_alone=true. By the way, the command example given at the end of (http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%272.10%27,swi%28%27/doc/Manual/compilation.html%27%29%29) doesn't generate any file at all. Anyway, I can't figure out if and how exactly I have to do this either.
Can anyone tell me how to solve this?
Forgive me, as this is not really a precise answer to your problem, just a report about my experience on the topic.
I've been working on pqConsole, a DLL that introduces Qt bindings via the C++ interface.
pqConsole, while still in development, has so far found its way in swipl-win, and I had the joy to work together with Jan Wielemaker making this little big step for Prolog audience widening.
I would suggest to build your DLL with G++, to get binary compatibility, and release SWI-Prolog component(s) as-is.
If you like Qt, you can use QtCreator for interface design, see for instance fdqueens.
There you can also see how I used to embed .pl in Qt project resources, to have more control about the application (users can't mess with the Prolog logic that's required from other parts) and over the release (no .pl to add, just the executable/DLL).
HTH
Solved it! In case somebody needs the answer someday:
int main(int argc, char *argv[]) {
char* av[50];
av[0] = (char*)"food.exe";
av[1] = (char*)"-x";
av[2] = (char*)"mystate.exe";
if(!PL_initialise(3, av))
cout << "NO init\n" ;
else
cout << "OK init\n" ;
cout << get_food() ;
getchar();
return 0;
}
Then:
swipl --goal=true --stand_alone=true -o mystate -c likes.pl
swipl-ld -shared -dll -o likes -goal true likes.cpp likes.pl -DLIKES_EXPORTS -v
g++ -o food.exe food.cpp -L"c:/program files (x86)/swipl/lib" -lswipl -I"c:/program files (x86)/swipl/include" -L. -llikes -I.

Issues compiling vmware web api client code into useable objects

I'm using vmware's web application api in an attempt just to simply retrieve the fields in the "ServiceContent" object. There is an example of how this should be accomplished located at the vmware forum. The example contained there compiles fine for me however I get segfaults when running the simple example - specifically the trace goes back to the soap_serializeheader() function (I believe these are defined in stdsoap2.cpp). My problem is that I do not know how to avoid this segfault and have no idea why this is occurring (as I am following the example almost word for word). I am using OS X tool chain (gcc version 4.0.1 (Apple Inc. build 5465) ) combined with (gsoap release 2.7.16). I tried gsoap 2.8 but got the same result. Below is the procedure I used to get to where I am now.
These are the commands I used to parse the wsdl:
wsdl2h -o vim25.h vimService.wsdl
Once this is parsed, I compiled using the following command:
soapcpp2 -x -C -pvsp vim25.h -I/place/where/stlvector.h/is
this generates files vspC.cpp, vspClient.cpp, and vspVimBindingProxy.cpp. Internally these files have the same prefixes for functions (i.e. ns1/ns2 etc) so my calls are the same as those in the example.
This is the command I am using to compile vspC.cpp and vspClient.cpp:
g++ -DWITH_COOKIES -DWITH_OPENSSL -c vspC.cpp
g++ -DWITH_COOKIES -DWITH_OPENSSL -c vspClient.cpp
This is the command I use to compile stdsoap2.cpp (if I do not compile with -DWITH_NONAMESPACES I get an error about an undefined symbol "_namepspaces" when I link everything):
g++ -DWITH_COOKIES -DWITH_OPENSSL -DWITH_NONAMESPACES -c stdsoap2.cpp
I then link everything together with the test code (again this is copied almost identically from the example, just with the changes to correctly refer to the files I created):
g++ -DWITH_COOKIES -DWITH_OPENSSL vspC.o vcpClient.o stdsoap2.o testcase.cpp -lssl -lcrypto -o doesntwork
This compiles correctly, but of course fails to run. I read about an OS X user in this vmware forum post who was also having trouble. It appears the gsoap guide says you cannot use stdsoap2.cpp's header and fault serialization codes, and you must compile them separately. The user in the OS X post seems to have done this, however I am not sure how to incorporate them into my test file (he creates the empty env.h file and then compiles it with soap2cpp) - if I include the envH.h file i get about naming conflicts with vspH.h. So a second question would be how do I use soap2cpp to compile all the stubs correctly so that there are not namespace conflicts (which is what I appear to be encountering).
I will not provide the source, as it is displayed at the first vwmare forum link by user stumpr. I do not believe the issue is in the source, but in the way I have used either wsdl2h, soap2cpp, or some incorrect combination of flags during compilation with g++.
Thanks for taking a look, and hopefully some one can resolve the issue!
EDIT I think I may have solved this - by using a 64bit system (and one with more memory). I tried compiling with -m32 on the X.6 and it was not able to do it (complaining about memory issues).
Hopefully someone will stumble upon this and be happy to know the answer.