%===== Display binary Near real time data =============================%
%  Example;
%  >> dsp_modnrt
%  Input File = ...please type file name with path, and hit return...
%
%           MATLAB m-file  coded by H. Murakami, EORC/NASDA 21 Nov. 2002
%
% Optional input:
%  color palette /export/emc2/murakami/GOCC.pal','r');
%  coast line    /export/emc2/murakami/MAPDATA/map1km.100_170_010_070
%======================================================================%
clear
infile=input('(dir/)Input File = ','s');
%
f_print='off';     % <- PS-file output 'on' or 'off'
coastl='off';     % <- overlay coast line 'on' or 'off'
coastl=input('> Coastline on or off = ','s');
if size(coastl,2)<1;coastl='off';end
cl_sft(1)=0;cl_sft(2)=0;
% cl_sft(1)=-0.01;cl_sft(2)=-0.05;   % <-tentative 250m
% cl_sft(1)=-0.04;cl_sft(2)=-0.02;   % <-tentative
f_logo='off';     % <- on or off
aspr=1;          % 0: auto, 1: equal
%
%--- lat lon range ---
lats=[-999,-999];lons=[-999,-999];  % if lats or lons ==-999;full scene
%------ if you want extract, please define lat-lon area like follows -----
%lats=[41,46];lons=[139,146];  % for zoom up of Hokkaido
%lats=[30,47];lons=[127,148];  % for zoom up of winter serge
%lats=[32,33.5];lons=[129.5,130.8];  % for zoom up of Ariake Bay
%lats=[25,35];lons=[124,132];  % for East China Sea
%lats=[43,48];lons=[142,146];  % for Okhotsk
%lats=[24,41];lons=[120,136];  % for East China Sea test
%lats=[43.8,44.8];lons=[143.2,144.6];  % for Saroma
%lats=[19,32];lons=[124,132];  % for 20020707
%lats=[34,37];lons=[138,141];  % for 20020711
%-------------------------------------------------------------------------
%
head=zeros(1,7);
f1=fopen([infile],'r');
if f1>-1;
%
head=fscanf(f1,'%d %d %g %g %g %g %g');fclose(f1);
if size(head,1)<1;
 head=zeros(7,1);
 head(1)=input('Pixel size = ');
 head(2)=input('Line size  = ');
 head(3)=input('UL long    = ');
 head(4)=input('UL lati    = ');
 head(5)=input('Resolution = ');
 head(6)=input('Slope      = ');
 head(7)=input('Offset     = ');
 label='';
 para0='';
 para   =input('Param name = ','s');
 if size(para,2)<1;para='        ';end
 k1=0;k2=0;k3=0;k4=0;
 loff=0;
else
 f1=fopen([infile],'r');
 para0=fread(f1,[125,1],'char');fclose(f1);
 k1=0;k2=0;
 for k=1:69;
  if k1==0 & para0(k:k)==','; k1=k+1;end;
  if k1>0 & (para0(k:k)==' ' | para0(k:k)==','); k2=k-1;end;
 end
 para='        ';
 para(1:k2-k1+1)=char(para0(k1:k2)');
 k3=0;k4=0;
 for k=k2+2:125;
  if k3==0 & para0(k:k)~=' '; k3=k;end;
  if para0(k:k)~=' ' | para0(k+1:k+1)==','; k4=k;end;
 end
 label(1:k4-k3+1)=char(para0(k3:k4)');
 loff=1;
end
%
nl=head(1);ml=head(2);dd=head(5);if dd<0.00001;dd=0.0025;end
if lons(1)==-999;slon=head(3);else;slon=lons(1);end
if lons(2)==-999;elon=slon+(nl-1)*dd;else;elon=lons(2);end
if lats(2)==-999;slat=head(4);else;slat=lats(2);end
if lats(1)==-999;elat=slat-(ml-1)*dd;else;elat=lats(1);end
%
subdeg=[slon,elon,slat,elat];
avlat=(slat+elat)/2*pi/180;
if aspr<0.1;aspr=sqrt(1/cos(avlat));end
%if aspr<0.1;aspr=1/cos(avlat);end
%
subset0(1:2)=round((subdeg(1:2)-head(3))/dd+1);
subset0(3:4)=round((head(4)-subdeg(3:4))/dd+1);
nl0=subset0(2)-subset0(1)+1;ml0=subset0(4)-subset0(3)+1;
subset(1)=max( 1,subset0(1));if subset0(1)<1;ofsn=-subset0(1)-1;else;ofsn=0;end
subset(2)=min(nl,subset0(2));
subset(3)=max( 1,subset0(3));if subset0(3)<1;ofsm=-subset0(3)+1;else;ofsm=0;end
subset(4)=min(ml,subset0(4));
nll=subset(2)-subset(1)+1;mll=subset(4)-subset(3)+1;
%
if subdeg(2)-subdeg(1)>16;inc=floor((subdeg(2)-subdeg(1))/8);
elseif subdeg(2)-subdeg(1)<3;inc=0.2;
elseif subdeg(2)-subdeg(1)<5;inc=0.5;
else;inc=1;end
lon=[ceil(subdeg(1)/inc-0.0001)*inc:inc:subdeg(2)];
lat=[floor(subdeg(3)/inc+0.0001)*inc:-inc:subdeg(4)];
lo1=round((lon-subdeg(1))/dd+1);
la1=round((subdeg(3)-lat)/dd+1);
%
for k=1:size(lon,2);
 if     lon(k)> 180;lon(k)=lon(k)-360;
 elseif lon(k)<-180;lon(k)=lon(k)+360;
 end
end
%
f1=fopen([infile],'r');
if loff<1;
 c1=uint8(zeros(ml0,nl0));
 fseek(f1,nl*4*loff,'bof');
 a1=fread(f1,[nl ml],'float32');fclose(f1);
 b1=a1(subset(1):subset(2),subset(3):subset(4))';
 lnd=(b1<0);
 avl=1-lnd;
 b1=b1*head(6)+head(7);
 dat_min=min(min(b1));
 b1=b1.*avl;
 dat_max=max(max(b1));
 dat_rng=dat_max-dat_min;
 dat_max=dat_max+dat_rng*0.05;
 dat_rng=dat_max-dat_min;
 dat_max=dat_max+dat_rng*0.05;
 dat_min=max(0,dat_min-dat_rng*0.05);
 clear a1 avl;
 npt=256; 
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd)+lnd*(npt-1));
 clear lnd b1;
 f1=fopen('/export/emc2/murakami/GRAD_black.pal','r');
 if f1>-1;
  ba1=fread(f1,[256 3],'uint8');fclose(f1);
  gg=zeros(npt,3);gg=ba1/255;
 else;
  gg=jet(npt);
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 end
%
elseif para(1:4)=='nLw_' | para(1:4)=='tau_'| para(1:4)=='alph'| para(1:4)=='L412';
 c1=uint8(zeros(ml0,nl0)); 
 fseek(f1,nl*2*loff,'bof');
 a1=fread(f1,[nl ml],'uint16');fclose(f1);
 b1=a1(subset(1):subset(2),subset(3):subset(4))';
 lnd=(b1>65534);
 avl=(b1<65534)&(b1>0);
 b1=b1*head(6)+head(7);
 dat_min=min(min(b1+(1-avl)*65535));
 b1=b1.*avl;
 dat_max=max(max(b1));
 dat_rng=dat_max-dat_min;
 dat_max=dat_max+dat_rng*0.05;
 dat_rng=abs(dat_max-dat_min);
 dat_max=dat_max+dat_rng*0.05;
 dat_min=max(0,dat_min-dat_rng*0.05);
 if para(1:4)=='nLw_';
  if     str2num(para(5:7))<600;dat_max=2.5;dat_min=0;
  elseif str2num(para(5:7))<650;dat_max=0.5;dat_min=0;
  else;                         dat_max=0.3;dat_min=0;
  end
  dat_rng=abs(dat_max-dat_min);
 end
 clear a1 avl;
 npt=256; 
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd)+lnd*(npt-1));
 clear lnd b1;
 f1=fopen('/export/emc2/murakami/GRAD_black.pal','r');
 if f1>-1;
  ba1=fread(f1,[256 3],'uint8');fclose(f1);
  gg=zeros(npt,3);gg=ba1/255;
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 else;
  gg=jet(npt);
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 end
%
elseif para(1:3)=='RcR' | para(1:3)=='nLw' | para(5:7)=='rgb';
 c1=uint8(zeros(ml0,nl0,3));
 fseek(f1,nl*loff,'bof');
 dat_max=255;dat_min=0;
 for j=1:3;
  a1=uint8(fread(f1,[nl ml],'uint8'));
  c1(ofsm+[1:mll],ofsn+[1:nll],j)=a1(subset(1):subset(2),subset(3):subset(4))';
 end
 fclose(f1);
 clear a1;
% a0=fopen('/export/emc2/murakami/GRAD.pal','r');
 a0=fopen('/export/emc2/murakami/GRAD_black.pal','r');
 if a0>-1;gg=fread(a0,[256 3],'uint8')/255;fclose(a0);
 else;gg=jet(npt);end
 if para(1:3)=='sst';
  dat_max=36.25;dat_min=-2;
  if para(5:7)=='rgb';
   dat_min=head(7);
   dat_max=dat_min+head(6)*255;
  end
 elseif para(1:3)=='chl' | para(1:3)=='CHL';
  dat_max=2;dat_min=-2;
  a0=fopen('/export/emc2/murakami/GOCC.pal','r');
  if a0>-1;gg=fread(a0,[256 3],'uint8')/255;fclose(a0);
  else;gg=jet(npt);end
 end
elseif para(1:3)=='sst';
 c1=uint8(zeros(ml0,nl0));
 fseek(f1,nl*2*loff,'bof');
 a1=fread(f1,[nl ml],'uint16');fclose(f1);
 b1=a1(subset(1):subset(2),subset(3):subset(4))'*head(6)+head(7)-273.15;
 lnd=(a1(subset(1):subset(2),subset(3):subset(4))>65534)';
 clear a1;
 dat_max=35;dat_min=-5;npt=256;
% dat_max=35;dat_min=-20;npt=256;
% dat_max=32;dat_min=20;npt=256;  % for 20020707
% dat_max=32;dat_min=24;npt=256;  % for 20020823
% dat_max=28;dat_min=8;npt=256;  % for 20020528
% dat_max=30;dat_min=22;npt=256;  % for 20020525
% dat_max=29;dat_min=20;npt=256;  % for 20020614
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd)+lnd*(npt-2));
 clear lnd b1;
 f1=fopen('/export/emc2/murakami/GOCC.pal','r');
 if f1>-1;
  ba1=fread(f1,[256 3],'uint8');fclose(f1);
  gg=zeros(npt,3);gg=ba1(round([34:0.7:213]),:)/255;
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0,0,0];gg(npt-1,1:3)=[0.4,0.4,0.4];
 else;
  gg=jet(npt);
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 end
%
elseif para(1:3)=='chl' | para(1:3)=='CHL';npt=256;
 c1=uint8(zeros(ml0,nl0));
 fseek(f1,nl*2*loff,'bof');
 a1=fread(f1,[nl ml],'uint16');fclose(f1);
 lnd=(a1(subset(1):subset(2),subset(3):subset(4))>65534)';
 out=(a1(subset(1):subset(2),subset(3):subset(4))>65533)'.*(1-lnd);
 msk=(a1(subset(1):subset(2),subset(3):subset(4))<1)';
 b1=log10(a1(subset(1):subset(2),subset(3):subset(4))'*head(6).*(1-msk)+0.000001*msk);
 clear a1 msk;
% dat_max=2.02;dat_min=-2; 
% dat_max=1.2;dat_min=-2;  % for 20020707
% dat_max=log10(60);dat_min=log10(0.01);
 dat_max=log10(120);dat_min=log10(0.01);  % for general
% dat_max=log10(10);dat_min=log10(0.01);
% dat_max=log10(120);dat_min=log10(0.03);
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd).*(1-out)+lnd*(npt-2)+out*(npt-1));
 clear lnd out b1;
 a0=fopen('/export/emc2/murakami/GOCC.pal','r');
 if a0>-1;
  ba1=fread(a0,[256 3],'uint8');fclose(a0);
  gg=ba1/255;
 else
  gg=jet(npt);
 end
% gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0,0,0];gg(npt-1,1:3)=[0.4,0.4,0.4];
%
elseif para(1:2)=='ss' | para(1:2)=='cd' | para(1:2)=='k4';npt=256;
 c1=uint8(zeros(ml0,nl0));
 fseek(f1,nl*2*loff,'bof');
 a1=fread(f1,[nl ml],'uint16');fclose(f1);
 lnd=(a1(subset(1):subset(2),subset(3):subset(4))>65534)';
 out=(a1(subset(1):subset(2),subset(3):subset(4))>65533)'.*(1-lnd);
 msk=(a1(subset(1):subset(2),subset(3):subset(4))<1)';
 b1=log10(a1(subset(1):subset(2),subset(3):subset(4))'*head(6).*(1-msk)+0.000001*msk);
 clear a1 msk;
 if     para(1:2)=='cd';dat_max=1.02;dat_min=-3; dat_max=0;dat_min=-3.1;
 elseif para(1:2)=='k4';dat_max=1.02;dat_min=-3; 
 elseif para(1:2)=='ss';dat_max=log10(120);dat_min=log10(0.01);
 end
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd).*(1-out)+lnd*(npt-2)+out*(npt-1));
 clear lnd out b1;
 a0=fopen('/export/emc2/murakami/GOCC.pal','r');
 if a0>-1;
  ba1=fread(a0,[256 3],'uint8');fclose(a0);
  gg=ba1/255;
 else
  gg=jet(npt);
 end
% gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0,0,0];gg(npt-1,1:3)=[0.4,0.4,0.4];
%
elseif para(1:3)=='HKr';
 c1=uint8(zeros(ml0,nl0,3));
 fseek(f1,nl*loff,'bof');
 for j=1:3;
  a1=uint8(fread(f1,[nl ml],'uint8'));
  c1(ofsm+[1:mll],ofsn+[1:nll],j)=a1(subset(1):subset(2),subset(3):subset(4))';
 end
 fclose(f1);
 clear a1;
%
elseif para(1:3)=='QKr';
 c1=uint8(zeros(ml0,nl0,3));
 fseek(f1,nl*loff,'bof');
 for j=1:2;
  a1=uint8(fread(f1,[nl ml],'uint8'));
  c1(ofsm+[1:mll],ofsn+[1:nll],j)=a1(subset(1):subset(2),subset(3):subset(4))';
 end
 fclose(f1);
 c1(ofsm+[1:mll],ofsn+[1:nll],3)=a1(subset(1):subset(2),subset(3):subset(4))';
 clear a1;
%
elseif para(1:3)=='par';
 c1=uint8(zeros(ml0,nl0));
 fseek(f1,nl*2*loff,'bof');
 a1=fread(f1,[nl ml],'uint16');fclose(f1);
 b1=a1(subset(1):subset(2),subset(3):subset(4))';
 lnd=(b1>65534);
 b1=b1*head(6)+head(7);
 dat_min=0;dat_max=70;
 dat_rng=dat_max-dat_min;
 clear a1;
 npt=256; 
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/dat_rng.*(1-lnd)+lnd*(npt-1));
 clear lnd b1;
 f1=fopen('/export/emc2/murakami/GRAD_black.pal','r');
 if f1>-1;
  ba1=fread(f1,[256 3],'uint8');fclose(f1);
  gg=zeros(npt,3);gg=ba1/255;
 else;
  gg=jet(npt);
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 end
%
elseif para(5:6)=='ch';
 c1=uint8(zeros(ml0,nl0));
 fseek(f1,nl*2*loff,'bof');
 a1=fread(f1,[nl ml],'uint16');fclose(f1);
 b1=a1(subset(1):subset(2),subset(3):subset(4))';
 lnd=(b1>65534);
% avl=(b1<32767);
 avl=(b1<65534);
 b1=b1*head(6)+head(7);
 dat_min=min(min(b1));
 b1=b1.*avl;
 dat_max=max(max(b1));
 dat_rng=dat_max-dat_min;
 dat_max=dat_max+dat_rng*0.05;
 dat_rng=dat_max-dat_min;
 dat_max=dat_max+dat_rng*0.05;
 dat_min=max(0,dat_min-dat_rng*0.05);
% dat_min=3.7;dat_max=4.1;dat_rng=dat_max-dat_min;
 clear a1 avl;
 npt=256; 
% c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd)+lnd*(npt-2));
 c1(ofsm+[1:mll],ofsn+[1:nll])=uint8((npt-1)*(b1-dat_min)/(dat_max-dat_min).*(1-lnd)+lnd*(npt-1));
 clear lnd b1;
% f1=fopen('/export/emc2/murakami/GOCC.pal','r');
 f1=fopen('/export/emc2/murakami/GRAD_black.pal','r');
 if f1>-1;
  ba1=fread(f1,[256 3],'uint8');fclose(f1);
%  gg=zeros(npt,3);gg=ba1(round([34:0.7:213]),:)/255;
  gg=zeros(npt,3);gg=ba1/255;
 else;
  gg=jet(npt);
  gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
 end
% gg(1,1:3)=[1,1,1];gg(npt,1:3)=[0.5,0.5,0.5];gg(npt-1,1:3)=[0.4,0.4,0.4];
end
%------------------------------------------------------ Make new pal
%f1=fopen('/export/emc2/murakami/GOCC.pal','r');
%ba1=fread(f1,[256 3],'uint8');fclose(f1);
%for i=1:256
% i1=32+floor((i-1)*0.69);
% i2=i1+1;
% r1=32+(i-1)*0.68-i1;
% gg(i,:)=round(ba1(i1,:)*(1-r1)+ba1(i1,:)*r1);
%end
%gg(1,1:3)=[255,255,255];
%f1=fopen('Scat.pal','w');
%fwrite(f1,gg,'uint8');
%fclose(f1);
%%f1=fopen('GRAD.pal','w');
%%fwrite(f1,round(gg*255),'uint8');fclose(f1);
%% f1=fopen('GRAD.pal','r');gg=fread(f1,[256 3],'uint8')/255;fclose(f1);
%
%---------------------- Display image ---------------------------
clf
if ml0*aspr>nl0;
set(gcf,'papertype','usletter','PaperOrientation','portrait','PaperPosition',[0.24706 0.25882 8 10.494],'Units','inches');
scps=get(gcf,'position');
set(gcf,'position',[scps(1)+scps(3)-7.2,scps(2)+scps(4)-9.4446,7.2,9.4446])
else
set(gcf,'papertype','usletter','PaperOrientation','landscape','PaperPosition',[0.24706 0.25882 10.494 8],'Units','inches');
scps=get(gcf,'position');
set(gcf,'position',[scps(1)+scps(3)-9.4446,scps(2)+scps(4)-7.2,9.4446,7.2])
end
if para(1:3)=='chl'|para(1:3)=='ss '|para(1:3)=='cdo'|para(1:3)=='k49'|para([4:6])=='_ch'| para(1:3)=='CHL'| para(2:4)=='Lw_'| para(1:3)=='tau'| para(1:3)=='par'| para(1:3)=='alp'| para(1:3)=='sst'| para(1:3)=='L41';
 if mll*aspr>nll;nsz=min(0.80,0.80*nl0/(ml0*aspr)*1.3125);msz=nsz/1.3125*(ml0*aspr)/nl0;
 else;nsz=min(0.80,0.80*nl0/(ml0*aspr)/1.3125);msz=nsz*1.3125*(ml0*aspr)/nl0;end
else
 if mll*aspr>nll;nsz=min(0.87,0.87*nl0/(ml0*aspr)*1.3125);msz=nsz/1.3125*(ml0*aspr)/nl0;
 else;nsz=min(0.87,0.87*nl0/(ml0*aspr)/1.3125);msz=nsz*1.3125*(ml0*aspr)/nl0;end
end
h1=axes('position',[0.07 0.08 nsz msz]);
%[c8,map]=rgb2ind(c1,256,'nodither');imshow(c8,map);  %% for RGB on 8-bit display %%
image(c1);
set(h1,'dataaspectratio',[aspr,1,1])
axis on;grid off;axis('ij');
set(gca,'xtick',lo1,'xticklabel',lon,'fontsize',11);
xlabel('Longitude','fontsize',13);
set(gca,'ytick',la1,'yticklabel',lat,'fontsize',11);
ylabel('Latitude','fontsize',13);
set(gca,'tickdir','out','ticklength',[0.005 0.005])
%
nlg=size(para,2);spara=para;
for k=1:nlg;if para(k:k)=='_';spara(k:k)=' ';end;end
nlg=size(label,2);slabel=label;
for k=1:nlg;if label(k:k)=='_';slabel(k:k)='-';end;end
if spara(1:3)=='nLw';
 title([deblank(slabel)],'fontsize',15)
else
 title([deblank(slabel),', ',deblank(spara)],'fontsize',15)
end
%
%-------------------------- coast line ------------------------------
if coastl(1:2)=='on';
 if slon>100 & elon<165 & slat>20 & elat<70
  mp=fopen('/export/emc2/murakami/MAPDATA/map1km.100_170_010_070','r');
  if mp>-1;l1=load('/export/emc2/murakami/MAPDATA/map1km.100_170_010_070');end
 elseif slon>=0 & elon<60
  mp=fopen('/export/emc2/murakami/MAPDATA/map1km.060_060_070_070','r');
  if mp>-1;l1=load('/export/emc2/murakami/MAPDATA/map1km.060_060_070_070');end
 elseif slon<0
  mp=fopen('/export/emc2/murakami/MAPDATA/map1km.180_180_090_090','r');
  if mp>-1;l1=load('/export/emc2/murakami/MAPDATA/map1km.180_180_090_090');end
 else
  mp=fopen('/export/emc2/murakami/MAPDATA/map1km.000_360_090_090','r');
  if mp>-1;l1=load('/export/emc2/murakami/MAPDATA/map1km.000_360_090_090');end
 end
 if mp>-1;
  l1=[l1(:,1)-slon+cl_sft(1),slat-l1(:,2)+cl_sft(2)]/dd+1;
   hold on;plot(l1(:,1),l1(:,2),'-k','linewidth',0.2);
  fclose(mp);
 end
end
%--------------------------------------------------------------------
%
%----------------------------- Scale bar ------------------------------------
if para(1:3)=='chl'|para(1:3)=='sst' | para(4:6)=='_ch'| para(1:3)=='CHL'| para(1:3)=='ss '| para(1:3)=='cdo'| para(1:3)=='k49'| para(2:4)=='Lw_'| para(1:3)=='tau'| para(1:3)=='par'| para(1:3)=='alp';
 h2=axes('position',[0.09+nsz 0.08 0.05 0.50]);
 ddd=(dat_max-dat_min)/100;ba=[dat_min:ddd:dat_max];
 bb=uint8((ba'-dat_min)/(dat_max-dat_min)*255);
 image(bb);axis on;axis('xy')
 set(h2,'dataaspectratio',[1,10,1])
 set(gca,'xtick',[ ]);
 if para(1:3)=='chl' | para(1:3)=='CHL';
  rbar=[0.01,0.03,0.1,0.3,1,3,10,30];rbar0=((log10(rbar)-dat_min)/ddd)+1;
  text(0.3,-4,'[mg m^{-3}]','fontsize',10);
 elseif para(1:3)=='sst';
  rbar=[dat_min:(dat_max-dat_min)/5:dat_max];rbar0=[1:20:101];
  text(0.3,-4,'[^{o}C]','fontsize',10);
 elseif para(1:3)=='nLw' | para(1:3)=='L41';
  rbar=[dat_min:(dat_max-dat_min)/5:dat_max];rbar0=[1:20:101];
  text(0.3,-4,'[mW cm^{-2} str^{-1} um^{-1}]','fontsize',10);
 elseif para(4:6)=='_ch';
  rbar=[dat_min:(dat_max-dat_min)/5:dat_max];rbar0=[1:20:101];
  text(0.3,-4,'[W m^{-2} str^{-1} um^{-1}]','fontsize',10);
 elseif para(1:4)=='cdom' | para(1:4)=='k490';
  rbar=[dat_min:(dat_max-dat_min)/4:dat_max];rbar0=[1:25:101];
  text(0.3,-4,'log10 [m^{-1}]','fontsize',10);
 elseif para(1:3)=='ss ';
  rbar=[0.01,0.03,0.1,0.3,1,3,10,30];rbar0=((log10(rbar)-dat_min)/ddd)+1;
  text(0.3,-4,'[g m^{-3}]','fontsize',10);
 elseif para(1:3)=='k49';
  rbar=[0.001,0.01,0.1,1];rbar0=((log10(rbar)-dat_min)/ddd)+1;
  text(0.3,-4,'[m^{-1}]','fontsize',10);
 elseif para(1:3)=='tau';
  rbar=[dat_min:(dat_max-dat_min)/5:dat_max];rbar0=[1:20:101];
  text(0.3,-4,'[ ]','fontsize',10);
 elseif para(1:3)=='par' | para(1:3)=='alp';
  rbar=[dat_min:(dat_max-dat_min)/5:dat_max];rbar0=[1:20:101];
  text(0.3,-4,'[Ein/m^{2}/day]','fontsize',10);
 end
 set(gca,'ytick',rbar0,'yticklabel',rbar,'fontsize',10,'yaxislocation','right');
 grid on
 colormap(gg)
end
%------------------------------------------------------------------------------
%
%----------------------  logo -------------------------
if f_logo(1:2)=='on';
 logo=imread('../GLIcal/logo_nasda_eorc.jpg','jpg');
 h=axes('position',[0.08+nsz-0.141 0.025 0.15 0.03]);
 image(logo);
 set(h,'dataaspectratio',[1,1,1]);
 axis off
 logo=imread('../GLIcal/oceanl.jpg','jpg');
 h=axes('position',[0.08+nsz+0.014 0.015 0.042 0.060]);
 image(logo);
 set(h,'dataaspectratio',[1,1,1]);
 axis off
end
%------------------------------------------------------
%
%-------------------- PS file ---------------------------------
if f_print(1:2)=='on';
% print('-dpsc',[label(1:k4-k3+1),'.ps']);
 print('-djpeg',[deblank(label(1:25)),deblank(para(1:4)),'.jpg']);
end
%--------------------------------------------------------------
%
else
 disp(['No Input File = ',infile]);
end
%
