forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using Numerical Recipes with FTN95

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
jlb



Joined: 21 Oct 2020
Posts: 7

PostPosted: Mon Dec 21, 2020 2:30 pm    Post subject: Using Numerical Recipes with FTN95 Reply with quote

Some recipes (Numerical Recipes in Fortran 90: Volume 2, by W.H. Press et al.) use a subsidiary routine (xxx_private) for sharing / hiding data. The principle is given in the following example, without any original calculation for copyright reasons.
In its original version, the example fails at execution time with "access violation, the instruction at address xx attempted to write to an illegal location", after the value of j having been corrrectly displayed (j in mcof: 3).
Code:
PROGRAM xmin
  IMPLICIT NONE
  INTERFACE
    SUBROUTINE fg(i)
      IMPLICIT NONE
      INTEGER, INTENT(IN) :: i
    END SUBROUTINE fg
  END INTERFACE
  INTERFACE
    SUBROUTINE mmin(funcs,j)
      IMPLICIT NONE
      INTERFACE
        SUBROUTINE funcs(i)
          INTEGER, INTENT(IN) :: i
        END SUBROUTINE funcs
      END INTERFACE
      INTEGER :: j
    END SUBROUTINE mmin
  END INTERFACE
  CALL mmin(fg,3) 
END PROGRAM xmin

SUBROUTINE mmin(funcs,j)
  IMPLICIT NONE
  INTERFACE
    SUBROUTINE funcs(i)
      INTEGER, INTENT(IN) :: i
    END SUBROUTINE funcs
  END INTERFACE
  INTEGER :: j
  CALL mmin_private 
  CONTAINS
  SUBROUTINE mmin_private
    IMPLICIT NONE
    CALL mcof
  END SUBROUTINE mmin_private
  SUBROUTINE mcof
  IMPLICIT NONE
    WRITE(*,*) 'j in mcof: ', j
    CALL funcs(0)
  END SUBROUTINE mcof
END SUBROUTINE mmin

SUBROUTINE fg(i)
  IMPLICIT NONE
  INTEGER, INTENT(IN) :: i
  WRITE(*,*) 'fg: ',i+1
END SUBROUTINE fg

I made a modification at the subroutine mcof to correct this, see below, but I cannot figure out why this should be necessary.

Code:
  SUBROUTINE mmin_private
    IMPLICIT NONE
    CALL mcof(funcs)
  END SUBROUTINE mmin_private
  SUBROUTINE mcof(funcs)
    IMPLICIT NONE
    INTERFACE
      SUBROUTINE funcs(i)
        INTEGER, INTENT(IN) :: i
      END SUBROUTINE funcs
    END INTERFACE
    WRITE(*,*) 'j in mcof: ', j
    CALL funcs(0)
  END SUBROUTINE mcof

Compiler version: FTN95 8.70


Last edited by jlb on Mon Dec 21, 2020 5:16 pm; edited 2 times in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 6679
Location: Salford, UK

PostPosted: Mon Dec 21, 2020 4:43 pm    Post subject: Reply with quote

jlb

This appears to be a fault in FTN95 and I have made a note of this.

The statement ordering is not correct at line 16 but that makes no difference to the outcome.
Back to top
View user's profile Send private message AIM Address
jlb



Joined: 21 Oct 2020
Posts: 7

PostPosted: Mon Dec 21, 2020 5:22 pm    Post subject: Reply with quote

Paul

Thanks for your attentive reviewing. I corrected this line in the source code above, sorry for the mistake, the interface for mmin doesn't seem to be required though.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group