diff --git a/devexec.c b/devexec.c index 9c7fd293..60848781 100644 --- a/devexec.c +++ b/devexec.c @@ -431,11 +431,15 @@ } break; case HWBusy: - if(pCountInt) + if(pCountInt != NULL && pDrivInt != NULL) { + SetStatus(eCountDrive); + } + else if(pCountInt != NULL && pDrivInt == NULL) + { SetStatus(eCounting); } - else if(pDrivInt) + else if(pDrivInt != NULL && pCountInt == NULL) { SetStatus(eDriving); } diff --git a/hkl.c b/hkl.c index 3fce290e..05edaa5d 100644 --- a/hkl.c +++ b/hkl.c @@ -603,12 +603,23 @@ static int calculateBisecting(MATRIX z1, pHKL self, SConnection *pCon, } /* - giving up! + giving up! But calculate one more time in order to show Jurg where + he should be. */ - for(i = 0; i < 4; i++) - { - fSet[i] = .0; + z1mToBisecting(self->fLambda,z1,&stt,&om,&chi,&phi); + if(iRetry == 1){ + rotatePsi(om,chi,phi,psi,&ompsi,&chipsi,&phipsi); + fSet[0] = (float)stt; + fSet[1] = (float)ompsi; + fSet[2] = (float)chipsi; + fSet[3]= (float)phipsi; + } else { + fSet[0] = (float)stt; + fSet[1] = (float)om; + fSet[2] = (float)chi; + fSet[3]= (float)phi; } + return 0; } /*----------------------------------------------------------------------*/ @@ -1203,6 +1214,7 @@ ente: char pBueffel[512]; float fUB[9], fPsi, fVal; float fHKL[3], fSet[4]; + double dVal; pHKL self = NULL; CommandList *pCom = NULL; pDummy pDum = NULL; @@ -1269,6 +1281,34 @@ ente: return 1; } } + else if(strcmp(argv[1],"fromangles") == 0) + { + if(argc < 6) + { + SCWrite(pCon, + "ERROR: need stt, om, chi,phi to calculate HKL from angles", + eError); + return 0; + } + for(i = 0; i < 4; i++) + { + iRet = Tcl_GetDouble(InterpGetTcl(pSics),argv[i+2],&dVal); + if(iRet != TCL_OK) + { + snprintf(pBueffel,511,"ERROR: failed to convert %s to number", + argv[i+2]); + SCWrite(pCon,pBueffel,eError); + return 0; + } + fSet[i] = (float)dVal; + } + angle2HKL(self,(double)fSet[0],(double)fSet[1], + (double)fSet[2],(double)fSet[3],fHKL); + sprintf(pBueffel,"HKL from angles: %8.4f %8.4f %8.4f ", + fHKL[0], fHKL[1],fHKL[2]); + SCWrite(pCon,pBueffel,eValue); + return 1; + } /*------------- lambda */ else if(strcmp(argv[1],"lambda") == 0) { diff --git a/motreg.c b/motreg.c index 348f833b..f47bc4ed 100644 --- a/motreg.c +++ b/motreg.c @@ -10,7 +10,7 @@ Mark Koennecke, August 2002 -----------------------------------------------------------------------*/ #include -#include +#include #include "fortify.h" #include "motreg.h" diff --git a/napi5.c b/napi5.c index 46c0b065..35e1173a 100644 --- a/napi5.c +++ b/napi5.c @@ -53,6 +53,11 @@ char iAccess[2]; } NexusFile5, *pNexusFile5; +/* + forward declaration of NX5closegroup in order to get rid of a nasty + warning +*/ +NXstatus CALLING_STYLE NX5closegroup (NXhandle fid); /*--------------------------------------------------------------------*/ @@ -116,14 +121,12 @@ unsigned int vers_major, vers_minor, vers_release, am1 ; hid_t fapl; int mdc_nelmts; - unsigned long rdcc_nelmts; + int rdcc_nelmts; size_t rdcc_nbytes; double rdcc_w0; - /* turn off the automatic HDF error handling */ - - H5Eset_auto(NULL,NULL); - + /* turn off the automatic HDF error handling */ + H5Eset_auto(NULL,NULL); #ifdef USE_FTIME struct timeb timeb_struct; #endif @@ -193,6 +196,12 @@ iRet=H5Pget_cache(fapl,&mdc_nelmts,&rdcc_nelmts,&rdcc_nbytes,&rdcc_w0); rdcc_nbytes=(size_t)cacheSize; iRet = H5Pset_cache(fapl,mdc_nelmts,rdcc_nelmts,rdcc_nbytes,rdcc_w0); + /* + setting the close degree is absolutely necessary in HDF5 + versions > 1.6. If you use a lessere version and the compiler + complains, comment it out but keep this in mind. + */ + H5Pset_fclose_degree(fapl,H5F_CLOSE_STRONG); am1 = H5F_ACC_TRUNC; pNew->iFID = H5Fcreate (filename, am1, H5P_DEFAULT, fapl); } else { @@ -331,7 +340,8 @@ pNexusFile5 pFile = NULL; int iRet; - pFile=NXI5assert(*fid); + pFile=NXI5assert(*fid); + iRet=0; iRet = H5Fclose(pFile->iFID); if (iRet < 0) { @@ -347,6 +357,7 @@ } free (pFile); *fid = NULL; + H5garbage_collect(); return NX_OK; } @@ -1139,7 +1150,68 @@ } return 1; } + /* --------------------------------------------------------------------- */ + /* Operator function. */ + + herr_t group_info1(hid_t loc_id, const char *name, void *opdata) + { + NexusFile5 self; + H5G_stat_t statbuf; + self.iNX = *((int*)opdata); + H5Gget_objinfo(loc_id, name, 0, &statbuf); + + switch (statbuf.type) + { + case H5G_GROUP: + self.iNX++; + *((int*)opdata)=self.iNX; + break; + case H5G_DATASET: + self.iNX++; + *((int*)opdata)=self.iNX; + break; + } + return 0; + } + + /*-------------------------------------------------------------------------*/ + + NXstatus CALLING_STYLE NX5getgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass) + { + pNexusFile5 pFile; + hid_t atype,attr_id; + char data[64]; + int iRet; + + pFile = NXI5assert (fid); + /* check if there is a group open */ + if (pFile->iCurrentG == 0) { + strcpy (pName, "root"); + strcpy (pClass, "NXroot"); + pFile->iNX=0; + iRet=H5Giterate(pFile->iFID,"/",0,group_info1,&pFile->iNX); + *iN=pFile->iNX; + } + else { + strcpy (pName,pFile->name_ref); + attr_id = H5Aopen_name(pFile->iCurrentG,"NX_class"); + if (attr_id<0) { + strcpy(pClass,"non"); + } else { + atype=H5Tcopy(H5T_C_S1); + H5Tset_size(atype,64); + H5Aread(attr_id, atype, data); + strcpy(pClass,data); + pFile->iNX=0; + iRet=H5Giterate(pFile->iFID,pFile->name_ref,0,group_info1, &pFile->iNX); + *iN=pFile->iNX; + H5Aclose(attr_id); + } + } + return NX_OK; + } + /*-------------------------------------------------------------------------*/ NXstatus CALLING_STYLE NX5getnextentry (NXhandle fid,NXname name, NXname nxclass, int *datatype) @@ -1151,6 +1223,7 @@ char data[128]; char ph_name[1024]; info_type op_data; + int iRet_iNX=-1; pFile = NXI5assert (fid); op_data.iname = NULL; @@ -1161,6 +1234,18 @@ } iRet=H5Giterate(pFile->iFID,pFile->name_ref,&idx,nxgroup_info,&op_data); strcpy(nxclass,""); + + if (pFile->iCurrentG == 0) { + pFile->iNX=0; + iRet_iNX = H5Giterate(pFile->iFID,"/",0,group_info1,&pFile->iNX); + } else { + pFile->iNX=0; + iRet_iNX = H5Giterate(pFile->iFID,pFile->name_ref,0,group_info1, &pFile->iNX); + } + if (idx == pFile->iNX) { + iRet_iNX = 2; + } + if (iRet > 0) { pFile->iStack5[pFile->iStackPtr].iCurrentIDX++; @@ -1245,23 +1330,22 @@ H5Tclose(atype); H5Dclose(grp); } - return NX_OK; - } - else if (iRet==0) - { - if (op_data.iname != NULL) { - free(op_data.iname); - } - pFile->iStack5[pFile->iStackPtr].iCurrentIDX = 0; - return NX_EOD; - } + return NX_OK; + } else { + if (iRet_iNX == 2) { + if (op_data.iname != NULL) { + free(op_data.iname); + } + pFile->iStack5[pFile->iStackPtr].iCurrentIDX = 0; + return NX_EOD; + } if (op_data.iname != NULL) { free(op_data.iname); } NXIReportError (NXpData, - "ERROR: Iteration was not successful"); + "ERROR: Iteration (directory) was not successful"); return NX_ERROR; } } @@ -1567,16 +1651,42 @@ int iPType,rank; char *iname = NULL; unsigned int idx; + int intern_idx=-1; pFile = NXI5assert (fileid); idx=pFile->iAtt5.iCurrentIDX; + iRet=0; if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0)) { /* global attribute */ pFile->iVID=H5Gopen(pFile->iFID,"/"); - iRet=H5Aiterate(pFile->iVID,&idx,attr_info,&iname); + intern_idx=H5Aget_num_attrs(pFile->iVID); + if (intern_idx > idx) { + iRet=H5Aiterate(pFile->iVID,&idx,attr_info,&iname); + } + else + { + iRet=0; + } + intern_idx=-1; + if (iRet < 0) { + NXIReportError (NXpData, "ERROR iterating through ROOT Attr. list!"); + return NX_ERROR; + } } else { - iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname); + intern_idx=H5Aget_num_attrs(pFile->iCurrentD); + if (intern_idx > idx) { + iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname); + } + else + { + iRet=0; + } + intern_idx=-1; + if (iRet < 0) { + NXIReportError (NXpData, "ERROR iterating through Attr. list!"); + return NX_ERROR; + } } if (iRet>0) { @@ -1650,31 +1760,28 @@ H5Tclose(atype); H5Sclose(aspace); H5Aclose(pFile->iCurrentA); - if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0)) - { - /* close group for global attribute */ - H5Gclose(pFile->iVID); - } return NX_OK; - } - else if (iRet==0) - { - if (iname != NULL) { - free(iname); - } - if (idx == 0) - { - pFile->iAtt5.iCurrentIDX = 0; - return NX_EOD; - } - pFile->iAtt5.iCurrentIDX = 0; - return NX_EOD; - } + } else { - if (iname != NULL) { - free(iname); - } + if ((pFile->iCurrentD == 0) && (pFile->iCurrentG==0)) + { + /* global attribute */ + intern_idx=H5Aget_num_attrs(pFile->iVID); + } else { + if (pFile->iCurrentD>0){ + intern_idx=H5Aget_num_attrs(pFile->iCurrentD); + } else { + intern_idx=H5Aget_num_attrs(pFile->iCurrentG); + } + } + if ((intern_idx == 0)||(intern_idx == idx)) { + pFile->iAtt5.iCurrentIDX = 0; + if (iname != NULL) { + free(iname); + } + return NX_EOD; + } NXIReportError (NXpData, "ERROR: Iteration was not successful"); return NX_ERROR; @@ -1792,33 +1899,42 @@ pNexusFile5 pFile; char *iname = NULL; unsigned int idx; - int iRet; + herr_t iRet; pFile = NXI5assert (fid); idx=0; + *iN = idx; if (pFile->iCurrentD == 0 && pFile->iCurrentG == 0) { /* global attribute */ pFile->iVID=H5Gopen(pFile->iFID,"/"); iRet = H5Aiterate(pFile->iVID,&idx,attr_info,&iname); - iRet = 1; - while (iRet != 0) { - iRet = H5Aiterate(pFile->iVID,&idx,attr_info,&iname); - } + if (iRet < 0) { + NXIReportError (NXpData, "iterating ERROR!"); + return NX_ERROR; + } + idx=H5Aget_num_attrs(pFile->iVID); + if (idx > 0) { *iN = idx; } else { *iN = 1; } + /* if (iname != NULL) { free(iname); - } + } + */ return NX_OK; } else { - iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname); + if (pFile->iCurrentD>0) { + iRet=H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname); + } else { + iRet=H5Aiterate(pFile->iCurrentG,&idx,attr_info,&iname); + } } if (iRet<0) { NXIReportError (NXpData, "Attribute number cannot be fixed!"); @@ -1828,84 +1944,17 @@ *iN=idx; return NX_OK; } - iRet = 1; - while (iRet != 0) { - iRet = H5Aiterate(pFile->iCurrentD,&idx,attr_info,&iname); - } + idx=H5Aget_num_attrs(pFile->iCurrentD); if (idx > 0) { *iN = idx; } else { *iN = 1; } - if (iname != NULL) { - free(iname); - } return NX_OK; } - /* --------------------------------------------------------------------- */ - /* Operator function. */ - - herr_t group_info1(hid_t loc_id, const char *name, void *opdata) - { - NexusFile5 self; - H5G_stat_t statbuf; - self.iNX = *((int*)opdata); - H5Gget_objinfo(loc_id, name, 0, &statbuf); - - switch (statbuf.type) - { - case H5G_GROUP: - self.iNX++; - *((int*)opdata)=self.iNX; - break; - case H5G_DATASET: - self.iNX++; - *((int*)opdata)=self.iNX; - break; - } - return 0; - } - - /*-------------------------------------------------------------------------*/ - - NXstatus CALLING_STYLE NX5getgroupinfo (NXhandle fid, int *iN, NXname pName, NXname pClass) - { - pNexusFile5 pFile; - hid_t atype,attr_id; - char data[64]; - int iRet; - - pFile = NXI5assert (fid); - /* check if there is a group open */ - if (pFile->iCurrentG == 0) { - strcpy (pName, "root"); - strcpy (pClass, "NXroot"); - pFile->iNX=0; - iRet=H5Giterate(pFile->iFID,"/",0,group_info1,&pFile->iNX); - *iN=pFile->iNX; - } - else { - strcpy (pName,pFile->name_ref); - attr_id = H5Aopen_name(pFile->iCurrentG,"NX_class"); - if (attr_id<0) { - strcpy(pClass,"non"); - } else { - atype=H5Tcopy(H5T_C_S1); - H5Tset_size(atype,64); - H5Aread(attr_id, atype, data); - strcpy(pClass,data); - pFile->iNX=0; - iRet=H5Giterate(pFile->iFID,pFile->name_ref,0,group_info1, &pFile->iNX); - *iN=pFile->iNX; - H5Aclose(attr_id); - } - } - return NX_OK; - } - /*-------------------------------------------------------------------------*/ NXstatus CALLING_STYLE NX5getgroupID (NXhandle fileid, NXlink* sRes) diff --git a/status.c b/status.c index 1e8ecf7e..27fc8063 100644 --- a/status.c +++ b/status.c @@ -64,6 +64,7 @@ "Halted", "Dead", "Waiting for User Input", + "Counting/Driving", NULL }; static char *iText[] = { @@ -80,6 +81,7 @@ "halt", "dead", "input", + "count/drive", NULL }; static pICallBack pCall = NULL; diff --git a/status.h b/status.h index 1d924560..d54c893b 100644 --- a/status.h +++ b/status.h @@ -21,7 +21,8 @@ eBatch, eHalted, eDead, - eInput + eInput, + eCountDrive } Status; /* for status display */