- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With my OPTIONAL variable (sortz), retlog=present(sortz) and (present(sortz) aren't working.
Not sure why. Here's what I have:
SUBROUTINE LIBRARIAN(prompt,choices,nchoices,nchosen,opts,nopts,
+optchosen,sortz)
USE DFLOGM
IMPLICIT NONE
............
LOGICAL, OPTIONAL :: sortz
LOGICAL(KIND=4) retlog
INTEGER x
...........
retlog=present(sortz)
if (retlog) then
x=1
else
x=2
endif
if (present(sortz) then
x=1
else
x=2
endif
With either test, the result is always x=1 even when I know I haven't passed the optional variable and in debug you can see it as "undefined".
This is a mixed language project - would my settings for "C, by reference", "Uppercase" or for "After All Args" disturb the workings of this ?
Any ideas would be appreciated.
Keith Richardson
Not sure why. Here's what I have:
SUBROUTINE LIBRARIAN(prompt,choices,nchoices,nchosen,opts,nopts,
+optchosen,sortz)
USE DFLOGM
IMPLICIT NONE
............
LOGICAL, OPTIONAL :: sortz
LOGICAL(KIND=4) retlog
INTEGER x
...........
retlog=present(sortz)
if (retlog) then
x=1
else
x=2
endif
if (present(sortz) then
x=1
else
x=2
endif
With either test, the result is always x=1 even when I know I haven't passed the optional variable and in debug you can see it as "undefined".
This is a mixed language project - would my settings for "C, by reference", "Uppercase" or for "After All Args" disturb the workings of this ?
Any ideas would be appreciated.
Keith Richardson
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
cancel this...I just found part on optional in Dr. Fortran in latest (12/00) newsletter!!!!
Thanks, Steve!
Thanks, Steve!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm glad to see that the Good Doctor was able to be of assistance.
Steve
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Now we're going to see why they call him 'THE GOOD DOCTOR' !
I read your piece and realized I either needed an interface in the calling routine or a contained subroutine. Since I have 50 calling routines, many of which include the optional sortz logical in the call, I opted for the former. So I changed my code to the following (changed or new lines as indicated):
So, in prose, I added the CONTAINS SUBROUTINE TEST, removed the optional switch for sortz (actually, I tried it both ways and it didn't make a difference), and called to TEST.
In debugging, I stepped into TEST and libsort got set to .true. in the contained subroutine TEST whether or not sortz was present (whether it said "undefined address" in the debugger or was actually set to .true. or .false.).
Very strange. What am I not understanding?
Thanks doc,
Keith
I read your piece and realized I either needed an interface in the calling routine or a contained subroutine. Since I have 50 calling routines, many of which include the optional sortz logical in the call, I opted for the former. So I changed my code to the following (changed or new lines as indicated):
SUBROUTINE LIBRARIAN(prompt,choices,nchoices,nchosen,opts,nopts, + optchosen,sortz) USE DFLOGM IMPLICIT NONE NEW -*INCLUDE 'CPCOM.FOR' !to use COMMON variable libsort INCLUDE 'RESOURCE.FD' CHARACTER*(*) prompt integer nchoices CHARACTER*(*) choices(nchoices) integer nchosen, nopts character*40 opts(nopts) integer optchosen changed-*LOGICAL sortz, sortz2 !removed OPTIONAL here, added sortz2 INTEGER x INTEGER*4 retint, numc integer ln(nchoices) COMMON numc EXTERNAL DISCALL TYPE (dialog) dlg NEW -*libsort=.false. !default is sortz is not present NEW -*call TEST (sortz) !sets libsort to .true. if sortz present, in contained subr. below NEW -*if (.not.libsort) then NEW -* sortz2=.false. !sortz not present so do not sort NEW -*else NEW -* sortz2=sortz NEW -*endif if (sortz2) then !use sortz2 instead of sortz !launch dialog with sorted list box IF(.not. DlgInit(IDD_LIBRARIAN_SORTED_4_OPT, dlg)) THEN WRITE (*,*) "ERROR: dialog not found" ELSE ............... ENDIF else ....!launch dialog w/out sorted list box endif RETURN new-* CONTAINS new-* SUBROUTINE TEST(sortlog) new-* include 'cp.com' new-* OPTIONAL :: sortlog new-* IF (PRESENT(sortlog)) libsort=.TRUE. new-* END SUBROUTINE TEST END SUBROUTINE
So, in prose, I added the CONTAINS SUBROUTINE TEST, removed the optional switch for sortz (actually, I tried it both ways and it didn't make a difference), and called to TEST.
In debugging, I stepped into TEST and libsort got set to .true. in the contained subroutine TEST whether or not sortz was present (whether it said "undefined address" in the debugger or was actually set to .true. or .false.).
Very strange. What am I not understanding?
Thanks doc,
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If my code is packed together in a giant run-on sentence when you folks read the prior post and you'd like to see it, just let me know and I'll e-mail it to you.
Keith
Keith
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In the code you've given, SORTZ is always going to be present, because it is specified in the call to TEST and is not OPTIONAL in LIBRARIAN. If you want to test whether SORTZ was passed in to LIBRARIAN, it has to be OPTIONAL here *AND* anyone who calls LIBRARIAN needs to have an explicit interface for it.
Steve (aka Dr. Fortran)
P.S. To prevent your code from running together, bracket it with:
I edited your entry to do that.
Steve (aka Dr. Fortran)
P.S. To prevent your code from running together, bracket it with:
...
I edited your entry to do that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks. That explains it!

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page