/* ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc Name : readump_mls_l3lp_data.c Usage : This program reads UARS MLS Level 3LP 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_mls_l3lp_data MLS_L3LP_SPARAM_L3LP_D0030.V0001_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_mls_l3lp_data.c -o readump_mls_l3lp_data executable code will be named readump_mls_l3lp_data cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc */ #include #include main(argc,argv) int argc; char *argv[]; { char line[1000]; char temp[30],data_file[180],str[80]; 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,*real4; float Lat,Lon,LST,SZA; float data[30]; int three_int[3]; static char *Pars[17] = {"COLUMN_O3","COLUMN_O3_SDEV","COLUMN_O3_183", "COLUMN_O3_183_SDEV","COLUMN_O3_205","COLUMN_O3_205_DEV", "PREF","QUALITY_CLO","QUALITY_H2O","QUALITY_O3", "QUALITY_O3_183","QUALITY_O3_205","QUALITY_TEMP", "TNGT_GEOD_ALT_PEFR_MAX","TNGT_GEOD_ALT_PEFR_MIN", "ZREF_GEOPOT","ZREF_GEOM"}; static char *Three_par[3] = {"MANEUVER_STAT","MMAFNO","REF_SOLAR_ILLUM"}; static char *Four_byte[4] = {"FLAG_ASCEND","SCAN_CHANGE","MMAF_STAT", "PAD"}; /* ******* 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); /* 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],20); printf(" Record Key : %s\n",temp); memset(temp,' ',20); 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); printf("-----------------------------\n"); printf(" SFDU T[I] & L[I] \n"); printf("-----------------------------\n"); memset(temp,' ',8); strncpy(temp,&line[40],4); printf(" Control ID : %s\n",temp); memset(temp,' ',8); strncpy(temp,&line[44],1); printf(" Version ID : %s\n",temp); strncpy(temp,&line[45],1); printf(" Class ID : %s\n",temp); strncpy(temp,&line[48],4); printf(" Data descriptive record ID : %s\n",temp); strncpy(temp,&line[52],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],20); printf(" Record Key : %s\n",temp); memset(temp,' ',20); strncpy(temp,&line[20],4); printf(" Satellite ID : %s\n",temp); memset(temp,' ',4); strncpy(temp,&line[24],2); printf(" Record type : %s\n",temp); strncpy(temp,&line[26],12); printf(" Instrument ID : %s\n",temp); strncpy(temp,&line[38],12); printf(" Subtype or Species : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[50],4); printf(" Format version number : %s\n",temp); strncpy(temp,&line[54],8); printf(" Physical record count : %s\n",temp); strncpy(temp,&line[66],8); printf(" Number of physical records in file : %s\n",temp); strncpy(temp,&line[74],23); printf(" File Creation Time in ASCII format : %s\n",temp); memset(temp,' ',23); printf(" Year day Ms for earliest data record : "); strncpy(temp,&line[97],3); sscanf(temp,"%d",&yr); strncpy(temp,&line[100],3); sscanf(temp,"%d",&dy); strncpy(temp,&line[103],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[111],3); sscanf(temp,"%d",&yr); strncpy(temp,&line[114],3); sscanf(temp,"%d",&dy); strncpy(temp,&line[117],8); sscanf(temp,"%d",&ms); printf("%3d %3d %8d\n",yr,dy,ms); memset(temp,' ',14); strncpy(temp,&line[125],3); printf(" Data level : %s\n",temp); strncpy(temp,&line[128],4); printf(" UARS day number : %s\n",temp); strncpy(temp,&line[132],4); printf(" Max. number of 32-bit words per record : %s\n",temp); strncpy(temp,&line[140],5); printf(" Record length in bytes : %s\n",temp); strncpy(temp,&line[145],6); printf(" Min/Max Latitude : %s\n",temp); strncpy(temp,&line[151],9); printf(" CCB version number : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[160],5); printf(" File cycle number : %s\n",temp); memset(temp,' ',12); strncpy(temp,&line[165],1); printf(" Virtual file flag : %s\n",temp); strncpy(temp,&line[166],4); printf(" Total number of time/version in file : %s\n",temp); strncpy(temp,&line[170],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],20); printf(" Record Key : %s \n",temp); memset(temp,' ',20); strncpy(temp,&line[20],4); printf(" Satellite ID : %s\n",temp); memset(temp,' ',8); strncpy(temp,&line[24],2); printf(" Record type : %s\n",temp); strncpy(temp,&line[26],12); printf(" Instrument ID : %s\n",temp); strncpy(temp,&line[38],10); printf(" Physical record count : %s\n",temp); memset(temp,' ',10); int4 = (int *)&line[48]; Total = *int4; printf(" Total number of points in record : %d\n",Total); int4 = (int *)&line[52]; Actual = *int4; /* printf(" Number of actual points : %d\n",Actual); */ int4 = (int *)&line[56]; printf(" Starting index of first actual point : %d\n",*int4); int4 = (int *)&line[60]; T1 = *int4; int4 = (int *)&line[64]; T2 = *int4; printf(" UDTF time : %d %d (year day, milliseconds)\n",T1,T2); real4 = (float *)&line[68]; Lat = *real4; printf(" Latitude : %f (degress)\n",Lat); real4 = (float *)&line[72]; Lon = *real4; printf(" Longitude : %f (degress)\n",Lon); int4 = (int *)&line[84]; Par_numb = *int4; printf(" Number of 32-bit Parameter words : %d\n",Par_numb); index = 88; for (i=0;i<17;i++) { real4 = (float *)&line[index]; data[i] = *real4; index += 4; } for (i=0;i<6;i++) { if (data[i] < -99.0) printf(" %-23s: %f (not retrived)\n",Pars[i],data[i]); else printf(" %-23s: %f (Dobson units)\n",Pars[i],data[i]); } printf(" %-23s: %f (-log(hPa))\n",Pars[6],data[6]); for (i=7;i<13;i++) { if (data[i] > 0) printf(" %-23s: %f (see MLS L3LP SFDU section 4.14)\n",Pars[i],data[i]); else printf(" %-23s: %f (not retrived)\n",Pars[i],data[i]); } for (i=13;i<17;i++) printf(" %-23s: %f (km)\n",Pars[i],data[i]); for (i=0;i<3;i++) { int4 = ( int*)&line[index]; three_int[i] = *int4; /* printf(" %-23s: %d\n",Three_par[i],three_int[i] ); */ index +=4; } switch(three_int[0]) { case 0: printf(" %-23s: %d (no maneuver)\n",Three_par[0],three_int[0]); break; case 1: printf(" %-23s: %d (orbit)\n",Three_par[0],three_int[0]); break; case 2: printf(" %-23s: %d (yaw maneuver)\n",Three_par[0],three_int[0]); break; case 3: printf(" %-23s: %d (roll maneuver)\n",Three_par[0],three_int[0]); break; case 4: printf(" %-23s: %d (other maneuver)\n",Three_par[0],three_int[0]); break; } printf(" %-23s: %d ",Three_par[1],three_int[1]); printf(" (see MLS L3LP SFDU section 4.14)\n"); switch(three_int[2]) { case 0: printf(" %-23s: %d ",Three_par[2],three_int[2]); printf(" (unable to determine condition) \n"); break; case 1: printf(" %-23s: %d (day exclusive of twilight)\n",Three_par[2], three_int[2]); break; case 2: printf(" %-23s: %d (night exclusive of twilight)\n",Three_par[2], three_int[2]); break; case 3: printf(" %-23s: %d (twilight, sunrise)\n",Three_par[2],three_int[2]); break; } printf(" %-23s: %X (see MLS L3LP SFDU section 4.14)\n",Four_byte[0], line[168]); printf(" %-23s: %X (see MLS L3LP SFDU section 4.14)\n",Four_byte[1], line[169]); printf(" %-23s: %c (see MLS L3LP SFDU section 4.14)\n",Four_byte[2], line[170]); rec++; } /* if ret != EOF */ } while (ret > 0); fclose(data_ifp); }