Back to home page

MITgcm

 
 

    


Warning, /utils/matlab/num2ioLb.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 [ioLb] = num2ioLb( iTr );
                0002 % [ioLb ] = num2ioLb( iTr);
                0003 % convert ptracer number to MITgcm ptracer-io label (2 characters)
                0004 %  do conversion on individual number (return a 2c label)
                0005 %  or on number array (N x 1) and then return a character array ( N x 2c )
                0006 
                0007  N=prod(size(iTr)); iTr=reshape(iTr,[N 1]);
                0008 
                0009 %- step 1 : express number in modified 62/52/10 base, digits: k1,k2
                0010 
                0011 %- base 52 in [100,620-1]
                0012  k2=fix(iTr-100);
                0013  k1=fix(k2/52);
                0014  k2=rem(k2,52)+10;
                0015 %- base 10 in [1,100-1]
                0016  [I]=find( iTr < 100 );
                0017  s0=fix(iTr-0);
                0018  tt=fix(s0/10);
                0019  k1(I)=tt(I);
                0020  tt=rem(s0,10);
                0021  k2(I)=tt(I);
                0022 %- base 62 in [620,62^2-1]
                0023  [I]=find( iTr >= 620 );
                0024  tt=fix(s0/62);
                0025  k1(I)=tt(I);
                0026  tt=rem(s0,62);
                0027  k2(I)=tt(I);
                0028 
                0029 %- step 2 : convert digits k1,k2 to ASCII code: j1,j2
                0030 % 0-9 :: 48-57
                0031 % A-Z :: 65-90
                0032 % a-z :: 97-122
                0033  n0=double('0');
                0034  n1=double('A');
                0035  n2=double('a');
                0036  nd=double('-');
                0037 % -36+65 = +29 ; -10+97 = +87
                0038  j1=k1-10+n2;
                0039  [I]=find(k1 >= 36 ); j1(I)=k1(I)-36+n1;
                0040  [I]=find(k1 < 10 ) ; j1(I)=k1(I)+n0;
                0041  j2=k2-10+n2;
                0042  [I]=find(k2 >= 36 ); j2(I)=k2(I)-36+n1;
                0043  [I]=find(k2 < 10 ) ; j2(I)=k2(I)+n0;
                0044 
                0045  [I]=find( iTr >= 62*62 ); j1(I)=nd; j2(I)=nd;
                0046 
                0047 %- step 3 : do the conversion to ASCII code
                0048 
                0049 % uses: char(); double();
                0050  ioLb=char([j1 j2]);
                0051 
                0052 % native2unicode() ; unicode2native() : <- much slower
                0053 %c1=native2unicode(j1);
                0054 %c2=native2unicode(j2);
                0055 %ioLb=strcat(c1,c2);
                0056 
                0057 return