There are bugs in DECwindows Motif 1.2 (but not 1.1) that affect the
PGPLOT driver xedriver.f (Fortran DECwindows driver). The following
note describes the bugs and a workaround. A better solution is to use
the new C X-window driver (xwdriv.c) if you have a DEC C compiler.
------------------------------------------------------------------------

Date: Sun, 23 Oct 1994 17:13:56 EDT
From: Rachael Padman +44 (223) 337310 <rachael@mrao.cam.ac.uk>
To: tjp@PERKIN.CALTECH.EDU
Message-ID: <00986621.ED91DF53.1@mrao.cam.ac.uk>
Subject: RE: PGPLOT under VMS 6.1 /Motif 1.2

Hello Tim,

Just to follow up on the problem I described earlier.

There is indeed a (or even many) problems with Motif 1.2., as has become
clear from various comments on vmsnet.alpha and related newsgroups. The
problems with XEDRIVER in your V4.9H show up as:

  +  Failure to create a bitmap from the LOGO data

  +  Failure to define the ICON name

  +  Failure to create an image in X$CREATE_IMAGE.

There are others, but don't seem to be used in your driver, and of the above
only the last actually matters. I have held off setting up a call to DEC until
I had a simple way to demonstrate the problem, but I have now received
a replacement routine for X$CREATE_IMAGE (appended) which does work, so I
have set up a call with DEC and we will see what happens --- I will keep you
informed.

In the meantime, in case it is of use to you, here is the new code:

Regards
Rachael

        ---------------------------------------------------------------

From:	MX%"bill@office.ab.umd.edu" 21-OCT-1994 15:29:36.96
To:	MX%"rachael@mrao.cam.ac.uk"
CC:	
Subj:	RE: bugs in xlib


>I saw your posting in vmsnet.misc at the end of August re bugs in
>xlib under Motif 1.2 (on AXP?).  I have several applications which no
>longer run correctly now that I have upgraded, and I believe these
>bugs to be the cause.
>
>Specifically, part of a graphics package that uses x$create_image and
>x$put_image seems to be broken. Following your comments, I tried replacing
>these with calls to xCreateImage and xPutImage, and with a bit of fiddling
>around with %VAL etc got a program which didn't crash, but which also failed
>to display a greyscale.
>
>Now my question is: Do you have any experience or knowledge yourself that
>the two DEC routines might be broken? I am thinking about putting together a
>simple application to demonstrate the problem, and assuming it is still
>there, then sending it to DEC, but I don't want to do all this if everyone
>else already knows about it. Of course, if you not only know about such a
>problem, but also have a fix for it, that would be very gratefully received.
>
>Many thanks for your time,
>Rachael Padman

Rachael,

I had simillar problems with FORTRAN-based X11 applications after
installing MOTIF 1.2.  My general solution has been to either rewrite in
C or to call the C version of the X function (like you attempted to do -
not always a trivial task due to C calling conventions).

So far I've only found two functions that don't work, and I have workarounds
for both that don't require writing C code or calling C functions...

The functions are:

X$CREATE_IMAGE and X$LOAD_QUERY_FONT

both of these functions return '0' no matter what you feed them.

Here are the workaround I have found...

X$LOAD_QUERY_FONT can be replaced by X$LOAD_FONT followed by X$QUERY_FONT -
this works just fine.

X$CREATE_IMAGE, on the other hand, is totally broken... here's a snippet
of code to take care of it (works on AXP and VAX with MOTIF 1.2 - Note
that this is not guaranteed to work with later versions of X11).  Just
replace all instances of X$CREATE_IMAGE in your code with HACK$CREATE_IMAGE
and your problem should be solved.  I never did figure out how to successfully
call XCreateImage() from FORTRAN, but then again I didn't try very hard.

	integer*4 function hack$create_image(display, visual, depth, format,
	1	offset, data, width, height, bitmap_pad, bytes_per_line,
	1	image)
	implicit none
	include 'sys$library:decw$xlibdef.for'
	integer*4 display,depth,format,offset,width,height,bitmap_pad,
	1	bytes_per_line
	byte data(*)
	record /x$visual/ visual
	record /x$image/ image
	image.x$l_imag_width = width
	image.x$l_imag_height = height
	image.x$l_imag_xoffset = offset
	image.x$l_imag_format = format
	image.x$a_imag_data=%loc(data)
	image.x$l_imag_byte_order=0
	image.x$l_imag_bitmap_unit=32
	image.x$l_imag_bitmap_bit_order=0
	image.x$l_imag_bitmap_pad=bitmap_pad
	image.x$l_imag_depth=depth
	if (bytes_per_line .eq. 0) then
	  image.x$l_imag_bytes_per_line=width
	else
	  image.x$l_imag_bytes_per_line=bytes_per_line
	endif
	image.x$l_imag_bits_per_pixel=8
	image.x$l_imag_red_mask = -1
	image.x$l_imag_green_mask = -1
	image.x$l_imag_blue_mask = -1
	hack$create_image=1
	return
	end


--
+--------------------------------------+-------------------------------------+
|   William P. Bame                    | Ground: William P. Bame             |
|   internet: bill@office.ab.umd.edu   |         UMMS/Shock Trauma           |
|             bbame@achi1.ab.umd.edu   |         22 South Greene Street      |
|   AT&T    : [Work] (410) 328-3062    |         Baltimore, MD 21201         |
|   CIS     : 71620,425                |         Room: T1R55                 |
+--------------------------------------+-------------------------------------+



From:	ST%"rachael@mrao.cam.ac.uk" 27-OCT-1994 06:00:08.62
To:	TJP
CC:	
Subj:	FWD: X$CREATE_IMAGE workaround example

Received: from ppsw3.cam.ac.uk by Deimos.Caltech.Edu with INTERNET ;
          Thu, 27 Oct 94 05:59:56 PDT
Received: from MRAO.ra.phy.cam.ac.uk by mauve.csi.cam.ac.uk 
          with SMTP-CAM (PP-7.1) as ppsw.cam.ac.uk;
          Thu, 27 Oct 1994 12:54:18 +0100
Received: by mrao.cam.ac.uk (MX V4.0 VAX) id 1; Thu, 27 Oct 1994 12:57:13 BST
Date: Thu, 27 Oct 1994 12:57:19 EDT
From: Rachael Padman +44 (223) 337310 <rachael@mrao.cam.ac.uk>
To: tjp@perkin.caltech.edu
Message-ID: <00986922.BDE4FA66.1@mrao.cam.ac.uk>
Subject: FWD: X$CREATE_IMAGE workaround example

Hi Tim,

thanks for your reply. I look forward to the next version of PGPLOT. In the
meantime, for your information, here is the response from DEC. So -- they
are aware of the problem, and I guess we are just waiting for the patch. 
I will leave it here unless anything particularly relevant occurs.

Regards
Rachael

                ------------------------------------------

To: rachael@mrao.cam.ac.uk
CC: if@uvo.dec.com
Subject: X$CREATE_IMAGE workaround example
Date: Thu, 27 Oct 94 12:38:18 +0000
From: if@uvo.dec.com
X-Mts: smtp

Hi,

Here's the example code we discussed. I have been unable to progress my 
enquiries into the availability of a patch for the problem. I'll keep you posted 
as soon as I hear of anything.

regards

	Ian

        program text_X                                                        
        implicit none                                                         
        include 'sys$library:decw$xlibdef.for/nolist'                         
                                                                              
        external XCreateImage                                                 
        record /x$visual/visual                                               
        record /x$image/img                                                   
        integer*4 display,func,window,screen,status,pimg                      
        integer*4 XCreateImage                                                
        integer*1 tablo(640,512)                                              
        display = x$open_display('decw$display')                              
        status = x$synchronize(display,1,func)                                
        screen = x$default_screen_of_display(display)                         
                                                                              
        window = x$create_simple_window(display,                              
        1       x$root_window_of_screen(screen),300,300,640,512,5,            
        1       x$white_pixel_of_screen(screen),                              
        1       x$black_pixel_of_screen(screen))                              
        call x$default_visual_of_screen(screen,visual)                        
                                                                              
        status = x$create_image(display,visual,8,x$c_z_pixmap,0,tablo,640,512,
        1       640,img)                                                      
c The img structure is filled in with 0 in motif v1.2                         
c                                                                             
c Workaround: Call the mit-c binding routine                                  
        pimg = XCreateImage(%val(display),visual,%val(8),%val(x$c_z_pixmap),  
        1       %val(0),tablo,%val(640),%val(512),%val(8),                    
        1       %val(640))                                                    
        CALL COPY_IMAGE( img, %VAL(pimg) )                                    
                                                                              
        end                                                                   
                                                                              
C Used with workaround to copy from pointer to structure                      
       SUBROUTINE COPY_IMAGE( TARGET, SOURCE )                                
       IMPLICIT NONE                                                          
       INCLUDE 'SYS$LIBRARY:DECW$XLIBDEF/NOLIST'                              
       RECORD  /X$IMAGE/ TARGET                                               
       RECORD  /X$IMAGE/ SOURCE                                               
                                                                              
       TARGET = SOURCE                                                        
                                                                              
       RETURN                                                                 
       END                                                                    


