1 |
% |
---|
2 |
% WRITE_OBS write standard observation files. |
---|
3 |
% the standards are m2d,o2d,m3d,o3d |
---|
4 |
% |
---|
5 |
% Call as: a = write_obs(fname,fmt,data,gridname,year,ncol,gmt); |
---|
6 |
% |
---|
7 |
% Input: |
---|
8 |
% fname - path/name of the file |
---|
9 |
% fmt - format string for writing the output |
---|
10 |
% e.g. fmt = ' %f %f %g %g\n' ; |
---|
11 |
% it should have ncol entries |
---|
12 |
% data - array of column data |
---|
13 |
% year - the year of the data; |
---|
14 |
% ncol - number of columns used; |
---|
15 |
% gmt - the gmt string from the data file (not yet) |
---|
16 |
% |
---|
17 |
% Written by: Charles G. Hannah Sept 1997. |
---|
18 |
% |
---|
19 |
function a = write_obs(fname,fmt,data,gridname,year,ncol,gmt); |
---|
20 |
|
---|
21 |
|
---|
22 |
% open fname |
---|
23 |
fpath=[]; |
---|
24 |
[pfid,message]=fopen([fpath fname],'w'); |
---|
25 |
if pfid==-1 |
---|
26 |
error([fpath fname,' not allowed to open and write. ',message]); |
---|
27 |
end |
---|
28 |
|
---|
29 |
fprintf(pfid,'XXXX\n'); |
---|
30 |
gridname=blank(gridname); |
---|
31 |
fprintf(pfid,'%s',gridname); |
---|
32 |
fprintf(pfid,'\nheader line\n'); |
---|
33 |
|
---|
34 |
fprintf(pfid,'%d\n',year); |
---|
35 |
fprintf(pfid,'%d\n',ncol); |
---|
36 |
% |
---|
37 |
aa = size(data); |
---|
38 |
if(ncol~=aa(2)) |
---|
39 |
disp('ncol sent does not agree with size of data array'); |
---|
40 |
end |
---|
41 |
% |
---|
42 |
%% write data to file |
---|
43 |
% fmt |
---|
44 |
fprintf(pfid,fmt,data'); |
---|
45 |
fclose(pfid); |
---|
46 |
return |
---|
47 |
|
---|