--- gagx.c	2008-05-02 15:21:50.000000000 +0200
+++ ../../work/src/gagx.c	2008-07-24 20:15:41.000000000 +0200
@@ -2845,19 +2845,21 @@
   if (barflg) gagsav (8,pcm,pgr);
   else  gagsav (6,pcm,pgr);
 }
 
 /* Do 2-D streamlines */
 
 void gastrm (struct gacmn *pcm) {
 struct gagrid *pgru, *pgrv, *pgrc=NULL;
-gadouble *u, *v, *c=0;
-gaint flag,lcol;
+gadouble *u, *v, *c=0, *ivals=NULL, *jvals=NULL;
+gaint flag, lcol, latscale=0;
 char *umask, *vmask, *cmask=NULL;
+gadouble (*igrab) (gadouble *, gadouble)=NULL;
+gadouble (*jgrab) (gadouble *, gadouble)=NULL;
 
   if (pcm->numgrd<2) {
     gaprnt (0,"Error plotting streamlines:  Only one grid provided\n");
     return;
   }
   pgru = pcm->result[0].pgr;
   pgrv = pcm->result[1].pgr;
   if (pgru->idim!=pgrv->idim || pgru->jdim!=pgrv->jdim ||
@@ -2868,39 +2870,52 @@
   }
   flag = 0;
   if (pcm->numgrd>2) {
     flag = 1;
     pgrc = pcm->result[2].pgr;
     if (pgrc->idim!=pgru->idim || pgrc->jdim!=pgru->jdim ||
         gagchk(pgrc,pgru,pgru->idim) || gagchk(pgrc,pgru,pgru->jdim)) {
       flag = 0;
-      gaprnt (0,"Error plotting streamlines:  Invalid color grid");
-      gaprnt (0,"   Color grid ignored -- has different scaling");
+      gaprnt (0,"Error plotting streamlines:  Invalid color grid\n");
+      gaprnt (0,"   Color grid ignored -- has different scaling\n");
     }
   }
 
+  if (pgru->idim==0 && pgru->jdim==1) {
+    igrab = pgru->igrab;
+    jgrab = pgru->jgrab;
+    ivals = pgru->ivals;
+    jvals = pgru->jvals;
+    if (pcm->mproj>2) latscale = 1;
+  }
+
   if ( (pcm->rotate && (pgru->idim!=2 || pgru->jdim!=3)) ||
       (!pcm->rotate && pgru->idim==2 && pgru->jdim==3)) {
     pgru = gaflip(pgru,pcm);
     pgrv = gaflip(pgrv,pcm);
     if (flag) pgrc = gaflip(pgrc,pcm);
+    if (jgrab) {
+      gaprnt (0,"Warning:  xyrev not supported with streamlines\n");
+      igrab = jgrab = NULL;
+      ivals = jvals = NULL;
+    }
   }
 
   gxstyl (1);
   gxwide (1);
   gas2d (pcm, pgru, 1);     /* Set up scaling, draw map if apprprt */
 
   gafram (pcm);
   idiv = 1.0; jdiv = 1.0;
 
   if (flag) {
     gamnmx (pgrc);
     if (pgrc->umin==0) {
-      gaprnt (0,"Connot color vectors -- Color grid all undefined\n");
+      gaprnt (0,"Cannot color vectors -- Color grid all undefined\n");
       flag = 0;
     } else gaselc(pcm,pgrc->rmin,pgrc->rmax);
   }
 
   u = pgru->grid;
   v = pgrv->grid;
   umask = pgru->umask;
   vmask = pgrv->umask;
@@ -2913,20 +2928,22 @@
   else lcol=1;
   gxcolr (lcol);
   gxstyl(pcm->cstyle);
   gxwide(pcm->cthick);
   gxclip (pcm->xsiz1, pcm->xsiz2, pcm->ysiz1, pcm->ysiz2);
 
   if (flag) {
     gxstrm (u,v,c,pgru->isiz,pgru->jsiz,umask,vmask,cmask,
-       flag,pcm->shdlvs,pcm->shdcls,pcm->shdcnt,pcm->strmden);
+       flag,pcm->shdlvs,pcm->shdcls,pcm->shdcnt,pcm->strmden,
+       igrab,jgrab,ivals,jvals,latscale);
   } else {
     gxstrm (u,v,NULL,pgru->isiz,pgru->jsiz,umask,vmask,0,
-       flag,pcm->shdlvs,pcm->shdcls,pcm->shdcnt,pcm->strmden);
+       flag,pcm->shdlvs,pcm->shdcls,pcm->shdcnt,pcm->strmden,
+       igrab,jgrab,ivals,jvals,latscale);
   }
 
   gxclip (0.0, pcm->xsiz, 0.0, pcm->ysiz);
   gxwide (pcm->annthk-3);
   gxcolr (pcm->anncol);
   if (pcm->pass==0 && pcm->grdsflg)
        gxchpl("GrADS: COLA/IGES",16,0.05,0.05,0.1,0.08,0.0);
   if (pcm->pass==0 && pcm->timelabflg) gatmlb(pcm);
--- gx.h	2008-01-10 17:42:05.000000000 +0100
+++ ../../work/src/gx.h	2008-07-24 16:36:19.000000000 +0200
@@ -390,17 +390,20 @@
 gaint undcol (gaint, gaint);
 gaint putxy  (gadouble, gadouble);
 void  shdcmp (void);
 gaint shdmax (void);
 
 /* routines in gxstrm:  gxstrm (do streamlines) */
 
 void gxstrm (gadouble *, gadouble *, gadouble *, gaint, gaint, char *, char *, char *,
-	     gaint, gadouble *, gaint *, gaint, gaint);
+	     gaint, gadouble *, gaint *, gaint, gaint,
+	     gadouble (*) (gadouble *, gadouble),
+	     gadouble (*) (gadouble *, gadouble),
+	     gadouble *, gadouble *, gaint);
 void strmar (gadouble, gadouble, gadouble, gadouble);
 gaint gxshdc (gadouble *, gaint *, gaint, gadouble);
 
 /* Routines in gxwmap:
    gxwmap: Draw world map
    gxnmap: Draw medium res n.am. map
    gxmout: Output section of world map
    gxnste: Set up projection scaling for north polar stereographic
--- gxstrm.c	2008-01-10 17:42:05.000000000 +0100
+++ ../../work/src/gxstrm.c	2008-07-24 22:43:35.000000000 +0200
@@ -20,61 +20,84 @@
 
 #include <stdio.h>
 #include <math.h>
 #include <gatypes.h>
 #include "gx.h"
 
 void gxstrm (gadouble *u, gadouble *v, gadouble *c, gaint is, gaint js,
    char *umask, char *vmask, char *cmask, gaint flag, gadouble *shdlvs,
-   gaint *shdcls, gaint shdcnt, gaint den) {
+   gaint *shdcls, gaint shdcnt, gaint den,
+   gadouble (*igrab) (gadouble *, gadouble),
+   gadouble (*jgrab) (gadouble *, gadouble),
+   gadouble *ivals, gadouble *jvals, gaint latscale) {
 gadouble x,y,xx,yy;
 gadouble *up, *vp, *cp, cv1,cv2,cv;
 gadouble uv1,uv2,uv,vv1,vv2,vv,auv,avv,xsav,ysav,xold=0.0,yold=0.0;
-gadouble fact,rscl,xxsv,yysv;
-gaint i,ii,jj,ii1,ij1,i2,j2,ipt,acnt,icol,scol,dis;
-gaint *it,siz,iacc,iisav,iscl,imn,imx,jmn,jmx,iz,jz,iss,jss,bflg;
-char *upmask,*vpmask,*cpmask;
+gadouble fact,rscl,xxsv,yysv,dx,dy,*dxp,*dyp,len;
+gaint i,ii,jj,ii1,ij1,i2,j2,ipt,icol,scol,dis;
+gaint siz,iacc,iisav,iscl,imn,imx,jmn,jmx,iz,jz,iss,jss,bflg;
+char *upmask,*vpmask,*cpmask,*it;
   scol = -9;
   icol = 1;
 
   /* Figure out the interval for the flag grid */
 
   i = is;
   if (js>i) i = js;
   iscl = 200/i;
   iscl = iscl + den - 5;
   if (iscl<1) iscl=1;
   if (iscl>10) iscl=10;
   fact = 0.5/((gadouble)iscl);
   rscl = (gadouble)iscl;
  
   /* Allocate memory for the flag grid */
 
-  iss = is*iscl; jss = js*iscl;
+  iss = (is-1)*iscl+1; jss = (js-1)*iscl+1;
   siz = iss*jss;
-  it = (gaint *)malloc(sizeof(gaint) * siz);
+  it = (char *)malloc(sizeof(char) * siz + sizeof(gadouble) * (is+js-2));
   if (it==NULL) {
     printf ("Cannot allocate memory for streamline function\n");
     return;
   }
   for (i=0; i<siz; i++) *(it+i) = 0;
+  if (jgrab) {
+    dxp = (gadouble *)(it+siz);
+    dyp = dxp+is-1;
+    xx = igrab(ivals,1.0);
+    for (i=0;i<is-1;i++) {
+      x = igrab(ivals,i+2.0);
+      dxp[i] = x-xx;
+      xx = x;
+    }
+    yy = jgrab(jvals,1.0);
+    for (i=0;i<js-1;i++) {
+      y = jgrab(jvals,i+2.0);
+      dyp[i] = y-yy;
+      yy = y;
+    }
+  }
 
   /* Loop through flag grid to look for start of streamlines.  
      To start requires no streams drawn within surrounding 
      flag boxes.  */
 
   i2 = 0;
   j2 = 0;
   for (i=0; i<siz; i++) {
     dis = 2;
     if (den<5) dis = 3;
     if (den>5) dis = 1;
-    imn = i2-dis; imx = i2+dis+1; 
     jmn = j2-dis; jmx = j2+dis+1;
+    if (latscale) {
+      xx = cos(jgrab(jvals,((gadouble)j2)/rscl+1.0)*pi/180);
+      dis = xx < 0.001 ? iss : floor((gadouble)dis / xx + 0.5);
+    }
+    imn = i2-dis; imx = i2+dis+1; 
     if (imn<0) imn = 0;
     if (imx>iss) imx = iss;
     if (jmn<0) jmn = 0;
     if (jmx>jss) jmx = jss;
     iacc = 0;
     for (jz=jmn; jz<jmx; jz++) {
       ipt = jz*iss+imn;
       for (iz=imn; iz<imx; iz++) {
@@ -87,17 +110,17 @@
       y = ((gadouble)j2)/rscl;
       xsav = x;
       ysav = y;
       gxconv (x+1.0,y+1.0,&xx,&yy,3);
       gxplot (xx,yy,3);
       xxsv = xx; yysv = yy;
       iisav = -999;
       iacc = 0;
-      acnt = 0;
+      len = 0.3;
       bflg = 0;
       while (x>=0.0 && x<(gadouble)(is-1) && y>=0.0 && y<(gadouble)(js-1)) {
         ii = (gaint)x;
         jj = (gaint)y;
         xx = x - (gadouble)ii;
         yy = y - (gadouble)jj;
         up = u + jj*is+ii; upmask = umask + jj*is+ii;  
         vp = v + jj*is+ii; vpmask = vmask + jj*is+ii; 
@@ -125,60 +148,85 @@
           scol = icol;
         }
         uv1 = *up + (*(up+1)-*up)*xx;
         uv2 = *(up+is) + (*(up+is+1)-*(up+is))*xx;
         uv = uv1 + (uv2-uv1)*yy;
         vv1 = *vp + (*(vp+1)-*vp)*xx;
         vv2 = *(vp+is) + (*(vp+is+1)-*(vp+is))*xx;
         vv = vv1 + (vv2-vv1)*yy;
+        if (jgrab) {
+          uv *= dyp[jj];
+          vv *= dxp[ii] * cos(jgrab(jvals,y+1.0)*pi/180);
+        }
         auv = fabs(uv); avv=fabs(vv);
-        if (auv<0.1 && avv<0.1) break;
+        if (auv<0.001 && avv<0.001) break;
         if (auv>avv) {
           vv = vv*fact/auv;
           uv = uv*fact/auv;
         } else {
           uv = uv*fact/avv;
           vv = vv*fact/avv;
         }
         x = x + uv;
         y = y + vv;
-        ii1 = (gaint)(x*rscl);
-        ij1 = (gaint)(y*rscl);
+        ii1 = (gaint)floor(x*rscl + 0.5);
+        ij1 = (gaint)floor(y*rscl + 0.5);
         ii1 = ij1*iss + ii1;
         if (ii1<0 || ii1>=siz) break;
-        if (*(it+ii1)==1) break;
+        if (*(it+ii1) & 1) break;
         if (ii1!=iisav && iisav>-1) *(it+iisav) = 1;
         if (ii1==iisav) iacc++;
         else iacc = 0;
         if (iacc>10) break;
         iisav = ii1;
+        if (latscale) {
+          xx = cos(jgrab(jvals,y+1.0)*pi/180);
+          dx = xx < 0.001 ? iss : 1/xx;
+        } else dx = 1.0;
+        imn = (gaint)floor(x*rscl - dx + 1.0);
+        imx = (gaint)floor(x*rscl + dx);
+        jmn = (gaint)floor(y*rscl);
+        jmx = jmn + 1;
+        if (imn<0) imn = 0;
+        if (imx>iss) imx = iss;
+        if (jmn<0) jmn = 0;
+        if (jmx>jss) jmx = jss;
+        for (jz=jmn; jz<=jmx; jz++) {
+          ipt = jz*iss+imn;
+          for (iz=imn; iz<=imx; iz++) {
+            *(it+ipt) |= 2;
+            ipt++;
+          }
+        }
         gxconv (x+1.0,y+1.0,&xx,&yy,3);
         if (icol>-1) {
           if (bflg) {gxplot(xold,yold,3); bflg=0;}
           gxplot (xx,yy,2);
         } else bflg = 1;
         xold = xx;
         yold = yy;
-        acnt++;
-        if (acnt>20) {
+        dx = xx-xxsv;
+        dy = yy-yysv;
+        len += sqrt(dx*dx + dy*dy);
+        if (len>0.6) {
           if (icol>-1) strmar (xxsv,yysv,xx,yy);
-          acnt = 0;
+          len = 0.0;
         }
         xxsv = xx; yysv = yy;
       }
       bflg = 0;
       x = xsav; y = ysav;
       gxconv (x+1.0,y+1.0,&xx,&yy,3);
       gxplot (xx,yy,3);
       xxsv = xx;
       yysv = yy;
       iisav = -999;
       iacc = 0;
-      acnt = 19;
+      len = 0.3;
       while (x>=0.0 && x<(gadouble)(is-1) && y>=0.0 && y<(gadouble)(js-1)) {
         ii = (gaint)x;
         jj = (gaint)y;
         xx = x - (gadouble)ii;
         yy = y - (gadouble)jj;
         up = u + jj*is+ii; upmask = umask + jj*is+ii;  
         vp = v + jj*is+ii; vpmask = vmask + jj*is+ii; 
         if (*upmask==0 || 
@@ -205,51 +253,77 @@
           scol = icol;
         }
         uv1 = *up + (*(up+1)-*up)*xx;
         uv2 = *(up+is) + (*(up+is+1)-*(up+is))*xx;
         uv = uv1 + (uv2-uv1)*yy;
         vv1 = *vp + (*(vp+1)-*vp)*xx;
         vv2 = *(vp+is) + (*(vp+is+1)-*(vp+is))*xx;
         vv = vv1 + (vv2-vv1)*yy;
+        if (jgrab) {
+          uv *= dyp[jj];
+          vv *= dxp[ii] * cos(jgrab(jvals,y+1.0)*pi/180);
+        }
         auv = fabs(uv); avv=fabs(vv);
-        if (auv<0.1 && avv<0.1) break;
+        if (auv<0.001 && avv<0.001) break;
         if (auv>avv) {
           vv = vv*fact/auv;
           uv = uv*fact/auv;
         } else {
           uv = uv*fact/avv;
           vv = vv*fact/avv;
         }
         x = x - uv;
         y = y - vv;
-        ii1 = (gaint)(x*rscl);
-        ij1 = (gaint)(y*rscl);
+        ii1 = (gaint)floor(x*rscl + 0.5);
+        ij1 = (gaint)floor(y*rscl + 0.5);
         ii1 = ij1*iss + ii1;
         if (ii1<0 || ii1>=siz) break;
-        if (*(it+ii1)==1) break;
+        if (*(it+ii1) & 1) break;
         if (ii1!=iisav && iisav>-1) *(it+iisav) = 1;
         if (ii1==iisav) iacc++;
         else iacc = 0;
         if (iacc>10) break;
         iisav = ii1;
+        if (latscale) {
+          xx = cos(jgrab(jvals,y+1.0)*pi/180);
+          dx = xx < 0.001 ? iss : 1/xx;
+        } else dx = 1.0;
+        imn = (gaint)floor(x*rscl - dx + 1.0);
+        imx = (gaint)floor(x*rscl + dx);
+        jmn = (gaint)floor(y*rscl);
+        jmx = jmn + 1;
+        if (imn<0) imn = 0;
+        if (imx>iss) imx = iss;
+        if (jmn<0) jmn = 0;
+        if (jmx>jss) jmx = jss;
+        for (jz=jmn; jz<=jmx; jz++) {
+          ipt = jz*iss+imn;
+          for (iz=imn; iz<=imx; iz++) {
+            *(it+ipt) |= 2;
+            ipt++;
+          }
+        }
         gxconv (x+1.0,y+1.0,&xx,&yy,3);
         if (icol>-1) {
           if (bflg) {gxplot(xold,yold,3); bflg=0;}
           gxplot (xx,yy,2);
         } else bflg = 1;
         xold = xx;
         yold = yy;
-        acnt++;
-        if (acnt>20) {
+        dx = xx-xxsv;
+        dy = yy-yysv;
+        len += sqrt(dx*dx + dy*dy);
+        if (len>0.6) {
           if (icol>-1) strmar(xx,yy,xxsv,yysv);
-          acnt = 0;
+          len = 0.0;
         }
         xxsv = xx; yysv = yy;
       }
+      for (iz=0; iz<siz; iz++) *(it+iz) |= *(it+iz) >> 1;
     }
     i2++;
     if (i2==iss) { i2 = 0; j2++; }
   }
   free (it);
 }
 
 static gadouble a150 = 150.0*3.1416/180.0;
