!
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
!
!         <<<<<---------------------------------------------->>>>>
!         <<<<<      7. I N T R I N S I C                    >>>>>
!         <<<<<         P R O C E D U R E S                  >>>>>
!         <<<<<---------------------------------------------->>>>>
!
!&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

! Intrinsic procedures are important because
!
! 1. They allow for increased efficiency when handling arrays on vector
!    or parallel computers
!
! 2. they extend the power of the language by providing access to 
!    facilities that are not otherwise available (inquiry functions 
!    for optional arguments, length of a character string ...)


!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Elemental numeric functions
!

  ABS(A)      ! returns the absolute value of an argument A of type 
              ! real, integer or complex

  AIMAG(X)    ! returns the imaginary part of the complex variable X

  AINT(A[,KIND]) ! truncates a real value A towards zero to produce a 
                 ! real that is a whole number 

  ANINT(A[,KIND]) ! returns a real whose value is the nearest whole 
                  ! number to the real value A

  CEILING(A) ! returns the least default integer greater than or equal 
             ! to its real argument

  FLOOR(A)   ! returns the greatest default integer less than or equal 
             ! to its real argument           

  CMPLX(X[,Y][,KIND]) ! converts X or (X,Y) to complex.

  INT(A[,KIND]) ! converts real A to integer type (truncated towards 
                ! zero)

  NINT(A[,KIND]) ! returns the integer value that is nearest to real A

  REAL(A,[,KIND]) ! converts to real type A (that may be integer, real 
                  ! or complex. In the latter case the imaginary 
                  ! part is ignored

                  
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Elemental functions that do not convert
!
!

  CONJG(Z) ! returns the conjugate of the complex value Z

  MAX(A1,A2[,A3, ...] ! returns the maximum of two or more integer 
                      ! or real values

  MIN(A1,A2[,A3, ...] ! returns the minimum of two or more integer 
                      ! or real values

  MOD(A,P)  ! returns the remainder of A modulo P, that is 
            ! A - INT(A/P)*P. If P=0 the result is processor-dependent

  SIGN(A,B) ! returns the absolute value of A times the sign of B
            ! A and B must be both integers or both real


!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Elemental mathematical functions 
!
!  
          
  ACOS(X)   ! arc cosine, expressed in radians in the range [0,Pi]

  ASIN(X)   ! arc sine, expressed in radians in the range [-Pi/2,Pi/2]

  ATAN(X)   ! Arc tangent, expressed in radians in the
            ! range [-Pi/2,Pi/2]     

  ATAN2(X,Y) ! The result is the principal value of the argument 
             ! of the complex number (X,Y), expressed in radians
             ! and in the range [-Pi,Pi] 
             ! The values of X and Y must not both be zero

  COSH(X)    ! returns the parabolic cosine function for real X

  SINH(X)    ! returns the parabolic sine function for real X
             
  TANH(X)    ! returns the parabolic tangent function for real X
           
  LOG(X)     ! return the natural logarithm for a real or complex 
             ! value of X. In the real case, X must be positive.
             ! In the complex case, X must not be zero and the imagnary
             ! part of the result lies in the range [-Pi,Pi]

  EXP(X)     ! returns the exponential function of X (real or complex)

  LOG10(X)   ! returns the common (base 10) logarithm of a real 
             ! argument, which must be positive

  SQRT(X)    ! returns the square root of X. If X is real, it must not
             ! be negative. If X is complex, the real part of the result 
             ! is positive .

  SIN(X)     ! returns the sine function of a real or complex X,
             ! which is treated as a value in radians
              
  COS(X)     ! returns the cosine function of a real or complex X,
             ! which is treated as a value in radians

  TAN(X)     ! returns the tangent function of a real or complex X,
             ! which is treated as a value in radians
           

!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Character-integer conversions 
!
!  

  ACHAR(I)   ! is of type character of lenght 1 and returns the 
             ! character in the ASCII collating sequence in positon I
             ! (must be between 1 and 127 to be processor-independent) 

  IACHAR(C)  ! is of type integer and returns the position
             ! in the ASCII collating sequence corresponding to the 
             ! character of length 1 C.



!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! String-handling functions 
!
!  

  ADJUSTL(STRING)   ! Adjusts left to return a string of the same 
                    ! length as STRING where all leading blanks are
                    ! removed and an equal number of trailing blanks 
                    ! are inserted

  ADJUSTR(STRING)   ! Adjusts right to return a string of the same 
                    ! length as STRING where all trailing blanks are
                    ! removed and an equal number of leading blanks 
                    ! are inserted                  

  INDEX(STRING,SUBSTRING[,BACK]) ! has type default integer and returns 
                                 ! the starting position of the string
                                 ! SUBSTRING as a substring of STRING,
                                 ! or zero if it does not occur as a
                                 ! substring. If BACK is absent or 
                                 ! present with value .FALSE.  the 
                                 ! the starting positon of the first 
                                 ! such substring is returned. If BACK 
                                 ! is present with value .TRUE. the 
                                 ! starting position of the LAST 
                                 ! such substring is returned

   LEN_TRIM(STRING) ! returns a default integer whose value is the 
                    ! length of STRING without trailing blancks

   SCAN(STRING,CH[,BACK])     ! returns a default integer which is 
                              ! the position of the character CH 
                              ! in the string STRING,
                              ! substring. If BACK is absent or 
                              ! present with value .FALSE.  the 
                              ! position of the leftmost such characters
                              ! is returned.  If BACK is present with 
                              ! value .TRUE. the rightmost position of
                              ! suchc character is returned


   LEN(STRING) ! enquiry function that returns a scalar default integer
               ! holding the number of characters in STRING

   REPEAT(STRING,N_COPIES)   ! produces a string which is the 
                             ! concatenation of N_COPIES copies of 
                             ! STRING

   TRIM(STRING)  ! returns STRING with all trailing blancks removed


!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Matrix operations 
!
!  

  DOT_PRODUCT (U, V) ! requires two arguments, each of
                     ! rank one and of the same size.
                     ! 
                     ! if U is REAL or INTEGER, it returns
                     !
                     ! SUM_i  U(i) V(i) 
                     ! 
                     ! if U is complex, it returns
                     !
                     ! SUM_i  U*(i) V(i) 

  C = MATMUL (A,B) 
  
  MATMUL (A, B)      ! Three cases are possible
                     ! 
                     ! 1.
                     ! A has shape (n,m) and B has shape (m,k) 
                     ! The result has shape (n,k) and element (i,j)
                     ! has value 
                     !
                     ! SUM_p  A(i,p) B(p,j)
                     !
                     ! 2.
                     ! A has shape (m) and B has shape (m,k) 
                     ! The result has shape (k) and element (j)
                     ! has value 
                     !
                     ! SUM_p  A(p) B(p,j)
                     !
                     !
                     ! 3.
                     ! A has shape (n,m) and B has shape (m) 
                     ! The result has shape (n) and element (i)
                     ! has value 
                     !
                     ! SUM_p  A(i,p) B(p)
                     !

 TRANSPOSE(A)        ! returns the matrix transpose 
 
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
! Transformational functions that reduce arrays 
!
! SINGLE-ARGUMENT CASE  
  
  LOGICAL, ARRAY(10) :: MASK
  ALL(MASK)                       ! returns the value .TRUE. if 
                                  ! all elements of MASK are true
                                  ! and .FALSE. otherwise

 
  LOGICAL, ARRAY(10) :: MASK
  ANY(MASK)                       ! returns the value .TRUE. if 
                                  ! any of the elements of MASK are true
                                  ! and .FALSE. otherwise

  
  LOGICAL, ARRAY(10) :: MASK
  COUNT(MASK)                     ! returns an integer that counts 
                                  ! the number of elements of the 
                                  ! logical array MAS that have 
                                  ! the value .TRUE.

  MAXVAL(A)                       ! returns the maximum value of an 
                                  ! element of the integer or real 
                                  ! array A

  MINVAL(A)                       ! returns the minimum value of an 
                                  ! element of the integer or real 
                                  ! array A

  PRODUCT(A)                      ! returns the product of the   
                                  ! elements of the integer or real 
                                  ! array A
                                  
  SUM(A)                          ! returns the sum of the   
                                  ! elements of the integer or real 
                                  ! array A

!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! Optional argument DIM
!

! It is possible to use one of the above SINGLE-ARGUMENT functions 
! on an array of rank > 1 by selecting a given dimension 
!
! Example

  REAL, DIMENSION(10,10,10) :: A
  REAL, DIMENSION(10,10)    :: Q
  Q = SUM(A,DIM=2)                     ! Q has value SUM(A(I,..,J))

!  Q(1,2) is the sum of the rank one vector A(1,:,2)  
  
!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! Optional argument MASK
!

! The functions MAXVAL, MINVAL, PRODUCT and SUM have an optional 
! third argument, a logical array MASK. This specifies logical 
! conditions to restrict the operations

! EXAMPLE

 REAL, DIMENSION(10) :: A
 REAL S
 S = SUM(A, MASK = A>0)   ! This sums only the positive elements of A


!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! ARRAY INQUIRY FUNCTIONS
!
! 
!  SIZE(ARRAY[,DIM])  
!
! Returns the size of the array ARRAY or extent along dimension DIM
! if the scalar integer DIM is present

! Example 
!

  REAL, DIMENSION(100) :: A
  N = SIZE(A)  

  REAL, DIMENSION(100,100) :: B
  N = SIZE(B,DIM=1)


!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
!
! RANDOM NUMBERS 
!
! The subroutine RANDOM_NUMBER return a pseudo-random number with 
! uniform distribution in therange [0,1]. It can be called with a 
! vector argument 

! Example:

  REAL, DIMENSION(10000) :: Z
  CALL RANDOM_NUMBER(Z)

! The subroutine RANDOM_SEED(SIZE) may be used to reset the SEED
! The integer SIZE is the size of the seed array (INTENT = OUT)
! Example

  REAL, DIMENSION(10000) :: Z1, Z2
  INTEGER SIZE
  
  CALL RANDOM_NUMBER(Z1)
  CALL RANDOM_SEED(SIZE)
  CALL RANDOM_NUMBER(Z2)


 

  
  
  
    
 



 

                                       
