# Compiling MEGAN3.2: ERROR: IF clause requires a scaler LOGICAL expression

**URL:** <https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351>\
**Category:** MEGAN\
**Created:** [June 16, 2022, 1:58pm UTC](https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351 "2022-06-16T13:58:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rrezaei83](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@rrezaei83](https://forum.cmascenter.org/u/rrezaei83)\
**Post date:** [June 16, 2022, 1:58pm UTC](https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351/1 "2022-06-16T13:58:52Z")

</div>

Hi everyone,  
I try to compile MEGAN3.2 using _gfortran_ compiler. After execution of the makefile, I get this error:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/b/ba7673fba395cb84fad40063e6cd0a1817df2c12.jpeg)

These are the related lines of _readmcip.f_ file:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/8/84007f19f9711e64468ea144ff596de95fd9feee.jpeg)

And this is the makefile of _MET2MGN_:

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/cmas/original/2X/c/cd32e097fdd5d9e9f6d7e1f61fbeb3619d03bde7.jpeg)

Could anyone help me to solve the problem?  
Thank you for any help in advance.

Reza,

---

<div class="post-metadata">

**Author:** ![amirdudu](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@amirdudu](https://forum.cmascenter.org/u/amirdudu)\
**Post date:** [June 16, 2022, 3:58pm UTC](https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351/2 "2022-06-16T15:58:13Z")

</div>

Hi Reza,  
Again, [MEGAN 3.2 Error While Running and Compiling - #5 by f.garcia](https://forum.cmascenter.org/t/megan-3-2-error-while-running-and-compiling/2976/5) this has helped me solve the problem that you have mentioned.

One of the posts says " Then I did something which don’t think is the right approach to these problems, but it worked. I changed “LFIRST” from logical to integer and changed the code to this:

```auto
        if((sdate+2000000).eq.jdate.and.(stime*100).eq.jtime) then
          lfirst = 100
        else
          lfirst = 50
        endif 
        if (lfirst==100) then

```

LFIRST is only used in this part of the code so I don’t think that there will be a problem with this change (I really have no idea whether I am write or wrong here)."

Hope it works for you too.  
Amir

---

<div class="post-metadata">

**Author:** ![rrezaei83](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@rrezaei83](https://forum.cmascenter.org/u/rrezaei83)\
**Post date:** [June 16, 2022, 4:03pm UTC](https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351/3 "2022-06-16T16:03:22Z")

</div>

@amirdudu  
Dear Amir,  
Thank you for your reply. I will test it.

---

<div class="post-metadata">

**Author:** ![cjcoats](https://avatars.discourse-cdn.com/v4/letter/c/ac8455/32.png) [@cjcoats](https://forum.cmascenter.org/u/cjcoats)\
**Post date:** [June 16, 2022, 4:55pm UTC](https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351/4 "2022-06-16T16:55:48Z")

</div>

No. `LFIRST` is never declared in _readmcip.f_ – but it should have been. And _gfortran_ is much more insistent upon Standard-compliant code than PGI Fortran…  
Edit line 20 in this file so that it declares it properly:

> ```
> `logical MCIP_rad,SAT_par,ENVYN,INITIAL_HOUR,ifsoil,lfirst`
> 
> ```

Likewise, _readpar.f_ uses illegal `PARAMETER` statements: lines 15-16 should be

> ```auto
> INTEGER, parameter :: mx=350
> INTEGER, parameter :: my=410
> INTEGER, parameter :: mz=30
> INTEGER, parameter :: nlat=61
> INTEGER, parameter :: nlon=121
> 
> ```

Aside: MEGAN is a code that is badly in violation of the coding standards that should be in place, and is seriously in need of review by a scientific-programming software engineer. In particular, a code that does not use `IMPLICIT NONE` throughout is seriously not to be trusted. And FWIW, I/O API routine M3ERR (used throughout this code) was declared **obsolete; do not use** back in late 1992.

---

<div class="post-metadata">

**Author:** ![rrezaei83](https://avatars.discourse-cdn.com/v4/letter/r/53a042/32.png) [@rrezaei83](https://forum.cmascenter.org/u/rrezaei83)\
**Post date:** [June 16, 2022, 9:17pm UTC](https://forum.cmascenter.org/t/compiling-megan3-2-error-if-clause-requires-a-scaler-logical-expression/3351/5 "2022-06-16T21:17:22Z")

</div>

@cjcoats  
I appreciate your response. This resolved the problem. _readwrfcamx.f_ file requires the same change as well.

Best regards,
