/******************************************************/ /* Reads 0D, 1D and 2D files from the current directory */ /* and translate them into files used for modelling. */ /* D. Boucher Oct. 1994 */ /******************************************************/ #include #include #include #include char field_name[7][11][12]={'\0'}; char field_data[7][11][12]={'\0'}; char tok[50],pulse[50]; struct LIST {char UFILE[21]; char FILE[16]; float mult; char FLAG[16]; int panel; int signal; }; struct LIST list_1D[] = { {" IP ","ip.trf", 1e-6, "+X", 1, 1}, {" BT ","bt.trf", 1., ".", 0, 0}, {" AMIN ","amin.trf", 1., ".", 0, 0}, {" RGEO ","rgeo.trf", 1., ".", 0, 0}, {" KAPPA ","kappa.trf", 1., ".", 0, 0}, {" DELTA ","delta.trf", 1., ".", 0, 0}, {" INDENT ","indent.trf", 1., ".", 0, 0}, {" PNBI ","pnbi.trf", 1e-6, "+X", 8, 4}, {" PICRH ","picrh.trf", 1e-6, "+X", 8, 3}, {" PFLOSS ","pfloss.trf", 1e-6, ".", 0, 0}, {" PRAD ","prad.trf", 1e-6, "X", 5, 2}, {" ZEFF ","zeff.trf", 1. , "+X", 7, 3}, {" NEL ","nel.trf", 1e-19, "+X", 7, 2}, {" VSURF ","vsurf.trf", 1., "X", 1, 2}, {" LI ","li.trf", 1., "X", 6, 2}, {" NMAIN0 ","nmain0.trf", 1e-19, ".", 0, 0}, {" THNT ","thnt.trf", 1e-15, "X", 8, 6}, {" WTH ","wth.trf", 1e-6, "X", 4, 1}, {" WTOT ","wtot.trf", 1e-6, ".", 0, 0}, {" TE0 ","te0.trf", 1e-3, "X", 2, 1}, {" TI0 ","ti0.trf", 1e-3, "X", 2, 2}, {" POHM ","pohm.trf", 1e-6, "X", 5, 1}, {" Q95 ","q95.trf", 1., ".", 0, 0}, {" IBOOT ","iboot.trf", 1e-6, "IBOOT",1, 1}, {"","",0.,".",0,0} }; struct LIST list_2D[] = { {" TE ","te.ant", 1e-3, "~X", 1, 1}, {" TI ","ti.ant", 1e-3, "~X", 1, 2}, {" NE ","ne.ant", 1e-19, "~X", 2, 1}, {" QNBIE ","qnbie.ant", 1e-6, "+~X", 8, 3}, {" QNBII ","qnbii.ant", 1e-6, "+~X", 8, 4}, {" QICRHE ","qicrhe.ant", 1e-6, "+~X", 5, 3}, {" QICRHI ","qicrhi.ant", 1e-6, "+~X", 5, 3}, {" SNBIE ","snbie.ant", 1e-19, "+~X", 8, 1}, {" SNBII ","snbii.ant", 1e-19, ".", 0, 0}, {" CURNBI ","curnbi.ant", 1e-6, "~jBEAM",1, 3}, {" NFAST ","nfast.ant", 1e-19, "+~X", 2, 4}, {" QRAD ","qrad.ant", 1e-6, "~X", 5, 1}, {" ZEFFR ","zeffr.ant", 1., "~X", 2, 5}, {" CHIE ","chie.ant", 1., "~X", 4, 2}, {" CHII ","chii.ant", 1., "~X", 4, 3}, {" CURTOT ","curtot.ant", 1e-6, "~X", 1, 3}, {" NIMP ","nimp.ant", 1e-19, "~X", 2, 3}, {" NM1 ","nm1.ant", 1e-19, "~X", 2, 2}, {" QOHM ","qohm.ant", 1e-6, "~X", 5, 9}, {" RMAJOR ","rmajor.ant", 1e2, ".", 0, 0}, {" RMINOR ","rminor.ant", 1e2, ".", 0, 0}, {" VOLUME ","volume.ant", 1., "X", 9, 3}, {" SURF ","surf.ant", 1., ".", 0, 0}, {"","",0.,".",0,0} }; FILE *experiment, *all_output; /****************************************************************/ float read_number(int *ern, FILE *file) {int line,col,count; char *p,c,str[250]; *ern = 0; fread(&c,1,1,file); while((c == ' ' || c == '\n') && !feof(file))fread(&c,1,1,file); if(feof(file)){fprintf(stdout,"\nERROR1: Syntax error.\n\n");*ern=-1;return(0.);} p=&str[0]; count = -1; while(!feof(file) && c !=' ' && c != '\n') { *p++=c; if(count == 4)break; fread(&c,1,1,file); if(c == 'E' || c == 'e')count=0; if(count>=0)count++; } *p = '\0'; if(feof(file)){fprintf(stdout,"\nERROR2: Syntax error.\n\n");*ern = -1;return(0.);} return(atof(str)); } /***************************************************************/ upper(char *name) {char *p; p=name; while(*p!='\0') {*p=(char)toupper((int)*p); p++; } } /****************************************************************/ /****************************************************************/ void read_next(FILE *file,char *fname, char field[7][11][12]) {int line,col; char *p,c; if((file = fopen(fname,"r"))==NULL) return; fread(&c,1,1,file); while((c == ' ' || c == '\n') && !feof(file))fread(&c,1,1,file); line=0;col=0; do {p = &field[col][line][0]; while(!feof(file) && c !=' ' && c != '\n') { *p++=c; fread(&c,1,1,file); } *p = '\0'; while((c == ' ' || c == '\n') && !feof(file))fread(&c,1,1,file); col++; if(col==7){col=0;line++;} } while(line < 11); fclose(file); } /***************************************************************/ void read_0D(char *name) {FILE *file; char fname[250]; int i,j; sprintf(fname,"%s_0d.dat",name); file = fopen(fname,"r"); if(file==NULL) {fprintf(stdout,"\nNo 0D file found.\n\n"); return; } fclose(file); read_next(file,"tokamak_0d.dat",field_name); read_next(file,fname,field_data); for(i=0;i<11;i++) {for(j=0;j<7;j++) if(strcmp(field_data[j][i],"??????????")!=0 && strcmp(field_data[j][i],"-9.999E-09")!=0 && strcmp(field_data[j][i],"-9999999")!=0) fprintf(stdout,"%-10s: %s\n",field_name[j][i],field_data[j][i]); } } /****************************************************************/ void output_1D(char *name,int nx, float x[], float y[]) {int i,j; char lname[250],str[250]; float mult; short nxs; FILE *file; i=0;while(strcmp(name,list_1D[i].UFILE) != 0 && list_1D[i].UFILE[0] != '\0') i++; if(list_1D[i].UFILE[0] == '\0') {fprintf(stdout,"Error: 1D signal %s not registered.\n",name); return; } sprintf(lname,list_1D[i].FILE); if(list_1D[i].panel != 0 && list_1D[i].signal != 0) {fprintf(experiment,"%s\n",lname); fprintf(experiment,"%s\t%d\t%d\n",list_1D[i].FLAG,list_1D[i].panel,list_1D[i].signal); } fprintf(all_output,"%s\n",lname); fprintf(all_output,"X\t1\t1\n"); mult=list_1D[i].mult; if((file = fopen(lname,"w"))==NULL)return; sprintf(str," %s %s %s %s",lname,tok,pulse); fwrite(str,80,1,file); for(i=0;i 1999){fprintf(stdout,"\nERROR: Too many X points.\n\n");exit(0);} /*---- read data -------*/ for(i=0;i 199){fprintf(stdout,"\nERROR: Too many X points.\n\n");exit(0);} /*---- find number radial points -------*/ do {fgets(str,255,file); p=&str[0]; while(*p && *p != ';')p++; *(p+3) = '\0'; if(strcmp(p,";-#")==0){*p='\0';break;} } while(!feof(file)); if(feof(file))return; ny = atoi(str); if(ny > 999){fprintf(stdout,"\nERROR: Too many Y points.\n\n");exit(0);} /*---- read data -------*/ for(i=0;i