/* $Id: crmat.c,v 1.1 2013/03/29 19:11:44 tl Exp $ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef SOLARIS #include #include #endif #ifdef LINUX #include #endif #include "ctk.h" float crmat[MAXDETPOS + 1][MAXCRYSTALNO + 1][4][4]; /*--------------------------------------------------------------------------*/ int crmat_writeassigments () { /* declarations */ int detector_pos, crystal_num, i, j; int out, siz; char str[132]; FILE *fp; fp = fopen ("crmat_assign.h", "w"); /* generate a lot of assignment statements */ /* NOT elegant, but for now it will have to do */ for (detector_pos = 1; detector_pos <= MAXDETPOS; detector_pos++) for (crystal_num = 0; crystal_num <= MAXCRYSTALNO; crystal_num++) { /* translation in cm */ crmat[detector_pos][crystal_num][0][3] /= 10; crmat[detector_pos][crystal_num][1][3] /= 10; crmat[detector_pos][crystal_num][2][3] /= 10; for (i = 0; i <= 3; i++) for (j = 0; j <= 3; j++) fprintf (fp, " crmat[%i][%i][%i][%i]= %10.6f;\n", detector_pos, crystal_num, i, j, crmat[detector_pos][crystal_num][i][j]); }; fclose (fp); /* dump crmat binary */ #ifdef LINUX sprintf (str, "crmat.LINUX"); #endif #ifdef SOLARIS sprintf (str, "crmat.SOLARIS"); #endif out = open (str, O_WRONLY | O_CREAT | O_TRUNC, PMODE); if (out != 0) printf ("%s is open (output) binary format\n", str); else { printf ("could not open %s\n", str); exit (1); }; siz = write (out, (char *) crmat, sizeof (crmat)); close (out); /* done */ return (0); } /*--------------------------------------------------------------------------*/ int crmat_askIY () { /* function to run IY's tk_dat and extract the */ /* values it gives; very slow but that is OK. */ /* We only really run it once ever */ /* declarations */ int detector_pos, crystal_num, i, j; FILE *fp; float dummy; for (detector_pos = 1; detector_pos <= MAXDETPOS; detector_pos++) for (crystal_num = 0; crystal_num <= MAXCRYSTALNO; crystal_num++) { fp = fopen ("aaa.sh", "w"); fprintf (fp, "#!/bin/csh \n"); fprintf (fp, "./tk_dat << +\n"); fprintf (fp, "%i %i\n", detector_pos, crystal_num + 1); fprintf (fp, "+\n"); fclose (fp); system ("chmod +x aaa.sh"); system ("./aaa.sh > aaa.out"); system ("cat aaa.out"); fopen ("aaa.out", "r"); fscanf (fp, "%f", &dummy); fscanf (fp, "%f %f %f %f", &crmat[detector_pos][crystal_num][0][0], &crmat[detector_pos][crystal_num][0][1], &crmat[detector_pos][crystal_num][0][2], &crmat[detector_pos][crystal_num][0][3]); fscanf (fp, "%f %f %f %f", &crmat[detector_pos][crystal_num][1][0], &crmat[detector_pos][crystal_num][1][1], &crmat[detector_pos][crystal_num][1][2], &crmat[detector_pos][crystal_num][1][3]); fscanf (fp, "%f %f %f %f", &crmat[detector_pos][crystal_num][2][0], &crmat[detector_pos][crystal_num][2][1], &crmat[detector_pos][crystal_num][2][2], &crmat[detector_pos][crystal_num][2][3]); fscanf (fp, "%f %f %f %f", &crmat[detector_pos][crystal_num][3][0], &crmat[detector_pos][crystal_num][3][1], &crmat[detector_pos][crystal_num][3][2], &crmat[detector_pos][crystal_num][3][3]); fclose (fp); printf ("%i %i\n", detector_pos, crystal_num); for (i = 0; i <= 3; i++) { for (j = 0; j <= 3; j++) printf ("%9.5f ", crmat[detector_pos][crystal_num][i][j]); printf ("\n"); }; }; /* done */ return (0); } /*--------------------------------------------------------------------------*/ int main () { crmat_askIY (); crmat_writeassigments (); exit (0); }