/************************************************************************************** * * * FILE: read_larc8_lidar Date: 8/14/94 * * VERSION:1.00 * * * * AUTHOR: Mandira Mukherjee, Langley DAAC * * * * PURPOSE/DESCRIPTION: * * * * This program reads the Langley Research center Cloud Lidar (LaRC-CL), its * * participation in the 1991 FIRE Intensive Field Observation (IFO)the resulting * * archive data product. The datafiles in larc8_lidar dataset are in ASCII format. Each* * file consists of a series of data records acquired during a single GMT day. For each* * data record there is a header section (140 bytes) followed by two simultaneously * * acquired arrays of digitized lidar backscatter data. The first array contains * * parallel channel data, and the second contains perpendicular channel data. The read * * program reads the header information from the datafile and assigns the Field * * Identifiers to the values. It stores the data according to the users request. The * * code currently offers the user to choose the data from P_DETECTOR (PARALLEL CHANNEL * * DATA) or S_DETECTOR (PERPENDICULAR CHANNEL DATA) or from BOTH DETECTORS (PARALLEL * * AND PERPENDICULAR CHANNEL DATA).If choosen P_DETECTOR please enter "P" or "p" else * * if choosen S_DETECTOR please enter "S" or "s" else if choosen BOTH DETECTORS please * * enter "A" or "a". The ouput can be directed to a file typing * * * * * * read_larc8_lidar datafilename > any_file_name * * P or S or A (for desired channel data) * * * * will read the binary data from the datafile and create the given filename. * * * * read_larc8_lidar datafilename * * * * will read the binary data file according to the user request input and send the * * output to the screen. * **************************************************************************************/ #include #include #include #include #include #include #include #define RECSIZE 80 main (argc,argv) int argc; char *argv[]; { void Print_heading(); /* Prints the header for read program */ void Get_input(); /* Get input filename*/ void Get_par_type(); /* Get input (p) (s) (a) from the detectors */ char buf[256]; /* Buffer to read in strings at atime */ /*char Ibuf[256];*/ char filename1[MAXPATHLEN+1], /* filename for first argument variable */ data_file[MAXPATHLEN+1], /* created data file */ par_type[10]; /* parameter type (p) (s) (a) */ int datapt, /* number of datapoints (2335) */ date, /* date data was collected */ sttm, /* start time */ endtm, /* end time */ recnum, /* record number */ latdeg, /* latitude in degrees */ latmin, /* latitude in minutes */ latsec, /* latitude in seconds */ londeg, /* longitude in degrees */ lonmin, /* longitude in minutes */ lonsec; /* longitude in seconds */ int l,i,n,k,k1,w,w1,j,iret,iret2; /* counters */ int ht, /* height above sealevel */ lid_id, /* in-house for lidar system used */ wv_ln, /* Wave length */ fi_vi, /* Field of view */ sa_ra, /* sample rate */ ti_an, /* tilt angle */ P_back, /* P back ground */ S_back, /* S back ground */ sh_avg; /* shots average */ int m, P_ba_wi, /* P detector band width */ P_del_tm, /* P detector delay time */ P_P1, /* Photo multiplier voltage */ P_P2, /* Gain associated amplification stage */ P_P3; /* P3 p detector unassigned field */ int S_ba_wi, /* S detector band width */ S_del_tm, /* S detector delay time */ S_P1, /* S detector photomultiplier voltage */ S_P2, /* S detector gain associated amplification stage */ S_P3; /* S detector P3 unassigned field */ int *P_ch_dat, /* memory allocated for P channel */ *S_ch_dat, /* memory allocated for S channel */ *A_ch_dat; /* memory allocated for both channels */ float ga_ra, /* gain ratio */ of_an, /* offset angle */ ca_an; /* calibration angle */ char *token; /* info or data being stored in loop */ FILE *fptr; /* file pointer */ /***********************************************************************************/ (void) Print_heading(); /*if(argc == 1) (void) Get_input(data_file);*/ (void) Get_par_type(par_type); printf("PARAMETER NAME REQESTED IS %s\n",par_type); strcpy(data_file,argv[1]); printf("DATA FILENAME REQESTED IS %s\n",data_file); if ((fptr = fopen (data_file,"r"))==NULL) { printf("*************************************************************\n"); printf("*ERROR-UNABLE TO OPEN THE DATA FILE. PROGRAM HAS BEEN TERMINATED\n"); printf("*****************************************************************\n"); exit (-1); } while((feof(fptr))==0) { for (n = 0;(n < 3); n++) { fgets (buf,80,fptr); printf ("\n"); if ((feof(fptr)!= 0)) { printf("\n\n\n"); printf("----------------------------------------------\n"); printf("*THE END OF FILE HAS BEEN REACHED \n"); printf("*THIS IS A NORMAL TERMINATION. \n"); printf("-----------------------------------------------\n"); exit(0); } /* printf ("\n\n %s\n",buf);*/ if(n == 0) { i = 0; { token = strtok(buf, ","); while (token != NULL) { i++ ; /*printf("Token %d = %s\n",i,token);*/ if (i==1) { datapt = atoi(token); printf("DATA POINTS = %d\n",datapt); } else if (i==2) { date = atoi(token); printf("DATE = %d\n",date); } else if(i == 3) { sttm = atoi(token); printf("START TIME = %d\n",sttm); } else if(i == 4) { endtm = atoi(token); printf("END TIME = %d\n",endtm); } else if (i == 5) { recnum = atoi(token); printf ("RECORD NUMBER = %d\n",recnum); } else if ( i == 6) { latdeg = atoi(token); printf("LATITUDE DEGREE = %d\n",latdeg); } else if (i == 7) { latmin = atoi(token); printf ("LATITUDE MINUTES = %d\n",latmin); } else if (i == 8) { latsec = atoi(token); printf("LATITUDE SECONDS = %d\n",latsec); } else if ( i == 9) { londeg = atoi(token); printf("LONGITUDE DEGREE = %d\n",londeg); } else if (i == 10) { lonmin = atoi(token); printf("LONGITUDE MINUTES = %d\n",lonmin); } else if ( i == 11) { lonsec = atoi(token); printf("LONGITUDE SECONDS = %d\n",lonsec); } token = strtok(NULL,","); } } } /* end of i loop */ else if (n == 1) { l =0; { token = strtok(buf, ","); while (token != NULL) { l++; /*printf("Token %d = %s\n",l,token);*/ if (l ==1) { ht = atoi(token); printf("HEIGHT ABOVE SEA LEVEL = %d\n",ht); } else if (l == 2) { lid_id = atoi(token); printf("IN-HOUSE FOR LIDAR SYSTEM USED = %d\n",lid_id); } else if ( l == 3) { wv_ln = atoi(token); printf("WAVE LENGTH = %d\n",wv_ln); } else if (l == 4) { fi_vi = atoi(token); printf("FIELD OF VIEW = %d\n",fi_vi); } else if ( l== 5) { sa_ra = atoi(token); printf("SAMPLE RATE = %d\n",sa_ra); } else if(l == 6) { ga_ra = atof(token); printf("GAIN RATIO = %3.3f\n",ga_ra); } else if (l == 7) { of_an = atof(token); printf("OFFSET ANGLE = %3.3f\n",of_an); } else if (l ==8) { ca_an = atof(token); printf("CALIBRATION ANGLE = %3.3f\n",ca_an); } else if ( l == 9) { ti_an = atoi(token); printf("TILT ANGLE = %d\n",ti_an); } else if ( l == 10) { P_back = atoi(token); printf("P_BACK GROUND = %d\n",P_back); } else if ( l == 11) { S_back = atoi(token); printf("S_BACK GROUND = %d\n",S_back); } else if ( l == 12) { sh_avg = atoi(token); printf("SHOTS AVERAGED = %d\n",sh_avg); } token = strtok(NULL,","); } } } /* end of l loop */ else if( n == 2) { m = 0; { token = strtok(buf, ","); while (token != NULL) { m++; /*printf("Token %d = %s\n",m,token);*/ if ( m == 1) { P_ba_wi = atoi(token); printf("P_DETECTOR BAND WIDTH = %d\n",P_ba_wi); } else if ( m == 2) { P_del_tm = atoi(token); printf("P_DETECTOR DELAY TIME = %d\n",P_del_tm); } else if ( m == 3) { P_P1 = atoi(token); printf("PHOTOMULTIPLIER VOLTAGE = %d\n",P_P1); } else if ( m == 4) { P_P2 = atoi(token); printf("GAIN ASSOC. AMPLIFICATION STAGE = %d\n",P_P2); } else if ( m == 5) { P_P3 = atoi(token); printf("P3 UNASSIGNED FIELD = %d\n",P_P3); } else if ( m == 6) { S_ba_wi = atoi(token); printf("S_DETECTOR BAND WIDTH = %d\n",S_ba_wi); } else if ( m == 7) { S_del_tm = atoi(token); printf("S_DETECTOR DELAY TIME = %d\n",S_del_tm); } else if ( m == 8) { S_P1 = atoi(token); printf("S_DETECTER PHOTOMULTIPLIER VOLTAGE = %d\n",S_P1); } else if ( m == 9) { S_P2 = atoi(token); printf("S_P2 GAIN ASSOC. AMPLIFICATION STAGE = %d\n",S_P2); } else if ( m == 10) { S_P3 = atoi(token); printf("S_DET P3 UNASSIGNED FIELD = %d\n\n",S_P3); } token = strtok(NULL,","); } } } /* end of m loop*/ } /*end of for */ k1 = 0; if (par_type[0] == 'P' || par_type[0] == 'p') { P_ch_dat = (int *)malloc(sizeof(int)*datapt); } else if(par_type[0] == 'S' || par_type[0] == 's') { S_ch_dat = (int *)malloc(sizeof(int)*datapt); } else { A_ch_dat = (int *)malloc(sizeof(int)*datapt*3); } for (j =0; (j < datapt+1);j++) { fgets(buf,80,fptr); /*printf("\n%s\n",buf);*/ k = 0; { token = strtok(buf, ","); while (token != NULL) { k++; k1++; /* printf("Token %d = %s\n",k1,token);*/ if (( k == 1) && (par_type[0] == 'P' || par_type[0] == 'p')) { P_ch_dat[j] = atoi(token); } else if ((k == 2) && (par_type[0] == 'S' || par_type[0] == 's')) { S_ch_dat[j] = atoi(token); } else if ((par_type[0] == 'A' || par_type[0] == 'a')&&(j!=datapt)) { A_ch_dat[k1] = atoi(token); } token = strtok(NULL,","); } } } /* initialize k loop */ iret = 0; iret2 =0; printf("DATA POINTS D A T A V A L U E S \n"); for (w=0;w