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

**URL:** <https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783>\
**Category:** Uncategorized\
**Created:** [June 17, 2022, 1:40pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783 "2022-06-17T13:40:08Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![1988](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/1988/32/1103_2.png) [@1988](https://fortran-lang.discourse.group/u/1988)\
**Post date:** [June 17, 2022, 1:40pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/1 "2022-06-17T13:40:08Z")

</div>

```fortran
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)

```

---

<div class="post-metadata">

**Author:** ![1988](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/1988/32/1103_2.png) [@1988](https://fortran-lang.discourse.group/u/1988)\
**Post date:** [June 17, 2022, 1:41pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/2 "2022-06-17T13:41:19Z")

</div>

![Snipaste_2022-06-17_21-29-16](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/0/06ec8e974c8131b60bf0190b78883fd77571c96a.png)

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [June 17, 2022, 1:58pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/3 "2022-06-17T13:58:58Z")

</div>

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](https://fortranwiki.org/fortran/show/Libraries).

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [June 17, 2022, 2:23pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/4 "2022-06-17T14:23:36Z")

</div>

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](https://stdlib.fortran-lang.org/interface/save_npy.html) and loading the data to matplotlib be easier?

savetxt is another alternative: [savetxt – Fortran-lang/stdlib](https://stdlib.fortran-lang.org/interface/savetxt.html)

---

<div class="post-metadata">

**Author:** ![Shahid](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahid/32/3672_2.png) [@Shahid](https://fortran-lang.discourse.group/u/Shahid)\
**Post date:** [June 17, 2022, 2:48pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/5 "2022-06-17T14:48:47Z")

</div>

Dislin is freely available now. [Dislin](https://www.dislin.de/index.html). I have been using it for a while. It is an amazing library.

---

<div class="post-metadata">

**Author:** ![awvwgk](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/awvwgk/32/154_2.png) [@awvwgk](https://fortran-lang.discourse.group/u/awvwgk)\
**Post date:** [June 19, 2022, 8:56am UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/6 "2022-06-19T08:56:42Z")

</div>

3 posts were split to a new topic: [Dislin plotting library](https://fortran-lang.discourse.group/t/dislin-plotting-library/3796)

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [June 17, 2022, 3:04pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/7 "2022-06-17T15:04:03Z")

</div>

There’s also [pyplot-fortran](https://github.com/jacobwilliams/pyplot-fortran) by @jacobwilliams.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [June 17, 2022, 3:18pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/8 "2022-06-17T15:18:41Z")

</div>

See [Graphics, plotting and user interfaces - Fortran Programming Language](https://fortran-lang.org/packages/graphics)

---

<div class="post-metadata">

**Author:** ![Aurelius\_Nero](https://avatars.discourse-cdn.com/v4/letter/a/a87d85/32.png) [@Aurelius\_Nero](https://fortran-lang.discourse.group/u/Aurelius_Nero)\
**Post date:** [June 17, 2022, 10:49pm UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/9 "2022-06-17T22:49:35Z")

</div>

I recommend the program gnuplot for this

> **[gnuplot](https://sourceforge.net/projects/gnuplot/)**
>
> Download gnuplot for free. A portable, multi-platform, command-line driven graphing utility. A famous scientific plotting package, features include 2D and 3D plotting, a huge number of output formats, interactive input or script-driven options, and a...

[http://www.gnuplot.info/](http://www.gnuplot.info/)

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

> [@How to solve the same numerical Problem in 7 different Programming Languages](https://fortran-lang.discourse.group/t/how-to-solve-the-same-numerical-problem-in-7-different-programming-languages/3548/10):
>
> I tried to improve his code Compiler: ifort Flags: -O3 I didn’t understand why he needed two subroutines He also adds some overhead with the subroutine call inside a loop I added some comments and spaces to make the code readable I also graph the data at the end If possible, how can I improve his code further ? program simple\_num\_prob implicit none integer :: i integer,parameter :: tf=25,n=10000 real,allocatable :: t(:),u(:) real :: dt real(kind=8) :: t1,t2 character(len=\*),…

Here are some videos on how to use gnuplot with Fortran

[![](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/3/3eee98a8a7dd2656b0409d15e4d6a9721b126d95.jpeg "Modern Fortran by Example (7) Gnuplot Part 1") ](https://www.youtube.com/watch?v=z-3Q9sCuDqk)

[![](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/b/be7694bb8595e3e91cda57337f7e14781d7b6afb.jpeg "Modern Fortran by Example (8) Gnuplot Part 2") ](https://www.youtube.com/watch?v=Xd2DIhxsLOI)

[![](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/2/2dc03b7f6eb0af623636c665dcbdc4e2e41911f0.jpeg "Modern Fortran by Example (9) Gnuplot Part 3") ](https://www.youtube.com/watch?v=jZ7uhZZHluI)

---

<div class="post-metadata">

**Author:** ![1988](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/1988/32/1103_2.png) [@1988](https://fortran-lang.discourse.group/u/1988)\
**Post date:** [June 18, 2022, 9:55am UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/12 "2022-06-18T09:55:27Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [June 18, 2022, 11:24am UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/13 "2022-06-18T11:24:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![1988](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/1988/32/1103_2.png) [@1988](https://fortran-lang.discourse.group/u/1988)\
**Post date:** [June 19, 2022, 3:17am UTC](https://fortran-lang.discourse.group/t/how-i-can-draw-a-surface-wave-model-like-the-figure-below/3783/14 "2022-06-19T03:17:52Z")

</div>

![IMG-20220619-WA0000](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/6/64de870d04c120e6e58c538855d23dda4567ea6d.jpeg)
