void mx2cmat(int m, int n, cmulti **A, int LDA, const mxArray *src) { mwSize size[2]={1,1}; mxArray *value=NULL; int i,j,k; for(j=0; j<n; j++){ for(i=0; i<m; i++){ // real part // prec value=mxGetField(src,j*m+i,"r_prec"); if(value!=NULL && mxIsInt64(value)){ rround(C_R(MAT(A,i,j,LDA)),(*(int64_t*)mxGetData(value))); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'prec'."); } // sign value=mxGetField(src,j*m+i,"r_sign"); if(value!=NULL && mxIsInt32(value)){ C_R(MAT(A,i,j,LDA))->_mpfr_sign=(*(int32_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'sign'."); } // exp value=mxGetField(src,j*m+i,"r_exp"); if(value!=NULL && mxIsInt64(value)){ C_R(MAT(A,i,j,LDA))->_mpfr_exp=(*(int64_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'exp'."); } // digits value=mxGetField(src,j*m+i,"r_digits"); if(value!=NULL && mxIsUint64(value)){ for(k=0; k<rget_size(C_R(MAT(A,i,j,LDA))); k++){ C_R(MAT(A,i,j,LDA))->_mpfr_d[k]=((uint64_t*)mxGetData(value))[k]; } } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'digits'."); } // imaginary part // prec value=mxGetField(src,j*m+i,"i_prec"); if(value!=NULL && mxIsInt64(value)){ rround(C_I(MAT(A,i,j,LDA)),(*(int64_t*)mxGetData(value))); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'prec'."); } // sign value=mxGetField(src,j*m+i,"i_sign"); if(value!=NULL && mxIsInt32(value)){ C_I(MAT(A,i,j,LDA))->_mpfr_sign=(*(int32_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'sign'."); } // exp value=mxGetField(src,j*m+i,"i_exp"); if(value!=NULL && mxIsInt64(value)){ C_I(MAT(A,i,j,LDA))->_mpfr_exp=(*(int64_t*)mxGetData(value)); } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'exp'."); } // digits value=mxGetField(src,j*m+i,"i_digits"); if(value!=NULL && mxIsUint64(value)){ for(k=0; k<rget_size(C_I(MAT(A,i,j,LDA))); k++){ C_I(MAT(A,i,j,LDA))->_mpfr_d[k]=((uint64_t*)mxGetData(value))[k]; } } else{ mexErrMsgIdAndTxt("MATLAB:mx2cmat","The arg should be Struct with the feild 'digits'."); } } } return; }
void func_print_cvec(func_t *f) { int i; //printf("complex["); printf("["); for(i=0; i<func_cvec_size(f); i++){ if(cis_real(func_cvec_at(f,i))){ mpfr_printf("%.5Rg",C_R(func_cvec_at(f,i))); }else if(cis_pure_imaginary(func_cvec_at(f,i))){ mpfr_printf("%.5Rg*I",C_I(func_cvec_at(f,i))); }else{ mpfr_printf("%.5Rg%+.5Rg*I",C_R(func_cvec_at(f,i)),C_I(func_cvec_at(f,i))); } if(i<(func_cvec_size(f))-1) printf(" "); } printf("]"); }
int main(void) { int rule = 0; temptype temp = 0; char cont[4]; memset(cont, '\0', 4); printf("Welcome to tempconvert!\n\n"); start: // first of all, show all the menu and shit printf( "Please choose the scale of your current datum.\n" "1)Kelvin\n" "2)Celsius\n" "3)Fahrenheit\n" "4)Rankine\n\n" ); printf( "Please choose the scale you want to convert it to.\n" "5)Kelvin\n" "6)Celsius\n" "7)Fahrenheit\n" "8)Rankine\n\n" ); printf("To exit type \"0\".\n\n"); printf("Now type both selections in order (least to greatest) and press ENTER.\n"); // get the selection scanf("%d", &rule); // check the selection switch(rule) { case 0: return 0; break; case 16: // K to C temp = ask_temp(); // insert here any way to check for the temp entered printf("%.2f K in C is %.2f\n", temp, K_C(temp)); break; case 17: // K to F temp = ask_temp(); printf("%.2f K in F is %.2f\n", temp, K_F(temp)); break; case 18: // K to R temp = ask_temp(); printf("%.2f K in R is %.2f\n", temp, K_R(temp)); break; case 25: // C to K temp = ask_temp(); printf("%.2f C in K is %.2f\n", temp, C_K(temp)); break; case 27: // C to F temp = ask_temp(); printf("%.2f C in ºF is %.2f\n", temp, C_F(temp)); break; case 28: // C to R temp = ask_temp(); printf("%.2f C in R is %.2f\n", temp, C_R(temp)); break; case 35: // F to K temp = ask_temp(); printf("%.2f F in K is %.2f\n", temp, F_K(temp)); break; case 36: // F to C temp = ask_temp(); printf("%.2f F in C is %.2f\n", temp, F_C(temp)); break; case 38: // F to R temp = ask_temp(); printf("%.2f F in R is %.2f\n", temp, F_R(temp)); break; case 45: // R to K temp = ask_temp(); printf("%.2f R in K is %.2f\n", temp, R_K(temp)); break; case 46: // R to C temp = ask_temp(); printf("%.2f R in C is %.2f\n", temp, R_C(temp)); break; case 47: // R to F temp = ask_temp(); printf("%.2f R in F is %.2f\n", temp, R_F(temp)); break; default: // not valid printf("Not a valid option. Bye.\n"); break; } printf("Convert something else? (Y/N): "); scanf("%3s", &cont); if(cont[0] == 'y' || cont[0] == 'Y') { rule = temp = 0; memset(cont, '\0', 4); putchar('\n'); goto start; } return 0; }