# include # include /*atoi*/ # include # include # include "./codegen/lib/Select_Ground_Motions/Select_Ground_Motions.h" int main(int argc, char** argv) { double nGM, T1, T1dej, ecSoilCode, isScaled, maxScale, weight_mean, weight_sd, nLoop, penalty, seedValue, M_bar, R_bar, eps_bar, nX, useVar; int i, j, countRSN, countPeriods; FILE *fileIn, *fileOut; char *cwd, *fileInName; char buff[PATH_MAX+1]; real_T errCode; // Open fileOut for writeing fileOut = fopen("sgm.out", "w"); // Check number of input arguments if (argc != 17) { fprintf(fileOut,"%i\n",3388); fprintf(fileOut,"Number of arguments is not correct.\n"); fprintf(fileOut,"Arguments: nGM, T1, T1dej, ecSoilCode(1,2,3,4), isScaled, maxScale, weight_mean, weight_sd, nLoop, penalty, seedValue, M_bar, R_bar, eps_bar, nX, useVar\n"); printf("Number of arguments is not correct.\n"); printf("Arguments: nGM, T1, T1dej, ecSoilCode(1,2,3,4), isScaled, maxScale, weight_mean, weight_sd, nLoop, penalty, seedValue, M_bar, R_bar, eps_bar, nX, useVar\n"); return -1; } else { nGM = atof(argv[1]); T1 = atof(argv[2]); T1dej = atof(argv[3]); ecSoilCode = atof(argv[4]); isScaled = atof(argv[5]); maxScale = atof(argv[6]); weight_mean = atof(argv[7]); weight_sd = atof(argv[8]); nLoop = atof(argv[9]); penalty = atof(argv[10]); seedValue = atof(argv[11]); M_bar = atof(argv[12]); R_bar = atof(argv[13]); eps_bar = atof(argv[14]); nX = atof(argv[15]); useVar = atof(argv[16]); } // Allocate memory for output emxArray_real_T *finalRecords; emxArray_real_T *finalDirections; emxArray_real_T *finalScaleFactors; emxArray_real_T *F_x; emxArray_real_T *F1_y1; emxArray_real_T *F1_y1a; emxArray_real_T *F1_y2; emxArray_real_T *F1_y3; emxArray_real_T *F1_yn; emxArray_real_T *F2_y1; emxArray_real_T *F3_y1; emxArray_real_T *F3_y2; emxArray_real_T *F4_y1; emxArray_real_T *F5_y1; emxArray_real_T *F6_y1; emxArray_real_T *F7_y1; emxInitArray_real_T(&finalRecords, 1); emxInitArray_real_T(&finalDirections, 1); emxInitArray_real_T(&finalScaleFactors, 1); emxInitArray_real_T(&F_x, 2); emxInitArray_real_T(&F1_y1, 2); emxInitArray_real_T(&F1_y1a, 2); emxInitArray_real_T(&F1_y2, 2); emxInitArray_real_T(&F1_y3, 2); emxInitArray_real_T(&F1_yn, 2); emxInitArray_real_T(&F2_y1, 2); emxInitArray_real_T(&F3_y1, 2); emxInitArray_real_T(&F3_y2, 2); double F4_x1[501]; emxInitArray_real_T(&F4_y1, 2); emxInitArray_real_T(&F5_y1, 2); emxInitArray_real_T(&F6_y1, 2); emxInitArray_real_T(&F7_y1, 2); // Open input 'data.bin' binary file cwd = getcwd(buff, PATH_MAX+1); fileInName = strcat(cwd, "/data.bin"); if(access(fileInName, F_OK) != -1) { fileIn = fopen(fileInName, "rb"); } else { fprintf(fileOut,"%i\n",3387); fprintf(fileOut,"Can not find input file 'data.bin'"); printf("Can not find input file 'data.bin'\n"); return -1; } // Read number of records and periods if(!fread(&countRSN, 4, 1, fileIn)) { fprintf(fileOut,"%i\n",3386); fprintf(fileOut,"Error while reading file 'data.bin'"); printf("Error while reading file 'data.bin'"); return -1; } if(!fread(&countPeriods, 4, 1, fileIn)) { fprintf(fileOut,"%i\n",3386); fprintf(fileOut,"Error while reading file 'data.bin'"); printf("Error while reading file 'data.bin'"); return -1; } // Allocate memory for input based on number of records and periods struct emxArray_real_T *idRef; idRef = (struct emxArray_real_T*)malloc(sizeof(struct emxArray_real_T)); idRef->data = malloc(sizeof(real_T)*countRSN); idRef->size = malloc(sizeof(int32_T)*1); idRef->allocatedSize = (sizeof(int32_T)*1); idRef->size[0] = countRSN; struct emxArray_real_T *Sa_1; Sa_1 = (struct emxArray_real_T*)malloc(sizeof(struct emxArray_real_T)); Sa_1->data = malloc(sizeof(real_T)*countRSN*countPeriods); Sa_1->size = malloc(sizeof(int32_T)*2); Sa_1->allocatedSize = (sizeof(int32_T)*1); Sa_1->size[0] = countRSN; Sa_1->size[1] = countPeriods; struct emxArray_real_T *Sa_2; Sa_2 = (struct emxArray_real_T*)malloc(sizeof(struct emxArray_real_T)*1); Sa_2->data = (real_T*)malloc(sizeof(real_T)*countRSN*countPeriods); Sa_2->size = malloc(sizeof(int32_T)*2); Sa_2->allocatedSize = (sizeof(int32_T)*1); Sa_2->size[0] = countRSN; Sa_2->size[1] = countPeriods; struct emxArray_real_T *sVs30; sVs30 = (struct emxArray_real_T*)malloc(sizeof(struct emxArray_real_T)); sVs30->data = malloc(sizeof(real_T)*countRSN); sVs30->size = malloc(sizeof(int32_T)*1); sVs30->allocatedSize = (sizeof(int32_T)*1); sVs30->size[0] = countRSN; // Store idReference data from binary to array for(i=0; idata[i], sizeof(real_T), 1, fileIn)) { fprintf(fileOut,"%i\n",3386); fprintf(fileOut,"Error while reading file 'data.bin'"); printf("Error while reading file 'data.bin'"); return -1; } } // Store Sa_1 data from binary to array and transpose the data for(i=0; idata[countRSN*j+i], sizeof(real_T), 1, fileIn)) { fprintf(fileOut,"%i\n",3386); fprintf(fileOut,"Error while reading file 'data.bin'"); printf("Error while reading file 'data.bin'"); return -1; } } } // Store Sa_2 data from binary to array and transpose the data for(i=0;idata[countRSN*j+i], sizeof(real_T), 1, fileIn)) { fprintf(fileOut,"%i\n",3386); fprintf(fileOut,"Error while reading file 'data.bin'"); printf("Error while reading file 'data.bin'"); return -1; } } } // Store sVs30 data from binary to array for(i=0; idata[i], sizeof(real_T), 1, fileIn)) { fprintf(fileOut,"%i\n",3386); fprintf(fileOut,"Error while reading file 'data.bin'"); printf("Error while reading file 'data.bin'"); return -1; } } // Close input file fclose(fileIn); // Call Select_Ground_Motions function, translated with Matlab Coder Select_Ground_Motions_initialize(); Select_Ground_Motions( idRef, Sa_1, Sa_2, sVs30, nGM, T1, T1dej, ecSoilCode, isScaled, maxScale, weight_mean, weight_sd, nLoop, penalty, seedValue, M_bar, R_bar, eps_bar, nX, useVar, finalRecords, finalDirections, finalScaleFactors, F_x, F1_y1, F1_y1a, F1_y2, F1_y3, F1_yn, F2_y1, F3_y1, F3_y2, F4_x1, F4_y1, F5_y1, F6_y1, F7_y1, &errCode); Select_Ground_Motions_terminate(); // Check for errors and output them to fileOut if(errCode==3390 || errCode==3391) { fprintf(fileOut, "%d", (int)floor(errCode)); return 1; } if(errCode==3389) { fprintf(fileOut, "%d", (int)floor(errCode)); } fprintf(fileOut, "\n"); // Output results for(i=0; isize[0]; i++) { fprintf(fileOut, "%d,%d,%.4f^", (int)floor(finalRecords->data[i]), (int)floor(finalDirections->data[i]), finalScaleFactors->data[i] ); } fprintf(fileOut, "\n"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F_x->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F1_y1->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F1_y1a->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F1_y2->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F1_y3->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[0]; i++) { for(j=0; jsize[1]; j++) { fprintf(fileOut, "%.10f,", F1_yn->data[F1_yn->size[0]*j+i]); } fprintf(fileOut, "%s", "~"); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F2_y1->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F3_y1->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F3_y2->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[0]; i++) { for(j=0; jsize[1]; j++) { fprintf(fileOut, "%.10f,", F4_y1->data[F4_y1->size[0]*j+i]); } fprintf(fileOut, "%s", "~"); } fprintf(fileOut, "%s", "^"); for(i=0; isize[0]; i++) { for(j=0; jsize[1]; j++) { fprintf(fileOut, "%.10f,", F5_y1->data[F5_y1->size[0]*j+i]); } fprintf(fileOut, "%s", "~"); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F6_y1->data[i]); } fprintf(fileOut, "%s", "^"); for(i=0; isize[1]; i++) { fprintf(fileOut, "%.10f,", F7_y1->data[i]); } fprintf(fileOut, "%s", "^"); // Close fileOut fclose(fileOut); // Clean up free(finalRecords); free(finalScaleFactors); free(Sa_1); free(Sa_2); free(sVs30); return 0; }