31
20160710T233234 1 2 ==Aamainbankmaker== 3 4 function Aamainbankmaker 5 % AAMAINBANKMAKER creates bank files in bnkmat with option to upgrade 6 inventory 7 clear all; clc; close all; 8 addpath([pwd,'\functions'],'-frozen'); 9 %% Input variables: 10 an_inventory=1; %set to 1 if the bank needs to be updated, else to 0: 11 checkroot = Agetvar('checkroot'); 12 fprintf('Aamainbankmaker:checkroot=%s\n',checkroot); 13 courselist = Agetvar('courselist'); 14 fprintf('Aamainbankmaker:checkroot=%s\n','courselist{:} too long to 15 print'); 16 %The top row of courselist is {'q_iz','l_nk','f_st','N_q','S_G'}, 17 followed 18 %(quizname, attributionlink, first question, number in quiz and number in 19 %study guide), respectively. Unless n_{N_q} is large, n_{S_G}=n_{N_q} 20 %After that, in the first row we have the courses, for example: 21 %{{'moc','phc','pht','ast','hwt','all'} 22 %After running Aabankmaker.m, go into the bnkmat folder and place a copy 23 of 24 %coursmaker.xls into the courses foler (with the _unifinished part 25 %removed). Then decide which course(s) are appriate for all the quizzes. 26 % moc,uph,cph,ast,hwt refer to mock test, university (calc) physics, 27 %... college (trig) physics, astronomy, and how things work, repectively. 28 Warnme('noturgent', ['root=',checkroot,' 29 inventory=',num2str(an_inventory)]); 30 if an_inventory%This is the procedure for updating bnkmat files from 31 Warnme('*', 'Be careful: This will rewrite the bnkmat files'); 32 Inventory%from the text files in the bank directory. 33 end; 34 % Load banksfrom bnkmat folder and create coursemaker_unfinished.xls: 35 [bnkquizname, bnkquesname,bnkclean]=Loadbanks;%Retrieves banks 36 % bnkquizname = bank of quiznames and Nques 37 % col 1 is quizname; sends inventory into each folder 38 % col 2 is Nques; (number questions in each quiz) 39 % col 3 is attribution html 40 % col 4 is studyguide 41 % bnkquesname = bank of question names (only). 42 % bnkclean = bank of textfiles (only) that have been "cleaned" 43 delete('coursemaker_unfinished.xls'); 44 strtemp ='coursemaker_unfinished.xls has been placed into bnkmat.'; 45 strtemp =[strtemp,' Place a copy of it in the courses folder']; 46 Warnme('noturgent',strtemp); 47 %Call Createcoursemaker which creates courslist_unfinished.xls 48 coursemaker = Createcoursemaker(bnkquizname,bnkclean,courselist); 49 xlswrite('coursemaker_unfinished',coursemaker); 50 end 51 52 %% Subfunctions 53 %function []= Inventory 54

function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

20160710T233234 1 2 ==Aamainbankmaker== 3 4 function Aamainbankmaker 5 % AAMAINBANKMAKER creates bank files in bnkmat with option to upgrade 6 inventory 7 clear all; clc; close all; 8 addpath([pwd,'\functions'],'-frozen'); 9 %% Input variables: 10 an_inventory=1; %set to 1 if the bank needs to be updated, else to 0: 11 checkroot = Agetvar('checkroot'); 12 fprintf('Aamainbankmaker:checkroot=%s\n',checkroot); 13 courselist = Agetvar('courselist'); 14 fprintf('Aamainbankmaker:checkroot=%s\n','courselist{:} too long to 15 print'); 16 %The top row of courselist is {'q_iz','l_nk','f_st','N_q','S_G'}, 17 followed 18 %(quizname, attributionlink, first question, number in quiz and number in 19 %study guide), respectively. Unless n_{N_q} is large, n_{S_G}=n_{N_q} 20 %After that, in the first row we have the courses, for example: 21 %{{'moc','phc','pht','ast','hwt','all'} 22 %After running Aabankmaker.m, go into the bnkmat folder and place a copy 23 of 24 %coursmaker.xls into the courses foler (with the _unifinished part 25 %removed). Then decide which course(s) are appriate for all the quizzes. 26 % moc,uph,cph,ast,hwt refer to mock test, university (calc) physics, 27 %... college (trig) physics, astronomy, and how things work, repectively. 28 Warnme('noturgent', ['root=',checkroot,' 29 inventory=',num2str(an_inventory)]); 30 if an_inventory%This is the procedure for updating bnkmat files from 31 Warnme('*', 'Be careful: This will rewrite the bnkmat files'); 32 Inventory%from the text files in the bank directory. 33 end; 34 % Load banksfrom bnkmat folder and create coursemaker_unfinished.xls: 35 [bnkquizname, bnkquesname,bnkclean]=Loadbanks;%Retrieves banks 36 % bnkquizname = bank of quiznames and Nques 37 % col 1 is quizname; sends inventory into each folder 38 % col 2 is Nques; (number questions in each quiz) 39 % col 3 is attribution html 40 % col 4 is studyguide 41 % bnkquesname = bank of question names (only). 42 % bnkclean = bank of textfiles (only) that have been "cleaned" 43 delete('coursemaker_unfinished.xls'); 44 strtemp ='coursemaker_unfinished.xls has been placed into bnkmat.'; 45 strtemp =[strtemp,' Place a copy of it in the courses folder']; 46 Warnme('noturgent',strtemp); 47 %Call Createcoursemaker which creates courslist_unfinished.xls 48 coursemaker = Createcoursemaker(bnkquizname,bnkclean,courselist); 49 xlswrite('coursemaker_unfinished',coursemaker); 50 end 51 52 %% Subfunctions 53 %function []= Inventory 54

Page 2: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

function []= Inventory 55 % INVENTORY reads the textfiles in bank and creates datafiles. 56 % Detailed explanation goes here 57 % bnkquizname = bank of quiznames and Nques 58 % col 1 sends inventory into each folder 59 % col 2 defines Nques for loops inside each quiz 60 % col 3 is attribution html 61 % col 4 is studyguide 62 % bnkquesname = bank of question names (only). 63 % bnkclean = bank of textfiles that have been "cleaned" 64 %calls Bnkfoldersizes, Readwikitext 65 %% Go into bank and create list of quizzes from bank's directory 66 cd(fullfile(Zroot,'bank')); % creates bnkquizname 67 quiznamelist = dir();% structure lists quiz directories 68 N=size(quiznamelist,1); 69 nquiz=0; 70 for n = 1:N 71 testfolder = quiznamelist(n).name; 72 %exclude non-quizfiles in bank directory 73 if ~strcmp('..',testfolder)... 74 && ~strcmp('.',testfolder)... 75 && ~strcmp('zzz',testfolder(1:3)); 76 nquiz=nquiz+1; 77 bnkquizname{nquiz,1}=testfolder; %list of quiznames 78 end 79 end 80 Nquiz=nquiz 81 % create bnkquizname, bnkquesname, and bnkclean all are (nquiz,nques) 82 for nquiz=1:Nquiz% this loop goes into each quiz in the bank of test 83 files 84 cd(fullfile(Zroot,'bank',bnkquizname{nquiz,1})); %Go into folder for each 85 quiz 86 quiznamelist= dir('*.txt');%directory of question paths for each quiz 87 Nques=size(quiznamelist,1); %Gets the number of questions in nquiz 88 cd('info_'); 89 bnkquizname{nquiz,2}=Nques;%Place Nques (# questions) into the 2nd 90 column. 91 tstring = fullfile(Zroot,'bank',bnkquizname{nquiz,1},'info_'); 92 if ~isdir('info_') 93 fprintf('Warning %s does not exist \n',tsting); 94 end 95 if exist(fullfile(tstring,'attribution_.txt'))==2 96 bnkquizname{nquiz,3}=Textfile2cellarray('attribution_.txt'); 97 end 98 if exist(fullfile(tstring,'study_.txt'))==2 99 bnkquizname{nquiz,4}=Textfile2cellarray('study_.txt'); 100 end 101 if exist(fullfile(tstring,'gallery_.txt'))==2 102 bnkgallery{nquiz}=Textfile2cellarray('gallery_.txt'); 103 end 104 for nques = 1:Nques %for each question in a given quiz 105 question = quiznamelist(nques).name; 106 %...extracts the filenames for each question in the quiz folder 107 %Next we remove 4 characters (.txt) from the question name: 108

Page 3: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

lengthpath2quiz=size(question,2); 109 %Next write the reduced question names into bnkquesname: 110 bnkquesname{nquiz,nques}=question(1:lengthpath2quiz-4); 111 %list of questions for each quiz, first in raw form: 112 tbnkrawtxt=Textfile2cellarray(fullfile(Zroot,'bank',bnkquizname{nquiz},qu113 estion)); 114 temp=Readwikitext(tbnkrawtxt); 115 new=numericalproblemsplit(temp); 116 bnkclean{nquiz,nques} = new; 117 end %...for each question in a given quiz 118 end%for nquiz=1:Nquiz (...goes into each quiz in the bank of test files) 119 cd(fullfile(Zroot,'bnkmat')); 120 save('bnkquizname','bnkquizname'); 121 save('bnkquesname','bnkquesname'); 122 save('bnkclean','bnkclean'); 123 save('bnkgallery','bnkgallery'); 124 clear('bnkgallery'); 125 %Place size of all subdirectories in 'bank' into the excel file 126 % 'Matlabbnkfoldersizes' in directory'bnkmat':; 127 Bnkfoldersizes; 128 cd(Zroot); 129 end %function Inventory 130 131 %% Subfunction Createcoursemaker 132 function [coursemaker]=Createcoursemaker(bnkquizname,bnkclean,courselist) 133 %CREATECOURSEMAKER deletes and rewrites coursemaker.xls 134 %bnkquizname cols: name, Nquiz, Attribution, Study 135 %bnkclean contains cleaned copies of each question (some with multiple 136 renditions) 137 %coursemaker cols: quiz, link, first, N, s, ...(courses) 138 Nquiz=size(bnkquizname,1); 139 coursemaker =courselist; 140 for nquiz=1:Nquiz 141 coursemaker{nquiz+1,1}=bnkquizname{nquiz,1};%1 (quiz)name 142 linkc = bnkquizname(nquiz,3); 143 linkst=strcat('',char(linkc{1})); 144 coursemaker{nquiz+1,2}=linkst;%2 link 145 firstcellarray=bnkclean{nquiz,1}; %...prepare for first 146 coursemaker{nquiz+1,3}=firstcellarray{1};%3 first 147 coursemaker{nquiz+1,4}=bnkquizname{nquiz,2};%N=Nquiz 148 coursemaker{nquiz+1,5}=bnkquizname{nquiz,2};%s=Study 149 end 150 end 151 152 %% Subfunction numericalproblemsplit 153 function newcell=numericalproblemsplit(temp) 154 nvers=0; %counts versions of problem 155 for nraw=1:length(temp) 156 tline=temp{nraw}; 157 if strcmp(tline(1),'{'); 158 nvers=nvers+1; 159 nprob=1; 160 newcell{nvers,nprob}=tline; 161 nprob=nprob+1; 162

Page 4: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

else 163 newcell{nvers,nprob}=tline; 164 nprob=nprob+1; 165 end %if 166 end%nraw=1:length(temp) 167 end%function newcell=numericalproblemsplit(temp) 168 169 ==Abmaincoursemaker== 170 171 function Abmaincoursemaker 172 %ABMAINCOURSEMAKER Decides what goes into one or more coreses 173 %This code opens coursemaker.xls in the courses folder, and after that 174 excel file 175 % ... has been upgraded, creates (coursename)_unfinished.xls 176 %%NOTE: The folder (coursename) has to already exist in the courses 177 folder. 178 % Upgrades are as follows: 179 % 1. Aamainbankmaker mades the banks in the bnkmat folder and places 180 % ... coursemaker_unfinished.xls there. 181 % 2. User converts to coursemaker.xls and places it in the courses 182 folder, 183 %... where the user modifies coursemaker.xls in two ways:(a) Reduce Stud 184 %... value if it is desirable to place only some questions from a given 185 %... quiz into the study guide, and (b) choose which quizzes are part of 186 %... which course. 187 % 3. Abmaincoursemaker goes into to the courses folder and opens 188 %... coursemaker.xls. For the course selected at the top of this code, 189 an 190 %... xls (Excel) file is placed inside the (already created) folder named 191 %... after this course (as is the Excel file). 192 % 4. The user (later?) chooses which quizzes go into each test, and how 193 many 194 %... questsions from eawillch quiz are placed in each exam. 195 close all; clc; clear;%clear all; 196 addpath([pwd,'\functions'],'-frozen'); 197 %%Input variables: 198 coursename = Agetvar('coursename'); 199 fprintf('Abmaincoursemaker:coursename=%s\n',coursename); 200 % 201 Numbertests = Agetvar('Numbertests'); 202 fprintf('Abmaincoursemaker:Numbertests=%s\n',Numbertests); 203 % 204 checkroot = Agetvar('checkroot'); 205 fprintf('Abmaincoursemaker:checkroot=%s\n',checkroot); 206 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 207 addpath([checkroot, '\functions'],'-frozen'); 208 Warnme('nowarning',['Checkroot=',checkroot]); 209 cd(fullfile(Zroot,'courses')); 210 [~,~,coursemaker]=xlsread('coursemaker.xls'); 211 toprow = coursemaker(1,:); 212 %coursen is the col number corresponding to the course at hand: 213 coursen= strcmp(toprow, coursename); 214 % Go through all quizzes in coursemaker and select ones for this course 215 Nquizbnk =size(coursemaker,1)-1;%Number quizzes in bank 216

Page 5: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

nquiz=0; %starts count of Nquiz=#quizzes from bank in this course 217 %create the top row of the coursename.xls file: 218 t1cell=coursemaker(1,1:5);%copies first 5 cols of first row of 219 coursemaker 220 t2cell = num2cell([1:Numbertests]);% add 5 cols for tests (if 221 Numbertests=5) 222 coursecell(1,:)={t1cell{:},t2cell{:}}; %combines 2 string arrays to one 223 for nquizbnk=1:Nquizbnk 224 %Reads from coursemaker whether the quiz belongs (cell2mat converts) 225 incourse=cell2mat(coursemaker(nquizbnk+1,coursen)); 226 if strcmp(incourse,'NaN') %This permits me to leave blanks in coursemaker 227 incourse = 0; 228 end 229 if incourse>0 230 nquiz=nquiz+1; %only add if the quiz is included 231 % LATER allow incourse =.5 if there is a 50% chance of using quiz 232 %This is where we add quizzes to moc 233 coursecell(nquiz+1,1:5)=coursemaker(nquizbnk+1,1:5); 234 end 235 Nquizzesincourse=nquiz;%# quizzes used in the course 236 end 237 cd(fullfile(Zroot,'courses',coursename)); 238 delete([coursename '_unfinished.xls']); 239 xlswrite([coursename '_unfinished'],coursecell); 240 241 %Now do the same for the 4 banks: *clean, *gallery, *quesname, *quizname: 242 delete([coursename 'clean_unfinished.mat']); 243 delete([coursename 'gallery_unfinished.mat']); 244 delete([coursename 'quesname_unfinished.mat']); 245 delete([coursename 'quizname_unfinished.mat']); 246 247 % Nquizzesincourse has just been calculated 248 % Numbertests = an input variable 249 % Find largest quiz in course: 250 largestquiz = 0; 251 for ncquiz = 1:Nquizzesincourse 252 if coursecell{ncquiz+1,4}>largestquiz 253 largestquiz = coursecell{ncquiz+1,4}; 254 end 255 end 256 [bnkquizname, bnkquesname,bnkclean]=Loadbanks; 257 crsquizname=cell(Nquizzesincourse,size(bnkquizname,2)); 258 crsquesname=cell(Nquizzesincourse,size(bnkquesname,2)); 259 crsclean=cell(Nquizzesincourse,size(bnkclean,2)); 260 bnkid=cell(Nquizzesincourse,1); 261 for ncquiz=1:Nquizzesincourse %loops all quizzes in course 262 %find index in (large) bnk for quizname 263 quiz2find=coursecell{ncquiz+1,1}; 264 bnkid= find(strcmp(bnkquizname(:,1),quiz2find)); 265 %create reduced version of the three banks: 266 crsquizname(ncquiz,:)=bnkquizname(bnkid,:); 267 crsquesname(ncquiz,:)=bnkquesname(bnkid,:); 268 crsclean(ncquiz,:)=bnkclean(bnkid,:); 269 270

Page 6: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

end %Nquizzesincourse 271 cd(fullfile(Zroot,'courses',coursename)); 272 273 if isdir('smallbanks') 274 message = 'Do you want to replace smallbanks in'; 275 Warnme('noturgent',[message ,coursename,'? ']); 276 end 277 path2reducedbanks=fullfile(Zroot,'courses',coursename,'smallbanks'); 278 mkdir(path2reducedbanks); 279 cd(path2reducedbanks); 280 save('crsquizname','crsquizname'); 281 save('crsquesname','crsquesname'); 282 save('crsclean','crsclean'); 283 end 284 285 286 287 ==Acmaintestmaker - Copy== 288 289 function Acmaintestmaker 290 %%ACMAINTESTMAKER sets up the smallbanks folder in [nameofcourse 291 'folder'] 292 %main function 293 clear all; close all; clc; 294 %%input%%%%%%%%%%%%%% 295 cd('C:\Program Files\MATLAB\qzbnk1606') 296 %%ACMAINQUIZPRINTER must be called from Zroot 297 clc;clear all;close all; 298 nameofcourse='all'; 299 addpath([pwd, '\functions'],'-frozen'); 300 301 rootshouldbe = Agetvar('checkroot');%not needed any more? 302 Verifyroot(rootshouldbe);%not needed any more? 303 clear rootshouldbe;%not needed any more? 304 305 wikiguide = Makewikiguide(nameofcourse); 306 c1test2quiz3ques= Makec1test2quiz3ques(nameofcourse,wikiguide); 307 cd(fullfile(Zroot,'courses',nameofcourse,'smallbanks')); 308 Makewikisyllabus(nameofcourse,wikiguide); 309 [listquizname,listattributes,listfirstques,listNquesinqz,listNqzques2tst] 310 ... 311 = Makeprintguides(nameofcourse,wikiguide); 312 cd(fullfile(Zroot,'courses',nameofcourse,'smallbanks')); 313 save('listquizname','listquizname');save('listattributes','listattributes314 '); 315 save('listfirstques','listfirstques');save('listNquesinqz','listNquesinqz316 '); 317 save('listNqzques2tst','listNqzques2tst'); 318 wikitableraw=Makewikitable(nameofcourse); 319 % 320 keyboard; 321 end %function Acmaintestmaker 322 %% Functions 323 %% Verifyroot has been moved to the functions folder 324

Page 7: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

%% Makewikiguide 325 function wikiguide = Makewikiguide(nameofcourse) 326 %%MAKEWIKIGUIDE reads coursemaker and creates wikiguide 327 %wikiguide is a cell array that organizes all questions that might be on 328 a 329 %one of the tests in a course. Questions are listed by quiz and name. 330 %coursemaker.xls is in courses and wikiguide goes into "nameofcourse" 331 %wikikguide.txt can be posted on wiki as an abbreviated course outline 332 %(more for instructors than for students). Wikiguide is also called to 333 %create the tests and studyguide 334 path2course=fullfile(Zroot,'courses',nameofcourse); 335 cd(path2course);% 336 [~,~,coursexls]=xlsread(fullfile(path2course,[nameofcourse,'.xls'])); 337 [Nrow,Ncol]=size(coursexls); 338 for nrow= 1:Nrow % replace NaN by zeros: 339 for ncol = 1:Ncol 340 if isnan(coursexls{nrow,ncol}) 341 coursexls{nrow,ncol}=0; 342 end 343 end 344 end 345 % make wikiguide (text and .mat) out of coursexls 346 for nrow=1:Nrow %make all the columns of wikiguide 347 %first two cols of wikiguide have special formatting 348 wikiguide{nrow,1}=num2str(coursexls{nrow,1}); 349 oldidstr=num2str(Oldid(coursexls{nrow,2})); 350 str = strcat('[[Special:Permalink/',oldidstr,'|',oldidstr,']]'); 351 wikiguide{nrow,2}=str; 352 wikiguide{nrow,3}=['<ref>', num2str(coursexls{nrow,3}), '</ref>']; 353 for ncol=4:Ncol %The other colums are copied directly 354 wikiguide{nrow,ncol}=num2str(coursexls{nrow,ncol}); 355 end 356 end 357 wikiguide{1,2}... 358 ='<ref> [[w:Special:Permalink/725501782#Attribution|Attribution]]</ref>'; 359 wikiguide{1,3}='<ref>First question in quiz</ref>'; 360 save('wikiguide','wikiguide'); 361 file2print=fullfile(path2course,'wikiguide.txt'); 362 Writecell2txt(file2print,Cellarray2wikitable(wikiguide)); 363 end%Makewikiguide 364 %ddddd 365 %% c1test2quiz3ques 366 function c1test2quiz3ques = ... 367 Makec1test2quiz3ques(nameofcourse,wikiguide) 368 %% MAKEC1TEST23QUIZ creates a 3d cell array of 369 % 1:all the testnames used in this course, 370 % e.g. S_G or T1, T2, or 1T1... 371 % 2: quiznames, e.g. AstroApparentRetroMotion 372 % 3:question names, e.g. AstroApparentRetroMotion 373 % uses [bnkquizname, bnkquesname,bnkclean]=Loadbanks; 374 % Loadbanks changes directory w cd(fullfile(Zroot,'bnkmat')) 375 % Then go int \courses\"nameofcourse" and writes crsbanksfull.txt 376 [bnkquizname, bnkquesname,~]=Loadbanks; 377 cd(fullfile(Zroot,'courses',nameofcourse)); 378

Page 8: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

%% Preallocate size of c1quiz2tst3que 379 % To see the first column of wikiguide uncomment: 380 %wikiguide_columns=wikiguide(1,:)%MAY COMMENT THIS LINE OUT 381 numberquizzes = size(wikiguide,1)-1; 382 numbertests = size(wikiguide,2)-4; 383 maxquestions=size(bnkquesname,2); 384 c1test2quiz3ques=cell(numberquizzes,numbertests,maxquestions); 385 bnkonlynames=bnkquizname(:,1);%Needed to remove quizzes not in course 386 bnkonlyNques=bnkquizname(:,2);%Needed to list all questions in a quiz 387 bnkonlyattr=bnkquizname(:,3);%Not needed in this function 388 bnkonlystud=bnkquizname(:,4);%Not needed in this function 389 fout = fopen('c1test2quiz3ques.txt','w+'); 390 for crstestn=5:size(wikiguide,2) 391 ctestname = wikiguide(1,crstestn); 392 fprintf(fout,'test =%s\n',cell2mat(ctestname)); 393 %crsquizn indexes quizzes used for the course 394 for crsquizn = 2:size(wikiguide,1) 395 cquizname=wikiguide(crsquizn,1); 396 fprintf(fout,'quiz =%s\n', cell2mat(cquizname) ); 397 bnkindex = find(ismember(bnkonlynames, cquizname)); 398 for nques=1:bnkonlyNques{bnkindex}; 399 %Here, bnkonlyNques{bnkindex} is the number of 400 %questions in each quiz in the main (bnk*.mat) bank. 401 c1test2quiz3ques(crstestn-4,crsquizn-402 1,nques)=bnkquesname(bnkindex,nques); 403 fprintf(fout,' c1test2quiz3ques(%i,%i,%i)=%s\n',... 404 crstestn-4,crsquizn-1,nques,bnkquesname{bnkindex,nques}); 405 end 406 end %for nrow = 2:size(wikiguide,1) 407 end %crstestn=5:size(wikiguide,2) 408 fclose(fout); 409 end %function c1quiz2tst3que 410 %% Makewikisyllabus 411 function Makewikisyllabus(nameofcourse,wikiguide) 412 %%MAKEWIKISYLLABUS creates wikisyllabus.txt in "nameofcourse" directory 413 %Displays a ===header=== for each test (except study guide). Under that 414 %header are all the quiznames (with permalinks) with both the # 415 %questions in the quiz, as well as # questions that go into each test. 416 cd(fullfile(Zroot,'courses',nameofcourse)); 417 Ntest=size(wikiguide,2)-4;%(includes studyguide) 418 Nquiz=size(wikiguide,1)-1;% replaces Nquiz=size(crsquizname,1); 419 ntextline=1;%lines in the textfile 420 for ntest=2:Ntest%by starting at 2 we skip S_G 421 wikisyllabus{ntextline}=strcat('===',wikiguide{1,ntest+4},'==='); 422 ntextline=ntextline+1; 423 nnquiz=0; %nnquiz only counts quizzes in a given test 424 for nquiz = 1:Nquiz %this loops ALL quizzes in course 425 quizname = wikiguide{nquiz+1,1}; 426 if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 427 nnquiz=nnquiz+1; 428 tmp=[wikiguide{nquiz+1,ntest+4} '/' wikiguide{nquiz+1,4}]; 429 tmp1 = [tmp ' ' 'from' ' ' wikiguide{nquiz+1,2}]; 430 tmp2 = [tmp1 ' ' 'to' ' ' quizname '</br>']; 431 wikisyllabus{ntextline}=tmp2; 432

Page 9: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

ntextline=ntextline+1; 433 end%if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 434 end %nquiz = 1:Nquiz 435 end %for ntest=1:Nquiz 436 file2open = strcat(nameofcourse,'wikisyllabus.txt'); 437 Writecell2txt(file2open,wikisyllabus); 438 save('wiksyllabus','wikisyllabus') 439 440 end%function Makewikisyllabus(wikiguide) 441 %% Makeprintguides 442 function ... 443 [listquizname,listattributes,listfirstques,listNquesinqz,listNqzques2tst]444 ... 445 =Makeprintguides(nameofcourse,wikiguide) 446 %%MAKEPRINTGUIDES organizes quizzes, attributions, etc. 447 %In all cases the first two rows are reserved for test and number of 448 %quizzes used in each test. The four outputs are in the same order as the 449 %columns of wikiguide: 1=quizname, 2=attribution, 3=firstques, 450 %4=Nquesinqz=number of questions in each quiz. 5=Nqzques2tst= number of 451 %questions from a quiz that goes into the test. 452 cd(fullfile(Zroot,'courses',nameofcourse)); 453 Ntest=size(wikiguide,2)-4;%(includes studyguide) 454 Nquiz=size(wikiguide,1)-1;% replaces Nquiz=size(crsquizname,1); 455 for ntest=1:Ntest % do first column (lists testnames) 456 listquizname{1,ntest}=wikiguide{1,ntest+4}; 457 listattributes{1,ntest}=wikiguide{1,ntest+4}; 458 listfirstques{1,ntest}=wikiguide{1,ntest+4}; 459 listNquesinqz{1,ntest}=wikiguide{1,ntest+4}; 460 listNqzques2tst{1,ntest}=wikiguide{1,ntest+4}; 461 end% % do first column (lists testnames) 462 % create 'listquizname' 463 for ntest=1:Ntest % create 'listquizname') 464 nnquiz=0;% used to count quizzes that go into given test 465 %listquizname: Rows 1=testname, 2=%quizzes, 3...=quiznames 466 for nquiz=1:Nquiz %loop through and get names of quizzes 467 if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 468 nnquiz=nnquiz+1; 469 listquizname{nnquiz+2,ntest}=wikiguide{nquiz+1,1}; 470 listattributes{nnquiz+2,ntest}=wikiguide{nquiz+1,2}; 471 listfirstques{nnquiz+2,ntest}=wikiguide{nquiz+1,3}; 472 listNquesinqz{nnquiz+2,ntest}=str2num(wikiguide{nquiz+1,4}); 473 listNqzques2tst{nnquiz+2,ntest}=... 474 str2num(wikiguide{nquiz+1,ntest+4}); 475 end%if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 476 end %nquiz=1:Nquiz %loop through and get names of quizzes 477 listquizname{2,ntest}=nnquiz;%number of quizzes 4 ntest 478 listattributes{2,ntest}=nnquiz; 479 listfirstques{2,ntest}=nnquiz; 480 listNquesinqz{2,ntest}=nnquiz; 481 listNqzques2tst{2,ntest}=nnquiz; 482 end%for ntest=1:Ntest 483 %end: 484 % function [listquizname,listattributes,listfirstques,listNquizzes]... 485 % =Makeprintguides(nameofcourse,wikiguide) 486

Page 10: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

end%Makeprintguides 487 %% Makewikitable(nameofcourse,wikiguide) 488 function wikitableraw = Makewikitable(nameofcourse) 489 490 %%MAKEWIKITABLE creates wikitable.mat and wikitable.txt 491 %wikitable.txt will be used by students to know which questions in the 492 %studgyide will be on each test. 493 path2course=fullfile(Zroot,'courses',nameofcourse); 494 cd(path2course);% 495 [~,~,coursexls]=xlsread(fullfile(path2course,[nameofcourse,'.xls'])); 496 [Nrow,Ncol]=size(coursexls); 497 for nrow= 1:Nrow % replace NaN by zeros: 498 for ncol = 1:Ncol 499 if isnan(coursexls{nrow,ncol}) 500 coursexls{nrow,ncol}=0; 501 end 502 end 503 end 504 linkindex=Ncol-2; 505 qidindex=Ncol-1; 506 firstindex=Ncol; 507 Ntest_ns=Ncol-5;%_ns = no studyguide in count 508 wikitableraw{1,1}='questions'; 509 wikitableraw{1,2}='max'; 510 for ntest=1:Ntest_ns 511 wikitableraw{1,2+ntest}=coursexls{1,5+ntest}; 512 end%ntest=1:Ntest_ns 513 wikitableraw{1,Ncol-2}='oldid'; 514 wikitableraw{1,Ncol-1}='q_'; 515 wikitableraw{1,Ncol}='1st';%This ends the first row. 516 517 %under construction begin 518 quescount=1;% used to create column 1 519 for nrow=2:Nrow% fill in each column row by row: 520 wikitableraw{nrow,2+ntest}=coursexls{nrow,5+ntest}; 521 %Make column 1: Problems in studyguide(first-last) 522 firstq=quescount; 523 n_sg=coursexls{nrow,5}; 524 lastq=firstq+n_sg-1; 525 str=[num2str(firstq) '&minus;' num2str(lastq)]; 526 wikitableraw{nrow,1}=str; 527 quescount=quescount+n_sg; 528 %Make column 2: Total problems from studyguide 529 wikitableraw{nrow,2}=coursexls{nrow,4};%aka n_sg 530 %Make columns 3 to 2+Ntest_ns 531 for ntest=1:Ntest_ns%excludes studyguide 532 wikitableraw{nrow,2+ntest}=coursexls{nrow,5+ntest}; 533 end%for ntest=1:Ntest_ns%excludes studyguide 534 %Make last col first and go backward. 535 str=Oldid(coursexls{nrow,2}); 536 str=['[[Special:Permalink/' str '|' str ']]']; 537 wikitableraw{nrow,Ncol-2}= str;%oldid 538 wikitableraw{nrow,Ncol-1}=['<ref>' coursexls{nrow,1} '</ref>'];%q_ 539 wikitableraw{nrow,Ncol}=['<ref>_' coursexls{nrow,3} '</ref>'];%1st 540

Page 11: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

end%for nrow=2:Nrow% fill in each column row by row: 541 %Save this table as wikitable.txt and wikitableraw.mat: 542 Writecell2txt('wikitable.txt',Cellarray2wikitable(wikitableraw)); 543 save('wikitableraw','wikitableraw'); 544 end%Makewikitable 545 546 ==Acmaintestmaker== 547 548 function Acmaintestmaker 549 %%ACMAINTESTMAKER sets up the smallbanks folder in [coursename 'folder'] 550 %main function 551 clear all; close all; clc; 552 addpath([pwd, '\functions'],'-frozen'); 553 coursename = Agetvar('coursename');%not needed any more? 554 wikiguide = Makewikiguide(coursename); 555 c1test2quiz3ques= Makec1test2quiz3ques(coursename,wikiguide); 556 cd(fullfile(Zroot,'courses',coursename,'smallbanks')); 557 Makewikisyllabus(coursename,wikiguide); 558 [listquizname,listattributes,listfirstques,listNquesinqz,listNqzques2tst] 559 ... 560 = Makeprintguides(coursename,wikiguide); 561 cd(fullfile(Zroot,'courses',coursename,'smallbanks')); 562 save('listquizname','listquizname');save('listattributes','listattributes563 '); 564 save('listfirstques','listfirstques');save('listNquesinqz','listNquesinqz565 '); 566 save('listNqzques2tst','listNqzques2tst'); 567 wikitableraw=Makewikitable(coursename); 568 % 569 keyboard; 570 end %function Acmaintestmaker 571 %% Functions 572 %% Verifyroot has been moved to the functions folder 573 %% Makewikiguide 574 function wikiguide = Makewikiguide(coursename) 575 %%MAKEWIKIGUIDE reads coursemaker and creates wikiguide 576 %wikiguide is a cell array that organizes all questions that might be on 577 a 578 %one of the tests in a course. Questions are listed by quiz and name. 579 %coursemaker.xls is in courses and wikiguide goes into "coursename" 580 %wikikguide.txt can be posted on wiki as an abbreviated course outline 581 %(more for instructors than for students). Wikiguide is also called to 582 %create the tests and studyguide 583 path2course=fullfile(Zroot,'courses',coursename); 584 cd(path2course);% 585 [~,~,coursexls]=xlsread(fullfile(path2course,[coursename,'.xls'])); 586 [Nrow,Ncol]=size(coursexls); 587 for nrow= 1:Nrow % replace NaN by zeros: 588 for ncol = 1:Ncol 589 if isnan(coursexls{nrow,ncol}) 590 coursexls{nrow,ncol}=0; 591 end 592 end 593 end 594

Page 12: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

% make wikiguide (text and .mat) out of coursexls 595 for nrow=1:Nrow %make all the columns of wikiguide 596 %first two cols of wikiguide have special formatting 597 wikiguide{nrow,1}=num2str(coursexls{nrow,1}); 598 oldidstr=num2str(Oldid(coursexls{nrow,2})); 599 str = strcat('[[Special:Permalink/',oldidstr,'|',oldidstr,']]'); 600 wikiguide{nrow,2}=str; 601 wikiguide{nrow,3}=['<ref>', num2str(coursexls{nrow,3}), '</ref>']; 602 for ncol=4:Ncol %The other colums are copied directly 603 wikiguide{nrow,ncol}=num2str(coursexls{nrow,ncol}); 604 end 605 end 606 wikiguide{1,2}... 607 ='<ref> [[w:Special:Permalink/725501782#Attribution|Attribution]]</ref>'; 608 wikiguide{1,3}='<ref>First question in quiz</ref>'; 609 save('wikiguide','wikiguide'); 610 file2print=fullfile(path2course,'wikiguide.txt'); 611 Writecell2txt(file2print,Cellarray2wikitable(wikiguide)); 612 end%Makewikiguide 613 %ddddd 614 %% c1test2quiz3ques 615 function c1test2quiz3ques = ... 616 Makec1test2quiz3ques(coursename,wikiguide) 617 %% MAKEC1TEST23QUIZ creates a 3d cell array of 618 % 1:all the testnames used in this course, 619 % e.g. S_G or T1, T2, or 1T1... 620 % 2: quiznames, e.g. AstroApparentRetroMotion 621 % 3:question names, e.g. AstroApparentRetroMotion 622 % uses [bnkquizname, bnkquesname,bnkclean]=Loadbanks; 623 % Loadbanks changes directory w cd(fullfile(Zroot,'bnkmat')) 624 % Then go int \courses\"coursename" and writes crsbanksfull.txt 625 [bnkquizname, bnkquesname,~]=Loadbanks; 626 cd(fullfile(Zroot,'courses',coursename)); 627 %% Preallocate size of c1quiz2tst3que 628 % To see the first column of wikiguide uncomment: 629 %wikiguide_columns=wikiguide(1,:)%MAY COMMENT THIS LINE OUT 630 numberquizzes = size(wikiguide,1)-1; 631 numbertests = size(wikiguide,2)-4; 632 maxquestions=size(bnkquesname,2); 633 c1test2quiz3ques=cell(numberquizzes,numbertests,maxquestions); 634 bnkonlynames=bnkquizname(:,1);%Needed to remove quizzes not in course 635 bnkonlyNques=bnkquizname(:,2);%Needed to list all questions in a quiz 636 bnkonlyattr=bnkquizname(:,3);%Not needed in this function 637 bnkonlystud=bnkquizname(:,4);%Not needed in this function 638 fout = fopen('c1test2quiz3ques.txt','w+'); 639 for crstestn=5:size(wikiguide,2) 640 ctestname = wikiguide(1,crstestn); 641 fprintf(fout,'test =%s\n',cell2mat(ctestname)); 642 %crsquizn indexes quizzes used for the course 643 for crsquizn = 2:size(wikiguide,1) 644 cquizname=wikiguide(crsquizn,1); 645 fprintf(fout,'quiz =%s\n', cell2mat(cquizname) ); 646 bnkindex = find(ismember(bnkonlynames, cquizname)); 647 for nques=1:bnkonlyNques{bnkindex}; 648

Page 13: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

%Here, bnkonlyNques{bnkindex} is the number of 649 %questions in each quiz in the main (bnk*.mat) bank. 650 c1test2quiz3ques(crstestn-4,crsquizn-651 1,nques)=bnkquesname(bnkindex,nques); 652 fprintf(fout,' c1test2quiz3ques(%i,%i,%i)=%s\n',... 653 crstestn-4,crsquizn-1,nques,bnkquesname{bnkindex,nques}); 654 end 655 end %for nrow = 2:size(wikiguide,1) 656 end %crstestn=5:size(wikiguide,2) 657 fclose(fout); 658 end %function c1quiz2tst3que 659 %% Makewikisyllabus 660 function Makewikisyllabus(coursename,wikiguide) 661 %%MAKEWIKISYLLABUS creates wikisyllabus.txt in "coursename" directory 662 %Displays a ===header=== for each test (except study guide). Under that 663 %header are all the quiznames (with permalinks) with both the # 664 %questions in the quiz, as well as # questions that go into each test. 665 cd(fullfile(Zroot,'courses',coursename)); 666 Ntest=size(wikiguide,2)-4;%(includes studyguide) 667 Nquiz=size(wikiguide,1)-1;% replaces Nquiz=size(crsquizname,1); 668 ntextline=1;%lines in the textfile 669 for ntest=2:Ntest%by starting at 2 we skip S_G 670 wikisyllabus{ntextline}=strcat('===',wikiguide{1,ntest+4},'==='); 671 ntextline=ntextline+1; 672 nnquiz=0; %nnquiz only counts quizzes in a given test 673 for nquiz = 1:Nquiz %this loops ALL quizzes in course 674 quizname = wikiguide{nquiz+1,1}; 675 if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 676 nnquiz=nnquiz+1; 677 tmp=[wikiguide{nquiz+1,ntest+4} '/' wikiguide{nquiz+1,4}]; 678 tmp1 = [tmp ' ' 'from' ' ' wikiguide{nquiz+1,2}]; 679 tmp2 = [tmp1 ' ' 'to' ' ' quizname '</br>']; 680 wikisyllabus{ntextline}=tmp2; 681 ntextline=ntextline+1; 682 end%if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 683 end %nquiz = 1:Nquiz 684 end %for ntest=1:Nquiz 685 file2open = strcat(coursename,'wikisyllabus.txt'); 686 Writecell2txt(file2open,wikisyllabus); 687 save('wiksyllabus','wikisyllabus') 688 689 end%function Makewikisyllabus(wikiguide) 690 %% Makeprintguides 691 function ... 692 [listquizname,listattributes,listfirstques,listNquesinqz,listNqzques2tst]693 ... 694 =Makeprintguides(coursename,wikiguide) 695 %%MAKEPRINTGUIDES organizes quizzes, attributions, etc. 696 %In all cases the first two rows are reserved for test and number of 697 %quizzes used in each test. The four outputs are in the same order as the 698 %columns of wikiguide: 1=quizname, 2=attribution, 3=firstques, 699 %4=Nquesinqz=number of questions in each quiz. 5=Nqzques2tst= number of 700 %questions from a quiz that goes into the test. 701 cd(fullfile(Zroot,'courses',coursename)); 702

Page 14: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

Ntest=size(wikiguide,2)-4;%(includes studyguide) 703 Nquiz=size(wikiguide,1)-1;% replaces Nquiz=size(crsquizname,1); 704 for ntest=1:Ntest % do first column (lists testnames) 705 listquizname{1,ntest}=wikiguide{1,ntest+4}; 706 listattributes{1,ntest}=wikiguide{1,ntest+4}; 707 listfirstques{1,ntest}=wikiguide{1,ntest+4}; 708 listNquesinqz{1,ntest}=wikiguide{1,ntest+4}; 709 listNqzques2tst{1,ntest}=wikiguide{1,ntest+4}; 710 end% % do first column (lists testnames) 711 % create 'listquizname' 712 for ntest=1:Ntest % create 'listquizname') 713 nnquiz=0;% used to count quizzes that go into given test 714 %listquizname: Rows 1=testname, 2=%quizzes, 3...=quiznames 715 for nquiz=1:Nquiz %loop through and get names of quizzes 716 if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 717 nnquiz=nnquiz+1; 718 listquizname{nnquiz+2,ntest}=wikiguide{nquiz+1,1}; 719 listattributes{nnquiz+2,ntest}=wikiguide{nquiz+1,2}; 720 listfirstques{nnquiz+2,ntest}=wikiguide{nquiz+1,3}; 721 listNquesinqz{nnquiz+2,ntest}=str2num(wikiguide{nquiz+1,4}); 722 listNqzques2tst{nnquiz+2,ntest}=... 723 str2num(wikiguide{nquiz+1,ntest+4}); 724 end%if str2num(wikiguide{nquiz+1,ntest+4}) >= 1 725 end %nquiz=1:Nquiz %loop through and get names of quizzes 726 listquizname{2,ntest}=nnquiz;%number of quizzes 4 ntest 727 listattributes{2,ntest}=nnquiz; 728 listfirstques{2,ntest}=nnquiz; 729 listNquesinqz{2,ntest}=nnquiz; 730 listNqzques2tst{2,ntest}=nnquiz; 731 end%for ntest=1:Ntest 732 %end: 733 % function [listquizname,listattributes,listfirstques,listNquizzes]... 734 % =Makeprintguides(coursename,wikiguide) 735 end%Makeprintguides 736 %% Makewikitable(coursename,wikiguide) 737 function wikitableraw = Makewikitable(coursename) 738 739 %%MAKEWIKITABLE creates wikitable.mat and wikitable.txt 740 %wikitable.txt will be used by students to know which questions in the 741 %studgyide will be on each test. 742 path2course=fullfile(Zroot,'courses',coursename); 743 cd(path2course);% 744 [~,~,coursexls]=xlsread(fullfile(path2course,[coursename,'.xls'])); 745 [Nrow,Ncol]=size(coursexls); 746 for nrow= 1:Nrow % replace NaN by zeros: 747 for ncol = 1:Ncol 748 if isnan(coursexls{nrow,ncol}) 749 coursexls{nrow,ncol}=0; 750 end 751 end 752 end 753 linkindex=Ncol-2; 754 qidindex=Ncol-1; 755 firstindex=Ncol; 756

Page 15: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

Ntest_ns=Ncol-5;%_ns = no studyguide in count 757 wikitableraw{1,1}='questions'; 758 wikitableraw{1,2}='max'; 759 for ntest=1:Ntest_ns 760 wikitableraw{1,2+ntest}=coursexls{1,5+ntest}; 761 end%ntest=1:Ntest_ns 762 wikitableraw{1,Ncol-2}='oldid'; 763 wikitableraw{1,Ncol-1}='q_'; 764 wikitableraw{1,Ncol}='1st';%This ends the first row. 765 766 %under construction begin 767 quescount=1;% used to create column 1 768 for nrow=2:Nrow% fill in each column row by row: 769 wikitableraw{nrow,2+ntest}=coursexls{nrow,5+ntest}; 770 %Make column 1: Problems in studyguide(first-last) 771 firstq=quescount; 772 n_sg=coursexls{nrow,5}; 773 lastq=firstq+n_sg-1; 774 str=[num2str(firstq) '&minus;' num2str(lastq)]; 775 wikitableraw{nrow,1}=str; 776 quescount=quescount+n_sg; 777 %Make column 2: Total problems from studyguide 778 wikitableraw{nrow,2}=coursexls{nrow,4};%aka n_sg 779 %Make columns 3 to 2+Ntest_ns 780 for ntest=1:Ntest_ns%excludes studyguide 781 wikitableraw{nrow,2+ntest}=coursexls{nrow,5+ntest}; 782 end%for ntest=1:Ntest_ns%excludes studyguide 783 %Make last col first and go backward. 784 str=Oldid(coursexls{nrow,2}); 785 str=['[[Special:Permalink/' str '|' str ']]']; 786 wikitableraw{nrow,Ncol-2}= str;%oldid 787 wikitableraw{nrow,Ncol-1}=['<ref>' coursexls{nrow,1} '</ref>'];%q_ 788 wikitableraw{nrow,Ncol}=['<ref>_' coursexls{nrow,3} '</ref>'];%1st 789 end%for nrow=2:Nrow% fill in each column row by row: 790 %Save this table as wikitable.txt and wikitableraw.mat: 791 Writecell2txt('wikitable.txt',Cellarray2wikitable(wikitableraw)); 792 save('wikitableraw','wikitableraw'); 793 end%Makewikitable 794 795 ==Admaintestprinter== 796 797 function Admaintestprinter( ~ ) 798 %ADMAINTESTPRINTER cycles through all the courses 799 % Detailed explanation goes here 800 clear; close all; clc; 801 %% input 802 addpath([pwd, '\functions'],'-frozen'); 803 coursename=Agetvar('coursename'); 804 checkroot=Agetvar('checkroot'); 805 Nvers=Agetvar('Nvers'); 806 cd(checkroot)%Must call from Zroot 807 %SetupAdmain begin 808 [outputfilename,listquizname,listattributes,listfirstques,... 809 listNquesinqz,listNqzques2tst,crsclean,crsquizname]= ... 810

Page 16: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

SetupAdmain(coursename);%SetupAdmain end 811 %Rendercourse begin 812 renderedcrs = Rendercourse(listquizname,listNquesinqz,listNqzques2tst,... 813 crsquizname,crsclean);%Rendercourse end 814 save('renderedcrs','renderedcrs'); 815 OptionshowListnq_c(0,listquizname,crsquizname);%0=>return 816 Firstlinewiki(outputfilename,listquizname, renderedcrs,coursename); 817 Wikisamplerend(outputfilename,listquizname, renderedcrs,... 818 coursename, listattributes); 819 Printstudypdf(outputfilename,listquizname, renderedcrs,... 820 coursename, listattributes); 821 Print2versions(Nvers,outputfilename,listquizname, renderedcrs,... 822 coursename, listattributes); 823 cd(fullfile(Zroot,'courses',coursename)); 824 load('wiksyllabus','wikisyllabus');%note spelling error 825 cd(fullfile('output',outputfilename)); 826 Writecell2txt('wikisyllabus.txt',wikisyllabus); 827 %place copy of coursename.xls into output folder 828 path2course=fullfile(Zroot,'courses',coursename); 829 localfile=[path2course, '\', coursename, '.xls']; 830 path2out=fullfile(path2course,'output',outputfilename); 831 newfile=[path2out, '\', coursename, '_copy.xls']; 832 copyfile(localfile,newfile) 833 keyboard;%type return in cmd window to return. 834 end %Admaintestprinter 835 %% Subfunctions 836 %fprintf('%i-:',MFileLineNr); 837 %% [...]SetupAdmain(coursename) 838 function [outputfilename,listquizname,listattributes,listfirstques,... 839 listNquesinqz,listNqzques2tst,crsclean,crsquizname]= ... 840 SetupAdmain(coursename) 841 %%SETUPADMAIN checks root, creates dated outputfile loads smallbanks 842 %It leaves the program in the local smallbanks directory. verifies Zroot, 843 %creates and loads bankks 844 rootshouldbe = 'C:\Program Files\MATLAB\qzbnk1606'; 845 Verifyroot(rootshouldbe); 846 cd(fullfile(Zroot,'courses',coursename,'output')); 847 outputfilename=[coursename datestr(now,'yyyymmddTHHMMSS')]; 848 fprintf('%i-SetupAdmain:outputfilename=%s 849 \n',MFileLineNr(),outputfilename); 850 mkdir(outputfilename);%creates a new file each time this function is 851 called 852 %Practiceprint(coursename,outputfilename);%diagnostic purposes only 853 cd(fullfile(Zroot,'courses',coursename,'smallbanks')) 854 load('listquizname','listquizname');%quizname 855 load('listattributes','listattributes');%attribution 856 load('listfirstques','listfirstques');%for diagnostic purposes only 857 load('listNquesinqz','listNquesinqz');%#questions in quiz 858 load('listNqzques2tst','listNqzques2tst');%#ques in quiz 2 test 859 load('crsclean','crsclean');%Nquiz x Nques with cell arrays as elements 860 load('crsquizname','crsquizname');%Nquiz x Nques w cell arrays as 861 elements 862 end%SetupAdmain end 863 %% OptionshowListnq_c(option,listquizname,crsquizname) 864

Page 17: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

function OptionshowListnq_c(option,listquizname,crsquizname) 865 %%OptionshowListnq_c was used to construct Listnq_c 866 % it may be commented out 867 if ~option, return, end; 868 fprintf('%i-OptionshowListnq_c: listquizname{1,:}=',MFileLineNr); 869 fprintf('%s ',listquizname{1,:});fprintf('\n'); 870 for ntest = 1:length(listquizname(1,:)) 871 fprintf('ntest=%i\n',ntest); 872 for nq_l=1:listquizname{2,ntest} 873 temp=listquizname(:, ntest); 874 fprintf('nq_l=%i %s (of listquizname(nq_l+2,ntest)=%i)\n',... 875 nq_l,temp{2+nq_l},listquizname{2,ntest}); 876 listquiznamecell{nq_l,ntest}=temp{2+nq_l}; 877 end%for nquiz 878 end%for ntest 879 explanation='The rows of all crs* files indicate the quizzes. '; 880 explanation = [explanation 'Function Listnq_c takes the quizname and ']; 881 explanation = [explanation 'returns the row in crsquizname. ']; 882 fprintf('%i-OptionshowListnq_c: %s\n',MFileLineNr,explanation); 883 for count = 1:size(crsquizname,1) 884 fprintf('coursequizname{%i,1}=%s\n\n',count,crsquizname{count,1}); 885 end%count 886 fprintf('%i-OptionshowListnq_c: %s\n',MFileLineNr,'Now we test 887 Listng_c'); 888 889 890 for n = 1:length(listquizname(1,:)) 891 fprintf('\n * ntest=%i ,test=%s ',n,listquizname{1,n}); 892 for q=1:listquizname{2,n} 893 fprintf('\n ntest=%i,nquiz=%i,quiz=%s\n',n,q,listquizname{q+2,n}) 894 n_crs=Listnq_c(n,q,listquizname,crsquizname); 895 fprintf('Listnq_c(ntest,nquiz)=%i=>%s\n', n_crs,crsquizname{n_crs,1}); 896 897 end 898 end 899 900 end 901 %OptionshowListnq_c end 902 %% nqc=Listnq_c(ntest,nql,listquizname,crsquizname) 903 function nqc=Listnq_c(ntest,nql,listquizname,crsquizname) 904 %%LISTNQ_C converts list variables from (ntest,nql) to nqc 905 % more commments can go here. 906 % fprintf('%i-L; ',MFileLineNr);%maybe 2 long! 907 quizname=listquizname{nql+2,ntest}; 908 nqc=find(strcmp(quizname,crsquizname(:,1))); 909 end% Listnq_c 910 function renderedcrs = Rendercourse... 911 (listquizname,listNquesinqz,listNqzques2tst, ... 912 crsquizname,crsclean) 913 fprintf('%i-Rendercourse calls Listnq_c=L;',MFileLineNr); 914 testlist=listquizname(1,:); 915 Ntest=length(testlist); 916 for ntest=1:Ntest 917 %fprintf('%i-Listnq_c: ntest=%i (%s)\n',MFileLineNr,ntest,... 918

Page 18: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

% listquizname{1,ntest}); 919 row=0;%row is the row number in the new cell array crsrnd 920 for nq_list=1:listquizname{2,ntest} %latter is # quizzes in ntest 921 %nq_list indexes the quizzes for ntest in the list order, or as the 922 %course was designed by the 'coursename' excel file (i.e. moc). 923 N_qq=listNquesinqz{nq_list+2,ntest};%list # questions in quiz 924 N_t=listNqzques2tst{nq_list+2,ntest};%list # questions to test 925 926 if N_qq==N_t %don't randomize if all questions are present 927 quesrank=[1:N_qq];%was incorrectly depicted as linspace 928 else 929 quesrank=randperm(N_qq); 930 end%if N_q==N_t 931 for nques=1:N_t %selecting questions from the test 932 row=row+1; 933 randomquestion=quesrank(nques); 934 nqc=Listnq_c(ntest,nq_list,listquizname,crsquizname); 935 temp = crsclean{nqc,randomquestion}; 936 renderedcrs{row,ntest}=temp; 937 %fprintf('%i-Listnq_c: row%i: %s\n',MFileLineNr,... 938 %row,temp{1}); 939 end%for nques=1:N_t 940 end%for nq_list=1:listquizname{2,ntest} 941 end%for ntest=1:Ntest 942 end%Rendercourse end 943 %% Firstlinewiki(outputfilename,listquizname,renderedcrs,coursename) 944 function Firstlinewiki(outputfilename,listquizname, ... 945 renderedcrs,coursename) 946 %%FIRSTLINEWIKI is also a rendition of the course that students should 947 not 948 %%see. 949 fprintf('\n%i-Firstlinewiki;',MFileLineNr); 950 cd(fullfile(Zroot,'courses',coursename,'output',outputfilename)); 951 save('renderedcrs','renderedcrs'); 952 foutfrstlinwik = fopen('firstlinewiki.txt','w+'); 953 fprintf(foutfrstlinwik,'%s\n','Created using function Firstlinewiki'); 954 fprintf(foutfrstlinwik,'%s\n', strcat('{{cot|',outputfilename,'}}')); 955 str = '<pre style="white-space: pre; white-space: -moz-pre;'; 956 str = [str,'white-space: -pre; white-space: -o-pre;"><nowiki>']; 957 fprintf(foutfrstlinwik,'%s\n',str); 958 Ntest=length(listquizname(1,:)); 959 for ntest=1:Ntest 960 fprintf(foutfrstlinwik,'*ntest=%i: %s\n',... 961 ntest,listquizname{1,ntest}); 962 tempcell=renderedcrs(:,ntest); 963 rowmax=size(tempcell,1); 964 for row = 1:rowmax; 965 temp=renderedcrs{row,ntest}; 966 if ~isempty(temp) 967 fprintf(foutfrstlinwik,'%s\n',temp{1}); 968 end% ~isempty(temp) 969 end %for row = 1:rowmax; 970 end%for ntest=1:Ntest 971 fprintf(foutfrstlinwik,'%s\n', '</nowiki></pre>{{cob}}'); 972

Page 19: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

fclose(foutfrstlinwik); 973 end %Firstlinewiki 974 %% Pickquestion(norandom,question) 975 function rawquestion = Pickquestion(norandom,question) 976 %PICKQUESTION returns a cell array corresponding to one question 977 %norandom=0 if a random selection is needed, the input, e.g., 978 %question=renderedcrs{2,1} was obtained from renderedcrs cell array; 979 %fprintf('%i-Pickquestion:\n',MFileLineNr); 980 nversions=size(question,1);%nversions > 1 iff numerical 981 %This makes it impossible to select a number greater than nversions. 982 %1: random selection of conceptual ques 983 %fprintf('%i-Pickquestion:%%1 \n',MFileLineNr); 984 %fprintf('%i-PC;',MFileLineNr); %Might be too long for command window 985 if norandom==0 && nversions==1 986 select=1; 987 nmax=size(question,2); 988 aseed=randperm(nmax-1); 989 vquestion{1}=question(select,1); 990 for n=2:nmax %copy in original orderf 991 antxt=question{select,1+aseed(n-1)}; 992 cnt=1; 993 plusorminus=antxt(cnt); 994 while ~ ( strcmp(antxt(cnt),' ') || ... 995 strcmp(antxt(cnt),'+') ||... 996 strcmp(antxt(cnt),'-')) 997 count=count+1; 998 plusorminus=antxt(cnt); 999 end 1000 if cnt>3 1001 %temp = question(1,1); 1002 message = 'gap in conceptual question:\n%s'; 1003 error(message, question{1,1}); 1004 end%if 1005 text2print= strcat(plusorminus,char(n+95),') '); 1006 vquestion{n}=[text2print, antxt(cnt+1:end)];%keep original order 1007 end%for 1008 end%if norandom==0 && nversions==1 1009 %2: random selection of numerical ques 1010 %fprintf('%i-Pickquestion:%%2 \n',MFileLineNr); 1011 if norandom==0 && nversions>1 1012 if nversions<3 1013 message = 'This numerical question has only %i versions:\n%s'; 1014 error(message, question{1,1}); 1015 end 1016 selections=randperm(nversions-2); 1017 select = 2+selections(1); %Don't select from the first two 1018 nmax=size(question,2); %#answers plus one (for question) 1019 for n=1:nmax 1020 vquestion{n}=question(select,n); 1021 end%for 1022 end% if norandom==0 && nversions>1 1023 %3: nonrandom selection of conceptual ques 1024 %fprintf('%i-Pickquestion:%%3\n',MFileLineNr); 1025 if norandom>0 && nversions==1 1026

Page 20: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

nmax=size(question,2); %Case 4 1027 select=1; %only option available 1028 vquestion{1}=question(select,1); 1029 for n=2:nmax %copy in original order 1030 antxt=question{select,n}; 1031 cnt=1; 1032 plusorminus=antxt(cnt); 1033 while ~ ( strcmp(antxt(cnt),' ') || ... 1034 strcmp(antxt(cnt),'+') ||... 1035 strcmp(antxt(cnt),'-')) 1036 count=count+1; 1037 plusorminus=antxt(cnt); 1038 end 1039 if cnt>3 1040 temp = question(1,1); 1041 message = 'gap in conceptual question:\n%s'; 1042 error(message, question{1,1}); 1043 end 1044 text2print= strcat(plusorminus,char(n+95),' '); 1045 vquestion{n}=[text2print, antxt(cnt+1:end)];%keep original order 1046 end%for 1047 end%if norandom>0 && nversions==1 1048 %4: nonrandom selection of numerical ques 1049 %fprintf('%i-Pickquestion:%%4\n',MFileLineNr); 1050 if norandom>0 && nversions>1 1051 nmax=size(question,2); 1052 select=min(norandom,nversions); 1053 for n=1:nmax 1054 vquestion{n}=question(select,n); 1055 end%for%this copies the entire "selected" question 1056 end%if norandom>0 && nversions>1 1057 %fprintf('norandom %i\n',norandom) 1058 %fprintf('%i-Pickquestion temp1:\n',MFileLineNr); 1059 for n=1:nmax 1060 cell2print=vquestion{1,n}; 1061 str=char(cell2print); 1062 %fprintf('%s\n',str); 1063 end 1064 %fprintf('\n'); 1065 for n=1:nmax 1066 cell2print=vquestion{1,n}; 1067 rawquestion{n}=char(cell2print); 1068 end%for n=1:nmax 1069 %fprintf('%i-leave Pickquestion\n',MFileLineNr); 1070 end%Pickquestion 1071 %% Wikisamplerend(...) 1072 function Wikisamplerend(outputfilename,listquizname, renderedcrs,... 1073 coursename,listattributes) 1074 %%WIKISAMPLEREND prints a sample rendition to output 1075 %It is in wiki version of approximately what instructors would see 1076 %in the pdf file. Students can see samples, but not the actual 1077 %document that an instructor would use. 1078 %foutlocal = 1;%May uncomment to see command window 1079 fprintf('\n%i-Wikisamplerend calls Pickquestion=PC:',MFileLineNr()); 1080

Page 21: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

foutlocal = fopen('wikisamplerend.txt','w+'); 1081 cd(fullfile(Zroot,'courses',coursename,'output',outputfilename)); 1082 for ntest=1:size(renderedcrs,2)%=Ntest 1083 testname=listattributes{1,ntest}; 1084 fprintf(foutlocal,'===[[/%s/]]===\n',testname); 1085 Nques=length(find(~cellfun(@isempty,renderedcrs(:,ntest)))); 1086 %Note: renderedcrs(:,ntest)) is a cell array that contains all the 1087 %questions of a quiz, with empty cells at the end if exists fewer than 1088 %the maximum number of questions present. 1089 for nques=1:Nques%=Nques 1090 questionarray=Pickquestion(0,renderedcrs{nques,ntest}); 1091 for nline=1:length(questionarray)%=Nanswers+1 1092 fprintf(foutlocal,'%s\n',questionarray{nline}); 1093 end%ffor nline=1:length(questionarray)%=Nanswers+1 1094 fprintf(foutlocal,'\n'); 1095 end%for nques=1:length(renderedcrs(:,ntest))%=Nques 1096 1097 end%ntest=1:size(renderedcrs,2)%=Ntest 1098 %if ~foutlocal==1,fclose(foutlocal);end; 1099 fclose(foutlocal); 1100 end%Wikisamplerend 1101 function Printstudypdf(outputfilename,listquizname, renderedcrs,... 1102 coursename, listattributes) 1103 %%PRINTSTUDYPDF prints out a studyguide 1104 %The textfile studypdf.txt will be reopenned for the guide/attrib. 1105 fprintf('\n%i-Printstudypdf calls Pickquestion=PC:',MFileLineNr()); 1106 fout = fopen('studypdf.txt','w+'); 1107 fprintf(fout,'%s\n%s\n','__TOC__', outputfilename); 1108 cd(fullfile(Zroot,'courses',coursename,'output',outputfilename)); 1109 %for ntest=1:size(renderedcrs,2)%=Ntest%Uncomment for 1110 ntest=1;% This replaces the for loop 1111 for key = 1:2 %key=1 for questions, =2 for key 1112 testname=listattributes{1,ntest}; 1113 switch key 1114 case 1% for questions 1115 fprintf(fout,'==%s: Studyguide==\n',testname); 1116 case 2% for key 1117 fprintf(fout,'===%s (key)===\n',testname); 1118 end %switch Key 1119 Nques=length(find(~cellfun(@isempty,renderedcrs(:,ntest)))); 1120 for nques=1:Nques%=Nques 1121 fprintf(fout,'%s\n',...%Start page-break-avoid 1122 '<div style="page-break-inside:avoid;">'); 1123 questionarray=Pickquestion(0,renderedcrs{nques,ntest}); 1124 questext=questionarray{1}; 1125 fprintf(fout,'%i) %s\n',nques,questext(2:end-1));%question 1126 for nline=2:length(questionarray)%answers 1127 answerst=questionarray{nline}; 1128 switch key 1129 case 1% for questions 1130 fprintf(fout,':%s\n',answerst(2:end)); 1131 case 2% for key 1132 fprintf(fout,':%s\n',answerst); 1133 end %switch Key 1134

Page 22: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

end%for nline=2:length(questionarray) 1135 fprintf(fout,'%s\n','</div>');%End page-break-avoid 1136 end%for nques=1:length(renderedcrs(:,ntest))%=Nques 1137 fprintf(fout,'%s\n','{{pagebreak}}'); 1138 end%for key = 1:2 1139 %end%for ntest=2:Ntest 1140 %Studyguide only: 1141 savepwd=pwd; 1142 cd(fullfile(Zroot,'courses',coursename)); 1143 load('wikitableraw','wikitableraw'); 1144 cd(savepwd); 1145 wikitable2print = Cellarray2wikitable(wikitableraw); 1146 fprintf(fout,'%s\n','===Index: Studyguide to tests==='); 1147 for row = 1:length(wikitable2print) 1148 fprintf(fout,'%s\n',wikitable2print{row}); 1149 end%for row = 1:length(wikitable2print) 1150 fprintf(fout,'%s\n','{{reflist}}'); 1151 fclose(fout); 1152 end%function Printstudypdf 1153 function Print2versions(Nvers,outputfilename,listquizname, 1154 renderedcrs,... 1155 coursename, listattributes) 1156 %%PRINT2versions prints 2 versions 1157 %The textfile studypdf.txt will be reopenned for the guide/attrib. 1158 fprintf('\n%i-Printstudypdf calls Pickquestion=PC:',MFileLineNr()); 1159 fout = fopen('print2versions.txt','w+'); 1160 cd(fullfile(Zroot,'courses',coursename,'output',outputfilename)); 1161 ts='{{DISPLAYTITLE:<span style="font-size:50%">Quizbank/Test</span>}}'; 1162 fprintf(fout,'%s\n\n',ts); 1163 ts='<span style="font-size: 16pt; font-family:Courier;">%s</span>\n\n'; 1164 fprintf(fout,ts,outputfilename); 1165 ts='This identifier represents a unique rendition of the course'; 1166 ts=[ts,' ''''%s''''.']; 1167 fprintf(fout,ts, coursename); 1168 ts=' It contains %i versions that are identical except for numerical'; 1169 ts=[ts, ' values and order of questions and answers in test.']; 1170 fprintf(fout,ts,Nvers); 1171 fprintf(fout,' For more information visit [[Quizbank]].\n'); 1172 fprintf(fout,'\n __TOC__\n{{pagebreak}}\n'); 1173 for ntest=2:size(renderedcrs,2)% 1174 1175 for nvers=1:Nvers 1176 for key = 1:2 %key=1 for questions, =2 for key 1177 testname=listattributes{1,ntest}; 1178 switch key 1179 case 1% for questions 1180 fprintf(fout,'===%s:%s:V%i===\n',... 1181 coursename,testname,nvers); 1182 ts='<div style="text-align: right; direction: ltr;'; 1183 ts = [ts,... 1184 ' margin-left: 1em;"><small>%s</small></div> \n']; 1185 fprintf(fout,ts,outputfilename); 1186 case 2% for key 1187 fprintf(fout,'====KEY:%s:%s:V%i====\n',... 1188

Page 23: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

coursename,testname,nvers); 1189 fprintf(fout,'<small>%s</small>\n',outputfilename); 1190 end %switch Key 1191 Nques=length(find(~cellfun(@isempty,renderedcrs(:,ntest)))); 1192 for nques=1:Nques%=Nques 1193 fprintf(fout,'%s\n',...%Start page-break-avoid 1194 '<div style="page-break-inside:avoid;">'); 1195 questionarray=Pickquestion(0,renderedcrs{nques,ntest}); 1196 questext=questionarray{1}; 1197 fprintf(fout,'%i) %s\n',nques,questext(2:end-1));%question 1198 for nline=2:length(questionarray)%answers 1199 answerst=questionarray{nline}; 1200 switch key 1201 case 1% for questions 1202 fprintf(fout,':%s\n',answerst(2:end)); 1203 case 2% for key 1204 fprintf(fout,':%s\n',answerst); 1205 end %switch Key 1206 end%for nline=2:length(questionarray) 1207 fprintf(fout,'%s\n','</div>');%End page-break-avoid 1208 end%for nques=1:length(renderedcrs(:,ntest))%=Nques 1209 fprintf(fout,'%s\n','{{pagebreak}}'); 1210 end%for key = 1:2 1211 end%for nvers=1:Nvers 1212 end%for ntest=2:Ntest 1213 1214 end%function Printstudypdf 1215 1216 1217 ==foldersizesthisfolder== 1218 1219 1220 function foldersizesthisfolder 1221 homepath=pwd; 1222 rootpath=homepath; 1223 fileshere = dir(); 1224 N=size(fileshere,1); 1225 nfiles=0; 1226 fileinventory{1,1}='filename'; 1227 fileinventory{1,2}='kilobytes'; 1228 totalsize=0; 1229 for n = 1:N 1230 afile = fileshere(n).name; 1231 if ~strcmp('..',afile) && ~strcmp('.',afile); 1232 nfiles=nfiles+1; 1233 fileinventory{nfiles+1,1}=afile; %list of quiznames 1234 totalsize = totalsize + dirsize(fullfile(rootpath,afile)) ; 1235 fileinventory{nfiles+1,2}=round(dirsize(fullfile(rootpath,afile))/1000); 1236 end 1237 end 1238 fileinventory{nfiles+3,1}='total'; 1239 fileinventory{nfiles+3,2}=round(totalsize/1000); 1240 fileinventory{nfiles+4,1} = homepath; 1241 xlswrite('matlabInventory',fileinventory); 1242

Page 24: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

1243 function x = dirsize(path) 1244 s = dir(path); 1245 name = {s.name}; 1246 isdir = [s.isdir] & ~strcmp(name,'.') & ~strcmp(name,'..'); 1247 this_size = sum([s(~isdir).bytes]); 1248 sub_f_size = 0; 1249 if(~all(isdir == 0)) 1250 subfolder = strcat(path, filesep(), name(isdir)); 1251 sub_f_size = sum([cellfun(@dirsize, subfolder)]); 1252 end 1253 x = this_size + sub_f_size; 1254 end % dirsize 1255 end 1256 1257 ==printout== 1258 1259 clear all; clc; close all; 1260 documax=10; 1261 addpath([pwd, '\functions'],'-frozen'); 1262 mkdir('printouts/functions'); 1263 flist = dir('*.m'); 1264 for n=1:length(flist)%Create textfiles for functions in main folder 1265 [fp,fn,fe] = fileparts(flist(n).name); 1266 locfile = flist(n).name; 1267 path2printouts = fullfile(Zroot,'journals','printouts\'); 1268 destfile=[path2printouts fn '.txt']; 1269 copyfile(locfile,destfile); 1270 end 1271 cd('functions'); 1272 flist = dir('*.m'); 1273 for n=1:length(flist) %Create textfiles for function folder 1274 [fp,fn,fe] = fileparts(flist(n).name); 1275 locfile = flist(n).name; 1276 path2printouts = fullfile(Zroot,'journals','printouts','functions\'); 1277 destfile=[path2printouts fn '.txt']; 1278 copyfile(locfile,destfile); 1279 end 1280 %Make textfile and write first datstr ID line 1281 cd(fullfile(Zroot,'journals','printouts')); 1282 fout=fopen('..\wiki_inventory.txt','w+'); 1283 fprintf(fout,'%s\n',datestr(now,'yyyymmddTHHMMSS')); 1284 1285 %main%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1286 flist = dir('*.txt');%Import all text files 1287 for ntxt=1:length(flist); 1288 [fp,fn,fe] = fileparts(flist(ntxt).name); 1289 fprintf('test %s\n',fn); 1290 fprintf(fout,'\n==%s==\n\n',fn) 1291 textfile = flist(ntxt).name; 1292 fin=fopen(textfile,'r');%start function 1293 tempcell=textscan(fin,'%s','Delimiter','\n');%creates 1x1 cell 1294 tempcell=tempcell{1};%creates a 1xNline cell 1295 for nline=1:length(tempcell) 1296

Page 25: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

fprintf(fout,'%s\n',tempcell{nline}); 1297 end%for nline=1:length(tempcell) 1298 fclose(fin);%start function 1299 end%for ntxt=1:length(flist);%main folder 1300 fprintf(fout,'/n/n THESE FUNCTIONS ARE IN THE FUNCTIONS DIRECTORY\n\n'); 1301 %functions%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1302 cd(fullfile(Zroot,'journals','printouts','functions')); 1303 flist = dir('*.txt');%Import all text files 1304 for ntxt=1:length(flist);%functions folder 1305 [fp,fn,fe] = fileparts(flist(ntxt).name); 1306 textfile = flist(ntxt).name; 1307 fprintf(fout,'\n===%s===\n\n',fn);%demoted to subheader 1308 1309 fin=fopen(textfile,'r');%start function 1310 tempcell=textscan(fin,'%s','Delimiter','\n');%creates 1x1 cell 1311 tempcell=tempcell{1};%creates a 1xNline cell 1312 for nline=1:length(tempcell) 1313 fprintf(fout,'%s\n',tempcell{nline}); 1314 end%for nline=1:length(tempcell) 1315 fprintf(fout,'</nowiki></source>\n'); 1316 fclose(fin);%start function 1317 1318 end%for ntxt=1:length(flist);%main folder 1319 %%%%%%%%%%%%%%close output%%%%%%%%%% 1320 fclose(fout); 1321 cd(fullfile(Zroot,'journals')); 1322 helpdlg('See wiki_inventory.txt in journals folder'); 1323 1324 1325 /n/n THESE FUNCTIONS ARE IN THE FUNCTIONS DIRECTORY 1326 1327 1328 ===Agetvar=== 1329 1330 function value = Agetvar( tempvar ) 1331 %AGETVAR renturns variables used by all the functions 1332 % Detailed explanation goes here 1333 switch tempvar 1334 case 'checkroot' 1335 value ='C:\Program Files\MATLAB\qzbnk1606'; 1336 case 'coursename' 1337 value='phc'; 1338 case 'courselist' 1339 value = {'q_iz','l_nk','f_st','N_q','S_G','moc',... 1340 'phc','pht','ast','hwt','all'}; 1341 case 'Numbertests' 1342 value=6; 1343 case 'Nvers' 1344 value=2; 1345 end %switch 1346 end% Agetvar 1347 1348 </nowiki></source> 1349 1350

Page 26: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

===Bnkfoldersizes=== 1351 1352 1353 function Bnkfoldersizes 1354 %%BNKFOLDERSIZES places excel spreadsheet in bnkmat 1355 cd(fullfile(Zroot,'bank')); 1356 temphome =pwd; 1357 rootpath=temphome; 1358 fileshere = dir(); 1359 N=size(fileshere,1); 1360 nfiles=0; 1361 fileinventory{1,1}='filename'; 1362 fileinventory{1,2}='kilobytes'; 1363 totalsize=0; 1364 for n = 1:N 1365 afile = fileshere(n).name; 1366 if ~strcmp('..',afile) && ~strcmp('.',afile); 1367 nfiles=nfiles+1; 1368 fileinventory{nfiles+1,1}=afile; %list of quiznames 1369 totalsize = totalsize + dirsize(fullfile(rootpath,afile)) ; 1370 fileinventory{nfiles+1,2}=round(dirsize(fullfile(rootpath,afile))/1000); 1371 end 1372 end 1373 fileinventory{nfiles+3,1}='total'; 1374 fileinventory{nfiles+3,2}=round(totalsize/1000); 1375 fileinventory{nfiles+4,1} = temphome; 1376 cd(fullfile(Zroot,'bnkmat')); 1377 xlswrite('Matlabbnkfoldersizes',fileinventory); 1378 1379 1380 function x = dirsize(path) 1381 s = dir(path); 1382 name = {s.name}; 1383 isdir = [s.isdir] & ~strcmp(name,'.') & ~strcmp(name,'..'); 1384 this_size = sum([s(~isdir).bytes]); 1385 sub_f_size = 0; 1386 if(~all(isdir == 0)) 1387 subfolder = strcat(path, filesep(), name(isdir)); 1388 sub_f_size = sum([cellfun(@dirsize, subfolder)]); 1389 end 1390 x = this_size + sub_f_size; 1391 end % dirsize 1392 end 1393 </nowiki></source> 1394 1395 ===Cellarray2wikitable=== 1396 1397 %% Cellarray2wikitable 1398 function wikitable = Cellarray2wikitable(cellarray) 1399 %CELLARRAY2WIKITABLE reads a 2d cellarray and converts it to a wikitable 1400 %that is compatible with wikiversity. There are no header rows. 1401 [Nrow,Ncol]=size(cellarray); 1402 wikitable{1}='{| class="wikitable"'; 1403 for row = 1:Nrow %do the other rows 1404

Page 27: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

wikitable{2*row}='|-'; 1405 str=strcat('| ',num2str(cellarray{row,1})); 1406 for ncol=2:Ncol 1407 str = strcat(str, ' || ', num2str(cellarray{row,ncol})); 1408 end 1409 wikitable{2*row+1} =str; 1410 end 1411 wikitable{2*row+2} = '|}'; 1412 end%Cellarray2wikitable 1413 </nowiki></source> 1414 1415 ===Loadbanks=== 1416 1417 function [bnkquizname, bnkquesname,bnkclean]= Loadbanks(~) 1418 %%LOADBANKS loads [bnkquizname, bnkquesname,bnkclean] into directory 1419 bnkmat 1420 cd(fullfile(Zroot,'bnkmat')); 1421 load('bnkquizname.mat'); 1422 %bnkquizname columns: 1_quizname #2_questions 3_attribution 4_study 1423 gallery 1424 load('bnkquesname.mat'); 1425 %bnkquesname= question names (nothing else) in same rows as above 1426 load('bnkclean.mat'); 1427 %bnkclean= clean version of questions in same order as above 1428 %"clean version" = quesr1-ans1-...-ansnr-quesr1-ans1-... (r=#renditions) 1429 Nquiz=size(bnkquizname,1); 1430 NNques=0; 1431 for nquiz = 1:Nquiz 1432 NNques=NNques+bnkquizname{nquiz,2}; 1433 end 1434 fprintf('%i quizzes and %i questions in bank.\n',Nquiz,NNques); 1435 end%function Loadbanks 1436 1437 </nowiki></source> 1438 1439 ===MFileLineNr=== 1440 1441 function LineNr = MFileLineNr() 1442 % MFILELINENR returns the current linenumber 1443 Stack = dbstack; 1444 LineNr = Stack(2).line; % the line number of the calling function 1445 end 1446 1447 </nowiki></source> 1448 1449 ===Oldid=== 1450 1451 function oldid=Oldid(taddress) 1452 %OLDID takes a permalink and extracts the oldid 1453 %detailed summary goes here I 1454 strt=strfind(taddress,'oldid='); 1455 endt=size(taddress,2); 1456 oldid=taddress(strt+6:endt); 1457 end 1458

Page 28: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

1459 </nowiki></source> 1460 1461 ===Practiceprint=== 1462 1463 function Practiceprint(nameofcourse,outputfilename) 1464 %PRACTICEPRINT should not be used. 1465 %It creates statusAdmain.txt and wikistudyguide.txt for diagnostic 1466 %purposes. 1467 fprintf(... 1468 'Practiceprint prints statusAdmain.txt and wikistudyguide.tst to '); 1469 fprintf('%s\n',outputfilename); 1470 cd(fullfile(Zroot,'courses',nameofcourse,'smallbanks')); 1471 load('listquizname','listquizname');%quizname 1472 load('listattributes','listattributes');%attribuition 1473 load('listfirstques','listfirstques');%1st ques in quiz 1474 load('listNquesinqz','listNquesinqz');%#questions in a given quiz 1475 load('listNqzques2tst','listNqzques2tst');%#quiz questions going 2 test 1476 load('crsclean','crsclean');%Nquiz x Nques with cell arrays as elements 1477 load('crsquizname','crsquizname');%Nquiz x Nques with cell arrays as 1478 elements 1479 cd(fullfile(Zroot,'courses',nameofcourse,'output',outputfilename)); 1480 finstatus=fopen('statusAdmain.txt','w+'); 1481 finwiki=fopen('wikistudyguide.txt','w+'); 1482 fprintf(finstatus,'%s: statusAdmain.txt\n',outputfilename); 1483 fprintf(finwiki,'%s: wikistudyguide.txt\n',outputfilename); 1484 Ntests=size(listquizname,2);%is # tests in course (including S_G) 1485 disp(' Search *Option to print* below to print test to Command Window'); 1486 for ntests=1:Ntests 1487 testname=listquizname{1,ntests};%name of test 1488 Nqzintest=listquizname{2,ntests};% #quizzes used by this test 1489 fprintf(finstatus,'%s uses %i quizzes\n',testname,Nqzintest); 1490 fprintf(finwiki,'==%s==\n',testname); 1491 1492 for nqzintest=1:Nqzintest 1493 quizname=listquizname{nqzintest+2,ntests}; %name of quiz 1494 Nqzques2tst=listNqzques2tst{nqzintest+2,ntests}; 1495 %*Option to print* 1496 %fprintf('...nqzintest+3=%i,ntests=%i\n',nqzintest+3,ntests); 1497 Nquesinqz=listNquesinqz{2,ntests}; %#questions in quiz 1498 fprintf(finstatus,'%i/%i from %s\n',Nqzques2tst, Nquesinqz,quizname); 1499 fprintf(finwiki,'===%s===\n',quizname); 1500 fprintf(finwiki,'<quiz display=''simple''>\n'); 1501 %% Now we need a for loop to print each question for wikistudyguide 1502 for nquesinqz=1:Nqzques2tst 1503 %fprintf('....ntests=%i; nquesinz=%i; Nquesinqz=%i\n'... 1504 % ,ntests,nquesinqz,Nquesinqz);%*Option to print* 1505 crsquizindex= find(strcmp(crsquizname(:,1),quizname)); 1506 questionstr = crsclean{crsquizindex,nquesinqz}; 1507 for quesline=1:size(questionstr,2) 1508 line2print =questionstr{1,quesline}; 1509 %fprintf('%s\n',line2print);%Option to print 1510 fprintf(finwiki,'%s\n',line2print); 1511 end%for quesline=1:... 1512

Page 29: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

fprintf(finwiki,'\n'); 1513 end%for nquesinqz=1:size(questionstr,2) 1514 fprintf(finwiki,'</quiz>\n'); 1515 end%nquesinqz=1:Nqusinqz 1516 end%nqzintest=1:Nqzintest 1517 fclose(finstatus); 1518 fclose(finwiki); 1519 % end create 'statusAdmain.txt 1520 1521 end%function practiceprint 1522 </nowiki></source> 1523 1524 ===Readwikitext=== 1525 1526 function [quescell] = Readwikitext( quescellraw ) 1527 %% reads a raw question and removes all but the question and answers 1528 m = 1;%m is the number of elements in the cleaned question. 1529 for n = 1:size(quescellraw,1); 1530 tstring=quescellraw{n}; 1531 if size(tstring,2)>5 && strcmp(tstring(1:5),'{<!--') 1532 quescell{m}=tstring;%Here the element was a question 1533 m=m+1; 1534 end 1535 if size(quescellraw{n},2)>1 && strcmp(tstring(1),'+') 1536 quescell{m}=quescellraw{n}; 1537 m=m+1; 1538 end; 1539 if size(tstring,2)>1 && strcmp(tstring(1),'-') 1540 quescell{m}=tstring; 1541 m=m+1; 1542 end; 1543 end 1544 end 1545 1546 </nowiki></source> 1547 1548 ===Textfile2cellarray=== 1549 1550 function [ textarray ] =Textfile2cellarray( filetoread ) 1551 %converts a textfile to a cellarray 1552 1553 fin = fopen(filetoread,'r'); 1554 tline = fgetl(fin); 1555 textarray = cell(0,1); 1556 while ischar(tline); 1557 textarray{end+1,1} = tline; 1558 tline = fgetl(fin); 1559 end 1560 fclose(fin); 1561 end 1562 1563 </nowiki></source> 1564 1565 ===Verifyroot=== 1566

Page 30: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

1567 1568 function Verifyroot(rootshouldbe) 1569 %VERIFYROOT checks that the course has not been renewed. 1570 %This renewal occurs when to name of the folder that holds the quizbank 1571 is 1572 %changed, or perhaps if the quisbank is moved to another computer. the 1573 two 1574 %prior functions Aa* and Ab* don't yet have this feature. 1575 checkroot =pwd;% 1576 fprintf('Verifyroot: %s = %s \n',checkroot,rootshouldbe); %MUST UPGRADE 1577 occasionally 1578 if ~strcmp(checkroot,rootshouldbe); 1579 beep;pause(.5);beep;pause(.5);beep;pause(.5);beep;pause(.5); 1580 Warnme('x','URGENT: UPGRADE PATH2ROOT !!!!!!!!!!!') 1581 end 1582 end%Verifyroot 1583 </nowiki></source> 1584 1585 ===Warnme=== 1586 1587 function [ ] = Warnme(urgency,message) 1588 %WARNINGDIALOG warns user before prceeding 1589 % urgency states: 1590 % 'noturgent' = do not offer option of exiting 1591 % 'nowarning' = do not warn 1592 % 'x' (or anything else) = warn with option of exiting 1593 if strcmp(urgency,'nowarning') 1594 return 1595 end; 1596 if strcmp(urgency,'noturgent') 1597 f=warndlg(message, 'Note:'); 1598 drawnow 1599 waitfor(f); 1600 return 1601 end 1602 if strcmp('Yes',questdlg([message,' Exit now?'])) 1603 disp('message'); 1604 error('Terminated by Warnme'); 1605 end 1606 end 1607 1608 1609 1610 1611 </nowiki></source> 1612 1613 ===Writecell2txt=== 1614 1615 function Writecell2txt(file2open,what2print) 1616 %UNTITLED Writes a 1-d cell array to a text file 1617 %file2open is a filename, not an address. You need to cd(change 1618 directory) 1619 %before calling gunction. what2print is a 1-d cell array. Don't forget 1620

Page 31: function Aamainbankmaker - upload.wikimedia.org · 174 %This code opens coursemaker.xls in the courses folder, and after that 175 excel file 176 % ... has been upgraded, creates (coursename)_unfinished.xls

%that literals are usually accomplished by doubling %% for percent \\ for 1621 %backslash, I think. 1622 Nlines=length(what2print); 1623 fout=fopen(file2open,'w+'); 1624 for n=1:Nlines 1625 fprintf(fout,'%s\n',what2print{n}); 1626 end 1627 fclose(fout); 1628 end 1629 </nowiki></source> 1630 1631 ===Zroot=== 1632 1633 function [ root ] = Zroot(~ ) 1634 %zroot returns the root directory (must change!) 1635 % Must be changed everytime the code is rebuilt 1636 root = 'C:\Program Files\MATLAB\qzbnk1606'; 1637 end 1638 1639 </nowiki></source> 1640