| 1 | function [nIt,rList,tim,vvA,listV,kList]=read_StD(namF,sufx,listV); | function [nIt,rList,tim,vvA,listV,listK]=read_StD(namF,sufx,listV); | 
| 2 | % [nIt,rList,tim,vvA,listV,kList]=read_StD(namF,sufx,listV); | % [nIt,rList,tim,vvA,listV,listK]=read_StD(namF,sufx,listV); | 
| 3 | % | % | 
| 4 | % read ASCII stat-Diags output files (after splitted by script extract_StD) | % read ASCII stat-Diags output files (after splitted by script extract_StD) | 
| 5 | % | % | 
| 6 | % input: listV = list of fileds to read in ; if ='all_flds' => read all fields | % input: listV = list of fileds to read in ; if ='all_flds' => read all fields | 
| 7 | %        namF  = prefix of all file names to read (after extract_StD) | %        namF  = prefix of all file names to read (after extract_StD) | 
| 8 | %        sufx  = suffix of all file names to read (after extract_StD) | %        sufx  = suffix of all file names to read (after extract_StD) | 
| 9 | % output: | % output: | 
| 10 | %  nIt      = number of time reccords | %  nIt      = number of time reccords | 
| 11 | %  rList    = list of region number | %  rList    = list of region number | 
| 12 | %  tim(:,1) = iterations number ; tim(:,2) = time in simulation | %  tim(:,1) = iterations number ; tim(:,2) = time in simulation | 
| 13 | %  listV    = list of fields | %  listV    = list of fields | 
| 14 | %  kList    = list of levels number | %  listK    = list of level numbers | 
| 15 | %  vvA      = 5 dims output array: | %  vvA      = 5 dims output array: | 
| 16 | %           ( kLev, time_rec, region_rec, [ave,std,min,max,vol], var_rec ) | %           ( kLev, time_rec, region_rec, [ave,std,min,max,vol], var_rec ) | 
| 17 |  |  | 
| 26 | fprintf(['read ',sufx,' :']); | fprintf(['read ',sufx,' :']); | 
| 27 | rf=-1; if strcmp(char(listV),'all_flds'), rf=0; end | rf=-1; if strcmp(char(listV),'all_flds'), rf=0; end | 
| 28 |  |  | 
| 29 | %- read from Header file: | %- read from Header file: | 
| 30 | %   frequency ; list of regions ; list of levels ; (+ list of Var, if rf=0) | %   frequency ; list of regions ; list of levels ; (+ list of Var, if rf=0) | 
| 31 | fid=fopen(namfhd,'r'); | fid=fopen(namfhd,'r'); | 
| 32 | D=dir(namfhd); | D=dir(namfhd); | 
| 33 | if size(D,1) == 1, | if size(D,1) == 1, | 
| 34 | fprintf(' head'); | fprintf(' head'); | 
| 35 | else error(['file: ',namfhd,' not found']); return; end | else error(['file: ',namfhd,' not found']); return; end | 
| 36 | flag=1; l=0; k=3; | flag=1; l=0; k=3; | 
| 37 | while flag > 0 | while flag > 0 | 
| 38 | tline=fgetl(fid); | tline=fgetl(fid); | 
| 39 | if ischar(tline), l=l+1; | if ischar(tline), l=l+1; | 
| 40 | %disp(tline); | %disp(tline); | 
| 41 | if tline(2:12) == ' frequency ', | if tline(2:12) == ' frequency ', | 
| 42 | frq=sscanf(tline(17:end),'%f'); | frq=sscanf(tline(17:end),'%f'); | 
| 43 | k=k-1; | k=k-1; | 
| 44 | end | end | 
| 46 | rList=sscanf(tline(17:end),'%i'); | rList=sscanf(tline(17:end),'%i'); | 
| 47 | k=k-1; | k=k-1; | 
| 48 | end | end | 
| 49 | if tline(2:15) == ' Nb of levels ', | if tline(2:15) == ' Nb of levels ', | 
| 50 | kList=sscanf(tline(17:end),'%i'); | kList=sscanf(tline(17:end),'%i'); | 
| 51 | k=k-1; | k=k-1; | 
| 52 | end | end | 
| 53 | if rf >=0 & tline(2:10) == ' Fields  ', | if rf >=0 & tline(2:10) == ' Fields  ', | 
| 54 | tmp=[tline(17:end),' ']; i1=0; | tmp=[tline(17:end),' ']; i1=0; | 
| 55 | for i=1:length(tmp), | for i=1:length(tmp), | 
| 56 | if isspace(tmp(i)), | if isspace(tmp(i)), | 
| 57 | if i1 > 0 & i > i1, | if i1 > 0 & i > i1, | 
| 58 | if rf == 0, listV=cellstr(tmp(i1:i-1)); | if rf == 0, listV=cellstr(tmp(i1:i-1)); | 
| 59 | else listV(rf+1)=cellstr(tmp(i1:i-1)); end | else listV(rf+1)=cellstr(tmp(i1:i-1)); end | 
| 60 | i1=i+1; rf=rf+1; | i1=i+1; rf=rf+1; | 
| 61 | else i1=i+1; | else i1=i+1; | 
| 62 | end | end | 
| 63 | end | end | 
| 64 | end | end | 
| 65 | end | end | 
| 66 | if tline(2:15) == ' end of header', | if tline(2:15) == ' end of header', | 
| 67 | flag=0; | flag=0; | 
| 68 | end | end | 
| 69 | else flag=-1; end | else flag=-1; end | 
| 88 | case 'THETASQ' ,  var2='T2'; | case 'THETASQ' ,  var2='T2'; | 
| 89 | otherwise     var2=var1; | otherwise     var2=var1; | 
| 90 | end | end | 
| 91 | listV(j)=cellstr(var2); | listV(j)=cellstr(var2); | 
| 92 | if strcmp(var1,var2), fprintf(' %s\n',var2); | if strcmp(var1,var2), fprintf(' %s\n',var2); | 
| 93 | else fprintf(' %s --> %s\n',var1,var2); end | else fprintf(' %s --> %s\n',var1,var2); end | 
| 94 | end | end | 
| 118 | %- initialize output & save Iter: | %- initialize output & save Iter: | 
| 119 | tim=zeros(nIt,2); vvA=zeros(n3d,nIt,nReg,5,nbV); | tim=zeros(nIt,2); vvA=zeros(n3d,nIt,nReg,5,nbV); | 
| 120 | msgA=' '; msgB=' '; | msgA=' '; msgB=' '; | 
| 121 | tim(:,1)=var; | tim(:,1)=var; | 
| 122 |  |  | 
| 123 | dIt=ones(1,nIt); | dIt=ones(1,nIt); | 
| 124 | if nIt > 1, dIt(2:nIt)=tim(2:nIt,1)-tim(1:nIt-1,1); dIt(1)=dIt(2); end | if nIt > 1, dIt(2:nIt)=tim(2:nIt,1)-tim(1:nIt-1,1); dIt(1)=dIt(2); end | 
| 125 | % fprintf(' (dIt: %i %i)',min(dIt(1:nIt)),max(dIt(1:nIt))); | % fprintf(' (dIt: %i %i)',min(dIt(1:nIt)),max(dIt(1:nIt))); | 
| 127 | %            (frq<0 : no volume correction if snap-shot) | %            (frq<0 : no volume correction if snap-shot) | 
| 128 | if frq > 0, dIt=1./max(1,dIt); else dIt=ones(1,nIt); end | if frq > 0, dIt=1./max(1,dIt); else dIt=ones(1,nIt); end | 
| 129 |  |  | 
| 130 | %- build time: | %- build time: | 
| 131 | delT=0; | delT=0; | 
| 132 | if nIt > 1, delT=(tim(nIt,1)-tim(1,1))/(nIt-1); delT=max(0,delT); end | if nIt > 1, delT=(tim(nIt,1)-tim(1,1))/(nIt-1); delT=max(0,delT); end | 
| 133 | if delT > 0, | if delT > 0, | 
| 158 | ' reading field: ',namV]); | ' reading field: ',namV]); | 
| 159 | end | end | 
| 160 | if nk > 0, vvA(1:nk,:,:,:,nv)=vv1; end | if nk > 0, vvA(1:nk,:,:,:,nv)=vv1; end | 
| 161 |  | if nv == 1, listK=nk; else listK=[listK nk]; end | 
| 162 | end | end | 
| 163 | fprintf(' <= end \n'); | fprintf(' <= end \n'); | 
| 164 | if length(msgA) ~= 1, fprintf(['  not found:',msgA,'\n']) ; end | if length(msgA) ~= 1, fprintf(['  not found:',msgA,'\n']) ; end | 
| 165 | if length(msgB) ~= 1, fprintf(['  dim Pb:',msgB,'\n']) ; end | if length(msgB) ~= 1, fprintf(['  dim Pb:',msgB,'\n']) ; end | 
| 166 | if n3d == 0, n3d=1; vvA=zeros(n3d,nIt,nReg,5,nbV); end | if n3d == 0, n3d=1; vvA=zeros(n3d,nIt,nReg,5,nbV); else | 
| 167 |  | s3d=max(listK); if n3d > s3d, vvA=vvA(1:s3d,:,:,:,:); end | 
| 168 |  | end | 
| 169 |  |  | 
| 170 | return | return | 
| 171 |  |  | 
| 182 | vv1=reshape(vv1,[nk nReg nit 5]); | vv1=reshape(vv1,[nk nReg nit 5]); | 
| 183 | vvm=permute(vv1,[1 3 2 4]); | vvm=permute(vv1,[1 3 2 4]); | 
| 184 | else | else | 
| 185 | %fprintf(['\n ERROR in Dim, var=',nmV,' :']); fprintf(' %i',size(var)); | %fprintf(['\n ERROR in Dim, var=',nmV,' :']); fprintf(' %i',size(var)); | 
| 186 | %fprintf(' ; nk,nReg,nit= %i %i %i\n',nk,nReg,nit); | %fprintf(' ; nk,nReg,nit= %i %i %i\n',nk,nReg,nit); | 
| 187 | msg=sprintf([' in ',nmV,' : %i <> %ix%ix%i'],size(var,1),nk,nReg,nit); nk=0; | msg=sprintf([' in ',nmV,' : %i <> %ix%ix%i'],size(var,1),nk,nReg,nit); nk=0; | 
| 188 | vvm=zeros(1,nit,nReg,5); | vvm=zeros(1,nit,nReg,5); |