A stand alone software using fortran / C/ C++ - c++

I need to build a standalone Windows-based software, using the Fortran and or C/C ++. I expect users to download the program, install it and use it generically in a Windows environment.
Main aim of the software is to perform complex nonlinear optimization, and possibly constrained optimization. I expect users to interact with the program using a highly interactive graphics user interface. Practically, depicting results user high-end graphics is a necessity.
I want to know whether it is possible to achieve these using freely available libraries for Fortran/C/C++.

Many, if not most, of the (freely available) open source optimization codes are written in Fortran and or C/C++. For a quick overview, please have a look at Hans Mittelmann's Decision Tree for Optimization Software.
There is also the COIN-OR Foundation, which hosts many optimization codes (most written in C/C++, I believe) and support tools. You can find the list of available projects here.
If by complex optimization you refer to complex numbers, please have a look at this SO question for further elaboration on how to formulate optimization problems involving complex numbers.

You can use Fortran to write routines for computation and transform everything into a dll.
The application can be written in C++ (for example GUI in Qt).
For visualization there are good libraries in C++, like VTK, otherwise you can use OpenGl.
If you want numerical libraries additionally, you can use LAPACK for example.

Related

What visualization libraries are available for Fortran? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
What visualization open sources or free software libraries are available for the Fortran programming language? Are there any similar to MatPlotLib for Python, for Fortran?
If not, most scientists require visualization not only to generate some outputs but also to investigate data trends, which is missing in Fortran although its speed in computation is well-known.
Note:
This question is intended to discover available, or planned to be available, graphical libraries for Fortran. It is clearly not going to compare different packages among different programming languages.
The flexibility, quality of outputs, interactivity, multi-dimensionality, free/open source etc are of factors to be discovered.
Just to make this list, a bit more complete ...
PLPLOT
GINO Suite
Winteracter
NCAR (outdated)
There is also gtk-fortran.
gtk-fortran offers also an interface to PLplot (>=5.13 in the GTK 3 branch).
I think there are some libraries available, which allow you to do directly some rendering of data from Fortran, however nothing like MatPlotLib, as far as I know.
Edit: Here is a short link collection:
http://www.astro.caltech.edu/~tjp/pgplot/
http://sourceforge.net/projects/gnuplotfortran/
http://www.mps.mpg.de/dislin/
http://www.vigyan.com/desl/FLAVOR.HTM (maybe not exactly matching here)
But the main point of the typical Fortran application is not the visualization of the data, but its generation. Typically you produce some output file, which can then be read by gnuplot or some other visualization tool. A common data container format is for example HDF5.
If there is still some need for direct visualization from within the Fortran application, you can use the ISO_C_Binding to interface with any C-Library, which should provide you with plentiful options. Still for these cases it is likely, that you will need to generate some wrapping layer around the C-API to provide an convenient usage in the Fortran application.
Free: Mjograph (2d plots only) and Veusz (2d and 3d plots)
Perhaps you can generate csv or simple space-delimited files with your Python/Compiled-Fortran code, and process using 2d plotting software like Mjograph and/or 2d/3d software like Veusz. Mjograph is only available via Mac and/or Java platform. Veusz is scriptable with Python, it was built using Python with Qt & Numpy, in fact the save file is just a plain Python script, and is comparable to gnuplot (at least in terms of ease of use). The tutorial with veusz clearly shows what the capabilities are. I like that it starts you off with the GUI, but you can wean off to pure scripting afterwards.
Mjograph: http://www.ochiailab.dnj.ynu.ac.jp/mjograph/
Veusz: https://veusz.github.io/
Veusz seems a little more natural compared to dumping data into Matlab or Mathematica. At least if you are used to pushing python and Fortran around with Bash scripts on linux.
If you insist on 3d data, I would take a second look at DISLIN, it can work quite well depending on what you need to visualize. The license is quite affordable for commericial-use. If using for academic use it's free.
Typically, a Fortran user creates massive data files then uses some 3rd party visualization software that fits the application. There are a couple of libraries that directly link to Fortran. Dislin is a fantastic one (particularly on Windows). It has a ton of documentation and once the learning curve is over you can create great GUI's as well. GnuplotFortran is an interface from Fortran to the standard gnuplot. I've yet to use it, but hear good things.
My choice would be something like PV-WAVE from Visual Numerics Inc. -- lately bought out by Rogue Wave Solutions.
This uses a big library of Fortran routines and employs its own special 4G language to speed up coding your own custom data displays.
This product is not cheap -- it was developed for applications like seismic data analysis, wind speed/direction data representation, simulation of things like airfoil flow, injection-molding cooling, stress analysis, etc -- but it is the best that I've seen.
Very clear documentation, examples supplied for each library sub-program, good help guide, direct line to tech support.
Leaves MatLab for dead.

Anyone used the MATLAB tool to produce C/C++ code? Is the resulting code viable for production use?

We have some researchers who do a lot of work in MATLAB. We often would love to try their code as part of a bigger workflow that requies the algorithms to be put into C/C++ or Python. I've seen MathWorks advertise a tool to create native C or C++ code. How good is the code? Does it support the toolboxes? I'd still see it as an early prototyping tool but wondering how good the code is. Thoughts?
I have worked with mathworks extensively in the past on this. The toolboxes are expensive, but the support is outstanding. We benchmarked code generated for a specific DSP and it was within 10% the speed of hand generated code, and took a fraction of the time to generate. Mathworks has been investing heavily in these toolchains the past several years and they are getting very good. Some toolboxes are supported, look at the docs online.
The code produced by the Embedded Coder is, in my opinion, very good and it's a product that is widely used in industry, especially in automotive applications. It's generally designed to generate code from Simulink for real-time applications though. Look at the user stories on the website: http://www.mathworks.co.uk/products/embedded-coder/?s_cid=global_nav.
Support for toolboxes depends on what your requirements are. If you need something that only uses standard libraries, then support is limited, but if that doesn't matter to you, then you may have more success.
A word of warning though: it's expensive.

C or C++ for a Robot?

Greetings,
I am trying to decide between C and C++ for my robot. I am a 5+ year veteran of Visual Basic.NET, however I'm going with Linux (Ubuntu) on this robot, and there is a compatibility problem between Linux and the .NET Framework. I want to stick with whichever language I choose for all of my projects, so I want to make sure that I choose the most appropriate one for the task.
For reference, I will describe my current robot in progress and what I am going to do with it. I am in the process of building a full-sized R4 Astromech (yep, I'm one of those guys). I have incorporated a PC motherboard with an Intel Core 2 2.1 GHz processor, 1 GB RAM. I will be using a scratch-built parallel interface card to control the drive motors, head motor, as well as a secondary parallel interface card (going to a second parallel port) which all of the sensors (IR, Ultrasonic Ranging, Visual Recognition via webcam, etc.) will be going to. Commands will be given using speech recognition (currently have a VB.NET scratch-built recognition program that I will be adapting to the new language).
Given the specifications and desired goals listed above, would I be better off with C or C++? I greatly appreciate any suggestions that you might have.
Thanks!
Thaskalas
What do you mean by a compatibility problem? Have you looked at Mono? It's an open-source implementation of the .NET libraries. It's geared toward C# not VB.NET but if you're more comfortable in a .NET environment use that. Speed isn't really an issue here as a Core2Duo is plenty fast for what you need to do.
If Mono won't work for you, I'd recommend C++. There are a lot more libraries out there for C++ (or at least, I am familiar with more, e.g. Boost), which can use most C libraries too. There's no real speed penalty for using C++. While using C wouldn't be bad per-se, C++ has some benefits and no drawbacks, so it's probably the better choice.
I would recommend using ROS. It will let you get started with a sophisticated Inter-Process Communications manager, as well as a large library of sophisticated robotics code, including multiple implementations of SLAM and other critical robotics algorithms. ROS also lets you program in multiple languages, including C, C++, and Python, so you aren't stuck with one language or another down the road.
I would also recommend C++ and ROS. In our company we're migrating to it, because there's so many people working on it, expanding it, and adding lots of cool features.
With this, you can forget about implementing most of the basic low-level stuff and start working on what you intend to research.
It's really easy to set up and start developing.
Since you're running Linux on it, I'd recommend a split approach, where you do the lower-level (device interface, where you may need fast performance) stuff in C (or C++), and the higher level stuff in a modern language like C# (using Mono) or Java, or even Python.
Python especially is hugely expressive, has a large set of libraries, and has a pretty straightforward C interface.
Writing your high-level control stuff in a low-level language like C/C++ will get old fast (IMHO). Robots should be fun!
Have you considered D? It's a fairly new language, is compiled to native code and can link directly to C. (The entire C standard library is even available from D, and bindings to the POSIX API are included in the standard library.) Basically all you need to do to use any C library from D is compile it with a C compiler and translate the function prototypes, constant declarations, etc. in the header file.
D is low-level enough that an experimental kernel is written in it, but has modern features like garbage collection (though manual memory management is still permitted), builtin strings and arrays, and more advanced/easier to use template metaprogramming facilities than C++. The biggest disadvantage is lack of a mature toolchain and libraries for enterprise-y things, but for your purposes that probably doesn't matter. BTW, if you need to do a bunch of matrix manipulation and stuff, there's the SciD project, which provides nice templated wrappers over LAPACK and BLAS.
Use C++. You have the space. You can use it "as a better C" to start with.
C++ is a bigger tool bag; why would you not want that!? You need not use all the tools, but with C you'd have no choice. Most importantly with C++ you have the choice of using both C and C++ third-party libraries.

C/C++ Library or example code for DSP Using the TI-MSP430

I am working on a little dsp project doing audio processing (e.g., Nyquist rate sampling, over- and undersampling, reconstruction) that is real-time embedded using my board. The current board/chip I am using is the msp430 series from Texas Instruments.
MSP430F5438 Experimenter Board <-- ( Among recommendation )
http://focus.ti.com/docs/toolsw/folders/print/msp-exp430f5438.html
First of all would you recommend buying a copy of matlab or octave as my main coding tool. I am using the CCS ( Code composer studio) from Texas Instruments of which came with my board.
Second is there any DSP (Open source) Library's for c/c++ that I can use for my project.
I think Matlab may be useful for getting algorithms down "on paper" without having to worry about hardware. It's also useful for the various DSP functions that you may want to try (which either come with Matlab or are available as a package/toolbox). However, a function that you get "for free" in Matlab would need to be rewritten if it doesn't exist in a C/C++ library.
Also you will eventually need to get the code into the MSP - I've used CCS in the past, as well as, IAR Systems which I was very happy with.
For your second question, check out answers to this SO question which asks the same thing. One link that looks promising is this one: http://spuc.sourceforge.net/.
Your board should have come with code examples. According to the page you linked to above, it comes with MSP430F54xx Code Examples (Rev. O) (zip 525 KB). Did you try any of these examples ?
In general, using a high-level language for algorithmic development is a great idea. I've heard, though don't know for sure, that Code Composer Studio has integration with MATLAB to the extent that you can run MATLAB code right on your target. If
this is true,
you have the budget for it, and
you're not trying to wring every last gram of performance from the chip,
then this is definitely a great feature. Otherwise, Octave is a very good alternative. It is sometimes slower than MATLAB, and doesn't have some of the more exotic toolboxes, but for prototyping and learning it's perfectly suitable and FREE.
Recently I've been using Python with NumPy for prototyping, and I'm very happy with it. You might consider this rather than MATLAB/Octave, especially if you're coming from C++. The language is easy to work with, unlike MATLAB, and the NumPy (and sometimes SciPy) extension libraries provide a lot of the same basic functionality. It is also easy to call C libraries from Python, providing an easy way to port pieces of your high-level stuff into C iteratively.
As for libraries, I've also heard good things about SPUC, which gary comtois recommended. I haven't worked with a TI chip in a while, but they used to provide some of the building blocks like sin, cos, FFT, and biquad in various application notes or even as a linkable library.
The MSP430 isn't a specialist DSP processor. However, that doesn't (necessarily) mean you can't process audio with it, but it may not be straightforward.
I'd probably try and set up a timer interrupt at the required audio sampling frequency which reads a sample from the ADC, does something to it, and outputs it to the audio DAC.
You only have a 12-bit ADC, so don't expect miracles or CD-quality audio.
void my12KHzTimer()
{
writeDAC(readADC() / 2); // DSP loop to reduce volume by 6 dB
}
writeDAC and readADC are assumed to do what they say on the tin...

Matlab vs. Visual C++? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm doing a Windows Application the uses lots of charts. Its practically a dataviewer. I started doing Matlab, because its easier, but I realized it's too slow. I wanted to change to another language. Somebody recommended me Visual C++ or Java. But Im not sure. What language should I use??
In my opinion the speed gain from going to another "faster" language is not as much as refining your algorithm.
The "problem" with MATLAB is that it allows you to do some nasty things, such as resizing your matrix in a tight loop. You should really try to pinpoint your bottlenecks using the following command:
profile on
... run your program
profile off
profile report
This will give you nice information about which function takes how long to execute and which line creates the biggest bottleneck. You can also see how many times a function is called and a M-Lint Code Check Report is included.
These measurements and hints can show you the bottlenecks of your algorithm. if your sure there isn't a way to reduce the callcount/speed of a function using a smarter algorithm. Such as do I really need that big 2d matrix where a smart vector would be large enough, or if I found a artifact, why would I still continue searching for artifacts. You could write the functions you're experiencing the most performance problems with in c/c++ and use it as a function in matlab. You can get a big speedup out of correctly choosing which functions to implement in c/c++. There is an amount of overhead with calling a c/c++ function from MATLAB, or more correctly there is a overhead in c/c++ to get the data from MATLAB, so a function which is called 10000 times will not be the best to implement in c/c++, you'd be better of with the function higher up the callstack.
It depends on what your requirements are.
The advantage of using matlab is that it's strong in numerical calculations. If you don't need that, then there is no advantage to using matlab. In this case, all those languages are okay, and many others (Python, C#, ...) as well. It depends on which language you are most comfortable with.
If you do want the advantages of matlab then:
Try optimizing in matlab. Most optimization techniques are language independent.
There are tools to translate matlab to C automatically. You can then try to compile with all optimizations on. I seriously doubt this will help much, however, especially considering the GUI part.
First and foremost, as other answers have mentioned, you need to profile your code to find out where the bottleneck is. I would check out Doug Hull's blog at The MathWorks, specifically this entry about using the profiler. This will help you find out where all the work is being done in your code.
If the source of the slowdown is associated with data processing, there may be a number of ways to speed things up (vectorizing, writing a mex file, etc.).
If the source of the slowdown is your GUI, this may be even easier to solve. There are a number of blog posts, both from Doug and other MathWorkers, which I've seen that deal with GUI design. There have also been a few questions on SO dealing with it (here's one). If you're dealing with displaying very large data sets, this submission from Jiro Doke on The MathWorks File Exchange may help speed things up.
It's hard to give you more specific advice since I don't know how you are designing your GUI, but if that turns out to be the bottleneck in displaying your data there are many resources to turn to for improving its speed before you go through the hassle of switching to a whole other language.
Don't forget that you can create functions in C++ that can be called from Matlab. And TADA, you have access to both environments !
I would use C#. It is easier than C++ and integrates well with the Windows platform. Just find a free graphing library for it and you're good to go.
There are plenty of other options depending on your preference of language. Eg. Qt with Python or C++.
As far as I know, the most common methodology is to first do the proof of concept or just the main algorithm on Matlab, because of its ease of use and convenience for math calculations, and after that to translate it to a "real" programming language in order to improve the performance. Usually C or C++ act as the "real" language, but in your case, aiming to do a Windows application, perhaps C# will be the best option.
I found that GUI programming in MATLAB can get really nasty if your application gets more complex. BTW MATLAB can also be called from Java easily (and vice versa, current versions basically provide an interactive Java console).
Just as a side note, if you still need the math power of Matlab, you may want to check out Scilab. It's open-source and free, and it has examples of how it can be integrated with other C# or C++. I have created projects on which Scilab was running in the background to perform all the data math operations; and displaying them with C#'s ZedGraph library. Worked like magic!
I suggest you using Java and the JFreeChart (http://www.jfree.org/jfreechart/) library. I found very easy (and fast) developing applications with a lot of charts of different typologies. If you don't need particularly fast performances, you can use Java. I suppose that there are similar libraries for C#, but I'm not sure.
An alternative to Matlab and Scilab is another free software: Octave.
I don't know about Scilab, but Octave syntax is nearly the same as matlab so you can import code with minimal effort.
If you need fancy toolboxes though, Scilab and Octave might let you down, so check this.
You can execute Octave functions in a C++ program:
http://en.wikipedia.org/wiki/GNU_Octave
I do not think that you can call your own m-files functions from your C++ program though. In the past, the Matlab compiler would let users run matlab programs without installing Matlab, but not without installing a huge library (250 MB if I remember correctly). Nevermind if your Matlab program took 20 kB, you had to distribute the huge library.
Please someone edit/comment on the situation today!
It has been a while since I used the GUI "ability" of Matlab, but back then (2005) I found it awful. Ugly, hard to use, very hard to maintain, dependent on user settings of windows parameters.
Please comment or edit on that too, they may have made progress!
If they have not, I believe that Matlab is NOT the way to go for a program that you want to deliver to anyone.
If you can use Visual Studio for doing your GUI, do that. I second the earlier opinions: go with what you're comfortable with.
If you need the Matlab functions, go with what you're comfortable with, that supports Matlab libraries.
First of all Visual C++ is not a language is an IDE for developing applications.
Second... Which languages do you know? You can have several options. Take a look to:
C++ + Qt (Mine preferred option, powerful and easy to understand)
C# + .NET or WPF
Java
If you can tell more information we could find a language that matches your needs.