Simplification rule not being applied properly - symbolic-math

I'm trying to use Dirac Bra-Ket notation in Maxima using the code from here http://raoul.koalatux.ch/sites/ladderoperator/ladder_operator.html
declare(bra, nonscalar);
declare(ket, nonscalar);
dotscrules:true;
matchdeclare(m,lambda([t],featurep(t,integer)));
matchdeclare(n,lambda([t],featurep(t,integer)));
tellsimp(bra(m).ket(n), kron_delta(m,n));
For most expressions it works:
bra(0) . ket(0);
ket(1) . bra(0) . ket(0);
bra(1) . ket(1) . bra(0) . ket(0);
all simplify correctly, but
bra(1) . ket(1) . bra(0);
fails to simplify to bra(0). How can I get Maxima to simplify this case?

I think you can start with this:
declare(bra, nonscalar);
declare(ket, nonscalar);
dotscrules:true;
matchdeclare(m,lambda([t],featurep(t,integer)));
matchdeclare(n,lambda([t],featurep(t,integer)));
tellsimp(bra(m).ket(n), kron_delta(m,n));
simp:false;
matchdeclare(aa, true);
matchdeclare(bb, true);
matchdeclare(cc, true);
tellsimp (aa.(bb.cc),(aa.bb).cc);
simp:true;
/* Tests */
bra(0) . ket(0);
ket(1) . bra(0) . ket(0);
bra(1) . ket(1) . bra(0) . ket(0);
bra(1) . ket(1) . bra(0);
ket(1) . bra(1) . ket(1);

Related

SAS dynamic arrays with changing start and stop values

I am working on a longitudinal dataset where each row is a subject and each column is an event. There are no limits to the number of events that a subject can have, but the events are coded in a few ways. For the sake of this example let's say one of the coded ways is binary (good, bad).
I am trying to find
1) all of the event strings consisting of 3 or more events (with no count limit) that are within 24 hours of one another (on the same subject) from start to finish. There also may be multiple successes of this criteria within the same subject.
2) for each of the successes (string of 3 or more events within 24 hours) I need to count the number of good events.
I've included code that generates similar data to mine. For now I'm simplifying to 26 observations but I have up to 42 for a single subject.
data examp;
informat subject 4. epdt1 epdt2 epdt3 epdt4 epdt5 epdt6 epdt7 epdt8 epdt9 epdt10 epdt11 epdt12 epdt13 epdt14 epdt15 epdt16 epdt17 epdt18 epdt19 epdt20 epdt21 epdt22 epdt23 epdt24 epdt25 epdt26 datetime20.
good1 good2 good3 good4 good5 good6 good7 good8 good9 good10 good11 good12 good13 good14 good15 good16 good17 good18 good19 good20 good21 good22 good23 good24 good25 good26 1.;
input subject epdt1 epdt2 epdt3 epdt4 epdt5 epdt6 epdt7 epdt8 epdt9 epdt10 epdt11 epdt12 epdt13 epdt14 epdt15 epdt16 epdt17 epdt18 epdt19 epdt20 epdt21 epdt22 epdt23 epdt24 epdt25 epdt26
good1 good2 good3 good4 good5 good6 good7 good8 good9 good10 good11 good12 good13 good14 good15 good16 good17 good18 good19 good20 good21 good22 good23 good24 good25 good26;
format subject: 4. epdt: datetime20. good: 1.;
datalines;
3098 . . 25JUL1998:01:46:27 25JUL1998:02:16:05 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3021 13JAN1999:17:31:37 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1982 01FEB1998:02:29:01 12APR1999:19:49:00 03JUN2018:21:00:00 13AUG1999:13:39:00 . . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . . . . .
1093 11APR2015:16:10:57 30AUG2015:00:52:28 14SEP2015:08:24:25 09MAY1999:00:28:37 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4089 29JUN1998:05:18:34 23JUL1998:18:31:11 07FEB1999:05:25:45 07FEB1999:05:29:26 07FEB1999:05:32:04 07FEB1999:05:34:05 14FEB1999:18:00:13 14FEB1999:18:01:02 14FEB1999:18:03:24 14FEB1999:18:05:55 14FEB1999:18:16:45 14FEB1999:18:19:04 14FEB1999:18:31:57 14FEB1999:18:35:22 28JUL1998:18:32:02 31DEC1998:00:22:33 . . . . . . . . 1 1 1 1 1 1 1 1 1 1 1 . 1 . 1 . . . . . . . . . .
3055 18FEB1998:11:34:00 14JUL1998:01:20:34 13OCT1998:10:49:08 30OCT1998:18:14:58 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1239 07MAR1998:06:02:18 01JUN1998:08:18:20 23JUN1998:07:52:11 04JUL1998:08:47:04 29JUL1998:23:16:41 29JUL1998:23:30:03 29JUL1998:23:42:56 30JUL1998:00:08:03 30JUL1998:00:12:30 30JUL1998:00:14:58 30JUL1998:00:36:00 30JUL1998:00:38:33 30JUL1998:00:57:56 30JUL1998:01:01:03 30JUL1998:01:06:10 30JUL1998:01:16:50 30JUL1998:01:24:19 30JUL1998:01:32:30 30JUL1998:01:42:55 30JUL1998:01:50:24 30JUL1998:02:08:46 30JUL1998:02:20:18 30JUL1998:02:22:08 30JUL1998:02:28:52 30JUL1998:02:31:29 30JUL1998:02:51:29 . . 1 . 1 1 1 1 1 1 1 . 1 1 1 1 1 1 1 1 1 1 1 1 . 1
9834 10JUL1999:20:22:24 14JUL1999:00:52:02 14JUL1999:17:02:38 14JUL1999:17:30:06 21FEB2000:12:41:34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
run;
proc sort data=examp; by subject;
data epwide_dt1;
format apppair $7000.;
set examp;
by subject;
%macro loops;
array eptm (*)epdt1-epdt26; array apptm (*) good1-good26;
*********using the starting value for identifying pairs;
*******trimmed then for the sake of making the macro work;
%do start=1 %to 26;
%do stop=3 %to 26;
%if &start.<&stop. %then %do ;
/***********to figure out if the difference between the pairs of times are 24 hours;*/
tbtw=eptm[&stop.]-eptm[&start.];
/* *********number of points between them;*/
diff=(&stop.)- (&start.);
*******calculate the summaries between all episodes from start to stop;
array appr&start.&stop. (*) ap&start.-ap&stop.;
array stmct&start.&stop.(*) st&start.-st&stop.;
%do i=&start. %to &stop.;
******calculate the number of appropriate episodes;
if apptm[&i] ne . then appr&start.&stop.[&i]=apptm[&i];
else appr&start.&stop.[&i]=0;
totapp=sum(of appr&start.&stop.(*));
if totapp=. then totapp=0;
****after you calculate the total value dump the array before the next itteration;
/*call missing(of appr&start.&stop.{*});*/
if (eptm[&start.] ne . and eptm[&stop.] ne . and diff>=2 and .<tbtw<86400 and totapp>1 ) then do;
appPair=catx(" ",apppair,"(",strip(put(&start., 3.)),"-",strip(put(&stop.,3.)),":", strip(put(totapp,3.)),"Good)");
end;
%end;
%end;
%end;
%end;
%mend;
%loops ;
run;
The error message below is what's resulting:
ERROR: Array subscript out of range at line 1 column 2.
apppair= subject=1093 epdt1=11APR2015:16:10:57 epdt2=30AUG2015:00:52:28 epdt3=14SEP2015:08:24:25
epdt4=09MAY1999:00:28:37 epdt5=. epdt6=. epdt7=. epdt8=. epdt9=. epdt10=. epdt11=. epdt12=. epdt13=. epdt14=. epdt15=.
epdt16=. epdt17=. epdt18=. epdt19=. epdt20=. epdt21=. epdt22=. epdt23=. epdt24=. epdt25=. epdt26=. good1=. good2=.
good3=. good4=. good5=. good6=. good7=. good8=. good9=. good10=. good11=. good12=. good13=. good14=. good15=. good16=.
good17=. good18=. good19=. good20=. good21=. good22=. good23=. good24=. good25=. good26=. FIRST.subject=1
LAST.subject=1 tbtw=1323117 diff=1 ap1=0 ap2=0 ap3=0 st1=. st2=. st3=. totapp=0 ap4=0 st4=. ap5=0 st5=. ap6=0 st6=.
ap7=0 st7=. ap8=0 st8=. ap9=0 st9=. ap10=0 st10=. ap11=0 st11=. ap12=0 st12=. ap13=0 st13=. ap14=0 st14=. ap15=0
st15=. ap16=0 st16=. ap17=0 st17=. ap18=0 st18=. ap19=0 st19=. ap20=0 st20=. ap21=0 st21=. ap22=0 st22=. ap23=0 st23=.
ap24=0 st24=. ap25=0 st25=. ap26=0 st26=. _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 35:20 1 at 57:20 1 at 83:20 1 at 113:20 1 at 147:20 1 at 185:20 1 at 227:20
1 at 273:20 1 at 323:20 1 at 377:20 1 at 435:20 1 at 497:20 1 at 563:20 1 at 633:20
1 at 707:20 1 at 785:20 1 at 867:20 1 at 953:20 1 at 1043:20 1 at 1137:20 1 at 1235:20
1 at 1337:20
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 2 observations read from the data set WORK.EXAMP.
WARNING: The data set WORK.EPWIDE_DT1 may be incomplete. When this step was stopped there were 0 observations and
109 variables.
WARNING: Data set WORK.EPWIDE_DT1 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 2.35 seconds
cpu time 2.13 seconds
Thanks in advance for any suggestions!
I am not sure I quite understand your full problem. But consider that if you want to sum the subset of values in an array from index START to index STOP you just use a DO loop.
For example to sum X10 to X20 you could use code like this:
array x (100) ;
start=10;
stop=20;
do i=start to stop;
total=sum(total,0,x(i));
end;
So you should be able to solve this without macro code. Which should make debugging much easier.
I finally got it working!!! I used #Tom 's suggestion to remove the need for creating a sub array of each of the pairs, as it was causing ALOT of problems. I also streamlined the output and asked it to output each pair that is "Good" so that I will be able to evaluate them easier. Previously it was creating appPair (my evaluation summary for each iteration within the start stop loop producing a bunch of extraneous output).
data epwide_dt1;
set examp;
by subject;
if first.subject then totapp=0;
%macro loops;
array eptm (*)epdt1-epdt26;
array apptm (*) good1-good26;
*********using the starting value for identifying pairs;
%do start=1 %to 24;
%do stop=3 %to 26;
%if &start.<&stop. %then %do ;
totapp=0;
/***********to figure out if the difference between the pairs of times are 24 hours;*/
tbtw=eptm[&stop.]-eptm[&start.];
/* *********number of points between them;*/
diff=(&stop.)- (&start.);
%do i=&start. %to &stop.;
******calculate the number of good events;
totapp=sum(totapp, 0,apptm[&i]);
***output the summary on the pair that can be evaluated in the next step;
if &i=&stop. and (eptm[&start.] ne . and eptm[&stop.] ne . and diff>=2 and 0<tbtw<86400 and totapp>1 ) then do;
appPair=catx(" ","(",strip(put(&start., 3.)),"-",strip(put(&stop.,3.)),":", strip(put(totapp,3.)),"Good)");
output;
end;
%end;
%end;
%end;
%end;
%mend;
%loops ;
run;

inadvertent change of shared memory - c programming

I'm making a programme that uses shared memory, semaphore et message queue to create a board game where programs fight each others.
In my code I create the shared memory which functions well (it seems) and I put in it an int** map.
The problem is, between the map creation and after the return of the same function, the map change alone (I do not modify it). Can you explain me why please?
Here is a sample of my code:
int create_ressources(int *shmid, key_t *key,
player_t *player, board_t *map)
{
printf("%s\n", "--- Entrée dans fonction creat_ressources ---");
create_shared_memory(shmid, key);
create_map(map, shmid); // <- here the map has changed
print_board(map);
return (SUCCESS);
}
void create_shared_memory(int *shmid, const key_t *key)
{
(*shmid) = shmget((*key), SH_SIZE, SHM_W | SHM_R);
if ((*shmid) == -1)
(*shmid) = shmget((*key), SH_SIZE, IPC_CREAT | SHM_W | SHM_R);
if (!*shmid)
exit(ERROR);
}
void create_map(board_t *map, const int *shmid)
{
void *addr = NULL;
addr = shmat((*shmid), NULL, SHM_R | SHM_W);
map = (board_t*)addr;
print_board(map); // <- here the map is good
}
Here is the map when I just created and when it's good:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
And here is the same map just after the create_map function exit:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . 3 . 214252960 32767 1023324160 32686 214253192 32767 2 . 2053 . 1021207349 32686 . . 1835008 . 1833744 . 1833744 . .
. 5 . 3932160 . 3956736 . 3954464 . 3971488 . 1835008 . 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . 4096 . 1178 . . . 1023435112 32686 3 . . . 1021283966 32686 . . 32 . 1 . 1021226648 32686 1023438176 32686 32 . 47 1 10 . .
. 1023435112 32686 214252960 32767 1021225751 32686 2147479968 3 214252960 32767 1023324160 32686 1021206312 32686 -1 -1 1023434912 3 1021176224 32686 1021249988 32686 214252192 32767 1017297071 32686 . . 1021213293 32686 214253120 1 5636179 . 6 . 214252192 32767 95177 3 1023435072 32686 1023438176 32686 . . 2053 . 5636179
. 1 . 33261 . . . . . 1868984 . 4096 . 3656 . 1522236691 . 852133901 . 1515984691 . . . 1517241387 . 248361376 . . . . . . . . 3 4196129 . 1023435112 32686 . . 1023430720 32686 214253120 32767 . . 1021213735 32686 1
. . . 214253112 32767 . . . 1 1023438176 32686 . . 10 . 214253088 32767 214253104 32767 1023435112 32686 . . . . . . . . . . 1023438176 32686

PHPExcel drawing new lines when combining sheets

I'm combining about 20 excel sheets (user uploaded) using PHPExcel into a report. This is done by using this bit of code:
$filename = APP . 'docs' . DS . 'reports' . DS . $Workbooks[0]['Report']['company'] . '.' . $Workbooks[0]['Report']['report_name'] . '.' . $Workbooks[0]['Report']['extension'];
$blacklist = array('Company Organogram');
$MasterFile = $this->PhpExcel->createMasterFile($filename,$company . '.' . $title,$colour);
foreach($Workbooks as $Workbook) :
if(!in_array($Workbook['Report']['report_name'],$blacklist)) {
$file = APP . 'docs' . DS . 'reports' . DS . $Workbook['Report']['company'] . '.' . $Workbook['Report']['report_name'] . '.' . $Workbook['Report']['extension'];
$MasterFile = $this->PhpExcel->addExternalWorksheet($MasterFile,$file,$company . '.' . $title,$colour);
#unlink($file);
}
endforeach;
$this->PhpExcel->saveToDisk(APP . 'docs' . DS . 'reports' . DS . 'Weekly Reports for Week ' . (date('W') + 1) . '.xlsx',$MasterFile);
I'm working with CakePHP, so there is a helper. saveToDisk simply saves the file to the disc after which it is attached and sent to a mailing list.
All the above works fine. But I'm having issues where the combining process draws in extra lines. For instance, this:
becomes this:
How would I fix this? Is there something I should set so it doesn't draw in all the lines?

Export Excel file using xlsHelper

I am using xlsHelper of cakephp to export in excel format.It is working fine in all the major browser and opening file in all operating system except "mac" operating system?
May this help you..
<?php
$this->layout="";
$filename=strtotime("now");
header ("Expires: 0");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/vnd.ms-excel");
header ("Content-Disposition: attachment; filename=".$filename.".xls");
header ("Content-Description: Generated Report" );
// echo 'Number of Rows::'."\t" . count($test)."\n";
// echo "\n";
echo 'Id' . "\t" .
'EnrollmentId' . "\t" .
'IDS' . "\t" .
'sysreq' . "\t" .
'sysproc' . "\t" .
'Request' . "\t" .
'Response' . "\t" .
'Created' . "\n";
foreach($test as $val):
echo $val['abc']['id']. "\t" .
$val['xyz']['enrollment_id']. "\t" .
$val['bca']['IDS']. "\t" .
$val['mca']['_sysreq']. "\t" .
$val['car']['_sysproc']. "\t" .
$val['azx']['SYSBATCHNO']. "\t" .
$val['tyu']['MSGS']. "\t" .
$val['wer']['created']. "\n";
endforeach;
?>

Does CakePHP 2.0 still need $name declared in the model?

I was under the impression that we had to declare - public $name = 'ModelName'; in the model exclusively for PHP4. Now that cakephp no longer supports PHP4 I thought there no longer needs to be $name declaration in the model. The cookbook still has instructions to include it though: http://book.cakephp.org/2.0/en/models.html
The models work fine without it from what I see. What is it used for, and why do I need it?
Thanks!
It is just a leftover from the earlier cookbooks. See for example http://book.cakephp.org/2.0/en/models/model-attributes.html#name, it mentions PHP4 compatibility even though CakePHP 2.0 no longer works with PHP4.
So, to answer your question: no, you do not have to declare $name in your models.
you dont need need $name in any of your classes.
not even in 1.3 (who still uses php4 anyway^^), but especially not in 2.0.
I wrote an enhanced UpgradeShell which removes those unnecessary chunks from all class files:
http://cakephp.lighthouseapp.com/projects/42648/tickets/2117-improvements-for-20-upgrade-shell
but this new command I didnt yet add to the ticket patch.
I called the command "name"
/**
* Remove name (lib, controller, model, view, component, behavior, helper, fixture)
*
* #return void
*/
public function name() {
$libs = App::path('Lib');
$views = App::path('views');
$controllers = App::path('controllers');
$components = App::path('components');
$models = App::path('models');
$helpers = App::path('helpers');
$behaviors = App::path('behaviors');
$this->_paths = array_merge($libs, $views, $controllers, $components, $models, $helpers, $behaviors);
$this->_paths[] = TESTS . 'Fixture' . DS;
if (!empty($this->params['plugin'])) {
$pluginPath = App::pluginPath($this->params['plugin']);
$this->_paths = array(
$pluginPath . 'Lib' . DS,
$pluginPath . 'Controller' . DS,
$pluginPath . 'Controller' . DS . 'Component' .DS,
$pluginPath . 'View' . DS,
$pluginPath . 'View' . DS . 'Helper' . DS,
$pluginPath . 'Model' . DS,
$pluginPath . 'Model' . DS . 'Behavior' . DS,
$pluginPath . 'Test' . DS . 'Fixture' . DS,
$pluginPath . 'libs' . DS,
$pluginPath . 'controllers' . DS,
$pluginPath . 'controllers' . DS . 'components' .DS,
$pluginPath . 'views' . DS,
$pluginPath . 'views' . DS . 'helpers' .DS,
$pluginPath . 'models' . DS,
$pluginPath . 'models' . DS . 'behaviors' . DS,
$pluginPath . 'tests' . DS . 'fixtures' . DS,
);
}
$patterns = array(
array(
'remove var $name = ...;',
'/\bvar\s*\$name\s*=\s*(.*);/',
''
),
array(
'remove public $name = ...;',
'/\bpublic\s*\$name\s*=\s*(.*);/',
''
),
);
$this->_filesRegexpUpdate($patterns);
}

Resources