Skip to content

Commit

Permalink
Remove unused/truncated array of coefficient numbers
Browse files Browse the repository at this point in the history
- fmt_igrf.c amended to use file direct from IAGA/NGDC
(previous version had headers stripped)
- IGRF_maxN removed as the array length was autoupdated,
but the contents were not. As the array isn't used
(present as legacy code only) removal was best option.
- Lgm_IGRF.h regenerated from updated fmt_igrf.c
  • Loading branch information
drsteve committed Jan 27, 2025
1 parent dc347f6 commit 2424f00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 44 deletions.
2 changes: 0 additions & 2 deletions libLanlGeoMag/Lgm/Lgm_IGRF.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ static int IGRF_nModels = 26;
static double IGRF_epoch[27] = { 1900.0, 1905.0, 1910.0, 1915.0, 1920.0, 1925.0, 1930.0, 1935.0, 1940.0, 1945.0,
1950.0, 1955.0, 1960.0, 1965.0, 1970.0, 1975.0, 1980.0, 1985.0, 1990.0, 1995.0, 2000.0, 2005.0, 2010.0, 2015.0, 2020.0, 2025.0 };

static int IGRF_MaxN[27] = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13 };

static double IGRF_Re = 6371.2; // km This is the so-called "magnetic reference spherical radius" that is adopted in IGRF modeling
static char IGRF_Model[] = "IGRF14";
static char IGRF_Model_Description[] = "14th Generation International Geomagnetic Reference Field";
Expand Down
56 changes: 14 additions & 42 deletions libLanlGeoMag/Utils/fmt_igrf.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <string.h>
#include <ctype.h>



int NumberOfColumns( char *String ){


int n;


/*
* strip off trailing non-alpha-numeric characters...
*/
Expand All @@ -22,29 +18,21 @@ int NumberOfColumns( char *String ){
}
}


n = 0;

if ( strtok( String, " \t" ) == NULL ) return(0);
else ++n;


while ( strtok( NULL, " \t" ) != NULL ){
++n;
}

return( n );

}





main(){



int main(){
char Line[4098], GaussType, ModelName[50][128];
double ModelYear[50];
char h1[2048], h2, h3;
Expand All @@ -53,7 +41,6 @@ main(){
double g[50][14][14], h[50][14][14];
FILE *fpin, *fpout;


for (i=0; i<50; ++i){
for(n=0; n<13; ++n){
for(m=0; m<13; ++m){
Expand All @@ -62,28 +49,32 @@ main(){
}
}



// open txt file containing coefficients
// fpin = fopen("igrf12coeffs.txt", "r");
fpin = fopen("igrf14coeffs.txt", "r");

// read off header
fgets(Line, 4096, fpin);
printf("Line = %s\n", Line);
// read off header (two comment lines, two header lines)
for (int hl=0; hl<4; hl++) {
fgets(Line, 4096, fpin);
printf("Line = %s\n", Line);
}

// read in a line of data (as opposed to the header -- better indicator of whats really here
fgets(Line, 4096, fpin);
printf("Line = %s\n", Line);
printf("Data Line = %s\n", Line);
nColumns = NumberOfColumns( Line );
printf("Columns = %d\n", nColumns);


nModels = nColumns - 4; // there are 3 colums at start defining coeff, plus SV at the end.
printf("nModels = %d\n", nModels);


rewind(fpin);
rewind(fpin); // rewind to start of filee
// read off header
for (int hl=0; hl<3; hl++) {
fgets(Line, 4096, fpin);
printf("Line = %s\n", Line);
}

fscanf(fpin, "%s %c %c", h1, &h2, &h3);
for (i=0; i<nModels; ++i){
Expand All @@ -93,11 +84,6 @@ main(){
fgets(Line, 128, fpin); /* read off the rest of the line (icluding newline) */







/*
* Read in the SV terms as though they were an additional model (they
* arent, but its convenient to keep track of the coeffs.)
Expand All @@ -113,10 +99,6 @@ main(){

printf("Got: %c_%d_%d\n", GaussType, n, m);





/*
* dump values to the proper g and h arrays..
*/
Expand All @@ -128,15 +110,12 @@ main(){
h[i][n][m] = val[i];
}


}

}

fclose(fpin);



/*
* Now dump out the coefficients as C static arrays...
*/
Expand Down Expand Up @@ -181,8 +160,6 @@ main(){
fprintf(fpout, " };\n\n");


fprintf(fpout, "static int IGRF_MaxN[%d] = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 13, 13, 13 };\n", nModels+1);
fprintf(fpout, "\n");
fprintf(fpout, "static double IGRF_Re = 6371.2; // km This is the so-called \"magnetic reference spherical radius\" that is adopted in IGRF modeling\n");
fprintf(fpout, "static char IGRF_Model[] = \"IGRF14\";\n");
fprintf(fpout, "static char IGRF_Model_Description[] = \"14th Generation International Geomagnetic Reference Field\";\n");
Expand Down Expand Up @@ -246,9 +223,6 @@ main(){
}
fprintf(fpout, " };\n");




for (i=0; i<nModels; ++i){
if (i==0) {
fprintf(fpout, "\n\nstatic double IGRF_h[%d][14][14] = {\n", nModels+1);
Expand Down Expand Up @@ -311,6 +285,4 @@ main(){

fclose(fpout);



}

0 comments on commit 2424f00

Please sign in to comment.