# How can I apply this function Y = d+asin(bx-c) in the code shown below? Where a represents the amplitude

**URL:** <https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787>\
**Category:** Uncategorized\
**Created:** [June 18, 2022, 12:10pm UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787 "2022-06-18T12:10:29Z")\
**Posts on this page:** 6\
**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 18, 2022, 12:10pm UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787/1 "2022-06-18T12:10:29Z")

</div>

```auto
program Make_2D_Model
	implicit none
     integer:: i,j,nx,nz 
     integer :: idepth
 character*1,allocatable,dimension(:,:) :: icode
nx=1000  
nz=500
idepth=100
	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

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-18_17-41-54](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/9/9271cb8210420cb6f46fda9a40cece29d33c5439.png)

```auto

```

---

<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, 1:15pm UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787/2 "2022-06-18T13:15:00Z")

</div>

If I understand your code:

```fortran
			if(j<=idepth)then
				icode(i,j)='1'
			elseif(j>idepth)then
				icode(i,j)='3'		
            endif

```

it defines a flat surface at j=idepth, ‘1’ is red and ‘3’ is blue in your figure. But as its name suggests, `idepth` depends on `i`. Just before the `if`, you should write something like `idepth = d + a*sin(b*i-c)`, with the good values for a, b, c, d.  
And if you want also the flat segments, it would be something like `idepth = min(d+a*sin(b*i-c), e)` where `e` is the z position of those flat segments.

---

<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, 1:24pm UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787/3 "2022-06-18T13:24:47Z")

</div>

Note also that in modern Fortran you don’t need to define yourself the unit value (2012 in your code). You can write `open(newunit=my_file, file=....` where `my_file` is an integer variable that will automatically receive an available unit number.

---

<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, 1:38pm UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787/4 "2022-06-18T13:38:40Z")

</div>

I’m usin Visual Studio 2013

---

<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, 2:38pm UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787/5 "2022-06-18T14:38:14Z")

</div>

`newunit` was introduced in Fortran 2008. It depends on the Fortran compiler you use.

---

<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:34am UTC](https://fortran-lang.discourse.group/t/how-can-i-apply-this-function-y-d-asin-bx-c-in-the-code-shown-below-where-a-represents-the-amplitude/3787/6 "2022-06-19T03:34:13Z")

</div>

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