Beispiel #1
0
 Composite_Query_Obj():read_write_base()
     ,Id(0LL)
     ,Site_Id(0LL)
     ,Name("")
     ,Select_Part("")
     ,From_Part("")
     ,Where_Part("")
     ,Group_Part("")
     ,Having_Part("")
     ,Order_Part("")
     ,Is_Workflow(false)
 {
     // set name
     data_name("Composite_Query");
     // add fields
     addDXMap( new llongXfer("Id", &Id ));
     addDXMap( new llongXfer("Site_Id", &Site_Id ));
     addDXMap( new stringXfer("Name", &Name ));
     addDXMap( new stringXfer("Select_Part", &Select_Part ));
     addDXMap( new stringXfer("From_Part", &From_Part ));
     addDXMap( new stringXfer("Where_Part", &Where_Part ));
     addDXMap( new stringXfer("Group_Part", &Group_Part ));
     addDXMap( new stringXfer("Having_Part", &Having_Part ));
     addDXMap( new stringXfer("Order_Part", &Order_Part ));
     addDXMap( new boolXfer("Is_Workflow", &Is_Workflow ));
 }
Beispiel #2
0
  users_Obj():read_write_base()
  ,id(0LL)
  ,first("")
  ,last("")
  ,login("")
  ,password("")
  ,phone("")
  ,email("")
  ,fax("")
  ,pager("")
  ,xml_preferences("")
  ,group_id(0LL)
  {  
    // set name
    data_name("users");
    // add fields
    addDXMap( new llongXfer("id", &id ));
    addDXMap( new stringXfer("first", &first ));
    addDXMap( new stringXfer("last", &last ));
    addDXMap( new stringXfer("login", &login ));
    addDXMap( new stringXfer("password", &password ));
    addDXMap( new stringXfer("phone", &phone ));
    addDXMap( new stringXfer("mobile", &mobile ));
    addDXMap( new stringXfer("email", &email ));
    addDXMap( new stringXfer("fax", &fax ));
    addDXMap( new stringXfer("pager", &pager ));
    addDXMap( new stringXfer("xml_preferences", &xml_preferences ));
    addDXMap( new llongXfer("group_id", &group_id ));
    // cerr <<  "llongXfer(group_id: " << group_id << endl;

  }
Beispiel #3
0
    Time_Obj():read_write_base()
    ,Id(0LL)
    ,Task(0LL)
    ,Start( )
    ,Stop( )
    ,Description("")
    ,Hours(0.0)
    ,Status(0LL)
    ,Invoice(0LL)
    ,Performed_By(0LL)
    {
// set name
      data_name("Time");
// add fields
      addDXMap( new llongXfer("Id", &Id ));
      addDXMap( new llongXfer("Task", &Task ));
      addDXMap( new time_dateXfer("Start", &Start ));
      addDXMap( new time_dateXfer("Stop", &Stop ));
      addDXMap( new stringXfer("Description", &Description ));
      addDXMap( new doubleXfer("Hours", &Hours ));
      addDXMap( new llongXfer("Status", &Status ));
      addDXMap( new llongXfer("Invoice", &Invoice ));
      addDXMap( new llongXfer("Performed_By", &Performed_By ));
      Start.normalize();
      Stop.normalize();
    }
Beispiel #4
0
    // Constructor
    Category():read_write_base(),CategoryID(0LL)
    {
        data_name("Category");
        // ALWAYS make the key be first, so we can skip it in insert logic
        addDXMap( new llongXfer("CategoryID", &CategoryID) );
        addDXMap( new stringXfer("CategoryName", &CategoryName) );

    }
Beispiel #5
0
 // Constructor
 Payment_Service():read_write_base(),Id(0LL),Type(0L)  
 {
   data_name("Payment_Service");    
   addDXMap( new llongXfer("Id", &Id) );
   addDXMap( new llongXfer("Type", &Type) );
   addDXMap( new stringXfer("Name", &Name) );
   addDXMap( new stringXfer("Label", &Label) );
   addDXMap( new stringXfer("Instructions", &Instructions) ); 
 }
Beispiel #6
0
 // ctor dtor and assign op.
 Customer_Payment_Parameter():Customer_Payment_Parameter_Datum()  
 {
   data_name("Customer_Payment_Parameter");
   addDXMap( new llongXfer("Id", &Id) );
   addDXMap( new llongXfer("Customer_Pmt_Service_Id", &Customer_Pmt_Service_Id) );
   addDXMap( new llongXfer("Pmt_Type_Param_Id", &Pmt_Type_Param_Id) );    
   addDXMap( new stringXfer("Machine_Name", &Machine_Name) );
   addDXMap( new stringXfer("Value", &Value) );
 }  
Beispiel #7
0
 Form_Label_Obj():read_write_base()
 ,Id(0LL)
 ,form_name("")
 ,label_a("")
 ,label_b("")
 ,label_c("")
 ,label_d("")
 ,label_e("")
 ,label_f("")
 ,label_g("")
 ,label_h("")
 ,label_i("")
 ,label_j("")
 ,label_k("")
 ,label_l("")
 ,label_m("")
 ,label_n("")
 ,label_o("")
 ,label_p("")
 ,label_q("")
 ,label_r("")
 ,label_s("")
 ,label_t("")
 ,label_u("")
 ,label_v("")
 ,label_w("")
 {
   // set name
   data_name("Form_Label");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new stringXfer("form_name", &form_name ));
   addDXMap( new stringXfer("label_a", &label_a ));
   addDXMap( new stringXfer("label_b", &label_b ));
   addDXMap( new stringXfer("label_c", &label_c ));
   addDXMap( new stringXfer("label_d", &label_d ));
   addDXMap( new stringXfer("label_e", &label_e ));
   addDXMap( new stringXfer("label_f", &label_f ));
   addDXMap( new stringXfer("label_g", &label_g ));
   addDXMap( new stringXfer("label_h", &label_h ));
   addDXMap( new stringXfer("label_i", &label_i ));
   addDXMap( new stringXfer("label_j", &label_j ));
   addDXMap( new stringXfer("label_k", &label_k ));
   addDXMap( new stringXfer("label_l", &label_l ));
   addDXMap( new stringXfer("label_m", &label_m ));
   addDXMap( new stringXfer("label_n", &label_n ));
   addDXMap( new stringXfer("label_o", &label_o ));
   addDXMap( new stringXfer("label_p", &label_p ));
   addDXMap( new stringXfer("label_q", &label_q ));
   addDXMap( new stringXfer("label_r", &label_r ));
   addDXMap( new stringXfer("label_s", &label_s ));
   addDXMap( new stringXfer("label_t", &label_t ));
   addDXMap( new stringXfer("label_u", &label_u ));
   addDXMap( new stringXfer("label_v", &label_v ));
   addDXMap( new stringXfer("label_w", &label_w ));
 }
Beispiel #8
0
 Report_Type_Obj():read_write_base()
 ,Id(0LL)
 ,Name("")
 {  
   // set name
   data_name("Report_Type");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new stringXfer("Name", &Name ));
 }
Beispiel #9
0
  // Constructor
  Customer_Payment_Service()
  :Id(0LL),Customer_Id(0LL)
  ,Payment_Service_Id(0LL) 
  {
    data_name("Customer_Payment_Service");    
    addDXMap( new llongXfer("Id", &Id) );
    addDXMap( new llongXfer("Customer_Id", &Customer_Id) );
    addDXMap( new llongXfer("Payment_Service_Id", &Payment_Service_Id) );

  } 
Beispiel #10
0
 Scheme_Table_Obj():read_write_base()
 ,Id(0LL)
 ,Name("")
 ,Abbr("")
 {  
   // set name
   data_name("Scheme_Table");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new stringXfer("Name", &Name ));
   addDXMap( new stringXfer("Abbr", &Abbr ));
 }  
Beispiel #11
0
 roles_Obj():read_write_base()
 ,id(0LL)
 ,name("")
 ,comment("")
 {  
   // set name
   data_name("roles");
   // add fields
   addDXMap( new llongXfer("id", &id ));
   addDXMap( new stringXfer("name", &name ));
   addDXMap( new stringXfer("comment", &comment ));
 }
Beispiel #12
0
 Ordered_Items():Ordered_Items_Datum(),read_write_base()  
 {
   data_name("Ordered_Items"); 
   // ALWAYS make the key be first, so we can skip it in insert logic
   addDXMap( new llongXfer("Id", &Id) );
   addDXMap( new llongXfer("Product_Id",&Product_Id) );
   addDXMap( new llongXfer("Order_Id",&Order_Id) );   
   addDXMap( new intXfer("Product_Count",&Product_Count) ); 
   addDXMap( new moneyXfer("Total_Price",&Total_Price) );
   addDXMap( new llongXfer("Order_Status_Id", &Order_Status_Id) );
   addDXMap( new stringXfer("Tracking_Number", &Tracking_Number) );    
           
 }
Beispiel #13
0
  // Constructor
  groups():read_write_base(),id(0LL),site_admin(false)
  {    
    data_name("groups");       
    // ALWAYS make the key be first, so we can skip it in insert logic
    addDXMap( new llongXfer("id", &id) );
    
    addDXMap( new stringXfer("name", &name) );                   
    // addDXMap( new stringXfer("domain", &domain) );
    // addDXMap( new stringXfer("url", &url) );

    addDXMap( new boolXfer("site_admin", &site_admin) );    
     
  }
Beispiel #14
0
 FieldChange_Obj():read_write_base()
 ,Id(0LL)
 ,auditTable(0LL)
 ,Name("")
 ,Value("")
 {  
   // set name
   data_name("w3audit.FieldChange");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new llongXfer("auditTable", &auditTable ));
   addDXMap( new stringXfer("Name", &Name ));
   addDXMap( new stringXfer("Value", &Value ));
 }
Beispiel #15
0
Var *Interpreter::_make_varargs_type( const Vec<Var> &uv_args, const Vec<Var> &nv_args, const Vec<int> &nv_name, int off ) {
    // class VarargsItemEnd
    if ( off >= uv_args.size() + nv_args.size() )
        return &type_VarargsItemEnd;

    // class VarargsItemBeg[ data_type, data_name, next_type ]
    Var data_type = type_of( off >= uv_args.size() ? nv_args[ off - uv_args.size() ] : uv_args[ off ] );
    Var data_name( &type_SI32, cst( off >= uv_args.size() ? nv_name[ off - uv_args.size() ] : -1 ) );

    Var *parms[ 3 ];
    parms[ 0 ] = &data_type;
    parms[ 1 ] = &data_name;
    parms[ 2 ] = _make_varargs_type( uv_args, nv_args, nv_name, off + 1 );
    return type_for( class_info( class_VarargsItemBeg ), parms );
}
Beispiel #16
0
 Scheme_Field_Obj():read_write_base()
 ,Id(0LL)
 ,Scheme_Table(0LL)
 ,Name("")
 ,Col_Type("")
 ,Links_To(0LL)
 {  
   // set name
   data_name("Scheme_Field");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new llongXfer("Scheme_Table", &Scheme_Table ));
   addDXMap( new stringXfer("Name", &Name ));
   addDXMap( new stringXfer("Col_Type", &Col_Type ));
   addDXMap( new llongXfer("Links_To", &Links_To ));
 }  
Beispiel #17
0
  Task_Obj():read_write_base()
  ,Id(0LL)
  ,Project(0LL)
  ,Name("")
  ,Estimated_Time(0.0)
  ,Actual_Time(0.0)
  ,Description("")
  ,Start( )
  ,Task_Order(1000L)
  ,Hierarchy(0L)
  ,Status(0LL)
  ,Percent_Complete(0L)
  ,Parent_Task(0LL)
  ,Estimate(0.0)
  ,Requestor(0LL)
  ,Requested( )
  ,Estimated_End( )
  ,Actual_End( )
  {
    // set name
    data_name("Task");

    // Defaults: add 2000 years to the end times
    Estimated_End.addYears(2000);
    Actual_End.addYears(2000);
    
    // add fields
    addDXMap( new llongXfer("Id", &Id ));
    addDXMap( new llongXfer("Project", &Project ));
    addDXMap( new stringXfer("Name", &Name ));
    addDXMap( new doubleXfer("Estimated_Time", &Estimated_Time ));
    addDXMap( new doubleXfer("Actual_Time", &Actual_Time ));
    addDXMap( new stringXfer("Description", &Description ));
    addDXMap( new time_dateXfer("Start", &Start ));
    addDXMap( new longXfer("Task_Order", &Task_Order ));
    addDXMap( new longXfer("Hierarchy", &Hierarchy ));
    addDXMap( new llongXfer("Status", &Status ));
    addDXMap( new longXfer("Percent_Complete", &Percent_Complete ));
    addDXMap( new llongXfer("Parent_Task", &Parent_Task ));
    addDXMap( new moneyXfer("Estimate", &Estimate ));
    addDXMap( new llongXfer("Requestor", &Requestor ));
    addDXMap( new oc_dateXfer("Requested", &Requested ));
    addDXMap( new oc_dateXfer("Estimated_End", &Estimated_End ));
    addDXMap( new oc_dateXfer("Actual_End", &Actual_End )); 
  }
Beispiel #18
0
 Attachments_Obj():read_write_base()
     ,Id(0LL)
     ,Message(0LL)
     ,Task(0LL)
     ,URL("")
     ,Title("")
     ,Description("")
 {
     // set name
     data_name("Attachments");
     // add fields
     addDXMap( new llongXfer("Id", &Id ));
     addDXMap( new llongXfer("Message", &Message ));
     addDXMap( new llongXfer("Task", &Task ));
     addDXMap( new stringXfer("URL", &URL ));
     addDXMap( new stringXfer("Title", &Title ));
     addDXMap( new stringXfer("Description", &Description ));
 }
 Report_Parameters_Obj():read_write_base()
 ,Id(0LL)
 ,Report_Id(0LL)
 ,Display_Label("")
 ,Data_Element("")
 ,Tag_Name("")
 ,Choices_Query("")
 ,Parameter_Type("")  
 {  
   // set name
   data_name("Report_Parameters");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new llongXfer("Report_Id", &Report_Id ));
   addDXMap( new stringXfer("Display_Label", &Display_Label ));
   addDXMap( new stringXfer("Data_Element", &Data_Element ));
   addDXMap( new stringXfer("Tag_Name", &Tag_Name ));
   addDXMap( new stringXfer("Choices_Query", &Choices_Query ));
   addDXMap( new stringXfer("Parameter_Type", &Parameter_Type ));    
 }
Beispiel #20
0
 Ordered_Item_Obj():read_write_base()
 ,Id(0LL)
 ,Product_Id(0LL)
 ,Order_Id(0LL)
 ,Product_Count(0)
 ,Total_Price(0.0)
 ,Shipping(0.0)
 ,Internal_Id("")
 ,External_Id("")
 {  
   // set name
   data_name("Ordered_Item");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new llongXfer("Product_Id", &Product_Id ));
   addDXMap( new llongXfer("Order_Id", &Order_Id ));
   addDXMap( new intXfer("Product_Count", &Product_Count ));
   addDXMap( new moneyXfer("Total_Price", &Total_Price ));
   addDXMap( new moneyXfer("Shipping", &Shipping ));
   addDXMap( new stringXfer("Internal_Id", &Internal_Id ));
   addDXMap( new stringXfer("External_Id", &External_Id ));
 }
Beispiel #21
0
 Ordered_Obj():read_write_base()
 ,Id(0LL)
 ,Product_Id(0LL)
 ,Customer_Id(0LL)
 ,Order_Status_Id(1LL)
 ,Product_Total(0.0)
 ,Shipping_Total(0.0)
 ,Tax_Total(0.0)
 ,Order_Total(0.0)
 ,Order_Date( )
 ,Ship_Date( )
 ,Reconcile_Date( )
 ,Transaction_Id("")
 ,Shipping_Co(0LL)
 ,Tracking_Number("")
 ,Notes("")
 ,Customer_Pmt_Svc_Id(0LL)
 {  
   // set name
   data_name("Ordered");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new llongXfer("Product_Id", &Product_Id ));
   addDXMap( new llongXfer("Customer_Id", &Customer_Id ));
   addDXMap( new llongXfer("Order_Status_Id", &Order_Status_Id ));
   addDXMap( new moneyXfer("Product_Total", &Product_Total ));
   addDXMap( new moneyXfer("Shipping_Total", &Shipping_Total ));
   addDXMap( new moneyXfer("Tax_Total", &Tax_Total ));
   addDXMap( new moneyXfer("Order_Total", &Order_Total ));
   addDXMap( new time_dateXfer("Order_Date", &Order_Date ));
   addDXMap( new time_dateXfer("Ship_Date", &Ship_Date ));
   addDXMap( new time_dateXfer("Reconcile_Date", &Reconcile_Date ));
   addDXMap( new stringXfer("Transaction_Id", &Transaction_Id ));
   addDXMap( new llongXfer("Shipping_Co", &Shipping_Co ));
   addDXMap( new stringXfer("Tracking_Number", &Tracking_Number ));
   addDXMap( new stringXfer("Notes", &Notes ));
   addDXMap( new llongXfer("Customer_Pmt_Svc_Id", &Customer_Pmt_Svc_Id ));
 }
Beispiel #22
0
 Hosting_Obj():read_write_base()
 ,Id(0LL)
 ,Company(0LL)
 ,Invoice(0LL)
 ,From_Date( )
 ,To_Date( )
 ,Site_URL("")
 ,Billing_Interval(0)
 ,Charge_Per_Month(0.0)
 ,Charge(0.0)
 {
   // set name
   data_name("Hosting");
   // add fields
   addDXMap( new llongXfer("Id", &Id ));
   addDXMap( new llongXfer("Company", &Company ));
   addDXMap( new llongXfer("Invoice", &Invoice ));
   addDXMap( new oc_dateXfer("From_Date", &From_Date ));
   addDXMap( new oc_dateXfer("To_Date", &To_Date ));
   addDXMap( new stringXfer("Site_URL", &Site_URL ));
   addDXMap( new intXfer("Billing_Interval", &Billing_Interval ));
   addDXMap( new moneyXfer("Charge_Per_Month", &Charge_Per_Month ));
   addDXMap( new moneyXfer("Charge", &Charge ));
 }
Beispiel #23
0
 Orders():read_write_base(),
 Id(0LL),Product_Id(0LL),Patron_Id(0LL),
 Order_Status_Id(os_awaiting_shipment),Patron_Payment_Service_Id(0LL),
 Product_Total(0.0),Shipping_Total(0.0),Tax_Total(0.0),
 Order_Total(0.0),Order_Date( )
 {
   data_name("Orders");       
   addDXMap( new llongXfer("Id", &Id) );
   addDXMap( new llongXfer("Product_Id", &Product_Id) );  // first product in order
   addDXMap( new llongXfer("Patron_Id", &Patron_Id) );    // the one who bought it
   addDXMap( new llongXfer("Order_Status_Id", &Order_Status_Id) );  
   addDXMap( new llongXfer("Patron_Payment_Service_Id", &Patron_Payment_Service_Id) ); // how they bought it
   addDXMap( new moneyXfer("Product_Total", &Product_Total) );  // total of all products
   addDXMap( new moneyXfer("Shipping_Total", &Shipping_Total) ); // total shipping   
   addDXMap( new moneyXfer("Tax_Total", &Tax_Total) );    
   addDXMap( new moneyXfer("Order_Total", &Order_Total) );
   addDXMap( new oc_dateXfer("Order_Date", &Order_Date) );
   addDXMap( new oc_dateXfer("Ship_Date", &Ship_Date) );
   addDXMap( new oc_dateXfer("Reconcile_Date", &Reconcile_Date) ); 
   addDXMap( new stringXfer("Transactions_Id", &Transactions_Id) );
   addDXMap( new llongXfer("Shipping_Co", &Shipping_Co) );
   addDXMap( new stringXfer("Tracking_Number", &Tracking_Number) );
   addDXMap( new stringXfer("Notes", &Notes) );                                         
 }
Beispiel #24
0
/*==========================================
 * main
 *========================================== */
int main(int argc, char* argv[])
{
  int c, iter, ITER=0, seed=0;
  enum dataType data = LdaC;
  enum dataType testdata = LdaC;
  int dots = 0;

  enum GibbsType fix_hold = GibbsNone;
  char *stem;
  char *resstem;
  int topwords = 20;
  int noerrorlog = 0;
  int displayed = 0;
  int load_vocab = 0;
  int checkpoint = 0;
  int restart = 0;
  int dopmi = 0;
  int restart_hca = 0;
  int load_phi = 0;
  int load_mu = 0;
  int procs = 1;
  int maxW = 0;
  enum ScoreType score=ST_idf;
  
  double BM0val=0, BM1val =0, BP0val=0, BP1val=0;
  
  clock_t t1=0, t2=0, t3=0;
  double tot_time = 0;
  double psample_time = 0;
  enum ParType par;
  /*
   *  default values
   */
  ddN.T = 10;
  ITER = 100;
  ddN.TEST = 0;

  pctl_init();

  while ( (c=getopt(argc, argv,"b:c:C:d:ef:F:g:G:h:K:l:L:N:o:pq:vr:s:S:t:T:vVW:"))>=0 ) {
    switch ( c ) {
    case 'b':
      if ( !optarg || sscanf(optarg,"%d",&ddP.back)!=1 )
        yap_quit("Need a valid 'b' argument\n");
      break;
    case 'c':
      if ( !optarg || sscanf(optarg,"%d",&checkpoint)!=1 )
        yap_quit("Need a valid 'c' argument\n");
      break;
    case 'C':
      if ( !optarg || sscanf(optarg,"%d",&ITER)!=1 )
	yap_quit("Need a valid 'C' argument\n");
      break;
    case 'd':
      if ( !optarg || sscanf(optarg,"%d",&dots)!=1 )
	yap_quit("Need a valid 'd' argument\n");
      break;
    case 'e':
      noerrorlog++;
      break;
    case 'f':
      if ( strcmp(optarg,"witdit")==0 ) 
	data = WitDit;
      else if ( strcmp(optarg,"docword")==0 ) 
	data = Docword;
      else if ( strcmp(optarg,"ldac")==0 ) 
	data = LdaC;
      else if ( strcmp(optarg,"bag")==0 ) 
	data = TxtBag;
      else if ( strcmp(optarg,"lst")==0 ) 
	data = SeqTxtBag;
       else
	yap_quit("Illegal data type for -f\n");
      break;
    case 'F':
      if ( strcmp(optarg,"all")==0 ) {
	for (par=ParAM; par<=ParBB; par++) 
	  ddT[par].fix = 1;
      } else {
	par = findpar(optarg);
	if ( par==ParNone )
	  yap_quit("Illegal arg for -F\n");
	ddT[par].fix = 1;
      }
      break;
    case 'g':
	{
	  char var[100];
	  int st=0;
	  if ( !optarg || sscanf(optarg,"%[^, ],%d", &var[0], &st)<1  )
            yap_quit("Need a valid 'g' argument\n");
          par = findpar(var);
          if ( par==ParBP1 )
            ddP.kbatch = st;
          else
            yap_quit("Illegal var for -g\n");
        }
        break;      
    case 'G':
      {
	char var[100];
	int st=0, cy=0;
	if ( !optarg || sscanf(optarg,"%[^, ],%d,%d",
			       &var[0], &cy, &st)<2 || st<0 || cy<0 )
	  yap_quit("Need a valid 'G' argument\n");
	par = findpar(var);
	if ( par==ParNone || par==ParB0P || par==ParB0M )
	  yap_quit("Illegal var for -G\n");
        ddT[par].fix = 0;
	ddT[par].start = st;
	ddT[par].cycles = cy;
      }
      break;
    case 'h':
      {
	fix_hold = GibbsHold;
	if ( !optarg  )
	  yap_quit("Need a valid 'h' argument\n");
        if ( strncmp(optarg,"dict,",5)==0 ) {
          if ( sscanf(&optarg[5],"%d",&ddP.hold_dict)<1 || ddP.hold_dict<2 )
            yap_quit("Need a valid 'hdict' argument\n");
        } else if ( strncmp(optarg,"fract,",6)==0 ) {
          if ( sscanf(&optarg[6],"%lf",&ddP.hold_fraction)<1 
               || ddP.hold_fraction<=0 || ddP.hold_fraction>=1 )
            yap_quit("Need a valid 'hfract' argument\n");
        } else if ( strncmp(optarg,"doc,",4)==0 ) {
          if ( sscanf(&optarg[4],"%d",&ddP.hold_every)<1 || ddP.hold_every<2 )
            yap_quit("Need a valid 'hdoc' argument\n");
        } else
          yap_quit("Need a valid 'h' argument\n");
      }
      break;
   case 'K':
      if ( !optarg || sscanf(optarg,"%d",&ddN.T)!=1 )
	yap_quit("Need a valid 'K' argument\n");
      break;
    case 'l':
      if ( !optarg )
	yap_quit("Need a valid 'l ' argument\n");
      if ( strncmp(optarg,"phi,",4)==0 ) {
	if ( sscanf(&optarg[4],"%d,%d",&ddP.phiiter, &ddP.phiburn)<2 )
	  yap_quit("Need a valid 'l word,' argument\n");      
      } else if ( strncmp(optarg,"theta,",6)==0 ) {
	if ( sscanf(&optarg[6],"%d,%d",&ddP.thetaiter, &ddP.thetaburn)<2 )
	  yap_quit("Need a valid 'l word,' argument\n");      
      } else if ( strncmp(optarg,"mu,",3)==0 ) {
	if ( sscanf(&optarg[3],"%d,%d",&ddP.muiter, &ddP.muburn)<2 )
	  yap_quit("Need a valid 'l word,' argument\n");      
      } else if ( strncmp(optarg,"prog,",5)==0 ) {
	if ( sscanf(&optarg[5],"%d,%d",&ddP.progiter, &ddP.progburn)<2 )
	  yap_quit("Need a valid 'l prog,' argument\n");
      } else
	yap_quit("Need a valid DIAG code in 'l' argument\n");
      break;
    case 'L':
      if ( !optarg )
	yap_quit("Need a valid 'L ' argument\n");
      if ( strncmp(optarg,"like,",5)==0 ) {
	if ( sscanf(&optarg[5],"%d,%d",&ddP.mltiter, &ddP.mltburn)<1 )
	  yap_quit("Need a valid 'L like' argument\n");
      } else
	yap_quit("Need a valid DIAG code in 'L' argument\n");
      break;
    case 'N':
      if ( !optarg || sscanf(optarg,"%d,%d", &ddP.maxN, &ddP.maxM)<1 )
	yap_quit("Need a valid 'N' argument\n");
      break;
    case 'o':
      {
	char *ptr = strchr(optarg, ',');
	int len = strlen(optarg);
	if ( ptr ) 
	  len = ptr - optarg;
        if ( strncmp(optarg,"idf",len)==0 )
          score = ST_idf;
        else if ( strncmp(optarg,"count",len)==0 )
          score = ST_count;
        else if ( strncmp(optarg,"Q",len)==0 )
          score = ST_Q;
        else if ( strncmp(optarg,"cost",len)==0 )
          score = ST_cost;
        else
          yap_quit("Need a valid parameter for 'o' argument\n");
	if ( ptr ) {
	  /*  there was a second arg */
	  if ( sscanf(ptr+1, "%d", &topwords) != 1)
	    yap_quit("Need a valid second 'o' argument\n");
	}
      break;
      }
      break;
   case 'p':
      dopmi++;
      break;
   case 'q':
      if(!optarg || sscanf(optarg, "%d", &procs) != 1)
	yap_quit("Need a valid 'q' argument\n");
      break;
    case 'r':
      if(!optarg )
	yap_quit("Need a valid 'r' argument\n");
      if ( strcmp(optarg,"tca")==0 )
	restart++;
      else if ( strcmp(optarg,"hca")==0 )
	restart_hca++;
      else if ( strcmp(optarg,"phi")==0 )
	load_phi++;
      else if ( strcmp(optarg,"mu")==0 )
	load_mu++;
      else
	yap_quit("Need a valid 'r' argument\n");
      break;
    case 's':
      if ( !optarg || sscanf(optarg,"%d",&seed)!=1 )
	yap_quit("Need a valid 's' argument\n");
      break;
    case 'S':
      {
	char var[100];
	double vin=0;
	if ( !optarg || sscanf(optarg,"%[^=, ]=%lf",
			       &var[0], &vin)<2  )
	  yap_quit("Need a valid 'S' argument\n");
	par = findpar(var);
	if ( par==ParNone )
	  yap_quit("Illegal var for -S\n");
	else if ( par==ParBM0 ) 
	  BM0val = vin;
	else if ( par==ParBM1 ) 
	  BM1val = vin;
	else if ( par==ParBP0 ) 
	  BP0val = vin;
	else if ( par==ParBP1 ) 
	  BP1val = vin;
	else
	  *(ddT[par].ptr) = vin;
      }   
      break;
    case 't':
      if ( !optarg || sscanf(optarg,"%d",&ddP.training)!=1 )
	yap_quit("Need a valid 't' argument\n");
      break;
    case 'T':
      if ( !optarg )
	yap_quit("Need a valid 'T' argument\n");
      {
	char *tname = data_name(optarg,data);
	FILE *fp = fopen(tname,"r");
	if ( fp==NULL ) {
          free(tname);
	  tname = data_name(optarg,testdata);
	  fp = fopen(tname,"r");
        } else {
	  testdata = data;
        }
        free(tname);
	if ( fp!=NULL ) {
	  /*  its a valid test filename */
          ddP.teststem = optarg;
	  fclose(fp);
	} else if ( sscanf(optarg,"%d",&ddN.TEST)!=1 )
	  yap_quit("Need a valid 'T' argument\n");
      }
      break;
    case 'v':
      verbose++;
      break;
    case 'V':
      load_vocab = 1;
      break;
    case 'W':
      if ( !optarg || sscanf(optarg,"%d",&maxW)<1 )
	yap_quit("Need a valid 'W' argument\n");
      break;
    default:
      yap_quit("Unknown option '%c'\n", c);
    }
  }

  if (argc-optind != 2) {
    usage();
    exit(-1);
  }
  if ( optind>=argc ) {
    yap_quit("No arguments given\n");
  }
  stem = strdup(argv[optind++]);
  resstem = strdup(argv[optind++]);

  if ( dopmi )
    load_vocab = 1;
  if ( dopmi && verbose !=2 ) {
    /*  
     *   due to the use of the ".top" file
     *   its really multi-purpose 
     */
    yap_quit("When computing PMI verbose must be exactly 2\n");
  }

  if ( noerrorlog==0 ) {
    char *wname = yap_makename(resstem, ".log");
    yap_file(wname);
    free(wname);
  }
  
  yap_commandline(argc, argv);
#ifdef H_THREADS
  yap_message(" Threads,");
#endif

  if ( restart || restart_hca ) {
    char *fname = yap_makename(resstem,".par");
    FILE *fp = fopen(fname,"r");
    char *buf;
    if ( !fp ) 
      yap_quit("Parameter file '%s' doesn't exist\n", fname);
    fclose(fp);
    free(fname);
    buf = readpar(resstem,"T",50);
    if ( !buf ) 
      yap_quit("Parameter file '%s' has no T\n", fname);
    ddN.T = atoi(buf);
    free(buf);
    if ( restart ) {
      buf = readpar(resstem,"E",50);
      if ( !buf ) 
	yap_quit("Parameter file '%s' has no E\n", fname);
      ddN.E = atoi(buf);
      free(buf);
      pctl_read(resstem);
    }
    if ( maxW==0 ) {
      buf = readpar(resstem,"W",50);
      if ( buf ) {
	maxW = atoi(buf);
	free(buf);
      }
    }
    if ( ddP.training==0 ) {
      buf = readpar(resstem,"TRAIN",50);
      if ( buf ) {
	ddP.training = atoi(buf);
	free(buf);
      } 
    }
    if ( ddN.TEST==0 ) {
      buf = readpar(resstem,"TEST",50);
      if ( buf ) {
	ddN.TEST = atoi(buf);
	free(buf);
      }
    }
  } 

  assert(ddN.T>0);
  assert(ddN.TEST>=0);
  assert(restart || restart_hca || ITER>0);
	
  if ( load_phi && ddP.phiiter>0 )
    yap_quit("Options '-l phi,...' and '-r phi' incompatible\n");
  if ( load_mu && ddP.muiter>0 )
    yap_quit("Options '-l mu,...' and '-r mu' incompatible\n");

  /*
   *   set random number generator
   */
  if ( seed ) {
    rng_seed(rngp,seed);
  } else {
    rng_time(rngp,&seed);
  }
  yap_message("Setting seed = %lu\n", seed);
  
  /*
   *  read data and get dimensions
   */
  {
    D_bag_t *dbp = data_read(stem, data);
    int training = pctl_training(dbp->D);
    if ( ddP.teststem ) {
      D_bag_t *dbpt = data_read(ddP.teststem, testdata);
      /* need to load a separate test set, strip to bare training */
      data_shrink(dbp, training);
      ddN.TEST = dbpt->D;
      data_append(dbp, dbpt);
      free(dbpt->w);  free(dbpt->d); free(dbpt);
    }
    if ( maxW>0 ) {
      if ( dbp->W <= maxW ) 
        dbp->W = maxW;
      if ( dbp->W > maxW )
        data_vocabshrink(dbp, maxW);
    }
    /*
     *  transfer into system
     */
    ddN.D = dbp->D;
    ddN.W = dbp->W;    
    ddN.N = dbp->N;
    ddN.NT = dbp->N;
    ddN.DT = training;
    ddD.w = dbp->w;
    ddD.d = dbp->d;
    free(dbp);
    if ( ddN.DT<ddN.D ) {
      /*  recompute NT */
      int i;
      for (i=0; i<ddN.N; i++)
        if ( ddD.d[i]>=ddN.DT )
          break;
      ddN.NT = i;
    }
  }

  data_read_epoch(stem);

  /*
   *  at this point, dimensions are fixed, so load phi and mu if needed
   */
  if ( load_phi )
    pctl_loadphi(resstem);
  if ( load_mu )
    pctl_loadmu(resstem);

  /*
   *   correct parameters after command line
   */
  pctl_fix(ITER);
  if ( BM0val>0 ) {
    ddP.b_mu[0] = BM0val;
  }
  if ( BM1val>0 ) {
    int i;
    for (i=1; i<ddN.E; i++)
      ddP.b_mu[i] = BM1val;
  }
  if ( BP0val>0 ) {
    int i;
    for (i=0; i<ddN.T; i++)
      ddP.b_phi[0][i] = BP0val;
  }
  if ( BP1val>0 ) {
    int i;
    if ( ddN.E==1 )
      yap_quit("b_phi[1] invalid when epochs==1\n");
    for (i=0; i<ddN.T; i++)
      ddP.b_phi[1][i] = BP1val;
  }
  pctl_samplereport();

  /*
   *   all data structures
   */
  data_alloc();
  if ( ddP.phiiter>0 )
    phi_init(resstem);
  else 
    ddS.phi = NULL;
  if ( ddP.muiter>0 )
    mu_init(resstem);
  else 
    ddS.mu = NULL;
  if ( ddP.thetaiter>0 )
    theta_init(resstem);
  else 
    ddS.theta = NULL;
  tca_alloc();
  if ( PCTL_BURSTY() ) 
    dmi_init(&ddM, ddS.z, ddD.w, ddD.N_dTcum,
             ddN.T, ddN.N, ddN.W, ddN.D, ddN.DT,
	     (fix_hold==GibbsHold)?pctl_hold:NULL);
  if ( load_vocab ) {
    data_vocab(stem);
  }

  cache_init();
  
  /*
   *  yap some details
   */
  data_report(ITER, seed);
  pctl_report();
 
  /*
   *  load/init topic assignments and prepare statistics
   */
  if ( restart || restart_hca) {
    tca_read_z(resstem, 0, ddN.DT);
    tca_rand_z(ddN.T, ddN.DT, ddN.D);
  } else {
    tca_rand_z(ddN.T, 0, ddN.D);
  }
  tca_reset_stats(resstem, restart, 0);

  if ( (restart || restart_hca ) && ITER ) 
      yap_message("Initial log_2(perp)=%lf\n", -M_LOG2E * likelihood()/ddN.NT);

  if ( ITER )
      yap_report("cycles: ");
  
  for (iter=0; iter<ITER; iter++) {
    int  pro;
    double thislp = 0;
    int   thisNd = 0;
    int doc;
#ifdef H_THREADS
    pthread_t thread[procs];
#endif
    D_pargs_p parg[procs];
    
#ifdef MU_CACHE
    mu_side_fact_reinit();
#endif
#ifdef PHI_CACHE
    phi_cache_reinit();
#endif

    t1 = clock();
    
    /*
     *  sampling
     */
#ifdef IND_STATS
    ddP.doc_ind_stats = u32tri(ddN.T,ddN.E,ddN.E);
    ddP.word_ind_stats = u32tri(ddN.T,ddN.E,ddN.E);
#endif

   /*  a bit complex if no threads!  */
    doc = 0;
    for (pro = 0 ; pro < procs ; pro++){
      parg[pro].dots=dots;
      parg[pro].procs=procs;
      parg[pro].doc = &doc;
#ifndef H_THREADS
      sampling_p(&parg[pro]);
#else
      if ( procs==1 ) 
	sampling_p(&parg[pro]);
      else if( pthread_create(&thread[pro],NULL,sampling_p,(void*) &parg[pro]) != 0){
        yap_message("thread failed %d\n",pro+1 );
      }
#endif
    }
#ifdef H_THREADS
    if ( procs>1 ) {
       //waiting for threads to finish
       for (pro = 0; pro < procs; pro++){
         pthread_join(thread[pro], NULL);
       }
    }
#endif

    // getting lp, Nd and clock
    for(pro = 0; pro < procs; pro++){
      thislp +=  parg[pro].thislp;
      thisNd +=  parg[pro].thisNd;
      tot_time += parg[pro].tot_time;
    }
#ifdef H_THREADS
    if ( procs>1 )
      tca_reset_stats(NULL,1,1);
#endif
    /*
     *  full check
     */
#ifndef NDEBUG
    {
      int e, d;
      check_cp_et();
      for (e=0; e<ddN.E; e++)
        check_m_vte(e);
      for (d=0; d<ddN.DT; d++)
        check_n_dt(d);
    }
#endif

#ifdef IND_STATS
    {
      char *fname = yap_makename(resstem,".istats");
      FILE *ifp = fopen(fname,"a");
      int e1, e2, kk;
      fprintf(ifp,"Iteration %d\n", iter);
      for (kk=0; kk<ddN.T; kk++) {
	fprintf(ifp," Topic %d\n", kk);
	for (e1=0; e1<ddN.E; e1++) {
	  fprintf(ifp,"  Epoch %d\n     ", e1);
	  for (e2=0; e2<ddN.E; e2++)
	    fprintf(ifp," %u", (unsigned)ddP.doc_ind_stats[kk][e1][e2]);
	  fprintf(ifp,"\n     ");
	  for (e2=0; e2<ddN.E; e2++)
	    fprintf(ifp," %u", (unsigned)ddP.word_ind_stats[kk][e1][e2]);
	  fprintf(ifp,"\n");
	}
      }
      fclose(ifp);
      free(ddP.doc_ind_stats[0][0]); free(ddP.doc_ind_stats[0]); 
      free(ddP.doc_ind_stats); 
      free(ddP.word_ind_stats[0][0]); free(ddP.word_ind_stats[0]); 
      free(ddP.word_ind_stats);
      free(fname);
    }
#endif
    
    /*
     *   sample hyperparameters
     */
    t3 = clock();
    pctl_sample(iter, procs);
   
    /*
     *   do time calcs here to remove diagnostics+reporting
     */
    t2 = clock();
    tot_time += (double)(t2 - t1) / CLOCKS_PER_SEC;
    psample_time += (double)(t2 - t3) / CLOCKS_PER_SEC;
    /*
     *   progress reports
     */
    if ( ( iter>ddP.progburn && (iter%ddP.progiter)==0 ) || iter+1>=ITER ) {
      yap_message(" %d\nlog_2(perp)=%lf,%lf", iter, 
		  -M_LOG2E * likelihood()/ddN.NT, -M_LOG2E * thislp/thisNd);
      pctl_update(iter);
      if ( verbose && iter%10==0 )
	yap_probs();
      if ( iter>0 && verbose>1 ) {
	if ( ddN.tokens ) {
	  tca_displaytopics(resstem,topwords,score);
	  displayed++;
	}
      }
      if ( iter+1<ITER ) {
	// yap_message("\n");
	yap_report("cycles: ");
      }
    } else {
      yap_message(" %d", iter);
      if ( verbose>1)  yap_message("\n");
    }
  
    if ( checkpoint>0 && iter>0 && iter%checkpoint==0 ) {
      data_checkpoint(resstem, stem, iter+1);
      yap_message(" checkpointed\n");
      tca_report(resstem, stem, ITER, procs, fix_hold, 
		 (dopmi&&displayed>0)?1:0);
    }
    if ( ddP.phiiter>0 && iter>ddP.phiburn && (iter%ddP.phiiter)==0 )
      phi_update();
    if ( ddP.thetaiter>0 && iter>ddP.thetaburn && (iter%ddP.thetaiter)==0 )
      theta_update();
    if ( ddP.muiter>0 && iter>ddP.muburn && (iter%ddP.muiter)==0 )
      mu_update();
  } // over iter
  
  if ( ITER ) 
      yap_report("Finished after %d cycles on average of %lf+%lf(s) per cycle\n",
	     iter,  (tot_time-psample_time)/iter, psample_time/iter);
  
  if ( ( verbose==1 || ((iter+1)%5!=0 && verbose>1) ) ) {
    if ( ddN.tokens ) {
       tca_displaytopics(resstem,topwords,score);
       displayed++;
    }
  }

  yap_probs();

  if ( ITER>0 ) 
	data_checkpoint(resstem, stem, ITER);
 
  tca_report(resstem, stem, ITER, procs, fix_hold, (dopmi&&displayed>0)?1:0);

  if ( ddP.phiiter>0 )
      phi_save(resstem);
  if ( ddP.thetaiter>0 )
      theta_save(resstem);
  if ( ddP.muiter>0 )
      mu_save(resstem);

  /*
   *  free
   */
  phi_free();
  theta_free();
  mu_free();
  cache_free();
  pctl_free();
  data_free();
  dmi_free(&ddM);
  tca_free();
  free(stem);
  free(resstem);
  rng_free(rngp);

  return 0;
}