/* write example NeXus/HDF data file using the napi.c library */ #include #include #include #include #include #ifdef __MWERKS__ #include #include #endif #define ENTRY_CLASS "NXentry" /* name of all proper entrys */ #define SCAN_CLASS "NXdata" /* name of all proper data1 scans */ #define DEFAULT_CLASS "NXdefault" /* name of all proper data1 scans */ #define INSTRUMENT_CLASS "NXinstrument" /* name of class for all instrument Vgroups */ #define SAMPLE_CLASS "NXsample" /* name of class for all sample Vgroups */ #define PI 3.14159265 #define CCDXY 32 /* small use 32, big use 64 */ #define CCDZ 3 /* small use 3, big use 11 */ #include "napi.h" #define LOCATION "APS:6-BM-R" #define PROG_NAM "ORDIF" #define VERSION "0.2 alpha" #define SECONDS(X) ( ((float)(clock()-X))/((float)CLOCKS_PER_SEC) ) clock_t startTick; int reOpenTest(char *file_name, int num, int ientry_start); void write100scan(NXhandle file_id, int ientry); void NXstring(NXhandle file_id, char *name, char *str); void NXputStringAttr(NXhandle file_id, char *name, char *str); void main(int argc, char *argv[]) { NXhandle file_id; int32 dims[10]; int32 j, ii, iii; int i; /* index of loops [0,dim] */ float32 x; int one=1; /* a 32 bit one, used with DFNT_INT32 */ int two=2; /* a 32 bit two, used with DFNT_INT32 */ int three=3; /* a 32 bit three, used with DFNT_INT32 */ char equation[255]; char *file_name = "Nexamples.hdf"; char *user_name = "John Q. Public"; char *user_mail = "Chemistry Dept.\rBerkeley U.\r CA 11111"; char *user_email = "joe@pdp8.chem.mit.edu"; char *user_phone = "900-555-1212"; char *user_fax = "900-555-1213"; float32 *CCD_x_axis,*CCD_y_axis; int16 ***ccd_data; float32 gain1, gain2; float32 hkl_near[3]; float32 mono_energy[501]; float32 theta[51]; float32 ttheta[51]; float32 chi[51]; float32 phi[51]; float32 h1[360], k1[360], l1[360]; int32 ic1[501]; int32 ic2[501]; int32 scint[360]; float32 computed[501]; float32 h1a[21][21], k1a[21][21], l1a[21][21]; int32 ic1a[21][21]; float32 computeda[21][21]; clock_t endTick; int time_test=0; #ifdef __MWERKS__ argc = ccommand(&argv); SIOUXSettings.autocloseonquit = FALSE; SIOUXSettings.asktosaveonclose = TRUE; SIOUXSettings.columns = 80; SIOUXSettings.rows = 50; #endif /* * if (argc<2) { printf("must use 'new' or 'old' in command line\r"); exit(1);} * printf("argv[0] = '%s'",argv[0]); * for (i=1;i1) { if (strcmp(argv[1],"time")==0) time_test = 1; printf(" argv[0] = '%s'\r",argv[1]); } printf("argc = %d, time_test = %d\r",argc,time_test); /* Open output file and output global attributes */ printf("opening file\r"); startTick = clock(); NXopen (file_name, NXACC_CREATE, &file_id); NXputStringAttr(file_id,"user_name",user_name); NXputStringAttr(file_id,"location",LOCATION); NXputStringAttr(file_id,"program_name",PROG_NAM); NXputStringAttr(file_id,"user_mail",user_mail); NXputStringAttr(file_id,"user_email",user_email); NXputStringAttr(file_id,"user_phone",user_phone); NXputStringAttr(file_id,"user_fax",user_fax); /* entry1, The maximally minimal entry. */ printf("\r\rstarting 'entry1'\r"); NXmakegroup (file_id, "Entry1", "NXentry"); NXopengroup (file_id, "Entry1", "NXentry"); NXstring(file_id, "date", "22-feb-1996"); NXstring(file_id, "hour", "23:59:59.00 UT"); NXstring(file_id, "entry_analysis", "NONE"); NXstring(file_id, "entry_intent", "misc"); NXclosegroup (file_id); /* entry2, A simple EXAFS scan with log ratio stored in data file. */ printf("\r\rstarting 'entry2'\r"); for (i=0;i<501;i++) { /* make a dummy scan of 501 points */ mono_energy[i] = 20. + .001 * i; ic1[i] = 200000; ic2[i] = 100000 + 2*i; } dims[0]=501; /* scan of 501 points, rank=1 */ gain1 = gain2 = 1.e8; NXmakegroup (file_id, "Entry2", "NXentry"); NXopengroup (file_id, "Entry2", "NXentry"); NXstring(file_id, "date", "23-feb-1996"); /* data for whole entry */ NXstring(file_id, "hour", "00:10:59.10 -7"); NXstring(file_id, "entry_analysis", "data"); NXstring(file_id, "entry_intent", "NONE"); NXstring(file_id, "title", "Mo K-edge"); NXmakegroup (file_id, "Data1", "NXdata"); NXopengroup (file_id, "Data1", "NXdata"); NXmakedata (file_id, "mono_energy", DFNT_FLOAT32, 1, dims); NXopendata (file_id, "mono_energy"); NXputdata (file_id, mono_energy); NXputStringAttr(file_id,"units","keV"); NXputattr (file_id, "axis", &one, 1, DFNT_INT32); NXmakedata (file_id, "ic1", DFNT_INT32, 1, dims); NXopendata (file_id, "ic1"); NXputdata (file_id, ic1); NXputStringAttr(file_id,"units","photons"); NXputattr (file_id, "gain", &gain1, 1, DFNT_FLOAT32); NXputattr (file_id, "I_monitor", &one, 1, DFNT_INT32); NXmakedata (file_id, "ic2", DFNT_INT32, 1, dims); NXopendata (file_id, "ic2"); NXputdata (file_id, ic2); NXputStringAttr(file_id,"units","photons"); NXputattr (file_id, "gain", &gain2, 1, DFNT_FLOAT32); NXputattr (file_id, "signal", &two, 1, DFNT_INT32); NXputattr (file_id, "primary", &two, 1, DFNT_INT32); for (i=0;i