/* ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc Name : readump_pem_l3tp_data.c Usage : To read UARS PEM 3TP data which distributes from GSFCDAAC unix system. To run this program just enter program name followed by metadata file name. Example: readump_pem_l3tp_data Description : program opens meta data file (*.*META) first (which entered from command line) to get data file name (*.*PROD) and it's phyrec size then opens and reads that data file. Author : KE - JUN SUN Hughes_STX Date : February 2, 1994 Limitations : Since data are 32 bit IEEE floating point reals so it won't work on 64 bit floating point machine. (like CONVEX) Notes : Since this program need to get data file name and data file record size from metadata file, thus metadata file and data file pair must be coexistent. Algorithm information : No calculation is performed in this program. Version : 0 To compile this progam : cc readump_pem_l3tp_data.c -o readump_pem_l3tp_data executable code will be named readump_pem_l3tp_data Modification: May 12, 1994 by sandee@pemrac.space.swri.edu (Sandee Jeffers) ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc*/ #include #include main(argc,argv) int argc; char *argv[]; { char line[22630]; char temp[30],data_file[160],str[80],dirname[80]; char file_type[13]; int index1,index2,i,k,n,ret,rec,select,rec_size,*int4,tempint; int Total,Actual,T1,T2,Numb,Par_numb,yr,dy,ms; FILE *meta_ifp,*data_ifp; float *lat,*lon,*real4,tmpfloat; float data[2816],stdv[2816],Lat,Lon; int row,col,zero; /* ******* Open meta data file first ******** */ meta_ifp = fopen(argv[1],"r"); if (meta_ifp == NULL) { printf(" Can not open meta data file \n"); exit(); } for(i=0;i<10;i++) { fgets(line,80,meta_ifp); if(i==1) { strncpy(temp,&line[12],12); /* file type */ sscanf(temp,"%s",file_type); } } /* get data file name from line 10 or from meta data file name */ /* strncpy(str,&line[14],50); sscanf(str,"%s",data_file); */ strncpy(data_file,argv[1],(strlen(argv[1])-5)); strcat(data_file,"_PROD"); fgets(line,80,meta_ifp); fgets(line,80,meta_ifp); /* get record size from meta file */ strncpy(temp,&line[16],5); rec_size = atoi(temp); fclose(meta_ifp); /* **** Now open data file **** */ data_ifp=fopen(data_file,"r"); if (data_ifp == NULL) { printf(" Can not open data file \n"); exit(0); } printf(" ******************************************\n"); printf(" Reading %s\n",data_file); printf(" ******************************************\n"); memset(temp,' ',25); fread(line,1,rec_size,data_ifp); printf("-----------------------------\n"); printf(" Descriptor \n"); printf("-----------------------------\n"); printf(" SFDU T[Z] & L[Z] \n"); printf("-----------------------------\n"); strncpy(temp,&line[0],4); printf(" Control ID : %s\n",temp); memset(temp,' ',8); strncpy(temp,&line[4],1); printf(" Version ID : %s\n",temp); strncpy(temp,&line[5],1); printf(" Class ID : %s\n",temp); strncpy(temp,&line[8],4); printf(" Data descriptive record ID : %s\n",temp); strncpy(temp,&line[12],8); printf(" Length : %s\n",temp); printf("-----------------------------\n"); printf(" SFDU T[I] & L[I] \n"); printf("-----------------------------\n"); memset(temp,' ',8); strncpy(temp,&line[20],4); printf(" Control ID : %s\n",temp); memset(temp,' ',8); strncpy(temp,&line[24],1); printf(" Version ID : %s\n",temp); strncpy(temp,&line[25],1); printf(" Class ID : %s\n",temp); strncpy(temp,&line[28],4); printf(" Data descriptive record ID : %s\n",temp); strncpy(temp,&line[32],8); printf(" Length : %s\n",temp); memset(temp,' ',25); fread(line,1,rec_size,data_ifp); printf("-----------------------------\n"); printf(" Label record \n"); printf("-----------------------------\n"); strncpy(temp,&line[0],4); printf(" Satellite ID : %s\n",temp); memset(temp,' ',4); strncpy(temp,&line[4],2); printf(" Record type : %s\n",temp); strncpy(temp,&line[6],12); printf(" Instrument ID : %s\n",temp); strncpy(temp,&line[18],12); printf(" Subtype or Species : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[30],4); printf(" Format version number : %s\n",temp); strncpy(temp,&line[34],8); printf(" Physical record count : %s\n",temp); strncpy(temp,&line[46],8); printf(" Number of physical records in file : %s\n",temp); strncpy(temp,&line[54],23); printf(" File Creation Time : %s\n",temp); memset(temp,' ',23); printf(" Year day Ms for earliest data record : "); strncpy(temp,&line[77],3); sscanf(temp,"%d",&yr); strncpy(temp,&line[80],3); sscanf(temp,"%d",&dy); strncpy(temp,&line[83],8); sscanf(temp,"%d",&ms); printf("%3d %3d %8d\n",yr,dy,ms); memset(temp,' ',8); printf(" Year day Ms for last data record : "); strncpy(temp,&line[91],3); sscanf(temp,"%d",&yr); strncpy(temp,&line[94],3); sscanf(temp,"%d",&dy); strncpy(temp,&line[97],8); sscanf(temp,"%d",&ms); printf("%3d %3d %8d\n",yr,dy,ms); memset(temp,' ',14); strncpy(temp,&line[105],3); printf(" Data level : %s\n",temp); strncpy(temp,&line[108],4); printf(" UARS day number : %s\n",temp); strncpy(temp,&line[112],4); printf(" Max. number of 32-bit words per record : %s\n",temp); strncpy(temp,&line[120],5); printf(" Record length in bytes : %s\n",temp); strncpy(temp,&line[125],9); printf(" CCB version number : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[134],5); printf(" File cycle number : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[139],1); printf(" Virtual file flag : %s\n",temp); strncpy(temp,&line[140],4); printf(" Total number of time/version in file : %s\n",temp); strncpy(temp,&line[144],4); printf(" Number of time/version in record : %s\n",temp); rec = 2; do { memset(temp,' ',25); ret = fread(line,1,rec_size,data_ifp); if (ret > 0) { printf("-----------------------------\n"); printf(" Record : %d data record\n",rec); printf("-----------------------------\n"); strncpy(temp,&line[0],4); printf(" Satellite ID : %s\n",temp); memset(temp,' ',8); strncpy(temp,&line[4],2); printf(" Record type : %s\n",temp); strncpy(temp,&line[6],12); printf(" Instrument ID : %s\n",temp); strncpy(temp,&line[18],10); printf(" Physical record count : %s\n",temp); memset(temp,' ',10); int4 = (int *)&line[28]; Total = *int4; printf(" Max. number of 32-bit words in record : %d\n",Total); int4 = (int *)&line[32]; Actual = *int4; printf(" Number of actual 32-bit words in record : %d\n",Actual); int4 = (int *)&line[40]; T1 = *int4; int4 = (int *)&line[44]; T2 = *int4; printf(" UDTF time : %d %d (year day, milliseconds)\n",T1,T2); real4 = (float *)&line[48]; Lat = *real4; printf(" Latitude : %f (degress)\n",Lat); real4 = (float *)&line[52]; Lon = *real4; printf(" Longitude : %f (degress)\n",Lon); int4 = (int *)&line[64]; Par_numb = *int4; printf(" Number of 32-bit Parameter words : %d\n",Par_numb); if(strcmp(file_type,"MEPS_ELEC_ED")==0|| strcmp(file_type,"MEPS_PROT_ED")==0) { int4 = (int *)&line[68]; T1 = *int4; int4 = (int *)&line[72]; T2 = *int4; printf(" 1/3 time in UDTF format : %d %d (year day, milliseconds)\n", T1,T2); real4 = (float *)&line[76]; Lat = *real4; printf(" 1/3 Latitude : %f (degress)\n",Lat); real4 = (float *)&line[80]; Lon = *real4; printf(" 1/3 Longitude : %f (degress)\n",Lon); int4 = (int *)&line[84]; T1 = *int4; int4 = (int *)&line[88]; T2 = *int4; printf(" 2/3 time in UDTF format : %d %d (year day, milliseconds)\n", T1,T2); real4 = (float *)&line[92]; Lat = *real4; printf(" 2/3 Latitude : %f (degress)\n",Lat); real4 = (float *)&line[96]; Lon = *real4; printf(" 2/3 Longitude : %f (degress)\n",Lon); index1 = 100; index2 = 11364; printf(" ----------------------------------------------\n"); if (strcmp(file_type,"MEPS_ELEC_ED")==0) printf(" MEPS ELECTRON\n"); else printf(" MEPS PROTON\n"); printf(" Data (erg/cm^3/s) Stdv (erg/cm^3/s)\n"); printf(" ----------------------------------------------\n"); row = 0; col = 0; for (i=0;i<2816;i++) { real4 = (float *)&line[index1]; data[i] = *real4; real4 = (float *)&line[index2]; stdv[i] = *real4; index1 += 4; index2 += 4; } for (row=0;row<32;row++) for (col=0;col<88;col++) { i = row+32*col; if (data[i] != 0.0 || stdv[i] != 0.0) { printf(" (%2d,%2d) %e %e\n",row,col,data[i],stdv[i]); } } } /* if type is MEP_ELEC_ED */ else if(strcmp(file_type,"HEPS_ELEC_ED")==0) { if(rec ==2) { real4 = (float*)&line[68]; printf(" Deposit Altitude : %f (km)\n",*real4); real4 = (float*)&line[72]; printf(" Dipole Latitude : %f (degrees)\n",*real4); real4 = (float*)&line[76]; printf(" Dipole Longitude : %f (degrees)\n",*real4); int4 = (int*)&line[80]; Actual = *int4; printf(" Number of alphas used : %d\n",Actual); index1=84; printf(" Alpha parameters used \n"); for (i=0;i 0); fclose(data_ifp); }