/* Sample program to read the J-format magnetic data file. This program reads J-format data files and displays the data in each 1 minutes. This program is compiled by Microsoft Visual C ver.4.0. Standard functions of C are used in the program. Therefore another C compiler will be able to compile this program. The "Large memory model" should be used to compile this program. Information of J-format is also seen on the Web page http://denji102.geo.kyushu-u.ac.jp/denji/obs/equator/system/jformat.html */ /* sample program ver.1.0 1991/ 6/25 M.Shinohara */ /* ver.2.0 1999/ 4/15 M.Shinohara */ #include #include /* subroutines in this program */ short dspinformation(char *readfile); void readinformation(char *readfile,char *station, short *year, short *month, short *day, short *lt, short *dt, double *sensitivity); void openmagdata(FILE **fp, char *readfile, short *basevalue); void closemagdata(FILE *fp); void read_1hour(FILE *fp, short *h, short *d, short *z, short *basevalue, short sampl_t); void findmagdataposition(FILE *fp); void calcbasevalue(FILE *fp, short *basevalue); /* 1991/ 6/25 M.Shinohara */ /* 1999/ 4/15 M.Shinohara */ void main ( short argc , char *argv[] ) { FILE *fp; static short h[3600],d[3600],z[3600]; /* magnetic data */ short basevalue[3]; /* base value */ short i,j,k,hour,min,sec,sampl_t; basevalue[0]=0; /* initialize of basevalue */ basevalue[1]=0; basevalue[2]=0; if ( argc < 2 ) { printf("\nusage : sampl_j p1 p2 p3...\n"); printf( " : p1 p2 p3... = J-format data file name\n"); printf( " 1999/ 4/15 M.Shinohara, Kyushu University\n\n"); printf( "example : sampl_j r970926.msr\n"); printf( " : sampl_j r990223.kuj r990224.kuj\n\n"); exit(0); } for ( i=0; i H=%8d D=%8d Z=%8d \n", hour,min,sec,h[k],d[k],z[k]); } } closemagdata(fp); printf("\n"); } } /* display file information */ /* parameter : char *readfile --- data file name */ /* 1991/ 6/25 M.Shinohara */ /* 1999/ 4/15 M.Shinohara */ short dspinformation(char *readfile) { double sensitivity[3]; /* sensitivity */ char station[8]; short year,month,day; short ltime,dt; /* read information part */ readinformation(readfile,station,&year,&month,&day, <ime,&dt,sensitivity); printf(" station = %8s \n",station); printf(" date = %4d / %2d / %2d \n",year,month,day); printf(" local time = %4d hour\n",ltime); printf(" sampling rate = %4d sec \n",dt); printf("sensitivity "); printf(" H=%8.4lf",sensitivity[0]); printf(" D=%8.4lf",(float)sensitivity[1]); printf(" Z=%8.4lf\n",sensitivity[2]); return(dt); } /* Read file information */ /* parameter : char *readfile --- data file name char *station --- station name short *year --- year short *month --- month short *day --- day short *ltime --- local time short *dt --- sampling rate double *sensitivity --- sensitivity */ /* 1991/ 6/25 M.Shinohara */ /* 1999/ 4/15 M.Shinohara */ void readinformation(char *readfile, char *station, short *year, short *month, short *day, short *ltime, short *dt, double *sensitivity) { FILE *fp; char c[20]; fp=fopen(readfile,"rt"); /* open data file */ if ( fp==NULL ) /* when can't find data file */ { printf("data file is not found '%s' !\n",readfile); exit(0); } /* read some information */ fscanf(fp,"%s",station); fscanf(fp,"%d %d %d",year,month,day); fscanf(fp,"\r\n LT= %d DT= %d %s",ltime,dt,c); fscanf(fp,"\r\n H= %le D= %le Z= %le", sensitivity,sensitivity+1,sensitivity+2); fclose(fp); /*close data file */ return; } /* Open magnetic data file */ /* parameter : FILE **fp --- file pointer of data file char *readfile --- data file name short *basevalue --- basevalue */ /* 1991/ 6/25 M.Shinohara */ /* 1999/ 4/15 M.Shinohara */ void openmagdata(FILE **fp, char *readfile, short *basevalue) { *fp=fopen(readfile,"rb"); /* open data file */ if ( *fp==NULL ) /* when can't find data file */ { printf("data file is not found '%s' !\n",readfile); exit(0); } /* find start position of magnetic data */ findmagdataposition(*fp); /* calculate today's basevalue */ calcbasevalue(*fp,basevalue); return; } /* 1999/ 4/15 M.Shinohara */ void closemagdata(FILE *fp) { fclose(fp); /*close data file */ return; } /* Read 1 hour magnetic data */ /* parameter : FILE *fp --- file pointer of data file short *h --- H component data short *d --- D component data short *z --- data array of short *basevalue --- basevalue short sampl_t --- sampling time of magnetic data*/ /* 1991/ 6/25 M.Shinohara */ /* 1999/ 4/15 M.Shinohara */ void read_1hour(FILE *fp, short *h, short *d, short *z, short *basevalue, short sampl_t) { short dbuff[3]; short i,j; /* read and calculate magnetic data of each component */ for ( i=0; i<3600; i=i+sampl_t ) { /* read 1 hour data */ fread((char *)dbuff,2,3,fp); /* calculate each component */ for (j=i;j