How can I convert these VB calculations to Objective-c? - objective-c

I have an older program that I wrote some time ago in VB then late updated for VB.Net. The program calculates the ephemerides of comets based on orbital elements downloaded from the Minor Planet Center website. I am now trying to make an iPhone/iPad application using the same idea and the same calculations. Unfortunately I am too new at objective-c that trying to convert the extensive calculations is proving quite difficult for me. I am hoping that someone can help me out and at least give me some pointers.
In particular, I have no idea how to accomplish this in objective-c:
Dim d1 As Date = DateSerial(yr_peri%, mo_peri%, dy_peri%)
dateser# = d1.ToOADate()
dateser# = dateser# + frac_day_peri#
jdperi# = 2415018.5 + dateser#
and this:
' Find Julian Day Number of start date & time
Dim d2 As Date = DateSerial(yr%, mo%, dd%)
Dim inputdate# = d2.ToOADate()
jdp# = inputdate + 2415018.5 ' use this day for phenom (rise/set) calcs
jd# = jdp# + fd# ' add fractional days
Here is the full VB version of the calculations in case it helps to understand the context:
Public Sub calc(ByVal cname$, ByVal qq#, ByVal e#, ByVal w#, ByVal om#, ByVal I#, ByVal yr_peri%, ByVal mo_peri%, ByVal day_peri#, ByVal abs_mag#, ByVal mag_n#)
Dim ep#
Dim dy_peri%, frac_day_peri#, dateser#, jdperi#
Dim yr%, mo%, dd%, fd#
Dim jdp#, jd#, interval#
Dim twi%, p_date#, ut#, er%
Dim t#, tt#, f#, p#, g#, q#, h#, r#
Dim a1#, a2#, b1#, b2#, c1#, c2#
Dim sdt#, a#, n#, period#, m#, e0#
Dim mrs#, frs%, ers0#, drs#, jrs%, mrs1#, e2#
Dim tv#, v#, r1#, r2#, w0#, s#, s0#
Dim x#, y#, z#, ls#, ms#, es#, th#, vs#, c#, th2000#
Dim rs#, xs#, ys#, zs#, xx#, yy#, radeg#, rad#, ra#, ras$
Dim dl#, dlm#, sd#, dec#, ds$
Dim cospsi#, psi#, elong#, cosbeta#, beta#, phase#
Dim ha#, ang#, az#, sinalt#, alt#, m1#, vl#
Dim Lati$, Longi$
Dim outpt$
'----------------------------------------------
'** AA=ASTRONOMICAL ALGORITHMS BY JEAN MEEUS **
'----------------------------------------------
counter% = 0
ep# = 23.439291 ' year 2000, AA page 214
cname$ = Trim(cname$)
'Get orbital elements
MainForm.grpEphemerides.Text = "Comet: " & cname$ & " - " + when$ ' Name
'qq# = Val(comet$(ind%, 1)) ' perihelion dist
'e# = Val(comet$(ind%, 2)) ' eccentricity (1=parabola)
'w# = Val(comet$(ind%, 3)) ' arg of perihelion - little omega
'om# = Val(comet$(ind%, 4)) ' long of ascending node - big omega
'I# = Val(comet$(ind%, 5)) ' inclination
'yr_peri% = Val(comet$(ind%, 6)) ' year
'mo_peri% = Val(comet$(ind%, 7)) ' month
'day_peri# = Val(comet$(ind%, 8)) ' day
'abs_mag# = Val(comet$(ind%, 9)) ' magnitude coef #1
'mag_n# = Val(comet$(ind%, 10)) ' magnitude coef #2
' Find JD of perihelion
dy_peri% = Int(day_peri#) ' day
frac_day_peri# = day_peri# - dy_peri% ' fractional day
Dim d1 As Date = DateSerial(yr_peri%, mo_peri%, dy_peri%)
dateser# = d1.ToOADate()
dateser# = dateser# + frac_day_peri#
jdperi# = 2415018.5 + dateser#
' Start date/time
yr% = Val(MainForm.txtYear.Text)
mo% = Val(MainForm.txtMonth.Text)
dd% = Val(MainForm.txtDay.Text)
fd# = Val(MainForm.txtHour.Text) / 24 + Val(MainForm.txtMin.Text) / 1440 + Val(MainForm.txtSec.Text) / 86400
lat# = Val(MainForm.txtLat.Text)
lon# = Val(MainForm.txtLon.Text)
' Find Julian Day Number of start date & time
Dim d2 As Date = DateSerial(yr%, mo%, dd%)
Dim inputdate# = d2.ToOADate()
jdp# = inputdate + 2415018.5 ' use this day for phenom (rise/set) calcs
jd# = jdp# + fd# ' add fractional days
interval# = Val(MainForm.txtInterval.Text)
' Determine if fixed times or rise/set phenomena
If MainForm.rdbFixedTimes.Checked = True Then
twi% = 0 ' use fixed times
Else
twi% = 1 ' use twilight times
interval# = Int(interval#) ' Set integer days (fraction doesn't make sense)
If interval# < 1 Then interval# = 1 ' make sure interval is at least one day
End If
'-----------
' Loop here
'-----------
While counter% <= Val(MainForm.txtNumSteps.Text)
If twi% = 1 Then
'Serial date of this calculation
p_date# = jdp# - 2415018.5
Call phenom(p_date#, ut#, er%) ' calcs for rise/set, returns er% (among other stuff)
jd# = Int(p_date#) + 2415018.5 + ut# / 24 + 1 / 2880
If er% = 1 Then ' er%=1 means no phenom (ex: sunrise) that day
ser_date# = jd# - 2415018.5
outpt$ = Format$(ser_date#, "mm/dd/yy") + " " + "No Rise/Set Phenomena on this Date"
GoTo No_phenom
End If
End If
' Days from perihelion of comet
t# = jd# - jdperi#
' Time (in Julian Centuries (36525 days)) since 1900 Jan 0.5 ET
' AA page 151
tt# = (jd# - 2451545.0#) / 36525.0!
'-------------- CALC F,G,H,P,Q,R (PP214 IN AA) ---------------
f# = Cos(dr# * om#)
p# = -Sin(dr# * om#) * Cos(dr# * I#)
g# = Sin(dr# * om#) * Cos(dr# * ep#)
q# = Cos(dr# * om#) * Cos(dr# * I#) * Cos(dr# * ep#) - Sin(dr# * I#) * Sin(dr# * ep#)
h# = Sin(dr# * om#) * Sin(dr# * ep#)
r# = Cos(dr# * om#) * Cos(dr# * I#) * Sin(dr# * ep#) + Sin(dr# * I#) * Cos(dr# * ep#)
'---------------- CALC A1,A2,B1,B2,C1,C2 (PP214 AA) -----------------
Call rec2pol(p#, f#, a1#, a2#)
Call rec2pol(q#, g#, b1#, b2#)
Call rec2pol(r#, h#, c1#, c2#)
'--------------- SIDEREAL TIME AT GREENWICH (PP84 AA) ----------------
' In degrees
sdt# = 280.46061837 + 360.98564736629 * (jd# - 2451545) + 0.000387933 * tt# * tt# - tt# * tt# * tt# / 38710000
sdt# = sdt# - 360 * Int(sdt# / 360)
'------------------- CALC ECCENTRIC & TRUE ANOMALY --------------------
If e# < 1 Then ' elliptical motion (pp214 AA)
a# = qq# / (1 - e#) ' semi major axis (AU)
n# = 0.9856076686 / a# / Sqrt(a#) ' mean motion (deg/day)
period# = 360 / n# / 365.25
MainForm.lblOrbitInf.Text = "Semimajor axis: " + Format$(a#, "#.000") + " AU Period: " + Format$(period#, "#.00") + " Years"
m# = n# * t# ' mean anomaly
e0# = rd# * e# ' "modified" eccentricity, page 187)
'ecc anomaly (page 195)
mrs# = m# * dr#
frs% = Sign(mrs#)
mrs# = Abs(mrs#) / (2 * pi#)
mrs# = (mrs# - Int(mrs#)) * 2 * pi# * frs%
If mrs# < 0 Then mrs# = mrs# + 2 * pi#
frs% = 1
If mrs# > pi# Then frs% = -1
If mrs# > pi# Then mrs# = 2 * pi# - mrs#
ers0# = pi# / 2
drs# = pi# / 4
For jrs% = 1 To 53
mrs1# = ers0# - e# * Sin(ers0#)
ers0# = ers0# + drs# * Sign(mrs# - mrs1#)
drs# = drs# / 2
Next jrs%
ers0# = ers0# * frs%
e2# = ers0# * rd#
'alpha# = (1 - e#) / (4 * e# + .5)
'beta# = m# / (8 * e# + 1)
'signbeta% = Sgn(beta#)
'cube# = beta# + signbeta% * Sqr(beta# ^ 2 + alpha# ^ 3)
'signz% = Sgn(cube#)
'zz# = signz% * (Abs(cube#)) ^ (1 / 3)
'ss0# = zz# - alpha# / 2
'ss# = ss0# - .078 * ss0# ^ 5 / (1 + e#)
'e1# = m# + e# * (3 * ss# - 4 * ss# ^ 3)
'loop1% = 0 ' counter
1040:
'e2# = e1# + (m# + e0# * Sin(dr# * e1#) - e1#) / (1 - e# * Cos(dr# * e1#))
'If Abs(e2# - e1#) < .0000000001 Or loop1% > 1000 Then ' e2#:ecc anom found
tv# = Sqrt((1 + e#) / (1 - e#)) * Tan(dr# * e2# / 2)
v# = 2 * rd# * Atan(tv#) ' true anomaly
r1# = a# * (1 - e# * Cos(dr# * e2#)) ' dist from sun AU
GoTo 2120
'Else
' e1# = e2# ' new ecc anomaly
' loop1% = loop1% + 1
' GoTo 1040
'End If
Else ' parabolic motion (pp225 AA)
MainForm.lblOrbitInf.Text = "This comet has a parabolic orbit-semimajor axis and period not determined"
w0# = 0.0364911624 * t# / qq# / Sqrt(qq#)
s# = 0
2110:
s0# = (2 * s# * s# * s# + w0#) / 3 / (s# * s# + 1)
If Abs(s# - s0#) > 0.0000000001 Then
s# = s0#
GoTo 2110
End If
s# = s0#
v# = 2 * rd# * Atan(s#) ' true anomaly
r1# = qq# * (1 + s# * s#) ' distance from sun (AU)
End If
2120:
v# = v# - 360 * Int(v# / 360) ' true anomaly
'r1#= dist from sun in au (above)
r2# = r1# * 92955807.0# ' Dist from sun (miles)
'-------- CALC HELIOCENTRIC RECT COORD OF COMET (PP215 AA) ----------
x# = r1# * a2# * Sin(dr# * (a1# + w# + v#))
y# = r1# * b2# * Sin(dr# * (b1# + w# + v#))
z# = r1# * c2# * Sin(dr# * (c1# + w# + v#))
'-------- CALC GEOCENTRIC RECT COORD OF SUN (PP151,152 AA) ---------
ls# = 280.46645 + 36000.76983 * tt# + 0.0003032 * tt# * tt#
ls# = ls# - 360 * Int(ls# / 360)
ms# = 357.5291 + 35999.0503 * tt# - 0.0001559 * tt# * tt# - 0.00000048 * tt# * tt# * tt#
ms# = ms# - 360 * Int(ms# / 360)
es# = 0.016708617 - 0.000042037 * tt# - 0.0000001236 * tt# * tt#
c# = (1.9146 - 0.004817 * tt# - 0.000014 * tt# * tt#) * Sin(dr# * ms#) + (0.019993 - 0.000101 * tt#) * Sin(2 * dr# * ms#) + 0.00029 * Sin(3 * dr# * ms#)
th# = ls# + c# ' TH is Sun's true longitude
vs# = ms# + c# ' VS is Sun's true anomaly
' pp152 AA
th2000# = th# - 0.01397 * (yr% + mo% / 12 + dd% / 365 - 2000) ' Sun true long referred to 2000
' sun's radius vector
rs# = (1.000001018 * (1 - es# * es#)) / (1 + es# * Cos(dr# * vs#))
' rectangular coord of sun (pp159 AA)
xs# = rs# * Cos(dr# * th2000#) ' Xsun
ys# = rs# * Sin(dr# * th2000#) * Cos(dr# * ep#) ' Ysun
zs# = rs# * Sin(dr# * th2000#) * Sin(dr# * ep#) ' Zsun
'------------- CALC GEOCENTRIC RA & DEC (PP 119 IN AFFC) --------------
xx# = xs# + x#
yy# = ys# + y#
Call rec2pol(xx#, yy#, radeg#, rad#)
ra# = radeg# / 15 ' RA of comet (2000) in hours
' 0 means time
ras$ = dec2ddmm(ra#, 0) ' ra in string form
'dist from comet to earth (au)
dl# = Sqrt((xs# + x#) ^ 2 + (ys# + y#) ^ 2 + (zs# + z#) ^ 2)
dlm# = dl# * 92955807.0# ' distance from earth in miles
sd# = (zs# + z#) / dl#
'DEC of comet (2000)
dec# = rd# * Atan(sd# / Sqrt(-sd# * sd# + 1))
' 1 means angle
ds$ = dec2ddmm(dec#, 1) ' dec in string form
' Calc elongation
cospsi# = (rs# * rs# + dl# * dl# - r1# * r1#) / (2 * rs# * dl#)
psi# = -Atan(cospsi# / Sqrt(-cospsi# * cospsi# + 1)) + pi# / 2
elong# = psi# * rd#
elong# = elong# - 360 * Int(elong# / 360)
' Calc phase
cosbeta# = (r1# * r1# + dl# * dl# - rs# * rs#) / (2 * r1# * dl#)
beta# = -Atan(cosbeta# / Sqrt(-cosbeta# * cosbeta# + 1)) + pi# / 2
phase# = beta# * rd#
phase# = phase# - 360 * Int(phase# / 360)
'------------ CALCULATE ALTITUDE & AZIMUTH (AA PP89) --------------
ha# = sdt# - lon# - radeg#
yy# = Sin(dr# * ha#)
xx# = (Cos(dr# * ha#) * Sin(dr# * lat#) - Tan(dr# * dec#) * Cos(dr# * lat#))
' rectangular to polar
Call rec2pol(xx#, yy#, ang#, rad#)
az# = ang# + 180
az# = az# - 360 * Int(az# / 360)
sinalt# = Sin(dr# * lat#) * Sin(dr# * dec#) + Cos(dr# * lat#) * Cos(dr# * dec#) * Cos(dr# * ha#)
alt# = rd# * Atan(sinalt# / Sqrt(1 - sinalt# * sinalt#))
'-------------- CALC EST MAGNITUDES & ORBITAL VELOCITY (AA PP 216) ---------------
m1# = abs_mag# + 5 * Log(dl#) / Log(10) + 2.5 * mag_n# * Log(r1#) / Log(10)
If e# < 1 Then
vl# = 42.1219 * Sqrt((1 / r1#) - (1 / (2 * a#))) ' elliptical orbital velocity, page 223
Else
vl# = 42.1219 * Sqrt(1 / r1#) ' parabolic orital velocity (my approximation)
End If
'------------- Stuff for output form -------------
Dim dt As DateTime = DateTime.FromOADate(dateser#)
MainForm.lblJDperi.Text = "Date of perihelion: " + dt.ToString("dd MMM yyyy hh:mm:ss") + " UTC JD: " + Format$(jdperi#, "#.00000")
Lati$ = " "
Longi$ = " "
If lat# > 0 Then Lati$ = "N " Else Lati$ = "S "
If lon# > 0 Then Longi$ = "W" Else Longi$ = "E"
MainForm.lblLoc.Text = "Observing Location: " + Format$(lat#, "+00.0000;-00.0000") + Chr(176) + Lati$ + Format$(lon#, "+000.0000;-000.0000") + Chr(176) + Longi$
'Serial date of this calculation
ser_date# = jd# - 2415018.5
' put the main info into a string
dt = DateTime.FromOADate(ser_date#)
outpt = dt.ToString("MM/dd/yy HH:mm:ss") & " " & ras$ & " " & ds$ & " " & Format$(alt#, "+00.0;-00.0") & Chr(176) & " " & Format$(az#, "000.0") & Chr(176)
outpt = outpt & " " & Format$(r1#, "00.0000") & " " & Format$(dl#, "00.0000") & " " & Format$(m1#, "+00.0;-00.0") + " " & Format$(elong#, "000.0") & Chr(176)
No_phenom:
' put the string into the list box
MainForm.lstPosition.Items.Add(outpt)
' put the "extra" data into the array
extra#(counter%, 0) = t# ' time to perih
extra#(counter%, 1) = vl# ' speed
extra#(counter%, 2) = phase# ' phase
extra#(counter%, 3) = v# ' true anomaly
' Increment counter
counter% = counter% + 1
' New JD
jd# = jd# + interval#
jdp# = jdp# + interval#
End While ' do again until done
End Sub
I appreciate any help or direction anyone can give on converting this function to objective-c.
Regards,
Keith

When working with dates in Objective-C you will often need to work with more than 1 class unlike other languages such as C#, Java and VB.NET. For creating a date from a string or getting a string from a date you will want to use the NSDateFormatter. Now when attempting to modify or create a date with "components" (year,month,day etc.) you will want to use NSDateComponents along with the correct NSCalendar. The component solution looks like it will assist you with the DateSerial part. The line jdp# = inputdate + 2415018.5 should be convertible (if it is seconds) to
jdp = [NSDate dateWithTimeInterval:2415018.5 sinceDate:inputdate];

Related

Adding Hours to Date based on Working shift duration

I am creating a software which would find out the production complete date based on start date.
This will be working like it would find out the total hours required to complete the production and then add it to start date.
Now I want to add hours based on how the Production shift is working. These checkboxes tell that weather the shift is working or not. If checkbox is checked it means shift is working, otherwise not.
Based on shift working, it would add the hours to date, For example
Based on Calculation the time required is 900 hrs, now if Monday and Tuesday only one shift is working then while calculating end date it would consider only 12 hours from this 900 hrs for Monday and Tuesday.
Screenshot of WinForm
production24 = ((rpm * 24 * 60) / (pick * 39.37)) * (eff / 100)
production12 = ((rpm * addvalue * 60) / (pick * 39.37)) * (eff / 100)
production1 = ((rpm * 1 * 60) / (pick * 39.37)) * (eff / 100)
production24 = Math.Round(production24, 2, MidpointRounding.AwayFromZero)
production12 = Math.Round(production12, 2, MidpointRounding.AwayFromZero)
production1 = Math.Round(production1, 2, MidpointRounding.AwayFromZero)
pro_24.Text = Convert.ToString(production24)
Pro_12.Text = Convert.ToString(production12)
Pro_1.Text = Convert.ToString(production1)
If fl <> 0 And production1 <> 0 Then
timereqinhr = fl / production1
Else
timereqinhr = 0
End If
getdate = DatePicker.Value + Time_Picker.Value.TimeOfDay
falldate = getdate.AddHours(timereqinhr + offshift)
fallingtime.Text = falldate.ToString("dd/MM/yyyy | hh:mm tt")
Label9.Text = "Time required for " + fabric_Length.Text + " Meters"
Dim productiontime, productionhr, productionmin As String
productiontime = Math.Floor(timereqinhr / 24)
productionhr = Math.Floor(((timereqinhr / 24) - productiontime) * 24)
productionmin = Math.Floor(((((timereqinhr / 24) - productiontime) * 24) * 60) - (productionhr * 60))
Label8.Text = (productiontime + " Days, " + productionhr + " Hours " + productionmin + " Min ")

For Statement in assigning random values to integers in VBA

NN1 = Int((500 - 100 + 1) * Rnd + 100)
NN2 = Int((500 - 100 + 1) * Rnd + 100)
NN3 = Int((500 - 100 + 1) * Rnd + 100)
NN4 = Int((500 - 100 + 1) * Rnd + 100)
I assume that we can reduce this into
For i = 1 to 4
"NN" & i = Int((500 - 100 + 1) * Rnd + 100)
Next i
However, I am getting a compilation error. How do I rectify this?
Dim NN() As Integer
For i = 1 To 4
NN(i) = Int((500 - 100 + 1) * Rnd + 100)
Next i
I would suggest using an Array instead of multiple Integers

VBA appears to leave a for loop without cause?

I have a for loop (the last loop in the code below) which fills some arrays with values through some computations.
However, for some reason, once i=5 it jumps back up to the top of the loop (the x+h part) without going through the rest of the loop.
While x < xmax
If x + h < xmax Then 'If the step is going to overshoot the desired xmax
x = x + h 'make h adequately smalller
Else
h = xmax - x
x = xmax
End If
'k(Order #, equation #)
For j = 1 To 6 'First to 6th order
'temp=riddersmethodT(temp) 'Calculate temperature of mixture
FT = 0
rho(0) = 0 'Setting FT and rho_av to 0 to be re-calculated
For i = 1 To 7
rho(0) = rho(0) + rho(i) * Y4(i) 'Calculate average density of mixture
FT = FT + Y4(i)
vol_F = vol_F + Y4(i) * MW(i) / rho(i) 'Calculating the total volumetric flowrate (m^3/s)
Next i
rho(0) = rho(0) / FT
For i = 1 To 8 'Calculating all of the k(1) values for eq 1 to 8
k(j, i) = AllODES(x, Y4, i, j, k, h, temp, diameter, vol_F, rho(0))
Next i
Next j
For i = 1 To 8
Y4Old(i) = Y4(i) 'Saving old y4 values to calc delta0
Y4(i) = Y4(i) + h * (k(1, i) * (37 / 378) + k(3, i) * (250 / 621) + k(4, i) * (125 / 594) + k(6, i) * (512 / 1771))
Y5(i) = Y4(i) + h * (k(1, i) * (2825 / 27648) + k(3, i) * (18575 / 48384) + k(4, i) * (13525 / 55296) + k(5, i) * (277 / 14336) + k(6, i) * (0.25))
delta0(i) = error
delta1(i) = Abs(Y5(i) - Y4(i))
delRatio(i) = Abs(delta0(i) / delta1(i)) 'Ratio of errors; careful of getting zeroes!
Next i
I don't understand how this can be possible seeing as i is not being manipulated within that loop. If you have any insight, please let me know!
My guess is that your final loop over i has a divide by zero somewhere. You could handle errors in your loop using something like the following:
Sub yourSub()
For i = 1 To 8
On Error GoTo ErrorHandler:
Y4Old(i) = Y4(i)
'Saving old y4 values to calc delta0
Y4(i) = Y4(i) + h * (k(1, i) * (37 / 378) + k(3, i) * (250 / 621) + k(4, i) * (125 / 594) + k(6, i) * (512 / 1771))
Y5(i) = Y4(i) + h * (k(1, i) * (2825 / 27648) + k(3, i) * (18575 / 48384) + k(4, i) * (13525 / 55296) + k(5, i) * (277 / 14336) + k(6, i) * (0.25))
delta0(i) = error
delta1(i) = Abs(Y5(i) - Y4(i))
delRatio(i) = Abs(delta0(i) / delta1(i)
Next i
Cleanup:
' do cleanup here
Exit Sub
ErrorHandler:
' handle error here
Resume Cleanup
End Sub
But it would be best to fix your match which is allowing a division by zero in the first place.

VBA calling a variable by name inside a loop

Ok here's the deal: I need to do a comprehensive check in a .csv file (comparing the one in my current sheet to an external one). I decided to divide the list into 10 equal sections (deciles). In each decile I choose a random value belonging to that section and use that row number to compare the two sets of data.
Where things fall apart is inside the FOR function. I am looking for a way to go through each decile (starting from rand0) and have VBA check whether the values of the .csv and the Data sheet in this workbook are equal. If they are not - a function (called get_param) is to be executed.
I dont quite understand how to have VBA go through the FOR function from Dec = 0 to 9 - so in essence from row number rand0 to row number rand9 and perform the inequality check (in the second IF function). The rand & Dec part does not work. I am looking for clues on how to fix this or on a new implementation to do the same thing.
A few more details:
n is the number of rows in the .csv file (equal to a couple of thousand).
np is the number of rows in this file (should be equal to n - if not, execute function). ParamLocation is designated automatically - it should be located in a specific location.
Sub check_changes_param()
Dim Dec As Integer
Call public_dims
Call deciles
Set ParamBook = Workbooks.Open(ParamLocation)
'==========CHECKS IF PARAMETERS.xlsm EXISTS IN THE CORRECT LOCATION==========
If ParamLocation = "" Then
MsgBox "The Parameters.xlsm file does not exist or is in the incorrect location. Please ensure it is located in " & ParamLocation
Else
For Dec = 0 To Dec = 9
If ThisWorkbook.Sheets("Data").Cells(rand & Dec, 11) <> ParamBook.Sheets("Data").Cells(rand & Dec, 11) Or n <> np Then
Call get_param
Exit For
End If
Next Dec
End If
End Sub
Public Sub deciles()
rand0 = Int((n / 10) * 1) * Rnd + 1
rand1 = Int((n / 10) * 2 - (n / 10) * 1 + 1) * Rnd + (n / 10) * 1
rand2 = Int((n / 10) * 3 - (n / 10) * 2 + 1) * Rnd + (n / 10) * 2
rand3 = Int((n / 10) * 4 - (n / 10) * 3 + 1) * Rnd + (n / 10) * 3
rand4 = Int((n / 10) * 5 - (n / 10) * 4 + 1) * Rnd + (n / 10) * 4
rand5 = Int((n / 10) * 6 - (n / 10) * 5 + 1) * Rnd + (n / 10) * 5
rand6 = Int((n / 10) * 7 - (n / 10) * 6 + 1) * Rnd + (n / 10) * 6
rand7 = Int((n / 10) * 8 - (n / 10) * 7 + 1) * Rnd + (n / 10) * 7
rand8 = Int((n / 10) * 9 - (n / 10) * 8 + 1) * Rnd + (n / 10) * 8
rand9 = Int(n - (n / 10) * 9 + 1) * Rnd + (n / 10) * 9
End Sub
Try this instead:
Sub check_changes_param()
Dim Dec As Integer
Call public_dims
Dim deciles As Variant
deciles = decilesArray()
Set ParamBook = Workbooks.Open(ParamLocation)
'==========CHECKS IF PARAMETERS.xlsm EXISTS IN THE CORRECT LOCATION==========
If ParamLocation = "" Then
MsgBox "The Parameters.xlsm file does not exist or is in the incorrect location. Please ensure it is located in " & ParamLocation
Else
For Dec = 0 To UBound(deciles)
If ThisWorkbook.Sheets("Data").Cells(deciles(Dec), 11) <> ParamBook.Sheets("Data").Cells(deciles(Dec), , 11) Or n <> np Then
Call get_param
Exit For
End If
Next Dec
End If
End Sub
Public Function decilesArray() As Variant
randomize()
rand0 = Int((n / 10) * 1) * Rnd + 1
rand1 = Int((n / 10) * 2 - (n / 10) * 1 + 1) * Rnd + (n / 10) * 1
rand2 = Int((n / 10) * 3 - (n / 10) * 2 + 1) * Rnd + (n / 10) * 2
rand3 = Int((n / 10) * 4 - (n / 10) * 3 + 1) * Rnd + (n / 10) * 3
rand4 = Int((n / 10) * 5 - (n / 10) * 4 + 1) * Rnd + (n / 10) * 4
rand5 = Int((n / 10) * 6 - (n / 10) * 5 + 1) * Rnd + (n / 10) * 5
rand6 = Int((n / 10) * 7 - (n / 10) * 6 + 1) * Rnd + (n / 10) * 6
rand7 = Int((n / 10) * 8 - (n / 10) * 7 + 1) * Rnd + (n / 10) * 7
rand8 = Int((n / 10) * 9 - (n / 10) * 8 + 1) * Rnd + (n / 10) * 8
rand9 = Int(n - (n / 10) * 9 + 1) * Rnd + (n / 10) * 9
decilesArray= Array(rand0,rand1,rand2,rand3,rand4,rand5,rand6,rand7,rand8,rand9)
End Sub
I propose this correction,
public dim statements should be defined outside sub or functions.
use an array instead of concatenation to refer to a variable, rand & dec is not a correct VBA syntax to address rand0, ... rand9 variables.
Dim rand(9)
Sub check_changes_param()
Dim Dec As Integer, n
' Call public_dims ' put dim instructions as first instructions of this module
n = 10 'modify 10 to reflect correct value
Call deciles(n)
Set ParamBook = Workbooks.Open(ParamLocation)
'==========CHECKS IF PARAMETERS.xlsm EXISTS IN THE CORRECT LOCATION==========
If ParamLocation = "" Then
MsgBox "The Parameters.xlsm file does not exist or is in the incorrect location. Please ensure it is located in " & ParamLocation
Else
For Dec = 0 To 9
If ThisWorkbook.Sheets("Data").Cells(rand(Dec), 11) <> ParamBook.Sheets("Data").Cells(rand(Dec), 11) Or n <> np Then
Call get_param
Exit For
End If
Next Dec
End If
End Sub
Public Sub deciles(n)
rand(0) = Int((n / 10) * 1) * Rnd + 1
For i = 1 To 8
rand(i) = Int((n / 10) * (i + 1) - (n / 10) * (i + 1) + 1) * Rnd + (n / 10) * i
Next
rand(9) = Int(n - (n / 10) * 9 + 1) * Rnd + (n / 10) * 9
End Sub

Algorithm For Finding Greenwich Mean Sidereal Time Having Problems

I have currently gotten an algorithm to work for finding the Julian Day for my current location, but when using this value to proceed in finding the Greenwich Mean Sidereal Time, I get some very funky numbers. Can anyone run this script and maybe determine where my calculations go wrong? Thanks.
#1/user/bin/python
import math
from time import gmtime, strftime
#Sidereal Time Program
#Julien Date Converter
seconds = (int(strftime("%S")) * .01)
JD1 = ((367 * (int(strftime("%Y")))) - ((7 * ((int(strftime("%Y")))
+ (((int(strftime("%m"))) + 9) / 12))) / 4)
+ ((275 * (int(strftime("%m")))) / 9) + (int(strftime("%d"))) + 1721013.5
+ ((int(strftime("%I")) + (seconds) + 4) / 24) - 0.5 + 0.5 + 1.46)
JD2 = ((367 * (int(strftime("%Y")))) - ((7 * ((int(strftime("%Y")))
+ (((int(strftime("%m"))) + 9) / 12))) / 4)
+ ((275 * (int(strftime("%m")))) / 9) + (int(strftime("%d"))) + 1721013.5
+ ((int(12) + 4) / 24) - 0.5 + 0.5 - 0.192361555)
H = JD1 - JD2
JD = JD2 + (H / 24)
D1 = JD1 - 2451545.0
D2 = JD2 - 2451545.0
T = D1 / 36525
GMST1 = 6.697374558 + (0.06570982441908 * D2) + (1.00273790935 * H) + (0.000026 * (T * T))
GMST2 = 18.697374558 + (24.06570982441908 * D1)
o = 125.04 - (0.052954 * D1)
L = 280.47 + (0.98565 * D1)
e = 23.4393 - (0.0000004 * D1)
x = 2 * L
sym = (-0.000319 * (math.sin (o))) - (0.000024 * (math.sin (x)))
eqeq = (sym * (math.cos (e)))
GAST1 = GMST1 + eqeq
GAST2 = GMST2 +eqeq
print (JD1)
print (T)
print (GAST1)
print (GAST2)
Edit: Here is the formula I am using: http://aa.usno.navy.mil/faq/docs/GAST.php
It appears that this is a package that will do what you want. See, e.g., here.