# include # include /*atoi*/ # include # include # include # include "./codegen/lib/agc/agc.h" char** str_split(char* a_str, const char a_delim) { char** result = 0; size_t count = 0; char* tmp = a_str; char* last_comma = 0; char delim[2]; delim[0] = a_delim; delim[1] = 0; /* Count how many elements will be extracted. */ while (*tmp) { if (a_delim == *tmp) { count++; last_comma = tmp; } tmp++; } /* Add space for trailing token. */ count += last_comma < (a_str + strlen(a_str) - 1); /* Add space for terminating null string so caller * knows where the list of returned strings ends. */ count++; result = malloc(sizeof(char*) * count); if (result) { size_t idx = 0; char* token = strtok(a_str, delim); while (token) { assert(idx < count); *(result + idx++) = strdup(token); token = strtok(0, delim); } assert(idx == count - 1); *(result + idx) = 0; } return result; } int main(int argc, char** argv){ double lambdaCt, betaC, TRagR; real_T agc_, agr_; int i, num_kpn_x, num_kpn_y; char** kpn_x_tokens; char** kpn_y_tokens; if (argc != 6){ printf("Number of arguments is not correct.\n"); printf("Arguments: lambdaCt, kpn_x, kpn_y, betaC, TRagR\n"); return -1; } else { lambdaCt = atof(argv[1]); kpn_x_tokens = str_split(argv[2],' '); kpn_y_tokens = str_split(argv[3],' '); betaC = atof(argv[4]); TRagR = atof(argv[5]); } if(kpn_x_tokens && kpn_y_tokens) { for (i = 0; *(kpn_x_tokens + i); i++) { //printf("month=[%s]\n", *(kpn_x_tokens + i)); //free(*(tokens + i)); } num_kpn_x = i; struct emxArray_real_T *kpn_x; kpn_x = (struct emxArray_real_T*)malloc(sizeof(struct emxArray_real_T)); kpn_x->data = malloc(sizeof(real_T)*num_kpn_x); kpn_x->size = malloc(sizeof(int32_T)*1); kpn_x->allocatedSize = (sizeof(int32_T)*1); kpn_x->size[0] = num_kpn_x; for (i = 0; *(kpn_x_tokens + i); i++) { kpn_x->data[i] = atof(*(kpn_x_tokens + i)); free(*(kpn_x_tokens + i)); } free(kpn_x_tokens); for (i = 0; *(kpn_y_tokens + i); i++) { //printf("month=[%s]\n", *(kpn_y_tokens + i)); } num_kpn_y = i; struct emxArray_real_T *kpn_y; kpn_y = (struct emxArray_real_T*)malloc(sizeof(struct emxArray_real_T)); kpn_y->data = malloc(sizeof(real_T)*num_kpn_y); kpn_y->size = malloc(sizeof(int32_T)*1); kpn_y->allocatedSize = (sizeof(int32_T)*1); kpn_y->size[0] = num_kpn_y; for (i = 0; *(kpn_y_tokens + i); i++) { kpn_y->data[i] = atof(*(kpn_y_tokens + i)); free(*(kpn_y_tokens + i)); } free(kpn_y_tokens); //Call Select_Ground_Motions function, translated with MAtlab Coder agc_initialize(); agc(lambdaCt, kpn_x, kpn_y, betaC, TRagR, &agc_, &agr_); agc_terminate(); printf("%.10f\n", agc_); printf("%.10f\n", agr_); //Clean up free(kpn_x); free(kpn_y); return 0; } else { return -1; } }