Difference between revisions of "COPSbscalcloop"

From Pnb
Jump to navigation Jump to search
(Created page with "<pre> function COPSbscalcloop(infile) %loop for calling bscalc %Erik Stassinos %modified for C-OPScast 6-20-2013 scale = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1...")
 
 
Line 201: Line 201:
  
 
</pre>
 
</pre>
 +
 +
 +
back to [[C-OPS/CERBERUS Mfiles]]

Latest revision as of 14:07, 13 February 2014


function COPSbscalcloop(infile)
%loop for calling bscalc
%Erik Stassinos


%modified for C-OPScast 6-20-2013



scale = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]; %will be changed to be read from a file.
%interval = [10,10,10,12,12,12,12,12,12,12,12,12,10,10,10,10,10,10,10,10,10,12,12,12,12,12,12,12,12,12,10,10,10,10,10,10];
interval = [5,5,5,5,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,2,2,2,2,2,2];

%%%% old
% -r EdZ320 1 10
% -r EdZ340 1 10
% -r EdZ380 1 10
% -r EdZ395 1 12
% -r EdZ412 1 12
% -r Edz443 1 12
% -r Edz465 1 12
% -r EdZ490 1 12
% -r EdZ510 1 12
% -r EdZ532 1 12
% -r EdZ555 1 12
% -r EdZ560 1 12
% -r EdZ625 1 10
% -r Edz665 1 10
% -r EdZ670 1 10
% -r EdZ683 1 10
% -r EdZ710 1 10
% -r EdZ780 1 10

% -r LuZ320 1 10
% -r LuZ340 1 10
% -r LuZ380 1 10
% -r LuZ395 1 12
% -r LuZ412 1 12
% -r Luz443 1 12
% -r Luz465 1 12
% -r LuZ490 1 12
% -r LuZ510 1 12
% -r LuZ532 1 12
% -r LuZ555 1 12
% -r LuZ560 1 12
% -r LuZ625 1 10
% -r 1lu665 1 10
% -r LuZ670 1 10
% -r LuZ683 1 10
% -r LuZ710 1 10
% -r LuZ780 1 10
%infile = 'akrmP101216B.lcd.1';

%rqfid = fopen('/home/data65/pb/REPROCESS_2010/PRR/rqclist.txt')
rqfid = fopen('/home/oceancolor/Plumes_and_Blooms/workspace/eriks/C-OPS/Copsrqclist.txt');

chin = 1;
while ~feof(rqfid)
    chline = fgets(rqfid);
    channels3(chin,:) = {chline(1:6)};
    %channels3 = channels3'
    chin = chin + 1;
    if chin >= 37
        break
    end
end
channels3 = channels3';

s = struct('channel',channels3,'scale',scale,'interval',interval);
valac = [];
for L = 1:size(scale,2)
    
%vars =%bscalcE(s(L).channel,s(L).scale(L),s(L).interval(L),'bananKrqcmmP101216B.l%cd.1')
vars = bscalcE_angQ(s(L).channel,s(L).scale(L),s(L).interval(L),infile);

valac = [valac;{vars}];


if ~ischar(valac) % added by ES 9-18-2012
%%char(valac)  %why is this here??
end
end

%===generate new file=====

newfile = strcat('bs',infile);
nf = fopen(newfile,'w+');
infp = fopen(infile,'r+');
pull =[];

%write file and put in (0-) values "a"
%-----------------------
%Find index of Ed and Lu chans to generate 0- line
ct = 0;%channel index counter
p =1; %pulling index
infi = fopen(infile);
%for L2 = 1:size(scale,2)
  while ~feof(infi)
      s(p).channel;
      ckl = fgets(infi);
      %if strncmp(ckl,'1mer_time',9) ==1; %changed 12-3-12 1mer_time
      if strncmp(ckl,'FrameCount',10) ==1; %changed 12-3-12 1mer_time
         ct =1;
         %keyboard
      end
          if strncmp(ckl,s(p).channel,6) ==1
              %ct = ct+1
              pull(p) = ct;
              p = p +1;
              
          end
          if length(pull) >= size(scale,2) %should only be Ed and Lu
              break
          end
       if ct >=1
          ct = ct+1;
      end
  end
%=========++++++get # of columns
frewind(infi);
ctr =0;
flag = 0;
%while ~feof(infi)
 for i = 1:1000

   tt = fgets(infi);
    %if strncmp(tt,'1mer_time',9) ==1; %changed 12-3-12 0prr_record from 1mer_time
    if strncmp(tt,'FrameCount',10) ==1; %changed 12-3-12 0prr_record from 1mer_time
        % ctr = ctr+1;
        flag =1;
    end
        %while strncmp(tt,'<data>',6) ~=1
         %   tt = fgets(infi);
         if flag == 1
            ctr = ctr+1;

         end
            if strncmp(tt,'<derived_parameters>',20) ==1
                ctr = ctr -1;

            end
        if strncmp(tt,'<data>',6) ==1
            ctr = ctr - 1;
            break
        end
            
        %end
    %end
end

zeromin_line = ones(1,ctr)*-9.9E35;
%zeromin_line = ones(1,ctr-2)*-9.9E35; %for prr_bincheat
fclose(infi);
clear i;
for i = 1:length(pull)
    oneval = char(valac(i));
    [a,b,c] = strread(oneval,'%s%s%s','delimiter',' ');
    val = char(c(2));
    zerominus = str2num(val);

    zeromin_line(pull(i)) = zerominus;
end


%-------------------------  
  
while ~feof(infp)
    linep = fgets(infp);
    fprintf(nf,linep);
    
    if strncmp(linep,'<data>',6) == 1
        %fprintf(nf,linep)

        %fprintf(nf,'%s',zeromin_line)
        
        dlmwrite(newfile,zeromin_line,'-append','delimiter',' ','precision','%.5d');
        fseek(nf,0,'eof');
       % dlmwrite(newfile,' ','-append')

        %fprintf(nf,'%s\n','')
        
    end
    
    
end
%===end generate new file====
%===add stats line==

for L = 1:size(scale,2)
fprintf(nf,'%s\n',['bscalc ', s(L).channel,' ', num2str(s(L).scale(L)),' ', num2str(s(L).interval(L)),' ', infile]);

if ~ischar(valac) %added by ES 9-18-2012
    ln = valac(L);
fprintf(nf,'%s\n',char(ln));
end
%fprintf(nf,'%s/n')
end



back to C-OPS/CERBERUS Mfiles