Re: What is wrong with this search for the character PV/PQ



sara_patty wrote:
....

The following works fine!!!!

Implicit integer*2 (I-N)

As a general practice, I'd suggest getting rid of the implicit statement in favor of "implicit none" and explicit declarations of variables used in order to minimize accidental type errors and aid the compiler in its efforts to help you write correct code

implicit none
integer :: kount

Unless you have some other reason not shown, there's little reason to have asked for a 16-bit integer rather than the default size here.

character CB(80)

This specifies an array of single characters of size 80, not a character string of 80 character length. (I sorta' get the idea you figured that out later on, but it's probably not the easiest way to work for most cases if you have a recent compiler).

....

read (15,901,end=999) CB
> if (CB(3) .eq. 'C' .and. cb(4) .eq. 'V') write (16,902)
> (CB(i),i=1,80)
> if (CB(4) .eq. 'C' .and. cb(5) .eq. 'V') write (16,902)
> (CB(i),i=1,80)

This does read the record into the array, but as you show, you then had to deal w/ each character individually. That's inconvenient at best.

You also were having problems with which column the data starts in apparently -- which of the two statements above was actually executed--do you know? It appeared to me from your earlier posting there were two leading spaces in the record but that wasn't possible to be determined conclusively from the formatting of the post...


character(len=80) :: CB
...
read(15,'(A)') CB

' assume the two spaces was correct then you _could_ do
if(CB(4:6) == 'CVB') write(16,*) CB

but to make things a little easier so you wouldn't have to count the spacing you could do

if(index(CB,'CVB') > 0) write(16,*)CB

and let the character-handling intrinsics help you...

hth...

--
.



Relevant Pages

  • Re: Character strings and arrays
    ... > However, as Giles pointed out, given character:: string, reference ... > to stringis NOT a syntax error per se (without implicit none). ... IMPLICIT NONE has no effect at all on the legality or the symantics. ...
    (comp.lang.fortran)
  • Re: How to detect NULL input?
    ... > implicit none ... >C CHARACTER(*) evaluateinput ... You need to replace the END program statement by a CONTAINS ...
    (comp.lang.fortran)
  • Re: Type casting of integer to character in fortran
    ... >>IMPLICIT NONE ... >>This outputs equivalent ASCII Character in place of 2. ... >>Whats the way to typecast integer to character? ... > representation of 2 as an integer to the ASCII representation of the ...
    (comp.lang.fortran)
  • Re: Character strings and arrays
    ... || to stringis NOT a syntax error per se (without implicit none). ... | change the function to some character function, ... to declare a "real external function". ...
    (comp.lang.fortran)
  • Is this a compiler bug?
    ... implicit none ... integer, allocatable, dimension:: array ... end module stor ... allocate ) ...
    (comp.lang.fortran)