%121217: v3.0 one more output from 'swath_main_stn.f90': 'elv'

function [wusa] = read_MODIS_swath_v40(modis,filepath,filename)
   disp(filename)
   fullname = [filepath,filename];
   numOth = 3; %lat, lon, elv  %v3.0 has elv as one more output.
   numParm = 5; %Flxall(5,3)
   numIntv = 3; %Flxall(5,3)
   MISSVAL = -9999.;

 if strcmp(modis,'terra')
         day = str2num(filename(17:19));
         hor = str2num(filename(21:22));
         mnt = str2num(filename(23:24));
      elseif strcmp(modis,'aqua')
         day = str2num(filename(16:18));
         hor = str2num(filename(20:21));
         mnt = str2num(filename(22:23));
  end

 
     

      %! * Flxall(Ip,Iv) : Ip=1 to Nfpar, Iv=1 to Nintv, all-sky flux;
      %!      Ip=1, top of atmosphere down-flux
      %!      Ip=2, top of atmosphere up-flux
      %!      Ip=3, surface down-flux
      %!      Ip=4, surface up-flux
      %!      Ip=5, diffuse surface down-flux
      %
      %!      Iv=1, shortwave
      %!      Iv=2, visible (PAR)
      %!      Iv=3, near infrared
      %!   Flxclr(Ip,Iv) : as Flxall but clear-sky flux
      %
      
      fid = fopen(fullname, 'r');
         NX = fread(fid,1,'int32');
         NY = fread(fid,1,'int32');
         %dM = fread(fid,(2+numParm*numIntv*2)*NX*NY,'float32');
         dM = fread(fid,(numOth+numParm*numIntv*2)*NX*NY,'float32'); %new data has "elv" at pos 3
      fclose(fid);
      dM(dM<-900)=NaN;

      dM = reshape(dM, [(numOth+numParm*numIntv*2),NX,NY]);
      latM = squeeze(dM(1,:,:));
      lonM = squeeze(dM(2,:,:));
      %elvM = squeeze(dM(3,:,:)); %new output for v3.0 
      dM = dM(numOth+1:end,:,:);
      dM = reshape(dM, [numParm,numIntv,2,NX,NY]);

      fdnM = squeeze(dM(3,1,1,:,:));
      fupM = squeeze(dM(4,1,1,:,:));
      flxc = squeeze(dM(3,1,2,:,:));%ssdc
      %flxM = fupM./fdnM; disp('--- flxM=fupM./fdnM')     
     
     
      



   wusa.day  = day;
   wusa.hor  = hor;
   wusa.mnt  = mnt;
 
   wusa.varM = fdnM;
   wusa.varC = flxc; 
   wusa.latM = latM;
   wusa.lonM = lonM;

end  %-------------------------------------------------------------------------------







