2003-01-20 05:58:50 +08:00
|
|
|
!
|
2004-02-26 19:50:36 +08:00
|
|
|
! Copyright (C) 2001-2004 Carlo Cavazzoni and PWSCF group
|
2003-01-20 05:58:50 +08:00
|
|
|
! This file is distributed under the terms of the
|
|
|
|
! GNU General Public License. See the file `License'
|
|
|
|
! in the root directory of the present distribution,
|
|
|
|
! or http://www.gnu.org/copyleft/gpl.txt .
|
|
|
|
!
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
! ... SUBROUTINE field_count: accepts two string (one of them is optional)
|
|
|
|
! and one integer and count the number of fields
|
|
|
|
! in the string separated by a blank or a tab
|
|
|
|
! character. If the optional string is specified
|
|
|
|
! (it has anyway len=1) it is assumed as the
|
|
|
|
! separator character.
|
2006-02-02 01:56:16 +08:00
|
|
|
! Ignores any character following the exclamation
|
2004-03-29 16:42:37 +08:00
|
|
|
! mark (fortran comment)
|
|
|
|
!
|
2006-02-02 01:56:16 +08:00
|
|
|
! ... SUBROUTINE con_cam: counts the number of fields in a string
|
|
|
|
! separated by the optional character
|
|
|
|
!
|
2004-03-29 16:42:37 +08:00
|
|
|
! ... SUBROUTINE field_compare: accepts two strings and one integer. Counts the
|
|
|
|
! fields contained in the first string and
|
|
|
|
! compares it with the integer.
|
|
|
|
! If they are less than the integer calls the
|
|
|
|
! routine error and show by the second string the
|
|
|
|
! name of the field where read-error occurred.
|
2004-10-01 23:56:21 +08:00
|
|
|
!
|
|
|
|
#include "f_defs.h"
|
|
|
|
!
|
2004-02-26 19:50:36 +08:00
|
|
|
!----------------------------------------------------------------------------
|
|
|
|
MODULE parser
|
|
|
|
!----------------------------------------------------------------------------
|
|
|
|
!
|
2004-03-29 16:42:37 +08:00
|
|
|
USE io_global, ONLY : stdout
|
2003-01-20 05:58:50 +08:00
|
|
|
USE kinds
|
2004-02-26 19:50:36 +08:00
|
|
|
!
|
2006-02-02 01:56:16 +08:00
|
|
|
PRIVATE
|
2004-02-26 19:50:36 +08:00
|
|
|
!
|
2006-02-02 01:56:16 +08:00
|
|
|
PUBLIC :: parse_unit, field_count, read_line
|
2004-02-26 19:50:36 +08:00
|
|
|
!
|
2006-02-02 01:56:16 +08:00
|
|
|
INTEGER :: parse_unit = 5 ! normally 5, but can be set otherwise
|
2004-02-26 19:50:36 +08:00
|
|
|
!
|
2006-02-02 01:56:16 +08:00
|
|
|
CONTAINS
|
2004-12-21 23:28:01 +08:00
|
|
|
!
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
!--------------------------------------------------------------------------
|
|
|
|
PURE SUBROUTINE field_count( num, line, car )
|
|
|
|
!--------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
|
|
|
INTEGER, INTENT(OUT) :: num
|
|
|
|
CHARACTER(LEN=*), INTENT(IN) :: line
|
|
|
|
CHARACTER(LEN=1), OPTIONAL, INTENT(IN) :: car
|
2006-03-17 02:04:33 +08:00
|
|
|
#if defined (__AIX) || defined (__MAC)
|
2005-04-13 21:36:49 +08:00
|
|
|
! ... with the IBM xlf compiler some combination of flags lead to
|
2004-10-01 23:56:21 +08:00
|
|
|
! ... variables being defined as static, hence giving a conflict
|
|
|
|
! ... with PURE function. We then force the variable to be AUTOMATIC
|
|
|
|
CHARACTER(LEN=1), AUTOMATIC :: sep1, sep2
|
|
|
|
INTEGER, AUTOMATIC :: j
|
|
|
|
#else
|
2004-03-29 16:42:37 +08:00
|
|
|
CHARACTER(LEN=1) :: sep1, sep2
|
|
|
|
INTEGER :: j
|
2004-10-01 23:56:21 +08:00
|
|
|
#endif
|
2003-01-20 05:58:50 +08:00
|
|
|
!
|
|
|
|
!
|
|
|
|
num = 0
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
IF ( .NOT. present(car) ) THEN
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
sep1 = char(32) ! ... blank character
|
|
|
|
sep2 = char(9) ! ... tab character
|
|
|
|
!
|
|
|
|
DO j = 2, MAX( LEN( line ), 256 )
|
|
|
|
!
|
|
|
|
IF ( line(j:j) == '!' .OR. line(j:j) == char(0) ) THEN
|
|
|
|
!
|
|
|
|
IF ( line(j-1:j-1) /= sep1 .AND. line(j-1:j-1) /= sep2 ) THEN
|
|
|
|
!
|
|
|
|
num = num + 1
|
|
|
|
!
|
|
|
|
END IF
|
|
|
|
!
|
|
|
|
EXIT
|
|
|
|
!
|
|
|
|
END IF
|
|
|
|
!
|
|
|
|
IF ( ( line(j:j) == sep1 .OR. line(j:j) == sep2 ) .AND. &
|
|
|
|
( line(j-1:j-1) /= sep1 .AND. line(j-1:j-1) /= sep2 ) ) THEN
|
|
|
|
!
|
|
|
|
num = num + 1
|
|
|
|
!
|
|
|
|
END IF
|
|
|
|
!
|
|
|
|
END DO
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
ELSE
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
sep1 = car
|
|
|
|
!
|
|
|
|
DO j = 2, MAX( LEN( line ), 256 )
|
|
|
|
!
|
|
|
|
IF ( line(j:j) == '!' .OR. &
|
|
|
|
line(j:j) == char(0) .OR. line(j:j) == char(32) ) THEN
|
|
|
|
!
|
|
|
|
IF ( line(j-1:j-1) /= sep1 ) num = num + 1
|
|
|
|
!
|
|
|
|
EXIT
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
END IF
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
IF ( line(j:j) == sep1 .AND. line(j-1:j-1) /= sep1 ) num = num + 1
|
|
|
|
!
|
|
|
|
END DO
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
END IF
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
RETURN
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
END SUBROUTINE field_count
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
!
|
|
|
|
!--------------------------------------------------------------------------
|
|
|
|
SUBROUTINE read_line( line, nfield, field, end_of_file )
|
|
|
|
!--------------------------------------------------------------------------
|
|
|
|
!
|
|
|
|
USE mp, ONLY : mp_bcast
|
2006-03-27 01:14:44 +08:00
|
|
|
USE mp_global, ONLY : world_comm
|
2004-03-29 16:42:37 +08:00
|
|
|
USE io_global, ONLY : ionode, ionode_id
|
|
|
|
!
|
|
|
|
IMPLICIT NONE
|
|
|
|
!
|
|
|
|
CHARACTER(LEN=*), INTENT(OUT) :: line
|
|
|
|
CHARACTER(LEN=*), OPTIONAL, INTENT(IN) :: field
|
|
|
|
INTEGER, OPTIONAL, INTENT(IN) :: nfield
|
|
|
|
LOGICAL, OPTIONAL, INTENT(OUT) :: end_of_file
|
|
|
|
LOGICAL :: tend
|
|
|
|
!
|
|
|
|
!
|
|
|
|
IF( LEN( line ) < 256 ) THEN
|
2006-02-02 23:20:26 +08:00
|
|
|
CALL errore(' read_line ', ' input line too short ', MAX(LEN(line),1) )
|
2004-03-29 16:42:37 +08:00
|
|
|
END IF
|
|
|
|
!
|
|
|
|
IF ( ionode ) THEN
|
2006-02-02 23:20:26 +08:00
|
|
|
30 READ (parse_unit, fmt='(A256)', ERR=10, END=10) line
|
2005-04-13 18:44:37 +08:00
|
|
|
IF( line == ' ' .OR. line(1:1) == '#' ) GO TO 30
|
2004-03-29 16:42:37 +08:00
|
|
|
tend = .FALSE.
|
|
|
|
GO TO 20
|
|
|
|
10 tend = .TRUE.
|
|
|
|
20 CONTINUE
|
|
|
|
END IF
|
|
|
|
!
|
2006-03-27 01:14:44 +08:00
|
|
|
CALL mp_bcast( tend, ionode_id, world_comm )
|
|
|
|
CALL mp_bcast( line, ionode_id, world_comm )
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
IF( PRESENT(end_of_file) ) THEN
|
|
|
|
end_of_file = tend
|
|
|
|
ELSE IF( tend ) THEN
|
2006-02-02 23:20:26 +08:00
|
|
|
CALL infomsg(' read_line ', ' end of file ', -1 )
|
2004-03-29 16:42:37 +08:00
|
|
|
ELSE
|
2004-03-29 17:34:14 +08:00
|
|
|
IF( PRESENT(field) ) CALL field_compare( line, nfield, field )
|
2004-03-29 16:42:37 +08:00
|
|
|
END IF
|
|
|
|
!
|
|
|
|
RETURN
|
|
|
|
!
|
|
|
|
END SUBROUTINE read_line
|
|
|
|
!
|
|
|
|
!
|
|
|
|
!--------------------------------------------------------------------------
|
2004-03-29 17:34:14 +08:00
|
|
|
SUBROUTINE field_compare( str, nf, var )
|
2004-03-29 16:42:37 +08:00
|
|
|
!--------------------------------------------------------------------------
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
IMPLICIT NONE
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
2004-03-29 17:34:14 +08:00
|
|
|
CHARACTER(LEN=*), INTENT(IN) :: var
|
|
|
|
INTEGER, INTENT(IN) :: nf
|
|
|
|
CHARACTER(LEN=*), INTENT(IN) :: str
|
|
|
|
INTEGER :: nc
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
CALL field_count( nc, str )
|
|
|
|
!
|
|
|
|
IF( nc < nf ) &
|
|
|
|
CALL errore( ' field_compare ', &
|
|
|
|
& ' wrong number of fields: ' // TRIM( var ), 1 )
|
|
|
|
!
|
|
|
|
RETURN
|
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
END SUBROUTINE field_compare
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
|
|
|
!
|
|
|
|
!--------------------------------------------------------------------------
|
2003-01-20 05:58:50 +08:00
|
|
|
SUBROUTINE con_cam(num, line, car)
|
2004-03-29 16:42:37 +08:00
|
|
|
!--------------------------------------------------------------------------
|
2003-01-20 05:58:50 +08:00
|
|
|
CHARACTER(LEN=*) :: line
|
|
|
|
CHARACTER(LEN=1) :: sep
|
|
|
|
CHARACTER(LEN=1), OPTIONAL :: car
|
|
|
|
INTEGER :: num, j
|
|
|
|
|
|
|
|
num = 0
|
|
|
|
IF (len(line) .GT. 256 ) THEN
|
2003-11-04 18:26:03 +08:00
|
|
|
WRITE( stdout,*) 'riga ', line
|
|
|
|
WRITE( stdout,*) 'lunga ', len(line)
|
2003-01-20 05:58:50 +08:00
|
|
|
num = -1
|
|
|
|
RETURN
|
|
|
|
END IF
|
|
|
|
|
2003-11-04 18:26:03 +08:00
|
|
|
WRITE( stdout,*) '1riga ', line
|
|
|
|
WRITE( stdout,*) '1lunga ', len(line)
|
2003-01-20 05:58:50 +08:00
|
|
|
IF ( .NOT. present(car) ) THEN
|
|
|
|
sep=char(32) !char(32) is the blank character
|
|
|
|
ELSE
|
|
|
|
sep=car
|
|
|
|
END IF
|
|
|
|
|
|
|
|
DO j=2, MAX(len(line),256)
|
|
|
|
IF ( line(j:j) == '!' .OR. line(j:j) == char(0)) THEN
|
|
|
|
RETURN
|
|
|
|
END IF
|
|
|
|
IF ( (line(j:j) .EQ. sep) .AND. &
|
|
|
|
(line(j-1:j-1) .NE. sep) ) THEN
|
|
|
|
num = num + 1
|
|
|
|
END IF
|
|
|
|
END DO
|
|
|
|
RETURN
|
|
|
|
END SUBROUTINE con_cam
|
2004-03-29 16:42:37 +08:00
|
|
|
!
|
2003-01-20 05:58:50 +08:00
|
|
|
END MODULE parser
|