Hi,
I want to create a file and write data in that file as shown below to use the 'pm3d' command in Gnuplot and plot a 3D contour graph. I want to add one blank space line when the value of the X variable changes. How to write data like this in a file?
Example :
X Y Z
1 1 2
1 2 5
1 3 10
2 1 5
2 2 8
2 3 13
3 1 10
3 2 13
3 3 18
Am 13.07.22 um 08:24 schrieb Pratik Patel:
Hi,
I want to create a file and write data in that file as shown below to use the 'pm3d' command in Gnuplot and plot a 3D contour graph. I want to add one blank space line when the value of the X variable changes. How to write data like this in a file?
Example :
X Y Z
1 1 2
1 2 5
1 3 10
2 1 5
2 2 8
2 3 13
3 1 10I onestly think you should start with the data structure holding the x,
3 2 13
3 3 18
y, and z values. How is the data being read in? Do you employ DO
loops, explicit or implicit?
If you employ DO loops it should be an easy task to adapt them to your
output needs.
Jakob
If you mean you already have some arrays X,Y,Z of simple integers just about any
format would do. If you mean you want to do it in one line it is possible with the
MERGE intrinsic and an implied DO, but that would start to obfuscate the code.
As noted, if you could show a sample code it might be you can print the data as
you generate it and not have to create the data arrays, etc. Do you mean you just
want something like this?
program testitThank you so much, John. This code will work for me.
implicit none
! generate some sample data
integer,parameter :: i=100
integer :: x(i),y(i),z(i), j
real :: r(i)
call random_number(r)
x=r*10
call random_number(r)
y=r*10
call random_number(r)
z=r*10
! write the arrays adding a line when the X value changes
write(*,'("X Y Z")')
do j=1,i
if(x(j).ne.x(max(1,j-1))) write(*,*)
write(*,'(*(g0,1x))')x(j),y(j),z(j)
enddo
end program testit
..
Thank you so much, John. This code will work for me.
On Wednesday, July 13, 2022 at 4:44:48 PM UTC+5:30, John wrote:
If you mean you already have some arrays X,Y,Z of simple integers just about any
format would do. If you mean you want to do it in one line it is possible with the
MERGE intrinsic and an implied DO, but that would start to obfuscate the code.
As noted, if you could show a sample code it might be you can print the data as
you generate it and not have to create the data arrays, etc. Do you mean you just
want something like this?
program testit
implicit none
! generate some sample data
integer,parameter :: i=100
integer :: x(i),y(i),z(i), j
real :: r(i)
call random_number(r)
x=r*10
call random_number(r)
y=r*10
call random_number(r)
z=r*10
! write the arrays adding a line when the X value changes
write(*,'("X Y Z")')Thank you so much, John. This code will work for me.
do j=1,i
if(x(j).ne.x(max(1,j-1))) write(*,*)
write(*,'(*(g0,1x))')x(j),y(j),z(j)
enddo
end program testit
Hi,.
I want to create a file and write data in that file as shown below to use the 'pm3d'
command in Gnuplot and plot a 3D contour graph. I want to add one blank space line when the value of the X variable changes. How to write data like this in a file?
Example :
X Y Z
1 1 2
1 2 5
1 3 10
2 1 5
2 2 8
2 3 13
3 1 10
3 2 13
3 3 18
On Wednesday, July 13, 2022, at 7:55:42 AM UTC-4, Pratik Patel wrote:@FortranFan
..@Pratik Patel,
Thank you so much, John. This code will work for me.
You may also keep in mind the Fortran-lang site and the Discourse there if you have further needs and interests with Fortran:
https://fortran-lang.org/
https://fortran-lang.discourse.group/
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 159 |
Nodes: | 16 (0 / 16) |
Uptime: | 99:33:56 |
Calls: | 3,209 |
Files: | 10,563 |
Messages: | 3,009,786 |