Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intrensic error

Status
Not open for further replies.

Astrodude

Programmer
Jun 10, 2010
7
US
Hello everyone

I'm using gfortran on SUSE to compile my code and receive the following error:
Code:
       yr_step = sign(1,delta_yr)                             
                       1
Error: 'b' argument of 'sign' intrinsic at (1) must be the same type and kind as 'a'

Here's my code:
Code:
        subroutine solar_loc(yr,t1,mean_long,declination)
        implicit none
        

        integer*2 yr,yr_step,delta_yr,i,iyr
        integer*4 t1
        integer*4 index
        real*4 mean_long,declination
        real*8 d,lambda,g,eps,L
        real*8 L0(10)/279.642,279.403,279.165,278.926,279.673,279.434,
     1                279.196,278.957,279.704,279.465/
        real*8 DL/0.985647/
        real*8 G0(10)/356.892984,356.637087,356.381191,356.125295,
     1    356.854999,356.599102,356.343206,356.087308,356.817011,356.56/
        real*8 DG/0.98560028/
        real*8 EPS0(10)/23.440722,23.440592,23.440462,23.440332,
     1    23.440202,23.440072,23.439942,23.439811,23.439679,23.439548/
        real*8 DE/-0.00000036/
        real sind,asind
        save

        d = 0

        if (yr .lt. 1900) then
           index = yr - 88
        else
           index = yr - 1988
        endif

        if (index .le. 0) then   
           delta_yr = index - 1  
        else if (index .gt. 10) then
           delta_yr = index - 10
        else 
           delta_yr = 0
        endif

        if (index .le. 0) index = 1
        if (index .gt. 10) index = 10

        yr_step = sign(1,delta_yr)
        delta_yr = abs(delta_yr)  


        do i = 1,delta_yr
          if (yr_step .gt. 0) then
            iyr = 98 + i - 1
          else 
            iyr = 89 - i
          end if
          if (mod(iyr,4).eq.0)then
            d = d + 366*yr_step   
          else
            d = d + 365*yr_step
          end if
        end do  

        d = d + t1/86400.

        L = L0(index) + DL*d
        g = G0(index) + DG*d
        do while (L.lt.0)   
          L = L + 360.      
        end do
        do while (g.lt.0)
          g = g + 360.   
        end do

        L = mod(L,360.0d0)
        g = mod(g,360.0d0)

        lambda = L + 1.915*sind(g) + 0.020*sind(2*g)
        eps = EPS0(index) + DE*d

        declination = asind(sind(eps)*sind(lambda))
        mean_long = L
        return
        end

Any suggestions? Thanks in advance!

 
sign(a, b) returns a with the sign of b. Both must be of the same type. In your case, you have a being INTEGER and b being INTEGER*2. Try
Code:
yr_step = sign(1_2,delta_yr)
Alternatively
Code:
integer*2 yrpositive
...
yrpositive = 1
...
yr_step = sign(yrpositive, delta_yr)
I prefer the first method but people who don't know the notation will moan about it in code reviews.
 
Both of the methods work well, but I'm sticking with the first one.

Now however I receive the error:
Code:
Function 'sind' has no IMPLICIT type

My guess is to fix this with:
Code:
real sind

Agree?
 
Agreed.

sind is one of those routines that may be intrinsic on some compilers (eg IVF). On others you have to define it.
 
Right.

So I added
Code:
real sind

But now the compiler complains
Code:
undefined reference to sind

Why is that?
 
sind is an intrinsic on some compilers but not on others. You can define it as
Code:
real function sind(angle_deg)
real angle_deg
sind = sin(angle_deg * 3.1415926535 / 180.0)
end function sind
 
Thanks! That does the trick.

But what about...
Code:
 lambda = L + 1.915*sind(g) + 0.020*sind(2*g)             
1
Error: Unclassifiable statement at (1)

 
At a guess, it doesn't like mixing the types. Why not just make everything real*8
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top