Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Help with scigraph

Roland_P_
Beginner
873 Views

Hi,

In a university project I need to write codes in Fortran to create user subroutines which are then used by a modelling software. One of my tasks is to plot XY graphs. I tried to use SCIGRAPH, but I don't know how to do the plotting, when data are read from file.

I’ve read the manual of it, in which is written, that I have to use the following structure, and I have to add how many points I want to plot:

REAL*4 array(2,7,1) !(seven means, that I want to plot seven x-y points)

DATA array / x1,y1, x2,y2, x3,y3, .....  x7,y7/

To count the number of data (usually it’s unknown) in the used file I wrote a simple program, that works, so I think it isn’t a problem, but I don't know how I should modify the given sample to do the plotting from file.

I would be grateful, if somebody could help me with this problem.

Please consider that I am a beginner programmer, so I’m quite new to VS and Parallel Studio, any help/suggestions are welcome!

Thanks in advance!

Roland

0 Kudos
14 Replies
Steve_Lionel
Honored Contributor III
873 Views

Have you studied the SCIGRAPH sample? It demonstrates use of most of the plot types.

0 Kudos
Roland_P_
Beginner
873 Views

Hello Steve!

First of all I want to thank You to deal with my problem.

I studied the sample file, in which the plotted points are given in direct way like that:

"640,0.52,  660,0.54, 680,0.57, 720,0.59, 740,0.60, 760,0.62, 770,0.63,".

But I've so many points in the created file, that I couldn't give them in the code one by one.

Could You tell me, how can I solve this problem in an easy way?

And I think it's an another problem, that my data in the mentioned file (which I create) are in another structure, as in the sample program. For the better understanding I attach one of my txt file.

Thank for Your time!

Roland

0 Kudos
Steve_Lionel
Honored Contributor III
873 Views

I can't tell you how to write your program, but as SCIGRAPH.TXT says, all data to be plotted is passed in the form of an array. So first you need to read your data into an array, and then call the appropriate plotting subroutine. The XYDemo subroutine in the demo source could be adapted to your use - instead of that subroutine's use of DATA to define the array, you'd read the values from your text file.

Just be aware that if you are using SCIGRAPH that you must build your application as a "QuickWin" project. This is one of the project type choices when you create the project.

0 Kudos
Roland_P_
Beginner
873 Views

Dear Steve,

I'm not sure that I can use "QuickWin" project. Could You recommend me other possibility to do the plotting?

Roland

0 Kudos
Steve_Lionel
Honored Contributor III
873 Views

Why can't you use QuickWin? If for some reason you can't, then you can't use SCIGRAPH.

Other choices are  PGPLOT and PLplot. I have never used these.

0 Kudos
andrew_4619
Honored Contributor II
873 Views

Roland P. wrote:
Dear Steve,

I'm not sure that I can use "QuickWin" project. Could You recommend me other possibility to do the plotting?

Roland

Excel!

0 Kudos
Roland_P_
Beginner
873 Views

Dear Steve,

the codes, that I have to write to the modelling program (Cycle-Tempo) which is mentioned in my very first question requires ".for" extension. The ".for" file which I've to use/overwrite is created earlier by the developer direct for CT.

If I wrote the plotting code/program in a QuickWin project can I call it in the .for file as a module?

Sorry, if the question is amateur, but I'm really a beginner in Fortran programming.

Thanks,

Roland

0 Kudos
Steve_Lionel
Honored Contributor III
873 Views

Sure - .for simply is a convention to tell the compiler that the source is fixed-form. While fixed-form is not recommended for new development, it is fully supported and can do everything free-form source can do. See:

Doctor Fortran in "Source Form Just Wants to be Free"

0 Kudos
andrew_4619
Honored Contributor II
873 Views

 I need to write codes in Fortran to create user subroutines which are then used by a modelling software. 

It sounds to me that you need to write user subroutines that are used in an existing application e.g. FEA system, thus the talk of Quickwin etc is not relevant as you are not making a complete application just some specific code fragments. If i understand correctly the user subroutine has two tasks, to grab specific data from the modeller and then maybe produce some graphical output. The quickest/easiest way of doing this is to grab and format the data into suitable files and then graph these in some third party existing software package. I think you need to be a bit more explicit in describing what you are trying to do and the scope of your project,

 

0 Kudos
Johannes_Rieke
New Contributor III
873 Views

Hi, I agree Andrew that it makes more sense to write the data with your user routine in a formatted way, so that you can plot the data with whatever is best suited for you. I've to deal often with very similar cases and prefer using Gnuplot (http://www.gnuplot.info/), which eats a lot of simple formats (space or comma separated lists). Alternatively, if you have python installed, matplotlib is a very powerful lib. You can show plots also easily in an interactive window. Jacob Williams has written an easy to use interface for Fortran, which generates the python scripts automatically (https://github.com/jacobwilliams/pyplot-fortran).

Best regards, Johannes

ps: Gnuplot and Python/matplotlib are open source...

0 Kudos
Roland_P_
Beginner
873 Views

Dear Andrew and Johannes,

You see my task well. Cycle-Tempo is a program for the thermodynamic modeling and optimatization of systems for the production of electricity, heat and refrigeration. The developers of the program gave the users different subroutines, which you can modify your model and collect data.

It can work with different mediums (e.g. water/steam, natural gas, refrigerants), but it can plot diagrams just for the water/steam cycles.

One of our goals in the project to write a subroutine, which can plot working circuits besides the water/steam (e.g. Rankine circuit). For this I have to grab the required data and do the plotting.

Earlier I tried the mentioned GNUPLOT, and it worked correctly, but my project leader said, that it would be better, if we don’t have to use third party program. But for plan ’B’ I kept GNUPLOT.

I think my only problem with SCIGRAPH is, that I couldn’t declare a single array in the required structure in a general way (e.g. with x and y), which is mentioned in one of my former comments.

I would be grateful, if somebody could help with it. If I’m not able to solve this problem I think I’ll use GNUPLOT.

Thanks for YOUR time and help!

Roland

0 Kudos
mecej4
Honored Contributor III
873 Views

This is one way to read (x,y) pairs from a file. Read the file once to find how many data pairs it contains. Rewind the file, allocate the arrays x() and y(), and read the file again, this time putting the values into the arrays. Here is a sketch of the code, which you should flesh out with declarations, etc,, and adapt to your requirements.

    open(unit=20, file='xy.dat', form='formatted')
    n = 0
    do
       read(20,*,end=100)xx, yy
       n = n+1
    end do
100 allocate(x(n),y(n))
    rewind(20)
    read(20,*)(x(i),y(i),i=1,n)
    close(20)

 

0 Kudos
Johannes_Rieke
New Contributor III
873 Views

Hi Roland, as far as I understand, you have to write a subroutine which is linked into the main code of Cylce-Tempo in a Quickwin environment. You already managed to get data and write a suited input file for Gnuplot. Now you like to modify your subroutine to call Scigraph to get the desired plot and you do not know how the data should be formatted?

Without knowing the exact interface I would guess you need to have something like this:

! define an array
integer                      :: i_dim, j_dim, k_dim
real(4), allocatable :: my_array(:,:,:)

! do some stuff and get knowledge of  i_dim, j_dim, k_dim
! i_dim = 2 -> 2D -> x, y
! j_dim == number of data points in a set
! k_dim == number of data sets
! e.g.: my_array(2, 7, 3) -> 2D, 7 points, 3 data sets
allocate(my_array(i_dim, j_dim, k_dim)

! fill data with life
my_array(1,2,3) = ....

! call Scigraph
call PlotMultiData(xyGraph,my_array,k_dim,xyDataSets,xyAxes(1),xyAxes(2))

! finish your code

The only information about Scigraph I found is this (http://jp.xlsoft.com/documents/intel/cvf/cvf_pg.pdf). The interfaces are confusing, But I think the above definition should work.

0 Kudos
Steve_Lionel
Honored Contributor III
873 Views

Scigraph is provided as one of the sample programs. It is fairly well documented in a text file that is included with the code, as well as the example program calling various Scigraph routines. It is not a "feature" of the Intel Fortran product (the same was true of CVF.)

0 Kudos
Reply