include # How many versions of a column can one have. define MAX_VERSIONS 100 #--------------------------------------------------------------------------- .help dark_table May 92 hrs .ih NAME dst_dark_open -- Open the statistics tables. dst_dark_write -- Write the statistics to the specified table. .endhelp #--------------------------------------------------------------------------- procedure dst_dark_open (table_name, table) char table_name[ARB] # I: Name of table to open. pointer table # O: The table descriptor. # Declarations. pointer sp pointer tmp_string # Function prototypes. int access(), strlen(), tbtacc() pointer tbtopn() begin # If no name is specified, no table is opened. if (strlen (table_name) == 0) { table = NULL } else { if (access (table_name, 0, 0) == YES) { if (tbtacc (table_name) == YES) { table = tbtopn (table_name, READ_WRITE, 0) } else { call smark (sp) call salloc (tmp_string, SZ_LINE, TY_CHAR) call sprintf (Memc[tmp_string], SZ_LINE, "file %s exists but isn't a table") call pargstr (table_name) call error (1, Memc[tmp_string]) call sfree (sp) } } else { table = tbtopn (table_name, NEW_FILE, 0) call tbtcre (table) } } end #--------------------------------------------------------------------------- # End of dst_dark_open #--------------------------------------------------------------------------- # dst_dark_write -- Write the average dark for each diode to the table. procedure dst_dark_write (table, root, sum, n_add, n_diodes) pointer table # I: Table descriptor. char root[ARB] # I: Root name. double sum[n_diodes] # I: Sum for each diode. int n_add[n_diodes] # I: Number of groups in each sum. int n_diodes # I: Number of diodes in event. # Declarations. int version # What version of the column is being used. pointer average # Average array. pointer column # Column pointer. pointer colname # Name of the column. pointer sp # Stack pointer. pointer tmp_string # Temporary string. begin if (table != NULL) { call smark(sp) call salloc (average, n_diodes, TY_DOUBLE) call salloc (colname, SZ_LINE, TY_CHAR) call salloc (tmp_string, SZ_LINE, TY_CHAR) version = 1 call strcpy (root, Memc[colname], SZ_LINE) while (version < MAX_VERSIONS) { call tbcfnd (table, Memc[colname], column, 1) if (column == NULL) break else { call eprintf ("WARNING: A column %s already exists, trying ") call pargstr (Memc[colname]) version = version + 1 call sprintf (Memc[colname], SZ_LINE, "%s_%d") call pargstr (root) call pargi (version) call eprintf ("%s\n") call pargstr (Memc[colname]) } } if (version == MAX_VERSIONS) { call sprintf (Memc[tmp_string], SZ_LINE, "could not write dark sum for observations %s") call pargstr (Memc[colname]) call error (1, Memc[tmp_string]) } # Create the column. call tbcdef (table, column, Memc[colname], "COUNT RATE", "%6.6g", TY_DOUBLE, 1, 1) # Calculate the average for each diode. call achtid (n_add[1], Memd[average], n_diodes) call adivd (sum, Memd[average], Memd[average], n_diodes) # Write out the information. call tbcptd (table, column, Memd[average], 1, n_diodes) call sfree(sp) } end #--------------------------------------------------------------------------- # End of dst_dark_write #---------------------------------------------------------------------------