0001 function fnames = writeAlphaDatabase(x,MODE)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 fnames = getAlphaDatabaseName(x{1});
0017
0018
0019
0020
0021
0022
0023 precision = [ 11;
0024 4;
0025 4;
0026 4;
0027 4;
0028 4;
0029 4;
0030 4;
0031 4;
0032 4;
0033 4;
0034 2;
0035 3;
0036 3;
0037 3;
0038 0;
0039 0];
0040
0041 wdth = [ 1;
0042 5;
0043 5;
0044 5;
0045 5;
0046 2;
0047 2;
0048 5;
0049 3;
0050 5;
0051 3;
0052 2;
0053 2;
0054 4;
0055 7;
0056 1;
0057 1];
0058 format_string = '';
0059 for k=1:length(precision)
0060 if precision(k) > 0
0061 newS = sprintf('%%%d.%dE ',precision(k)+1,precision(k));
0062 else
0063 newS = '%d ';
0064 end
0065
0066 for m=1:size(x{k},2)
0067 format_string = [format_string newS];
0068 end
0069 end
0070 format_string = [format_string '\n'];
0071
0072 for k=1:size(fnames,1)
0073
0074
0075
0076
0077 if strcmp(MODE,'APPEND')
0078 tfile = fopen(fnames{k},'a+');
0079 elseif strcmp(MODE,'REPLACE')
0080 tfile = fopen(fnames{k},'w+');
0081 else
0082 error('writeAlphaDatabase:WrongFlag',...
0083 'Invalid FLAG specification: Only APPEND and REPLACE accepted.')
0084 end
0085
0086
0087 year = str2double(fnames{k}(end-10:end-7));
0088 month = str2double(fnames{k}(end-5:end-4));
0089 mjdstart = date2mjd(year,month,1,0,0,0);
0090 if month < 12
0091 mjdstop = date2mjd(year,month+1,1,0,0,0);
0092 else
0093 mjdstop = date2mjd(year+1,1,1,0,0,0);
0094 end
0095 I = (x{1} >= mjdstart) & (x{1} < mjdstop);
0096 data_matrix = [];
0097 for k=1:length(x)
0098 if size(x{k},2) ~= wdth(k)
0099 disp(sprintf('writeAlphaDatabase:: Warning: element %d of x has width %d, expected %d',...
0100 k,size(x{k},2),wdth(k)))
0101 end
0102 data_matrix = cat(2,data_matrix,x{k}(I,1:wdth(k)));
0103 end
0104
0105 fprintf(tfile,format_string,data_matrix');
0106 fclose(tfile);
0107 end
0108
0109 end