include # outtbl_init -- set up the output table # # Description: # ------------ # set up/acquire column identifiers and pointer to table descriptor of the # output table. # If the output table does not exist, this routine will initialize it, # define column names according to the input, and open it. If the output # table does exist, this routine will open the table, check and find # identifiers for all columns, and define columns if they do not already # exist in the table. It also gives the pointer to table descriptor and # number of rows already written in output table. # # Version Date Author Description # 1 05-19-87 J.-C. Hsu design and coding # 2 09-09-87 J.-C. Hsu new F77 interface # 3 11-09-90 J.-C. Hsu rewrite in SPP #------------------------------------------------------------------------------- procedure outtbl_init (tbname, colnam, unit, colfmt, dtype, ncol, tp, colidn, nrows) ## input char tbname[SZ_FNAME] # output table name char colnam[SZ_COLNAME, ncol], unit[SZ_COLUNITS, ncol] char colfmt[SZ_COLFMT, ncol] # column name(s), unit(s), and format(s) int dtype[ncol] # data types int ncol # number of columns ## output pointer tp # pointer to table descripter pointer colidn[ncol] # pointers to column descripters int nrows # number of rows existed in output table ## local int i int exist int tbtacc() pointer tbtopn() int tbpsta() #------------------------------------------------------------------------------ begin # check if the table exists exist = tbtacc (tbname) # if table already exists, open it, get number of existing rows if (exist == YES) { tp = tbtopn (tbname, READ_WRITE, 0) nrows = tbpsta (tp, TBL_NROWS) # check column names, get their identifiers, and if nonexistent, # create them call tbcfnd (tp, colnam, colidn, ncol) do i = 1, ncol { if (colidn[i] == NULL) { iferr (call tbcdef (tp, colidn[i], colnam[1, i], unit[1, i], colfmt[1, i], dtype[i], 1, 1)) { call eprintf ("cannot create column %s\n") call pargstr (colnam[1,i]) call tbtclo (tp) call error (1, "") } } } } else { # if table does not exist, initialize it, define all columns # and open it tp = tbtopn (tbname, NEW_FILE, 0) if (tp == NULL) { call eprintf ("cannot create new table %s\n") call pargstr (tbname) call error (1, "") } do i = 1, ncol { iferr (call tbcdef (tp, colidn[i], colnam[1, i], unit[1, i], colfmt[1, i], dtype[i], 1, 1)) { call tbtclo (tp) call error (1, "cannot define columns") } } call tbtcre (tp) nrows = 0 } end