'CR1000X Series Datalogger ' ''''''''''''''''''''''''''''''''''''''''''''' '' SPA TESTER For SPA.CR1X '' '' '' '' Solar Position Algorithm (SPA) '' '' for '' '' Solar Radiation Application '' '' '' '' October 30, 2018 '' '' '' '' Filename: SPA_Tester.CR1X '' '' '' '' Afshin Michael Andreas '' '' Afshin.Andreas@NREL.gov (303)384-6383 '' '' '' '' Metrology Laboratory '' '' Solar Radiation Research Laboratory '' '' National Renewable Energy Laboratory '' '' 15013 Denver W Pkwy, Golden, CO 80401 '' ''''''''''''''''''''''''''''''''''''''''''''' ' ''''''''''''''''''''''''''''''''''''''''''''' '' This Sample program shows how to use '' '' the SPA_Enc.CR1X code. '' ''''''''''''''''''''''''''''''''''''''''''''' ' ' NOTE: The CRBasic Code only works on Campbell Scientific data loggers that support DOUBLE data types, ' such as the CR1000X and CR6. This code has been tested on the CR1000X OS 2.0. As needed the ' file extension should be renamed to .CR1X or .CR6 (or the model appropriate to data logger). ' ' Prior to loading and starting this CRBasic code, the following files must be loaded on data logger CPU: ' SPA_Enc.CR1X - NREL SPA CRBasic Code (encrypted) ' spa_l_terms.txt - NREL SPA Earth Periodic L Terms (text file) ' spa_b_terms.txt - NREL SPA Earth Periodic B Terms (text file) ' spa_r_terms.txt - NREL SPA Earth Periodic R Terms (text file) ' spa_y_terms.txt - NREL SPA Periodic Y Terms for the nutation in longitude and obliquity (text file) ' spa_pe_terms.txt - NREL SPA Periodic PE Terms for the nutation in longitude and obliquity (text file) ' ' 'Constants for Site Location used for NREL SPA Inputs Const TZ_c = -7.0 'Observer time zone [hours] (negative west of Greenwich) ' valid range: -18 to 18 hours, error code: 8 Const Lon_c = -105.178 'Observer longitude [degrees] (negative west of Greenwich) ' valid range: -180 to 180 degrees, error code: 9 Const Lat_c = 39.743 'Observer latitude [degrees] (negative south of equator) 'valid range: -90 to 90 degrees, error code: 10 Const Alt_c = 1829 'Observer elevation [meters] ' valid range: -6500000 or higher meters, error code: 11 Const Pres_c = 835 'Annual average local pressure [millibars] 'valid range: 0 to 5000 millibars, error code: 12 Const Temp_c = 10 'Annual average local temperature [degrees Celsius] ' valid range: -273 to 6000 degrees Celsius, error code; 13 Const Slope_c = 0.0 'Surface slope [degrees] (measured from the horizontal plane) 'valid range: -360 to 360 degrees, required for Incidence Angle only, error code: 14 Const AzmRot_c = 0.0 'Surface azimuth rotation (measured from south to projection of surface normal on horizontal plane, negative east) 'valid range: -360 to 360 degrees, required for Incidence Angle only, error code: 15 Const DelT_c = 68.884 'delta_t = 32.184 + (TAI-UTC) - DUT1 at http://maia.usno.navy.mil/ser7/ser7.dat ' valid range: -8000 to 8000 seconds, error code: 7 Const DelUT1_c = 0.3 'delta_ut1 = DUT1 at http://maia.usno.navy.mil/ser7/ser7.dat 'valid range: -1 to 1 second (exclusive), error code 17 Include "CPU:SPA_Enc.CR1X" 'Include NREL SPA CRBasic Code (encrypted) Dim Time(9) 'Time Array for NREL SPA Input (from data logger clock), error codes 1 through 6 Public spa(SPA_COUNT) As Double 'NREL SPA Output Array Alias spa(1) = Zenith 'topocentric zenith angle [degrees] Alias spa(2) = Azimuth 'topocentric azimuth angle (eastward from north) [for navigators and solar radiation] Alias spa(3) = Azimuth_Astro 'topocentric azimuth angle (westward from south) [for astronomers] Alias spa(4) = Incidence 'surface incidence angle [degrees] Alias spa(5) = jd 'Julian day Alias spa(6) = jc 'Julian century Alias spa(7) = jde 'Julian ephemeris day Alias spa(8) = jce 'Julian ephemeris century Alias spa(9) = jme 'Julian ephemeris millennium Alias spa(10) = l 'earth heliocentric longitude [degrees] Alias spa(11) = b 'earth heliocentric latitude [degrees] Alias spa(12) = r 'earth radius vector [Astronomical Units, AU] Alias spa(13) = theta 'geocentric longitude [degrees] Alias spa(14) = beta 'geocentric latitude [degrees] Alias spa(15) = x_0 'mean elongation (moon-sun) [degrees] Alias spa(16) = x_1 'mean anomaly (sun) [degrees] Alias spa(17) = x_2 'mean anomaly (moon) [degrees] Alias spa(18) = x_3 'argument latitude (moon) [degrees] Alias spa(19) = x_4 'ascending longitude (moon) [degrees] Alias spa(20) = del_psi 'nutation longitude [degrees] Alias spa(21) = del_epsilon 'nutation obliquity [degrees] Alias spa(22) = epsilon0 'ecliptic mean obliquity [arc seconds] Alias spa(23) = epsilon 'ecliptic true obliquity [degrees] Alias spa(24) = del_tau 'aberration correction [degrees] Alias spa(25) = lamda 'apparent sun longitude [degrees] Alias spa(26) = nu0 'Greenwich mean sidereal time [degrees] Alias spa(27) = nu 'Greenwich sidereal time [degrees] Alias spa(28) = alpha 'geocentric sun right ascension [degrees] Alias spa(29) = delta 'geocentric sun declination [degrees] Alias spa(30) = h 'observer hour angle [degrees] Alias spa(31) = xi 'sun equatorial horizontal parallax [degrees] Alias spa(32) = del_alpha 'sun right ascension parallax [degrees] Alias spa(33) = delta_prime 'topocentric sun declination [degrees] Alias spa(34) = alpha_prime 'topocentric sun right ascension [degrees] Alias spa(35) = h_prime 'topocentric local hour angle [degrees] Alias spa(36) = e0 'topocentric elevation angle (uncorrected) [degrees] Alias spa(37) = del_e 'atmospheric refraction correction [degrees] Alias spa(38) = e 'topocentric elevation angle (corrected) [degrees] Public spa_init_result 'SPA Initializing error code related to reading or parsing periodic terms from CPU 'Init Result Codes: 0 = No Error, 1 = L Term Error, 2 = B Term Error, 3 = R Term Error, 4 = Y Term Error, 5 = PE Term Error Public spa_result 'Error code from NREL_SPA() function, see SPA Input Constants above for error codes Public SolPos_Zen Public SolPos(5) 'Array for CRBasic SolarPosition() output Alias SolPos(1) = SolPos_Azm Alias SolPos(2) = SolPos_Elev Alias SolPos(3) = SolPos_HourAngle Alias SolPos(4) = SolPos_Declination Alias SolPos(5) = SolPos_AirMassPC Public PTemp, Batt 'Data logger measurements 'Define Data Tables DataTable (DataOut,True,-1) DataInterval (0,1,Min,10) Average (1,PTemp,FP2,False) Minimum (1,Batt,FP2,False,False) Sample (2,spa,IEEE4) EndTable 'Main Program BeginProg 'Call NREL SPA Initialization Function NREL_SPA_Init(spa_init_result) Scan (1,Sec,0,0) 'Get data logger time RealTime(Time()) 'Call NREL SPA Function with required inputs; outputs will populate into spa array NREL_SPA(spa, Time, TZ_c, Lat_c, Lon_c, Alt_c, Pres_c, Temp_c, DelT_c, DelUT1_c, Slope_c, AzmRot_c, spa_result) 'Call CRBasic built-in SolarPostion function (based on older NREL SOLPOS) for optional comparison to SPA SolarPosition (SolPos,Time(),TZ_c*3600,Lat_c,Lon_c,Alt_c,Pres_c,Temp_c) SolPos_Zen = 90.0 - SolPos_Elev PanelTemp (PTemp,_60Hz) Battery (Batt) CallTable DataOut NextScan EndProg