0001 function par=readScript(fn)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 par=[];
0012
0013 if (strcmp(fn(end-2:end),'.red'))
0014 disp('Improper file type. Must have ext .red')
0015 return
0016 end
0017
0018 fid=fopen(fn,'r');
0019 if (fid==-1)
0020 error('Script not found!')
0021 end
0022
0023
0024 while(1)
0025 lin=fgets(fid);
0026 if (lin==-1)
0027
0028 break;
0029 else
0030 str=sscanf(lin,'%s');
0031 if (~checkstr(str))
0032 [par,q]=interpret(par,lin);
0033 if(~q)
0034 fclose(fid);
0035 return
0036 end
0037 end
0038 end
0039 end
0040
0041
0042 names=fieldnames(par);
0043 caltype=parlist('caltype');
0044 if (length(names)==length(caltype))
0045 disp('Script read successfully!');
0046 disp(' ')
0047 fclose(fid);
0048 return
0049 else
0050 disp('Parameter settings for some calibration step is missing')
0051 disp('Setting to default values in readScript.m');
0052 disp(['Length names',int2str(length(names)),' Length caltype',int2str(length(caltype))]);
0053
0054 par=setdefault(par);
0055 disp(' ')
0056 end
0057
0058
0059
0060
0061 fclose(fid);
0062
0063
0064 if(par.interactive.flag==1)
0065 if(par.plotflag.flag==0)
0066 display('Warning: to use interactive mode you must plot data');
0067 display('Setting your plotflag parameter to true');
0068 par.plotflag.flag = 1;
0069 end
0070 end
0071
0072 return;
0073
0074
0075
0076 function par=setdefault(par);
0077
0078 names=fieldnames(par);
0079 caltype=parlist('caltype');
0080
0081 disp(' ')
0082 for i=1:length(caltype)
0083 f=find(strcmp(names,caltype{i}));
0084 if (isempty(f))
0085 disp(sprintf('"%s" parameter not found! Will use default', ...
0086 caltype{i}));
0087 list=parlist(caltype{i});
0088 def=getdefault(caltype{i});
0089 if (isstrval(list))
0090 eval(sprintf('par.%s.%s=def;',caltype{i},list{1}));
0091 else
0092 if (length(def)~=length(list))
0093 disp('Default values does not match parameter list.')
0094 disp('Parameter setting for this calibraiton step')
0095 disp('will be ignored.')
0096 else
0097 for m=1:length(list)
0098 eval(sprintf('par.%s.%s=%f;',caltype{i},list{m},def(m)));
0099 end
0100 end
0101 end
0102 end
0103 end
0104
0105
0106
0107
0108 function [par,q]=interpret(par,lin)
0109
0110
0111
0112 caltype=parlist('caltype');
0113 f=regexpi(lin,':');
0114
0115 type=caltype{find(strcmp(lin(1:f-1),caltype))};
0116 if (isempty(type))
0117 disp('Unknown calibration type detected in script file')
0118 disp('Script will be ignored')
0119 q=0;
0120 par=[];
0121 return
0122 end
0123
0124
0125 list=parlist(type);
0126
0127
0128
0129 q=isstrval(list);
0130 if (isstrval(list)==1)
0131 [par,q]=getstrval(par,list,type,lin(f+1:end));
0132 elseif(isstrval(list)>=2)
0133 [par,q]= getSingleStrVal(par, list, type, lin(f+1:end),q);
0134 else
0135 [par,q]=getnumval(par,list,type,lin(f+1:end));
0136 end
0137
0138
0139
0140 function [par,q]=getstrval(par,list,type,str)
0141
0142
0143 str=findspaces(str);
0144
0145
0146 key=sort(getkey(list));
0147 isGood = zeros(size(str));
0148 for m=1:length(str)
0149 if(any(strcmp(str(m), key)))
0150 isGood(m) = 1;
0151 else
0152 isGood(m) = 0;
0153 end
0154 end
0155
0156
0157 if(~any(strcmp('alpha', str)))
0158 display('WARN, no alpha step detected in redScript');
0159 display('This is okay if you have loaded previous data via load_d');
0160 display('ohterwise you should run some alpha correction');
0161 display('to put the data in the correct format, otherwise doomed to fail.');
0162
0163 end
0164
0165
0166 if (all(isGood))
0167 eval(sprintf('par.%s.%s=str;',type,list{1}));
0168 q=1;
0169 else
0170 disp('Parameter list values does not match those')
0171 disp('given in the script file')
0172 disp('routines listed are incorrect or mispelled');
0173 disp('SCRIPT WILL BE IGNORED');
0174 q=0; par=[];
0175 end
0176
0177
0178
0179 function [par,q]=getSingleStrVal(par,list,type,str,q)
0180
0181
0182 str=findspaces(str);
0183
0184
0185
0186 if(q==3)
0187 tempw=sprintf('%s\t',str{1:end});
0188 eval(sprintf('par.%s.%s=%s;',type,list{1},['''',tempw,'''']));
0189 clear tempw
0190 q=1;
0191 else
0192 for m=1:length(list)
0193 eval(sprintf('par.%s.%s=str{m};',type,list{m}));
0194 q=1;
0195 end
0196 end
0197
0198 return;
0199
0200
0201
0202 function [par,q]=getnumval(par,list,type,val)
0203
0204 q=1;
0205
0206
0207 val=sscanf(val,'%f');
0208
0209
0210 if(strcmp(type, 'bitmask'))
0211 eval(sprintf('par.%s.%s = val'';', type, list{1}));
0212 return;
0213 end
0214
0215 if(strcmp(type, 'mains'))
0216 eval(sprintf('par.%s.%s = val'';', type, list{1}));
0217 return;
0218 end
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 if (length(val)~=length(list))
0231 disp(val)
0232 disp('Parameter list values does not match those')
0233 disp('given in the script file')
0234 disp('Script will be ignored')
0235 q=0;
0236 par=[];
0237 return
0238 end
0239
0240
0241 for i=1:length(val)
0242 eval(sprintf('par.%s.%s=%f;',type,list{i},val(i)));
0243 end
0244
0245 return;
0246
0247
0248
0249
0250 function list=parlist(type)
0251
0252 list=[];
0253
0254
0255 caltype={'routines', 'bitmask','deglitch', 'rfi', 'rfio', 'coord', 'mains', ...
0256 'alpha', 'tsys', 'noise', 'stokes', 'load', 'pointing', ...
0257 'tau', 'load_d','save_d','ground','astro','plotflag', 'saveplot', 'interactive', 'autorun', ...
0258 'autosave', 'rev', 'field', 'fits','dataselect','dataselect_name'};
0259
0260
0261 if (strcmp(type,'caltype'))
0262 list=caltype;
0263 return
0264 end
0265
0266 switch type
0267 case 'rev'
0268 list={'version'};
0269
0270 case 'routines'
0271 list={'order'};
0272
0273 case 'bitmask'
0274 list={'bitVals'};
0275
0276 case 'deglitch'
0277 list={'chan1', 'chan2'};
0278
0279 case 'rfio'
0280 list={'aggressive'};
0281
0282 case 'rfi'
0283 list={'fast', 'polarization', 'intensity'};
0284
0285 case 'coord'
0286 list={'hemisphere'};
0287
0288 case 'fits'
0289 list={'domapflag','frame','projection','hdf','source','ini','pyplot'};
0290
0291 case 'dataselect'
0292 list={'dflags'};
0293
0294 case 'dataselect_name'
0295 list={'fname'};
0296
0297 case 'mains'
0298 list={'tukey'};
0299
0300 case 'alpha'
0301 list={'type', 'solve', 'jump', 'flat'};
0302
0303 case 'stokes'
0304 list={'maxVal', 'slope', 'smooth'};
0305
0306 case 'pointing'
0307 list={'method'};
0308
0309 case 'tsys'
0310 list={'valuehi', 'valuelo'};
0311
0312 case 'noise'
0313 list={'valuehi', 'valuelo', 'primary'};
0314
0315
0316
0317
0318 case 'load'
0319 list={'scaleType'};
0320
0321 case 'tau'
0322 list={'sigma'};
0323
0324 case 'load_d'
0325 list={'filename'};
0326
0327 case 'save_d'
0328 list={'filename'};
0329
0330 case 'ground'
0331 list={'template_filename_stub'};
0332
0333 case 'astro'
0334 list={'noflag'};
0335
0336 case 'plotflag'
0337 list={'flag'};
0338
0339 case 'saveplot'
0340 list={'flag','web'};
0341
0342 case 'interactive'
0343 list={'flag'};
0344
0345 case 'autorun'
0346 list={'flag'};
0347
0348 case 'autosave'
0349 list={'flag'};
0350
0351 case 'field'
0352 list={'name'};
0353
0354 end
0355
0356
0357
0358
0359 function val=getdefault(type)
0360
0361 val=[];
0362
0363 switch type
0364 case 'routines'
0365 val = { 'pointing', 'deglitch', 'rfi', 'rfio', 'mains', 'alpha', 'load', ...
0366 'tsys', 'noise', 'tau', 'load_d', 'save_d','ground','astro', 'stokes', 'power', ...
0367 'overf', 'rms', 'summary', 'fits','dataselect','dataselect_name'};
0368
0369
0370 case 'bitmask'
0371 val = [0 1 5 6 7 8 10 12 15];
0372
0373 case 'deglitch'
0374
0375 val(1) = 5;
0376
0377 val(2) = 2;
0378
0379 case 'rfi'
0380
0381 val(1) = 4;
0382 val(2) = 3;
0383 val(3) = 5;
0384
0385 case 'rfio'
0386
0387 val(1) = 3;
0388
0389 case 'coord'
0390
0391 val = 1;
0392
0393 case 'mains'
0394
0395 val = [0];
0396
0397 case 'tsys'
0398
0399 val(1) = 100;
0400 val(2) = 10;
0401
0402 case 'pointing'
0403
0404 val(1) = 1;
0405
0406 case 'noise'
0407 val(1) = 4.0;
0408 val(2) = 1;
0409 val(3) = 8;
0410
0411
0412
0413
0414
0415
0416 case 'alpha'
0417
0418 val(1) = 1;
0419
0420 val(2) = 0;
0421
0422 val(3) = 2;
0423
0424 val(4) = 0.2;
0425
0426 case 'stokes'
0427
0428 val(1) = 2;
0429 val(2) = 30;
0430 val(3) = 10;
0431
0432 case 'load'
0433
0434 val = 0;
0435
0436 case 'tau'
0437
0438 val = 3;
0439
0440 case 'load_d'
0441
0442 val = 'default';
0443
0444 case 'save_d'
0445
0446 val = 'default';
0447
0448 case 'ground'
0449
0450 val = 'default_';
0451
0452 case 'astro'
0453
0454 val = 0;
0455
0456 case 'galactic'
0457
0458 val = 1;
0459
0460 case 'plotflag'
0461
0462 val=1;
0463
0464 case 'saveplot'
0465
0466 val(1)=0;
0467 val(2)=0;
0468
0469 case 'interactive'
0470
0471 val=0;
0472
0473 case 'field'
0474
0475 val = 'other';
0476
0477 case 'autorun'
0478
0479 val=0;
0480
0481 case 'autosave'
0482
0483 val=0;
0484
0485 case 'rev'
0486
0487 val=NaN;
0488
0489 case 'dataselect'
0490
0491 val='-zkg';
0492
0493 case 'dataselect_name'
0494 val='BASIC';
0495 end
0496
0497
0498
0499
0500 function q=isstrval(list)
0501
0502 if (~strmatch(list{1}, 'order', 'exact') | ~strmatch(list{1}, 'name', ...
0503 'exact') | ~strmatch(list{1}, 'domapflag', 'exact') | ~strmatch(list{1}, 'dflags', ...
0504 'exact') | ~strmatch(list{1}, 'template_filename_stub', 'exact') | ~strmatch(list{1}, 'filename', 'exact') | ~strmatch(list{1}, 'fname','exact') )
0505 q=0;
0506 return
0507 end
0508
0509 switch list{1}
0510 case 'order'
0511 q = 1;
0512
0513 case 'name'
0514 q = 2;
0515
0516 case 'domapflag'
0517 q=2;
0518
0519 case 'dflags'
0520 q=3;
0521
0522 case 'fname'
0523 q=2;
0524
0525 case 'template_filename_stub'
0526 q=2;
0527
0528 case 'filename'
0529 q=2;
0530
0531 otherwise
0532 q=0;
0533 end
0534
0535
0536
0537 function q=checkstr(str)
0538
0539 if (isempty(str))
0540 q=1;
0541 else
0542 if (str(1)=='#')
0543 q=1;
0544 else
0545 q=0;
0546 end
0547 end
0548
0549
0550
0551
0552
0553 function key=getkey(list)
0554
0555 switch list{1}
0556 case 'order'
0557 key= {'pointing', 'deglitch', 'rfi', 'rfio', 'mains', 'alpha', 'load', 'tsys', ...
0558 'noise', 'tau','load_d','save_d','ground','astro','stokes', 'power', 'overf', ...
0559 'rms', 'summary', 'fits','dataselect','dataselect_name'};
0560
0561 end
0562
0563
0564
0565
0566
0567
0568
0569
0570
0571
0572
0573