| 9 | */ |
| 10 | |
| 11 | int main () { |
| 12 | unsigned int i, m = 128; |
| 13 | double sampling = 1.; |
| 14 | void *API; |
| 15 | struct GMT_DATASET *Din = NULL; |
| 16 | struct GMT_DATASET *Dout = NULL; |
| 17 | struct GMT_DATASEGMENT *S = NULL; |
| 18 | char input[GMT_VF_LEN] = {""}; |
| 19 | char output[GMT_VF_LEN] = {""}; |
| 20 | uint64_t par[] = {1, 1, 512, 1}; |
| 21 | char command[2*GMT_VF_LEN + 64]; |
| 22 | |
| 23 | /* Initialize the GMT session */ |
| 24 | API = GMT_Create_Session ("GMT_spectrum1d", 2, 0, NULL); |
| 25 | /* Create the data */ |
| 26 | Din = GMT_Create_Data (API, GMT_IS_DATASET, GMT_IS_LINE, GMT_CONTAINER_AND_DATA, par, NULL, NULL, 0, -1, NULL); |
| 27 | S = Din->table[0]->segment[0]; |
| 28 | for (i = 0; i < 512; i++) |
| 29 | S->data[0][i] = sin(2.*(double)i) + 2.*cos((double)i); // stupid data, just for testing |
| 30 | /* Open a virtual file to hold the data */ |
| 31 | GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_LINE, GMT_IN, Din, input); |
| 32 | /* Open a virtual file to hold the result */ |
| 33 | GMT_Open_VirtualFile (API, GMT_IS_DATASET, GMT_IS_LINE, GMT_OUT, NULL, output); |
| 34 | /* Create the parameters string */ |
| 35 | sprintf (command, "%s -S%d -D%lf -W -N ->%s", input, 2*m, sampling, output); |
| 36 | /* Call the module */ |
| 37 | GMT_Call_Module (API, "spectrum1d", GMT_MODULE_CMD, command); |
| 38 | /* Free input stuff */ |
| 39 | GMT_Close_VirtualFile (API, input); |
| 40 | GMT_Destroy_Data (API, &Din); |
| 41 | /* Get the spectrum in memory */ |
| 42 | Dout = GMT_Read_VirtualFile (API, output); |
| 43 | /* Close output file */ |
| 44 | GMT_Close_VirtualFile (API, output); |
| 45 | /* Print the result on stdout */ |
| 46 | S = Dout->table[0]->segment[0]; |
| 47 | for (i = 0; i < S->n_rows; i++) |
| 48 | printf("%f %f\n", S->data[0][i], S->data[1][i]); |
| 49 | if (S->n_rows != m) |
| 50 | printf("%d rows (%d expected)\n", (int)S->n_rows, m); |
| 51 | /* Free output */ |
| 52 | GMT_Destroy_Data (API, &Dout); |
| 53 | /* Destroy session */ |
| 54 | if (GMT_Destroy_Session (API)) return EXIT_FAILURE; |
| 55 | } |
nothing calls this directly
no test coverage detected