How I can draw a surface wave model like the figure below?

program Make_2D_Model
	implicit none
	integer :: radius, cx, cy
     integer:: i,j,nx,nz 
     integer :: idepth
 character*1,allocatable,dimension(:,:) :: icode

nx=1000  
nz=500
idepth=100
radius=20
 cx=500 !Center-X
 cy=40  !Center-y
	allocate(icode(1:nx,1:nz))	
	do i=1,nx
		do j=1,nz
			if(j<=idepth)then
				icode(i,j)='1'
			elseif(j>idepth)then
				icode(i,j)='3'		
            endif
		enddo
    enddo

    do i=1,nx
        do j=1,nz
            if(((i-cx)**2+(j-cy)**2)<=radius**2)then
                icode(i,j)='2'
            endif
        enddo
    enddo


open(2012,file='model.txt',status='unknown')
		do j=1,nz
			write(2012,1000)(icode(i,j),i=1,nx)
		enddo
	close(2012)
	1000 format(<nx>a1)

    end program Make_2D_Model
![Snipaste_2022-06-17_21-29-16|690x420](upload://ZfGwp8qMj5y21HhRlNPtCX59fs.png)

2 Likes

1 Like

You will need to use some graphics library if you want to do it from the Fortran program or you will need a graphics tool of sorts that can convert the character encoding into a picture. There are plenty of possibilities, which makes it difficult to give specific advice. You may want to examine the Wiki page Libraries in Fortran Wiki.

3 Likes

Why does this have to be done with a compiled language like Fortran? Wouldn’t Python or R be better suited for this job? Wouldn’t using stdlib’s save_npy – Fortran-lang/stdlib and loading the data to matplotlib be easier?

savetxt is another alternative: savetxt – Fortran-lang/stdlib

3 Likes

Dislin is freely available now. Dislin. I have been using it for a while. It is an amazing library.

3 Likes

3 posts were split to a new topic: Dislin plotting library

There’s also pyplot-fortran by @jacobwilliams.

4 Likes

See Graphics, plotting and user interfaces - Fortran Programming Language

3 Likes

I recommend the program gnuplot for this

http://www.gnuplot.info/

Here is a simple example of where I use gnuplot from Fortran to plot some data:

Here are some videos on how to use gnuplot with Fortran

3 Likes

I want to create a model for the two ground layers, where the first layer is represented by the number(1), and the second layer is an irregular surface layer represented by the number (2). I want to print the result in a (TXT. file).

1 Like

The shape of your surface can be easily obtained with a sinus function combined with a min() function for the flat segments.

2 Likes

IMG-20220619-WA0000

1 Like