Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c3dec28
Formatting
mghenderson64 Sep 18, 2019
fd13056
Changed LambdaIntegrand() to calculate at at variable r istead of ass…
mghenderson64 Sep 18, 2019
a91ef68
Commented out debugging printf()'s
mghenderson64 Sep 18, 2019
f0ef349
Added an argument to ComputeI_FromMltMlat(), ComputeI_FromMltMlat1() …
mghenderson64 Sep 18, 2019
e54af2d
Improved search for drift shell FLs. Fixed issues with Shabansky orbi…
mghenderson64 Sep 18, 2019
a5ec7dc
Added Lgm_FluxTubeVolume.c for compilation
mghenderson64 Sep 18, 2019
0623da4
Added entries to make Lgm_FluxTubeVolume.c work
mghenderson64 Sep 18, 2019
074b43e
Changed a number of function protottypes to add ErrorStatus argument.
mghenderson64 Sep 18, 2019
69282cf
Added additioonal memory management routines for KdTree stuff.
mghenderson64 Sep 18, 2019
c605eb4
Changed Lgm_MagStep_BS_rtol from 1e-5 to 0.0 -- improves stability of…
mghenderson64 Sep 18, 2019
2953c9b
Added yet another version of the B_From_ScatteredMesh stuff -- this i…
mghenderson64 Sep 18, 2019
0349c28
Changes to the divergence free stuff -- still experimental.
mghenderson64 Sep 18, 2019
ebc7e0c
Removed 2 debugging lines.
mghenderson64 Sep 18, 2019
472d688
A possibly impactful change: In order to get Bmin correct on FLs that…
mghenderson64 Sep 18, 2019
5253be3
Aome formating changes. Change in return value when last point goes f…
mghenderson64 Sep 18, 2019
d5f07d2
No changes to code, but I added a comment describing a modification t…
mghenderson64 Sep 18, 2019
2ab9d68
Fixed bugs in code. Files are still hardcoded to mghenderson directory.
mghenderson64 Sep 19, 2019
92c5ccd
Cleaned up example code.
mghenderson64 Sep 19, 2019
c79e5fb
Added test to see if "Objects" are dewfined before using them.
mghenderson64 Sep 19, 2019
4ac6c1d
Extensive changes to get ISearchMethod2 working. Also added logic to …
mghenderson64 Sep 19, 2019
284c69e
Changed MLT from 37.75 to 13.75 (same, but less confusing).
mghenderson64 Sep 19, 2019
52c90c5
Cleaned up the dipole test code.
mghenderson64 Sep 19, 2019
297219b
Routines to compute flux tube volume (integral of 1/|B| from southern…
mghenderson64 Sep 19, 2019
762805f
Adding missing makefile
mghenderson64 Sep 19, 2019
feddd4a
Adding missing makefile
mghenderson64 Sep 19, 2019
ea0eac2
Changed function prototypep name from FluxTubeVolume to Lgm_FluxTubeV…
mghenderson64 Sep 19, 2019
7d55127
Added regression test for FluxTubeVolume calculation.
mghenderson64 Sep 23, 2019
00ed5e6
Added check_FluxTubeVolume.c
mghenderson64 Sep 23, 2019
558ddc9
The DOY wasnt being set in Lgm_TT_to_UTC(). Fixed. There my be other …
mghenderson64 Oct 9, 2019
957e13b
Various old mods
mghenderson64 Oct 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions Examples/CoordQuickStart/CoordQuickStart.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,28 @@ int main( ) {
long int Date;
double UTC, Lat, Lon, r;

Date = 20170101; // Jan 1, 2000
/*
Date: 2014-08-29 15:32:13.811285
GMST: 3.67943418927
ITRF: [-13710.99888512 -3465.32964842 10000. ]
TEME: [ 10000. 10000. 10000.]
*/


//Date = 20170101; // Jan 1, 2000
Date = 20140829; // Jan 1, 2000
//Date = 20000101; // Jan 1, 2000
UTC = 12.0+0.0/60.0; // Universal Time Coordinated (in decimal hours)
//UTC = 12.0+0.0/60.0; // Universal Time Coordinated (in decimal hours)
UTC = 15.0+32.0/60.0+13.811285/3600.0;
Ugsm.x = -6.6; Ugsm.y = 3.4; Ugsm.z = -2.3; // Set a vector in GSM coordinates

// Set up all the necessary variables to do transformations for this Date and UTC
/* Options for setting Sun/Moon pos are: */
//Lgm_Set_CTrans_Options(LGM_EPH_HIGH_ACCURACY, LGM_PN_IAU76, c); /* Uses LGM high accuracy analytic solution */
Lgm_Set_CTrans_Options(LGM_EPH_DE, LGM_PN_IAU76, c); /* Uses JPL Development Ephemeris */
Lgm_Set_CTrans_Options(LGM_EPH_HIGH_ACCURACY, LGM_PN_IAU76, c); /* Uses LGM high accuracy analytic solution */
//Lgm_Set_CTrans_Options(LGM_EPH_DE, LGM_PN_IAU76, c); /* Uses JPL Development Ephemeris */
//Lgm_Set_CTrans_Options(LGM_EPH_LOW_ACCURACY, LGM_PN_IAU76, c); /* Uses Basic Ephemeris Calcs*/


//Lgm_Set_CTrans_Options(LGM_EPH_LOW_ACCURACY, LGM_PN_IAU76, c); /* Same as NOT calling Set_CTrans_Options */
Lgm_Set_Coord_Transforms( Date, UTC, c );

Expand Down
3 changes: 3 additions & 0 deletions Examples/EopExample/QuickStartEop.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ int main( ) {

Date = 20040812; // August 12, 2004
UTC = 12.34567; // Universal Time Coordinated (in decimal hours)
Date = 20140829; // Jan 1, 2000
UTC = 15.0+32.0/60.0+13.811285/3600.0;

JD = Lgm_Date_to_JD( Date, UTC, c ); // Compute JD
Ugsm.x = -6.6; Ugsm.y = 3.4; Ugsm.z = -2.3; // Set a vector in GSM coordinates

Expand Down
132 changes: 132 additions & 0 deletions Examples/FluxTubeVolume/FluxTubeVolume.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <Lgm_CTrans.h>
#include <Lgm_QinDenton.h>
#include <Lgm_ElapsedTime.h>
#include <Lgm_FluxToPsd.h>
#include <omp.h>


int main(){

double x, y, GeodLat, GeodLong, GeodHeight ;
double UTC, JD;
long int Date;
int Flag;
double V, r, mlat, MLT, cl, sl, Phi, Sb;


double Hdid, Hnext, s, Inc;
int reset=0, Ni;
Lgm_Vector u_scale;
int EnhancedFlag;
Lgm_QinDentonOne p;
Lgm_Vector u, u_sm, v1, v2, v3, Bvec;
Lgm_MagModelInfo *mInfo2, *mInfo = Lgm_InitMagInfo();
char Filename[1024];
int i, ii, nDivs, Status;
FILE *fpout;
FILE *fpout2 = fopen( "FL.txt", "w" );


Date = 20130324;
UTC = 23.462;
UTC = 23.662;
JD = Lgm_Date_to_JD( Date, UTC, mInfo->c );
Lgm_Set_Coord_Transforms( Date, UTC, mInfo->c );
printf("Tilt = %g\n", mInfo->c->psi*DegPerRad );
//exit(0);

Lgm_get_QinDenton_at_JD( JD, &p, 1, 1 );
Lgm_set_QinDenton( &p, mInfo );

Lgm_MagModelInfo_Set_MagModel( LGM_IGRF, LGM_EXTMODEL_TS04, mInfo );
Lgm_MagModelInfo_Set_MagModel( LGM_CDIP, LGM_EXTMODEL_T87, mInfo );
Lgm_MagModelInfo_Set_MagModel( LGM_IGRF, LGM_EXTMODEL_T96, mInfo );
Lgm_MagModelInfo_Set_MagModel( LGM_IGRF, LGM_EXTMODEL_T89, mInfo );
Lgm_MagModelInfo_Set_MagModel( LGM_IGRF, LGM_EXTMODEL_TS04, mInfo );
Lgm_MagModelInfo_Set_MagModel( LGM_IGRF, LGM_EXTMODEL_OP77, mInfo );
Lgm_MagModelInfo_Set_MagModel( LGM_IGRF, LGM_EXTMODEL_T01S, mInfo );

char *s1, *s2, *s3, *s4;
Lgm_Get_ExtMagModelStrings( &s1, &s2, &s3, &s4, mInfo );
printf( "s1 = %s\n", s1 );
printf( "s2 = %s\n", s2 );
printf( "s3 = %s\n", s3 );
printf( "s4 = %s\n", s4 );
sprintf( Filename, "V_%s.txt", mInfo->ExtMagModelStr1 );
fpout = fopen( Filename, "w" );


//mInfo->fp = fpout2;
mInfo->SavePoints = FALSE;
MLT = 0.0;
r = 1.0 + 200.0/Re;
GeodHeight = 200.0;
Inc = 0.1;
Ni = (80.0-60.0)/Inc;
mInfo->Lgm_MagStep_BS_atol = 1e-6;
mInfo->Lgm_MagStep_BS_rtol = 0.0;
mInfo->VerbosityLevel = 0;

#pragma omp parallel private(Status,mlat,Phi,cl,sl,u_sm,u,v1,v2,v3,mInfo2,Flag,nDivs,V,Sb)
#pragma omp for schedule(dynamic, 20)
for ( i=0; i<=Ni; i++ ) {

mlat = 60.0 + Inc*i;

mInfo2 = Lgm_CopyMagInfo( mInfo );

/*
* Trace from given SM position
*/
printf("mlat, MLT = %g %g ", mlat, MLT);
Phi = 15.0*(MLT-12.0)*RadPerDeg;
cl = cos( mlat * RadPerDeg ); sl = sin( mlat * RadPerDeg );
u_sm.x = r*cl*cos(Phi); u_sm.y = r*cl*sin(Phi); u_sm.z = r*sl;
Lgm_Convert_Coords( &u_sm, &u, SM_TO_GSM, mInfo2->c );
//printf("u_sm = %g %g %g\n", u_sm.x, u_sm.y, u_sm.z );
//printf("u = %g %g %g\n", u.x, u.y, u.z );

Flag = Lgm_Trace( &u, &v1, &v2, &v3, GeodHeight, 1e-7, 1e-7, mInfo2 );
mInfo2->Bm = mInfo2->Ellipsoid_Footprint_Bn;


if ( Flag == LGM_CLOSED ) {
nDivs = mInfo2->Stotal/0.1;
if ( nDivs < 200 ) nDivs = 200;
mInfo2->Hmax = mInfo2->Stotal/((double)(nDivs));

Status = Lgm_TraceLine3( &v1, mInfo2->Stotal, nDivs, 1.0, 1e-7, FALSE, mInfo2 );

if ( !InitSpline( mInfo2 ) ) {
printf("Failed to init spline\n");
exit(1);
} else {

V = Lgm_FluxTubeVolume( mInfo2 );
Sb = SbIntegral_interped2( mInfo2, 0.0, mInfo2->Stotal );
printf( "south, north = %g %g , mlat, MLT, FluxTubeVolume, Sb = %g %g %g %g\n", mInfo2->Ssouth, mInfo2->Snorth, mlat, MLT, V, Sb );
fprintf( fpout, "%g %g\n", mlat, V );
fflush( fpout );
FreeSpline( mInfo2 );

}
} else {
printf("\n");
}

Lgm_FreeMagInfo( mInfo2 );


}

fclose( fpout );
fclose( fpout2 );
Lgm_FreeMagInfo( mInfo );




}
9 changes: 9 additions & 0 deletions Examples/FluxTubeVolume/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Very simple makefile illustrating how to use pkg-config to compile

all: FluxTubeVolume

FluxTubeVolume: FluxTubeVolume.c
gcc FluxTubeVolume.c `pkg-config --cflags --libs lgm` -o FluxTubeVolume

clean:
rm FluxTubeVolume
43 changes: 24 additions & 19 deletions Examples/KdTree/DstNNs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main( ) {
double Time, JD, JDs, JDe, UTC, x, y, z, r, dist, *Dist, delta;
long int Date, KeepList[10000], nKeepList, Id;
unsigned long int n, *Idx, nSearches, Id_Old;
char Filename[256];
char Filename[256], IsoDateTime[40];
Lgm_KdTree *KdTree;
Lgm_KdTreeData *kNN;
int K, Kgot, i, j, jj, d, D, k, ny, nm, nd, Keep;
Expand All @@ -30,26 +30,25 @@ int main( ) {
/*
* Read in Dst data from 1976 -> 2011
*/
Date = 19580101; UTC = 12.0; JDs = Lgm_Date_to_JD( Date, UTC, c );
Date = 19760101; UTC = 12.0; JDs = Lgm_Date_to_JD( Date, UTC, c );
Date = 20110101; UTC = 12.0; JDe = Lgm_Date_to_JD( Date, UTC, c );
Date = 19760102; UTC = 12.0; JDe = Lgm_Date_to_JD( Date, UTC, c );
Date = 19570101; UTC = 12.0; JDs = Lgm_Date_to_JD( Date, UTC, c );
Date = 20190630; UTC = 12.0; JDe = Lgm_Date_to_JD( Date, UTC, c );
n = 0;
for ( JD=JDs; JD<=JDe; JD += 1.0 ) {
Date = Lgm_JD_to_Date( JD, &ny, &nm, &nd, &UTC );
sprintf( Filename, "/home/mghenderson/Data/Dst/%4d/Dst_%ld.dat", ny, Date );
printf("reading: %s\n", Filename );
//if ( (fp = fopen( Filename, "r" ) ) != NULL ) {
// while ( fscanf( fp, "%lf %lf %lf %lf %lf\n", &Time, &dum1, &dum2, &dum3, &DstIndex ) != EOF ){
// Dst[n] = DstIndex;
// if ((Time > 0.0)&&(Time < 1.0)&&(Date == 20011124)) printf("n = %ld\n", n);
// if ( n == 120228 ) printf("Date = %ld\n", Date);
// if ( n == 250434 ) printf("Date = %ld\n", Date);
// ++n;
// }
// fclose( fp );

//}
if ( (fp = fopen( Filename, "r" ) ) != NULL ) {
while ( fscanf( fp, "%19s %ld %lf %lf", IsoDateTime, &Date, &Time, &DstIndex ) != EOF ){
//printf("IsoDateTime = %s\n", IsoDateTime);
Dst[n] = DstIndex;
//if ((Time > 0.0)&&(Time < 1.0)&&(Date == 20011124)) printf("n = %ld\n", n);
//if ( n == 120228 ) printf("Date = %ld\n", Date);
//if ( n == 250434 ) printf("Date = %ld\n", Date);
++n;
}
fclose( fp );

}
}
printf("n = %ld\n", n);

Expand All @@ -59,14 +58,19 @@ int main( ) {
*/
D = 96*2;
LGM_ARRAY_2D( u, D, n, double );
long int nj =0;
for ( j=0; j<n-2*D; j++ ) {
//printf("j=%d\n", j);
for ( d=0; d<D; d++ ) {
u[d][j] = Dst[j+d];
}
++nj;
}
printf("nj = %ld\n", nj);
printf("Creating %d dimensional KdTree with %ld points\n", D, n);
Lgm_ElapsedTimeInit( &t, 255, 150, 0 );
KdTree = Lgm_KdTree_Init( u, (void **)B, n, D );
//KdTree = Lgm_KdTree_Init( u, (void **)B, n, D );
KdTree = Lgm_KdTree_Init( u, (void **)B, nj, D );
Lgm_PrintElapsedTime( &t );


Expand All @@ -75,7 +79,8 @@ int main( ) {
*/
LGM_ARRAY_1D( q, D, double );
for ( d=0; d<D; d++ ) {
q[d] = u[d][227016];
q[d] = u[d][227017];
//q[d] = u[d][226990];
}


Expand Down Expand Up @@ -136,7 +141,7 @@ int main( ) {
printf(" )\n");

fp_out = fopen("DstNNs.dat", "w");
if (nKeepList > 4) nKeepList = 4;
if (nKeepList > 10) nKeepList = 10;
for ( jj=0; jj<nKeepList; jj++ ) {
j = KeepList[jj];
fprintf( fp_out, "%d %g 3\n", 0, kNN[j].Position[0] );
Expand Down
Loading