hoefling@uicsrd.csrd.uiuc.edu (01/16/88)
All I wanted to do was pass a value to the csh status variable from an Apollo Fortran program. Like a C program would do for "exit(n);". The manuals had nothing on the subject. The (800) 2APOLLO help line was baffled (actually they suggested I write a file containing the status code, then cat it once I was back in the shell, but I didn't care for that solution). So, in playing around, we came up with a still-pretty-cruddy solution, but one which hid the cruddiness inside the program, so I don't mind it so much. For those interested, here's the Fortran code: integer x,y,z pointer /z/ x equivalence (z,y) y = 8 call exit(x) end This returns the value 8 to the status variable in csh, which you can see by "echo $status". Apparently, "call exit" passes the argument by reference (puts the arg address on the stack), while the exit routine is expecting the *value* to be on the stack. What results if you don't play the above tricks is that the status variable gets what is apparently the address of the argument. So that's why we had to trick Fortran into believing that the address of the variable x was actually the status return code value (8 in this case). If anyone knows of a cleaner way of doing this, I would love to hear of it. Jay Hoeflinger University of Illinois at Urbana-Champaign Center for Supercomputing Research and Development UUCP: {ihnp4,uunet,convex}!uiucuxc!uicsrd!hoefling ARPANET: hoefling%uicsrd@uxc.cso.uiuc.edu CSNET: hoefling%uicsrd@uiuc.csnet BITNET: hoefling@uicsrd.csrd.uiuc.edu (217) 244-0288
hoefling@uicsrd.csrd.uiuc.edu (01/28/88)
Well, the (800) 2APOLLO help line came up with a real solution this time. It is straightforward and I wonder why it took so many calls and so long for them get it. Anyway, here is a way to pass back a status value to the c-shell: %include '/sys/ins/base.ins.ftn' %include '/sys/ins/pgm.ins.ftn' call pgm_$set_severity(<severity-code>) call pgm_$exit end where <severity-code> is one of: pgm_$ok pgm_$true pgm_$false pgm_$warning pgm_$error pgm_$output_invalid pgm_$internal_error pgm_$program_faulted Any other value for the <severity-code> causes the status variable in the c-shell to get the value 0. So, you can't use it to return just any old value. Jay
Jinfu@cup.portal.com (01/31/88)
Another trick just came up to my head could be using a C routine. First you pass the value to the C routine (I believe the Apollo C manual has a section about how to pass data between C and FORTRAN as well as Pascal), then use the C routine to do a exit(n) gracefully. Only problem of doing this is you will have to link one more file. Jinfu Chen Arpa: Jinfu@cup.portal.com