@@ -1036,7 +1036,7 @@ class DLL_EXPORT HDF5_IO
10361036 // -----------------------------------------------------------------------------
10371037 // load spectra volume as float (T_real) but scan_info as double (T_real2)
10381038 template <typename T_real, typename T_real2>
1039- bool load_spectra_vol_polar_energy_scan (std::string path, std::string filename, size_t detector_num, data_struct::Spectra_Volume<T_real>* spec_vol, data_struct::Scan_Info<T_real2> &scan_info, bool logerr = true )
1039+ bool load_spectra_vol_polar_energy_scan (std::string path, std::string filename, size_t detector_num, data_struct::Spectra_Volume<T_real>* spec_vol, data_struct::Scan_Info<T_real2> &scan_info, data_struct::Params_Override<T_real>* params_override, bool logerr = true )
10401040 {
10411041 std::stack<std::pair<hid_t , H5_OBJECTS> > close_map;
10421042 hid_t file_id, dset_id, space_id;
@@ -1247,9 +1247,10 @@ class DLL_EXPORT HDF5_IO
12471247 scan_info.meta_info .scan_type = STR_SCAN_TYPE_POLAR_XANES;
12481248 // Take 1 spectra per magnetic polarization, divide them by 2 and store in each row
12491249 scan_info.meta_info .requested_cols = dims3[0 ] / 2 ;
1250- scan_info.meta_info .requested_rows = 2 ;
1250+ scan_info.meta_info .requested_rows = 2 ; // two polarities
12511251 scan_info.meta_info .x_axis .resize (scan_info.meta_info .requested_cols );
12521252 scan_info.meta_info .y_axis .resize (scan_info.meta_info .requested_rows );
1253+ scan_info.meta_info .polarity_pattern = params_override->polarity_pattern ;
12531254 spec_vol->resize_and_zero (scan_info.meta_info .requested_rows , scan_info.meta_info .requested_cols , dims3[2 ]);
12541255
12551256 struct data_struct ::Scaler_Map<T_real2> energy_map;
@@ -1314,58 +1315,90 @@ class DLL_EXPORT HDF5_IO
13141315 int polarity = 0 ;
13151316 int idx = 0 ;
13161317
1317- if (use_pr1 && (pr1_array .size () != dims3[ 0 ]) )
1318+ if (params_override != nullptr && params_override-> polarity_pattern .size () == 0 )
13181319 {
1319- logE<<str_pr1_path<<" is not the same size as spectra data. Can not load properly.\n " ;
1320- _close_h5_objects (close_map);
1321- return false ;
1322- }
1323- else if (use_pr1 == false && (pr2_array.size () != dims3[0 ]))
1324- {
1325- logE<<str_pr2_path<<" is not the same size as spectra data. Can not load properly.\n " ;
1326- _close_h5_objects (close_map);
1327- return false ;
1320+ if (use_pr1 && (pr1_array.size () != dims3[0 ]))
1321+ {
1322+ logE << str_pr1_path << " is not the same size as spectra data. Can not load properly.\n " ;
1323+ _close_h5_objects (close_map);
1324+ return false ;
1325+ }
1326+ else if (use_pr1 == false && (pr2_array.size () != dims3[0 ]))
1327+ {
1328+ logE << str_pr2_path << " is not the same size as spectra data. Can not load properly.\n " ;
1329+ _close_h5_objects (close_map);
1330+ return false ;
1331+ }
13281332 }
1333+ int polarity_str_idx = 0 ;
1334+ int left_pol_idx = 0 ;
1335+ int right_pol_idx = 0 ;
13291336
13301337 for (size_t i = 0 ; i < dims3[0 ]; i++)
13311338 {
13321339 offset3[0 ] = i;
13331340 H5Sselect_hyperslab (space_id, H5S_SELECT_SET, offset3, nullptr , count3, nullptr );
13341341
1335- if (i > 0 )
1342+ if (params_override != nullptr && params_override->polarity_pattern .size () > 0 )
1343+ {
1344+ if (polarity_str_idx >= params_override->polarity_pattern .size ())
1345+ {
1346+ polarity_str_idx = 0 ;
1347+ }
1348+ if (params_override->polarity_pattern .at (polarity_str_idx) == ' L' )
1349+ {
1350+ polarity = 0 ;
1351+ idx = left_pol_idx;
1352+ left_pol_idx++;
1353+ }
1354+ else if (params_override->polarity_pattern .at (polarity_str_idx) == ' R' )
1355+ {
1356+ polarity = 1 ;
1357+ idx = right_pol_idx;
1358+ right_pol_idx++;
1359+ }
1360+ else
1361+ {
1362+ logW << " Unknown polarity override " << params_override->polarity_pattern [polarity_str_idx] << " in override string : " << params_override->polarity_pattern << " \n " ;
1363+ }
1364+ }
1365+ else
13361366 {
1337- if (use_pr1 )
1367+ if (i > 0 )
13381368 {
1339- if (pr1_array[i] != pr1_array[i- 1 ] )
1369+ if (use_pr1 )
13401370 {
1341- if (polarity == 1 )
1342- {
1343- polarity = 0 ;
1344- idx++;
1345- }
1346- else
1371+ if (pr1_array[i] != pr1_array[i - 1 ])
13471372 {
1348- polarity = 1 ;
1373+ if (polarity == 1 )
1374+ {
1375+ polarity = 0 ;
1376+ idx++;
1377+ }
1378+ else
1379+ {
1380+ polarity = 1 ;
1381+ }
13491382 }
13501383 }
1351- }
1352- else
1353- {
1354- if (pr2_array[i] != pr2_array[i-1 ])
1384+ else
13551385 {
1356- if (polarity == 1 )
1386+ if (pr2_array[i] != pr2_array[i - 1 ] )
13571387 {
1358- polarity = 0 ;
1388+ if (polarity == 1 )
1389+ {
1390+ polarity = 0 ;
1391+ }
1392+ else
1393+ {
1394+ polarity = 1 ;
1395+ }
13591396 }
13601397 else
13611398 {
1362- polarity = 1 ;
1399+ idx++ ;
13631400 }
13641401 }
1365- else
1366- {
1367- idx++;
1368- }
13691402 }
13701403 }
13711404
@@ -8468,6 +8501,18 @@ class DLL_EXPORT HDF5_IO
84688501 }
84698502 }
84708503
8504+ // Save polarity pattern
8505+ if (_open_h5_dataset (STR_POLARITY_PATTERN, filetype, scan_grp_id, 1 , count, count, dset_id, dataspace_id))
8506+ {
8507+ char tmp_char[255 ] = { 0 };
8508+ meta_info->polarity_pattern .copy (tmp_char, 254 );
8509+ status = H5Dwrite (dset_id, memtype, memoryspace_id, dataspace_id, H5P_DEFAULT, (void *)tmp_char);
8510+ if (status < 0 )
8511+ {
8512+ logE << " failed to write " << STR_POLARITY_PATTERN << " \n " ;
8513+ }
8514+ }
8515+
84718516 if (_open_h5_dataset (STR_SCAN_TIME_STAMP, filetype, scan_grp_id, 1 , count, count, dset_id, dataspace_id))
84728517 {
84738518 char tmp_char[255 ] = { 0 };
0 commit comments