int AmbaEncPage_process_PostData (Page * currentPage) { int ret = 0; AmbaTransfer transfer; Message msg; transfer_init(&transfer); int i = 0; int req_cnt = get_value(postInfo, "req_cnt"); int req = 0; int info = 0; int data = 0; char buffer[SHORTLEN] = {0}; char* postInfo_buf = NULL; postInfo_buf = strstr(postInfo, "req_cnt"); if (postInfo_buf != NULL) { for(i = 0; i < req_cnt; i++) { if ((strstr(postInfo, "sec") != NULL) && (strstr(postInfo, "data") != NULL)) { char* string_buffer = NULL; string_buffer = (char *)malloc(MSG_INFO_LEN); if (string_buffer == NULL) { LOG_MESSG("EncPage post data error"); return -1; } memset(string_buffer, 0, MSG_INFO_LEN); url_decode(string_buffer, postInfo_buf, strlen(postInfo_buf)); memset(&msg, 0, sizeof(Message)); parse_postSec(string_buffer, &msg, i); parse_postData(string_buffer, &msg, i); ret = transfer.send_set_request(REQ_SET_PARAM, ENCODE_PORT, msg); if (ret < 0) { return -1; } free(string_buffer); string_buffer = NULL; } else if ((strstr(postInfo,"req") != NULL)&&(strstr(postInfo,"info") != NULL)){ memset(buffer, 0, SHORTLEN); sprintf(buffer, "req%d", i); req = get_value(postInfo, buffer); memset(buffer, 0, SHORTLEN); sprintf(buffer, "info%d", i); info = get_value(postInfo, buffer); memset(buffer, 0, SHORTLEN); sprintf(buffer, "data%d", i); data = get_value(postInfo, buffer); ret = transfer.send_fly_request(req, info, data); if (ret != 0) { return -1; } } return 0; } } return 1; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (primordial_init(&pr,&pt,&pm) == _FAILURE_) { printf("\n\nError in primordial_init \n=>%s\n",pm.error_message); return _FAILURE_; } if (nonlinear_init(&pr,&ba,&th,&pt,&pm,&nl) == _FAILURE_) { printf("\n\nError in nonlinear_init \n=>%s\n",nl.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&nl,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } /****** output the transfer functions ******/ printf("Output of transfer functions (l, q, k, nu, Delta)\n"); printf("(in flat space, q=k and nu=inf) \n"); /* 1) select the mode, initial condition, type and multipole of the function you want to plot: */ int index_mode=pt.index_md_scalars; int index_ic =pt.index_ic_ad; int index_type=tr.index_tt_t0; /* 2) here is an illustration of how to output the transfer functions at some (k,l)'s of your choice */ /* int index_l = 0; double q=3.6e-4; double transfer; if (transfer_functions_at_q(&tr, index_mode, index_ic, index_type, index_l, q, &transfer ) == _FAILURE_) { printf("\n\nError in transfer_function_at_k \n=>%s\n",tr.error_message); return _FAILURE_; } printf("%d %e %e\n",tr.l[index_l],q,transfer); */ /* 3) here you can output the full tabulated arrays for all k and l's*/ int index_q; int index_l; double transfer; FILE * output; output=fopen("output/test.trsf","w"); for (index_l=0; index_l<tr.l_size[index_mode]; index_l++) { for (index_q=0; index_q<tr.q_size; index_q++) { /* use this to plot a single type : */ transfer = tr.transfer[index_mode] [((index_ic * tr.tt_size[index_mode] + index_type) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q]; /* or use this to plot the full temperature transfer function: */ /* transfer = tr.transfer[index_mode][((index_ic * tr.tt_size[index_mode] + tr.index_tt_t0) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q] + tr.transfer[index_mode][((index_ic * tr.tt_size[index_mode] + tr.index_tt_t1) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q] + tr.transfer[index_mode][((index_ic * tr.tt_size[index_mode] + tr.index_tt_t2) * tr.l_size[index_mode] + index_l) * tr.q_size + index_q]; */ if (transfer != 0.) { fprintf(output,"%d %e %e %e %e\n", tr.l[index_l], tr.q[index_q], tr.k[index_mode][index_q], tr.q[index_q]/sqrt(ba.sgnK*ba.K), transfer); } } fprintf(output,"\n\n"); //} } fclose(output); /****** all calculations done, now free the structures ******/ if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (nonlinear_free(&nl) == _FAILURE_) { printf("\n\nError in nonlinear_free \n=>%s\n",nl.error_message); return _FAILURE_; } if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct lensing le; /* for lensing spectra */ struct output op; /* for output files */ struct spectra_nl nl; /* for calculation of non-linear spectra */ ErrorMsg errmsg; if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&le,&op,&nl,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&bs,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } if (primordial_init(&pr,&pt,&pm) == _FAILURE_) { printf("\n\nError in primordial_init \n=>%s\n",pm.error_message); return _FAILURE_; } if (spectra_init(&ba,&pt,&tr,&pm,&sp) == _FAILURE_) { printf("\n\nError in spectra_init \n=>%s\n",sp.error_message); return _FAILURE_; } if (output_init(&ba,&pt,&sp,&op) == _FAILURE_) { printf("\n\nError in output_init \n=>%s\n",op.error_message); return _FAILURE_; } /****** done ******/ int index_mode=0; int index_eta; int index_ic=0; int index_k; double delta_rho_bc,rho_bc; double delta_i,rho_i; double P_bc; int last_index_back; double * pvecback_long; double k,pk; FILE * output; double z,eta; double * tki; if(pt.has_matter_transfers == _FALSE_) { printf("You need to switch on mTk calculation for this code\n"); return _FAILURE_; } output=fopen("output/Pcb.dat","w"); class_alloc(pvecback_long,sizeof(double)*ba.bg_size,errmsg); class_alloc(tki,sizeof(double)*sp.ln_k_size*sp.tr_size,errmsg); z=0.; if(background_eta_of_z(&ba,z,&eta) == _FAILURE_) { printf("\n\nError running background_eta_of_z \n=>%s\n",ba.error_message); return _FAILURE_; } if(background_at_eta(&ba, eta, long_info, normal, &last_index_back, pvecback_long) == _FAILURE_) { printf("\n\nError running background_at_eta \n=>%s\n",ba.error_message); return _FAILURE_; } if (spectra_tk_at_z(&ba,&sp,z,tki) == _FAILURE_) { printf("\n\nError in spectra_tk_at_z \n=>%s\n",sp.error_message); return _FAILURE_; } for (index_k=0; index_k<sp.ln_k_size; index_k++) { k=exp(sp.ln_k[index_k]); delta_rho_bc=0.; rho_bc=0.; /* T_b(k,eta) */ delta_i = tki[index_k*sp.tr_size+sp.index_tr_b]; rho_i = pvecback_long[ba.index_bg_rho_b]; delta_rho_bc += rho_i * delta_i; rho_bc += rho_i; /* T_cdm(k,eta) */ if (ba.has_cdm == _TRUE_) { delta_i = tki[index_k*sp.tr_size+sp.index_tr_cdm]; rho_i = pvecback_long[ba.index_bg_rho_cdm]; delta_rho_bc += rho_i * delta_i; rho_bc += rho_i; } if (primordial_spectrum_at_k(&pm,index_mode,linear,k,&pk) == _FAILURE_) { printf("\n\nError in primordial_spectrum_at_k \n=>%s\n",pm.error_message); return _FAILURE_; } P_bc=pk*pow(delta_rho_bc/rho_bc,2)*2.*_PI_*_PI_/k/k/k; fprintf(output,"%e %e\n",k,P_bc); } /******************/ if (spectra_free(&sp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",sp.error_message); return _FAILURE_; } if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
int class_assuming_bessels_computed( struct file_content *pfc, struct precision * ppr, struct background * pba, struct thermo * pth, struct perturbs * ppt, struct bessels * pbs, struct transfers * ptr, struct primordial * ppm, struct spectra * psp, struct nonlinear * pnl, struct lensing * ple, struct output * pop, double z, double * psCl, int lmin, int lmax, ErrorMsg errmsg) { /*local variables*/ double pvecback[100]; double T21; int l; double tau; /* conformal age, in unit of Mpc */ double pk_tmp; double k; double * pk_ic; if (input_init(pfc,ppr,pba,pth,ppt,pbs,ptr,ppm,psp,pnl,ple,pop,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(ppr,pba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",pba->error_message); return _FAILURE_; } if (thermodynamics_init(ppr,pba,pth) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",pth->error_message); return _FAILURE_; } if (perturb_init(ppr,pba,pth,ppt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",ppt->error_message); return _FAILURE_; } if (transfer_init(ppr,pba,pth,ppt,pbs,ptr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",ptr->error_message); return _FAILURE_; } if (primordial_init(ppr,ppt,ppm) == _FAILURE_) { printf("\n\nError in primordial_init \n=>%s\n",ppm->error_message); return _FAILURE_; } if (spectra_init(ppr,pba,ppt,ptr,ppm,psp) == _FAILURE_) { printf("\n\nError in spectra_init \n=>%s\n",psp->error_message); return _FAILURE_; } if (nonlinear_init(ppr,pba,pth,ppt,pbs,ptr,ppm,psp,pnl) == _FAILURE_) { printf("\n\nError in nonlinear_init \n=>%s\n",pnl->error_message); return _FAILURE_; } if (lensing_init(ppr,ppt,psp,pnl,ple) == _FAILURE_) { printf("\n\nError in lensing_init \n=>%s\n",ple->error_message); return _FAILURE_; } if (output_init(pba,ppt,psp,pnl,ple,pop) == _FAILURE_) { printf("\n\nError in output_init \n=>%s\n",pop->error_message); return _FAILURE_; } background_functions(pba, 1/(1.+z), 1, pvecback); /* T21 := 7.59*10^-2 h (1+\delta) (1+z)^2 / E(z); * E[z]:= Sqrt[Omega_m(1+z)^3+Omega_l exp(-3 Integrate[(1+w)/a, a])] mK */ T21 = 7.59 * 0.01 * pba->h * pow(1.+z,2) / (pvecback[pba->index_bg_H]/pba->H0); background_tau_of_z(pba, z, &tau); for (l=lmin; l<=lmax; l+=1) { k = l/(pba->conformal_age - tau); /* tau in Mpc; k in spectra_pk_at_k_and_z is in [1/Mpc] */ spectra_pk_at_k_and_z(pba, ppm, psp, k, z, &pk_tmp, pk_ic); /* 3-D vs 2-D: l(l+1)Cl/2PI = k^3 P21(k)/2PI^2, P21(k) = (T21*Y)^2 * P(k) */ /* psCl[l]'s are in mK^2 */ if(l%100==0) printf("z is %e, l is %d, tau is %e, k is %e, pk is %e\n", z, l, tau, k, pk_tmp); psCl[l] = 2*M_PI/(l*1.0*(l+1)) * T21*T21 * pow(k, 3) * pk_tmp/(2*M_PI*M_PI); } /****** all calculations done, now free the structures ******/ if (lensing_free(ple) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",ple->error_message); return _FAILURE_; } if (nonlinear_free(pnl) == _FAILURE_) { printf("\n\nError in nonlinear_free \n=>%s\n",pnl->error_message); return _FAILURE_; } if (spectra_free(psp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",psp->error_message); return _FAILURE_; } if (primordial_free(ppm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",ppm->error_message); return _FAILURE_; } if (transfer_free(ptr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",ptr->error_message); return _FAILURE_; } if (perturb_free(ppt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",ppt->error_message); return _FAILURE_; } if (thermodynamics_free(pth) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",pth->error_message); return _FAILURE_; } if (background_free(pba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",pba->error_message); return _FAILURE_; } return _SUCCESS_; }
int main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct spectra sp; /* for output spectra */ struct nonlinear nl; /* for non-linear spectra */ struct lensing le; /* for lensed spectra */ struct output op; /* for output files */ ErrorMsg errmsg; /* for error messages */ if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&nl,&le,&op,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&bs,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } /****** output the transfer functions ******/ printf("Output of transfer functions (l, k, Delta)\n"); /* 1) select the mode, initial condition, type and multipole of the function you want to plot: */ int index_mode=pt.index_md_scalars; int index_ic =pt.index_ic_ad; int index_type=tr.index_tt_lcmb; //int index_type=tr.index_tt_density+2; /* 2) here is an illustration of how to output the transfer functions at some (k,l)'s of your choice */ /* int index_l = 0; double k=3.6e-4; double transfer; if (transfer_functions_at_k(&tr, index_mode, index_ic, index_type, index_l, k, &transfer ) == _FAILURE_) { printf("\n\nError in transfer_function_at_k \n=>%s\n",tr.error_message); return _FAILURE_; } printf("%d %e %e\n",tr.l[index_l],k,transfer); */ /* 3) here you can output the full tabulated arrays for all k and l's*/ int index_k; int index_l; double transfer; for (index_l=0; index_l<tr.l_size[index_mode]; index_l++) { //for (index_l=20; index_l<21; index_l++) { for (index_k=0; index_k<tr.k_size[index_mode]; index_k++) { transfer=tr.transfer[index_mode] [((index_ic * tr.tt_size[index_mode] + index_type) * tr.l_size[index_mode] + index_l) * tr.k_size[index_mode] + index_k]; if (transfer != 0.) { printf("%d %e %e\n",tr.l[index_l],tr.k[index_mode][index_k],transfer); } } printf("\n\n"); } /****** all calculations done, now free the structures ******/ if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }
/* send file f to VisioBraille */ void fileput(char *f) { int n; char *c; int res; int fd; if (visiobases_dir && (f[0]!='.' || (f[1]!='.' && f[1]!='/') || (f[1]=='.' && f[2]!='/'))) { char *f2 = malloc(strlen(visiobases_dir)+1+strlen(f)); strcpy(f2,visiobases_dir); strcat(f2,f); if (tryToFind(f2, &fd)) { free(f2); goto ok; } fprintf(stderr,"couldn't get it from download directory, trying from current directory.\n"); free(f2); } if (!tryToFind(f, &fd)) { fprintf(stderr,"open failed, giving up that file\n"); return; } ok: transfer_init(fileput); printf("putting %s\n",f); /* truncate filename : no extension, 8 chars max */ if ((c=strrchr(f,'/'))) f=c+1; for (c=f;*c && *c!='.' && c<f+VB_MAXFNLEN;c++); n=c-f; obuf[0]=VB_FILEHERE; obuf[1]=numpacket='1'; obuf[2]=VB_FILET_AGENDA; memcpy(&obuf[3],f,n); memcpy(filename,f,n); filename[n]=0; osize=n+3; otries=0; sizetransferred=0; while(1) { SEND(obuf,osize); printf("\r%s: %dKo...",filename,sizetransferred>>10); fflush(stdout); RECV(); if (ibuf[0]==VB_NEXT) break; if (res<2) { showPacket(res); continue; } if (ibuf[0]!=VB_ACK_DATA) { showPacket(res); continue; } if (ibuf[1]!=numpacket) { showPacket(res); continue; } if ((res=read(fd,&obuf[2],SIZE_PUT))<0) { fprintf(stderr,"reading data on disk for file %s failed: %s\n" "So giving up for this file\n",strerror(errno),filename); break; } if (res==0) { /* eof */ obuf[0]=VB_DATA_OVER; osize=1; otries=0; WaitForOk(); break; } obuf[0]=VB_HERES_DATA; obuf[1]=numpacket=(numpacket+1)&'7'; osize=res+2; otries=0; sizetransferred+=res; } /* transfer finished */ close(fd); printf("ok\n"); }
/* get file f on VisioBraille */ void fileget(char *f) { int n=strlen(f),lnpath,lnext; char *c,*d; int res; int fd; struct stat st; char *path,*ext; if (n==0) return; /* find path, if any */ for (c=f+n-1; c>=f && *c!='/'; c--); if (c>=f) { path=f; lnpath=c-f; *c++='\0'; f=c; } else { path=NULL; lnpath=-1; } /* remove extension */ for (c=f; *c && *c!='.'; c++); if (*c) { ext=c; lnext=n-(ext-f); } else { ext=NULL; lnext=-1; } n=c-f; if (path) printf("getting %s in %s\n",f,path); else printf("getting %s\n",f); transfer_init(fileget); /* sending filename (can contain * and ?) */ obuf[0]=VB_UNLOAD; memcpy(&obuf[1],f,n); osize=n+1; otries=0; while(1) { SEND(obuf,osize); numpacket='1'; RECV(); if (ibuf[0]==VB_FILES_OVER[0]) break; /* end of file list */ if (res<3) { showPacket(res); continue; } if (ibuf[0]!=VB_FILEHERE) { showPacket(res); continue; } if (ibuf[1]!=numpacket) { showPacket(res); continue; } /* ok, VisioBraille proposed a file, let's try to get it */ if (res-3>VB_MAXFNLEN) { fprintf(stderr,"name too long, giving up that file\n"); obuf[0]=VB_NEXT; obuf[1]=ibuf[1]; osize=2; otries=0; continue; } /* copy its name */ { char fullpath[(lnpath+1)+(res-3)+(ext?lnext+1:strlen(visiobases_ext))+1]; if (path) { strcpy(fullpath,path); strcat(fullpath,"/"); } for(c=ibuf+3,d=fullpath+lnpath+1;c-ibuf<res;*d++=tolower(*c++)) fullpath[lnpath+1+res-3]='\0'; strcat(fullpath,ext?ext:visiobases_ext); if (backup && stat(fullpath,&st)>=0) if (renameBackups(fullpath)==-1) perror("couldn't rename backups, overwriting"); if ((fd=open(fullpath,O_WRONLY|O_CREAT|O_TRUNC,0644))<0) { /* openout failed, give up that file */ perror(fullpath); fprintf(stderr,"open failed, giving up that file\n"); obuf[0]=VB_NEXT; obuf[1]=ibuf[1]; osize=2; otries=0; continue; } /* start transfer : */ obuf[0]=VB_ACK_DATA; obuf[1]=numpacket; osize=2; otries=0; numpacket=(numpacket+1)&'7'; sizetransferred=0; /* ready to transfer ! */ while (1) { SEND(obuf,osize); printf("\r%s: %dKo...",fullpath,sizetransferred>>10); fflush(stdout); RECV(); if (ibuf[0]==VB_DATA_OVER) break; if (res<2) { showPacket(res); continue; } if (ibuf[0]!=VB_HERES_DATA) { showPacket(res); continue; } if (ibuf[1]!=numpacket) { showPacket(res); continue; } if (write(fd,ibuf+2,res-2)<res-2) { fprintf(stderr,"writing data on disk for file %s\n" "So giving up\n",fullpath); transfer_abort(RET_EUNIX); } obuf[0]=VB_ACK_DATA; obuf[1]=numpacket; osize=2; otries=0; sizetransferred+=res-2; numpacket=(numpacket+1)&'7'; } /* transfer finished */ close(fd); printf("ok\n"); obuf[0]=VB_OK; osize=1; otries=0; } } transferring=0; }
main(int argc, char **argv) { struct precision pr; /* for precision parameters */ struct background ba; /* for cosmological background */ struct thermo th; /* for thermodynamics */ struct perturbs pt; /* for source functions */ struct bessels bs; /* for bessel functions */ struct transfers tr; /* for transfer functions */ struct primordial pm; /* for primordial spectra */ struct output op; struct lensing le; struct spectra sp; /* for output spectra */ struct spectra_nl nl; /* for calculation of non-linear spectra */ ErrorMsg errmsg; if (input_init_from_arguments(argc, argv,&pr,&ba,&th,&pt,&bs,&tr,&pm,&sp,&le,&op,&nl,errmsg) == _FAILURE_) { printf("\n\nError running input_init_from_arguments \n=>%s\n",errmsg); return _FAILURE_; } if (background_init(&pr,&ba) == _FAILURE_) { printf("\n\nError running background_init \n=>%s\n",ba.error_message); return _FAILURE_; } if (thermodynamics_init(&pr,&ba,&th) == _FAILURE_) { printf("\n\nError in thermodynamics_init \n=>%s\n",th.error_message); return _FAILURE_; } if (perturb_init(&pr,&ba,&th,&pt) == _FAILURE_) { printf("\n\nError in perturb_init \n=>%s\n",pt.error_message); return _FAILURE_; } if (bessel_init(&pr,&bs) == _FAILURE_) { printf("\n\nError in bessel_init \n =>%s\n",bs.error_message); return _FAILURE_; } if (transfer_init(&pr,&ba,&th,&pt,&bs,&tr) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",tr.error_message); return _FAILURE_; } if (primordial_init(&pr,&pt,&pm) == _FAILURE_) { printf("\n\nError in transfer_init \n=>%s\n",pm.error_message); return _FAILURE_; } if (spectra_init(&ba,&pt,&tr,&pm,&sp) == _FAILURE_) { printf("\n\nError in spectra_init \n=>%s\n",sp.error_message); return _FAILURE_; } if (trg_init(&pr,&ba,&th,&pm,&sp,&nl) == _FAILURE_) { printf("\n\nError in trg_init \n=>%s\n",nl.error_message); return _FAILURE_; } /****** done ******/ if (trg_free(&nl) == _FAILURE_) { printf("\n\nError in trg_free \n=>%s\n",nl.error_message); return _FAILURE_; } if (spectra_free(&sp) == _FAILURE_) { printf("\n\nError in spectra_free \n=>%s\n",sp.error_message); return _FAILURE_; } if (primordial_free(&pm) == _FAILURE_) { printf("\n\nError in primordial_free \n=>%s\n",pm.error_message); return _FAILURE_; } if (transfer_free(&tr) == _FAILURE_) { printf("\n\nError in transfer_free \n=>%s\n",tr.error_message); return _FAILURE_; } if (bessel_free(&bs) == _FAILURE_) { printf("\n\nError in bessel_free \n=>%s\n",bs.error_message); return _FAILURE_; } if (perturb_free(&pt) == _FAILURE_) { printf("\n\nError in perturb_free \n=>%s\n",pt.error_message); return _FAILURE_; } if (thermodynamics_free(&th) == _FAILURE_) { printf("\n\nError in thermodynamics_free \n=>%s\n",th.error_message); return _FAILURE_; } if (background_free(&ba) == _FAILURE_) { printf("\n\nError in background_free \n=>%s\n",ba.error_message); return _FAILURE_; } return _SUCCESS_; }