include include procedure t_dsimg () # Read the image display server buffer and write an IRAF (OIF or STF) # format image. pointer sp pointer imname int frame int clgeti() bool clgetb() begin call smark (sp) call salloc (imname, SZ_FNAME, TY_CHAR) # Get the input cl parameters frame = clgeti ("frame") # Get the file names from the cl parameters call clgstr ("image", Memc[imname], SZ_FNAME) # Copy the display buffer to the image call dsimg (frame, Memc[imname], clgetb("maxrange")) call sfree (sp) end procedure dsimg (frame, imname, maxr) char imname[ARB] int frame bool maxr pointer im, ds pointer imlin, dslin int nx, ny int line short min, max short lmin, lmax pointer imd_mapframe(), immap(), imgl2s(), impl2s() long clktime() begin # Open the display frame buffer as an image ds = imd_mapframe (frame, READ_ONLY, YES) nx = IM_LEN(ds,1) ny = IM_LEN(ds,2) # Open the output image as a copy of the display buffer im = immap (imname, NEW_COPY, ds) min = MAX_SHORT max = 0 do line = 1, ny { # For each image line call printf ("line %4d/%d %3d%%\r") call pargi (line) call pargi (ny) call pargi (int(100.0 * real(line) / real(ny))) call flush (STDOUT) # Get an image line dslin = imgl2s (ds, line) if (!maxr) call alims (Mems[dslin], nx, lmin, lmax) if (!maxr) { if (lmin < min) min = lmin if (lmax > max) max = lmax } imlin = impl2s (im, line) # Copy the display buffer line to the image line call amovs (Mems[dslin], Mems[imlin], nx) } call printf ("\n") # Update the header IM_LIMTIME(im) = clktime (long(0)) if (maxr) { min = 0 max = 255 } # update the data range call imaddr (im, "datamin", real(min)) call imaddr (im, "datamax", real(max)) IM_MIN(im) = real(min) IM_MAX(im) = real(max) call imunmap (ds) call imunmap (im) end