Exemplo n.º 1
0
void Group_Create_OnInitDialog (HWND hDlg)
{
   LPCREATEGROUPDLG lpp = (LPCREATEGROUPDLG)GetWindowLongPtr (hDlg, DWLP_USER);

   // Fix the title of the dialog
   //
   ULONG status;
   TCHAR szName[ cchNAME ];
   asc_CellNameGet_Fast (g.idClient, g.idCell, szName, &status);

   TCHAR szText[ cchRESOURCE ];
   GetDlgItemText (hDlg, IDC_NEWGROUP_TITLE, szText, cchRESOURCE);

   LPTSTR pszText = FormatString (szText, TEXT("%s"), szName);
   SetDlgItemText (hDlg, IDC_NEWGROUP_TITLE, pszText);
   FreeString (pszText);

   // Attach a spinner to the ID control
   //
   CheckDlgButton (hDlg, IDC_NEWGROUP_ID_AUTO, TRUE);
   CreateSpinner (GetDlgItem (hDlg, IDC_NEWGROUP_ID), 10, TRUE, -0x7FFFFFFF, -1, -1);
   Group_Create_OnID (hDlg);

   StartTask (taskOBJECT_GET, hDlg, (PVOID)(g.idCell));
}
Exemplo n.º 2
0
void Elapsed_Edit_OnSetFocus (ElapsedInfo *pei, HWND hEdit)
{
   pei->fCanCallBack --;

   RECT rSpinner;
   GetRectInParent (pei->hElapsed, &rSpinner);
   rSpinner.left = rSpinner.right;
   rSpinner.right = rSpinner.left + GetSystemMetrics (SM_CXVSCROLL);
   rSpinner.bottom -= 2; // just like Win95 does

   DWORD dwMin;
   DWORD dwPos;
   DWORD dwMax;
   Elapsed_Edit_GetSpinnerRange (pei, hEdit, &dwMin, &dwPos, &dwMax);

   CreateSpinner (hEdit, 10, FALSE, dwMin, dwPos, dwMax, &rSpinner);
   if (pei->hSpinner)
      DestroyWindow (pei->hSpinner);

   if (hEdit == pei->hHours)
      SP_SetFormat (hEdit, TEXT("%lu"));
   else
      SP_SetFormat (hEdit, TEXT("%02lu"));

   pei->hSpinner = SP_GetSpinner (hEdit);
   pei->hSpinnerBuddy = hEdit;

   SendMessage (hEdit, EM_SETSEL, (WPARAM)0, (LPARAM)-1);  // select all

   pei->fCanCallBack ++;
}
Exemplo n.º 3
0
void Misc_OnInitDialog (HWND hDlg)
{
   if (fFirstTime) {
#if undef
      Config_GetLanAdapter(&g.Configuration.nLanAdapter);
#endif
      Config_GetProbeInt (&g.Configuration.csecProbe);
      Config_GetNumThreads (&g.Configuration.nThreads);
      Config_GetNumDaemons (&g.Configuration.nDaemons);
      Config_GetSysName (g.Configuration.szSysName);
      Config_GetRootVolume (g.Configuration.szRootVolume);
      Config_GetMountRoot (g.Configuration.szMountDir);

#if undef
      nLanAdapter = g.Configuration.nLanAdapter;
#endif
      csecProbe = g.Configuration.csecProbe;
      nThreads = g.Configuration.nThreads;
      nDaemons = g.Configuration.nDaemons;
      lstrcpy(szSysName, g.Configuration.szSysName);
      lstrcpy(szRootVolume, g.Configuration.szRootVolume);
      lstrcpy(szMountDir, g.Configuration.szMountDir);

      fFirstTime = FALSE;
   }

#if undef
   CreateSpinner (GetDlgItem (hDlg, IDC_LAN_ADAPTER), 99, FALSE, nLANA_MIN, nLanAdapter, nLANA_MAX);
#endif
   CreateSpinner (GetDlgItem (hDlg, IDC_PROBE), 10, FALSE, csecPROBE_MIN, csecProbe, csecPROBE_MAX);
   CreateSpinner (GetDlgItem (hDlg, IDC_THREADS), 10, FALSE, cTHREADS_MIN, nThreads, cTHREADS_MAX);
   CreateSpinner (GetDlgItem (hDlg, IDC_DAEMONS), 10, FALSE, cDAEMONS_MIN, nDaemons, cDAEMONS_MAX);

   SetDlgItemText (hDlg, IDC_SYSNAME, szSysName);
   SetDlgItemText (hDlg, IDC_ROOTVOLUME, szRootVolume);
   SetDlgItemText (hDlg, IDC_MOUNTDIR, szMountDir);
#if undef
   CheckDlgButton (hDlg, IDC_AUTOLANA, (nLanAdapter==-1));
   EnableWindow(GetDlgItem(hDlg,IDC_LAN_ADAPTER),(nLanAdapter!=-1));
#endif
}
Exemplo n.º 4
0
void Diag_OnInitDialog (HWND hDlg)
{
   if (fFirstTime) {
      Config_GetTraceBufferSize(&g.Configuration.nTraceBufSize);
      Config_GetTrapOnPanic(&g.Configuration.fTrapOnPanic);
      Config_GetReportSessionStartups(&g.Configuration.fReportSessionStartups);
      
      nTraceBufSize = g.Configuration.nTraceBufSize;
      fTrapOnPanic = g.Configuration.fTrapOnPanic;
      fReportSessionStartups = g.Configuration.fReportSessionStartups;
      
      fFirstTime = FALSE;
   }

   CreateSpinner (GetDlgItem (hDlg, IDC_TRACE_LOG_BUF_SIZE), 10, FALSE, nBUFSIZE_MIN, nTraceBufSize, nBUFSIZE_MAX);

   SetUpYesNoCombo(hDlg, IDC_TRAP_ON_PANIC, fTrapOnPanic);
   SetUpYesNoCombo(hDlg, IDC_REPORT_SESSION_STARTUPS, fReportSessionStartups);
}
Exemplo n.º 5
0
void Server_Salvage_OnInitDialog (HWND hDlg, LPIDENT lpi)
{
   CheckDlgButton (hDlg, IDC_AGGREGATE_ALL, (lpi->fIsServer()) ? TRUE : FALSE);
   CheckDlgButton (hDlg, IDC_FILESET_ALL,  (lpi->fIsFileset()) ? FALSE : TRUE);

   EnableWindow (GetDlgItem (hDlg, IDC_SERVER), FALSE);
   EnableWindow (GetDlgItem (hDlg, IDC_AGGREGATE), FALSE);
   EnableWindow (GetDlgItem (hDlg, IDC_AGGREGATE_ALL), FALSE);
   EnableWindow (GetDlgItem (hDlg, IDC_FILESET), FALSE);
   EnableWindow (GetDlgItem (hDlg, IDC_FILESET_ALL), FALSE);
   EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);

   LPSVR_ENUM_TO_COMBOBOX_PACKET lpp = New (SVR_ENUM_TO_COMBOBOX_PACKET);
   memset (lpp, 0x00, sizeof(SVR_ENUM_TO_COMBOBOX_PACKET));
   lpp->hCombo = GetDlgItem (hDlg, IDC_SERVER);
   lpp->lpiSelect = lpi->GetServer();
   StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lpp);

   CheckDlgButton (hDlg, IDC_SALVAGE_SIMUL, TRUE);
   CreateSpinner (GetDlgItem(hDlg,IDC_SALVAGE_NUM), 10, FALSE, 2, 4, 12);
}
Exemplo n.º 6
0
void Filesets_Create_OnEndTask_FindQuotaLimits (HWND hDlg, LPTASKPACKET ptp, LPSET_CREATE_PARAMS pscp)
{
   size_t cMin = TASKDATA(ptp)->ckMin;
   size_t cNow = pscp->ckQuota;
   size_t cMax = TASKDATA(ptp)->ckMax;

   if (gr.cbQuotaUnits == cb1MB)
      {
      cMin /= ck1MB;
      cNow /= ck1MB;
      cMax /= ck1MB;
      }

   HWND hQuota = GetDlgItem (hDlg, IDC_SET_QUOTA);
   if (!fHasSpinner (hQuota))
      {
      CreateSpinner (hQuota, 10, FALSE, (DWORD)cMin, (DWORD)cNow, (DWORD)cMax);
      }
   else
      {
      SP_SetRange (hQuota, cMin, cMax);
      SP_SetPos (hQuota, cNow);
      }
}
Exemplo n.º 7
0
void Server_Scout_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp)
{
   LPIDENT lpiServer = (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER);

   if (!ptp->rc)
      {
      TCHAR szText[ cchNAME ];
      lpiServer->GetServerName (szText);
      ErrorDialog (ptp->status, IDS_ERROR_REFRESH_SERVER_STATUS, TEXT("%s"), szText);
      }
   else
      {
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_AGGFULL), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_AGGFULL_PERCENT), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_SETFULL), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_SETFULL_PERCENT), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_AGGALLOC), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_SVCSTOP), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_TIMEOUT), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_SETNOVLDB), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_SETNOSERV), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_WARN_AGGNOSERV), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_AUTOREFRESH), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SVR_AUTOREFRESH_MINUTES), TRUE);

      CheckDlgButton (hDlg, IDC_SVR_WARN_AGGFULL, (TASKDATA(ptp)->lpsp->perWarnAggFull != 0));
      CheckDlgButton (hDlg, IDC_SVR_WARN_SETFULL, (TASKDATA(ptp)->lpsp->perWarnSetFull != 0));
      CheckDlgButton (hDlg, IDC_SVR_WARN_AGGALLOC, TASKDATA(ptp)->lpsp->fWarnAggAlloc);
      CheckDlgButton (hDlg, IDC_SVR_WARN_SVCSTOP, TASKDATA(ptp)->lpsp->fWarnSvcStop);
      CheckDlgButton (hDlg, IDC_SVR_WARN_TIMEOUT, TASKDATA(ptp)->lpsp->fWarnSvrTimeout);
      CheckDlgButton (hDlg, IDC_SVR_WARN_SETNOVLDB, TASKDATA(ptp)->lpsp->fWarnSetNoVLDB);
      CheckDlgButton (hDlg, IDC_SVR_WARN_SETNOSERV, TASKDATA(ptp)->lpsp->fWarnSetNoServ);
      CheckDlgButton (hDlg, IDC_SVR_WARN_AGGNOSERV, TASKDATA(ptp)->lpsp->fWarnAggNoServ);

      CheckDlgButton (hDlg, IDC_SVR_AUTOREFRESH, (TASKDATA(ptp)->lpsp->oa.cTickRefresh != 0));

      CreateSpinner (GetDlgItem (hDlg, IDC_SVR_AUTOREFRESH_MINUTES),
                     10, FALSE,  // base, signed
                     1,
                     TASKDATA(ptp)->lpsp->oa.cTickRefresh / cmsec1MINUTE,
                     60L * 24L);  // maximum refresh rate of one day

      Server_Scout_OnAutoRefresh (hDlg, lpiServer);


      CreateSpinner (GetDlgItem (hDlg, IDC_SVR_WARN_AGGFULL_PERCENT),
                     10, FALSE,  // base, signed
                     1,
                     (TASKDATA(ptp)->lpsp->perWarnAggFull == 0) ? perDEFAULT_AGGFULL_WARNING : TASKDATA(ptp)->lpsp->perWarnAggFull,
                     100L);

      Server_Scout_OnAggWarn (hDlg, lpiServer);

      CreateSpinner (GetDlgItem (hDlg, IDC_SVR_WARN_SETFULL_PERCENT),
                     10, FALSE,  // base, signed
                     1,
                     (TASKDATA(ptp)->lpsp->perWarnSetFull == 0) ? perDEFAULT_SETFULL_WARNING : TASKDATA(ptp)->lpsp->perWarnSetFull,
                     100L);

      Server_Scout_OnSetWarn (hDlg, lpiServer);
      }
}
Exemplo n.º 8
0
void Filesets_General_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPIDENT lpi)
{
   LPTSTR pszText;

   TCHAR szUnknown[ cchRESOURCE ];
   GetString (szUnknown, IDS_UNKNOWN);

   if (!ptp->rc)
      {
      SetDlgItemText (hDlg, IDC_SET_CREATEDATE, szUnknown);
      SetDlgItemText (hDlg, IDC_SET_UPDATEDATE, szUnknown);
      SetDlgItemText (hDlg, IDC_SET_ACCESSDATE, szUnknown);
      SetDlgItemText (hDlg, IDC_SET_BACKUPDATE, szUnknown);
      SetDlgItemText (hDlg, IDC_SET_USAGE, szUnknown);
      SetDlgItemText (hDlg, IDC_SET_STATUS, szUnknown);
      SetDlgItemText (hDlg, IDC_SET_FILES, szUnknown);

      TCHAR szSvrName[ cchNAME ];
      TCHAR szAggName[ cchNAME ];
      TCHAR szSetName[ cchNAME ];
      lpi->GetServerName (szSvrName);
      lpi->GetAggregateName (szAggName);
      lpi->GetFilesetName (szSetName);
      ErrorDialog (ptp->status, IDS_ERROR_REFRESH_FILESET_STATUS, TEXT("%s%s%s"), szSvrName, szAggName, szSetName);
      }
   else
      {
      TCHAR szText[ cchRESOURCE ];

      EnableWindow (GetDlgItem (hDlg, IDC_SET_LOCK), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_UNLOCK), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_QUOTA), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), TRUE);
      EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), TRUE);

      if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeCreation))
         SetDlgItemText (hDlg, IDC_SET_CREATEDATE, szUnknown);
      else
         SetDlgItemText (hDlg, IDC_SET_CREATEDATE, szText);

      if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeLastUpdate))
         SetDlgItemText (hDlg, IDC_SET_UPDATEDATE, szUnknown);
      else
         SetDlgItemText (hDlg, IDC_SET_UPDATEDATE, szText);

      if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeLastAccess))
         SetDlgItemText (hDlg, IDC_SET_ACCESSDATE, szUnknown);
      else
         SetDlgItemText (hDlg, IDC_SET_ACCESSDATE, szText);

      if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeLastBackup))
         SetDlgItemText (hDlg, IDC_SET_BACKUPDATE, szUnknown);
      else
         SetDlgItemText (hDlg, IDC_SET_BACKUPDATE, szText);

      wsprintf (szText, TEXT("%lu"), TASKDATA(ptp)->fs.nFiles);
      SetDlgItemText (hDlg, IDC_SET_FILES, szText);

      size_t nAlerts = Alert_GetCount (lpi);
      if (nAlerts == 1)
         {
         GetString (szText, IDS_SETSTATUS_1ALERT);
         SetDlgItemText (hDlg, IDC_SET_STATUS, szText);
         }
      else if (nAlerts > 1)
         {
         pszText = FormatString (IDS_SETSTATUS_2ALERT, TEXT("%lu"), nAlerts);
         SetDlgItemText (hDlg, IDC_SET_STATUS, pszText);
         FreeString (pszText);
         }
      else // (nAlerts == 0)
         {
         if (TASKDATA(ptp)->fs.State & fsBUSY)
            GetString (szText, IDS_SETSTATUS_BUSY);
         else if (TASKDATA(ptp)->fs.State & fsSALVAGE)
            GetString (szText, IDS_SETSTATUS_SALVAGE);
         else if (TASKDATA(ptp)->fs.State & fsMOVED)
            GetString (szText, IDS_SETSTATUS_MOVED);
         else if (TASKDATA(ptp)->fs.State & fsLOCKED)
            GetString (szText, IDS_SETSTATUS_LOCKED);
         else if (TASKDATA(ptp)->fs.State & fsNO_VOL)
            GetString (szText, IDS_SETSTATUS_NO_VOL);
         else
            GetString (szText, IDS_STATUS_NOALERTS);
         SetDlgItemText (hDlg, IDC_SET_STATUS, szText);
         }

      if (TASKDATA(ptp)->fs.Type == ftREADWRITE)
         {
         Filesets_DisplayQuota (hDlg, &TASKDATA(ptp)->fs);
         }
      else
         {
         if (TASKDATA(ptp)->fs.Type == ftREPLICA)
            GetString (szText, IDS_USAGE_REPLICA);
         else // (TASKDATA(ptp)->fs.Type == ftCLONE)
            GetString (szText, IDS_USAGE_CLONE);

         pszText = FormatString (szText, TEXT("%.1B"), (double)TASKDATA(ptp)->fs.ckUsed * cb1KB);
         SetDlgItemText (hDlg, IDC_SET_USAGE, pszText);
         FreeString (pszText);

         if (GetDlgItem (hDlg, IDC_SET_USAGEBAR))
            {
            RECT rUsagebar;
            GetRectInParent (GetDlgItem (hDlg, IDC_SET_USAGEBAR), &rUsagebar);

            HFONT hf = (HFONT)SendMessage (GetDlgItem (hDlg, IDC_SET_USAGEBAR), WM_GETFONT, 0, 0);
            DestroyWindow (GetDlgItem (hDlg, IDC_SET_USAGEBAR));

            if (TASKDATA(ptp)->fs.Type == ftREPLICA)
               GetString (szText, IDS_NO_QUOTA_REPLICA);
            else // (TASKDATA(ptp)->fs.Type == ftCLONE)
               GetString (szText, IDS_NO_QUOTA_CLONE);

            HWND hDesc = CreateWindow (TEXT("static"),
                          szText,
                          WS_CHILD | SS_SIMPLE,
                          rUsagebar.left, rUsagebar.top,
                          cxRECT(rUsagebar), cyRECT(rUsagebar),
                          hDlg,
                          (HMENU)-1,
                          THIS_HINST,
                          0);
            SendMessage (hDesc, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
            ShowWindow (hDesc, SW_SHOW);
            }

         EnableWindow (GetDlgItem (hDlg, IDC_SET_QUOTA), FALSE);
         EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN), FALSE);
         EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), FALSE);
         EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), FALSE);
         EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), FALSE);
         EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), FALSE);
         }

      if (TASKDATA(ptp)->lpsp->perWarnSetFull == 0)
         {
         GetString (szText, IDS_SETFULL_WARN_OFF);
         SetDlgItemText (hDlg, IDC_SET_WARN_SETFULL_DEF, szText);
         }
      else
         {
         GetString (szText, IDS_SETFULL_WARN_ON);
         pszText = FormatString (szText, TEXT("%lu"), TASKDATA(ptp)->lpsp->perWarnSetFull);
         SetDlgItemText (hDlg, IDC_SET_WARN_SETFULL_DEF, pszText);
         FreeString (pszText);
         }

      CheckDlgButton (hDlg, IDC_SET_WARN, (TASKDATA(ptp)->lpfp->perWarnSetFull != 0));
      if (TASKDATA(ptp)->lpfp->perWarnSetFull != 0)
         {
         if (TASKDATA(ptp)->lpfp->perWarnSetFull != -1)
            CheckDlgButton (hDlg, IDC_SET_WARN_SETFULL, TRUE);
         else
            CheckDlgButton (hDlg, IDC_SET_WARN_SETFULL_DEF, TRUE);
         }

      CreateSpinner (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT),
                     10, FALSE,   // base, signed
                     1,
                     (TASKDATA(ptp)->lpfp->perWarnSetFull == 0 || TASKDATA(ptp)->lpfp->perWarnSetFull == -1) ? perDEFAULT_SETFULL_WARNING : TASKDATA(ptp)->lpfp->perWarnSetFull,
                     100); // min, default, max

      Filesets_General_OnWarnings (hDlg, lpi);
      }
}
Exemplo n.º 9
0
void            Optimize(double *x, int n, void (*df) (const double *, double *, void *),
                     double (*f) (const double *, void *), double *fx, void *data,
		     double *bd, int noisy, const bool writeTemp, const bool readTemp)
{
	OPTOBJ         *opt;
	double          fo, fn, tol, md;
	int             i, max_step;
	int             max_restart, restarts;
	char           *errstring = NULL;
	double          fact;
	double         *scale;
	SPINNER        *spin;
	int             newbound = 1;
	bool tempOk = true;


	opt = NewOpt(n);
	if (NULL == opt) {
		return;
	}
	InitializeOpt(opt, x, n, df, f, *fx, data, bd);
	if (readTemp){
                FILE * fp = fopen(TEMPFILE,"r");
                if(NULL==fp){
                        errx(EXIT_FAILURE,"Failed from read from temporary file");
                }
                fread(opt->x,sizeof(double),n,fp);
		fread(opt->dx,sizeof(double),n,fp);
		fread(((struct scaleinfo * )opt->state)->scale,sizeof(double),n,fp);
		fread(&opt->fc,sizeof(double),1,fp);
                fclose(fp);
                for ( int i=0 ; i<n ; i++){
                        fprintf(stdout,"%e ",x[i]);
                }
                fputc('\n',stdout);
        }


	tol = 3e-8;
	max_step = 100;
	max_restart = 20;
	restarts = -1;

	/* Do optimization, allowing restarts so don't get bogged down. */

	if (noisy == 2) {
		printf("Initial\tf: %8.6f\nStep     f(x)      delta\n", opt->fc);
	} else if (noisy == 1) {
		spin = CreateSpinner(2);
	}
	do {
		fo = opt->fc;
		InitializeH(opt);
		fact = 1.;
		do {
			fn = opt->fc;
			errn = 0;
			md = TakeStep(opt, tol, &fact, &newbound);
			MakeErrString(&errstring, errn);
			step++;
			if ( calcerr(fn,opt->fc)<=tol){
			   OPTMESS( printf("Step was small. Trying steepest descent.\n");)
			   opt->fc = SteepestDescentStep(opt);
			   for ( int i=0 ; i<opt->n ; i++){ opt->x[i] = opt->xn[i]; }
			   opt->f(opt->x,opt->state); opt->neval++;
			   opt->df(opt->x, opt->dx, opt->state); opt->neval++;
			   for ( int i=0 ; i<opt->n ; i++){ opt->space[i] = -opt->dx[i];}
			   UpdateActiveSet (opt->x, opt->space, ((struct scaleinfo *) opt->state)->scale, opt->H,
			                                       opt->lb, opt->ub, opt->onbound, opt->n,&newbound);
			   InitializeH(opt);
			}
                        if (noisy == 2) {
                                printf("%3d: %9f %10.5e %4d %s\t%9.3f\n", step, opt->fc,
                                  fabs(opt->fc - fn), opt->neval, errstring, md);
                        } else if (noisy == 1) {
                                UpdateSpinner(spin);
                        }
			// Write temporary values to file
			if (writeTemp && tempOk){
				FILE * fp = fopen(TEMPFILE,"w");
				if(NULL==fp){
					warnx("Failed to open temporary file");
					tempOk = false;
				} else {
					fwrite(opt->x,sizeof(double),opt->n,fp);
					fwrite(opt->dx,sizeof(double),n,fp);
					fwrite(((struct scaleinfo * )opt->state)->scale,sizeof(double),n,fp);
					fwrite(&opt->fc,sizeof(double),1,fp);
					fclose(fp);
				}
			}

		} while ((calcerr(fn,opt->fc) > tol) || newbound );
Exemplo n.º 10
0
void Aggregates_General_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp)
{
   LPIDENT lpi = (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER);

   if (!ptp->rc)
      {
      TCHAR szUnknown[ cchRESOURCE ];
      GetString (szUnknown, IDS_UNKNOWN);
      SetDlgItemText (hDlg, IDC_AGG_ID,       szUnknown);
      SetDlgItemText (hDlg, IDC_AGG_DEVICE,   szUnknown);
      SetDlgItemText (hDlg, IDC_AGG_FILESETS, szUnknown);
      SetDlgItemText (hDlg, IDC_AGG_USAGE,    szUnknown);

      TCHAR szSvrName[ cchNAME ];
      TCHAR szAggName[ cchNAME ];
      lpi->GetServerName (szSvrName);
      lpi->GetAggregateName (szAggName);
      ErrorDialog (ptp->status, IDS_ERROR_REFRESH_AGGREGATE_STATUS, TEXT("%s%s"), szSvrName, szAggName);
      }
   else
      {
      TCHAR szText[ cchRESOURCE ];
      wsprintf (szText, TEXT("%lu"), TASKDATA(ptp)->as.dwID);
      SetDlgItemText (hDlg, IDC_AGG_ID, szText);

      SetDlgItemText (hDlg, IDC_AGG_DEVICE, TASKDATA(ptp)->pszText1);

      LPTSTR pszText = FormatString (IDS_AGG_FILESETS, TEXT("%lu%.1B"), TASKDATA(ptp)->nFilesets, (double)cb1KB * (double)(TASKDATA(ptp)->as.ckStorageAllocated));
      SetDlgItemText (hDlg, IDC_AGG_FILESETS, pszText);
      FreeString (pszText);

      double dUsed  = 1024.0 * (TASKDATA(ptp)->as.ckStorageTotal - TASKDATA(ptp)->as.ckStorageFree);
      double dTotal = 1024.0 * TASKDATA(ptp)->as.ckStorageTotal;
      DWORD dwPer   = 100;
      if (TASKDATA(ptp)->as.ckStorageTotal != 0)
         {
         dwPer = (DWORD)( 100.0 * (TASKDATA(ptp)->as.ckStorageTotal - TASKDATA(ptp)->as.ckStorageFree) / TASKDATA(ptp)->as.ckStorageTotal );
         dwPer = limit( 0, dwPer, 100 );
         }

      LPTSTR pszUsage = FormatString (IDS_USAGE_AGGREGATE, TEXT("%.1B%.1B%lu"), dUsed, dTotal, dwPer);
      SetDlgItemText (hDlg, IDC_AGG_USAGE, pszUsage);
      FreeString (pszUsage);

      SendDlgItemMessage (hDlg, IDC_AGG_USAGEBAR, PBM_SETRANGE, 0, MAKELPARAM(0,100));
      SendDlgItemMessage (hDlg, IDC_AGG_USAGEBAR, PBM_SETPOS, (WPARAM)dwPer, 0);

      if (TASKDATA(ptp)->lpsp->fWarnAggAlloc)
         {
         EnableWindow (GetDlgItem (hDlg, IDC_AGG_WARNALLOC), TRUE);
         CheckDlgButton (hDlg, IDC_AGG_WARNALLOC, TASKDATA(ptp)->lpap->fWarnAggAlloc);
         }

      EnableWindow (GetDlgItem (hDlg, IDC_AGG_WARN), TRUE);

      if (TASKDATA(ptp)->lpsp->perWarnAggFull == 0)
         {
         GetString (szText, IDS_AGGFULL_WARN_OFF);
         SetDlgItemText (hDlg, IDC_AGG_WARN_AGGFULL_DEF, szText);
         }
      else
         {
         pszText = FormatString (IDS_AGGFULL_WARN_ON, TEXT("%lu"), TASKDATA(ptp)->lpsp->perWarnAggFull);
         SetDlgItemText (hDlg, IDC_AGG_WARN_AGGFULL_DEF, pszText);
         FreeString (pszText);
         }

      CheckDlgButton (hDlg, IDC_AGG_WARN, (TASKDATA(ptp)->lpap->perWarnAggFull != 0));
      if (TASKDATA(ptp)->lpap->perWarnAggFull != 0)
         {
         if (TASKDATA(ptp)->lpap->perWarnAggFull != -1)
            CheckDlgButton (hDlg, IDC_AGG_WARN_AGGFULL, TRUE);
         else
            CheckDlgButton (hDlg, IDC_AGG_WARN_AGGFULL_DEF, TRUE);
         }

      CreateSpinner (GetDlgItem (hDlg, IDC_AGG_WARN_AGGFULL_PERCENT),
                     10, FALSE,   // base, signed
                     1,
                     (TASKDATA(ptp)->lpap->perWarnAggFull == 0 || TASKDATA(ptp)->lpap->perWarnAggFull == -1) ? perDEFAULT_AGGFULL_WARNING : TASKDATA(ptp)->lpap->perWarnAggFull,
                     100); // min, default, max

      Aggregates_General_OnWarnings (hDlg);
      }
}
Exemplo n.º 11
0
void Time_OnCreate (TimeInfo *pti)
{
   Subclass_AddHook (GetParent(pti->hTime), TimeDlgProc);

   TCHAR szTimeSep[ cchRESOURCE ];
   if (!GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_STIME, szTimeSep, cchRESOURCE))
      lstrcpy (szTimeSep, TEXT(":"));

   TCHAR sz24Hour[ cchRESOURCE ];
   if (!GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITIME, sz24Hour, cchRESOURCE))
      pti->f24Hour = FALSE;
   else
      pti->f24Hour = (sz24Hour[0] == TEXT('1')) ? TRUE : FALSE;

   TCHAR sz0Hour[ cchRESOURCE ];
   if (!GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_ITLZERO, sz0Hour, cchRESOURCE))
      pti->f0Hours = FALSE;
   else
      pti->f0Hours = (sz0Hour[0] == TEXT('1')) ? TRUE : FALSE;

   RECT rTime;
   GetClientRect (pti->hTime, &rTime);

   POINT ptTime = {0,0};
   ClientToScreen (pti->hTime, &ptTime);
   ScreenToClient (GetParent (pti->hTime), &ptTime);

   SIZE s88; // size of widest likely double-digit number
   SIZE sTimeSep; // size of ":"
   SIZE sAMPM; // size of "AM/PM" listbox
   TCHAR szAM[ cchRESOURCE ];
   TCHAR szPM[ cchRESOURCE ];

   HDC hdc = GetDC (GetParent (pti->hTime));
   GetTextExtentPoint (hdc, TEXT("88"), lstrlen(TEXT("88")), &s88);
   GetTextExtentPoint (hdc, szTimeSep, lstrlen(szTimeSep), &sTimeSep);
   if (!pti->f24Hour)
      Time_GetAMPMSize (hdc, &sAMPM, szAM, szPM);
   ReleaseDC (GetParent (pti->hTime), hdc);

   LONG cxNumbers = cxRECT(rTime) - GetSystemMetrics (SM_CXVSCROLL) - (sTimeSep.cx);
   if (!pti->f24Hour)
      cxNumbers -= sTimeSep.cx + sAMPM.cx;
   LONG cxMinutes = max( cxNumbers/2, s88.cx );
   LONG cxHours   = cxNumbers - cxMinutes;

   cxMinutes = min (cxMinutes, (LONG)( 1.2 * s88.cx ));
   cxHours   = min (cxHours,   (LONG)( 1.2 * s88.cx ));  // don't be TOO wide.

   LONG cy = cyRECT(rTime);
   LONG yy = ptTime.y;

   pti->idHours = 100+NextControlID (GetParent (pti->hTime));
   pti->hHours = CreateWindow (
                TEXT("EDIT"),
                TEXT(""),
                WS_CHILD | WS_TABSTOP | ES_MULTILINE | ES_RIGHT | ES_NUMBER,
                ptTime.x, yy, cxHours, cy,
                GetParent(pti->hTime),
                (HMENU)pti->idHours,
                THIS_HINST,
                0);

   pti->hSep1 = CreateWindow (
                TEXT("STATIC"),
                szTimeSep,
                WS_CHILD | SS_CENTER,
                ptTime.x + cxHours, yy, sTimeSep.cx, cy,
                GetParent(pti->hTime),
                (HMENU)-1,
                THIS_HINST,
                0);

   pti->idMinutes = 100+NextControlID (GetParent (pti->hTime));
   pti->hMinutes = CreateWindow (
                TEXT("EDIT"),
                TEXT(""),
                WS_CHILD | WS_TABSTOP | ES_MULTILINE | ES_RIGHT | ES_NUMBER,
                ptTime.x + cxHours + sTimeSep.cx, yy, cxMinutes, cy,
                GetParent(pti->hTime),
                (HMENU)pti->idMinutes,
                THIS_HINST,
                0);

   if (!pti->f24Hour)
      {
      pti->hSep2 = CreateWindow (
                   TEXT("STATIC"),
                   TEXT(""),
                   WS_CHILD | SS_CENTER,
                   ptTime.x + cxHours + cxMinutes + sTimeSep.cx, yy, sTimeSep.cx, cy,
                   GetParent(pti->hTime),
                   (HMENU)-1,
                   THIS_HINST,
                   0);

      pti->idAMPM = 100+NextControlID (GetParent (pti->hTime));
      pti->hAMPM = CreateWindow (
                   TEXT("LISTBOX"),
                   TEXT(""),
                   WS_CHILD | WS_TABSTOP | LBS_NOINTEGRALHEIGHT | LBS_HASSTRINGS | LBS_OWNERDRAWFIXED | LBS_NOTIFY,
                   ptTime.x + cxHours + cxMinutes + 2 * sTimeSep.cx, yy, sAMPM.cx, cy,
                   GetParent(pti->hTime),
                   (HMENU)pti->idAMPM,
                   THIS_HINST,
                   0);
      }

   Subclass_AddHook (pti->hHours, TimeEditProc);
   Subclass_AddHook (pti->hMinutes, TimeEditProc);

   if (!pti->f24Hour)
      Subclass_AddHook (pti->hAMPM, TimeEditProc);

   HFONT hf = (HFONT)SendMessage (GetParent (pti->hTime), WM_GETFONT, 0, 0);
   SendMessage (pti->hHours,   WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
   SendMessage (pti->hSep1,    WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
   SendMessage (pti->hMinutes, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));

   if (!pti->f24Hour)
      {
      SendMessage (pti->hSep2, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
      SendMessage (pti->hAMPM, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
      }

   EnableWindow (pti->hHours,   IsWindowEnabled (pti->hTime));
   EnableWindow (pti->hSep1,    IsWindowEnabled (pti->hTime));
   EnableWindow (pti->hMinutes, IsWindowEnabled (pti->hTime));

   if (!pti->f24Hour)
      {
      EnableWindow (pti->hSep2, IsWindowEnabled (pti->hTime));
      EnableWindow (pti->hAMPM, IsWindowEnabled (pti->hTime));

      LB_StartChange (pti->hAMPM, TRUE);
      LB_AddItem (pti->hAMPM, szAM, 0);
      LB_AddItem (pti->hAMPM, szPM, 1);
      LB_EndChange (pti->hAMPM);
      LB_SetSelected (pti->hAMPM, 1);
      }

   ShowWindow (pti->hHours,   TRUE);
   ShowWindow (pti->hSep1,    TRUE);
   ShowWindow (pti->hMinutes, TRUE);

   if (!pti->f24Hour)
      {
      ShowWindow (pti->hSep2, TRUE);
      ShowWindow (pti->hAMPM, TRUE);
      }

   RECT rWindow;
   GetWindowRect (pti->hTime, &rWindow);
   rWindow.right += (cxHours + cxMinutes + sTimeSep.cx) - cxRECT(rTime);
   if (!pti->f24Hour)
      rWindow.right += sTimeSep.cx + sAMPM.cx;

   SetWindowPos (pti->hTime, NULL, 0, 0, cxRECT(rWindow), cyRECT(rWindow),
                 SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);

   RECT rSpinner;
   GetRectInParent (pti->hTime, &rSpinner);
   rSpinner.left = rSpinner.right;
   rSpinner.right = rSpinner.left + GetSystemMetrics (SM_CXVSCROLL);
   rSpinner.bottom -= 2; // just like Win95 does
   CreateSpinner (pti->hHours, 10, FALSE, 0, pti->timeNow.wHour, 24, &rSpinner);
   pti->hSpinner = SP_GetSpinner (pti->hHours);
   pti->hSpinnerBuddy = pti->hHours;

   Time_Edit_SetText (pti, pti->hHours);
   Time_Edit_SetText (pti, pti->hMinutes);
   Time_Edit_OnSetFocus (pti, pti->hHours);
   pti->fCanCallBack = TRUE;
}
Exemplo n.º 12
0
void            Optimize(double *x, int n, void (*df) (const double *, double *, void *),
                     double (*f) (const double *, void *), double *fx, void *data,
				                 double *bd, int noisy)
{
	OPTOBJ         *opt;
	double          fo, fn, tol, md;
	int             i, max_step;
	int             max_restart, restarts;
	char           *errstring = NULL;
	double          fact;
	double         *scale;
	SPINNER        *spin;
	int             newbound = 1, lastbound = 0;


	opt = NewOpt(n);
	if (NULL == opt) {
		return;
	}
	InitializeOpt(opt, x, n, df, f, *fx, data, bd);

	tol = 1e-8;
	max_step = 100;
	max_restart = 20;
	restarts = -1;

	/* Do optimization, allowing restarts so don't get bogged down. */

	if (noisy == 2) {
		printf("Initial\tf: %8.6f\nStep     f(x)      delta\n", *fx);
	} else if (noisy == 1) {
		spin = CreateSpinner(2);
	}
	do {
		fo = opt->fc;
		InitializeH(opt);
		fact = 1.;
		do {
			lastbound = newbound;
			fn = opt->fc;
			errn = 0;
			md = TakeStep(opt, tol, &fact, &newbound);
			MakeErrString(&errstring, errn);
			step++;
			if (noisy == 2) {
				printf("%3d: %9f %10.5f %4d %s\t%9.3f\n", step, opt->fc,
				  fabs(opt->fc - fn), opt->neval, errstring, md);
			} else if (noisy == 1) {
				UpdateSpinner(spin);
			}
		} while (fabs(opt->fc - fn) > tol || lastbound);

		if (noisy == 2) {
			printf("***\n");
		}
		restarts++;
	} while (restarts < max_restart && fabs(opt->fc - fo) > tol && RESTART);
	if (noisy == 1) {
		DeleteSpinner(spin);
	}
	if (step == max_step) {
		printf("Didn't converge after %d restarts. Returning best value.\n",
		       step);
	}
	scale = ((struct scaleinfo *) opt->state)->scale;
	for (i = 0; i < n; i++) {
		x[i] = tran_fun(opt->x[i] * scale[i]);
		opt->dx[i] *= scale[i] * dtran_fun(opt->x[i] * scale[i]);
	}
	*fx = opt->fc;

	/* AnalyseOptima(x,opt->dx,opt->n,opt->onbound,opt->lb,opt->ub); */

	FreeOpt(opt);
}