Create time table
I'm want to create a time table which interpolation in IGOR
I've try to calculate the seconds passed since 1904/01/01 00:00 by following code
But still won't work, I can't figure out what's going on
I new a table which show as
YEAR MONTH DAY HOUR MINUTE
2017 2 1 0 0
2017 2 1 1 0
2017 2 1 2 0
#pragma rtGlobals=1 // Use modern global access method.
Macro test()
Variable/G t1,t2,dt
String sdate="20170201_0000" // Start Time: YYYYMMDD_HHMM
String edate="20170201_0200" // End Time: YYYYMMDD_HHMM
Variable inter_min=60 // Interpolation with N minute
Variable inter_sec
String ssy=sdate[0,3] , eey=edate[0,3]
String ssm=sdate[4,5] , eem=edate[4,5]
String ssd=sdate[6,7] , eed=edate[6,7]
String ssh=sdate[9,10] , eeh=edate[9,10]
String ssn=sdate[11,12] , een=edate[11,12]
Variable sy=str2num(ssy) , ey=str2num(eey)
Variable sm=str2num(ssm) , em=str2num(eem)
Variable sd=str2num(ssd) , ed=str2num(eed)
Variable sh=str2num(ssh) , eh=str2num(eeh)
Variable sn=str2num(ssn) , en=str2num(een)
en=en+inter_min
If (inter_min==60)
inter_sec=3600
Endif
t1=date2secs(sy,sm,sd)+sh*60*60+sn*60+0 //calculate start time seconds
t2=date2secs(ey,em,ed)+eh*60*60+en*60+0 //calculate end time seconds
dt=abs(t2-t1)/inter_sec // total row
Make/D/N=(dt) secs,year,month,day,hour,minute
Edit secs,year,month,day,hour,minute
SetScale x,t1,t2,"dat",secs
secs=x
Variable num
Variable allnum=dt
Variable year_sec, month
Variable totaldays,temp, temp_year, temp_month, temp_days, temp_hour, temp_min
Do
temp=(secs[num]/31557600)
temp_year=round(temp+1904)
year[num]=temp_year
temp=date2secs(temp_year,01,01)+00*60*60+00*60+0
temp=ceil((secs[num]-temp)/86400)+1
print temp
If(year_temp==2012 || year_temp==2016)
totaldays=366
If((temp>=1) && (temp<=31))
temp_month=1
temp_days=temp
Endif
if((temp>31) && (temp<=60))
temp_month=2
temp_days=temp-31
endif
if((temp>60) && (temp<=91))
temp_month=3
temp_days=temp-31-29
endif
Endif
If((year_temp!=2012) || (year_temp!=2016))
totaldays=365
If((temp>=1) && (temp<=31))
temp_month=1
temp_days=temp
endif
if((temp>31) && (temp<=59))
temp_month=2
temp_days=temp-31
endif
if((temp>59) && (temp<=91))
temp_month=3
temp_days=temp-31-28
Endif
Endif
month[num]=temp_month
day[num]=temp_days
temp=date2secs(temp_year,temp_month,temp_days)+00*60*60+00*60+0
temp=(secs[num]-temp)/3600
temp_hour=floor(temp)
hour[num]=temp_hour
num+=1
While(num<=dt)
Endmacro
"Won't work" is not a good description. Does it not compile? Is the result wrong? ...?
Maybe you want to have a look at
That should do some of the work. Hours, minutes and seconds on top are easy.
Consider to use functions rather than macros.
HJ
PS: Timestamps in waves require double precision waves
April 25, 2017 at 07:36 am - Permalink