/****************************************************************/
/*	ab			03.02.2006			*/
/****************************************************************/
/*	Short Description :					*/
/*	Ampy's browse						*/
/*	Program to browse currently open dataset for different 	*/
/*	expnos like browse 4.					*/
/****************************************************************/
/*	Keywords :						*/
/*	DIR, SEARCH, BROWSE					*/
/****************************************************************/
/*	Description/Usage :					*/
/*	Program to select from different expnos of current 	*/
/*	dataset. Each experiment number is presented with	*/
/*	main experiment parameters as PULPROG, P1, D1, TE etc 	*/
/*	unlike browse 4 where only expno is shown.		*/
/****************************************************************/
/*	Author(s) :						*/
/*	Name		: Arseny Slobodyuk			*/
/*	Organisation	: Institute of Chemistry, FEBRAS 	*/
/*	Email		: ampy at ich.dvo.ru       		*/
/****************************************************************/
/*	Name		Date	Modification:			*/
/****************************************************************/


char status[256];
char pulp[32];
char menu[1024*32];
char * pmenu[128], * hires = NULL;
long int date = 0;
time_t tt;
int ns;
float te,pl1,p1,dl1,rg;
struct tm * stm;
int iavail,oldexpno = expno,mfreep = 0,pfreep = 0,l,delp;

GETCURDATA;

(void) sprintf (text,"%s/data/%s/nmr/%s",disk,user,name);
iavail = gethighest (text);
delp = stricmp(cmd,"del") == 0;
memset(pmenu,0,sizeof(pmenu));

for (expno=1;expno<iavail;expno++) {
  FETCHPARS("TE", &te);
  FETCHPARS("DATE",&date);
  stm = localtime(&date);
  FETCHPARS("NS",&ns);
  FETCHPARS("PULPROG",pulp);
  FETCHPARS("P 1",&p1);
  FETCHPARS("PL 1",&pl1);
  FETCHPARS("D 1",&dl1);
  FETCHPARS("RG",&rg);
  if (delp) sprintf(status,"%d",expno); else
    sprintf(status,"%02d %12s %02d.%02d.%02d %02d:%02d NS %d TE %3.0f P1 %3.1f PL1 %4.1f D1 %4.1f",
      expno,
      pulp,
      stm->tm_mday,stm->tm_mon+1,stm->tm_year>=100?stm->tm_year-100:stm->tm_year,stm->tm_hour,
      stm->tm_min,ns,te,p1,pl1,dl1);
  l = strlen(status);
  if (l + mfreep <= sizeof(menu) && pfreep < 128) {
    pmenu[pfreep++] = menu + mfreep;
    strcpy(menu + mfreep, status);
    mfreep += l + 1;
  }
}
hires = uxselect(text,pmenu,"Select experiment",delp?SEL_DELETE:SEL_RD_WIDE);
if (hires && !delp) {
  Show_status(hires);
  for (expno = 1; expno < iavail; expno++) {
    if (strcmp(pmenu[expno - 1], hires) == 0) break;
  }
} else expno = oldexpno;
VIEWDATA;
QUIT;

#include <inc/sysutil>
