How to type this part of the code correctly?

do i=1,nx
    do j=1,nz
        if(i<=600&&i>=500&&j<=-50&&j>=-60)then
            icode(i,j)='3'
        endif
    enddo
enddo

In Fortran, the AND operator is .and.

4 Likes

Logical operators: Operators and flow control - Fortran Programming Language

1 Like

icode(500:600, -60:-50) = '3'

4 Likes

Yes, but maybe the array has shape [nx,nz], and depending on the values of nx and nz, that could cause an out-of-bounds error.

2 Likes

If the code posted by OP is literally as shown, when j ranges from 1 to nz the condition j <= -50 is never satisfied, and the seven lines of code can be removed entirely!

1 Like

Just a quick and perhaps irrelevant reminder, if you do

if (  AAA .operator. BBB . operator.  CCC .operator. ...  )

It will be better to make sure all the AAA, BBB, CCC, etc are defined and have valid values. Otherwise it may cause some error. For example, see

1 Like