Loadwave: p in column detection
Hi,
I need to load text files with this format:
899,999 eV 1,382E+01 3,123E+00 352 A 206 A 171 A
999,999 eV 1,457E+01 2,976E+00 388 A 221 A 184 A
1,10 keV 1,528E+01 2,844E+00 424 A 235 A 197 A
1,20 keV 1,596E+01 2,727E+00 460 A 249 A 210 A
The delimiter is blank, and it turns out that at some point blanks appear at the beginning of the line. I don't control the format of this file, as it is provided by another software.
To download the file, I have used the following code to get text columns:
loadwave /A /K=2 /V={" ","",0,0} /J /L={0,0,0,0,0} path
It provides good results until the lines with blanks at the beginning are loaded: then Nan values are put in the first column (see attached screen copy).
Is there a way to fix that? I guess Igor interprets the first blank as a skipper to the next column. But how to prevent it to do that?
Thanks in advance.
Hi,
One option is to load the whole file as text string and then trimstring() to remove the outside whitespaces and then parse the resulting string into the various waves.
Andy
July 7, 2021 at 10:18 am - Permalink
Your text file may be in the fixed field format. In that format each column is a fixed number of characters. You need to use LoadWave with the /F flag if that is the case.
/F={numColumns, defaultFieldWidth, flags }
Indicates that the file uses the fixed field file format. Most FORTRAN programs generate files in this format.
July 7, 2021 at 10:26 am - Permalink
In reply to Hi, One option is to load… by hegedus
Thanks. In fact I did not find a way to load the file as a single column.
July 7, 2021 at 10:32 am - Permalink
The unit change mid column from eV to keV is also not nice. I think hegedus's suggestion may be the best option, but I would probably load the file as one big singe-column text wave and then use SScanF on each line to extract the numerical values and units
July 7, 2021 at 10:35 am - Permalink
Could you suggest me a command line to load file as a single-column text wave?
July 7, 2021 at 10:43 am - Permalink
OK I got it, using /L
Thanks for your help.
July 7, 2021 at 10:48 am - Permalink
If you post the file or a representative section of it, I may be able to recommend how to handle it.
July 8, 2021 at 02:34 pm - Permalink
Hi hrodstein,
Here is the file. I have fixed the issue with the following code, but it might be improved.
Thanks for your help.
Erik
string element, name
variable i, N, v1,v2,v3,v4, v5,v6
string str, s1, s2, s3, s4, nom_e, nom_n, pr,lon_strag, lat_strag, unit_s, unit_lat_strag, unit_lon_strag, energy, unit_energy, unit_pr
string path, nom_fic_loaded
path=" DD:Users:quiricoe:DOSSIERS-ERIC:RECHERCHE:PROJETS_EN_COURS:TNOs:NEWHORIZONS:ARROKOTH:TNOs_SURFACE_IRRADIATION:SRIM_Files:Se_Sn_CH3OH_300eV_30_MeV_MeV_per_mm_d0.8:"+name
print path
loadwave /N=filetodealwith /K=2 /V={"","",0,0} /J /L={0,25,131,0,1} path
nom_fic_loaded="filetodealwith0"
wave /T wave20=$nom_fic_loaded
N=numpnts(wave20)
print N
nom_n="Sn_"+element+"_SW"
nom_e="Se_"+element+"_SW"
pr="SW_"+element+"_PR"
lon_strag="SW_"+element+"_long_strag"
lat_strag="SW_"+element+"_lat_strag"
unit_s="SW_"+element+"_unit_S"
unit_lat_strag="SW_"+element+"_unit_lat_strag"
unit_lon_strag="SW_"+element+"_unit_long_strag"
energy="SW_"+element+"_energy"
unit_energy="SW_"+element+"_unit_energy"
unit_pr="SW_"+element+"_unit_pr"
Make /T /O /N=(N) wave21
wave21=wave20
Make /O /N=(N) $energy, $nom_e, $nom_n, $pr, $lon_strag, $lat_strag
Make /O /T /N=(N) $unit_lat_strag, $unit_lon_strag, $unit_energy, $unit_pr
wave wr0=$energy
wave wr1=$nom_e
wave wr2=$nom_n
wave wr3=$pr
wave wr4=$lon_strag
wave wr5=$lat_strag
wave /T wr6=$unit_lat_strag
wave/T wr7=$unit_lon_strag
wave /T wr8=$unit_energy
wave /T wr9=$unit_pr
i=0
do
str=replacestring(",", wave20[i], ".")
wave21[i]=str
sscanf str, "%e%s%e%e%e%s%e%s%e%s", v1,s1, v2, v3, v4, s2, v5,s3, v6, s4
wr0[i]=v1
wr1[i]=v2
wr2[i]=v3
wr3[i]=v4
wr4[i]=v5
wr5[i]=v6
wr6[i]=s4
wr7[i]=s3
wr8[i]=s1
wr9[i]=s2
if (cmpstr(wr8[i],"eV")==0)
wr0[i]=wr0[i]/1E6
endif
if (cmpstr(wr8[i],"keV")==0)
wr0[i]=wr0[i]/1E3
endif
if (cmpstr(wr9[i],"A")==0)
wr3[i]=wr3[i]/1E4
endif
if (cmpstr(wr9[i],"mm")==0)
wr3[i]=wr3[i]*1E3
endif
if (cmpstr(wr6[i],"A")==0)
wr5[i]=wr5[i]/1E4
endif
if (cmpstr(wr7[i],"A")==0)
wr4[i]=wr4[i]/1E4
endif
//Killwaves wr8, wr9, wr6, wr7
i=i+1
while( i<N)
end
July 8, 2021 at 09:23 pm - Permalink
I am attaching a zip file containing the data file that Erik provided and an Igor experiment containing procedures that load the file. It also contains a notebook explaining the procedures.
In brief, I used "Load Fixed Field Text" (LoadWave/F) to treat the file as fixed field. I treated the units as separate columns. I loaded the numeric and units columns, and then scaled the numeric waves by the units to produce waves in keV and um units.
The procedure require Igor Pro 7 at least because I used ints.
July 9, 2021 at 09:17 am - Permalink
A BIG thank you! It works very well.
Erik
July 9, 2021 at 11:02 am - Permalink