1      logical function argos_prepare_seqsiz(lfnout,lfnseq,filseq,nseq,
2     + nlnk)
3c
4c $Id$
5c
6c     function to scan the sequence file for the number of segments
7c
8      implicit none
9c
10#include "util.fh"
11c
12      integer lfnout,lfnseq,nseq,nlnk
13      character*255 filseq
14      character*80 card
15      integer length,ival,ncrd,ncnt
16c
17      length=index(filseq,' ')-1
18      open(unit=lfnseq,file=filseq(1:length),form='formatted',
19     + status='old',err=9999)
20c
21      nseq=0
22      nlnk=0
23      ncnt=1
24      ncrd=0
25c
26    1 continue
27      read(lfnseq,1000,end=9999,err=9999) card
28 1000 format(a)
29      if(ncrd.eq.0) ncnt=1
30      if(ncrd.gt.0) ncrd=ncrd-1
31      if(card(1:4).eq.'stop') goto 9
32      if(card(1:6).eq.'repeat') then
33      read(card,1002) ncrd,ncnt
34 1002 format(6x,2i5)
35      goto 1
36      endif
37      if(card(1:4).eq.'link') then
38      nlnk=nlnk+1
39      goto 1
40      endif
41      if(card(1:4).eq.'LINK') then
42      nlnk=nlnk+1
43      goto 1
44      endif
45c
46      read(card(1:5),1001,err=1) ival
47 1001 format(i5)
48      nseq=nseq+ncnt
49      goto 1
50c
51    9 continue
52c
53      close(unit=lfnseq)
54c
55      argos_prepare_seqsiz=.true.
56      return
57c
58 9999 continue
59      argos_prepare_seqsiz=.false.
60      return
61      end
62