/*subroutine file to create array of mass readings for mks rga*/ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* for S_rec_outMem */ #include /* for S_dev_noDeviceFound */ #include /* for wavformRecord */ #include /* for epicsMutexId */ #include /* for recGblRecordError() */ #include /* for DBF_DOUBLE */ /* local parameters */ #define SUCCESS 0 #define ERROR -1 /* Local prototypes */ static long mksRGA_InitArrayOut(subRecord *psub); static long mksRGA_ArrayOut(subRecord *psub); /*1 torr = 133.322368 pascals */ /* store mass and correlating pressure in an array of 101 length (includes 0)*/ typedef struct intArrayOut_s { epicsMutexId lock; double *preadings; /* ptr to waveform data from :COEF2IVB */ unsigned long *pnord; /* waveform pv, number of elements read */ unsigned long nelem; /* max number of waveform elements */ } intArrayOut_ts; /*============================================================================= Name: InitArrayOut Abs: Initialize records that use in mass spec Args: Type Name Access Description ------------------- ----------- ---------- ---------------------------- subRecord * psub read/write pointer to subroutine record Rem: Init Subroutine for $(PRI):$(SEC):$(POS):PRESS_ARRAY Input: -------- field(DESC, "Subroutine Record") field(INAM, "InitArrayOut") field(SNAM, "ArrayOut") field(INPA, "$(PRI):$(SEC):$(POS):CURMASS_I CP") field(INPB, "$(PRI):$(SEC):$(POS):CUR_CALC CP") field(INPC, "$(PRI):$(SEC):$(POS):PRESS_BUF.VAL") WAVEFORM field(INPD, "$(PRI):$(SEC):$(POS):TOTAL_PRESS.VAL PP") field(INPE, "$(PRI):$(SEC):$(POS):HYDR_PRESS.VAL PP") field(FLNK, "$(PRI):$(SEC):$(POS):PRESS_BUF") Output: -------- DPVT = Pointer to private device information mutex id waveform data number of elements read in waveform maximum number of elements in array Side: None Ret: int 0 - Successful -1 - for invalid INPA or invalid INPB ==============================================================================*/ static long mksRGA_InitArrayOut(subRecord *psub) { long status=SUCCESS; unsigned long i=0; DBADDR *pAddr=NULL; waveformRecord *pwf =NULL; struct intArrayOut_s *pdev =NULL; /* Check that this pv has not already been initialized */ if (psub->dpvt) return( -1 ); psub->dpvt = 0; /* Determine if we have a DB_LINK as INPC, if not then we'll have a CONSTANT */ if((psub->inpc).type==CONSTANT) { recGblRecordError(S_dev_noDeviceFound,(void *)psub,"sub: init_record"); return(ERROR); } /* Get the pointer to the record in INPB. * Is this a valid pv? If so, then verify that data type is double. * Later need to verify that this is a wavefore record... */ pAddr = dbGetPdbAddrFromLink(&psub->inpc); if (!pAddr || (pAddr->field_type != DBF_DOUBLE)) return(ERROR); /* Create an array of 2 pointers */ pdev = (intArrayOut_ts *)calloc(sizeof(intArrayOut_ts),1); if (!pdev) { recGblRecordError(S_rec_outMem,(void *)psub,"sub: init_record"); return(ERROR); } /* Set the private data information */ pwf = (waveformRecord *)pAddr->precord; pdev->preadings = (double *)pAddr->pfield; /* ptr to data :IVB */ pdev->pnord = &pwf->nord; /* ptr to # of wf items */ pdev->nelem = pAddr->no_elements; /* max number of data elements in record */ pdev->lock = epicsMutexMustCreate(); /* mutex to be used when updating waveform */ /* initalize the waveform to deal with plotting issues in EDM */ epicsMutexLock(pdev->lock); for(i=0; inelem; i++) pdev->preadings[i]=0.000000000000001; pdev->preadings[0]=0.000000000000001; epicsMutexUnlock(pdev->lock); /* return ptr to private device information */ psub->dpvt = pdev; return(status); } static long mksRGA_ArrayOut(subRecord *psub) { if(psub == NULL) return 0; long status = SUCCESS; /* return status */ int index; /* index counter */ int mass; double pressure; double totalpressure=0.0; double hydropressure=0.0; intArrayOut_ts *pdev = psub->dpvt; /* Get the address of wavefor record, and pointer to data */ if (!pdev || !pdev->preadings) { return(ERROR); } if (!pdev->nelem) { if (psub->f) printf("ArrayOut: No data in waveform (INPC) %s\n",psub->name); return(status); } mass = (int)(psub->a + 0.5); /*read mass in: adding 0.5 and truncateing is the same as rounding*/ pressure = (double) psub->b; /*read pressure in*/ if (psub->f) printf("\n\nmass=%d\tpressure=%e NELM=%ld NORD=%ld\n\n", mass,pressure,pdev->nelem,*(pdev->pnord) ); if ((mass<0) || (mass>=pdev->nelem)) { if (psub->f) printf("Mass (%d) is out-of-range (0-100)\n",mass); return(status); } /* set number of elements read */ *(pdev->pnord)=pdev->nelem; epicsMutexLock(pdev->lock); pdev->preadings[mass]=pressure; /* use mass as the index*/ epicsMutexUnlock(pdev->lock); /* * If starting a new scan put data back into graph * (when a new scan begins it erases graph otherwise) * else update data points normally as the scan progresses */ if(mass == 1) { for(index=1; indexnelem; index++) { if (psub->f) { printf("%e" ,pdev->preadings[mass]); if (index%10) printf("\n"); } totalpressure += pdev->preadings[index]; /* Keep track of hydrocarbon pressure when amu>45 */ if(index>=45) hydropressure += pdev->preadings[index]; }/* End of FOR loop */ dbPutLink(&psub->inpd, DBR_DOUBLE, &totalpressure, 0); dbPutLink(&psub->inpe, DBR_DOUBLE, &hydropressure, 0); } return(status); } static long mksRGA_killAllZeroes(subRecord *psub) { /* int counter=0; */ /* double readings[101]; */ /* if(counter==0) */ /* { */ /* int i; */ /* for(i=1;i<101;i++) */ /* { */ /* readings[i]=.00000000000001; */ /* dbPutLink(&psub->inpa, DBR_DOUBLE, readings, i); */ /* } */ /* counter++; */ /* } */ /* initalize the waveform to deal with plotting issues in EDM */ return 0; } epicsRegisterFunction(mksRGA_InitArrayOut); epicsRegisterFunction(mksRGA_ArrayOut); epicsRegisterFunction(mksRGA_killAllZeroes);