Re: How to detect NULL input?
- From: "robin" <robin_v@xxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 02:21:17 GMT
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.
.
- Follow-Ups:
- Re: How to detect NULL input?
- From: Rich Townsend
- Re: How to detect NULL input?
- References:
- How to detect NULL input?
- From: jane . sync
- Re: How to detect NULL input?
- From: Rich Townsend
- Re: How to detect NULL input?
- From: jane . sync
- How to detect NULL input?
- Prev by Date: Re: Input format and NaNs
- Next by Date: Re: How to pass a string to/from a function in 77
- Previous by thread: Re: How to detect NULL input?
- Next by thread: Re: How to detect NULL input?
- Index(es):
Relevant Pages
|
|