Warning, /utils/matlab/ioLb2num.m is written in an unsupported language. File is not indexed.
view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
fa492de2af Jean*0001 function [iTr] = ioLb2num( ioLb );
0002 % [iTr] = ioLb2num( ioLb );
0003 % convert MITgcm ptracer-io label (2 characters) to ptracer number
0004 % do conversion on individual 2c label
0005 % or on character array ( N x 2c ) and then return number array (N x 1)
0006
0007 if size(ioLb,2) == 1 & size(ioLb,2) == 2,
0008 N=1; ioLb=ioLb';
0009 else
0010 N=size(ioLb,1);
0011 end
0012
0013 %- step 1 : convert to 2 ASCII code: j1,j2
0014 jj=double(ioLb); j1=jj(:,1); j2=jj(:,2);
0015 %fprintf(['%4i ',c1,c2,' %3i %3i\n'],i,j1,j2);
0016
0017 % native2unicode() ; unicode2native() :
0018 % 0-9 :: 48-57
0019 % A-Z :: 65-90
0020 % a-z :: 97-122
0021 n0=double('0'); ne=10+n0;
0022 n1=double('A');
0023 n2=double('a');
0024 nd=double('-');
0025
0026 %- step 2 : convert to 2 digits k1,k2 (both in [0,61])
0027 iTr=-ones(N,1);
0028 k1=j1-n1+36;
0029 [J]=find( j1 < ne ); k1(J)=j1(J)-n0;
0030 [J]=find( j1 >= n2 ); k1(J)=j1(J)-n2+10;
0031 [J]=find( j1 < n0 ); k1(J)=0;
0032 k2=j2-n1+36;
0033 [I]=find( j2 < ne ); k2(I)=j2(I)-n0;
0034 [I]=find( j2 >= n2 ); k2(I)=j2(I)-n2+10;
0035 [I]=find( j2 < n0 ); k2(I)=0;
0036
0037 %- step 3 : build number in modified 62 base from 2 digits k1,k2
0038 % 620 = 100 + (10*2*26) ; 52 = 26+26 ; 62=10+26+26
0039 iTr= 0 + 62*k1 + k2;
0040 [I]=find( j1 < ne & j2 < ne ); iTr(I)= 0 + 10*k1(I) + k2(I);
0041 [I]=find( j1 < ne & j2 > ne ); iTr(I)=90 + 52*k1(I) + k2(I);
0042 [I]=find( j1 < n0 | j2 < n0 ); iTr(I)=0;
0043
0044 return