void read_dr_catalogs(Catalog *cat_d,Catalog *cat_r, np_t *sum_wd,np_t *sum_wd2, np_t *sum_wr,np_t *sum_wr2) { ////// // Reads or creates random and data catalogs Catalog cat_dat,cat_ran; cat_dat=read_catalog(fnameData,sum_wd,sum_wd2); if(gen_ran) { read_mask(); if(corr_type!=1) read_red_dist(); timer(0); cat_ran=mk_random_cat(fact_n_rand*cat_dat.np); timer(1); end_mask(); *sum_wr=(np_t)(fact_n_rand*cat_dat.np); *sum_wr2=(np_t)(fact_n_rand*cat_dat.np); } else cat_ran=read_catalog(fnameRandom,sum_wr,sum_wr2); #ifdef _DEBUG write_Catalog(cat_dat,"debug_DatCat.dat"); write_Catalog(cat_ran,"debug_RanCat.dat"); #endif //_DEBUG *cat_d=cat_dat; *cat_r=cat_ran; }
int main(void) { int ret, status; pid_t child, ctl; nl_catd messcat; output_init(); /* Generate the message catalog file from the text sourcefile */ if (system(NULL)) { if (create_catalog() != 0) UNRESOLVED(errno, "Can't create " MESSCAT_IN); ret = system("gencat " MESSCAT_OUT " " MESSCAT_IN); if (ret != 0) output ("Could not find the source file for message catalog.\n" "You may need to execute gencat yourself.\n"); } messcat = catopen("./" MESSCAT_OUT, 0); if (messcat == (nl_catd) - 1) UNRESOLVED(errno, "Could not open ./" MESSCAT_OUT); read_catalog(messcat, "parent"); child = fork(); if (child == -1) UNRESOLVED(errno, "Failed to fork"); if (child == 0) { read_catalog(messcat, "child"); exit(PTS_PASS); } ctl = waitpid(child, &status, 0); if (ctl != child) UNRESOLVED(errno, "Waitpid returned the wrong PID"); if ((!WIFEXITED(status)) || (WEXITSTATUS(status) != PTS_PASS)) FAILED("Child exited abnormally"); ret = catclose(messcat); if (ret != 0) UNRESOLVED(errno, "Failed to close the message catalog"); system("rm -f " MESSCAT_IN " " MESSCAT_OUT); #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; }
void get_bin() { struct catalog c; string str = ""; string str1 = ""; string str2 = ""; string str3 = ""; string strf = ""; c.num = 0; string data = ""; c = read_catalog(); FILE* out = fopen("create.data", "wb+"); string tmp = ""; freopen("data2.json","r",stdin); getline(cin,str); //ofstream out("create.data"); while(getline(cin,str)) { if (str == "[") continue; //文件开头标志 if (str == "]") break; //文件结束标志 int sum = 0; int count = 0; int aid[50]; int off[50]; string str3[50]; str3[0] = ""; int i = 2; //忽略开头的{“ int len = str.size(); while(i < len - 1) { int l = 0; //key_name的偏移亮 while(str[i] != '"') { str1 += str[i]; i++; } i += 3; //忽略”:和空格 if (str[i] == '{') { //key_type的偏移量 str2 = "json"; while(str[i] != '}') { str3[count] += str[i]; i++; l++; } str3[count] += '}'; l++; } else if (str[i] == '[') { str2 = "array"; while(str[i] != ']') { str3[count] += str[i]; i++; l++; } str3[count] += ']'; l++; } else if (str[i] == '"') { str2 = "text"; i++; while(str[i] != '"') { str3[count] += str[i]; i++; l++; } } else if (str[i] == 'f' || str[i] == 't') { str2 = "bool"; while(str[i] != ',' && str[i] != '}') { str3[count] += str[i]; i++; l++; } // if (str3[count] == "true")str3[count] = "t"; // else str3[count] = "f"; } else { str2 = "int"; string t = ""; while(str[i] != ',' && str[i] != '}') { t += str[i]; //str3[count] += str[i]; i++; l++; } str3[count] += (char)strtonum(t); } while(str[i] != ',' && i < len - 1) i++; if (i != len - 1) i += 3; off[count] = l; for (int j = 0; j < c.num; j++) { if(str1 == c.key_name[j] && str2 == c.key_type[j]) { aid[count] = j+1; break; } } str2 = ""; str1 = ""; count++; str3[count] = ""; } /* int ss = 0; out << count << ' '; for (int j = 0; j < count; j++) { out << aid[j] << ' '; } for (int j = 0; j < count; j++) { out << ss << ' '; ss += off[j]; sum += off[j]; } out << sum << ' '; for (int j = 0; j < count; j++) { out << str3[j]; } out << endl; } out.close(); fclose(stdin); */ int ss = 0; //out << count << ' '; tmp += (char)count; //tmp += ' '; for (int j = 0; j < count; j++) { //out << aid[j] << ' '; tmp += (char)(aid[j]); //tmp += ' '; } for (int j = 0; j < count; j++) { //out << ss << ' '; tmp += (char)ss; //tmp += ' '; ss += off[j]; sum += off[j]; } //out << sum << ' '; tmp += (char)sum; //tmp += ' '; for (int j = 0; j < count; j++) { //for (unsigned int i = 0; i < str3[j].length(); i++) out << str3[j][i]; //out << str3[j] << ' '; tmp += str3[j]; //tmp += ' '; } //out << endl; tmp += "\n"; if (tmp.size()/(PAGE_SIZE/32)) { fwrite(tmp.substr(0, (PAGE_SIZE/32)).data(), 32, PAGE_SIZE/32, out); tmp = tmp.substr((PAGE_SIZE/32), tmp.size()%(PAGE_SIZE/32)); } } fwrite(tmp.data(), 32, tmp.length(), out); fclose(out); /*out = fopen("create.data", "rb+"); char* text ; fread(text, 32, PAGE_SIZE/32, out); cout << text << endl; fclose(out);*/ out = NULL; fclose(stdin); }
int main(int argc,char *argv[]) { int i,j,k,l,m; struct catalog c; struct transformation t; double ra0,de0; float rmsmin; float x[NMAX],y[NMAX],rx[NMAX],ry[NMAX]; struct image img; char filename[128]; if (argc==1) strcpy(filename,"test.fits"); else if (argc==2) strcpy(filename,argv[1]); img=read_fits(filename); printf("files read\n"); c=read_catalog("out.dat"); printf("files read\n"); // Initial fit t.ra0=c.ra[0]; t.de0=c.de[0]; t.x0=(float) img.naxis1/2.0; t.y0=(float) img.naxis2/2.0; for (l=0;l<10;l++) { for (j=0;j<5;j++) { // Transform for (i=0;i<c.n;i++) forward(t.ra0,t.de0,c.ra[i],c.de[i],&c.rx[i],&c.ry[i]); // Select for (i=0,k=0;i<c.n;i++) { if (c.usage[i]==1) { x[k]=c.x[i]; y[k]=c.y[i]; rx[k]=c.rx[i]; ry[k]=c.ry[i]; k++; } } // Fit lfit2d(x,y,rx,k,t.a); lfit2d(x,y,ry,k,t.b); printf("%f %f %f %f %f %f %f %f\n",t.ra0,t.de0,t.a[0],t.a[1],t.a[2],t.b[0],t.b[1],t.b[2]); // Move reference point reverse(t.ra0,t.de0,t.a[0],t.b[0],&ra0,&de0); t.ra0=ra0; t.de0=de0; } // Compute and plot residuals for (i=0,c.xrms=0.0,c.yrms=0.0,m=0;i<c.n;i++) { if (c.usage[i]==1) { c.xres[i]=c.rx[i]-(t.a[0]+t.a[1]*c.x[i]+t.a[2]*c.y[i]); c.yres[i]=c.ry[i]-(t.b[0]+t.b[1]*c.x[i]+t.b[2]*c.y[i]); printf("%12.4f %12.4f %12.4f %12.4f %10.4f %10.4f\n",c.x[i],c.y[i],c.rx[i],c.ry[i],c.xres[i],c.yres[i]); c.res[i]=sqrt(c.xres[i]*c.xres[i]+c.yres[i]*c.yres[i]); c.xrms+=c.xres[i]*c.xres[i]; c.yrms+=c.yres[i]*c.yres[i]; c.rms+=c.xres[i]*c.xres[i]+c.yres[i]*c.yres[i]; m++; } } c.xrms=sqrt(c.xrms/(float) m); c.yrms=sqrt(c.yrms/(float) m); c.rms=sqrt(c.rms/(float) m); // Deselect outliers for (i=0;i<c.n;i++) { if (c.res[i]>2*c.rms) c.usage[i]=0; } } printf("%12.8lf %10.6lf %10.6lf %8.4f %8.4f %8.4f %8.4f\n",img.mjd,t.ra0,t.de0,t.a[1],t.a[2],t.b[1],t.b[2]); printf("%d/%d %f %f %f\n",m,c.n,c.xrms,c.yrms,c.rms); // add_fits_keywords(t,"test.fits"); modify_fits_keywords(t,filename); return 0; }