EXPORT void start_clock( const char *s) { int i; if (!debugging("CLOCK")) return; if (cputime == NULL) { MAX_TIMES = 40; cputime = (double*)malloc(MAX_TIMES*sizeof(double)); zero_scalar(cputime,MAX_TIMES*sizeof(double)); } if (top >= MAX_TIMES) { double *new_cputime; int NEW_MAX_TIMES = 2*MAX_TIMES; new_cputime = (double*)malloc(NEW_MAX_TIMES*sizeof(double)); zero_scalar(new_cputime,NEW_MAX_TIMES*sizeof(double)); for (i = 0; i < MAX_TIMES; i++) new_cputime[i] = cputime[i]; MAX_TIMES = NEW_MAX_TIMES; } for (i = 0; i < top; i++) (void) printf(" "); (void) printf("CLOCK (%s)\n",s); cputime[top] = cpu_seconds(); top++; } /*end start_clock*/
EXPORT POINTER_Q *delete_from_pointer_queue( POINTER_Q *pq) { PQ_HEADER *pq_header; if (pq == NULL) return NULL; pq_header = Pointer_queue_header(pq); if (pq_header == NULL) { (void) printf("WARNING in delete_from_pointer_queue(), " "can't delete element, probably already deleted\n"); return NULL; } if (pq_header->head == pq) pq_header->head = pq->next; if (pq_header->tail == pq) pq_header->tail = pq->prev; if (pq->prev) pq->prev->next = pq->next; if (pq->next) pq->next->prev = pq->prev; pq_header->n_queue--; zero_scalar(pq,sizeof(PTR_LIST)); if (pq_header->head == NULL && pq_header->alloc_type != USE_STORE_FOR_ALLOC) { POINTER_Q *pq_str, *p2str, *prev; pq_str = pq_header->pq_str; while (pq_str->next) pq_str = pq_str->next; do { free(pq_str->pointer); prev = pq_str->prev; free(pq_str); pq_str = prev; } while (pq_str); if ((p2str = pq_header->p2str) != NULL) { while (p2str->next) p2str = p2str->next; do { free(p2str->pointer); prev = p2str->prev; free(p2str); p2str = prev; } while (p2str); } zero_scalar(pq_header,sizeof(PQ_HEADER)); free(pq_header); return NULL; } return pq_header->head; } /*end delete_from_pointer_queue*/
EXPORT void f_clear_state( Locstate state, size_t sizest) { zero_scalar(state,sizest); } /*end f_clear_state*/
EXPORT void FrontInitStandardIO( int argc, char **argv, F_BASIC_DATA *f_basic) { char *in_name = f_basic->in_name; char *out_name = f_basic->out_name; char *restart_name = f_basic->restart_name; int *subdomains = f_basic->subdomains; f_basic->ReadFromInput = NO; f_basic->RestartRun = NO; #if defined(__MPI__) pp_init(&argc,&argv); #endif /* defined(__MPI__) */ argc--; argv++; strcpy(out_name,"intfc"); while (argc >= 1) { if (argv[0][0] != '-') { printf("Usage: example -o output\n"); exit(1); } switch(argv[0][1]) { case 'i': case 'I': f_basic->ReadFromInput = YES; zero_scalar(in_name,200); strcpy(in_name,argv[1]); argc -= 2; argv += 2; break; case 'r': case 'R': f_basic->RestartRun = YES; zero_scalar(restart_name,200); strcpy(restart_name,argv[1]); argc -= 2; argv += 2; break; case 't': case 'T': f_basic->RestartStep = atoi(argv[1]); argc -= 2; argv += 2; break; case 'd': case 'D': f_basic->dim = atoi(argv[1]); argc -= 2; argv += 2; break; case 'o': case 'O': zero_scalar(out_name,200); strcpy(out_name,argv[1]); #if defined(__MPI__) sprintf(out_name,"%s.%d",out_name,pp_mynode()); #endif /* defined(__MPI__) */ freopen(out_name,"w",stdout); zero_scalar(out_name,200); strcpy(out_name,argv[1]); argc -= 2; argv += 2; break; #if defined(__MPI__) case 'p': case 'P': { int i,total_num_proc = 1; for (i = 0; i < MAXD; ++i) { if (argc < 2 || argv[1][0] == '-') break; argc -= 1; argv += 1; subdomains[i] = atoi(argv[0]); total_num_proc *= subdomains[i]; } argc -= 1; argv += 1; if (total_num_proc != pp_numnodes()) { printf("total number of processors for the partition %d " "does not equal to requested np %d\n", total_num_proc,pp_numnodes()); clean_up(ERROR); } } #endif /* defined(__MPI__) */ } } } /* end FrontInitStatndardIO */
EXPORT void read_rectangular_grid( const IO_TYPE *io_type, RECT_GRID *gr, boolean bufzones, REMAP *remap) { FILE *file = io_type->file; char Line[2048]; char ss[120]; long offset; int i, c; int dim; int maxd = MAXD, size_float = FLOAT; boolean b_iput; int status; char *string; if (gr == NULL) { (void) printf("WARNING in read_rectangular_grid(), grid is null\n"); return; } zero_scalar(gr,sizeof(RECT_GRID)); gr->Remap = *remap; if (fgetstring(file,"Grid Dimension = ") == FUNCTION_FAILED) { gr->dim = 2; } else { status = fscanf(file,"%d",&dim); while ((c = getc(file)) != '\n'); if ((c = getc(file)) == '\f') /* Binary input */ { c = getc(file); if (c == 1) /*oldstyle printout*/ { size_t nbytes; (void) printf("WARNING in read_rectangular_grid(), " "old style binary IO only valid for\n" "reading from runs with same floating " "point precision and endian as output\n"); nbytes = fread((void *)gr,sizeof(RECT_GRID),1,file); return; } if (c != 0) { screen("ERROR in read_rectangular_grid(), " "Improper output format\n"); clean_up(ERROR); return; } b_iput = YES; status = fscanf(file,"%*s%*s%d%*s%*s%d",&maxd,&size_float); (void) getc(file); /* newline */ } else { b_iput = NO; (void) ungetc(c,file); } } gr->dim = dim; (void) sprintf(ss,"%10s = ",remap->Dnm[0]); if (fgetstring(file,ss) == FUNCTION_FAILED) { (void) printf("WARNING in read_rectangular_grid(), " "grid not found\n"); return; } string = fgets(Line,2046,file); /* clear end of X,Y line */ #define read_grid_float(x) \ if (b_iput) \ { \ (void) getc(file); /* get blank */ \ (void) read_binary_real_array(x,1,io_type); \ } \ else \ (void) fscan_float(file,(x)) /* Read grid endpoints */ for (i = 0; i < dim; ++i) { status = fscanf(file,"%*s%*s"); read_grid_float(gr->L+i); status = fscanf(file,"%*s%*s"); read_grid_float(gr->U+i); } /* Read grid spacings */ for (i = 0; i < dim; ++i) { status = fscanf(file,"%*s%*s"); read_grid_float(gr->h+i); status = fscanf(file,"%*s%*s%d",gr->gmax+i); } offset = ftell(file); (void) sprintf(ss," G%sL = ",remap->Dnm[0]); if (fgetstring(file,ss) == FUNCTION_FAILED) { for (i = 0; i < dim; ++i) { if (bufzones == YES) { gr->lbuf[i] = gr->ubuf[i] = 1; gr->GL[i] = gr->L[i]; gr->GU[i] = gr->U[i]; gr->VL[i] = gr->L[i] - cell_width(0,i,gr); gr->VU[i] = gr->U[i] + cell_width(gr->gmax[i]-1,i,gr); } else { gr->lbuf[i] = gr->ubuf[i] = 0; gr->GL[i] = gr->L[i]; gr->GU[i] = gr->U[i]; gr->VL[i] = gr->L[i]; gr->VU[i] = gr->U[i]; } } return; } (void) fseek(file,offset,SEEK_SET); /* Read global grid endpoints */ for (i = 0; i < dim; ++i) { status = fscanf(file,"%*s%*s"); read_grid_float(gr->GL+i); status = fscanf(file,"%*s%*s"); read_grid_float(gr->GU+i); } /* Read virtual domain endpoints */ for (i = 0; i < dim; ++i) { status = fscanf(file,"%*s%*s"); read_grid_float(gr->VL+i); status = fscanf(file,"%*s%*s"); read_grid_float(gr->VU+i); } /* Read buffer zone widths */ for (i = 0; i < dim; ++i) status = fscanf(file,"%*s%*s%d%*s%*s%d",gr->lbuf+i,gr->ubuf+i); set_rect_grid(gr->L,gr->U,gr->GL,gr->GU,gr->lbuf,gr->ubuf,gr->gmax, dim,&gr->Remap,gr); #undef read_grid_float return; } /*end read_rectangular_grid*/