From: Craig Powers on
Allamarein wrote:
> On 11 Mag, 23:20, Craig Powers <craig.pow...(a)invalid.invalid> wrote:
>> Allamarein wrote:
>>> On 11 Mag, 23:01, Craig Powers <craig.pow...(a)invalid.invalid> wrote:
>>>> Allamarein wrote:
>>>>> Let's suppose I produced 2 arrays
>>>>> REAL, DIMENSION (0:MAX_SIZE) :: T,Y
>>>>> where max_size is an appropriate integer.
>>>>> May you suggest a code that create a GRAPH.PLT to see a T (x axis)-
>>>>> Y(y axis) plot by gnuplot ?
>>>>> I would export T and Y in a single file called DATA.DAT too.
>>>>> May you proposed codes?
>>>> OPEN(UNIT=out_unit, FILE='DATA.DAT', STATUS='NEW')
>>>> DO I = 0, MAX_SIZE
>>>> WRITE(out_unit,*) T(I), Y(I)
>>>> ENDDO
>>>> Assumes appropriate declarations for I and out_unit. 'NEW' may not be
>>>> the best status, but it's an appropriate approximation. List-directed
>>>> format may not end up being what you want, but it's a nice easy starting
>>>> point.
>>>> I'm not familiar with gnuplot, so I'll leave the manipulation of the
>>>> data file as an exercise to you or other follow-ups.
>>> I'm a newbie.
>>> What means 'Assumes appropriate declarations for I and out_unit' ?
>>> Sorry, be patient....
>> INTEGER :: I
>> INTEGER, PARAMETER :: out_unit = 20
>>
>> out_unit doesn't have to be 20, but it should probably be greater than 9
>> (single-digit unit numbers risk colliding into compiler extensions that
>> pre-connect units with special destinations, like stderr, stdin, stdout,
>> and so on).
>
> status="new" gets error if I have just the file (of course).
> Shall I delete that before re-run?
> How can I modify my code?

Read your favorite Fortran reference for alternative statuses. My
preferred online reference is:
http://h21007.www2.hp.com/portal/download/files/unprot/fortran/docs/lrm/dflrm.htm

It only goes up to Fortran 95, but there are other places I can go if I
need newer stuff.
From: e p chandler on

"Allamarein" <matteo.diplomacy(a)gmail.com> wrote in message
news:1d0dbd64-079b-4846-9e47-6e11bdc4d743(a)p2g2000yqh.googlegroups.com...
> Let's suppose I produced 2 arrays
>
> REAL, DIMENSION (0:MAX_SIZE) :: T,Y
>
> where max_size is an appropriate integer.
> May you suggest a code that create a GRAPH.PLT to see a T (x axis)-
> Y(y axis) plot by gnuplot ?
> I would export T and Y in a single file called DATA.DAT too.
>
> May you proposed codes?

FIRST you have to know the data format required by gnuplot. see
http://www.duke.edu/~hpgavin/gnuplot.html
for a tutorial.

Next you write a Fortran program that writes the contents of the array to
your data file. I suspect that you will be able to use list directed
formatting to write your output file instead of having to line up your data
in columns but YMMV.

Here's an outline

open the output file
for index_var = its_min to its_max
write to the output file T(index_var), Y(index_var)
close the output file

You can even automate the process so that GnuPlot takes its commands from a
script in a command file.

- Elliot




From: rudra on
On May 12, 2:42 am, Allamarein <matteo.diplom...(a)gmail.com> wrote:
> status="new" gets error if I have just the file (of course).
> Shall I delete that before re-run?
> How can I modify my code?
status='NEW' means you are going to have a new file, and gives error
if the file already exists.
may be you can try status='replace' or just delete the file before a
fresh run.
From: ndl_91 on
On 11 mai, 22:46, Allamarein <matteo.diplom...(a)gmail.com> wrote:
> Let's suppose I produced 2 arrays
>
> REAL, DIMENSION (0:MAX_SIZE) :: T,Y
>
> where max_size is an appropriate integer.
> May you suggest a code that  create a GRAPH.PLT to see a T (x axis)-
> Y(y axis) plot by gnuplot ?
> I would export T and Y in a single file called DATA.DAT too.
>
> May you proposed codes?

Hi. There are several ways for drawing a curve from a code...
The simplest, you mentionned, is to write it outside the code but you
could imagine invoking gnuplot directly from your code by using a UNIX
pipe or a FIFO file. It allows you to produce real time vizualisation.
Tell me if your intersted in more details.
Anyway, Here is what you asked for :

>cat test.f90

program test
implicit none
integer, parameter :: MAX_SIZE=10
integer :: I_unit, I
real(kind=8), dimension(0:MAX_SIZE) :: T, Y
!
! Create your DATA
T(:)=(/ (real(I,kind=8), I=0,MAX_SIZE) /)
Y(:)=T(:)**2
!
! Write It to a file
I_unit=10
open(unit=I_unit,file="DATA.DAT",status="unknown",form="formatted")
do I=0,MAX_SIZE
write(I_unit,'(E15.7,1X,E15.7)') T(I),Y(I)
enddo
close(I_unit)
end program test

>cat GRAPH.PLT

reset
set title "My pretty graph"
set xl "t (s)"
set yl "Y (m)"
set key top left
set key Left reverse
set grid
plot "DATA.DAT" u 1:2 w lp lw 2 title "My curve"
set term push
set term postscript solid enhanced color colortext
set output "DATA.eps"
rep
set o
set term pop

Then you can call this script from gnuplot (load "GRAPH.PLT") or
simply by invoking gnuplot -persist GRAPH.PLT

Hope it helps,
NL