使用 MATLAB 的绘图功能作为 Fortran 程序的交互部分
尽管你们中的许多人只要阅读标题就会对我的目标有一个很好的了解 - 请允许我做一个简单的介绍。
我有一个 Fortran 程序 - 它由一个程序、一些内部子例程、7 个带有自己的程序的模块组成,并且......嗯,就是这样。
无需详细介绍,因为我认为目前没有必要,使用 MATLAB 绘图功能(主要是带有一些自定义功能的plot(x,y))作为交互式工具的最简单方法是什么?我的程序的一部分?现在我正在使用一些我自己的自定义绘图例程(基于 HPGL 和 Calcomp 的例程),但只是作为我练习的一部分,我想看看它会走向何方以及它将如何工作(这是否可能是我所建议的?)。另外,我需要付出多少努力?
我知道这个主题已经在网上的许多“教程”中得到了相当广泛的描述,但由于某种原因,我很难找到真正简单但说明性的介绍性教程。因此,如果有人可以发布一两个简单的例子,我将非常感激。或者直接拉着我的手指导我完成一个工作示例。
平台:IVF 11.something :) 在 Win XP SP2、Matlab 2008b 上
Although many of you will have a decent idea of what I'm aiming at, just from reading the title -- allow me a simple introduction still.
I have a Fortran program - it consists of a program, some internal subroutines, 7 modules with its own procedures, and ... uhmm, that's it.
Without going into much detail, for I don't think it's necessary at this point, what would be the easiest way to use MATLAB's plotting features (mainly plot(x,y) with some customizations) as an interactive part of my program ? For now I'm using some of my own custom plotting routines (based on HPGL and Calcomp's routines), but just as part of an exercise on my part, I'd like to see where this could go and how would it work (is it even possible what I'm suggesting?). Also, how much effort would it take on my part ?
I know this subject has been rather extensively described in many "tutorials" on the net, but for some reason I have trouble finding the really simple yet illustrative introductory ones. So if anyone can post an example or two, simple ones, I'd be really grateful. Or just take me by the hand and guide me through one working example.
platform: IVF 11.something :) on Win XP SP2, Matlab 2008b
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是让您的 Fortran 程序写入文件,然后让您的 Matlab 程序读取这些文件以获取您想要绘制的信息。我的大部分数字运算工作都是在 Linux 上进行的,因此我不完全确定 Windows 如何处理一个进程写入文件并同时处理另一个进程读取文件的情况。
不过,这有点混乱,因此您可能需要考虑使用 Matlab 调用 Fortran 程序(或其部分)并直接获取数据以进行绘图。在这种情况下,您需要研究 Matlab 文档中的创建 Fortran MEX 文件。如果您愿意使用 Matlab 来驱动流程并使用 Fortran 作为计算服务,那么这相对简单,并且可以满足您的需求。我会在随 Matlab 分发的示例中查找简单的 Fortran MEX 文件。
最后,您可以从 Fortran 程序中调用 Matlab,搜索调用 Matlab 引擎的文档。对我来说,了解这如何满足您的需求有点困难,而且这也不是我非常熟悉的东西。
如果您再次发布更详细的信息,我也许可以提供更具体的提示,但您可能应该开始卷起袖子,深入研究 MEX 文件。
The easiest way would be to have your Fortran program write to file, and have your Matlab program read those files for the information you want to plot. I do most of my number-crunching on Linux, so I'm not entirely sure how Windows handles one process writing a file and another reading it at the same time.
That's a bit of a kludge though, so you might want to think about using Matlab to call the Fortran program (or parts of it) and get data directly for plotting. In this case you'll want to investigate Creating Fortran MEX Files in the Matlab documentation. This is relatively straightforward to do and would serve your needs if you were happy to use Matlab to drive the process and Fortran to act as a compute service. I'd look in the examples distributed with Matlab for simple Fortran MEX files.
Finally, you could call Matlab from your Fortran program, search the documentation for Calling the Matlab Engine. It's a little more difficult for me to see how this might fit your needs, and it's not something I'm terribly familiar with.
If you post again with more detail I may be able to provide more specific tips, but you should probably start rolling your sleeves up and diving in to MEX files.
继续讨论 DISLIN 作为解决方案,答案不适合评论...
@MSB - 你好。我很抱歉写下你的答案,但这些评论太短了,以答案的形式回答问题是......无论如何......
DISLIN 的快速绘图功能 - - 例程 QPLOT 只需三个参数即可绘制曲线:X 数组、Y 数组和数字 N。请参阅手册第 16 章。加上只需几次额外的调用即可选择输出设备并标记轴。我没有使用过这个,所以我不知道自动缩放有多好。
是的,我知道 Quickplot,它有相关的例程,但它对于我的需求来说太固定了(无法改变任何东西),是的,它的自动缩放有点古怪。另外,graf 内的边距太大。
或者,如果您想使用 GRAF 的功能来设置图形框,可以使用子例程 GAXPAR 来自动生成推荐值。 -2 作为 LABDIG 的第一个参数自动确定刻度线标签中的位数。
你尝试过常规吗?
抱歉,我在 dislin 索引中找不到您引用的 GAXPAR 例程。你确定它的名字是完全一样的吗?
MSB回复:是的,我确定GAXPAR的拼写。这是 DISLIN 9.5 PDF 手册第 4 章中的最后一个例程。也许这是一个新的惯例?还有另一种实现自动缩放的途径:SETSCL——参见第 6 章。
到目前为止,我一直在做的事情(除了一些“duck Tape”解决方案之外)
它将把极值就在轴上。你知道我怎样才能在外面有一个“主要刻度边距”,以便在曲线和轴之间放置一些区域(同时仍然保持setscl的效果)?
即使你不喜欢内置的自动缩放,如果您已经在使用 DISLIN,那么滚动您自己的自动缩放将比从 MATLAB 调用 Fortran 更容易。您可以使用 Fortran 内部函数 minval 和 maxval 来查找数据中的最小值和最大值,然后编写一个子例程以向外舍入为“好的”舍入值。同样,决定刻度线间距的子程序。
这实际上并不是那么容易实现(如果有想法证明我是错的,我们将很高兴)。或者我应该说,如果你知道你的价值观的大致范围,那就很容易了。但如果你不这样做,而且你也不知道
无论您的值在 13-34 范围内还是在 1330-3440 范围内,那么...
...如果我在这里完全走错了路,请解释一下您是否同意不同的东西。我的英语有些欠缺,所以我只能希望上面的内容是可以理解的。
在确定圆形图开始/结束值的子例程中,您可以将实际的最小/最大值缩放到始终在 1 和 10 之间,然后有一个表格来选择合适的舍入值,然后取消缩放回到正确的范围。
--
Continuing the discussion of DISLIN as a solution, with an answer that won't fit into a comment...
@M. S. B. - hello. I apologize for writing in your answer, but these comments are much too short, and answering a question in the form of an answer with an answer is ... anyway ...
There is the Quick Plot feature of DISLIN -- routine QPLOT needs only three arguments to plot a curve: X array, Y array and number N. See Chapter 16 of the manual. Plus only several additional calls to select output device and label the axes. I haven't used this, so I don't know how good the auto-scaling is.
Yes, I know of Quickplot, and it's related routines, but it is too fixed for my needs (cannot change anything), and yes, it's autoscaling is somewhat quircky. Also, too big margins inside the graf.
Or if you want to use the power of GRAF to setup your graph box, there is subroutine GAXPAR to automatically generate recommended values. -2 as the first argument to LABDIG automatically determines the number of digits in tick-mark labels.
Have you tried the routines?
Sorry, I cannot find the GAXPAR routine you're reffering to in dislin's index. Are you sure it is called exactly like that ?
Reply by M.S.B.: Yes, I am sure about the spelling of GAXPAR. It is the last routine in Chapter 4 of the DISLIN 9.5 PDF manual. Perhaps it is a new routine? Also there is another path to automatic scaling: SETSCL -- see Chapter 6.
So far, what I've been doing (apart from some "duck tape" solutions) is
which will put the extreme values right on the axis. Do you know perhaps how could I go to have one "major tick margin" on the outside, as to put some area between the curve and the axis (while still keeping setscl's effects) ?
Even if you don't like the built-in auto-scaling, if you are already using DISLIN, rolling your own auto-scaling will be easier than calling Fortran from MATLAB. You can use the Fortran intrinsic functions minval and maxval to find the smallest and largest values in the data, than write a subroutine to round outwards to "nice" round values. Similarly, a subroutine to decide on the tick-mark spacing.
This is actually not so easy to accomplish (and ideas to prove me wrong will be gladly appreciated). Or should I say, it is easy if you know the rough range in which your values will lie. But if you don't, and you don't know
whether your values will lie in the range of 13-34 or in the 1330-3440, then ...
... if I'm on the wrong track completely here, please, explain if you ment something different. My english is somewhat lacking, so I can only hope the above is understandable.
Inside a subroutine to determine round graph start/end values, you could scale the actual min/max values to always be between 1 and 10, then have a table to pick nice round values, then unscale back to the correct range.
--
放弃 Matlab,因为它是专有的、昂贵的、臃肿/缓慢的,并且代码不容易并行化。
你应该做的是使用 DISLIN、PLplot、GINO、gnuplotfortran 等方面的东西。
Dump Matlab because its proprietary, expensive, bloated/slow and codes are not easy to parallelize.
What you should do is use something on the lines of DISLIN, PLplot, GINO, gnuplotfortran etc.