include include include define FOC_NOOVERLAP -1 # T_RATIOX -- divides relative DE image into list of images # # D. Giaretta, 01-Aug-1987 Original SPP version # Phil Hodge 24-Apr-1989 Change calling sequence of imparse. # Phil Hodge 29-Nov-1989 Change keyword WAVELEN to PHOTPLAM. procedure t_ratiox() char i_imlist[SZ_LINE] # input image list char divisor[SZ_FNAME] # divisor image char o_imlist[SZ_LINE] # output image list pointer i_list # input image template list pointer pointer o_list # output image template list pointer pointer imtopen() int imtgetim() pointer d_foc_coord, d_im, x_foc_immap() char i_image[SZ_FNAME] # single input image name char o_image[SZ_FNAME] # single output image name int imtlen() errchk imtopen, imtgetim, imtlen, x_foc_immap begin call clgstr("input", i_imlist, SZ_LINE) call clgstr("denominator", divisor, SZ_FNAME) call clgstr("output", o_imlist, SZ_LINE) i_list = imtopen( i_imlist) o_list = imtopen( o_imlist) if (imtlen( i_list) != imtlen( o_list) ) { call imtclose( i_list) call imtclose( o_list) call error(0, "Input and output lists not the same size") } # open the divisor image call salloc( d_foc_coord, SZ_FOC_COORD, TY_STRUCT) FOC_COORD_INIT( d_foc_coord) = false d_im = x_foc_immap( divisor, d_foc_coord, READ_ONLY, NULL) while( imtgetim( i_list, i_image, SZ_FNAME) != EOF && imtgetim( o_list, o_image, SZ_FNAME) != EOF ) { call xratio( d_foc_coord, i_image, o_image ) } call imunmap( FOC_IMPT( d_foc_coord) ) call imtclose( i_list) call imtclose( o_list) end # XRATIO -- divide single pair of image procedure xratio( d_foc_coord, i_image, o_image ) pointer d_foc_coord # i: divisor image pointer char i_image[SZ_FNAME] # i: input image name char o_image[SZ_FNAME] # i: output image name #-- pointer i_foc_coord, o_foc_coord # foc structures for input and output pointer x_foc_immap() pointer i_im, o_im, d_im long i_v[IM_MAXDIM], d_v[IM_MAXDIM], o_v[IM_MAXDIM] long npix char caltype[SZ_LINE] char i_optcrly[SZ_LINE], d_optcrly[SZ_LINE] real i_wavelen, d_wavelen, imgetr() pointer i_line, d_line, o_line int imgnlr(), impnlr(), junk, foc_overlap() bool streq() pointer sp real raterf() extern raterf errchk imgnlr, impnlr, x_foc_immap, foc_overlap begin call smark(sp) call printf( " processing %s --> %s\n" ) call pargstr(i_image) call pargstr(o_image) # special treatment for FOC coords call salloc( i_foc_coord, SZ_FOC_COORD, TY_STRUCT) FOC_COORD_INIT( i_foc_coord) = false i_im = x_foc_immap( i_image, i_foc_coord, READ_ONLY, d_foc_coord) if ( foc_overlap( true, true , i_foc_coord, d_foc_coord) == FOC_NOOVERLAP ) { call printf(" no processing performed\n") call imunmap( i_im) return } i_im = FOC_IMPT(i_foc_coord) d_im = FOC_IMPT(d_foc_coord) # check if the input image is source normalised call strcpy( EOS, caltype, SZ_LINE) iferr( call imgstr( d_im, "CALTYPE", caltype, SZ_LINE) ) ; if (!streq(caltype, "SOURCE_NON_UNIFORM") ) { iferr { call imgstr( i_im, "OPTCRLY", i_optcrly, SZ_LINE) call imgstr( d_im, "OPTCRLY", d_optcrly, SZ_LINE) i_wavelen = imgetr( i_im, "PHOTPLAM") d_wavelen = imgetr( d_im, "PHOTPLAM") if ( !streq( i_optcrly, d_optcrly) ) call printf ("OPTCRLY of divisor not that of numerator\n") if ( i_wavelen != d_wavelen) call printf ("PHOTPLAM of divisor not that of numerator\n") call flush(STDOUT) } then ; } # pixel coords i.e zoom/non-zoom should match ******** call salloc( o_foc_coord, SZ_FOC_COORD, TY_STRUCT) FOC_COORD_INIT(o_foc_coord) = true FOC_PC_COORDS(o_foc_coord) = FOC_PC_COORDS(i_foc_coord) iferr (o_im = x_foc_immap( o_image, o_foc_coord, NEW_COPY, i_foc_coord ) ) { call printf( " Cannot create output file for input %s \n") call pargstr(i_image) call flush(STDOUT) call imunmap(i_im) return } IM_PIXTYPE(o_im) = TY_REAL call amovkl(long(1), i_v, IM_MAXDIM) call amovkl(long(1), d_v, IM_MAXDIM) call amovkl(long(1), o_v, IM_MAXDIM) npix = IM_LEN(i_im, 1) while (impnlr( o_im, o_line, o_v) != EOF ) { junk = imgnlr( i_im, i_line, i_v) junk = imgnlr( d_im, d_line, d_v) call advzr( Memr[i_line], Memr[d_line], Memr[o_line], npix, raterf) } # label the output image call x_foc_out_label( o_foc_coord) if (streq(caltype, "SOURCE_NON_UNIFORM") ) call imastr( o_im, "CALTYPE", "SOURCE_NORMALISED ") call imunmap(o_im) call imunmap(i_im) call sfree(sp) end real procedure raterf(x) real x begin return(0) end # FOC_OVERLAP -- adjust images for overlap int procedure foc_overlap( pcc, print, p_foc, s_foc) bool pcc # i: photocathode coordinates? bool print # i: print info message? pointer p_foc # i/o: primary image FOC structure ( i.e. small image) pointer s_foc # i/o: secondary image FOC structure ( i.e. large image) #-- pointer spt pointer ppt int off, off1, off2, end0, end1, end2, step, i, j int spoff1, spoff2 long new_sstep[IM_MAXDIM] long new_pvoff[IM_MAXDIM] long new_svoff[IM_MAXDIM] long new_pvlen[IM_MAXDIM] long new_svlen[IM_MAXDIM] bool foc_changed_size() begin spt = FOC_IMPT( s_foc) ppt = FOC_IMPT( p_foc) for ( i=1; i<= IM_NPHYSDIM( ppt); i=i+1) { step = IM_VSTEP( ppt, i) if ( i == 1 && pcc ) { spoff1 = FOC_SAMPBEG( p_foc) spoff2 = FOC_SAMPBEG( s_foc) } else if ( i == 2 && pcc ) { spoff1 = FOC_LINEBEG( p_foc) spoff2 = FOC_LINEBEG( s_foc) } else { spoff1 = 1 spoff2 = 1 } off1 = IM_VOFF( ppt, i) + spoff1 + step - 1 end1 = off1 for ( j=1; j<= IM_NDIM(ppt); j=j+1) if ( IM_VMAP(ppt, j) == i) end1 = off1 + step*(IM_LEN( ppt, j) - 1) if ( step > 0 ) { off2 = spoff2 end2 = spoff2 + IM_SVLEN( spt, i) - 1 } else { end2 = spoff2 off2 = spoff2 + IM_SVLEN( spt, i) - 1 } if ( step > 0 ) { off = max( off1, off2 ) end0 = min( end1, end2 ) } else { off = min( off1, off2 ) end0 = max( end1, end2 ) } new_pvoff[i] = off - spoff1 + 1 new_svoff[i] = off - spoff2 + 1 new_sstep[i] = IM_VSTEP( ppt, i) new_pvlen[i] = (end0 - off )/step + 1 new_svlen[i] = (end0 - off )/step + 1 if ( new_pvlen[i] < 1 ) return( FOC_NOOVERLAP) } # see if we have changed anything: if ( foc_changed_size( p_foc, new_pvoff, new_pvlen, new_sstep) ) iferr( call foc_reopen( print, new_pvoff, new_pvlen, new_sstep, p_foc) ) return ( FOC_NOOVERLAP) if ( foc_changed_size( s_foc, new_svoff, new_svlen, new_sstep) ) iferr( call foc_reopen( print, new_svoff, new_svlen, new_sstep, s_foc)) return ( FOC_NOOVERLAP) return( FOC_OK ) end # FOC_CHANGED_SIZE -- see if we want to change the image size bool procedure foc_changed_size( p_foc, new_voff, new_len, new_step) pointer p_foc # i: foc image structure long new_voff[IM_MAXDIM] long new_len[IM_MAXDIM] long new_step[IM_MAXDIM] #-- pointer im int i begin im = FOC_IMPT( p_foc) for ( i=1; i <= IM_NPHYSDIM(im); i=i+1) { if ( IM_VOFF( im, i) + IM_VSTEP(im, i) != new_voff[i] || IM_LEN(im, IM_VMAP(im,i) ) != new_len[i] || IM_VSTEP(im, i) != new_step[i] ) return ( true ) } return ( false ) end # FOC_REOPEN -- open image with the desired section. If the open is OK # then we close the original open and copy info to the old foc structure. # Note we should only reopen READ_* files. procedure foc_reopen( print, new_voff, new_len, new_step, p_foc) bool print # i: print info? long new_voff[IM_MAXDIM] # i: new image offsets long new_len[IM_MAXDIM] # i: new axis lengths long new_step[IM_MAXDIM] # i: new step sizes pointer p_foc # i: foc image structure #-- pointer im, x_foc_immap(), im_new, d_foc_coord_new int i, accmode, cl_index, cl_size, ndim char imname[SZ_PATHNAME] char ksection[SZ_FNAME], section[SZ_FNAME] char ctemp[SZ_FNAME] char old_imname[SZ_FNAME] errchk x_foc_immap begin im = FOC_IMPT( p_foc) accmode = IM_ACMODE( im) ndim = IM_NPHYSDIM( im) if ( accmode != READ_ONLY && accmode != READ_WRITE ) call error( 0, "can only reopen existing image") call imparse( IM_NAME(im), imname, SZ_PATHNAME, ksection, SZ_FNAME, section, SZ_FNAME, cl_index, cl_size) call strcpy( IM_NAME(im), old_imname, SZ_FNAME) # construct new name # first add cluster info if it was present in original call strcpy( EOS, section, SZ_FNAME) if ( cl_index != 0 ) { call sprintf( section, SZ_FNAME, "[%d" ) call pargi( cl_index) if ( cl_size != 0 ) { call sprintf( ctemp, SZ_FNAME, "/%d") call pargi( cl_size) call strcat( ctemp, section, SZ_FNAME) } call strcat( "]", section, SZ_FNAME) } # then add section info for ( i=1; i <= ndim; i=i+1) { call sprintf( ctemp, SZ_FNAME, "%d:%d:%d") call pargi( new_voff[i]) call pargi( new_voff[i] + (new_len[i]-1)*new_step[i] ) call pargi( abs( new_step[i] ) ) if ( i == 1 ) call strcat( "[", section, SZ_FNAME) call strcat( ctemp, section, SZ_FNAME) if ( i != ndim ) call strcat( ",", section, SZ_FNAME ) if ( i == ndim ) call strcat( "]", section, SZ_FNAME ) } call strcat( section, imname, SZ_PATHNAME) call salloc( d_foc_coord_new, SZ_FOC_COORD, TY_STRUCT) FOC_COORD_INIT( d_foc_coord_new) = FOC_COORD_INIT( p_foc) im_new = x_foc_immap( imname, d_foc_coord_new, accmode, NULL) if ( print ) { call printf( " %s changed to %s\n") call pargstr( old_imname) call pargstr( IM_NAME(im_new) ) call flush( STDOUT) } # if everything is OK we can copy the contents of the new structure to # the old structure call imunmap( im) call amovi( Memi[d_foc_coord_new], Memi[p_foc], SZ_FOC_COORD) end