include include define SZ_HIST SZ_TIME+3*SZ_FNAME+200 define SZ_PUNIT 1 define SZ_SPEC 3 # ORDERPH_NTON -- Perform order phase from N input files onto N output files # # Description: # ------------ # # Date Author Description # ---- ------ ----------- # 25-Jan-1990 J.-C. Hsu rewrite in SPP #------------------------------------------------------------------------------ procedure orderph_nton (fin, fout, fphase, ftime, finmask, foutmask, nfin, period, epoch0, epoch0_spec, maskflag, timeflag) pointer fin, fout, fphase, ftime, finmask, foutmask # input: file template pointers int nfin # input: number of files in the input template double period # input: period of the light curve double epoch0 # input: epoch of the zero phase char epoch0_spec[SZ_SPEC] # how is zero phase epoch specified? bool maskflag # input: is there input mask file(s)? bool timeflag # input: is there input time file(s)? pointer arrdata, arrphase, arrmask # addresses of data pointer ipin, ipout, ipinmask, ipoutmask, ipphase char ifile[SZ_FNAME], ofile[SZ_FNAME], imask[SZ_FNAME], omask[SZ_FNAME], phfile[SZ_FNAME], timefile[SZ_FNAME] int npix # number of points in the time series int nchar, i pointer sp, ip # dummy pointer char text[SZ_HIST] pointer immap() pointer imgl1r(), impl1r(), impl1d() int imtgetim() long clktime() #============================================================================== begin # loop all input files do i = 1, nfin { # read the next file name in the template list nchar = imtgetim (fin, ifile, SZ_FNAME) nchar = imtgetim (fout, ofile, SZ_FNAME) nchar = imtgetim (fphase, phfile, SZ_FNAME) if (timeflag) nchar = imtgetim (ftime, timefile, SZ_FNAME) # open input, output, and phase files ipin = immap (ifile, READ_ONLY, 0) ipout = immap (ofile, NEW_COPY, ipin) ipphase = immap (phfile, NEW_COPY, ipin) npix = IM_LEN(ipin, 1) # input file must be 1-D data and real data type if (IM_NDIM(ipin) != 1) call error (1, "input is not 1-D data") if (IM_PIXTYPE(ipin) != TY_REAL) call error (1, "input file is not real data type") IM_PIXTYPE(ipphase) = TY_DOUBLE # allocate array space call smark (sp) call salloc (arrphase, npix, TY_DOUBLE) # read data from the input file arrdata = imgl1r (ipin) # if there is input mask, read its data if (maskflag) { nchar = imtgetim (finmask, imask, SZ_FNAME) nchar = imtgetim (foutmask, omask, SZ_FNAME) ipinmask = immap (imask, READ_ONLY, 0) if (IM_LEN(ipinmask,1) != npix) call error (1, "mismatch of file size between input and input mask") ipoutmask = immap (omask, NEW_COPY, ipin) arrmask = imgl1r (ipinmask) } # get the phase array # if the epoch0 specification is pix, it is only for the first file if (i > 1) call strcpy ("mjd", epoch0_spec, SZ_SPEC) call get_phase (timeflag, timefile, ipin, Memd[arrphase], period, epoch0, epoch0_spec, npix) # Sort phases, data, and mask values call sort_phase (Memd[arrphase], Memr[arrdata], Memr[arrmask], maskflag, npix) # put the result to the output files and close them ip = impl1r (ipout) call amovr (Memr[arrdata], Memr[ip], npix) ip = impl1d (ipphase) call amovd (Memd[arrphase], Memd[ip], npix) if (maskflag) { ip = impl1r (ipoutmask) call amovr (Memr[arrmask], Memr[ip], npix) call imunmap (ipinmask) call imunmap (ipoutmask) } # update header keyword(s) and history call impstr (ipphase, "BUNIT", "PHASE", SZ_BUNIT) call cnvtime (clktime(0), text, SZ_HIST) call strcat (" created by the task ORDERPHASE, ", text, SZ_HIST) call strcat ("from the science file: ", text, SZ_HIST) call strcat (ifile, text, SZ_HIST) if (timeflag) { call strcat (", and the time file: ", text, SZ_HIST) call strcat (timefile, text, SZ_HIST) } call imputh (ipphase, "HISTORY", text) call imputh (ipout, "HISTORY", text) # close files call imunmap (ipin) call imunmap (ipout) call imunmap (ipphase) # print out message of which files been created call printf ("orderphase: output file %s is created\n") call pargstr (ofile) call printf ("orderphase: phase file %s is created\n") call pargstr (phfile) if (maskflag) { call printf ("orderphase: output mask %s is created\n") call pargstr (omask) } call sfree (sp) } end