• Write format specifiers

    From Pratik Patel@21:1/5 to All on Tue Jul 12 23:24:44 2022
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jakob Mendel@21:1/5 to All on Wed Jul 13 09:06:50 2022
    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 10
    3 2 13
    3 3 18

    I onestly think you should start with the data structure holding the x,
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pratik Patel@21:1/5 to Jakob Mendel on Wed Jul 13 00:18:29 2022
    On Wednesday, July 13, 2022 at 12:37:02 PM UTC+5:30, Jakob Mendel wrote:
    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 10
    3 2 13
    3 3 18
    I onestly think you should start with the data structure holding the x,
    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

    I have employed Do Loop implicitly and generated data.
    There are 16k data points so can not be done manually.
    I'm looking for some format that can be used with write command.

    Pratik

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to All on Wed Jul 13 04:14:46 2022
    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")')
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John@21:1/5 to All on Wed Jul 13 04:32:29 2022
    As noted, you could do the printing all with one line of code, but it becomes very unclear
    what the line is doing versus a simple DO loop as per above.

    program testit
    implicit none
    integer,parameter :: i=100
    integer :: x(i),y(i),z(i), j
    real :: r(i)
    character(len=1) :: nl=new_line('a')
    call random_number(r)
    x=r*10
    call random_number(r)
    y=r*10
    call random_number(r)
    z=r*10

    write(*,'(4(g0,1x))') ' X','Y','Z','',(nl(:merge(1,0,x(j).ne.x(max(1,j-1)))), x(j),y(j),z(j),j=1,i)

    end program testit

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pratik Patel@21:1/5 to John on Wed Jul 13 04:55:40 2022
    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")')
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From FortranFan@21:1/5 to Pratik Patel on Wed Jul 13 06:00:07 2022
    On Wednesday, July 13, 2022 at 7:55:42 AM UTC-4, Pratik Patel wrote:

    ..
    Thank you so much, John. This code will work for me.

    @Pratik Patel,

    You may also to 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/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From FortranFan@21:1/5 to Pratik Patel on Wed Jul 13 05:56:47 2022
    On Wednesday, July 13, 2022 at 7:55:42 AM UTC-4, Pratik Patel wrote:
    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")')
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robin Vowels@21:1/5 to Pratik Patel on Wed Jul 13 06:18:12 2022
    On Wednesday, July 13, 2022 at 4:24:47 PM UTC+10, Pratik Patel wrote:
    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?
    .
    Use a WRITE statement with format control.
    .
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Pratik Patel@21:1/5 to FortranFan on Wed Jul 13 09:34:15 2022
    On Wednesday, July 13, 2022, at 6:30:12 PM UTC+5:30, FortranFan wrote:
    On Wednesday, July 13, 2022, at 7:55:42 AM UTC-4, Pratik Patel wrote:

    ..
    Thank you so much, John. This code will work for me.
    @Pratik Patel,

    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/
    @FortranFan
    Thank you so much for providing links. As I'm a beginner and will need to use this site frequently.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)