Re: How to detect NULL input?



jane.sync@xxxxxxxxx wrote in message <1138593234.901437.246450@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
>That worked for the string comparison with everything except NULL.
>Maybe I goofed something up in the main. The whole program is below.
>Did I goof something up?
>
> program test
> implicit none
> CHARACTER(12) fname
> CHARACTER(12) evaluateinput
>C CHARACTER(*) fname
>C CHARACTER(*) evaluateinput

The above two commented lines are valid only in a subroutine
or function where the names refer to dummy arguments.
The uncommented form needs to be used in the main program.

> 100 WRITE (*, 101)
>101 format ('String: ', $ )
> READ (*, *) fname
> print *, 'Test ',evaluateinput(fname)
> END program

You need to replace the END program statement by a CONTAINS
statement.
This makes the function visible to the program, and in particular,
makes the TYPE of the function visible.

> function evaluateinput(str1) result(string)
> implicit none
> character(*) str1
> character(*) string
> string = 'world'
> if (str1 .EQ. '') then

This is better as
if (len_trim(str1) == 0) then
[the lines below are not appropriate for this test,
but I expect that you are aware of that.]

> string = 'equal'
> else
> string = 'not equal'
> end if
> return
> end

Move the END program statement here.



.



Relevant Pages

  • Internal read. Ilegal o bug en g95?
    ... implicit none ... character:: value ... end type string ...
    (comp.lang.fortran)
  • Re: Internal read. Ilegal o bug en g95?
    ... implicit none ... character:: value ... end type string ...
    (comp.lang.fortran)
  • 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: What is wrong with this search for the character PV/PQ
    ... 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 ... This specifies an array of single characters of size 80, not a character string of 80 character length. ... This does read the record into the array, but as you show, you then had to deal w/ each character individually. ...
    (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)