Advertisement
Guest User

Untitled

a guest
May 24th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function [ data, long, lat ] = import_asc( filename )
  2. %
  3. %Objective: Import .asc file and return matrixes of data and lat/long coordinates
  4. %
  5. %Example:
  6. % [data, long,lat]=import_asc('file.asc');
  7. % pcolor(long,lat,data); shading flat;
  8. %
  9. %Author: Ricardo Dal'Agnol da Silva (ricds@hotmail.com)
  10. %
  11. fid = fopen(filename,'r');
  12. for i=1:6
  13. tmp=fgetl(fid);
  14. tmp=sscanf(tmp,'%s%f',[1 Inf]);
  15. tmp_s=size(tmp,2);
  16. header{i}=tmp(tmp_s);
  17. end
  18. [data,header{7}]=fscanf(fid,'%f');
  19. fclose (fid);
  20. n_col=header{1};
  21. n_lin=header{2};
  22. x_min=header{3};
  23. y_min=header{4};
  24. res=header{5};
  25. null=header{6};
  26. x_max=x_min+(n_col*res)-res;
  27. y_max=y_min+(n_lin*res)-res;
  28. [long,lat]=meshgrid(x_min:res:x_max,y_min:res:y_max);
  29. data=flipud(reshape(data,header{1},header{2})');
  30. data(data==null)=NaN;
  31.  
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement