示例#1
0
文件: t.c 项目: petermilne/mdsshell
int main( int argc, void **argv)
{
  int status;
  struct descrip ans;
  float val = 9876;
  struct descrip vald = {DTYPE_FLOAT,0};
  long sock = ConnectToMds((argc > 1) ? argv[1] : "lost.pfc.mit.edu:9000");
  if (sock != -1)
  {
    printf("status from MdsOpen = %d\n",MdsOpen(sock,"main",-1));
    ans.ptr = 0;
    if (MdsValue(sock,"f_float(member)",&ans,0) & 1)
    {
      printf("%g\n",*(float *)ans.ptr);
      val = *(float *)ans.ptr;
      val = val + (float)1.;
    }
    else
      printf("%s\n",ans.ptr);
    if (ans.ptr) 
    {
      free(ans.ptr);
      ans.ptr = 0;
    }
    vald.ptr = (void *)&val;
    status = MdsPut(sock,"member","$",&vald,0); 
    if (!(status & 1)) printf("Error during put %d\n",status);
    if (MdsValue(sock,"42.0",&ans,0) & 1)
      printf("%g\n",*(float *)ans.ptr);
    else
      printf("%s\n",ans.ptr);
    if (ans.ptr) free(ans.ptr);
  }
  return 1;
}
示例#2
0
static int doMdsPut(int argc, char **argv)
{
	if (getenv("MDS_SOCK")){
		int sock = atoi(getenv("MDS_SOCK"));

		fprintf(stderr, "MDS_SOCK is %s\n", getenv("MDS_SOCK"));

		switch(argc){
		case 3: {
			char* field = argv[1];
			char* value = argv[2];

			float fval = atof(value);
			struct descrip vald = {DTYPE_FLOAT,0};
			int status;

			

			fprintf(stderr, 
				"MdsPut sock:%d field:%s v:%s value:%g\n",
			       sock, field, value, fval);

			vald.ptr = (void *)&fval;
			status = MdsPut(sock, field,"$",&vald,0); 
			if (!(status & 1)){
				fprintf(stderr, 
					"Error during put %d\n",status);
			}
			return 0;
		} default:
			fprintf(stderr, "ERROR: args field value\n");
		}
	}else{
		fprintf(stderr, "MDS_SOCK environment var is missing\n");
	}
	return -1;
}
示例#3
0
文件: nidaq.c 项目: LucyScott/mdsplus
int DllExport _nidaq_store (int id, char *nodeName, int simultaneous)
{
	char channelName[256], pathName[256];
	int16 *data;
	int32 stats, samplesRead, idesc, idesc1, idesc2, idesc3, idesc4, idesc5, idesc6, dtype, null = 0;
	uInt32 i, arraySize, nPacket, packetSize;
	uInt64 numSamples;
	float64 convRate, dt, range, resolution, period;
	sTask *pTask;
	sDataChain *pData, *pNext;
	
	pTask = tasks.item + id;
	if (simultaneous)
	{
		dt = 0.0;
	}
	else
	{
		DAQmxGetTimingAttribute (pTask->handle, DAQmx_AIConv_Rate, &convRate);
		dt = 1.0/convRate;
	}

	if (pTask->type== DAQmx_Val_OnDemand)
	{
		pData = pTask->current;
		samplesRead = pTask->num * NBUF + pData->num;
		arraySize = pTask->numChannels * samplesRead;
		data = (int16 *)malloc(arraySize * sizeof (int16));
		nPacket = NBUF * pTask->numChannels;
		packetSize = nPacket * sizeof (int16);
		pNext = pTask->start;
		for (i=0; i<pTask->num; i++)
		{
			pData = pNext;
			memcpy (data + i * nPacket, pData->data, packetSize);
			pNext = pData->next;
			free (pData->data);
			free (pData);
		}
		memcpy (data + i * nPacket, pNext->data, pNext->num * pTask->numChannels * sizeof (int16));
		free (pNext->data);
		free (pNext);
	}
	else
	{
		/* # of samples */
		DAQmxGetTimingAttribute (pTask->handle, DAQmx_SampQuant_SampPerChan, &numSamples);
		arraySize = pTask->numChannels * numSamples;
		data = (int16 *)malloc(arraySize * sizeof (int16));
		DAQmxReadBinaryI16 (pTask->handle, DAQmx_Val_Auto, 10.0, DAQmx_Val_GroupByScanNumber, data, arraySize, &samplesRead, NULL);
	}
	/* Get the ADC resolution 12bits=NI6071,NI6115, 16bits=NI6143, 14bits but packed from bit 15=NI6133 */
	DAQmxGetChanAttribute (pTask->handle, NULL, DAQmx_AI_Resolution, &resolution);
	if (resolution == 14.) resolution = 16.;
	resolution = ldexp (1.0, (int) resolution-1);  

	/* Sampling time */
	DAQmxGetTimingAttribute (pTask->handle, DAQmx_SampClk_Rate, &period);
	period = 1.0/period; //Rate -> Time
	
	dtype = DTYPE_SHORT;
	idesc1 = descr(&dtype, data, &arraySize, &null);

	dtype = DTYPE_ULONG;
	idesc2 = descr(&dtype, &i, &null);

	idesc3 = descr(&dtype, &pTask->numChannels, &null);

	dtype = DTYPE_ULONGLONG;
	numSamples = samplesRead - 1;
	idesc4 = descr(&dtype, &numSamples, &null);

	dtype = DTYPE_DOUBLE;
	idesc = descr(&dtype, &range, &null);
	idesc5 = descr(&dtype, &convRate, &null);
	idesc6 = descr(&dtype, &period, &null);
	for (i=0; i<pTask->numChannels; i++)
	{
		/* Translate a channel name to a node name */
		DAQmxGetNthTaskChannel (pTask->handle, i+1, channelName, 256);
		sprintf (pathName, "%s:%s:FOO", nodeName, channelName);

		DAQmxGetChanAttribute (pTask->handle, channelName, DAQmx_AI_Max, &range);
		range /= resolution;

		convRate = i * dt;
		stats = MdsPut(pathName,"BUILD_SIGNAL(BUILD_WITH_UNITS($*$VALUE,'V'),(`$[$:*:($)]),MAKE_DIM(MAKE_WINDOW(0,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,'s'))))",
			&idesc, &idesc1, &idesc2, &idesc3, &idesc4, &idesc5, &idesc6, &null);
	}
	free (data);
	
	DAQmxStopTask (pTask->handle);
	return 1;
}
示例#4
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;
}
示例#5
0
void mdsPlusPut_Task(int param)
{
    unsigned long i;
    int socket;
    int null=0;
    int dtypeFloat = DTYPE_FLOAT;
    int dataDesc,timeDesc;
    int status=1, j;

    float          tdT;
    float          toffT;

    int            tnoRd;
    int            tshotID;
    char            ttagName[20];
    char            ttreeID[20];
    char            tserverID[20];
    float           *timeBase;

    DBADDR          *paddr;
    paddr = (DBADDR *)dbCalloc(1, sizeof(struct dbAddr));

    if(genSubDebug > 0)
        printf("Start MdsPut. ##############.\n");
    status = dbNameToAddr(mpActivePV, paddr);
    enum16Val = 1;
    status = dbPutField(paddr, DBR_ENUM, &enum16Val, 1);
    status = mdsPlusCreatePulse();
    /* loop numNode times */
    for(j = 0;j < numNode; j++) {
        if(genSubDebug > 5)
            printf("genSub: mdsPlusPut_Task() started. Task Position=%d, Flag=%ld\n",j,pmdsPutData[j].putFlag);
        if(pmdsPutData[j].putFlag == 0)
            goto endloop;

        epicsThreadSleep(0.01);

        tnoRd=(int)(pmdsPutData[j].noRd);
        tshotID=(int)(pmdsPutData[j].shotID);
        strcpy(ttagName,pmdsPutData[j].tagName);
        strcpy(ttreeID,pmdsPutData[j].treeID);
        strcpy(tserverID,pmdsPutData[j].serverID);

        tdT=pmdsPutData[j].dT;
        toffT=pmdsPutData[j].offT;

        if(genSubDebug > 3)
            printf("genSub: mdsPlusPut_Task() MdsConnect Ready. ServerID=[%s] TreeID=[%s] tagName=[%s] dt=[%f] off=[%f] noRd=[%d]\n",tserverID, ttreeID, ttagName, tdT, toffT, tnoRd);

        /* Connect server and open tree*/
        socket=MdsConnect(tserverID);
        if(socket == -1) {
            printf("genSub: Error connecting to mdsip server[%s].\n",tserverID);
            break;
        }
        if(genSubDebug > 5)
             printf("genSub: mdsPlusPut_Task() MdsConnected[%s]\n",tserverID);

        status=MdsOpen(ttreeID, &tshotID);
        if( !status_ok(status) ) {
             printf("genSub: Error opening tree [%s] for shot [%d].\n",
                            ttreeID,tshotID );
             break;
        }                
        if(genSubDebug > 5)
             printf("genSub: mdsPlusPut_Task() MdsOpened [%s] shot number [%d].\n",
                       ttreeID,tshotID);

        /* put data */
        timeBase = (float *)malloc(tnoRd*sizeof(float));
        for(i=0;i<tnoRd;i++)
            *(timeBase + i) = ((float)i)*tdT + toffT;

        dataDesc=descr(&dtypeFloat,pmdsPutData[j].dataArray,&tnoRd, &null);
        timeDesc=descr(&dtypeFloat,timeBase, &tnoRd, &null);
        status=MdsPut(ttagName,"BUILD_SIGNAL($1,,$2)",&dataDesc,&timeDesc,&null);
        if( !status_ok(status) ) {
            printf("genSub: Error writing signal.\n");
            break;
        }

        if(genSubDebug > 5)
            printf("genSub: mdsPlusPut_Task() MdsPutted to tag [%s]. shot number [%d], noRd=[%d].\n",
                                ttagName,tshotID,tnoRd);
        if(genSubDebug > 10)
            for(i=0;i<tnoRd;i++) {
                    printf("timeBase=%f,data=%f\n",
                                        *((float *)timeBase+i),*((float *)pmdsPutData[j].dataArray+i));
            }
        free(timeBase);
        status=MdsClose(ttreeID, &tshotID);
        if( !status_ok(status) ) {
            printf("genSub: Error closing tree for shot [%d].\n",tshotID );
            break;
        }
        if(genSubDebug > 5)
            printf("genSub: mdsPlusPut_Task() MdsClosed [%s] shot number [%d]\n",ttreeID,tshotID);

        endloop:
        if(genSubDebug > 5)
            printf("genSub: mdsPlusPut_Task() Data discarded for taskPos[%d].\n",j);
    }
    status = mdsPlusPrepNext();
    /* end of mdsput */
    startMdsPut = 0;
    status = dbNameToAddr(mpActivePV, paddr);
    enum16Val = 0;
    status = dbPutField(paddr, DBR_ENUM, &enum16Val, 1);
    free(paddr);
}
示例#6
0
long mdsPlusCreatePulse()
{
    int socket;
    int null=0;
    int dtype_long = DTYPE_LONG;
    int dtype_cstring = DTYPE_CSTRING;
    int dtype_float = DTYPE_FLOAT;

    int mdsstat, len;
    int idesc;
    int sdesc;
    int fdesc;
    int status=1,i;

    int bufsize=40;
    char buf[bufsize];
    char            treeID[20];
    char            serverID[20];
    int             shotID = 0;
    int 	    tmpShotID = 0;
    int             nextShotID;
    int             tok_pulse;
    float           coef=1.0;

    DBADDR  *paddr;
    long options, nRequest;

    paddr = (DBADDR *)dbCalloc(1, sizeof(struct dbAddr)); 
    /* Get server information */
    sprintf(buf, "icrf:daq:mptree:i.VAL");
    status = dbNameToAddr(buf, paddr);
    options = 0;
    nRequest = 1;
    status = dbGetField(paddr, DBR_STRING, buf, &options, &nRequest, NULL);
    i=sscanf(buf,"%s %s",serverID, treeID);
    /* Connect server */
/*    socket=MdsConnect(serverID);
    if(socket == -1) {
        printf("genSub: Error connecting to mdsip server[%s].\n",serverID);
        return(-1);
    }
    if(genSubDebug > 5)
            printf("genSub: mdsPlusCreatePulse() MdsConnected[%s]\n",serverID);
*/
    /* Get pulse id */
/*    sprintf(buf, "icrf:pulseid.VAL");*/
/*    sprintf(buf, "icrf:daq:mcont:pulseid.VAL");
    status = dbNameToAddr(buf, paddr);
    options = 0;
    nRequest = 1;
    status = dbGetField(paddr, DBR_LONG, &nextShotID, &options, &nRequest, NULL); 
*/    /* open MDSPlus */
    /* should be opened with shot -1 */
/*    shotID = -1;
    status=MdsOpen(treeID, &shotID);
    if( !status_ok(status) ) {
            printf("genSub: Error opening tree [%s] for shot [%d].\n",
                            treeID,shotID );
        return(-1);
    }
    if(genSubDebug > 5)
               printf("genSub: mdsPlusCreatePulse() MdsOpened [%s] shot number [%d].\n",
                            treeID,shotID);
*/    /* create new pulse */
    /* shot increment */
/*    sprintf(buf, "TCL(\"SET CURRENT %s /INCREMENT\")", treeID);
    idesc = descr(&dtype_long, &mdsstat, &null);
    status = MdsValue(buf,&idesc,&null,&len);
    if(genSubDebug > 0)
            printf("genSub: mdsPlusCreatePulse() MdsValue %s\n", buf);
*/
    /* get increased current shot id. increased shot ID should be same to the nextShotID */
/*    sprintf(buf, "TCL(\"SHOW CURRENT %s\",_output)", treeID);
    idesc = descr(&dtype_long, &mdsstat, &null);
    status = MdsValue(buf,&idesc,&null,&len);
    if( !status_ok(status) ) {
        printf("genSub: Error with %s.", buf);
        return (-1);
    }
    if(genSubDebug > 3)
            printf("genSub: mdsPlusCreatePulse() MdsValue %s\n",buf);

    if( status_ok(mdsstat) ) {
        sdesc = descr(&dtype_cstring, buf, &null, &bufsize);
        status = MdsValue("_output",&sdesc, &null, &len);
        if( !status_ok(status) ) {
            printf("genSub: Error getting output with %s.",buf);
        }
        sscanf(buf,"Current shot is %d", &tmpShotID);
        if(tmpShotID != nextShotID ) {
            printf("genSub: Shot ID is incorrect.\n");
            return(-1);
        }
        if(genSubDebug > 0)
                    printf("genSub: mdsPlusCreatePulse() MdsValue SHOW CURRENT gets shot number [%d].\n",
                            tmpShotID);
*/        /* create current pulse */
/*        sprintf(buf, "TCL(\"CREATE PULSE %d\")", tmpShotID);
        status = MdsValue(buf,&idesc,&null,&len);
        if(genSubDebug > 3)
            printf("genSub: mdsPlusCreatePulse() MdsValue %s\n",buf);
    }
*/    /* close and reopen with increased shot id*/
/*    status=MdsClose(treeID, &shotID);*/
    /* shotID=nextShotID;*/
    /* Connect server */
    socket=MdsConnect(serverID);
    if(socket == -1) {
        printf("genSub: Error connecting to mdsip server[%s].\n",serverID);
        return(-1);
    }
    if(genSubDebug > 5)
            printf("genSub: mdsPlusCreatePulse() MdsConnected[%s]\n",serverID);

    /* open MDSPlus */
    shotID = 0;
    status=MdsOpen(treeID, &shotID);
    if( !status_ok(status) ) {
            printf("genSub: Error opening tree [%s] for shot [%d].\n",
                            treeID,shotID );
        return(-1);
    }
    if(genSubDebug > 5)
               printf("genSub: mdsPlusCreatePulse() MdsOpened [%s] shot number [%d].\n",
                            treeID,shotID);

    /* write data at current(increased) shot id*/
    /* Get tokamak shot ID */
/*    sprintf(buf, "icrf:shotid.VAL");
    status = dbNameToAddr(buf, paddr);
    options = 0;
    nRequest = 1;
    status = dbGetField(paddr, DBR_LONG, &tok_pulse, &options, &nRequest, NULL);
*/    /* write tokamak shot id */
/*    idesc = descr(&dtype_long, &tok_pulse, &null);
    status = MdsPut("\\TOK_SHOT", "$", &idesc, &null);
    if(genSubDebug > 3)
            printf("genSub: mdsPlusCreatePulse() MdsPut [\\TOK_SHOT=%d]\n",tok_pulse);
*/
    /* Get current time string */
/*    sprintf(buf, "icrf:ioc:time.VAL");
    status = dbNameToAddr(buf, paddr);
    options = 0;
    nRequest = 1;
    status = dbGetField(paddr, DBR_STRING, buf, &options, &nRequest, NULL);
*/    /* write time */
/*    sdesc = descr(&dtype_cstring, buf, &null, &bufsize);
    status = MdsPut("\\PULSE_TIME", "$", &sdesc, &null);
    if(genSubDebug > 3)
            printf("genSub: mdsPlusCreatePulse() MdsPut [\\PULSE_TIME=%s]\n",buf);
*/    /* write coefficient */
    sprintf(buf, "icrf:daq:rfd:coef0.VAL");
    status = dbNameToAddr(buf, paddr);
    status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL);
    fdesc = descr(&dtype_float, &coef, &null);
    status = MdsPut("\\ICRF_0C", "$", &fdesc, &null);

    sprintf(buf, "icrf:daq:rfd:coef1.VAL");
    status = dbNameToAddr(buf, paddr);
    status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL);
    fdesc = descr(&dtype_float, &coef, &null);
    status = MdsPut("\\ICRF_1C", "$", &fdesc, &null);

    sprintf(buf, "icrf:daq:rfd:coef2.VAL");
    status = dbNameToAddr(buf, paddr);
    status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL);
    fdesc = descr(&dtype_float, &coef, &null);
    status = MdsPut("\\ICRF_2C", "$", &fdesc, &null);

    sprintf(buf, "icrf:daq:rfd:coef3.VAL");
    status = dbNameToAddr(buf, paddr);
    status = dbGetField(paddr, DBR_FLOAT, &coef, &options, &nRequest, NULL);
    fdesc = descr(&dtype_float, &coef, &null);
    status = MdsPut("\\ICRF_3C", "$", &fdesc, &null);

    status=MdsClose(treeID, &shotID);
    free(paddr);
    return(0);
}
示例#7
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;
}
示例#8
0
int mdsplus_data_put_sif(char* fileNamePath, int shotNumber, int storeMode, float blipTime, float daqTime)
{
char channelTagName[5][15] = {"\\HR_VSS01:FOO", "\\HR_VSS02:FOO", "\\HR_VSS03:FOO", "\\HR_VSS04:FOO", "\\HR_VSS05:FOO"};
char channelNodeName1[7][22] = {"\\HR_INFO:IMAGE_NO", "\\HR_INFO:IMAGE_RIGHT", "\\HR_INFO:IMAGE_TOP", "\\HR_INFO:SUBIMAGE_NO", "\\HR_INFO:T_EXPOSURE", "\\HR_INFO:T_INTEGRATE", "\\HR_INFO:T_KINETIC"};
/* char channelNodeName2[6][22] = {"\\HR_VSS01:POS_BOTTOM", "\\HR_VSS02:POS_LEFT", "\\HR_VSS03:RIGHT", "\\HR_VSS04:TOP", "\\HR_VSS05:HOR", "\\HR_VSS05:VER"};  */
char channelNodeName2[6][22] = {":POS_BOTTOM", ":POS_LEFT", ":RIGHT", ":TOP", ":HOR", ":VER"};
char channelWaveName[5][17] = {"\\HR_WAVE:FOO", "\\HR_WAVE:X_CAL0", "\\HR_WAVE:X_CAL1", "\\HR_WAVE:X_CAL2", "\\HR_WAVE:X_CAL3"};

char proterty[91][40] = {ATSIF_PROP_TYPE,ATSIF_PROP_ACTIVE,ATSIF_PROP_VERSION,ATSIF_PROP_TIME,ATSIF_PROP_FORMATTED_TIME,ATSIF_PROP_FILENAME,
ATSIF_PROP_TEMPERATURE,ATSIF_PROP_UNSTABILIZEDTEMPERATURE,ATSIF_PROP_HEAD,ATSIF_PROP_HEADMODEL,ATSIF_PROP_STORETYPE,
ATSIF_PROP_DATATYPE,ATSIF_PROP_SIDISPLACEMENT,ATSIF_PROP_SINUMBERSUBFRAMES,ATSIF_PROP_PIXELREADOUTTIME,ATSIF_PROP_TRACKHEIGHT,
ATSIF_PROP_READPATTERN,ATSIF_PROP_READPATTERN_FULLNAME,ATSIF_PROP_SHUTTERDELAY,ATSIF_PROP_CENTREROW,ATSIF_PROP_ROWOFFSET,
ATSIF_PROP_OPERATION,ATSIF_PROP_MODE,ATSIF_PROP_MODE_FULLNAME,ATSIF_PROP_TRIGGERSOURCE,ATSIF_PROP_TRIGGERSOURCE_FULLNAME,
ATSIF_PROP_TRIGGERLEVEL,ATSIF_PROP_EXPOSURETIME,ATSIF_PROP_DELAY,ATSIF_PROP_INTEGRATIONCYCLETIME,ATSIF_PROP_NUMBERINTEGRATIONS,
ATSIF_PROP_KINETICCYCLETIME,ATSIF_PROP_FLIPX,ATSIF_PROP_FLIPY,ATSIF_PROP_CLOCK,ATSIF_PROP_ACLOCK,ATSIF_PROP_IOC,
ATSIF_PROP_FREQUENCY,ATSIF_PROP_NUMBERPULSES,ATSIF_PROP_FRAMETRANSFERACQMODE,ATSIF_PROP_BASELINECLAMP,ATSIF_PROP_PRESCAN,
ATSIF_PROP_EMREALGAIN,ATSIF_PROP_BASELINEOFFSET,ATSIF_PROP_SWVERSION,ATSIF_PROP_SWVERSIONEX,ATSIF_PROP_MCP,ATSIF_PROP_GAIN,
ATSIF_PROP_VERTICALCLOCKAMP,ATSIF_PROP_VERTICALSHIFTSPEED,ATSIF_PROP_OUTPUTAMPLIFIER,ATSIF_PROP_PREAMPLIFIERGAIN,ATSIF_PROP_SERIAL,
ATSIF_PROP_DETECTORFORMATX,ATSIF_PROP_DETECTORFORMATZ,ATSIF_PROP_NUMBERIMAGES,ATSIF_PROP_NUMBERSUBIMAGES,ATSIF_PROP_SUBIMAGE_HBIN,
ATSIF_PROP_SUBIMAGE_VBIN,ATSIF_PROP_SUBIMAGE_LEFT,ATSIF_PROP_SUBIMAGE_RIGHT,ATSIF_PROP_SUBIMAGE_TOP,ATSIF_PROP_SUBIMAGE_BOTTOM,
ATSIF_PROP_BASELINE,ATSIF_PROP_CCD_LEFT,ATSIF_PROP_CCD_RIGHT,ATSIF_PROP_CCD_TOP,ATSIF_PROP_CCD_BOTTOM,ATSIF_PROP_SENSITIVITY,ATSIF_PROP_DETECTIONWAVELENGTH,
ATSIF_PROP_COUNTCONVERTMODE,ATSIF_PROP_ISCOUNTCONVERT,ATSIF_PROP_X_AXIS_TYPE,ATSIF_PROP_X_AXIS_UNIT,ATSIF_PROP_Y_AXIS_TYPE,ATSIF_PROP_Y_AXIS_UNIT,
ATSIF_PROP_Z_AXIS_TYPE,ATSIF_PROP_Z_AXIS_UNIT,ATSIF_PROP_USERTEXT,ATSIF_PROP_ISPHOTONCOUNTINGENABLED,ATSIF_PROP_NUMBERTHRESHOLDS,ATSIF_PROP_THRESHOLD1,
ATSIF_PROP_THRESHOLD2,ATSIF_PROP_THRESHOLD3,ATSIF_PROP_THRESHOLD4,ATSIF_PROP_AVERAGINGFILTERMODE,ATSIF_PROP_AVERAGINGFACTOR,ATSIF_PROP_FRAMECOUNT,
ATSIF_PROP_NOISEFILTER,ATSIF_PROP_THRESHOLD,ATSIF_PROP_TIME_STAMP};

  AT_U32 atu32_ret, atu32_noFrames, atu32_frameSize, atu32_noSubImages;
  float * imageBuffer;
  double calibValue;


  char *  sz_propertyValue;
  AT_U32 wave_mode;
  AT_U32 atu32_left,atu32_bottom,atu32_right,atu32_top,atu32_hBin, atu32_vBin;
  double at32_delay, at32_exposeTime, at32_integCycleTime, at32_kineticCycleTime;


  double x_cal0;
	double x_cal1;
	double x_cal2;
	double x_cal3;

	int imageNumber;                          /* imageNumber,    image count at time 30720/5120 = 6  int => unsigned long int  */
	int number_subImage;                   /* image count, subImage = 5  */
	int right_pixel;                         /* pixel number : 1024   int => unsigned long int  */
	int	image_length;                  /* 5120  = SubImage * 1024(frameSize) */
	
	int image_top;               /* Image Top ex.255  */
	int image_bottom;         /*Image Bottom ex.1  */
  AT_U32 total_length;
	  
	double cycle_time;   /* same value delay & kinetic_cycle & integration cycle time */
	double exposure_time;    /* exposure time ex.0.01700  */
	double integration_cycle;  /* Integration cycle time ex.0.21200  */
	char buf[50];
  char bufNode[50];
	int null = 0;
	int status;
	int socket;
	int j, i, m, iwave;
	unsigned long int k, jum;
	int dtype_float = DTYPE_FLOAT;
	int dtype_double = DTYPE_DOUBLE;
	int timeCount=0;   /* imageNumber * right_pixel  */
	int dtypeLong = DTYPE_LONG;

	double *timeArray;  /* number_image = imageNumber = Image.no_images  */
	float *dataArray;

	double *data;
	float *image_buffer1;
	
	int  tstat;
	int  dataDesc;
	int  timeDesc;
	int  wavedataDesc;
	int  idesc = descr(&dtypeLong, &tstat, &null); 
	int kkk;

  char tmpBuf[50];


 	
/* This function is used to select if the entire SIF file should be read or just the header section */
  atu32_ret = ATSIF_SetFileAccessMode(ATSIF_ReadAll);
  if(atu32_ret != ATSIF_SUCCESS) {
        printf("Could not set File access Mode. Error: %u\n", atu32_ret);
      }
      else {
        /* This function is used to open a SIF file where the file name and path are contained 
                                                           in the character array _sz_filename */
        atu32_ret = ATSIF_ReadFromFile(fileNamePath);
        if(atu32_ret != ATSIF_SUCCESS) {
          printf("Could not open File : %s.\nError: %u\n", fileNamePath,atu32_ret);
        }
        else {
          atu32_ret = ATSIF_GetNumberFrames(ATSIF_Signal, &atu32_noFrames);
          /* This function is used to retrieve the number of frames in the SIF file. */
          if(atu32_ret != ATSIF_SUCCESS) {
            printf("Could not Get Number Frames. Error: %u\n", atu32_ret);
          } else {
            printf("Image contains %u frames.\n", atu32_noFrames);
            atu32_ret = ATSIF_GetFrameSize(ATSIF_Signal, &atu32_frameSize);
            /* This function is used to retrieve the number of pixels in each frame in the SIF file. */
            if(atu32_ret != ATSIF_SUCCESS) {
              printf("Could not Get Frame Size. Error: %u\n", atu32_ret);
            } else {
              printf("Each frame contains %u pixels.\n", atu32_frameSize);
              atu32_ret = ATSIF_GetNumberSubImages(ATSIF_Signal, &atu32_noSubImages);
              /* This function is used to retrieve the number of sub-images in each frame in the SIF file. */
              if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not Get Number Sub Images. Error: %u\n", atu32_ret);
              } else {
                printf("Each frame contains %u sub images.\n", atu32_noSubImages);
                }
            }
            
            /* ################# Property Type and Value ##################*/
               sz_propertyValue = (char*)malloc((sizeof(char)*MAX_PATH));
              
/* We need This function. Because conversion and used the value from string to int value  */
              atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, ATSIF_PROP_EXPOSURETIME, sz_propertyValue, MAX_PATH);
              if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not get Property Value.\n");
              }
              else {
                at32_exposeTime = atof(sz_propertyValue);
                printf("Property Value ExposureTime : %s, %0.4f\n", sz_propertyValue,at32_exposeTime);
              }
              atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, ATSIF_PROP_DELAY, sz_propertyValue, MAX_PATH);
              if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not get Property Value.\n");
              }
              else {
                at32_delay = atof(sz_propertyValue);
                printf("Property Value Delay : %s\n", sz_propertyValue);
              }
              atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, ATSIF_PROP_INTEGRATIONCYCLETIME, sz_propertyValue, MAX_PATH);
              if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not get Property Value.\n");
              }
              else {
                at32_integCycleTime = atof(sz_propertyValue);
                printf("Property Value IntegrationCycleTime : %s, %0.4f\n", sz_propertyValue,at32_integCycleTime );
              }
              atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, ATSIF_PROP_KINETICCYCLETIME, sz_propertyValue, MAX_PATH);
              if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not get Property Value.\n");
              }
              else {
                at32_kineticCycleTime = atof(sz_propertyValue);
                printf("Property Value KineticCycleTime : %s, %0.4f \n", sz_propertyValue, at32_kineticCycleTime);
              }
              atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, ATSIF_PROP_MODE, sz_propertyValue, MAX_PATH);
              if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not get Property Value.\n");
              }
              else {
                 printf("Property Value Mode : %s\n", sz_propertyValue);
              }
              for(i = 0; i < 91; i++) {
                  atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, proterty[i], sz_propertyValue, MAX_PATH);
                  if(atu32_ret != ATSIF_SUCCESS) {
                      printf("Could not get Property Value : %s.\n",proterty[i]);
                  }
                  else {
                      printf("Property Value %s : %s\n",proterty[i], sz_propertyValue);
                  }
              }
           
           for(i = 0; i < (int)atu32_noFrames; i++) {
                  sprintf(tmpBuf,"TimeStamp %d",i);
                  atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, tmpBuf, sz_propertyValue, MAX_PATH);
                  if(atu32_ret != ATSIF_SUCCESS) {
                      printf("Could not get Property Value : %s.\n",tmpBuf);
                  }
                  else {
                      printf("Property Value %s : %s\n",tmpBuf, sz_propertyValue);
                  }
              }
            /* ################# Property Type and Value ##################*/
            for(i = 0; i < (int)atu32_noSubImages; i++) {
                
                printf("SubImage %u Properties:\n", (i + 1));
                /* This function is used to retrieve the information about each sub-image in the SIF file. */
                atu32_ret = ATSIF_GetSubImageInfo(ATSIF_Signal,
                                                  i,
                                                  &atu32_left,&atu32_bottom,
                                                  &atu32_right,&atu32_top,
                                                  &atu32_hBin,&atu32_vBin);
                if(atu32_ret != ATSIF_SUCCESS) {
                  printf("Could not Get Sub Image Info. Error: %u\n", atu32_ret);
                }
                else {
                  printf("\tleft\t: %u\tbottom\t: %u\n", atu32_left, atu32_bottom);
                  printf("\tright\t: %u\ttop\t: %u\n", atu32_right, atu32_top);
                  printf("\thBin\t: %u\tvBin\t: %u\n", atu32_hBin, atu32_vBin);
                }
           }
           /* I just check the data of frame in SIF file */
            imageBuffer  = (float*)malloc((sizeof(float))* atu32_frameSize);
            atu32_ret = ATSIF_GetFrame(ATSIF_Signal,0, imageBuffer, atu32_frameSize);
            if(atu32_ret != ATSIF_SUCCESS) {
              printf("Could not Get Frame. Error: %u\n", atu32_ret);
            } else {
              printf("The first 20 pixel values are : \n");
              for(i = 0; i < 20; i++) {
                  printf("%f\n", imageBuffer[i]);
               }
            }
             free(imageBuffer);
          }
        }
      }




#if 1
/* Wavelength = x_cal(0) + x_cal(1).X + x_cal(2).X^2 + x_cal(3).X^3  */
/* X is the pixel number on in left hand column.  double to float type changed 2009.05.15  */
/* AT_U32 atu32_ret, atu32_noFrames, atu32_frameSize, atu32_noSubImages;  */
/* AT_U32 atu32_left,atu32_bottom,atu32_right,atu32_top,atu32_hBin, atu32_vBin; */
/* AT_32 at32_delay, at32_exposeTime, at32_integCycleTime, at32_kineticCycleTime; */
/* time count number = total_length/image_length  */



cycle_time = at32_kineticCycleTime;   /* same value delay & kinetic_cycle & integration cycle time */
exposure_time = at32_exposeTime;    /* exposure time ex.0.01700  */
integration_cycle = at32_integCycleTime;  /* Integration cycle time ex.0.21200  */

/* This function is used to retrieve the information about each sub-image in the SIF file. */
atu32_ret = ATSIF_GetSubImageInfo(ATSIF_Signal, 0, &atu32_left,&atu32_bottom, &atu32_right,&atu32_top, &atu32_hBin,&atu32_vBin);
if(atu32_ret != ATSIF_SUCCESS) {
  printf("Could not Get Sub Image Info. Error: %u\n", atu32_ret);
}
 else {
 printf("\tleft\t: %u\tbottom\t: %u\n", atu32_left, atu32_bottom);
 printf("\tright\t: %u\ttop\t: %u\n", atu32_right, atu32_top);
 printf("\thBin\t: %u\tvBin\t: %u\n", atu32_hBin, atu32_vBin);
 }
 
image_top = atu32_top;               /* Image Top ex.255  */
image_bottom = atu32_bottom;         /*Image Bottom ex.1  */
image_length = atu32_frameSize * atu32_noSubImages;    /* 5120  = SubImage * 1024(frameSize) */
total_length = atu32_noFrames * atu32_frameSize * atu32_noSubImages;

image_buffer1 = (float*)malloc(4*(size_t)total_length);

atu32_ret = ATSIF_GetAllFrames(ATSIF_Signal, image_buffer1, total_length);
   if(atu32_ret != ATSIF_SUCCESS) {
       printf("Could not Get Frame. Error: %u\n", atu32_ret);
    } else {
          printf(" Success All frames data read. : \n");
    }

imageNumber = atu32_noFrames;                          /* imageNumber,    image count at time 30720/5120 = 6  int => unsigned long int  */
number_subImage = atu32_noSubImages;                   /* image count, subImage = 5  */
right_pixel = atu32_frameSize;                         /* pixel number : 1024   int => unsigned long int  */



	printf("total_length : %d \n",total_length);
	printf("image_length : %d \n",image_length);
	printf("number_image : %d \n",imageNumber);
	printf("imageNumber : %d \n",imageNumber);
	printf("number_subImage : %d \n",number_subImage);
	printf("left_pixel : %d \n",atu32_left);
	printf("right_pixel : %d \n",right_pixel);
	printf("cycle_time : %f \n",cycle_time);
	printf("exposure_time : %f \n",exposure_time);
	printf("integration_cycle : %f \n",integration_cycle);


	printf("SIF MDSplus Data Put Part. \n");
	timeCount = imageNumber*right_pixel;
	
	timeArray = (double*)malloc((sizeof(double))*imageNumber*right_pixel);  /* 1D plot Data Time - OK  */
	dataArray = (float*)malloc(4*(size_t)timeCount);  /* 1D plot Data   */
	data = (double *)malloc(sizeof(double)*right_pixel);   /* waveLength and Pixel Number  */

  iwave = 0;
  for(i=(int)atu32_frameSize; i >= 1; i--) {
       atu32_ret = ATSIF_GetPixelCalibration(ATSIF_Signal, ATSIF_CalibX, i, &calibValue);
      /* This function is used to retrieve wavelength in each frame in the SIF file.  */
       if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not Get ATSIF_GetPixelCalibration. Error: %u\n", atu32_ret);
       }else {
/*              printf("Wavelength pixel:%d , X: %f   ", i, calibValue);   */
               data[iwave] = calibValue;
               iwave ++;
       }
       }
       printf("\n");

 x_cal0 = data[0];
 x_cal1 = data[1] - data[0];
 x_cal2 = -0.000000;
 x_cal3 = -0.000000;

 if(x_cal1 < 0) {
      iwave = 0;
      for(i=1; i <= (int)atu32_frameSize; i++) {
       atu32_ret = ATSIF_GetPixelCalibration(ATSIF_Signal, ATSIF_CalibX, i, &calibValue);
      /* This function is used to retrieve wavelength in each frame in the SIF file.  */
       if(atu32_ret != ATSIF_SUCCESS) {
                printf("Could not Get ATSIF_GetPixelCalibration. Error: %u\n", atu32_ret);
       }else {
/*              printf("Wavelength pixel:%d , X: %f   ", i, calibValue);   */
               data[iwave] = calibValue;
               iwave ++;
       }
       }
      x_cal0 = data[0];
      x_cal1 = data[1] - data[0];
      x_cal2 = -0.000000;
      x_cal3 = -0.000000;
}

	printf("x_cal0 : %f \n",x_cal0);
	printf("x_cal1 : %f \n",x_cal1);
	printf("x_cal2 : %f \n",x_cal2);
	printf("x_cal3 : %f \n",x_cal3);

	if(storeMode == 1){
	  socket = MdsConnect(MDSIP);
	  if ( socket == -1)
	  {
		fprintf(stderr,"Error connecting to Server.\n");
		free(data);
		free(dataArray);
		free(timeArray);
		return 0;
	  }
	  fprintf(stdout, "\nMdsplus >>> MdsConnect(\"%s\")...OK\n",MDSIP);
  }
#if 0
  
  if(storeMode == 0){
	  sprintf(buf, "TCL(\"set tree %s/shot=-1\")",TREE);
	  status = MdsValue(buf, &idesc, &null, &len);
	  if (!status_ok(status))
	  {
		  fprintf(stderr,"Error TCL Command Set tree -1 \n");
		  return -1;
	  }
	  sprintf(buf, "TCL(\"create pulse %ld\")",shotNumber);
	  status = MdsValue(buf, &idesc, &null, &len);
	  if (!status_ok(status))
	  {
		  fprintf(stderr,"Error TCL Command Create Pulse  \n");
		  return -1;
	  }
	  sprintf(buf, "TCL(\"close\")",TREE);
	  status = MdsValue(buf, &idesc, &null, &len);
  }
#endif
  
  
	status = MdsOpen(TREE, &shotNumber);
	if (!status_ok(status))
	{
		fprintf(stderr,"Error openning tree for shot %l. \n",shotNumber);
		return -1;
	}
    fprintf(stdout, "\nMdsplus >>> MdsOpen(\"%s %d\")...OK\n",TREE,shotNumber);

	
/*  MdsPut Visible Spectrometer Data Infomation   */

	sprintf(buf, "FS_FLOAT(%d)", imageNumber);
	status  = MdsPut(channelNodeName1[0], buf,&null); 

	sprintf(buf, "FS_FLOAT(%d)", right_pixel);
	status  = MdsPut(channelNodeName1[1], buf,&null);

  sprintf(buf, "FS_FLOAT(%d)", image_top);
	status  = MdsPut(channelNodeName1[2],  buf,&null);

	sprintf(buf, "FS_FLOAT(%d)", number_subImage);
	status  = MdsPut(channelNodeName1[3],  buf,&null);

	sprintf(buf, "FS_FLOAT(%f)", exposure_time);
	status  = MdsPut(channelNodeName1[4], buf,&null); 

	sprintf(buf, "FS_FLOAT(%f)", integration_cycle);
	status  = MdsPut(channelNodeName1[5], buf,&null);

	sprintf(buf, "FS_FLOAT(%f)", cycle_time);
	status  = MdsPut(channelNodeName1[6], buf,&null); 
	wavedataDesc = descr(&dtype_double, data, &right_pixel, &null);

  atu32_ret = ATSIF_GetPropertyValue(ATSIF_Signal, ATSIF_PROP_X_AXIS_TYPE, sz_propertyValue, MAX_PATH);
  if(atu32_ret != ATSIF_SUCCESS) {
    printf("Could not get Property Value : %s.\n",ATSIF_PROP_X_AXIS_TYPE);
  } else {
          if(strcmp(sz_propertyValue,"Wavelength") != 0){
               wave_mode = 0;   /*pixel mode */
            } else {
               wave_mode = 1;  /*wavelength mode */
            }
            printf("Property Value %s : %s\n",ATSIF_PROP_X_AXIS_TYPE, sz_propertyValue);
  }

	if (wave_mode==1)
	{
		fprintf(stdout, "DAQ WAVEMode OK : %s \n",MODEWAVE);
#if 0
		fprintf(stdout,"1 Wave Data Cal 0 : %f \n", data[0]);
		fprintf(stdout,"1 Wave Data Cal 1 : %f \n", data[1]);
		for (i=0; i<right_pixel; i++)
		{	
		data[i] = x_cal0 + x_cal1*(i) + x_cal2*((i)^2) + x_cal3*((i)^3);
		}
		fprintf(stdout,"2 Wave Data Cal 0 : %f \n", data[0]);
		fprintf(stdout,"2 Wave Data Cal 1 : %f \n", data[1]);
#endif

		status  = MdsPut(channelWaveName[0], "BUILD_SIGNAL($1,,)", &wavedataDesc, &null);

		sprintf(buf, "FS_FLOAT(%f)", x_cal0);
		status  = MdsPut(channelWaveName[1], buf,&null); 
		sprintf(buf, "FS_FLOAT(%f)", x_cal1);
		status  = MdsPut(channelWaveName[2], buf,&null); 
		sprintf(buf, "FS_FLOAT(%f)", x_cal2);
		status  = MdsPut(channelWaveName[3], buf,&null); 
		sprintf(buf, "FS_FLOAT(%f)", x_cal3);
		status  = MdsPut(channelWaveName[4], buf,&null); 
	}
	else if (wave_mode!=1)
	{
		fprintf(stdout, "DAQ PIXMode  OK : %s \n",MODEPIX);
		for (i=0; i<right_pixel; i++)
		{
		data[i] = i+1;
		}
	}
	else 
	{
		fprintf(stdout, "DAQ PIXMode  No Good  : %s \n",MODEPIX);
		for (i=0; i<right_pixel; i++)
		{
		data[i] = i+1;
		}
		fprintf(stderr, "Error mode is not waveLength and Pixel number \n");
	}



	fprintf(stdout, "CA_DAQ Start Time : %f  & BLIP Time : %f \n",daqTime, blipTime);
	timeDesc = descr(&dtype_double, timeArray, &imageNumber, &null); 
	for (i=0; i<imageNumber; i++)
	{
		timeArray[i] = (double)(daqTime-blipTime)+ i*cycle_time;
		printf("timeArray : %f,  frame nu : %d  ",timeArray[i],i);
	}
	printf("\n");
/* 1D Data Time Plot image length = imagenumber * right_pixel  OK - 2008.02.11
	timeDesc = descr(&dtype_float, timeArray, &timeCount, &null); 

	fprintf(out,"int: timeCount %d\n",timeCount);
	for (i=0; i<timeCount; i++)
	{
			    
		timeArray[i] = (float)i/10;
		fprintf(out,"int2: timeArray2 : %f,  i2 : %d\n",timeArray[i],i);
	}
	dataDesc = descr(&dtype_float, dataArray, &timeCount, &null); //descr(TYPE, Data1D, 1Dcount,0)
*/

	kkk=1;
	dataDesc = descr(&dtype_float, dataArray, &right_pixel, &imageNumber, &kkk, &null);  /* descr(TYPE, Data3D, nx,ny,nz,0) ?? */

	if (wave_mode==1)
	{
		fprintf(stdout, "DAQ WAVEMode OK : %s \n",MODEWAVE);

		for (m=0,k=0; m<number_subImage; m++)
		{
			for (jum=0,j=0; j<imageNumber; j++)
			{   
				for (i=0; i<right_pixel; i++, k++)
				{	
					dataArray[j*right_pixel + i] = image_buffer1[k];
/*					printf("dataArray Put : %f,   image_buffer Data : %f, k = %d\n", dataArray[j*right_pixel + i],image_buffer1[k],k);  */
				}
				
				if(imageNumber>1)
				{
					jum=(j+1)*image_length + (m*right_pixel);  /* right_pixel = 1024, image_length = 5120 */
					k= jum;
				}
				
			}
			k = (m+1)*right_pixel ;

			status  = MdsPut(channelTagName[m], "BUILD_SIGNAL($1,,$2)", &dataDesc, &timeDesc, &null);   /* Data Put 2D and Time TEST ING */
			/*   MDSput The VSS Data Infomations about Image    */
			atu32_ret = ATSIF_GetSubImageInfo(ATSIF_Signal,
                                                  m,
                                                  &atu32_left,&atu32_bottom,
                                                  &atu32_right,&atu32_top,
                                                  &atu32_hBin,&atu32_vBin);
      if(atu32_ret != ATSIF_SUCCESS) {
           printf("Could not Get Sub Image Info. Error: %u\n", atu32_ret);
      }
			sprintf(buf, "FS_FLOAT(%d)", atu32_bottom);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[0]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_left);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[1]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_right);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[2]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_top);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[3]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_hBin);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[4]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_vBin);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[5]);
			status  = MdsPut(bufNode, buf,&null);
			printf("check Node name for each channel VSS Name: %s\n",bufNode);
		}
	}
	else if (wave_mode!=1)
	{
		fprintf(stdout, "DAQ PIXMode  OK : %s \n",MODEPIX);

		for (m=0,k=0; m<number_subImage; m++)
		{
			for (jum=0,j=0; j<imageNumber; j++)
			{   
				for (i=0; i<right_pixel; i++, k++)
				{	
/*					if(k==0){
					fprintf(stdout, "MDSplus Put the Data image_lastBuffData : %f Num k : %d \n", image_buffer1[k], k);
					}
*/
					dataArray[j*right_pixel + i] = image_buffer1[k];

/*					printf("dataArray Put : %f,   image_buffer Data : %f, k = %d\n", dataArray[j*right_pixel + i],image_buffer1[k],k);  */
/*					if(k==1023 || k==1024){
					fprintf(stdout, "MDSplus Put the Data image_lastBuffData 1023 or 1024 : %f Num k : %d \n", image_buffer1[k], k);
					}
*/
				}
				if(imageNumber>1)
				{
/*							jum=jum + (m*right_pixel) + (image_length);  //right_pixel = 1024, image_length = 5120  */
							jum=(j+1)*image_length + (m*right_pixel);  /* right_pixel = 1024, image_length = 5120   */
							k= jum;
				}
			}
			k = (m+1)*right_pixel ;
/*
//			status  = MdsPut(channelTagName[m], "BUILD_SIGNAL($1,,)", &dataDesc, &null);  //Data Put OK 2008.01.28 
//			status  = MdsPut(channelTagName[m], "BUILD_SIGNAL($1,,$2)", &dataDesc, &timeDesc, &null);   //Data Put 1D and Time OK 2008.02.11
//			status  = MdsPut(channelTagName[m], "BUILD_SIGNAL($1,,$2)", &dataDesc, &timeDesc, &null);   //Data Put 2D and Time TEST ING
*/
			status  = MdsPut(channelTagName[m], "BUILD_SIGNAL($1,,BUILD_WITH_UNITS($2,'S')", &dataDesc, &timeDesc, &null); 
/*   MDSput The VSS Data Infomations about Image    */
			atu32_ret = ATSIF_GetSubImageInfo(ATSIF_Signal,
                                                  m,
                                                  &atu32_left,&atu32_bottom,
                                                  &atu32_right,&atu32_top,
                                                  &atu32_hBin,&atu32_vBin);
      if(atu32_ret != ATSIF_SUCCESS) {
           printf("Could not Get Sub Image Info. Error: %u\n", atu32_ret);
      }
			sprintf(buf, "FS_FLOAT(%d)", atu32_bottom);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[0]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_left);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[1]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_right);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[2]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_top);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[3]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_hBin);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[4]);
			status  = MdsPut(bufNode, buf,&null);

			sprintf(buf, "FS_FLOAT(%d)", atu32_vBin);
			sprintf(bufNode, "\\HR_VSS0%d%s",m+1,channelNodeName2[5]);
			status  = MdsPut(bufNode, buf,&null);
			printf("check Node name for each channel VSS Name: %s\n",bufNode);
/*
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'wave'),BUILD_DIM(BUILD_WINDOW(0,2,10),BUILD_SLOPE($3)))", &dataDesc, &data, &timeDesc, &null);
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'wave'),BUILD_WITH_UNITS($3,'sec'))", &dataDesc, &data, &timeDesc, &null);
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'wave'),BUILD_WITH_UNITS($3,'sec'))", &dataDesc, &data2, &timeDesc, &null);
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'wave'),BUILD_WITH_UNITS($3,'sec'))", &dataDesc, 1024, &timeDesc, &null);
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'Sec'),BUILD_WITH_UNITS($3,'wave'))", &dataDesc, &timeDesc, &data2, &null);
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'Sec'),BUILD_WITH_UNITS($3,'wave'))", &dataDesc, &timeDesc, &right_pixel, &null);
//			status = MdsPut(channelTagName[m], "BUILD_SIGNAL(BUILD_WITH_UNITS($1,'Counts'),BUILD_WITH_UNITS($2,'Sec'),BUILD_WITH_UNITS($3,'wave'))", &dataDesc, &timeDesc, &right_pixel, &null);
//			Image Test Put    mdsput,"\TOP.X_IMAGE:FAST_CCD1","BUILD_SIGNAL($,*,MAKE_DIM(MAKE_WINDOW(0,425,0.0),MAKE_SLOPE(0.001)),MAKE_DIM(MAKE_WINDOW(0,401,0.0),MAKE_SLOPE(0.001)),MAKE_DIM(MAKE_WINDOW(0,$,0.0),MAKE_SLOPE(MAKE_WITH_UNITS($,'s'))))",jpgimage,filecount_1,dtime

//			fprintf(stdout, "MDSplus Put the Data channelTagName2 : %s int Size : %f \n", channelTagName[m],data2);
//			free(dataArray);
*/
		}
	}
	else 
	{
		fprintf(stderr, "Error mode is not waveLength and Pixel number \n");
	}
	free(data);
	free(timeArray);
	free(dataArray);

/*  MDSplus Close Tree  */
 	status = MdsClose(TREE, &shotNumber);
 	if (!status_ok(status))
	{
 		fprintf(stderr,"Error closing tree for shot %l. \n",shotNumber);
 		return -1;
	}
   fprintf(stdout, "\nMdsplus >>> MdsClose(\"%d\")...OK\n",shotNumber);

atu32_ret = ATSIF_CloseFile();
      if(atu32_ret != ATSIF_SUCCESS) {
           printf("Could not get Property Value.\n");
      }

#endif

	return 1;
}