/* cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc Name : readump_l3asbs_data.c Usage : This program reads UARS level 3BS data files distributed from the GSFC DAAC. To run this program, type the program name followed by the metadata file name (*META extension). Example: readump_l3asbs_data SOLSTICE_L3BS_D0172.V0005_C01_META Description : This program first opens the metadata file (*.*META) to get the data file name (*.*PROD), and its physical record size. The data file is then opened, and its contents are read and dumped to the screen. Author : KE - JUN SUN Hughes_STX Date : February 2, 1994 Limitations : This program and the data it reads are designed for machines running a UNIX operating system, and having 32-bit architecture. IEEE floating point and/or integer values will not translate correctly on other machines! Notes : Since this program uses the metadata file (*.*META) to get the data file name (*.*PROD) and record size, both the data file and its corresponding metadata file must be in the same directory. Algorithm information : No calculation is performed in this program. Version : 0 To compile this progam : cc readump_l3asbs_data.c -o readump_l3asbs_data executable code will be named readump_l3asbs_data ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc */ #include #include main(argc,argv) int argc; char *argv[]; { char line[5000]; char temp[30],str[80],data_file[180]; int index,i,n,ret,rec,select,rec_size,*int4; int Total,Actual,T1,T2,Numb,Par_numb,yr,dy,ms; FILE *meta_ifp,*data_ifp; float Lat,Lon,LST,SZA,WVLEN; float data[400],quality[400],*real4; char par_name[21], par_value[21]; /* ****** 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); /* 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); strncpy(temp,&line[16],5); /* get record size from meta file */ 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 %s\n",data_file); 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(" 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); fread(line,1,rec_size,data_ifp); printf("-----------------------------\n"); printf(" Label record \n"); printf("-----------------------------\n"); memset(temp,' ',8); 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],12); printf(" Data 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); memset(temp,' ',8); strncpy(temp,&line[42],4); printf(" Number of continuation records for file label :%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); strncpy(temp,&line[77],14); printf(" Year day Ms for 1st data record : %s\n",temp); strncpy(temp,&line[91],14); printf(" Year day Ms for last data record : %s\n",temp); memset(temp,' ',20); 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(" Number of data points per record : %s\n",temp); strncpy(temp,&line[116],6); sscanf(temp,"%s",temp); printf(" Base wavelength of data point value : %s (nm)\n",temp); memset(temp,' ',12); strncpy(temp,&line[122],5); printf(" Record length in bytes : %s\n",temp); strncpy(temp,&line[127],9); printf(" CCB version number : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[136],5); printf(" File cycle number : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[141],1); printf(" Virtual file flag : %s\n",temp); strncpy(temp,&line[142],4); printf(" Total number of time/version in file : %s\n",temp); strncpy(temp,&line[146],4); printf(" Number of time/version in record : %s\n",temp); memset(temp,' ',20); rec = 2; do { 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(" Total number of points in the record : %d\n",Total); int4 = (int *)&line[32]; Actual = *int4; printf(" Number of actual points : %d\n",Actual); real4 = (float *)&line[36]; WVLEN = *real4; printf(" Starting wavelength of 1st actual point : %f (nm)\n",WVLEN); int4 = (int *)&line[40]; T1 = *int4; int4 = (int *)&line[44]; T2 = *int4; printf(" UDTF time : %d %d (year day, milliseconds)\n\n",T1,T2); index = 64; for (i=0;i -3.4e38 && data[i] < 3.4e38) printf("%4d) %e %e \n",i,data[i],quality[i]); else printf("%4d) *** Fill value *** \n",i); } printf("\n"); int4 = (int*)&line[index]; Par_numb = *int4; printf(" Number of parameter pairs : %d\n",Par_numb); index += 4; printf("\n"); printf(" Parameter Name Parameter Value\n"); for (i=0;i 0 && i <= 10) printf("%s (watt/m^3)(nm)\n",par_value); else if (i >= 11 && i <= 14) printf("%s (nm)\n",par_value); else printf("%s (degrees)\n",par_value); index += 40; } rec++; } /* if ret != EOF */ } while (ret > 0); fclose(data_ifp); }