include # Column definitions. define LINES 1 define INTEN 2 define FWHM 3 define N_COLS 3 # Memory management. define Colname Memc[colname+($1-1)*(SZ_COLNAME+1)] define Colptr Memi[colptr+$1-1] define Fwhm Memr[fwhm_ptr] define Lines Memd[lines_ptr] define Nullflag Memb[nullflag] define Inten Memr[inten_ptr] define Sx Memc[sx] #--------------------------------------------------------------------------- .help mkw_rtab 11Apr95 source .ih NAME mkw_rtab -- Read lines from table. .ih DESCRIPTION Below is a description of the routine interface. .ls mkw_rtab (t, lines_ptr, inten_ptr, fwhm_ptr, nlines) This routine reads a table for line wavelengths, intensity, and width. The intensities and widths are both optional. If not present, the array pointers will be NULL. .ls ARGUMENTS .ls t (i: pointer) The table descriptor from which to read the lines. .le .ls lines_ptr (io: pointer) A pointer to a double-valued array of line wavelengths read from the table. The array is of type TY_DOUBLE and must be deallocated by the user with the routine 'mfree'. If already pointing to an array, the array will be re-allocated. .le .ls inten_ptr (io: pointer) A pointer to a double-valued array of line intensities read from the table. The array is of type TY_DOUBLE and must be deallocated by the user with the routine 'mfree'. If the table does not contain a column of intensities, the returned value will be NULL. If already pointing to an array, the array will be re-allocated. .le .ls fwhm_ptr (io: pointer) A pointer to a double-valued array of line full-width/half-max (FWHM) values read from the table. The array is of type TY_DOUBLE and must be deallocated by the user with the routine 'mfree'. If the table does not contain a column of intensities, the returned value will be NULL. If already pointing to an array, the array will be re-allocated. .le .le .ls ERRORS Errors generated by the system memory management routines. Errors generated by the TABLES access routines. Error #1: no column giving line position -- This column is required. .le .le .endhelp #--------------------------------------------------------------------------- procedure mkw_rtab (t, lines_ptr, inten_ptr, fwhm_ptr, nlines) pointer t # I: Input table descriptor. pointer lines_ptr # IO: Pointer to line array. pointer inten_ptr # IO: Pointer to intensity array. pointer fwhm_ptr # IO: Pointer to FWHM array. int nlines # IO: Number of lines in above arrays. # Declarations. pointer colname # Column names. pointer colptr # Column pointers. pointer nullflag # NULL indicators. pointer sp # Stack pointer. pointer sx # Generic string. int tbpsta() # Get table parameters. errchk malloc, realloc errchk salloc, sfree, smark errchk tbcfnd, tbcgtd, tbcgtr, tbpsta begin call smark (sp) call salloc (colname, (SZ_COLNAME+1)*N_COLS, TY_CHAR) call salloc (colptr, N_COLS, TY_POINTER) call salloc (sx, SZ_LINE, TY_CHAR) # Get column names from user. call clgstr ("lines_col", Colname(LINES), SZ_COLNAME) call clgstr ("int_col", Colname(INTEN), SZ_COLNAME) call clgstr ("width_col", Colname(FWHM), SZ_COLNAME) # Find the columns. Only LINES has to be there, other columns # are optional. call tbcfnd (t, Colname(1), Colptr(1), N_COLS) if (Colptr(LINES) == NULL) { call sprintf (Sx, SZ_LINE, "no column '%s' giving line positions") call pargstr (Colname(LINES)) call error (1, Sx) } # Read the lines. nlines = tbpsta (t, TBL_NROWS) call realloc (lines_ptr, nlines, TY_DOUBLE) call malloc (nullflag, nlines, TY_BOOL) call tbcgtd (t, Colptr(LINES), Lines, Nullflag, 1, nlines) # Read the Intensities. if (Colptr(INTEN) != NULL) { call realloc (inten_ptr, nlines, TY_REAL) call tbcgtr (t, Colptr(INTEN), Inten, Nullflag, 1, nlines) } else { if (inten_ptr != NULL) call mfree (inten_ptr, TY_REAL) } # Read the Fwhms. if (Colptr(FWHM) != NULL) { call realloc (fwhm_ptr, nlines, TY_REAL) call tbcgtr (t, Colptr(FWHM), Fwhm, Nullflag, 1, nlines) } else { if (fwhm_ptr != NULL) call mfree (fwhm_ptr, TY_REAL) } # That's all folks. call mfree (nullflag, TY_BOOL) call sfree (sp) end #--------------------------------------------------------------------------- # End of mkw_rtab #---------------------------------------------------------------------------