Re: Convert NCGM to color PostScript

From: Fred Clare (fred AT unknown)
Date: Thu Aug 07 1997 - 13:52:16 MDT


I have looked at your metafile. The reason that the -simulatebg flag
is not working with ctrans is because there was never any background
color specifically set. The background color is set by assigning a
color value to color index 0. It has been our advice to either set both
the foreground color (color index 1) and the background color, or set
neither of them. Setting just one can cause the type of problem you
are having, since different devices have different defaults for the
background color. In fact there is no specific PostScript operator to
effect coloring the background.

What has worked for me here in doing what you want with your file is to
do the following:

  ctrans -d ps.color your_file.ncgm | psblack > your_file.ps

*Do not* use the simulatebg flag on the ctrans invocation in this particular
case (the case where a background color was never specifically set). I do
not know why psblack should hang on you. It runs in seven seconds on my
Sun IPX (which is a pretty slow machine). It should be used as a filter
as indicated above, and as indicated in Bob Lackman's recent response
to ncarg-talk. I have attached the source for psblack below, so you will
have the most recent version.

The best solution for you is to obtain a more recent version of our
package (version 4.0 or later) and produce the desired PostScript
directly, making sure you specifically set the background color. Obtaining
Encapsulated PostScript directly can be achieved in the manner described
in Bob Lackman's recent posting to ncarg-talk.

If all of this fails, I can show you how to manually edit the PostScript
file to get a black background.

Source for psblack:

      PROGRAM BKGBLK
C
C This Fortran code is a filter (reads from standard input, writes
C to standard output) for PostScript files produced from the NCAR
C Graphics package. It forces a black background and bumps all B&W
C intensity values (values with R=G=B) larger than .79 to 1.0 .
C
      INTEGER CTFLG,CRFLG
      CHARACTER*80 LIN,LOUT
C
      DATA EPS /0.00001/
   10 CONTINUE
C
C Read an input line
C
      LIN = ' '
      READ(5,100,END=80) LIN
  100 FORMAT(A80)
C
C Force background color to black as the first plotting instruction in
C each frame.
C
      IF (LIN(1:3).EQ.'1 j') THEN
          WRITE(6,525)
  525 FORMAT(' ct 000 [0.0000 0.0000 0.0000] put')
          WRITE(6,530)
  530 FORMAT(' 000 o'/'n'/' 0404 1124 m'/' 4482 1124 l'/
     + ' 4482 5202 l'/' 0404 5202 l'/' 0404 1124 l'/'f')
      ENDIF
C
C Determine if this is a color table setting.
C
      CTFLG = 0
      DO 20 I=1,80
      IF (LIN(I:I) .EQ. ' ') THEN
        GO TO 20
      ELSE
        IF (LIN(I:I).EQ.'c' .AND. LIN(I+1:I+1).EQ.'t') THEN
          CTFLG = I
          GO TO 30
        ENDIF
      ENDIF
   20 CONTINUE
   30 CONTINUE
      IF (CTFLG .GT. 0) THEN
C
C Determine if the color values represent a gray value.
C
        CALL CKGRY(LIN,EPS,CTFLG,CRFLG,IDX,R,G,B)
C
C Encode the modified color values in LOUT.
C
        IF (CRFLG.NE.0) THEN
          LOUT = ' '
          WRITE(LOUT,500) IDX, R,G,B
  500 FORMAT(' ct ',I3,' [',F5.3,' ',F5.3,' ',F5.3,'] put')
        ELSE
          LOUT = LIN
        ENDIF
      ELSE
          LOUT = LIN
      ENDIF
C
C Trim blanks and Write to output.
C
      KPOS = 1
      DO 110 I=80,1,-1
        IF (LOUT(I:I) .NE. ' ') THEN
          KPOS = I
          GO TO 120
        ENDIF
  110 CONTINUE
  120 CONTINUE
      WRITE(6,130) (LOUT(LL:LL),LL=1,KPOS)
  130 FORMAT(80A1)
C
      GO TO 10
C
   80 CONTINUE
      STOP
      END
      SUBROUTINE CKGRY(LIN,EPS,JFLG,IFLG,IDX,R,G,B)
C
C Check if the input line in LIN contains a gray intensity value
C (within the limits of EPS). IFLG is 1 if a gray value is found;
C IFLG is 0 otherwise. If IFLG is 1, then IDX is the color index,
C and R, G, and B are the complemented color values.
C
      CHARACTER*80 LIN,CTMP
      REAL EPS,COLORS(3)
      INTEGER IFLG
C
      IFLG = 0
C
C Determine the location of the left bracket.
C
      ICOL = 0
      DO 10 I=1,80
        IF (LIN(I:I) .EQ. '[') THEN
          ICOL = I
          GO TO 20
        ELSE
          IF (I .EQ. 80) GO TO 40
          GO TO 10
        ENDIF
   10 CONTINUE
   20 CONTINUE
C
C Get the color index.
C
      READ(LIN(JFLG+2:ICOL-2),520) IDX
  520 FORMAT(I4)
C
C Get the three color values.
C
      JSTRT = ICOL+1
      DO 50 I=1,3
        CTMP = ' '
        K = 0
        DO 60 J=JSTRT,80
          K = K+1
          IF (LIN(J:J).EQ.' ' .OR. LIN(J:J).EQ.']') THEN
            IF (K .GT. 1) THEN
              CTMP(1:K-1) = LIN(JSTRT:J-1)
            ELSE
              GO TO 40
            ENDIF
            GO TO 70
          ELSE
            GO TO 60
          ENDIF
   60 CONTINUE
   70 CONTINUE
        READ(CTMP(1:K-1),500) COLORS(I)
  500 FORMAT(F10.3)
        JSTRT = J+1
   50 CONTINUE
C
C Determine if we have a gray value.
C
      IFLG = 0
      IF (ABS(COLORS(1)-COLORS(2)).LE.EPS .AND.
     - ABS(COLORS(2)-COLORS(3)).LE.EPS) IFLG = 1
C
C Adjust the intensities.
C
      IF (IFLG .EQ. 1) THEN
        DO 90 I =1,3
          IF (COLORS(I) .GT. .79) THEN
            COLORS(I) = 1.
          ENDIF
   90 CONTINUE
        R = COLORS(1)
        G = COLORS(2)
        B = COLORS(3)
      ELSE
        GO TO 40
      ENDIF
C
   40 CONTINUE
      RETURN
      END

  -Fred Clare



This archive was generated by hypermail 2b29 : Wed Jun 28 2000 - 09:40:32 MDT