Example #1
0
void MdsGetMsgDsc(int status, struct descriptor *out)
{
	MdsGetMsg(status);
	(MdsShrGetThreadStatic())->MdsGetMsgDsc_tmp.length = strlen((MdsShrGetThreadStatic())->MdsGetMsgDsc_tmp.pointer);
	StrCopyDx(out,&(MdsShrGetThreadStatic())->MdsGetMsgDsc_tmp);
	return;
}
Example #2
0
static char *MdsGetString(char *in)
{
    char *out = NULL;
    int status;
    struct descriptor in_d = {0,DTYPE_T,CLASS_S,0};
    EMPTYXD(xd);

    in_d.length = strlen(in);
    in_d.pointer = in;
    status = TdiCompile(&in_d, &xd MDS_END_ARG);
    if(status & 1)
		status = TdiData(&xd, &xd MDS_END_ARG);
    if(!(status & 1))
    {
    	strncpy(error_message, MdsGetMsg(status), 512);
		return NULL;
    }
    if(!xd.pointer)
    {
		strcpy(error_message, "Missing data");
		return NULL;
    }
    if(xd.pointer->dtype != DTYPE_T)
    { 
		MdsFree1Dx(&xd, NULL);
		strcpy(error_message, "Not a string");
		return NULL;
    }
    out = (char *)malloc(xd.pointer->length + 1);
    memcpy(out, xd.pointer->pointer, xd.pointer->length);
    out[xd.pointer->length] = 0;
    MdsFree1Dx(&xd, NULL);
    error_message[0] = 0;
    return out;
}
Example #3
0
JNIEXPORT void JNICALL Java_LocalDataProvider_SetEnvironmentSpecific(JNIEnv *env, jobject obj, 
																	 jstring in, jstring jdefNode)
{
	int status, nid;
    const char *in_char = (*env)->GetStringUTFChars(env, in, 0);
	const char *defNode;
    struct descriptor in_d = {0,DTYPE_T,CLASS_S,0};
    EMPTYXD(xd);
	error_message[0] = 0;
	if(in_char && *in_char)
	{
		in_d.length = strlen(in_char);
		in_d.pointer = (char *)in_char;
		status = TdiCompile(&in_d, &xd MDS_END_ARG);
		if(status & 1)
    		status = TdiData(&xd, &xd MDS_END_ARG);
		if(!(status & 1))
   			strncpy(error_message, MdsGetMsg(status), 512);
		MdsFree1Dx(&xd, NULL);
		(*env)->ReleaseStringUTFChars(env, in, in_char);
    }
	if(jdefNode)
	{
		defNode = (*env)->GetStringUTFChars(env, jdefNode, 0);
		status = TreeFindNode((char *)defNode, &nid);
		if(status & 1)
			TreeSetDefaultNid(nid);
		(*env)->ReleaseStringUTFChars(env, jdefNode, defNode);
	}

}
Example #4
0
	/*****************************************************************
	 * MdsMsg:
	 *****************************************************************/
int   MdsMsg(			/* Return: sts provided by user		*/
    int   sts			/* <r> status code			*/
   ,char  fmt[]			/* <r> format statement			*/
   , ...			/* <r:opt> arguments to fmt[]		*/
   )
   {
    int   k;
    int   write2stdout;
    va_list  ap;		/* arg ptr				*/

    write2stdout = isatty(fileno(stdout)) ^ isatty(fileno(stderr));
    if ((sts & ALREADY_DISPLAYED) && (sts != -1))
        return(sts);

    sprintf((MdsShrGetThreadStatic())->MdsMsg_text,"\r%s: ",pgmname());
    k = strlen((MdsShrGetThreadStatic())->MdsMsg_text);
    if (fmt)
       {
        va_start(ap,fmt);	/* initialize "ap"			*/
        vsprintf((MdsShrGetThreadStatic())->MdsMsg_text+k,fmt,ap);
        if (sts)
           {
            MDSfprintf(stderr,"%s\n\r    sts=%s\n\n\r",(MdsShrGetThreadStatic())->MdsMsg_text,MdsGetMsg(sts));
            if (write2stdout)
                MDSfprintf(stdout,"%s\n\r    sts=%s\n\n\r",
                    (MdsShrGetThreadStatic())->MdsMsg_text,MdsGetMsg(sts));
           }
        else
           {
            MDSfprintf(stderr,"%s\n\r",(MdsShrGetThreadStatic())->MdsMsg_text);
            if (write2stdout)
                MDSfprintf(stdout,"%s\n\r",(MdsShrGetThreadStatic())->MdsMsg_text);
           }
       }
    else
       {
        MDSfprintf(stderr,"%s:  sts=%s\n\r",(MdsShrGetThreadStatic())->MdsMsg_text,MdsGetMsg(sts));
        if (write2stdout)
            MDSfprintf(stdout,"%s:  sts=%s\n\r",(MdsShrGetThreadStatic())->MdsMsg_text,MdsGetMsg(sts));
       }

    return(sts | ALREADY_DISPLAYED);
   }
Example #5
0
/* Support routines for jScope */
static void MdsUpdate(char *exp, int shot)
{
    static int prev_shot;
    static char prev_exp[256];
    int status;

    error_message[0] = 0;
    if(!exp) return;
    if(shot == prev_shot && !strcmp(prev_exp, exp))
		return;
    prev_shot = shot;
    strcpy(prev_exp, exp);
    status =  TreeOpen(exp, shot, 0);
    if(!(status & 1))
		strncpy(error_message, MdsGetMsg(status), 512);
} 
Example #6
0
static float MdsGetFloat(char *in)
{
    float ris = 0;
    int status;
    struct descriptor in_d = {0,DTYPE_T,CLASS_S,0};
    EMPTYXD(xd);

    in_d.length = strlen(in);
    in_d.pointer = in;
    status = TdiCompile(&in_d, &xd MDS_END_ARG);
    if(status & 1)
    	status = TdiData(&xd, &xd MDS_END_ARG);
    if(status & 1)
    	status = TdiFloat(&xd, &xd MDS_END_ARG);
    if(!(status & 1))
    {
    	strncpy(error_message, MdsGetMsg(status), 512);
	    return 0;
    }
    if(!xd.pointer)
    {
		strcpy(error_message, "Missing data");
		return 0;
    }
    if(xd.pointer->class != CLASS_S)
    {
		strcpy(error_message, "Not a scalar");
		return 0;
    }
    switch(xd.pointer->dtype) {
	case DTYPE_BU:
	case DTYPE_B : ris = (float)(*(char *)xd.pointer->pointer); break;
	case DTYPE_WU:
	case DTYPE_W : ris = (float)(*(short *)xd.pointer->pointer); break;
	case DTYPE_LU:
	case DTYPE_L : ris = (float)(*(int *)xd.pointer->pointer); break;
	case DTYPE_F : ris = *(float *)xd.pointer->pointer; break;
	case DTYPE_FS: ris = *(float *)xd.pointer->pointer; break;
	case DTYPE_D :
	case DTYPE_G : ris = *(float *)xd.pointer->pointer; break; 
	default:	sprintf(error_message, "Not a supported type %d", xd.pointer->dtype);
			return 0;
    }
    MdsFree1Dx(&xd, NULL);
    error_message[0] = 0;
    return ris;
}
Example #7
0
static void EventRegisterRemote(char *eventName)
{
	int i, status;
	struct descrip evNameDsc, thisIpDsc, resDsc;

	struct ClientEventDescriptor *currEventDescr, *prevEventDescr;
	char thisIp[512];
	strncpy(thisIp, getenv("REVENT_THIS_MDSIP"), 511);
	configure();
	if(!thisIp || !*thisIp || numClientIpDescriptors == 0)
		return;  //Missing information for managing rempte events

	MakeDescrip(&thisIpDsc, DTYPE_CSTRING, 0, 0, thisIp);
	MakeDescrip(&evNameDsc, DTYPE_CSTRING, 0, 0, eventName);
	lock();
	prevEventDescr = currEventDescr = clientEventDescrHead;
	while(currEventDescr && strcmp(currEventDescr->eventName, eventName))
	{
		prevEventDescr = currEventDescr;
		currEventDescr = currEventDescr->nxt;
	}
	if(!currEventDescr)
	{
		currEventDescr = (struct ClientEventDescriptor *)malloc(sizeof(struct ClientEventDescriptor));
		currEventDescr->eventName = malloc(strlen(eventName) + 1);
		strcpy(currEventDescr->eventName, eventName);
		currEventDescr->refCount = 1;
		for(i = 0; i < numClientIpDescriptors; i++)
		{
			status = MdsValue(clientIpDescriptors[i].id, "RtEventsShr->EventRegisterExecute($1,$2)", &evNameDsc, &thisIpDsc, &resDsc, NULL);
			if(!(status & 1))
				printf("Error sending event: %s\n", MdsGetMsg(status));
		}
		if(prevEventDescr)
			prevEventDescr->nxt = currEventDescr;
		else
			clientEventDescrHead = currEventDescr;
	}
	else //already found: someone already registered fior this event on this machine
		currEventDescr->refCount++;
	unlock();
}
Example #8
0
	/****************************************************************
	 * TclDoMethod:
	 ****************************************************************/
int TclDoMethod()
   {
    int   i;
    int   argc;
    int   sts;
    unsigned char  do_it;
    struct descriptor_xd xdarg[255];
    static int   nid;
    static unsigned short boolVal;
    static struct descriptor_s bool_dsc =
                    {sizeof(boolVal), DTYPE_W, CLASS_S, (char *)&boolVal};
    static struct descriptor nid_dsc = {4,DTYPE_NID,CLASS_S,(char *)&nid};
    static struct descriptor_xd empty_xd = {0,DTYPE_DSC,CLASS_XD,0,0};
    static DYNAMIC_DESCRIPTOR(arg);
    static DYNAMIC_DESCRIPTOR(if_clause);
    static DYNAMIC_DESCRIPTOR(method);
    static DYNAMIC_DESCRIPTOR(object);
    static void  *arglist[256] = {(void *)2,&nid_dsc,&method};

    cli_get_value("OBJECT",&object);
    sts = TreeFindNode(object.dscA_pointer,&nid);
    if (sts & 1)
       {
        do_it = (TreeIsOn(nid) | cli_present("OVERRIDE")) & 1;
        if (cli_present("IF") & 1)
           {
            cli_get_value("IF",&if_clause);
            sts = TdiExecute(&if_clause,&bool_dsc MDS_END_ARG);
            if (sts & 1)
                do_it = do_it && boolVal;
            else
                do_it = 0;
           }
        if (do_it)
           {
            int dometh_stat;
            DESCRIPTOR_LONG(dometh_stat_d,0);
            cli_get_value("METHOD",&method);
            argc = 0;
            if (cli_present("ARGUMENT") & 1)
               {
                while (cli_get_value("ARGUMENT",&arg) & 1)
                   {
                    xdarg[argc] = empty_xd;
                    sts = TdiCompile(&arg,&xdarg[argc] MDS_END_ARG);
                    if (sts & 1)
                       {
                        arglist[argc + 3] = xdarg[argc].dscA_pointer;
                        argc++;
                       }
                    else
                        break;
                   }
               }
            if (sts & 1)
               {
#ifdef vms
                arglist[0] = (void *)(argc + 2);
#else
                dometh_stat_d.dscA_pointer = (char *)&dometh_stat;
                arglist[argc+3] = &dometh_stat_d;
                arglist[argc+4] = MdsEND_ARG;
                arglist[0] = (argc + 4)+(char *)0;
#endif

		sts = (char *)LibCallg(arglist,TreeDoMethod)-(char *)0;
                if (sts & 1) sts = dometh_stat;
               }
            str_free1_dx(&arg);
            str_free1_dx(&method);
            for (i = 0; i < argc; i++)
                MdsFree1Dx(&xdarg[i],NULL);
           }
       }
    str_free1_dx(&object);
#ifdef vms
    if (!(sts & 1)) lib$signal(sts,0);
#else
	if (!(sts & 1))
	{
		char msg[512];
		sprintf(msg,"Error executing method - %s",MdsGetMsg(sts));
		TclTextOut(msg);
	}
#endif
    return sts;
   }
Example #9
0
int acqMdsPutTCData(TCMDS_INFO *tcmds, int mode)
{
    int _null = 0;
    int status;
    int dtype_Double = DTYPE_DOUBLE;
    int dtype_Short = DTYPE_SHORT;
    int dtype_ULong = DTYPE_ULONG;

    int rawDataDesc;
    int rateDesc, startDesc, endDesc, voltageTDesc;
    int   id_end_Desc;

    int i, j, k;
	int slot;

    FILE *fpRaw = NULL;
    int  nTrueSampleCnt = 0;
    int  nTrueSampleCnt_1;
    double fVpp10_16bit;

    double fStartTime;
    double fEndTime;
    double fRealTimeGap;

    int   mdsSock;
    int   shot = tcmds->shot;

    long   totalCnt;

    FILE *fp;
    char szTemp[256];

    int   reConn = 0;
	char  tempNode[200];

	double *getData = NULL;

    nTrueSampleCnt = (tcmds->t1 - tcmds->t0) * 10;

	getData = (double *)malloc(sizeof(double)*nTrueSampleCnt);

    while(1) {
		if(mode == 1) { /* KSTAR MDS */
            mdsSock = MdsConnect("172.17.100.202:8000");
		}
		else if(mode == 0) { /* LOCAL MDS */
            mdsSock = MdsConnect("172.17.121.244:8000");
		}

        if(mdsSock == -1) {
            printf("--- MDS Connect Faile Reconnect [%d] ---\n", reConn);
            if(reConn >= 3) return -1;
            else reConn++;
        }
        else {
            break;
        }
    }

    reConn = 0;

    while(1) {
		if(mode == 1) /* KSTAR MDS */
			status = MdsOpen("HEATING", &shot);
		else if(mode == 0) /* LOCAL MDS */
            status = MdsOpen("nbi1", &shot);

        if ( !STATUS_OK(status) )
        {
            epicsThreadSleep(0.1);
            fprintf(stderr,"Error opening tree for shot %d.\n",shot);
            printf("%s\n", MdsGetMsg(status));
            if(reConn >= 3) return -1;
            else reConn++;
        }
        else {
            break;
        }
    }

    fStartTime = tcmds->t0;
    fEndTime = nTrueSampleCnt + fStartTime;

    fRealTimeGap = 1.0 / 10.0;
    nTrueSampleCnt_1 = nTrueSampleCnt - 1;

    rateDesc = descr(&dtype_Double, &fRealTimeGap, &_null);
    startDesc = descr(&dtype_Double, &fStartTime, &_null);
    endDesc = descr(&dtype_Double, &fEndTime, &_null);
    voltageTDesc = descr(&dtype_Double, &fVpp10_16bit, &_null);
    id_end_Desc = descr(&dtype_ULong, &nTrueSampleCnt_1, &_null);


	double read_data[nTrueSampleCnt*MAX_CARD_NUM];
	double raw_data[TC_MAX_CH][nTrueSampleCnt];

    for(slot=0; slot < MAX_CARD_NUM; slot++) {
		int ind = 0;
		int inc = 0;

		sprintf(szTemp, "/tmp/tc_%d_%d.dat", tcmds->card, slot);
		fp = fopen(szTemp, "r");
		fread(&read_data[0],  sizeof(double)*tcmds->t1*MAX_CARD_NUM*8, 1, fp);
		fclose(fp);
		for(i=0; i < tcmds->t1; i++) {
			for(j=0; j < TC_MAX_CH; j++) {
				for(k=0; k < 10; k++) {
					raw_data[j][k+ind] = read_data[k+inc];
				}
				inc += 10;
			}
			ind += 10;
		}

		for(i=0; i < TC_MAX_CH; i++) {

			printf("TC MDS NODE : [%s]\n", tcmds->mdsinfo[slot][i].node);
			memcpy(getData, &raw_data[i], sizeof(double)*nTrueSampleCnt);

	        rawDataDesc = descr(&dtype_Double, getData, &nTrueSampleCnt, &_null);

	        if( tcmds->mdsinfo[slot][i].mdsput != 0) {
				sprintf(tempNode, "\\%s", tcmds->mdsinfo[slot][i].node);


				if(mode == 1) { /* KSTAR MDS */
	         	    status = MdsPut(tempNode, 
						"BUILD_SIGNAL(BUILD_WITH_UNITS($,\"V\"),,MAKE_DIM(MAKE_WINDOW($,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,\"s\"))))", 
						&rawDataDesc, &startDesc, &endDesc, &rateDesc, &rateDesc, &_null);
				}
				else if(mode == 0) { /* LOCAL MDS */
			        status = MdsPut(tempNode ,
					    "BUILD_SIGNAL(BUILD_WITH_UNITS($,\"V\"),,MAKE_DIM(MAKE_WINDOW(0,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,\"s\"))))", 
					    &rawDataDesc, &id_end_Desc, &startDesc, &rateDesc, &_null);
				}

		        if(!((status) & 1)) {
	                printf("MdsPut Error --> node [%s]\n", tcmds->mdsinfo[slot][i].node);
	            }
	        }
		}
    }

	if(mode == 1) /* KSTAR MDS */
        status = MdsClose("HEATING", &shot);
	else if(mode == 0) /* LOCAL MDS */
		status = MdsClose("nbi1", &shot);
    MdsDisconnect(mdsSock);

    free(getData);
    getData = NULL;

    printf("--- TC MDSPlus Data Put OK ---\n");

    return 0;
}
Example #10
0
/*Support routine for MdsHelper */
JNIEXPORT jstring JNICALL Java_MdsHelper_getErrorString
  (JNIEnv *env, jclass cld, jint jstatus)
{
	char *error_msg = MdsGetMsg(jstatus);
	return (*env)->NewStringUTF(env, error_msg);
}
Example #11
0
static void *MdsGetArray(char *in, int *out_dim, int is_float, int is_byte, int is_double)
{
    float *float_ris = NULL;
    double *double_ris = NULL;
    int *int_ris = NULL;
	char *byte_ris = NULL;
    int status, dim, i;
    struct descriptor in_d = {0,DTYPE_T,CLASS_S,0};
    EMPTYXD(xd);
    struct descriptor_a *arr_ptr;
	char *expanded_in;

    error_message[0] = 0;
    *out_dim = 0;
	if(is_float)
	{
		expanded_in = malloc(strlen(in) + 16);
		sprintf(expanded_in, "fs_float((%s))", in);
		in_d.length = strlen(expanded_in);
		in_d.pointer = expanded_in;
	}
	else if(is_double)
	{
		expanded_in = malloc(strlen(in) + 16);
		sprintf(expanded_in, "ft_float((%s))", in);
		in_d.length = strlen(expanded_in);
		in_d.pointer = expanded_in;
	}
	else
	{
		expanded_in = malloc(strlen(in) + 16);
		sprintf(expanded_in, "long((%s))", in);
		in_d.length = strlen(expanded_in);
		in_d.pointer = expanded_in;
/*		in_d.length = strlen(in);
		in_d.pointer = in;*/
	}
    status = TdiCompile(&in_d, &xd MDS_END_ARG);
	if(is_float) free(expanded_in);
    if(status & 1)
    	status = TdiData(&xd, &xd MDS_END_ARG);
    if(!(status & 1))
    {
    	strncpy(error_message, MdsGetMsg(status), 512);
		return 0;
    }
    if(!xd.pointer)
    {
		strcpy(error_message, "Missing data");
		return 0;
    }
    if(xd.pointer->class != CLASS_A)
    {
		if(!is_float && !is_double) /*Legal only if used to retrieve the shot number*/
		{
			int_ris = malloc(sizeof(int));
			switch(xd.pointer->dtype)
			{
				case DTYPE_BU:
				case DTYPE_B : int_ris[0] = *((char *)xd.pointer->pointer); break;
				case DTYPE_WU:
				case DTYPE_W : int_ris[0] = *((short *)xd.pointer->pointer); break;
				case DTYPE_LU:
				case DTYPE_L : int_ris[0] = *((int *)xd.pointer->pointer); break;
				case DTYPE_F : 
				case DTYPE_FS : int_ris[0] = *((int *)xd.pointer->pointer); break;
			}
			*out_dim = 1;
			return int_ris;
		}
		strcpy(error_message, "Not an array");
		return 0;
	}
 	arr_ptr = (struct descriptor_a *)xd.pointer;
/*	if(arr_ptr->dtype == DTYPE_F || 
		arr_ptr->dtype == DTYPE_D ||
		arr_ptr->dtype == DTYPE_G ||
		arr_ptr->dtype == DTYPE_H) 
	{
		status = TdiFloat(&xd, &xd MDS_END_ARG);
		arr_ptr = (struct descriptor_a *)xd.pointer;
	}
	*/
	*out_dim = dim = arr_ptr->arsize/arr_ptr->length;
    if(is_float)
        float_ris = (float *)malloc(sizeof(float) * dim);
	else if(is_double)
		double_ris = (double *)malloc(sizeof(double) * dim);
    else if(is_byte)
		byte_ris = malloc(dim);
	else
        int_ris = (int *)malloc(sizeof(int) * dim);
    switch(arr_ptr->dtype) {
	case DTYPE_BU:
	case DTYPE_B : 
		for(i = 0; i < dim; i++)
		    if(is_float)
		    	float_ris[i] = ((char *)arr_ptr->pointer)[i];
			else if(is_double)
				double_ris[i] = ((char *)arr_ptr->pointer)[i];
		    else if(is_byte)
		    	byte_ris[i] = ((char *)arr_ptr->pointer)[i];
			else
		    	int_ris[i] = ((char *)arr_ptr->pointer)[i];
		break;
	case DTYPE_WU:
	case DTYPE_W : 
		for(i = 0; i < dim; i++)
		    if(is_float)
		    	float_ris[i] = ((short *)arr_ptr->pointer)[i];
			else if(is_double)
				double_ris[i] = ((char *)arr_ptr->pointer)[i];
		    else if(is_byte)
		    	byte_ris[i] = (char)(((short *)arr_ptr->pointer)[i]);
			else
				int_ris[i] = ((short *)arr_ptr->pointer)[i];
		break;
	case DTYPE_LU:
	case DTYPE_L : 
		for(i = 0; i < dim; i++)
		    if(is_float)
		    	float_ris[i] = (float)(((int *)arr_ptr->pointer)[i]);
			if(is_double)
		    	double_ris[i] = (double)(((int *)arr_ptr->pointer)[i]);
		    else if(is_byte)
		    	byte_ris[i] = ((int *)arr_ptr->pointer)[i];
			else
		    	int_ris[i] = ((int *)arr_ptr->pointer)[i];
		break;
	case DTYPE_F : 
	case DTYPE_FS :
		for(i = 0; i < dim; i++)
		    if(is_float)
		    	float_ris[i] = ((float *)arr_ptr->pointer)[i];
			else if(is_double)
		    	double_ris[i] = (double)((float *)arr_ptr->pointer)[i];
		    else if(is_byte)
		    	byte_ris[i] = (char)(((float *)arr_ptr->pointer)[i]);
			else
		    	int_ris[i] = (int)(((float *)arr_ptr->pointer)[i]);
		break;
	case DTYPE_FT :
		for(i = 0; i < dim; i++)
		    if(is_float)
		    	float_ris[i] = (float)((double *)arr_ptr->pointer)[i];
			else if(is_double)
			{
		    	double_ris[i] = ((double *)arr_ptr->pointer)[i];
			}
		    else if(is_byte)
		    	byte_ris[i] = (char)(((double *)arr_ptr->pointer)[i]);
			else
		    	int_ris[i] = (int)(((double *)arr_ptr->pointer)[i]);
		break;

	case DTYPE_D :
	case DTYPE_G :
	default:	strcpy(error_message, "Not a supported type");
			return NULL;
    }
    MdsFree1Dx(&xd, NULL);
    error_message[0] = 0;
    if(is_float)
    	return float_ris;
	else if(is_double)
		return double_ris;
    else if(is_byte) 
		return byte_ris;
	return int_ris;
}
Example #12
0
int proc_sendData2Tree(ST_STD_device *pSTDdev)
{
	int _null = 0; /* Used to mark the end of the argument list */
	int status; /* Will contain the status of the data access operation */
	int dypte_Short = DTYPE_SHORT ;
	int dtype_Double = DTYPE_DOUBLE;
	int dtype_ULong = DTYPE_ULONG; 

	short *databuf=NULL;	/* 2009. 7. 24 by woong.. for read bulk data */

	int rawDataDesc; /* Signal descriptor */
	int voltageTDesc;	
	int realRate_Desc, value_at_start_Desc;
	int id_end_Desc;

	int i; /*, ntemp2=0; */

	FILE *fpRaw=NULL;	
	char buf[128];
	int nTrueSampleCnt=0, nTrueSampleCnt_1;
	double dVpp10_16bit;
	int opmode;
	char tagname[60];


	double dStartTime;   /* -1 sec */
	double dRealTimeGap;

	ST_ACQ196 *pAcq196 = (ST_ACQ196 *)pSTDdev->pUser;


//	nTrueSampleCnt = (pSTDdev->ST_Base_fetch.dT1[0] - pSTDdev->ST_Base_fetch.dT0[0])*pSTDdev->ST_Base_fetch.nSamplingRate;
	nTrueSampleCnt = (pSTDdev->ST_Base_fetch.dRunPeriod)*pSTDdev->ST_Base_fetch.nSamplingRate;

	databuf = (short *)malloc(sizeof(short)* nTrueSampleCnt);
	if( databuf == NULL){		
		epicsPrintf("\n%s: >>> malloc(sizeof(short)* %d)... fail\n", pSTDdev->taskName, nTrueSampleCnt);
		return WR_ERROR;
	}
				
/*	
	switch( nSampleClk ) {
	case 1000: nTimeGap = 1000; break;
	case 2000: nTimeGap = 500; break;
	case 5000: nTimeGap = 200; break;
	case 10000: nTimeGap = 100; break;
	case 20000: nTimeGap = 50; break;
	case 50000: nTimeGap = 20; break;
	case 100000: nTimeGap = 10; break;
	case 200000: nTimeGap = 5; break;
	default: {
			fprintf(stderr,"appSampleRate not valid\n");
			free(data);
			free(timebase);
			free(unTimebase);
			return 0;
			}
	}
	nSkipCnt = 200000 / nSampleClk;
	fprintf(stdout, "\nMDSplus >>> Sample clock:%dHz, nTimeGap:%d, nSkipCnt:%d\n", nSampleClk, nTimeGap, nSkipCnt );
*/

/*************************************************************************/
#if 1
	if( mds_Connect(pSTDdev) == WR_ERROR ) {
		free(databuf);
		return WR_ERROR;
	}

	if( mds_Open_withFetch(pSTDdev) == WR_ERROR ) {
		free(databuf);
		return WR_ERROR;
	}
#endif

	opmode = pSTDdev->ST_Base.opMode;

/*************************************************************************/
#if 0
	if ( opmode != OPMODE_REMOTE ) {
		dStartTime = 0.0;  /* Data Zero Start Time */
	} else {
/*		dStartTime = (pSTDdev->ST_Base_fetch.dT0[0] - pSTDdev->ST_Base_fetch.fBlipTime) * pSTDdev->ST_Base_fetch.nSamplingRate; */
//		dStartTime = pSTDdev->ST_Base_fetch.dT0[0] - pSTDdev->ST_Base_fetch.fBlipTime; 2013. 7. 5 
		
	}
#endif
	dStartTime = pSTDdev->ST_Base_fetch.dT0[0];
	dRealTimeGap = 1.0 / (double)pSTDdev->ST_Base_fetch.nSamplingRate;
	dVpp10_16bit = 10.0 / 32768.0;
	nTrueSampleCnt_1 = nTrueSampleCnt - 1;
#if 0
	fprintf(stdout,"True Cnt:%d, Freq: %d, T0: %f, T1: %f, gap: %f \n", 
			nTrueSampleCnt, 
			pSTDdev->mds_nSamplingRate, 
			pSTDdev->mds_dT0[0], 
			pSTDdev->mds_dT1[0], 
			dRealTimeGap);
#endif
	realRate_Desc = descr(&dtype_Double, &dRealTimeGap, &_null);
	voltageTDesc = descr(&dtype_Double, &dVpp10_16bit, &_null);
	value_at_start_Desc = descr(&dtype_Double, &dStartTime, &_null);
	id_end_Desc = descr(&dtype_ULong, &nTrueSampleCnt_1, &_null);
	
	pAcq196->mdsplus_snd_cnt = 0;
	for(i = 0; i<96; i++) 
	{
		if( pAcq196->channelOnOff[i] ) 
		{
			sprintf(buf, "%s/b%d.%02d.dat", STR_CHANNEL_DATA_DIR, pAcq196->slot, i);

			fpRaw = fopen(buf, "rb");
			if( fpRaw == NULL) {
				status = MdsClose(pSTDdev->ST_mds.treeName[opmode], (int *)(pSTDdev->ST_Base_fetch.shotNumber));
				
				epicsPrintf("can't open data file : %s\n", buf);
				MdsDisconnect(pSTDdev->ST_mds.treeIPport);
				free(databuf);
				return(0);
			}
			fread( databuf, 2, nTrueSampleCnt, fpRaw);
			fclose(fpRaw);
#if 0			
/*			for(j = 0; j < pAcq196->sampleDataCnt; j++) */
			for(j = 0; j < nTrueSampleCnt; j++) 
			{
/*				fread( &int16TempBuf, 2, 1, fpRaw );
				fTemp = ((float)(int16TempBuf) * 10.0 ) / 32768.0;  */
				data[j] = ((float)(databuf[j]) * 10.0 ) / 32768.0; 
/*				
				if ( j > nTrueSampleCnt ) {
					epicsPrintf(" got to end count:%lu\n", j); 
					break;
				}
*/
			}
#endif


/*			dataDesc = descr(&dtype_Float, data, &nTrueSampleCnt, &_null); */
			rawDataDesc = descr(&dypte_Short, databuf, &nTrueSampleCnt, &_null);


			sprintf(tagname, "\\%s", pAcq196->strTagName[i]);

			status = MdsPut(tagname ,
				"BUILD_SIGNAL(BUILD_WITH_UNITS($*$,\"V\"),,MAKE_DIM(MAKE_WINDOW(0,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,\"s\"))))", 
				&rawDataDesc, &voltageTDesc,  &id_end_Desc, &value_at_start_Desc, &realRate_Desc, &_null);
			
			if ( !((status) & 1) )
			{
				printf("%s: Error tag\"%s\", ch%d: %s\n",pSTDdev->taskName, tagname, i, MdsGetMsg(status));
				printlog("%s: Error tag\"%s\", ch%d, shot %d: %s\n",pSTDdev->taskName, pAcq196->strTagName[i], i, pSTDdev->ST_Base_fetch.shotNumber, MdsGetMsg(status));
#if 0
				mds_Close_Disconnect(pAcq196);
				clearAllchFiles((int)pAcq196->slot);
	
				free(databuf);
				free(data);
				data=NULL;
				databuf=NULL;
				return 0;
#endif
			} 
			else 
				pAcq196->mdsplus_snd_cnt++;

/*			if( (pAcq196->mdsplus_snd_cnt % 10) == 9 ) 2010. 11. 11*/
				scanIoRequest(pSTDdev->ioScanPvt_userCall); 

/*			printf("%s, <cnt:%d>\n", pSTDdev->taskName, i ); */

		} 
		else  /*  if( pAcq196->channelOnOff[i] )  */
		{ 
/*			epicsPrintf(". ch%d off ", i)
			if( ntemp2 > 10) {
				epicsPrintf("\n");
				ntemp2 = 0;
			}
			ntemp2++;
*/
		}
	} /* for(i = 0; i<96; i++)   */

/*	printf("%s, Tree Put Done! <cnt:%d>\n", pSTDdev->taskName, pAcq196->mdsplus_snd_cnt ); */

	if( opmode == OPMODE_REMOTE ) 
		sprintf(buf, "Remote");
	else if( opmode == OPMODE_LOCAL) 
		sprintf(buf, "Local");
	else if( opmode == OPMODE_CALIBRATION) 
		sprintf(buf, "Calibration");
	else
		sprintf(buf, "N/A");


	printlog("%s %d: %s:(%.2f~%.2f) %dKHz, (snd: %.2f MB) (%d ch), Cnt:%d\n", 
		buf, pSTDdev->ST_Base_fetch.shotNumber, pSTDdev->taskName, 
				pSTDdev->ST_Base_fetch.dT0[0], pSTDdev->ST_Base_fetch.dT1[0], 
				pSTDdev->ST_Base_fetch.nSamplingRate/1000, 
/*				pAcq196->needDataSize/1024.0/1024.0, */
				pAcq196->mdsplus_snd_cnt *2*nTrueSampleCnt/1024.0/1024.0, 
				pAcq196->mdsplus_snd_cnt,
				nTrueSampleCnt 	);

	scanIoRequest(pSTDdev->ioScanPvt_userCall);  /* for last update */

/*
	printf("Put %s: raw:%.2fMB, snd:%.2fMB(%d), Cnt:%d ... OK!\n", pSTDdev->taskName, 
						pAcq196->needDataSize/1024.0/1024.0,
						pAcq196->mdsplus_snd_cnt *2*nTrueSampleCnt/1024.0/1024.0, 
						pAcq196->mdsplus_snd_cnt,
						nTrueSampleCnt );
*/
/*	fprintf(stdout,"\nMDSplus >>> Data size: %luKB/ch\n", (4*pAcq196->sampleDataCnt)/1024 ); */

	free(databuf);
	databuf = NULL;

#if 1
	mds_Close_withFetch(pSTDdev);
	mds_Disconnect(pSTDdev);
#endif
	
#if 0
	clearAllchFiles((int)pAcq196->slot);
#endif
	
	
	return WR_OK;
}