For Programmers: Free Programming Magazines  


Home > Archive > Fortran > August 2005 > TYPE *, SYSTEM executable statement









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author TYPE *, SYSTEM executable statement
Andy Mai

2005-08-25, 6:59 pm

I am developing some data processing code on a Compaq (HP?) SC45.
The statement

ier = system('rm '//trim(flnm))

gives me a floating point exception and the program dies (just after
it removes the file!).

I see from the man page ("man 3f system") that I should be calling
SYSTEM like this:

type *, system ('rm '//trim(flnm))

Actually, this works fine, although it dumps a line " 0"
into the printed output. I'm just wondering what the "type *," in
the above line means and how I should be thinking about it. At first
glance, it appears to be a non-standard *declaration* statement,
not an executable statement.

Also, is it possible to get a return code from this system call other
than the zero in the printed output? If so, how do I accomplish this?

Andy Mai
beliavsky@aol.com

2005-08-25, 6:59 pm

Andy Mai wrote:
> I am developing some data processing code on a Compaq (HP?) SC45.
> The statement
>
> ier = system('rm '//trim(flnm))
>
> gives me a floating point exception and the program dies (just after
> it removes the file!).
>
> I see from the man page ("man 3f system") that I should be calling
> SYSTEM like this:
>
> type *, system ('rm '//trim(flnm))
>
> Actually, this works fine, although it dumps a line " 0"
> into the printed output. I'm just wondering what the "type *," in
> the above line means and how I should be thinking about it. At first
> glance, it appears to be a non-standard *declaration* statement,
> not an executable statement.


<snip>

>From section 10.6 of the DIGITAL Fortran Language Reference Manual,

April 1997, which used to be distributed with Digital Visual Fortran:

"TYPE is a synonym for PRINT. All forms and rules for the PRINT
statement also apply to the TYPE statement."

TYPE is not a keyword in standard Fortran (and the manual acknowledges
this by printing the information about it in a blue font).

Steve Lionel

2005-08-25, 6:59 pm

On 25 Aug 2005 13:41:53 -0600, mai@mer.ucar.edu (Andy Mai) wrote:

>I am developing some data processing code on a Compaq (HP?) SC45.
>The statement
>
> ier = system('rm '//trim(flnm))
>
>gives me a floating point exception and the program dies (just after
>it removes the file!).


Try adding:

integer system

If you don't have that, it is implicitly REAL and you could get some rather
odd results, including FP errors.

>
>I see from the man page ("man 3f system") that I should be calling
>SYSTEM like this:
>
> type *, system ('rm '//trim(flnm))
>

That's just an example, and would also require the proper declaration of the
name for a reasonable result.

Steve Lionel
Software Products Division
Intel Corporation
Nashua, NH

User communities for Intel Software Development Products
http://softwareforums.intel.com/
Intel Fortran Support
http://developer.intel.com/software/products/support/
Richard E Maine

2005-08-25, 6:59 pm

In article <del6u1$kv8$1@mer.ucar.edu>,
mai@mer.ucar.edu (Andy Mai) wrote:

> I see from the man page ("man 3f system") that I should be calling
> SYSTEM like this:
>
> type *, system ('rm '//trim(flnm))
>


If you have a man page that suggests that, I'd suggest throwing out the
man page (and maybe whatever other garbage came with it. :-()

This usage of TYPE is an old nonstandard extension (which has nothing at
all to do with the standard TYPE statement introduced in f90). It is
approximately the equivalent of a PRINT statement. I forget the fine
details of any distinctions between that old nonstandard TYPE and PRINT,
but mostly.

1. Don't use that form of TYPE statement. It is nonstandard,
nonportable, and doesn't do anything particularly useful that isn't
better done with a PRINT statement.

2. In any case, it has nothing in particular to do with system() at all.
That example is clearly a case of someone randomly coming up with a
context to do something with the return value from system. Printing it
out was the first thing that occurred to them. Since that form of TYPE
statement is essentially a synonym for PRINT to standard output, it
shouldn't be surprising that that's what you get.

If you are getting an error, it almost certainly has nothing to do with
the use of the TYPE statement here. It may well be just that this change
to the code moves something around in memory in such a way that the
error doesn't show the same symptoms, but it is completely implausible
that this would actually fix the error.

> Also, is it possible to get a return code from this system call other
> than the zero in the printed output? If so, how do I accomplish this?


System and all similar things are vendor-specific extensions. As such,
you'll mostly have to look at the vendor documentation for such fine
points. However, although it is an extension, it is a common enough one
that most implementations have some things in common. One of those
commonalities is that, in versions of system() that return a status
value (not all of them do), the status value usually relates to whether
the system() call could successfully start a shell (command-line
processor). The 0 result you are seeing just says that a shell was
sucessfully started. It does not tell you anything about the success of
any programs (rm in this case) that might have then been started by that
shell. Unfortunately, in my experience, one is usually more interested
in the status of the programs, but that's not what is most often
available. There might be other vendor-specific procedures that can give
you the information you want, but they aren't as common as system().

--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
beliavsky@aol.com

2005-08-25, 6:59 pm

beliav...@aol.com wrote:

<snip>

> April 1997, which used to be distributed with Digital Visual Fortran:
>
> "TYPE is a synonym for PRINT. All forms and rules for the PRINT
> statement also apply to the TYPE statement."
>
> TYPE is not a keyword in standard Fortran (and the manual acknowledges
> this by printing the information about it in a blue font).


To correct my error, of course TYPE is a keyword used to declare
derived types, but its use as a synonym for PRINT is nonstandard.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com