/***********************************************************/ /* plot_decade.c */ /* */ /* Code to plot the 'decade of geopotential research' */ /* If needed, please modify the following file */ /* satellites.dat */ /* where name, countries, launch dates and lifetime */ /* are given together with mission type */ /* */ /* To compile type */ /* gcc plot_decade.c -o plot_decade.exe -lm */ /* /* Requires GMT program /* */ /* Benoit Langlais, Sep. 13, 2002, v1.2 */ /* */ /***********************************************************/ /***********************/ /**** include ****/ /***********************/ #include #include #include #include #include int jour_365[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int jour_366[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int main (argc, argv) int argc; char *argv[]; { FILE *fin, *fout; double width, height; int nbr_lines, nbr_sat; char str[200]; char name[30][23], status[30][2]; int an1[30], mois1[30], jour1[30], an2[30], mois2[30], jour2[30]; double date, date_in, datf; double time_deb[30], time_end[30]; int i, j, k; char temp[23], stat[2]; char command[250]; if (argc != 3) { printf("\t plot_decade.exe\n"); printf("\t This code will allow you to plot the figure\n"); printf("\t 'Decade of Geopotential Research' \n"); printf("\t Please check the file 'satellites.dat' in which all information\n"); printf("\t about satellites are given. This code will use gmt commands.\n"); printf("\t The output file will be 'decade.ps'.\n"); printf("\t Please type plot_decade.exe \n"); printf("\t and are in inches and can not exceed 8x10.\n"); printf("\t The code is designed for a max of 30 satellites. Optimal size is:\n"); printf("\t \twidth = 6.5i \n"); printf("\t \theight = nbr_sat / 3 + 1i\n"); printf("\t The information about satellites are in . There \n"); printf("\t are two lines per satellites, the first one contains name and \n"); printf("\t country (only the 23 first characters will be drawn). The second \n"); printf("\t line contains beginning and ending date (year month day) and the\n"); printf("\t mission type: GR is gravimetry\n"); printf("\t AM is absolute magnetics\n"); printf("\t BM is basic magnetics\n"); printf("\t GM is gravi/magnetics\n"); printf("\t Use small letters for planned missions\n"); printf("\t The last line must ended with \\n end-of-line. \n"); printf("\t For any questions contact Benoit Langlais\n"); printf("\t langlais@ltpmail.gsfc,nasa.gov\n"); printf("\t Version date: 09/06/02\n"); exit(-1); } /* Figure size */ width = atof(argv[1]); if (width < 0 || width > 8) { printf("\tBad range for . Please check and try again\n"); exit(-1); } height = atof(argv[2]); if (height < 0 || height > 10) { printf("\tBad range for . Please check and try again\n"); exit(-1); } /* satellites names and dates */ fin = fopen("satellites.dat", "r"); if (fin == NULL) { printf("\tCan not read 'satellites.dat'. Please check and try again\n"); exit(-1); } nbr_lines = 0; while (!feof(fin)) { fgets(str,200,fin); nbr_lines += 1; } nbr_sat = (nbr_lines - 1) / 2; if (2*nbr_sat != nbr_lines-1) { printf("\tError in number of lines in 'satellite.dat'(%d)\n",nbr_lines); printf("\tMust be an odd number. Please check and try again\n"); fclose(fin); exit(-1); } if (nbr_sat >= 30) { printf("\tThe code is not designed for more than 30 satellites.\n"); printf("\tPlease modify the code and try again\n"); exit(-1); } fseek(fin, 0, 0); /* Reading th file */ for (i = 0; i < nbr_sat; i++) { fgets(str,200,fin); for (j = 0 ; j<23 ; j += 1) { if (str[j] != '\n') { name[i][j] = str[j]; } else { for(k=j;k<23;k++) { name[i][k] =' '; } break; } } fscanf(fin, "%d %d %d %d %d %d %s\n", &an1[i], &mois1[i], &jour1[i], &an2[i], &mois2[i], &jour2[i], &status[i]); } /* time (in years) */ for (i = 0; i < nbr_sat; i++) { date = 0.; if (an1[i] % 4 == 0) { for (j = 1 ; j < mois1[i] ; j ++) { date += (double)jour_366[j]; } date = (double)an1[i] + (date + (double)jour1[i]) / 366.; } else { for (j = 1 ; j < mois1[i] ; j ++) { date += (double)jour_365[j]; } date = (double)an1[i] + (date + (double)jour1[i]) / 365.; } time_deb[i] = date; date_in = 0.; if (an2[i] % 4 == 0) { for (j = 1 ; j < mois2[i] ; j ++) { date_in += (double)jour_366[j]; } date_in = (double)an2[i] + (date_in + (double)jour2[i]) / 366.; } else { for (j = 1 ; j < mois2[i] ; j ++) { date_in += (double)jour_365[j]; } date_in = (double)an2[i] + (date_in + (double)jour2[i]) / 365.; } time_end[i] = date_in; } for (i = 0; i < nbr_sat; i++) { printf("%2d : %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c (%7.2lf/%7.2lf)\n", i, name[i][0], name[i][1], name[i][2], name[i][3], name[i][4], name[i][5], name[i][6], name[i][7], name[i][8], name[i][9], name[i][10], name[i][11], name[i][12], name[i][13], name[i][14], name[i][15], name[i][16], name[i][17], name[i][18], name[i][19], name[i][20], name[i][21], name[i][22], time_deb[i], time_end[i]); } for (i = 0; i < nbr_sat; i++) { date = time_deb[i]; datf = time_end[i]; for (k = 0 ; k<23 ; k += 1) temp[k] = name[i][k]; for (k = 0 ; k<2 ; k += 1) stat[k] = status[i][k]; j = i-1; while(j>=0 && time_deb[j] > date) { time_deb[j+1] = time_deb[j]; time_end[j+1] = time_end[j]; for (k = 0 ; k<23 ; k += 1) name[j+1][k] = name[j][k]; for (k = 0 ; k<2 ; k += 1) status[j+1][k] = status[j][k]; j --; } time_deb[j+1] = date; time_end[j+1] = datf; for (k = 0 ; k<23 ; k += 1) name[j+1][k] = temp[k]; for (k = 0 ; k<2 ; k += 1) status[j+1][k] = stat[k]; } /* Plot the yellow frame */ sprintf(command, "gmtset PAGE_COLOR 255/255/255"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2., (11.5 - height) / 2. + 0.5); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + width, (11.5 - height) / 2. + 0.5); fprintf(fout, "%lf %lf\n",(8.5 - width) / 2. + width, (11.5 - height) / 2. + height + 0.5); fprintf(fout, "%lf %lf", (8.5 - width) / 2., (11.5 - height) / 2. + height + 0.5); fclose(fout); /* Plot the basemap */ sprintf(command, "psxy .temp_file -JX8.5i/11i -R0/8.5/0/11 -X0 -Y0 -K -P -L -G255/255/000 > decade.ps"); system(command); sprintf(command, "psbasemap -JX%lfi/%lfi -R1998/2012/-%d/0 -Ba4f2/a1f1Sw -O -G255/255/255 -K -X%lfi -Y%lfi >> decade.ps", width-2.5, height-1., nbr_sat, (8.5 - width) / 2. + 2., (11.5 - height) / 2. + 0.5 +0.5); system(command); sprintf(command, "gmtset TICK_LENGTH 0c"); system(command); /* Plot the grid inside basemap */ sprintf(command, "psbasemap -JX -R -Bg2/g0NE -O -K >> decade.ps"); system(command); sprintf(command, "gmtset TICK_LENGTH 0.2c"); system(command); fout = fopen(".temp_file", "w"); for (i= 1 ; i < nbr_sat ; i ++) { fprintf(fout, "%d %d\n", 1998, -i); fprintf(fout, "%d %d\n", 2012, -i); fprintf(fout, ">\n"); } fclose(fout); sprintf(command, "psxy .temp_file -JX -R -M -W3/000/000/000ta -O -K >> decade.ps\n"); system(command); /* write the satellite names */ fout = fopen(".temp_file", "w"); for (i= 0 ; i < nbr_sat ; i ++) { fprintf(fout, "1997.5 %lf 10 0 1 MR ", (double)-i-0.5); for (j = 2 ; j < 23 ; j ++) { if (name[i][j] == ' ' && name[i][j-1] == ' ' && name[i][j-2] == ' ') { break; } else { fprintf(fout, "%c", name[i][j-2]); } } fprintf(fout, "\n"); } fclose(fout); sprintf(command, "pstext .temp_file -JX -R -N -O -K >> decade.ps\n"); system(command); /* plot the color boxes */ for (i= 0 ; i < nbr_sat ; i ++) { fout = fopen(".temp_file", "w"); if (status[i][0] == 'A' && status[i][1] == 'M') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -G200/000/000 -W2 -O -K >> decade.ps\n"); system(command); } else if (status[i][0] == 'a' && status[i][1] == 'm') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -Gp60/1:F200/000/000B255/255/255 -W2 -O -K >> decade.ps\n"); system(command); } else if (status[i][0] == 'B' && status[i][1] == 'M') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -G000/000/200 -W2 -O -K >> decade.ps\n"); system(command); } else if (status[i][0] == 'b' && status[i][1] == 'm') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -Gp60/1:F000/000/200B255/255/255 -W2 -O -K >> decade.ps\n"); system(command); } else if (status[i][0] == 'G' && status[i][1] == 'R') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -G000/200/000 -W2 -O -K >> decade.ps\n"); system(command); } else if (status[i][0] == 'g' && status[i][1] == 'r') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -Gp60/1:F000/200/000B255/255/255 -W2 -O -K >> decade.ps\n"); system(command); } else if (status[i][0] == 'G' && status[i][1] == 'M') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.5); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.5); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -G200/000/000 -O -K >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.5); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.5); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -G000/200/000 -O -K >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -W2 -O -K -L >> decade.ps\n"); system(command); } else if (status[i][0] == 'g' && status[i][1] == 'm') { fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.5); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.5); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -Gp60/1:F200/000/000B255/255/255 -O -K >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.5); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.5); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -Gp60/1:F000/200/000B255/255/255 -O -K >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.1); fprintf(fout, "%lf %lf\n", time_deb[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.9); fprintf(fout, "%lf %lf\n", time_end[i], (double)-i -0.1); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -W2 -O -K -L >> decade.ps\n"); system(command); } } /* Title */ fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 1.0, (11.5 - height) / 2. + height + 0.5 - 0.2); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + width - 1.0, (11.5 - height) / 2. + height + 0.5 - 0.2); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + width - 1.0, (11.5 - height) / 2. + height + 0.5 + 0.2); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 1.0, (11.5 - height) / 2. + height + 0.5 + 0.2); fclose(fout); sprintf(command, "psxy .temp_file -JX8.5i/11i -R0/8.5/0/11 -X-%lfi -Y-%lfi -O -K -W5 -G255/255/255 -L >> decade.ps\n", (8.5 - width) / 2. + 2., (11.5 - height) / 2. + 0.5 +0.5); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf 20 0 1 MC Decade of Geopotential Research\n", 8.5/2.,(11.5 - height) / 2. + height + 0.5); fclose(fout); sprintf(command, "pstext .temp_file -JX -R -O -K -G200/000/000 >> decade.ps\n"); system(command); /* Legend */ fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.2, (11.5 - height) / 2. + 0.5 - 0.3); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.5, (11.5 - height) / 2. + 0.5 - 0.3); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.5, (11.5 - height) / 2. + 0.5 - 0.5); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.2, (11.5 - height) / 2. + 0.5 - 0.5); fclose(fout); sprintf(command,"psxy .temp_file -JX -R -O -K -W2 -G000/000/200 -L >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf 15 0 1 ML Basic Magnetics (no absolute measurments)\n", (8.5 - width) / 2. + 0.6, (11.5 - height) / 2. + 0.5 - 0.4); fclose(fout); sprintf(command,"pstext .temp_file -JX -R -O -K >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.2, (11.5 - height) / 2. + 0.5 - 0.8); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.5, (11.5 - height) / 2. + 0.5 - 0.8); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.5, (11.5 - height) / 2. + 0.5 - 1.0); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.2, (11.5 - height) / 2. + 0.5 - 1.0); fclose(fout); sprintf(command,"psxy .temp_file -JX -R -O -K -W2 -G200/000/000 -L >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf 15 0 1 ML Absolute Magnetics (with precision attitude determination)\n", (8.5 - width) / 2. + 0.6, (11.5 - height) / 2. + 0.5 - 0.9); fclose(fout); sprintf(command,"pstext .temp_file -JX -R -O -K >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.2, (11.5 - height) / 2. + 0.5 - 1.3); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.5, (11.5 - height) / 2. + 0.5 - 1.3); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.5, (11.5 - height) / 2. + 0.5 - 1.5); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + 0.2, (11.5 - height) / 2. + 0.5 - 1.5); fclose(fout); sprintf(command,"psxy .temp_file -JX -R -O -K -W2 -G000/200/000 -L >> decade.ps\n"); system(command); fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf 15 0 1 ML Gravity / Time-Variable Gravity\n", (8.5 - width) / 2. + 0.6, (11.5 - height) / 2. + 0.5 - 1.4); fclose(fout); sprintf(command,"pstext .temp_file -JX -R -O -K >> decade.ps\n"); system(command); /* Frame */ fout = fopen(".temp_file", "w"); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. - 0.2, (11.5 - height) / 2. + 0.5 - 1.7); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. + width + 0.2, (11.5 - height) / 2. + 0.5 - 1.7); fprintf(fout, "%lf %lf\n",(8.5 - width) / 2. + width + 0.2, (11.5 - height) / 2. + height + 0.5 + 0.2 + 0.2); fprintf(fout, "%lf %lf\n", (8.5 - width) / 2. - 0.2, (11.5 - height) / 2. + height + 0.5 + 0.2 + 0.2); fprintf(fout, "%lf %lf", (8.5 - width) / 2. - 0.2, (11.5 - height) / 2. + 0.5 - 1.7); fclose(fout); sprintf(command, "psxy .temp_file -JX -R -O -W10 >> decade.ps\n"); system(command); sprintf(command, "rm -f .temp_file\n"); /* system(command); */ fclose(fin); }