Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ data, long, lat ] = import_asc( filename )
- %
- %Objective: Import .asc file and return matrixes of data and lat/long coordinates
- %
- %Example:
- % [data, long,lat]=import_asc('file.asc');
- % pcolor(long,lat,data); shading flat;
- %
- %Author: Ricardo Dal'Agnol da Silva (ricds@hotmail.com)
- %
- fid = fopen(filename,'r');
- for i=1:6
- tmp=fgetl(fid);
- tmp=sscanf(tmp,'%s%f',[1 Inf]);
- tmp_s=size(tmp,2);
- header{i}=tmp(tmp_s);
- end
- [data,header{7}]=fscanf(fid,'%f');
- fclose (fid);
- n_col=header{1};
- n_lin=header{2};
- x_min=header{3};
- y_min=header{4};
- res=header{5};
- null=header{6};
- x_max=x_min+(n_col*res)-res;
- y_max=y_min+(n_lin*res)-res;
- [long,lat]=meshgrid(x_min:res:x_max,y_min:res:y_max);
- data=flipud(reshape(data,header{1},header{2})');
- data(data==null)=NaN;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement