function[ninst nvars reactions rWells cWells] = write_file(wr,wc,species,init,reactions,rev_reactions,start,stop,increment)


fid=0;
while fid < 1 
      [fid, message] = fopen('temporary.txt', 'wt');
   if fid == -1
     disp('The temporary input file for the sim didn''t open');
   end
end
fprintf(fid, '[Reactions]\n');
[r,c] = size(reactions);
[r2,c2] = size(rev_reactions);
for row=1:r
    fprintf(fid, 'Rxn_%d:   %s [%d] \n', row, reactions{row,1}, reactions{row,2});
end
for row = 1:r2
    fprintf(fid, 'Rxn_%d:   %s [%d] [%d] \n', r+row, rev_reactions{row,1}, rev_reactions{row,2}, rev_reactions{row,3});
end
fprintf(fid, '\n[InitialValues]\n');
for num = 1:length(species)
    fprintf(fid, '%s=%e\n',species{num},init(wr,wc,num));
end
fprintf(fid, '\n[EvalInstants]\n');
fprintf(fid, '%d:%d+%d',start, stop, increment);
ninst = (stop - start)/increment + 1; 
[nvars x] = size(species);
[rWells cWells] = size(init(:,:,1));

fprintf(fid,'\n\n[HybridCVODESimulator:Parameters]');
fprintf(fid,'\nPartitionScheme = POPULATION');
fprintf(fid,'\nPopulationThreshold = 100');
fclose(fid);
