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)
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.
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
Dislin is freely available now. Dislin. I have been using it for a while. It is an amazing library.
3 posts were split to a new topic: Dislin plotting library
There’s also pyplot-fortran by @jacobwilliams.
I recommend the program gnuplot for this
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
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).
The shape of your surface can be easily obtained with a sinus function combined with a min()
function for the flat segments.