/[MITgcm]/MITgcm/pkg/mnc/mnc_create_dir.c
ViewVC logotype

Annotation of /MITgcm/pkg/mnc/mnc_create_dir.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (hide annotations) (download)
Tue Mar 23 05:24:44 2004 UTC (20 years, 2 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint52n_post, checkpoint53d_post, checkpoint54a_pre, checkpoint55c_post, checkpoint54e_post, checkpoint54a_post, checkpoint53c_post, checkpoint55d_pre, checkpoint57d_post, checkpoint57g_post, checkpoint57b_post, checkpoint57c_pre, checkpoint55j_post, checkpoint56b_post, checkpoint57e_post, checkpoint55h_post, checkpoint57g_pre, checkpoint54b_post, checkpoint53b_pre, checkpoint55b_post, checkpoint54d_post, checkpoint56c_post, checkpoint52m_post, checkpoint55, checkpoint53a_post, checkpoint57f_pre, checkpoint57a_post, checkpoint54, checkpoint54f_post, checkpoint53b_post, checkpoint55g_post, checkpoint55f_post, checkpoint57a_pre, checkpoint55i_post, checkpoint57, checkpoint56, checkpoint53, eckpoint57e_pre, checkpoint57h_done, checkpoint53g_post, checkpoint57f_post, checkpoint57c_post, checkpoint55e_post, checkpoint53f_post, checkpoint55a_post, checkpoint53d_pre, checkpoint54c_post, checkpoint57h_pre, checkpoint57h_post, checkpoint56a_post, checkpoint55d_post
Changes since 1.1: +34 -11 lines
File MIME type: text/plain
 o per AJA & JMC request, re-write the MNC directory creation code:
   - directory names (strings) are passed, encoded using integers
   - everything is run-time optional with flags in "data.mnc"
   - tested and works but would benefit from some cleanup

1 edhill 1.1 /************************************************* -*- mode: C -*-
2 edhill 1.2 * $Header: /u/gcmpack/MITgcm/pkg/mnc/mnc_create_dir.c,v 1.1 2004/03/22 05:10:10 edhill Exp $
3 edhill 1.1 * $Name: $
4     */
5    
6     /* Here, we get the definition of the FC_NAMEMANGLE() macro. */
7     #include "FC_NAMEMANGLE.h"
8    
9     #include <time.h>
10     #include <stdio.h>
11     #include <stdlib.h>
12     #include <unistd.h>
13     #include <assert.h>
14     #include <sys/stat.h>
15     #include <sys/types.h>
16     #include <sys/time.h>
17 edhill 1.2 void FC_NAMEMANGLE(mnccdir) ( int *nienc, int *ienc, int *idate )
18 edhill 1.1 {
19 edhill 1.2 char name[512], dname[512];
20 edhill 1.1 struct tm * tmp;
21     time_t tt;
22 edhill 1.2 int i, j, n, ntot, iyyyymmdd;
23 edhill 1.1 mode_t mode = 0x0;
24 edhill 1.2 char * cenc =
25     {"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.,+-=/~\0"};
26     int ncenc = 70;
27 edhill 1.1
28 edhill 1.2 n = ((*nienc) > 100) ? 100 : (*nienc);
29 edhill 1.1 tt = time(&tt);
30     tmp = localtime(&tt);
31 edhill 1.2 iyyyymmdd = tmp->tm_mday
32     + 100*(tmp->tm_mon + 1 + 100*(1900+tmp->tm_year));
33     for (i=0; i<n; i++) {
34     /* printf("ienc = %d, %c\n", ienc[i], cenc[ienc[i] - 1]); */
35     name[i] = cenc[ienc[i] - 1];
36     }
37     name[n] = '\0';
38     /* printf("name = \"%s\", n = %d\n", name, n); */
39 edhill 1.1 for (i=1; i<10000; i++) {
40 edhill 1.2 if (*idate == 1)
41     snprintf(dname, 100, "%s%08d_%04d\0", name, iyyyymmdd, i);
42     else
43     snprintf(dname, 100, "%s%04d\0", name, i);
44 edhill 1.1 mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
45 edhill 1.2 if (mkdir(dname, mode) == 0) {
46 edhill 1.1 break;
47     }
48     }
49 edhill 1.2 n = (int)(strlen(dname));
50     /* printf("dname = \"%s\", n = %d\n", dname, n); */
51     ntot = 0;
52     for (i=0; i<n; i++) {
53     for (j=0; j<ncenc; j++) {
54     if (cenc[j] == dname[i]) {
55     ienc[ntot] = j + 1;
56     ntot++;
57     break;
58     }
59     }
60     }
61     *nienc = ntot;
62 edhill 1.1 }
63    
64    

  ViewVC Help
Powered by ViewVC 1.1.22