simData () { fpConfig_t fp; /* Get a Page for the pixel data. */ page = smcGetPage (smc, TY_DATA, (im_nx*im_ny*(im_bitpix/8)), TRUE, TRUE); if (page == (smcPage_t *) NULL) { fprintf (stderr, "Error getting data page.\n"); return; } fp.xSize = im_nx; /* Set the fpConfig struct. */ fp.ySize = im_ny; fp.xStart = 0; fp.yStart = 0; fp.dataType = 1; smcSetFPConfig (page, &fp); smcSetWho (page, 2); /* Set the 'who' field */ smcSetExpID (page, 3.141592654); /* Set the 'expid' field */ smcSetObsetID (page, "3.14159"); /* Set the 'obsetid' field */ /* Create a raster in the shared area */ make_raster ((int *)smcGetPageData(page), im_nx, im_ny, color_mode++); /* Unlock and Detach from the page. */ smcUnlock (page); smcDetach (smc, page, FALSE); }
simMetaData () { fpConfig_t fp; mdConfig_t md; int i, nkeyw = 256; /* Get a Page for the metadata. */ page = smcGetPage (smc, TY_META, (80*nkeyw), TRUE, TRUE); if (page == (smcPage_t *) NULL) { fprintf (stderr, "Error getting metadata page.\n"); return; } md.metaType = 1; /* Set the mdConfig struct. */ md.numFields = nkeyw; smcSetMDConfig (page, &md); fp.xSize = im_nx; /* Set the fpConfig struct. */ fp.ySize = im_ny; fp.xStart = 0; fp.yStart = 0; fp.dataType = 1; smcSetFPConfig (page, &fp); smcSetWho (page, 2); /* Set the 'who' field */ smcSetExpID (page, 3.141592654); /* Set the 'expid' field */ smcSetObsetID (page, "3.14159"); /* Set the 'obsetid' field */ /* Create a dummy header in the shared area */ make_header ((char *)smcGetPageData(page), nkeyw); /* Unlock and Detach from the page. */ smcUnlock (page); smcDetach (smc, page, FALSE); }
main (int argc, char **argv) { char c, fname[64], buf[64], resp[32], val[12], config[128]; int i, j, debug=0, clear = 1, nimages=1, delay=0, interactive=1; int nsegs, pagenum, nvals, imnum=0; void *data; char *cdata, *cp; int *idata, *ip; short *sdata, *sp; double stime, etime; /* Process command-line arguments. */ strcpy (fname, "\0"); for (i=1; i < argc; i++) { if (strncmp (argv[i], "-cache", 2) == 0) { strcpy (fname, argv[++i]); } else if (strncmp (argv[i], "-delay", 2) == 0) { delay = atoi (argv[++i]); } else if (strncmp (argv[i], "-x", 2) == 0) { debug++; } else if (strncmp (argv[i], "-nimages", 2) == 0) { nimages = atoi (argv[++i]); } else if (strncmp (argv[i], "-keep", 2) == 0) { clear = 0; } else if (strncmp (argv[i], "-interactive", 2) == 0) { interactive = 1; } else if (strncmp (argv[i], "-batch", 2) == 0) { interactive = 0; } else if (strncmp (argv[i], "-help", 2) == 0) { printHelp (); exit (0); } else printf ("Unrecognized option: %s\n", argv[i]); } /* Initialize the config string. */ sprintf (config, "debug=%d,cache_file=%s", debug, fname); /* Open/Attach to the cache. */ printf ("Opening cache....\n"); if ((smc = smcOpen (config)) == (smCache_t *)NULL) fprintf (stderr, "Error opening cache, invalid file?.\n"); /* Simulate the readout sequence> */ for (i=1; i <= nimages; i++) { printf ("Generating image %d ....", i); simMetaData (); /* pre-readout header */ simData (); /* pixel data */ simMetaData (); /* post-readout header */ printf ("done.\n"); sleep (delay); /* pause requested time */ } /* Once we're done, see if we want drop into a command mode. */ if (interactive) { imnum = nimages; /* Command loop */ printf ("%s (%d)> ", argv[0], getpid()); while ((c = getchar())) { switch (c) { case 'n': /* new sequence */ stime = smUtilTime(); nimages = optargi (); nimages = max (1, nimages); for (i=0; i < nimages; i++) { printf ("Generating readout %d (%d/%d) ....", imnum++, smc->npages, smc->top); simMetaData (); simData (); simMetaData (); printf ("done.\n"); } etime = smUtilTime(); printf ("Created %d images in %f sec\n",nimages,(etime-stime)); break; case 'd': /* detach from segment */ smcListPages (smc, -1); printf ("which page? "); scanf ("%d", &pagenum); page = &smc->pdata[pagenum]; if (page->ac_locked) printf ("Page is locked for access.\n"); else smcDetach (smc, page, FALSE); break; case 'l': /* list segments */ nsegs = optargi (); if (nsegs < 0 && smc->npages == 0) { printf ("No pages yet allocated, showing first 8.\n"); smcListPages (smc, 8); } else smcListPages (smc, nsegs); break; case 'i': /* initialize cache */ case 'I': if (smc) { int stat; printf ("Initializing cache....\n"); stat = smcInitialize (smc); if (stat && debug) smcPrintCacheInfo (smc, "After Initialize:"); } else printf ("Cannot initialize() before open()\n"); break; case '\n': printf ("%s (%d)> ", argv[0], getpid()); continue; case 'p': /* print cache info */ if (smc) { smcPrintCacheInfo (smc, (char *)NULL); smcPrintCfgInfo (&smc->sysConfig, (char *)NULL); } else printf ("Null cache ptr, try opening a cache first.\n"); break; case 'q': /* quit */ case 'C': /* close cache */ printf ("free cache? "); scanf ("%s", val); smc = smcClose (smc, is_true(val[0])); printf ("After smcClose(): smc = 0x%x\n", smc); break; case 'g': /* print segment data */ smcListPages (smc, -1); printf ("which page? "); scanf ("%d", &pagenum); page = &smc->pdata[pagenum]; if (page->ac_locked) printf ("Page is locked for access.\n"); else { printf ("how many lines? "); scanf ("%d", &nvals); if (page->type == TY_META) { cdata = (char *)smcGetPageData (page); for (cp=cdata, i=0; i < nvals; i++) { printf ("%.80s", cp); cp += 80; } } else { idata = (int *)smcGetPageData (page); for (i=0; i < nvals; i++) printf ("(%d) %s", idata[i],(i&&(i%4==0))?"\n":""); } printf ("\n"); } break; default: printf ("Unknown command: '%c'\n", c); } if (c == 'q' || c == 'C') break; } } printf ("Done\n"); if (smc && !interactive) smcClose (smc, clear); }
/* rtdDisplayPixels -- Display the pixels of a SMC page. */ void rtdDisplayPixels (smcPage_t *page) { int i, nx=0, ny=0, xs=0, ys=0, bitpix=32; int fb_w, fb_h, fbconfig, nf, nb, rowlen, lx, ly; XLONG *pix, *dpix, *ip, *op; float z1, z2; char *det = NULL; static XLONG *dpix_buf=(XLONG *)NULL, sv_nx=0, sv_ny=0, first_time=1; fpConfig_t *fp; pixStat stats; if (!disp_enable) /* sanity checks */ return; if (!cdl) return; fp = smcGetFPConfig (page); /* get the focal plane config */ nx = fp->xSize; ny = fp->ySize; xs = fp->xStart; ys = fp->yStart; /* Get the pixel pointer and raster dimensions. Allocate space for a ** buffer we'll reuse as long as the size remains the same to cut down ** on memory allocation in a long-running process, */ pix = (XLONG *) smcGetPageData (page); if ((nx*ny) != (sv_nx*sv_ny)) { if (dpix_buf) free ((XLONG *)dpix_buf); sv_nx = nx; sv_ny = ny; first_time = 1; } if (first_time) { dpix = dpix_buf = (XLONG *) calloc ((nx*ny), sizeof (XLONG)); first_time = 0; } else dpix = (XLONG *)dpix_buf; /* Select a frame buffer large enough for the image. */ cdl_selectFB (cdl, (2*nx+3*DISP_GAP), (2*ny+3*DISP_GAP), &fbconfig, &fb_w, &fb_h, &nf, 1); if (verbose && debug) { printf ("Using Frame Buffer #%d: %d x %d (%d frames)\n", fbconfig, fb_w, fb_h, nf); } /* Now copy the page pixels to the display raster. We will trim the ** the 64 reference pixels at the end of each row if needed and reset ** our origin based on the location of the chip. For NEWFIRM the 4 ** detectors are assumed to tbe layed out as follows: ** ** +----+----+ where A1,A2 is Array 1 or 2 ** | A2 | A1 | Pa is Pan A ** | Pb | Pb | Pb is Pan B ** +----+----+ ** | A1 | A2 | The SMC page contains the data such that the ** | Pa | Pa | starting address represents the corners of ** +----+----+ the detector area, w/ readout moving to the ** centers. We'll trim the reference pixels and ** reset our ogin for the display as needed. */ if (trim_ref) { /* extract display area */ ip = pix; op = dpix; rowlen = nx - REFERENCE_WIDTH; nb = rowlen * (bitpix / 8); for (i=0; i < ny; i++) { bcopy (ip, op, nb); ip += (rowlen + REFERENCE_WIDTH); op += rowlen; /* ip += (rowlen + REFERENCE_WIDTH) * sizeof(XLONG); op += (rowlen) * sizeof(XLONG); */ } } else { rowlen = nx; bcopy (pix, dpix, (nx*ny*(bitpix/8))); } /* Compute the pixel statistics. Note the reference pixels are still on ** the right side of the array at this stage. */ if (stat_enable) rtdPixelStats (pix, nx, ny, &stats); #ifdef KPNO #ifdef DISPLAY_ORIGINAL_DETECTOR if (xs == 0 && ys == 0) { /* A1/Pa */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan A/1"; } else if (xs != 0 && ys == 0) { /* A2/Pa */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan A/2"; } else if (xs == 0 && ys != 0) { /* A2/Pb */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan B/2"; } else if (xs != 0 && ys != 0) { /* A1/Pb */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan B/1"; } #else #ifdef DISPLAY_FALL07_LAYOUT /* Note that the conditionals are based on the original detector ** layout, we define the (lx,ly) so they are moved to the proper ** quadrant for the display. */ if (xs == 0 && ys == 0) { /* A1 */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan A/1"; } else if (xs != 0 && ys == 0) { /* A2 */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan A/2"; } else if (xs == 0 && ys != 0) { /* B2 */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan B/2"; } else if (xs != 0 && ys != 0) { /* B1 */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan B/1"; } #else /* Note that the conditionals are based on the original detector ** layout, we define the (lx,ly) so they are moved to the proper ** quadrant for the display. ** ** This is the configuration used for Feb08 */ if (xs == 0 && ys == 0) { /* A1 */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan A/1"; } else if (xs != 0 && ys == 0) { /* B2 */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan B/2"; } else if (xs == 0 && ys != 0) { /* A2 */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan A/2"; } else if (xs != 0 && ys != 0) { /* B1 */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan B/1"; } #endif #endif #else #ifdef CTIO /* Note that the conditionals are based on the original detector ** layout, we define the (lx,ly) so they are moved to the proper ** quadrant for the display. ** ** This is the configuration used for Feb08 */ if (xs == 0 && ys == 0) { /* B1 */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan B/1"; } else if (xs != 0 && ys == 0) { /* B2 */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) + (DISP_GAP/2); det = "Pan B/2"; } else if (xs == 0 && ys != 0) { /* A1 */ lx = (fb_w / 2) - (DISP_GAP/2) - rowlen; ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan A/1"; } else if (xs != 0 && ys != 0) { /* S2 */ lx = (fb_w / 2) + (DISP_GAP/2); ly = (fb_h / 2) - (DISP_GAP/2) - ny; det = "Pan A/2"; } #endif #endif /* Z-scale the raster for display. */ cdl_computeZscale (cdl, dpix, rowlen, ny, bitpix, &z1, &z2); cdl_zscaleImage (cdl, &dpix, rowlen, ny, bitpix, z1, z2); stats.z1 = z1; stats.z2 = z2; stats.detName = det; if (verbose) printf ("%s: lx=%4d ly=%4d nx=%4d ny=%4d z1=%.3f z2=%.3f\n", det, lx, ly, rowlen, ny, z1, z2); /* Make a guess at the WCS, need this to set the fbconfig. */ cdl_setWCS (cdl, det, det, 1.0, 0.0, 0.0, -1.0, (float)lx, (float)(fb_h-ly), z1, z2, 1); /* Write the subraster to the display. */ cdl_writeSubRaster (cdl, lx, ly, rowlen, ny, dpix); /* Update the status display in the Supervisor GUI. */ rtdUpdateStats (&stats); /*free (dpix);*/ /* clean up. */ }