diff -u ORG/anamx/aimgn.f90 anamx/aimgn.f90
--- ORG/anamx/aimgn.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/aimgn.f90	2018-05-15 18:47:28.000000000 +0900
@@ -343,6 +343,7 @@
     ' loop', klp, 'rms.Step :', rs, 'rms.Residual :', dv
   open(9,status='scratch')
   write(9,*) klp, rs, dv
+  flush(6)        !--- or  call flush(6)
   call conv2(g,nfx,nfy, r, mx,my, u, mxm,mym,nds)
   p1 = 0.
   do l=1,nds; do j=1,mym; do i=1,mxm
@@ -377,6 +378,7 @@
     write(6,'(a5,i4,3x,a10,f8.2,3x,a14,f7.2)')   &
       ' loop', klp, 'rms.Step :', rs, 'rms.Residual :', dv
     write(9,*) klp, rs, dv
+    flush(6)        !--- or  call flush(6)
 
     p1p = p1
     call conv2(g,nfx,nfy, q, mx,my, v, mxm,mym,nds)
@@ -474,7 +476,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/aimgnc.f90 anamx/aimgnc.f90
--- ORG/anamx/aimgnc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/aimgnc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -336,6 +336,7 @@
     ' loop', klp, kc, 'rms.Step :', rs, 'rms.Residual :', dv
   open(9,status='scratch')
   write(9,*) klp, kc, rs, dv
+  flush(6)        !--- or  call flush(6)
   call conv2(g,nfx,nfy, r, mx,my, u, mxm,mym,nds)
   p1 = 0.
   do l=1,nds; do j=1,mym; do i=1,mxm
@@ -375,6 +376,7 @@
     write(6,'(a5,i4,i3,3x,a10,f8.2,3x,a14,f7.2)')   &
       ' loop', klp, kc, 'rms.Step :', rs, 'rms.Residual :', dv
     write(9,*) klp, kc, rs, dv
+    flush(6)        !--- or  call flush(6)
     if ((kc == 5) .or. (dv < 0.1) .or. (ilp >= nloop)) exit
     p1p = p1
     call conv2(g,nfx,nfy, q, mx,my, v, mxm,mym,nds)
@@ -472,7 +474,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/aimgs.f90 anamx/aimgs.f90
--- ORG/anamx/aimgs.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/aimgs.f90	2018-05-15 18:47:28.000000000 +0900
@@ -341,6 +341,7 @@
     ' loop', klp, 'rms.Step :', rs, 'rms.Residual :', dv
   open(9,status='scratch')
   write(9,*) klp, rs, dv
+  flush(6)        !--- or  call flush(6)
 
   call conv2(g,nfx,nfy, r, mx,my, u, mxm,mym,nds)
   p1 = 0.
@@ -376,6 +377,7 @@
     write(6,'(a5,i4,3x,a10,f8.2,3x,a14,f7.2)')   &
       ' loop', klp, 'rms.Step :', rs, 'rms.Residual :', dv
     write(9,*) klp, rs, dv
+    flush(6)        !--- or  call flush(6)
 
     p1p = p1
     call conv2(g,nfx,nfy, q, mx,my, v, mxm,mym,nds)
@@ -472,7 +474,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/aimgsc.f90 anamx/aimgsc.f90
--- ORG/anamx/aimgsc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/aimgsc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -335,6 +335,7 @@
     ' loop', klp, kc, 'rms.Step :', rs, 'rms.Residual :', dv
   open(9,status='scratch')
   write(9,*) klp, kc, rs, dv
+  flush(6)        !--- or  call flush(6)
 
   call conv2(g,nfx,nfy, r, mx,my, u, mxm,mym,nds)
   p1 = 0.
@@ -375,6 +376,7 @@
     write(6,'(a5,i4,i3,3x,a10,f8.2,3x,a14,f7.2)')   &
       ' loop', klp, kc, 'rms.Step :', rs, 'rms.Residual :', dv
     write(9,*) klp, kc, rs, dv
+    flush(6)        !--- or  call flush(6)
     if ((kc == 5) .or. (dv < 0.1) .or. (ilp >= nloop)) exit
 
     p1p = p1
@@ -472,7 +474,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/axdeq.f90 anamx/axdeq.f90
--- ORG/anamx/axdeq.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/axdeq.f90	2018-06-17 17:09:08.000000000 +0900
@@ -230,6 +230,7 @@
   dv = sqrt(ss / float(ndpt))
   write(6,'(a5,i4,3x,a10,f8.2,3x,a14,f7.2)')   &
     ' loop', klp, 'rms.Step :', ds, 'rms.Residual :', dv
+  flush(6)        !--- or  call flush(6)
   open(9,status='scratch')
   write(9,*) klp, ds, dv
 
@@ -261,6 +262,7 @@
     dv = sqrt(ss / float(ndpt))
     write(6,'(a5,i4,3x,a10,f8.2,3x,a14,f7.2)')   &
       ' loop', klp, 'rms.Step :', ds, 'rms.Residual :', dv
+    flush(6)        !--- or  call flush(6)
     write(9,*) klp, ds, dv
   enddo
   close(20)
diff -u ORG/anamx/axdeqc.f90 anamx/axdeqc.f90
--- ORG/anamx/axdeqc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/axdeqc.f90	2018-06-17 17:09:08.000000000 +0900
@@ -233,6 +233,7 @@
   lp = 0
   write(6,'(a5,i4,i3,3x,a10,f8.2,3x,a14,f7.2)')   &
     ' loop', klp, lp, 'rms.Step :', ds, 'rms.Residual :', dv
+  flush(6)        !--- or  call flush(6)
   open(9,status='scratch')
   write(9,*) klp, lp, ds, dv
 
@@ -269,6 +270,7 @@
     endif
     write(6,'(a5,i4,i3,3x,a10,f8.2,3x,a14,f7.2)')   &
       ' loop', klp, lp, 'rms.Step :', ds, 'rms.Residual :', dv
+    flush(6)        !--- or  call flush(6)
     write(9,*) klp, lp, ds, dv
     if ((lp >= 5) .or. (dv < 0.1)) exit
   enddo
diff -u ORG/anamx/cimgn.f90 anamx/cimgn.f90
--- ORG/anamx/cimgn.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/cimgn.f90	2018-05-15 18:47:28.000000000 +0900
@@ -361,6 +361,7 @@
   write(6,'(a5,i4,3x,a13,f7.3,a2,f7.4,3x,a6,f7.2,3x,a6,f7.2)')   &
       ' loop', klp, 'rms.Step/Src.', 0., ' /', rv, 'Misfit', dv, 'T.Res.', dv
   write(9,*) klp, 0., 0., rv, dv, dv
+  flush(6)        !--- or  call flush(6)
 
   if (nloop /= 0) then
     ilp = 1;  klp = klp + 1
@@ -404,6 +405,7 @@
       ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
     write(9,*) klp, ee, rs, rv, dv, tr
     kc = 0;  trp = tr
+    flush(6)        !--- or  call flush(6)
   endif
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
@@ -563,7 +565,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/cimgnc.f90 anamx/cimgnc.f90
--- ORG/anamx/cimgnc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/cimgnc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -394,6 +394,7 @@
     ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
   write(9,*) klp, ee, rs, rv, dv, tr
   kc = 0;  trp = tr
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -466,6 +467,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -551,7 +553,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/cimgs.f90 anamx/cimgs.f90
--- ORG/anamx/cimgs.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/cimgs.f90	2018-05-15 18:47:28.000000000 +0900
@@ -361,6 +361,7 @@
   write(6,'(a5,i4,3x,a13,f7.3,a2,f7.4,3x,a6,f7.2,3x,a6,f7.2)')   &
       ' loop', klp, 'rms.Step/Src.', 0., ' /', rv, 'Misfit', dv, 'T.Res.', dv
   write(9,*) klp, 0., 0., rv, dv, dv
+  flush(6)        !--- or  call flush(6)
 
   if (nloop /= 0) then
     ilp = 1;  klp = klp + 1
@@ -475,8 +476,9 @@
       write(6,'(a5,i4,6x,a25,e10.3,10x,a6,f7.2)')   &
         ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
       write(9,*) klp, ee, rs, rv, dv, tr
-     endif
-   trp = tr
+    endif
+    trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -563,7 +565,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/cimgsc.f90 anamx/cimgsc.f90
--- ORG/anamx/cimgsc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/cimgsc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -394,6 +394,7 @@
     ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
   write(9,*) klp, ee, rs, rv, dv, tr
   kc = 0;  trp = tr
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -466,6 +467,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -551,7 +553,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/exdeq1.f90 anamx/exdeq1.f90
--- ORG/anamx/exdeq1.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/exdeq1.f90	2018-12-04 11:20:00.000000000 +0900
@@ -209,6 +209,8 @@
   do k=1,ndpt
     f(1,k) = (f(1,k)-xlm)*1000.;  ic = nint(f(1,k)/smx)
     f(2,k) = (f(2,k)-ylm)*1000.;  jc = nint(f(2,k)/smy)
+    if ((ic < 0) .or. (ic >= mxm)) cycle
+    if ((jc < 0) .or. (jc >= mym)) cycle
     ht = tt(ic+1,jc+1)
     if (ht /= tnul) then
       z = f(3,k) - ht;  if (z < zd) zd = z
diff -u ORG/anamx/exdeq2.f90 anamx/exdeq2.f90
--- ORG/anamx/exdeq2.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/exdeq2.f90	2018-12-04 11:20:00.000000000 +0900
@@ -209,6 +209,8 @@
   do k=1,ndpt
     f(1,k) = (f(1,k)-xlm)*1000.;  ic = nint(f(1,k)/smx)
     f(2,k) = (f(2,k)-ylm)*1000.;  jc = nint(f(2,k)/smy)
+    if ((ic < 0) .or. (ic >= mxm)) cycle
+    if ((jc < 0) .or. (jc >= mym)) cycle
     ht = tt(ic+1,jc+1)
     if (ht /= tnul) then
       z = f(3,k) - ht;  if (z < zd) zd = z
diff -u ORG/anamx/exdeq3.f90 anamx/exdeq3.f90
--- ORG/anamx/exdeq3.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/exdeq3.f90	2018-12-04 11:20:00.000000000 +0900
@@ -266,6 +266,8 @@
   do k=1,ndpt
     f(1,k) = (f(1,k)-xlm)*1000.;  ic = nint(f(1,k)/smx)
     f(2,k) = (f(2,k)-ylm)*1000.;  jc = nint(f(2,k)/smy)
+    if ((ic < 0) .or. (ic >= mxm)) cycle
+    if ((jc < 0) .or. (jc >= mym)) cycle
     ht = tt(ic+1,jc+1)
     if (ht /= tnul) then
       z = f(3,k) - ht;  if (z < zd) zd = z
diff -u ORG/anamx/exdeq4.f90 anamx/exdeq4.f90
--- ORG/anamx/exdeq4.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/exdeq4.f90	2018-12-04 11:20:00.000000000 +0900
@@ -317,6 +317,8 @@
   do k=1,ndpt
     f(1,k) = (f(1,k)-xlm)*1000.;  ic = nint(f(1,k)/smx)
     f(2,k) = (f(2,k)-ylm)*1000.;  jc = nint(f(2,k)/smy)
+    if ((ic < 0) .or. (ic >= mxm)) cycle
+    if ((jc < 0) .or. (jc >= mym)) cycle
     ht = tt(ic+1,jc+1)
     if (ht /= tnul) then
       z = f(3,k) - ht;  if (z < zd) zd = z
diff -u ORG/anamx/fimgs.f90 anamx/fimgs.f90
--- ORG/anamx/fimgs.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/fimgs.f90	2018-05-15 18:47:28.000000000 +0900
@@ -376,6 +376,7 @@
   write(6,'(a5,i4,3x,a13,f7.3,a2,f7.4,3x,a6,f7.2,3x,a6,f7.2)')   &
       ' loop', klp, 'rms.Step/Src.', 0., ' /', rv, 'Misfit', dv, 'T.Res.', dv
   write(9,*) klp, 0., 0., rv, dv, dv
+  flush(6)        !--- or  call flush(6)
 
   if (nloop /= 0) then
     ilp = 1;  klp = klp + 1
@@ -426,6 +427,7 @@
       ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
     write(9,*) klp, ee, rs, rv, dv, tr
     kc = 0;  trp = tr
+    flush(6)        !--- or  call flush(6)
   endif
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
@@ -592,7 +594,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/fimgsc.f90 anamx/fimgsc.f90
--- ORG/anamx/fimgsc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/fimgsc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -416,6 +416,7 @@
     ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
   write(9,*) klp, ee, rs, rv, dv, tr
   kc = 0;  trp = tr
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -495,6 +496,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -582,7 +584,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/genroff.f90 anamx/genroff.f90
--- ORG/anamx/genroff.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/genroff.f90	2019-03-11 13:31:00.000000000 +0900
@@ -3,6 +3,7 @@
   integer :: lwkdir, lrtrim
   real,allocatable :: var(:,:)
   real(8),allocatable :: dlat(:), dlon(:)
+  character(8),allocatable :: lnam(:)
   character(80) :: wdr, flog, fnam1, fnam2, fnam3, sfnam, buf
   character(20) :: sdtm;  character(8) :: area, spec, s1, s2
   character(3) :: yn
@@ -39,11 +40,13 @@
   read(2,'(a)') sfnam
   k = 0;  dlats = 0.;  dlons = 0.;  vmags = 0.
 
-  allocate(dlat(npv));  allocate(dlon(npv));  allocate(var(4,npv))
+  allocate(dlat(npv));  allocate(dlon(npv))
+  allocate(var(4,npv));  allocate(lnam(npv))
 
   do n=1,npv
     read(2,'(a8,i12,2x,a8,f10.2)') s1, kd, s2, var(4,n)
     if (yn == 'Yes') var(4,n) = -var(4,n)
+    lnam(n) = s1
     do
       read(1,'(a)') buf
       do while ((buf(1:1) == '#') .or. (buf(1:1) == '&'))
@@ -104,7 +107,11 @@
   write(3,'(a1,1x,a8,4x,a4,i6,4x,a16,a8)')   &
       '#', area, 'npv=', npv, 'Trend Removal : ', spec
   write(3,'(a,a)') '# InvertSign: ', yn
+  s1 = "        "
   do n=1,npv
+    if (lnam(n) /= s1) then
+      s1 = lnam(n); write(3,'(a1,a8)') '&', s1
+    endif
     write(3,'(f12.5,2hN ,f12.5,2hE ,f8.2,2hm ,f8.2,2hnT)')   &
       dlat(n), dlon(n), var(3,n), var(4,n)
   enddo
diff -u ORG/anamx/nimgn.f90 anamx/nimgn.f90
--- ORG/anamx/nimgn.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/nimgn.f90	2018-05-15 18:47:28.000000000 +0900
@@ -401,6 +401,7 @@
     write(9,*) klp, ee, rs, rv, dv, tr
     kc = 0;  trp = tr
   endif
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -471,6 +472,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -558,7 +560,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/nimgnc.f90 anamx/nimgnc.f90
--- ORG/anamx/nimgnc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/nimgnc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -391,6 +391,7 @@
     ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
   write(9,*) klp, ee, rs, rv, dv, tr
   kc = 0;  trp = tr
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -461,6 +462,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -548,7 +550,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/nimgs.f90 anamx/nimgs.f90
--- ORG/anamx/nimgs.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/nimgs.f90	2018-05-15 18:47:26.000000000 +0900
@@ -398,6 +398,7 @@
     write(9,*) klp, ee, rs, rv, dv, tr
     kc = 0;  trp = tr
   endif
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -468,6 +469,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -554,7 +556,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/nimgsc.f90 anamx/nimgsc.f90
--- ORG/anamx/nimgsc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/nimgsc.f90	2018-05-15 18:47:28.000000000 +0900
@@ -388,6 +388,7 @@
     ' loop', klp, 'Updated hyper-parameter =', ee, 'T.Res.', tr
   write(9,*) klp, ee, rs, rv, dv, tr
   kc = 0;  trp = tr
+  flush(6)        !--- or  call flush(6)
 
   do while ((kc < 5) .and. (dv >= 0.1) .and. (ilp < nloop))
     ilp = ilp + 1;  klp = klp + 1
@@ -458,6 +459,7 @@
       write(9,*) klp, ee, rs, rv, dv, tr
     endif
     trp = tr
+    flush(6)        !--- or  call flush(6)
   enddo
 
   write(6,'(1x)')
@@ -544,7 +546,7 @@
       write(99,'(22x,a)') 'Linear trend removed'
       write(99,'(a,f8.2,a,f7.3,a,f7.3,a)')   &
         ' Trend surface in nT :', cf, ' + (', af, ' * x) + (', bf, ' * y)'
-      write(6,'(5x,a)')   &
+      write(99,'(5x,a)')   &
         '( x/y : N/E coord. in mesh unit referred to the center of area )'
     else
       write(99,'(22x,a)') 'without removal of Linear trend'
diff -u ORG/anamx/plmvarc.f90 anamx/plmvarc.f90
--- ORG/anamx/plmvarc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/plmvarc.f90	2019-02-09 23:00:00.000000000 +0900
@@ -5,12 +5,11 @@
   real,allocatable :: g(:)
   character(80) :: wdr, flog, fnin, fnln, fnpt, fnam, buf
   character(72) :: out;  character(20) :: sdtm;  character(8) :: area;
-  character(6) :: s6;  character(4) :: s4
-  character(3) :: spl = '   ';  character(1) :: yn
+  character(6) :: s6, ss;  character(3) :: spl = '   ';  character(1) :: yn
   integer :: kclo = Z'005576', kchi = Z'67006a', kcnv = Z'e8e8e8'
   integer :: mrgb(30)
   integer :: ldr, mc, i, j, n, k, IER
-  integer :: istep, istp, kpl, kscl, klll, kshl, km, iinc, kinc
+  integer :: istep, istp, kpl, kscl, klll, kshl, km, ls, iinc, kinc
   integer :: nc, ncc, iorg, korg, ispa, ispb
   integer :: ixs, iys, mszx, mszy, nmx, nmy
   integer :: isf, itf, ksf, ktf, idf, kdf, mval, np
@@ -151,40 +150,76 @@
   if ((np < 1) .or. (np > 8)) call abendm('invalid pen number')
   fscl = fscl * 100.;  ccm = fscl/100000.
   kleg = 0;  kscl = 0;  sclr = 0.;  sclu = 0.;  klll = 0;  kshl = 0
-  if ((fscl < 3333334.) .and. (fscl >= 20000.)) then
-    km = nint(fscl)/25000
-    if (km == 0)  km = 1
-    if (km > 50) km = 50
-    if ((km > 2) .and. (km < 5))   km = 2
-    if ((km > 5) .and. (km < 10))  km = 5
-    if ((km > 10) .and. (km < 20)) km = 10
-    if ((km > 20) .and. (km < 50)) km = 20
-    iinc = km;  kinc = km + km/2
-    if (km == 50) iinc = 60
-    if ((km == 1) .or. (km == 5) .or. (km == 50)) kinc = iinc
-    dscl = float(km)/ccm
-    call prompt('  Draw  ColorGrading Legend  ?  ')
-    call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
-    if ((yn == 'y') .or. (yn == 'Y')) then
-      kleg = 1;  dleg = float(11+nspc) * 0.8
-      write(out,'(a,f4.1,a)') '      size :  2cm Wide,', dleg, 'cm High'
-      call premsg(out)
-      call prompt('    Lower-Left Pos. ? (right and up)')
-      call gparmf2(' in cm ==> ', slgr, slgu)
+  if (fscl < 25000.) then               !ScaleBar (km [m])
+    km = nint(fscl)/25
+    if (km < 2) then
+      km = 1;  ss = '1 m';  ls = 3
+    else if (km < 5) then
+      km = 2;  ss = '2 m';  ls = 3
+    else if (km < 10) then
+      km = 5;  ss = '5 m';  ls = 3
+    else if (km < 20) then
+      km = 10;  ss = '10 m';  ls = 4
+    else if (km < 50) then
+      km = 20;  ss = '20 m';  ls = 4
+    else if (km < 100) then
+      km = 50;  ss = '50 m';  ls = 4
+    else if (km < 200) then
+      km = 100;  ss = '100 m';  ls = 5
+    else if (km < 500) then
+      km = 200;  ss = '200 m';  ls = 5
+    else
+      km = 500;  ss = '500 m';  ls = 5
     endif
-    call prompt('  Draw  Scale Bar  ?  ')
-    call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
-    if ((yn == 'y') .or. (yn == 'Y')) then
-      kscl = 1
-      write(out,'(a,f4.1,a)') '      size :', dscl, 'cm Wide, 0.8cm High'
-      call premsg(out)
-      call prompt('    Lower-Left Pos. ? (right and up)')
-      call gparmf2(' in cm ==> ', sclr, sclu)
+      iinc = 1;  kinc = 1               ![LatLonIntv]: 1min x 1min
+    dscl = float(km*100) / fscl
+  else                                  !ScaleBar (km [km])
+    km = nint(fscl)/25000
+    if (km < 2) then
+      km = 1;  ss = '1 km';  ls = 4     ![LatLonIntv]: 1min x 1min
+    else if (km < 5) then
+      km = 2;  ss = '2 km';  ls = 4         !  2min x 3min
+    else if (km < 10) then
+      km = 5;  ss = '5 km';  ls = 4         !  5min x 5min
+    else if (km < 20) then
+      km = 10;  ss = '10 km';  ls = 5       ! 10min x 15min
+    else if (km < 50) then
+      km = 20;  ss = '20 km';  ls = 5       ! 20min x 30min
+    else if (km < 100) then
+      km = 50;  ss = '50 km';  ls = 5       !  1deg x 1deg
+    else if (km < 200) then
+      km = 100;  ss = '100 km';  ls = 6     !  2deg x 3deg
+    else if (km < 500) then
+      km = 200;  ss = '200 km';  ls = 6     !  5deg x 5deg
+    else
+      km = 500;  ss = '500 km';  ls = 6     ! 10deg x 10deg
     endif
-    call prompt('  Draw Lat.Lon.Lines ?')
-    call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
-    if ((yn == 'y') .or. (yn == 'Y')) klll = 1
+    iinc = km;  if (km >= 50) iinc = km + km/5;  kinc = iinc
+    if ((km==2) .or. (km==10) .or. (km==20) .or. (km==100))   &
+      kinc = iinc + iinc/2
+    dscl = float(km)/ccm
+  endif
+  call prompt('  Draw  ColorGrading Legend  ?  ')
+  call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
+  if ((yn == 'y') .or. (yn == 'Y')) then
+    kleg = 1;  dleg = float(11+nspc) * 0.8
+    write(out,'(a,f4.1,a)') '      size :  2cm Wide,', dleg, 'cm High'
+    call premsg(out)
+    call prompt('    Lower-Left Pos. ? (right and up)')
+    call gparmf2(' in cm ==> ', slgr, slgu)
   endif
+  call prompt('  Draw  Scale Bar  ?  ')
+  call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
+  if ((yn == 'y') .or. (yn == 'Y')) then
+    kscl = 1
+    write(out,'(a,f4.1,a)') '      size :', dscl, 'cm Wide, 0.8cm High'
+    call premsg(out)
+    call prompt('    Lower-Left Pos. ? (right and up)')
+    call gparmf2(' in cm ==> ', sclr, sclu)
+  endif
+  call prompt('  Draw Lat.Lon.Lines ?')
+  call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
+  if ((yn == 'y') .or. (yn == 'Y')) klll = 1
   call prompt('  Draw Coastlines ?   ')
   call gparma('  "y" for Yes, othewise No ==> ', 1, yn)
   if ((yn == 'y') .or. (yn == 'Y')) then
@@ -268,9 +303,8 @@
     call plot(sclr+dscl, sclu,     2)
     call plot(sclr,      sclu,     2)
     call plot(sclr,      sclu+0.3, 2)
-    write(s4,'(i2,a2)') km, 'km'
     call lstyle('T', 0.5, 0., 0, -255)
-    call ptext(s4, 4, sclr+dscl/2., sclu+0.5, 2)
+    call ptext(ss, ls, sclr+dscl/2., sclu+0.5, 2)
     call newpen(1)
   endif
   call scisor(0., 0., wide, high)
diff -u ORG/anamx/plsim.f90 anamx/plsim.f90
--- ORG/anamx/plsim.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/plsim.f90	2018-05-06 00:29:18.000000000 +0900
@@ -114,7 +114,7 @@
     if ((1+nkw) >= (my-nke)) call abendm('no range')
     np = my - nke - nkw;  hlen = float(mszy * (np-1))
     write(str1,'(a,i4)') 'W-E  ix#', nsec
-    write(str2,'(a,i3,2x,a,i3,a)') '(LmW=', nks, 'LmE=', nkn, ')'
+    write(str2,'(a,i3,2x,a,i3,a)') '(LmW=', nkw, 'LmE=', nke, ')'
 
     allocate(z(np));  allocate(v(np,nly))
 
diff -u ORG/anamx/plsimc.f90 anamx/plsimc.f90
--- ORG/anamx/plsimc.f90	2017-12-23 18:00:00.000000000 +0900
+++ anamx/plsimc.f90	2018-05-06 00:29:20.000000000 +0900
@@ -114,7 +114,7 @@
     if ((1+nkw) >= (my-nke)) call abendm('no range')
     np = my - nke - nkw;  hlen = float(mszy * (np-1))
     write(str1,'(a,i4)') 'W-E  ix#', nsec
-    write(str2,'(a,i3,2x,a,i3,a)') '(LmW=', nks, 'LmE=', nkn, ')'
+    write(str2,'(a,i3,2x,a,i3,a)') '(LmW=', nkw, 'LmE=', nke, ')'
 
     allocate(z(np));  allocate(v(np,nly))
 
